太仓钟点房:Linux平台上运行Fortran代码

来源:百度文库 编辑:中财网 时间:2024/04/29 21:53:31

copy from:http://www.nikhef.nl/~templon/fortran.html


Information about running Fortran codes under Linux


I am interested in any information people have that could be useful here; please send email to the address at the bottom of the page. As I am no longer actively developing in Fortran, I mostly add info here when someone else tells me it's missing. So please let me know if you miss something here!

Recent (within past year) Additions


18 October 2005 -- Corrected broken link to SciTools Page (thanks to Peter Richards of PJR Consulting for the heads-up). 
03 February 2005 -- More G95/GFortran info (thanks to Tobias Schlüter for this information).
Fortran is the language of the past, and one of the languages of the present, as far as physics is concerned. Hence this page. This page system was originally oriented towards the previous version (F77) of Fortran, but it now contains (as far as I know) all information on F90/F95 for Linux as well.

These pages are almost entirely specific to Linux, with the exception of the paragraph you are reading right now. For general Fortran information, Tomasz Plewa's page, The Fortran Library, and The Fortran Market are good places to start. Check out one of the following links (free book-size documents in postscript format) if you need to learn Fortran 77 or Fortran 90. Arnaud deSitter maintains a page onFortran Compiler Tips and Tricks. Finally, here are some tips on what constitutes good Fortran coding style.


One more note: I run Linux on an x86 box, thus my experience comes solely from experience with this platform. All comments below apply to the x86 platforms unless specifically noted.

Fortran Compilers for Linux

There are several choices. Here is a list. Please contact me if you see something inaccurate or know of something that is missing. Click on the compiler name for more detailed information.

Commercial Compilers

The information below is mostly about the compilers' capabilities. Polyhedron Software has posted a table making performance comparisons between many linux compilers. Not all the ones listed below are covered on their page, but they do have many different benchmarks and thus give a better idea of speed differences in a wide range of applications.

The theory group at NIKHEF has done some comparisons as well, you can see their results at their fortran performace page.

  • Absoft Fortran for Linux --- This is the compiler I use. Native Fortran 77 and Fortran-90 compilers are available. Both the Fortran-77 and Fortran-90 products support most of the VAX/VMS, MIL-STD, and other common extensions. Code produced by this compiler on Linux/Intel is on average faster than all other compilers I've tested. Absoft has released a version for Linux/PowerPC! Educational discount, site license available. Absoft F77 allows you to link in directly libraries compiled with g77, which is a huge advantage for some people. Absoft's F90 front-end is based on Cray's compiler technology. Click here for more detailed information.
  • Lahey LF95 Express --- This compiler runs on Intel Linux platforms. Performance is near the top of the list for x86/Linux compilers (see the Polyhedron Benchmarks for more information), comparable to Absoft's compiler. The compiler only differs from Fujitsu's (see below) by user-interface and tool support, the underlying code generators and parsers are apparently identical. I gave an early version of this compiler a fairly thorough test, and it is a good product. I don't know how their normal tech support is, but I got answers to all my questions fairly quickly and in detail. Their compiler is a good deal (pricewise) compared to many of the others, on the other hand the other vendors have more extensive tool support (hooks to parallel libraries, etc.) If you don't need all these tools, you probably can't go wrong with this product. Anyone having more experience is welcome to contribute more info.

    If you have this product and are having trouble running it on a Suse Linux system, check Lahey's web site for a patch.

  • Intel F95 for Linux --- This compiler is in production as of this writing (September 2001). A free license is available for noncommercial users. I don't have any detailed information on this product, but the NIKHEF Theory Group has seen that it's the only Linux compiler that appears to have effective optimization for the Pentium IV machines. Check out Intel's Site. In-depth evaluations are appreciated!
  • Portland Group Fortran Compilers --- PG has released High-Performance Fortran and Fortran-77 compiler products. The HPF Release now includes a native F90 compiler. The Native Fortran 77 compiler is very similar to Absoft's. I think this product is quite comparable in quality to Absoft's offering, and you probably couldn't go wrong with either one. Follow this linkto read comments about this compiler sent by other users. Also, Portland Group offers a free fifteen-day evaluation of their compilers (pick it up by ftp, and get a license key via email.) Please visit their web site and register there, or contact jeannie@pgroup.com .
  • Fujitsu Fortran Compiler --- This product lives on since it forms the guts of Lahey's system. A newsgroup posting by Fujitsu claims that development of this compiler continues. However, Fujitsu no longer sells this compiler directly.
  • Compaq (prev. DEC) Fortran --- Many of us remember DEC Fortran being the One True Fortran. Wasn't really true, but it was a great compiler system, and a version of that system has now been released for the Linux OS on Alpha systems. This is good news for Linux/Alpha people, since there were not many compilers from which to choose on that platform (and no native F90 compiler at all!)
  • NAGWare f95 --- F95-to-C translator, although NAG would prefer F95-to-C "compiler". Inexpensive. I know of some people who really swear by this compiler. I tried the beta version and was quite pleased with it.
  • NA FortranPlus --- Native Fortran 95 compiler. In principle therefore also an F77 compiler, but a report on comp.lang.fortran suggests that the F77 support is incomplete. Our group has no experience with this compiler. I have yet to hear any positive reports about the Linux version, but Alan Miller has contributed some notes on the Windows version which are mostly positive. Please consider submitting a review if you are familiar with this compiler.
  • Microway NDP Fortran --- Would have been the first native Fortran-77 compiler for Linux/x86. Product development was stopped before compiler was fully working. Don't let anyone sell you a copy.
  • SNI F77 --- This compiler was produced by Siemens Nixdorf in Germany. It appears to be a full F77 native compiler for Intel/Linux platforms. As of March 2001 I could find no information on this compiler and no vendors selling it; it appears to have been discontinued. Please contact me if you have different information. Erik Schnetter has contributed his impressionsof the SNI compiler.

