1
$\begingroup$

I would like to write the most optimized program for array manipulation in Fortran (e.g. matrix multiplication of large matrices, squaring large matrices, etc.)

So, using the fortran compilers on the market today (e.g. gfortran), how does F77 measure up against F90/95 (or F03)? Is there a particular compiler I should use to optimize speed with a certain version of Fortran?

Furthermore, is there a difference in how I code these Fortran programs to optimize speed that is based distinctly in the version of Fortran used? Or is this simply changing the extension name (e.g. .f90 to .f70) and the program will run faster?

$\endgroup$
5
  • $\begingroup$ Simpler languages are easier to optimize. Fortran 77 is the simplest Fortran. However, your Fortran compiler will not care about the suffix, but only the syntax. $\endgroup$ Jun 14, 2015 at 2:59
  • $\begingroup$ @Jeff So, if I write Fortran with F77 syntax, gfortran will compile it at a higher performance than F90/F95? $\endgroup$ Jun 14, 2015 at 3:13
  • $\begingroup$ That's not what I said. If you specify what you want to do precisely, I'll be able to make a proper evaluation. $\endgroup$ Jun 14, 2015 at 3:29
  • 1
    $\begingroup$ Use MATMUL to multiply to matrices. My question boils down to whether there's an inherent difference in performance between the two languages. I realize that with F03, your average user could create a good deal of overhead from pointer aliasing. But I have seen charts where Fortran77 is claimed to be "fastest"---I have no idea what this is supposed to mean. $\endgroup$ Jun 14, 2015 at 3:34
  • $\begingroup$ The performance of the MATMUL intrinsic is invariant to language except in 77, where it is not supported. $\endgroup$ Jun 14, 2015 at 3:40

1 Answer 1

7
$\begingroup$

There is almost no good reason to write your own dense matrix manipulation routines until you have compared to fast libraries (MKL, FLAME, MAGMA, etc). Writing these libraries is challenging work that depends highly on the target architecture and requires deeper concepts than naive nested do loops. There's a whole literature on the subject that you should engage with, and you should note that basically none of the best-performing libraries in this space are written in Fortran (of any flavor) these days. Most of them are C/C++ plus targeted intrinsics or assembly code. Compilers just aren't magic enough to achieve the full performance of any chips.

$\endgroup$
7
  • $\begingroup$ So, you recommend abandoning Fortran and using libraries (like MKL, FLAME, MAGMA, etc.) in C/C++ code? $\endgroup$ Jun 13, 2015 at 15:51
  • 2
    $\begingroup$ You can call many of the libraries from C/C++ or Fortran since they have interfaces in both languages. I'm not suggesting abandoning Fortran necessarily, but I am suggesting abandoning the idea of writing your own dense matrix routines unless the library is too slow for your needs or doesn't have the function you want. Take advantage of all the hard work that others have done so that you can get to your real goals quicker. $\endgroup$
    – Bill Barth
    Jun 13, 2015 at 16:00
  • $\begingroup$ That's reasonable. Well, there is also a simpler question here than writing my own dense matrix routines (though, I would have probably started doing that). I'm interested in how the various standards of Fortran (77/90/95/03) perform against one another AND against various compilers out today (some of which I may not know). Let's say a simple MATMUL operation: how do they perform against each other? $\endgroup$ Jun 13, 2015 at 16:04
  • $\begingroup$ I appreciate the library references though! $\endgroup$ Jun 13, 2015 at 16:06
  • $\begingroup$ What's the best free compiler for high performance? Any recommendations? $\endgroup$ Jun 13, 2015 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.