Recently I was given the job of cleaning up and modifying a CFD code for my undergrad research project. I thought this would be the perfect opportunity to compare compilers. As you can see from the previous post, I'm interested in how fast open-source software is compared to commercial software.
I obviously can't post the code as it is property of OSU, but I can say that it is more scientifically oriented than anything else. That is to say that it is all number-crunching and nothing really computer-sciency. The code is nothing but simple mathematical operations, logical statements, and file I/O. Plus, it's FORTRAN...so it has to be simple.
Anyway, I put GNU Fortran 4.4 (gfortran) and Intel Fortran Composer XE 2011 (ifort) on an old laptop running 32-bit Linux. The laptop has a single-core Intel Pentium M processor running at 1.7 GHz. I ran each version a few times and measured the times using the time command.
Here are the results (using the standard -O2 setting):
gfortran: 5m56s = 356 seconds
ifort: 4m17s = 257 seconds
It's no surprise that Intel's compiler would produce faster code for an Intel processor. The speedup is 356/257 = 1.39x. This lines up with the figures shown on Intel's site: http://software.intel.com/en-us/articles/intel-composer-xe/.
Update 3/27/11: I retried with gfortran 4.5 and it shaved off 27 seconds (5m39s), resulting in a modified speedup of 1.32.
Update 3/31/11: I retried using the -O3 flag for gfortran and the -fast flag for ifort (highest optimization settings for each compiler), resulting in times of 5m16 and 4m9, respectively. This gives a speedup of 1.27.
Conclusion: It's safe to say that for Fortran, the Intel compiler is approximately 20-40% faster.
Subscribe to:
Post Comments (Atom)
Completely off-topic, but important nonetheless:
ReplyDeleteifort is worlds more versatile than gfortran. This CFD code is not my own work and was kind of beat with a stick until it worked. There are quite a few errors in the code and it's not exactly efficient. ifort was mostly happy with it as it is, but gfortran required me to go through and fix 5 or 6 of these errors and was still slower.
Here's a nice comparison of the various different Fortran compilers, for reference: http://www.polyhedron.com/compare0html
ReplyDeleteTheir results match mine for the most part, i.e. ifort is nominally 30% faster than gcc.
Could you try again with the following gfortran options:
ReplyDelete-O3 -ffast-math -march=native -funroll-loops -fno-protect-parens -flto
With "-fno-protect-parens" one violates Fortran's parenthesis protection (which ifort does by default; cf. -assume (no)protect_parens). With -march=native one optimizes for the system on which one compiles (ifort: -xHost) and with -flto one does a link-time optimization (cross-file optimization; ifort: -ipo).
Intel's "-fast" is approximately identical to "-O3 -ffast-math -march=native -flto"
With newer gfortran's, I would additionally use -fstack-arrays (matches ifort's default setting - and the reason ifort is that stack hungry).
Side note: I tried gfortran 4.7 and ifort 11.1 on a Core2 with the Polyhedron benchmark. Result: 9.52s with "gfortran -march=native -ffast-math -funroll-loops -O3 -finline-limit=600 -fwhole-program -fstack-arrays -flto" and 9.86s with "ifort -fast" (implies: "-ipo -O3 -no-prec-div -static -xHost"). Thus, I get a speedup of 0.97x if I use the Intel compiler.
Probably more interestingly are the differences between the different benchmarks: For "gas_dyn" ifort only needs 56% of the time of gfortran while for "induct" it needs 65% longer than gfortran.
Great/informative comment.
ReplyDeleteI'm not so versed in all the different command-line options. I wonder if GCC has an equivalent of -fast.