Free Compilers

  • GCC --- GCC is the GNU Compiler Collection. The project unifies the C, C++, and Fortran-77 compilers (gcc, g++, and g77), and attempts to make the system close to the cutting edge in terms of compiler optimizations available.

    there is an older page about Gnu Fortran 77 that has been recommended. I have used G77 to compile Garfield which is a simulation code containing tens of thousands of lines of source; it compiled and ran correctly with no problems whatsoever.

  • There is a page dedicated to specially-optimized versions of gnu compilers for various architectures.
  • Gnu and Fortran90/95: The situation here is quite confusing and seems to change frequently. See the following for information:
    • Gfortran. This is the Fortran95 compiler that is part of the Gnu Compiler Collection gcc.
    • G95. A related Fortran95 project, but not the same project.
    • some information on the relationship between the two projects. I should point out that this information seems to represent only one of two points of view on the relationship. I know too little about the projects to be able to judge if it's accurate.
  • OpenWatcom --- Sybase Inc. has decided to make the Watcom compiler line (C/C++/Fortran) open source. I am not sure at this point that the compilers actually run under Linux, but the sources are all there, and the announcement on comp.os.linux.announce stated that the project team was able to port from Dec Alpha to NT on Alpha in about a week, so Linux support should be coming very soon if it isn't already there. Any new information is welcome.
  • PSR VAST/f90 --- This product was similar to f2c in that it translated f90 code into f77 code, and used g77 to compile this translated code into an executable image. It is no longer available. From their web site:
    "Veridian Personal Linux f90 VersionThis product is no longer being offered.For alternatives, see Absoft Fortran or the F compiler, and you might wantto keep an eye on the g95 project.
  • ADAPTOR --- A "high performance fortran compilation system" provided by the folks at GMD and SCAI in Germany. It appears that this tool translates HPF (High-Performance Fortran) code into either F77 or F90 code. That code is linked in with a library that performs distributed computation via PVM or MPI. I don't do HPF, but if anyone who does wishes to provide a review of this tool I would be happy to include it.
  • pg77 --- A special version of the g77 compiler which has been optimized to produce code for Pentium machines.
  • f2c (+ gcc) --- This was previously the "standard" Linux Fortran system. Not native - f2c translates to C, and true compilation handled by gcc. Thus this "compiler" should run on any of the various Linux hardware platforms. Very stable and well-debugged. Handles almost no extensions to the ANSI F77 standard. Good performance, slow compilation, excellent "paranoia" results (certain compiler options are required ... see the link above for more info). Debugging using gdb is difficult, but is supported through an add-on package (see the f2c-stabs entry below.) Available free of charge by ftp.
  • Imagine1 F Compiler --- F is a language which is a subset of Fortran 95, and the latest release contains some features anticipated for Fortran-200X. It is not Fortran 77 compatible, but Jos Bergervoet reports that one may link in object files compiled with g77. So you can't compile F77 code, but you can still use your old libraries. If you are beginning a new project and thus do not have to be F77 or VAX compatible, and would like to use both Fortran and modern language constructs, you may be interested in this. I have no personal experience with it. This is the home page for Imagine, and here is the Linux binary package.
  • HPFFE --- This is a front-end code for HPF 2.0 (which includes all of Fortran-90). I don't think it actually makes executables. I have contacted the authors for more information. Any reviews or more information is welcome.

Comparisons between compilers, benchmarks

More information to come here when I find it. Contributions are welcome. 
Performance comparison: Absoft/Intel/Lahey/Portland -- John Wolter from NASA sent a note about this page. 
Porting Experiences for Six Different Compilers --- Barbara Robson has sent in comments about linux fortran compilers based on her project to port an F95 code. Compilers covered are PGI, NAG, Absoft, Lahey, Fujitsu, and NA Software. 
Polyhedron Benchmarks --- Polyhedron maintains a very thorough table of benchmarks for various Fortran compilers, interesting for anyone desiring the utmost in performance. 
Phoenix vs. the Linux Compilers --- Peter Hauschildt has submitted a detailed comparison of the performance of the Phoenix code when compiled by Absoft, NAG, and PGI compilers on x86 Linux boxes. Phoenix is a VERY LARGE stellar atmospherics code. 
My personal silly benchmark 
I have a very small code which computes bremsstrahlung energy-loss distributions for high-energy electrons. Go here to pick up a package containing this benchmark and some instructions. The program almost certainly fits in cache. Go here to see results of running this benchmark on my machine, and others, using code from various compilers.

Tips and Tricks

Suggestions and info to help you get the most out of your Fortran+Linux system.
  • The Alignment Info Page talks about the importance of data alignment in getting the maximum execution speed out of your code. This is particularly important for Pentium and Pentium-Pro machines, where you can slow down (or speed up) your code by something like 50 percent by alignment effects.

Linux-Specific Fortran Tools

These packages help use Fortran on Linux systems more effectively and/or more easily.

Compiler driver scripts

These scripts allow you to run f2c and gcc together and with the correct arguments, without having to issue two commands. You issue one command, which looks like a typical Fortran compiler program. It manages the separate phases of f2c and gcc compilation. Slackware comes standard with a script called f77 (which I do not recommend), and RedHat comes standard with fort77 (see below.)
  • f77/reorder --- Wolfgang Wander at DESY has an alternate version of the f77 script (the "standard" Linux f2c+gcc driver.) His version of f77 fixes the bugs of the original (like not working correctly in Makefiles). "reorder" prepares your code for f2c translation by fixing some common standard-violating coding practices which f2c will not accept. "reorder" has recently been upgraded so that the emitted debugger information is in sync with the original source file. You can find this package at his f77 Problem Page.
  • fort77 --- fort77 is another f77 replacement. It works very well in Makefiles, and its compiler-option flags more closely resemble those of typical Unix f77 compilers than do those of the Slackware f77 script. Thus, Makefiles from other Unix systems will probably work with it (and possibly not with f77.) It also uses gcc flags which are different (better?) than those of f77 when you turn on optimization.
  • yaf77 --- Yet Another f77. I don't have any information on this script itself. Some libraries are included with this package that some net people have found helpful in porting codes from other systems to Linux.
fort77 and yaf77 can be found at any Sunsite mirror, directory devel/lang/fortran.

Debugger Support

NAGWare F95 code can be directly debugged with gdb, and Absoft's compiler ships with its own fully symbolic source-level debugger. Users of one of the various f2c+gcc packages can use the f2c-stabs package, which is an Emacs interface to gdb. It has its own Fortran parser, and knows how to translate the names used in the Fortran source so that gdb can find them. Look here for a package description from the author (Harvey J. Stein, ).

Other Fortran Tools Available for Linux

Forcheck --- Forcheck is a Fortran 77 and Fortran 90 parser which verifies the syntax of program units and the consistency of the entire program. It has been developed by Leiden University in the Netherlands, but it is a commercial product. The following information comes from the Forcheck Group at Leiden: 
"It warns for all kinds of anomalies such as unassigned or unreferenced items. It produces listings and cross-references of all syntax items. For the global program it provides a call-tree, a subprogram index, and cross-references of procedures, i/o, include files, common blocks and even common-block elements. Forcheck supports most Fortran language extensions of many compilers and can be tuned easily by the user. It can be used as a software engineering tool for small up to very large projects." 
I have a copy and am generally quite pleased with it. I am especially happy that it supports F90 and DEC-Fortran STRUCTUREs, so I can analyze much more code than I could with FTNCHEK. There are still a couple of things for which I like FTNCHEK better, for example FTNCHEK has more user-friendly global analysis (it will tell you the line number and type of interface mismatches which reside in different files, something FORCHECK cannot do). Forcheck has a web page (click here).

