Re: [Numpy-discussion] gfortran/g77+f2py vs gcc+Cython speed comparison
On Dec 23, 2007 12:57 PM, Ondrej Certik [EMAIL PROTECTED] wrote: Hi, I needed to write 2D Ising model simulation into my school and I decided to compare the two possible solutions how to do it, so I of course wrote it in Python, then rewrote it in Fortran + f2py, and also Cython. What is better? Read below. :) But for the impatient, I am going to use Cython, reasons below. I recently tried a similar experiment with the opposite result :) So it's a lot slower. This is very surprising indeed. I have just tried to run your code but can't get the fortran generated module to work. But I wonder how you got such a difference, because in my recent comparisons I generally got about 0-2 % faster (i.e. negligible) results with gfortran compared to gcc and a much bigger difference (in favour of fortran) with the Intel compilers. In fact for simple tests gcc and gfortran produce almost identical assembler code (use -s switch to check). For the more mature compilers (i.e. Intel) fortran is faster as it is inherently easier to optimize (easier data dependency analysis and vectorisation). The main reason I can think of is the gfortran version you are using and the optimisation switches. Any version 4.0.x is seriously suboptimal (first released version). Big gains were made from 4.0-4.1 and 4.1-4.2. I would suggest 4.2 as the minimum version to use. The development version 4.3 is faster still (also for gcc) because of recent vectorisation work. When using g77 compiler instead of gfortran, I get a speed up 4.8 times. The difference between g77 and gfortran with version 4.3 is now very small, plus gfortran is going to benefit from all the new vectorisation and optimisation work in gcc. It will not be long before it over takes for good. In addition you can use modern fortran 95/2003 code which makes life much easier! In in addition to all that it is very actively maintained and destined to be the default compiler on all linux systems as it is bundled with gcc. So, what do you think of that? If you are using a modern gfortran version then I suggest you have found a bug, in which case I would take it to the gfortran mailing list. If not, then try version 4.3 which can be downloaded from the gfortran wiki: gcc.gnu.org/wiki/GFortran In the mean time, after Christmas, I'll try and get your code working and see for myself the difference. Seasons greetings, John -- Telephone: (+44) (0) 7739 105209 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] gfortran/g77+f2py vs gcc+Cython speed comparison
Hi John, thanks for the response. This is very surprising indeed. I have just tried to run your code but can't get the fortran generated module to work. But I wonder how you Yes, I really didn't try to make it robust, I just made it work for me on Debian unstable. got such a difference, because in my recent comparisons I generally got about 0-2 % faster (i.e. negligible) results with gfortran compared to gcc and a much bigger difference (in favour of fortran) with the Intel compilers. In fact for simple tests gcc and gfortran produce almost identical assembler code (use -s switch to check). For the more mature compilers (i.e. Intel) fortran is faster as it is inherently easier to optimize (easier data dependency analysis and vectorisation). The main reason I can think of is the gfortran version you are using and the optimisation switches. Any version 4.0.x is seriously suboptimal (first released version). Big gains were made from 4.0-4.1 and 4.1-4.2. I would suggest 4.2 as the minimum version to use. The development version 4.3 is faster still (also for gcc) because of recent vectorisation work. I use: $ gfortran --version GNU Fortran (GCC) 4.2.3 20071123 (prerelease) (Debian 4.2.2-4) Copyright (C) 2007 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING $ When using g77 compiler instead of gfortran, I get a speed up 4.8 times. The difference between g77 and gfortran with version 4.3 is now very small, plus gfortran is going to benefit from all the new vectorisation and optimisation work in gcc. It will not be long before it over takes for good. In addition you can use modern fortran 95/2003 code which makes life much easier! In in addition to all that it is very actively maintained and destined to be the default compiler on all linux systems as it is bundled with gcc. Yes, I also think gfortran is the way to go, since g77 is dead upstream. But currently, the g77 still gives quite a lot faster code than gfortran, but I hope it will change. So, what do you think of that? If you are using a modern gfortran version then I suggest you have found a bug, in which case I would take it to the gfortran mailing list. If not, then try version 4.3 which can be downloaded from the gfortran wiki: gcc.gnu.org/wiki/GFortran In the mean time, after Christmas, I'll try and get your code working and see for myself the difference. So your suggestion is to prepare a clean fortran example, that, when compiled with gfortran, runs a lot slower, than if compiled with g77? Yep, I can do that. So what is your personal opinion about fortran vs C for scientific computing? From the social point of view, I much prefer C, since a lot more people know it, but as you say, the good fortran compilers are a lot better, than the C compilers. So I don't know. Probably depends on the project and a code I want to reuse. Ondrej ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] gfortran/g77+f2py vs gcc+Cython speed comparison
On Dec 24, 2007 1:29 PM, Ondrej Certik [EMAIL PROTECTED] wrote: Hi John, When using g77 compiler instead of gfortran, I get a speed up 4.8 times. The difference between g77 and gfortran with version 4.3 is now very small, plus gfortran is going to benefit from all the new vectorisation and optimisation work in gcc. It will not be long before it over takes for good. In addition you can use modern fortran 95/2003 code which makes life much easier! In in addition to all that it is very actively maintained and destined to be the default compiler on all linux systems as it is bundled with gcc. Yes, I also think gfortran is the way to go, since g77 is dead upstream. But currently, the g77 still gives quite a lot faster code than gfortran, but I hope it will change. Yes, I just proved myself wrong (not a rare occurrence...), on my slow laptop: With gcc (4.3.0 20071223 (experimental)): real0m3.272s user0m3.120s sys 0m0.044s With gfortran (4.3.0 20071223 (experimental)): real0m4.294s user0m3.976s sys 0m0.020s With g77 (3.4.6): real0m2.928s user0m2.812s sys 0m0.044s If g77=1.0 then gcc=1.27 and gfortran=1.41 (far from 4.8 times though!!) This is in contrast to my recent experiments between gfortran and gcc, though that code used f95 stuff extensively so was never tested against g77. So your suggestion is to prepare a clean fortran example, that, when compiled with gfortran, runs a lot slower, than if compiled with g77? Yep, I can do that. The most interesting will be to compile with g77 and gfortran with the options to spit out the generated assembler code, then we can see exactly where the difference is. I'll dig back in the gfortran mailing lists and see previous conclusions of the g77 vs gfortran debate (which occur often). You may just be exercising a particularly unoptimized part of gfortran. So what is your personal opinion about fortran vs C for scientific computing? From the social point of view, I much prefer C, since a lot more people know it, but as you say, the good fortran compilers are a lot better, than the C compilers. So I don't know. Probably depends on the project and a code I want to reuse. If you haven't guessed I'm pro fortran! My path was C++ - Matlab - Scipy (which I still use for prototyping and short calculations) - fortran for big simulations. Of course, the wonderful f2py helps combining the last two steps! The turning point came when I discovered modern object orientated fortran features and particularly the array intrinsics/operations in fortran 95/2003. I realised that I could code my stuff in almost as few lines as Matlab and Scipy and also have the fastest execution (if using commercial compilers). My hope (slightly set back today) is that gfortran will mature into being as fast/faster than gcc/g77 for most code. In that case, with gcc on every linux system, then the social opposition should disappear. Though this still will not help against people who think f77 is fortran, ignoring the last 30 years of development. Anyway, I really must go home now... John ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion