Python is far from a top performer according to benchmark test...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samuel Walters

    #31
    OT: Of C, Fortran and pointer aliasing Was: Python if far from a top performer...

    |Thus Spake Rainer Deyke On the now historical date of Sun, 11 Jan 2004
    06:46:50 +0000|
    [color=blue]
    > Samuel Walters wrote:[color=green]
    >> So, I guess that my point is that C might not be the right language for
    >> doing numerical processing, but it seems the right language for
    >> implementing the primitives of numerical processing.[/color]
    >
    > The issue with C is that it is too slow for implementing those
    > primitives (in part due to pointer aliasing issues). Fortran is
    > considerably faster.[/color]

    I stand corrected.

    Please help me to understand the situation better.

    I went digging for technical documents, but thus far haven't found many
    useful ones. It seems everyone but me already understands pointer
    aliasing models, so they might discuss them, but they don't explain them.
    I am limited in part by my understanding of compilers and also by my
    understanding of Fortran. Here is what I have gathered so far:

    Fortran lacks a stack for function calls. This promotes speed, but
    prevents recursive functions. (Most recursive functions can efficiently be
    written as loops, though, so this shouldn't be considered a hindrance.)

    Fortran passes all arguments by reference. (This is the peppiest way to do
    it, especially with static allocation)

    Fortran 77 lacks explicit pointers and favors static allocation. This
    allows for the compiler to apply powerful automatic optimization.

    Fortran 90 added explicit pointers, but required them to only be pointed
    at specific kinds of objects, and only when those particular objects are
    declared as targets for pointers. This allows the compiler to still apply
    powerful automatic optimizations to code. I'm a bit hazy as to whether
    Fortran 90 uses static or dynamic allocation, or a combination of both,
    and whether it permits recursion.

    These pointers not only reference location, but also dimension and stride.
    Stride is implicit in C pointer declarations (by virtue of compile-time
    knowledge of the data type pointed to) but dimension is not.

    Fortran's extensions for parallel programming have been standardized, and
    the language itself makes it easy to decide how to parallelize procedures
    at compile time. Thus, it is especially favored for numeric computation on
    big iron with lots of parallelism.

    Now, for C:

    Because of dynamic allocation on the stack and the heap, there is no
    compile-time knowledge of where a variable will live, which adds an extra
    layer of reference for even static variables. This also invalidates many
    of optimizations used by Fortran compilers.

    C lacks many of the fundamental array handling semantics and primitives
    that Fortran programs rely on. Implementing them in C is a real PITA.

    C memory allocation is just plain goofy in comparison to Fortran.

    To sum up:
    Fortran sacrifices generality and dynamism for compile-time knowledge
    about data, and deeply optimizes based on that knowledge.

    C sacrifices speed for the sake of generality and dynamism.

    Please correct me or help me flesh out my ideas. Please don't skimp on
    the low-level details, I've done my fair share of assembly programming, so
    what I don't understand, I'll probably be able to find out by googling a
    bit.

    Some other interesting things I found out:

    There are two projects that allow interfacing between Python and Fortran:
    F2Py

    PyFortran
    Download Python-Fortran Connection Tool for free. Pyfort is a tool for creating extensions to the Python language with Fortran routines. It supports F77-interfaced routines now, with plans for supporting more of F90 later.


    Fortran amply supports interfaces to C and C++

    Fortran is compiled. (Doh! and I thought it was interpreted.)

    There are lots of debates on whether C++ will ever be as fast as Fortran.
    The consensus seems to be "Only if you use the right compiler with the
    right switches and are insanely careful about how you program. IOW Don't
    bother, just use Fortran if you want to do numeric processing.

    Well, there's another language to add to my list of languages to learn. It
    seems to be "The Right Tool" for a great many applications, it interfaces
    well with other languages, and it's extremely portable. Chances are, I'll
    end up using it somewhere somehow someday. Now. To find some Fortran
    tutorials.

    Thanks in advance for any of your knowledge and wisdom you are willing to
    confer upon me.

    Sam Walters.

    --
    Never forget the halloween documents.

    """ Where will Microsoft try to drag you today?
    Do you really want to go there?"""

    Comment

    • Ganesan R

      #32
      Re: QOTW?

      >>>>> "Samuel" == Samuel Walters <swalters_usene t@yahoo.com> writes:
      [color=blue]
      > I/O is one of our strengths, because we understand that most programs are
      > not algorithmically bound, but rather I/O bound. I/O is a big
      > bottle-neck, so we should be damn good at it. The fastest assembly
      > program won't do much good if it's always waiting on the disk-drive.[/color]

      Actually, Python is much slower than Perl for I/O. See the thread titled
      "Python IO Performance?" in groups.google.c om for a thread started by me on
      this topic. I am a full time C programmer but do write occasional
      Python/Perl for professional/personal use.

      To answer the original question about how much percentage of time I spend
      optimizing my Python programs - probably never. However I did switch back to
      using Perl for my most of my text processing needs. For one program that was
      intended to lookup patterns in a gzipped word list, performance of the
      original python version was horribly slow. Instead of rewriting it in Perl,
      I simply opened a pipe to zgrep and did post processing in python. This
      turned out to be much faster - I don't remember how much faster, but I
      remember waiting for the output from the pure python version while the
      python+zgrep hybrid results were almost instantaneous.

      Ganesan

      --
      Ganesan R

      Comment

      • John J. Lee

        #33
        Re: OT: Of C, Fortran and pointer aliasing Was: Python if far from a top performer...

        Samuel Walters <swalters_usene t@yahoo.com> writes:
        [color=blue]
        > |Thus Spake Rainer Deyke On the now historical date of Sun, 11 Jan 2004
        > 06:46:50 +0000|[/color]
        [...][color=blue][color=green]
        > > The issue with C is that it is too slow for implementing those
        > > primitives (in part due to pointer aliasing issues). Fortran is
        > > considerably faster.[/color]
        >
        > I stand corrected.
        >
        > Please help me to understand the situation better.
        >
        > I went digging for technical documents, but thus far haven't found many
        > useful ones. It seems everyone but me already understands pointer
        > aliasing models, so they might discuss them, but they don't explain them.[/color]
        [...]

        (haven't read all your post, so sorry if I'm telling you stuff you
        already know)

        Pointer aliasing is just the state of affairs where two pointers refer
        to a single region of memory. Fortran compilers have more information
        about aliasing than do C compilers, so can make more assumptions at
        compilation time.

        Have you tried comp.lang.fortr an, comp.lang.c++, comp.lang.c, etc?






        John

        Comment

        • David M. Cooke

          #34
          Re: Python is far from a top performer according to benchmarktest.. .

          At some point, Samuel Walters <swalters_usene t@yahoo.com> wrote:[color=blue]
          >
          > Whether one uses Fortran, Python, or any other language, all primitives
          > are eventually implemented in either C or assembly. At some point or
          > another, we end up scraping bare metal and silicon to get our answers.
          > The question then becomes, "How easily can I extend this language to fit
          > my needs." NumPy is evidence that at least a few people said "Easily
          > enough." I don't know how extensible Fortran is, but I would guess "very"
          > since I've heard of it being applied in many domains other than numerical
          > processing. (OpenFirmware, for example.)[/color]

          You're confusing Fortran with Forth, which is a stack-based language,
          much like Postscript, or RPL used on HP 48 calculators.

          These days, I doubt Fortran is used for anything but numerical processing.

          --
          |>|\/|<
          /--------------------------------------------------------------------------\
          |David M. Cooke
          |cookedm(at)phy sics(dot)mcmast er(dot)ca

          Comment

          • Dan Bishop

            #35
            Re: OT: Of C, Fortran and pointer aliasing Was: Python if far from a top performer...

            Samuel Walters <swalters_usene t@yahoo.com> wrote in message news:<pan.2004. 01.11.10.38.45. 810669@yahoo.co m>...[color=blue]
            > |Thus Spake Rainer Deyke On the now historical date of Sun, 11 Jan 2004
            > 06:46:50 +0000|
            >[color=green]
            > > Samuel Walters wrote:[/color]
            > [Fortran is faster than C.]
            >[/color]
            ....[color=blue]
            > I went digging for technical documents, but thus far haven't found many
            > useful ones. It seems everyone but me already understands pointer
            > aliasing models, so they might discuss them, but they don't explain them.
            > I am limited in part by my understanding of compilers and also by my
            > understanding of Fortran. Here is what I have gathered so far:
            >
            > Fortran passes all arguments by reference. (This is the peppiest way to do
            > it, especially with static allocation)[/color]

            Btw, for some early compilers, this was the case even with literals,
            which meant that code like

            CALL FOO(4)
            PRINT *, 4

            could print something other than 4.
            [color=blue]
            > ...I'm a bit hazy as to whether
            > Fortran 90 uses static or dynamic allocation, or a combination of both,[/color]

            You can use both, at least for arrays.
            [color=blue]
            > and whether it permits recursion.[/color]

            Fortran 90 does permit recursion, although you have to explicitly
            declare functions as "recursive" .
            [color=blue]
            > Now, for C:[/color]
            ....[color=blue]
            > C lacks many of the fundamental array handling semantics and primitives
            > that Fortran programs rely on. Implementing them in C is a real PITA.[/color]

            This is one of my least favorite things about C.
            [color=blue]
            > C memory allocation is just plain goofy in comparison to Fortran.[/color]

            And even worse in comparison to Python ;-)

            Comment

            • Matthias

              #36
              Re: Straw poll on Python performance (was Re: Python is far from a top performer ...)

              Peter Hansen <peter@engcorp. com> writes:
              [color=blue]
              > This is my "straw poll" question:
              >
              > Do you spend a "significan t" amount of time actually optimizing your
              > Python applications? (Significant is here defined as "more than five
              > percent of your time", which is for example two hours a week in a
              > 40-hour work week.)[/color]

              I was working on an image processing application and was looking for a
              quick prototyping language. I was ready to accept a 10-fold decrease
              in execution speed w.r.t. C/C++. With python+psycho, I experienced a
              1000-fold decrease.

              So I started re-writing parts of my program in C. Execution speed now
              increased, but productivity was as low as before (actually writing the
              programs directly in C++ felt somewhat more natural). Often it
              happened that I prototyped an algorithm in python, started the
              program, implemented the algorithm in C as an extension module and
              before the python algorithm had finished I got the result from the
              C-algorithm. :-(

              I've tried numerics, but my code was mostly not suitable for
              vectorization and I did not like the pointer semantics of numerics.

              So my answer to the question above is NO, I don't spend significant
              times optimizing python code as I do not use python for
              computationally intensive calculations any more. My alternatives are
              Matlab and (sometimes) Common Lisp or Scheme or Haskell.

              Comment

              • Frithiof Andreas Jensen

                #37
                Re: Python is far from a top performer according to benchmark test...


                "Samuel Walters" <swalters_usene t@yahoo.com> wrote in message
                news:pan.2004.0 1.11.06.08.18.8 67825@yahoo.com ...
                [color=blue]
                > As I see it, when one considers which language is best for one's needs,
                > one considers a couple of things:
                >
                > 1) Does the language have the semantics I want.
                > 2) Does the language have the primitives I need.
                > 3) Can I *easily* build any missing or suboptimal primitives.
                >[/color]

                True.
                [color=blue]
                > One would assume that Fortran has the proper semantics for numerical
                > processing because it seems to have been wildly successful for a long
                > period of time.[/color]

                That, in my opinion, is wrong: Fortran is successful because it was there
                first!

                There exists a very large set of actively supported and proven libraries,
                NAG f.ex., which nobody will ever bother to port to another language just
                for the sake of it, and Fortran has been around for so long that it is well
                understood how best to optimise and compile Fortran code. It is easy enough
                to link with NAG if one needs to use it.
                [color=blue]
                > Fortran naturally comes with the primitives for numerical processing,
                > because numerical processing is its stated goal. ("FORmula TRANslation")[/color]

                ....or maybe the name sounded cool ;-)
                [color=blue]
                > Whether one uses Fortran, Python, or any other language, all primitives
                > are eventually implemented in either C or assembly. At some point or
                > another, we end up scraping bare metal and silicon to get our answers.[/color]

                Exactly - Fortran in itself does not do something that another language
                cannot do as well. It is just the case that Fortran is better understood
                when applied to numering processing than other languages because more
                "numerics" people used it than any other language.

                On DSP architectures, f.ex., I doubt that one would have better performance
                using Fortran in comparison with the C/C++ tools, DSP's usually ship with -
                because DSP's were "born" when C/C++ was hot.

                A lot of real, serious DSP work is done in Mathlab - thus skipping the issue
                of language choice and getting right onto getting the job done. This is good
                IMO.



                Comment

                • Lothar Scholz

                  #38
                  Re: Python is far from a top performer according to benchmark test...

                  Samuel Walters <swalters_usene t@yahoo.com> wrote in message news:<pan.2004. 01.11.06.08.18. 867825@yahoo.co m>...
                  [color=blue]
                  > I know very little about numeric processing, and even less about Fortran.
                  > It's true that my background is in mathematics, but in *pure* mathematics
                  > where pointer-based languages tend to be helpful, not hurtful.[/color]

                  Okay seems that you don't know a lot about compiler writing.

                  A C compiler only knows a little bit about the context so it must
                  always assume that a data inside a member can be referenced from
                  another place via an alias pointer.

                  Fortran does not have this problem so a lot of optimizations can be
                  done and values can be hold in registers for a much longer time,
                  resulting in much greater speed.

                  Remember that on supercomputers a 25% spped enhancement (which a good
                  fortran compiler is faster then C) can mean a few million dollars of
                  saved hardware costs. The coding time is not importing compared to the
                  running time. So real hard numerics are always done in Fortran.

                  GNU Fortran is a stupid project because it translates the Fortran code
                  to C.


                  Python for hardcore numerics, even with PyNumerics, is simply a very
                  bad solution.

                  Comment

                  • Peter Hansen

                    #39
                    Re: QOTW?

                    Ganesan R wrote:[color=blue]
                    >[color=green][color=darkred]
                    > >>>>> "Samuel" == Samuel Walters <swalters_usene t@yahoo.com> writes:[/color][/color]
                    >[color=green]
                    > > I/O is one of our strengths, because we understand that most programs are
                    > > not algorithmically bound, but rather I/O bound. I/O is a big
                    > > bottle-neck, so we should be damn good at it. The fastest assembly
                    > > program won't do much good if it's always waiting on the disk-drive.[/color]
                    >
                    > Actually, Python is much slower than Perl for I/O. See the thread titled
                    > "Python IO Performance?" in groups.google.c om for a thread started by me on
                    > this topic. I am a full time C programmer but do write occasional
                    > Python/Perl for professional/personal use.
                    >
                    > To answer the original question about how much percentage of time I spend
                    > optimizing my Python programs - probably never. However I did switch back to
                    > using Perl for my most of my text processing needs. For one program that was
                    > intended to lookup patterns in a gzipped word list, performance of the
                    > original python version was horribly slow. Instead of rewriting it in Perl,
                    > I simply opened a pipe to zgrep and did post processing in python. This
                    > turned out to be much faster - I don't remember how much faster, but I
                    > remember waiting for the output from the pure python version while the
                    > python+zgrep hybrid results were almost instantaneous.[/color]

                    I didn't consider this sort of thing in my poll, but I'd have to say you
                    actually *are* optimizing your Python programs, even if you did it by falling
                    back on another language...

                    -Peter

                    Comment

                    • Peter Hansen

                      #40
                      Re: Straw poll on Python performance (was Re: Python is far from a topperformer ...)

                      Paul Rubin wrote:[color=blue]
                      >
                      > Peter Hansen <peter@engcorp. com> writes:[color=green]
                      > > This is my "straw poll" question:
                      > >
                      > > Do you spend a "significan t" amount of time actually optimizing your
                      > > Python applications? (Significant is here defined as "more than five
                      > > percent of your time", which is for example two hours a week in a
                      > > 40-hour work week.)[/color]
                      >
                      > Yes, absolutely.
                      >[color=green]
                      > > Algorithmic improvements that you would make regardless of implementation
                      > > language do not qualify, and wasting time optimizing a script that you
                      > > run once a year so it takes ten seconds instead of fifteen also does not
                      > > qualify because you certainly didn't need to do it...[/color]
                      >
                      > Sometimes I'll take the time to implement a fancy algorithm in Python
                      > where in a faster language I could use brute force and still be fast
                      > enough. I'd count that as an optimization.[/color]

                      I would count it as optimization as well, which is why I qualified my
                      comment with "regardless of implementation language". Clearly in your
                      case that clause does not apply.

                      -Peter

                      Comment

                      • David M. Cooke

                        #41
                        Re: Python is far from a top performer according to benchmarktest.. .

                        At some point, llothar@web.de (Lothar Scholz) wrote:
                        [color=blue]
                        > Samuel Walters <swalters_usene t@yahoo.com> wrote in message news:<pan.2004. 01.11.06.08.18. 867825@yahoo.co m>...
                        >[color=green]
                        >> I know very little about numeric processing, and even less about Fortran.
                        >> It's true that my background is in mathematics, but in *pure* mathematics
                        >> where pointer-based languages tend to be helpful, not hurtful.[/color]
                        >
                        > Okay seems that you don't know a lot about compiler writing.
                        >
                        > A C compiler only knows a little bit about the context so it must
                        > always assume that a data inside a member can be referenced from
                        > another place via an alias pointer.
                        >
                        > Fortran does not have this problem so a lot of optimizations can be
                        > done and values can be hold in registers for a much longer time,
                        > resulting in much greater speed.
                        >
                        > Remember that on supercomputers a 25% spped enhancement (which a good
                        > fortran compiler is faster then C) can mean a few million dollars of
                        > saved hardware costs. The coding time is not importing compared to the
                        > running time. So real hard numerics are always done in Fortran.
                        >
                        > GNU Fortran is a stupid project because it translates the Fortran code
                        > to C.[/color]

                        Err, no. You're thinking of f2c. GNU Fortran uses the same backend as
                        the GNU C compiler, in that it translates to the same intermediate
                        language (sort of assembly language) on which optimizations are done.
                        But the C front end and the Fortran front end are separate.

                        The advantage of GNU Fortran is it's *portable*. It runs on everything
                        that GCC works on -- which is a lot. This makes a difference when
                        you're developing (like on my Apple iBook running Linux). And it looks
                        like the G95 project is humming along nicely.
                        [color=blue]
                        > Python for hardcore numerics, even with PyNumerics, is simply a very
                        > bad solution.[/color]

                        You're not limited to pure Python.

                        No one's saying you must use only C, or only Fortran, or only Python.
                        Use the best tool for the job. Python just has the advantage that
                        mixing C and Fortran into it is easy. Write your big, number-crunching
                        code as a Fortran routine, wrap it with f2py, then add a Python script
                        around it to run it. Presto, no fiddling with Fortran for reading in
                        input files, or output files (depending on your routine). You can even
                        write a GUI in Python if you wish. Or add a webserver.

                        --
                        |>|\/|<
                        /--------------------------------------------------------------------------\
                        |David M. Cooke
                        |cookedm(at)phy sics(dot)mcmast er(dot)ca

                        Comment

                        • Jeff Epler

                          #42
                          Re: Python is far from a top performer according to benchmarktest.. .

                          On Mon, Jan 12, 2004 at 05:42:22AM -0800, Lothar Scholz wrote:[color=blue]
                          > Python for hardcore numerics, even with PyNumerics, is simply a very
                          > bad solution.[/color]

                          I think that many of us are not in a situation where we have to make our
                          program run fast enough to save a million on a supercomputer, but where
                          we have to make our program run soon enough to save a few thousands or
                          maybe tens of thousands on programmer time.

                          ObLink: http://cens.ioc.ee/projects/f2py2e/

                          Jeff

                          Comment

                          • Lothar Scholz

                            #43
                            Re: Python is far from a top performer according to benchmark test...

                            cookedm+news@ph ysics.mcmaster. ca (David M. Cooke) wrote in message news:<qnk8ykdp3 a0.fsf@arbutus. physics.mcmaste r.ca>...[color=blue]
                            > At some point, llothar@web.de (Lothar Scholz) wrote:
                            >[color=green]
                            > > Samuel Walters <swalters_usene t@yahoo.com> wrote in message news:<pan.2004. 01.11.06.08.18. 867825@yahoo.co m>...
                            > >[color=darkred]
                            > >> I know very little about numeric processing, and even less about Fortran.
                            > >> It's true that my background is in mathematics, but in *pure* mathematics
                            > >> where pointer-based languages tend to be helpful, not hurtful.[/color]
                            > >
                            > > Okay seems that you don't know a lot about compiler writing.
                            > >
                            > > A C compiler only knows a little bit about the context so it must
                            > > always assume that a data inside a member can be referenced from
                            > > another place via an alias pointer.
                            > >
                            > > Fortran does not have this problem so a lot of optimizations can be
                            > > done and values can be hold in registers for a much longer time,
                            > > resulting in much greater speed.
                            > >
                            > > Remember that on supercomputers a 25% spped enhancement (which a good
                            > > fortran compiler is faster then C) can mean a few million dollars of
                            > > saved hardware costs. The coding time is not importing compared to the
                            > > running time. So real hard numerics are always done in Fortran.
                            > >
                            > > GNU Fortran is a stupid project because it translates the Fortran code
                            > > to C.[/color]
                            >
                            > Err, no. You're thinking of f2c. GNU Fortran uses the same backend as
                            > the GNU C compiler, in that it translates to the same intermediate
                            > language (sort of assembly language) on which optimizations are done.
                            > But the C front end and the Fortran front end are separate.
                            >[/color]

                            But the front end is, as far as i know, only responsible for syntax
                            analysis. All code generation like control flow analysis, register
                            allocation etc. is done on the intermediate 3 register language. And
                            the hints you could get from the fortran language are simply unused.

                            But i must say that i never used Fortran (when i studied physics) in
                            the last 15 years for any real programming. I only wanted to point out
                            that a lot of languages are by design faster then C. Fortran was one
                            of these. You can find articles on the web where the same is explained
                            for lisp and functional languages.

                            C and C++ is not a good compilation language when it comes to compiler
                            optimization.

                            Comment

                            • Robin Becker

                              #44
                              Re: Python is far from a top performer according to benchmark test...

                              In article <6ee58e07.04011 20542.5d79090d@ posting.google. com>, Lothar
                              Scholz <llothar@web.de > writes
                              .....[color=blue]
                              >
                              >Fortran does not have this problem so a lot of optimizations can be
                              >done and values can be hold in registers for a much longer time,
                              >resulting in much greater speed.
                              >[/color]

                              I'm not sure I agree with the above. Aliases could certainly occur in
                              fortran 77, I haven't used 90 so can't say for sure.[color=blue]
                              >Remember that on supercomputers a 25% spped enhancement (which a good
                              >fortran compiler is faster then C) can mean a few million dollars of
                              >saved hardware costs. The coding time is not importing compared to the
                              >running time. So real hard numerics are always done in Fortran.[/color]

                              --
                              Robin Becker

                              Comment

                              • Jacek Generowicz

                                #45
                                Re: Python is far from a top performer according to benchmark test...

                                michele.simiona to@poste.it (Michele Simionato) writes:
                                [color=blue]
                                > Jacek Generowicz <jacek.generowi cz@cern.ch> wrote in message news:<tyf65fgdm 81.fsf@pcepsft0 01.cern.ch>...[color=green]
                                > > Go on, raise your hand if you thought that "Lisp" is a slow,
                                > > interperted functional langugage.[/color]
                                >
                                > Never thought so.[/color]

                                Michele,

                                My post was not aimed at you specifically. It was aimed a lurkers who
                                might infer that Lisp is only used in AI (or whatever), or who might
                                have some unfounded assumptions about Lisp which would be re-inforced
                                by your post.

                                I was quite sure that my post would not be telling _you_ much you
                                didn't already know.

                                Comment

                                Working...