Foresys --- a very nice static analysis tool from Simulog in France. Does many of the same things that FORCHECK does. A nice plus is that code metrics are included; their value may be debated, but they are included if you want them. Also has a GUI; this is the only linux static analysis tool I have seen (for fortran that is) that has a GUI. Very nice, can easily take you with one click to the definition, or source code, for a variable or function on which you click in a source window. A trial version is available online.

Source Navigator --- a wonderful tool from Cygnus Solutions. Contains an integrated editor, cross-reference tool, "class browser" (which treats DEC-Fortran STRUCTUREs as "classes"), a graphical front-end to gprof, and more. It is now open-source; check it out at RedHat. Also check out a support and extensions page as well as the FAQ.

FTNCHEK --- FTNCHEK is a Fortran-77 parser which will make a nice listing file, construct a subroutine call tree (a sort of flow diagram for your program), and list all variables with their types. It also can do extensive syntax checking, and detects many classes of errors in ANSI fortran-77 code. Most F77 compilers will do none of this for you (except for find the coding errors, if they are severe enough.) The FTNCHEK listing file can be made to look very much like VAX Fortran's FOR/LIS output. Pick it up here.

NAGWare Tools --- Software from NAG for transformation and analysis of Fortran-77 and Fortran-95 code. More information here.

The Fortran Programmer's Workshop This tool can be thought of as an interactive "make" facility. It has methods for organizing source code into libraries, building various programs from this code, running programs, and other code-maintenance facilities. There is a command-line version as well as a new graphical version which uses Tcl/Tk. You can visit the Fortran Programmer's Workshop Web Page for more information. I have no experience with this tool, as I am a diehard make fan.

PlusFORT --- PlusFORT is a very sophisticated package which can analyze, beautify, and improve your Fortran codes. The package is quite a bit more difficult to use than is FTNCHEK (see above), but can do much more. It claims to handle all VAX/VMS extensions. I found that it will accept things such as STRUCTUREs, but does not do much with them other than parse them (sometimes incorrectly computing the size.) A free subset of the complete version is available for Linux platforms. Visit the PlusFORT Page for more information.

SNiFF+ --- A "source code engineering tool" which I know is in use at CERN, has now been released for Linux. Note that the version that you can download only works on glibc2.1 systems (like RedHat 6.0). I have not yet tried it, but here is what they sent me:

Description:SNiFF+ is the premier Source Code Engineering tool. SNiFF+ provides anintegrated collection of source code analysis, browsing, navigation,comprehension, editing, build, and configuration management tools for C,C++, FORTRAN, Java, and CORBA IDL developers. With support for Windows andall major UNIX platforms, SNiFF+ enables developers in cross-platform andmulti-language environments to utilize the same tool set and GUI.
Visit their web site to download an evaluation copy and find more information.

Understand --- Understand is a program-analysis tool for Fortran codes. You run this program with your source files as input, and it constructs a database which can be visually browsed. The tool appears to be best suited for "understanding" your program; clicking on any entity (under X windows) allows you to see a diagram of, for example, what routines call a particular subroutine, and what subroutines are called by it; find all the places a particular variable is used, where and how it is defined, etc. It also creates tables of program statistics which can be browsed under a WWW browser. A demo version can be downloaded from their web site.

asa --- This is an output filter for your Fortran output files. It looks at the Hollerith carriage-control strings in the first character position in each line (those pesky "0", "1", and "+" characters) and converts them into control codes understood by programs like "more" and by Unix printer software. This code should also work on other Unix systems.

Interactive Software Services Ltd distributes INTERACTER, a "multi-platform Fortran user-interface and graphics library for Unix, VMS, Windows, and DOS." They've had a Linux version available since September 1995. It supports the Fujitsu compiler, f2c and g77; the g77 support applies to Intel, Alpha, and SPARC platforms (you apparently do not need to purchase a separate license for each platform). The Linux version is priced lower than the other Unix versions. This information comes directly from ISS Ltd and I cannot confirm or deny it, as I have no direct experience with the product.

Other Linux Fortran Sites

  • Linux Fortran Article --- Steven Hughes' article about Fortran Tools and Linux is available online.
  • The Queen Mary and Westfield College's High-Energy Physics Group has a page about High Energy Physics and PC's; it has links to an archive of newsgroup postings related to Fortran on Linux, and to an archive of Fortran-related software for Linux.
  • Wolfgang Wander's f77 Problem Page, already mentioned.

See either my local page  for more Linux information. 
Or, go to my home page for other non-linux information.