HMC Homepage      CS Home

Fortran on Turing

What Compilers are available

Many different compilers exist for the Fortran computer language. The two main flavors of Fortran are Fortran 77 and Fortran 90. Each of these has separate compilers and the user must decide which flavor and compiler to use.

Turing has three different Fortran compilers available. For Fortran 77, Turing has the Portland Group's pghpf (High Performance Fortran Compiler), the GNU compiler g77, APOGEE's Fortran 77 compiler. To compile code for Fortran 90, Turing has APOGEE's Fortran 90 compiler.

Like most other languages, Fortran source code is ASCII text that is compiled into executable machine code. Use your favorite text editor to put the text into a file with the appropriate file extension. Fortran is picky about file extensions because it uses these to decide which type of code it is trying to compile. In general, use the extensions listed here for each different compiler. This will keep you file naming scheme consistent and later on you will know which compiler the code is written for.

Compiling with pghpf (Portland Group's Compiler)

The command to compile Fortran code using the Portland Group's compiler is pghpf.
  • You can compile the Fortran program hello.hpf using the default compiler options with the following command line:

    % pghpf hello.hpf

  • By default, the executable output is placed in the file a.out. You can use the -o option to specify the output file.

    % pghpf -o hello hello.hpf

  • There are many more command line options and switches than are listed here. For a full list, look at the man page for pghpf with the command:

    % man pghpf

The Portland Group's compiler uses the extension .hpf to designate its source files. The compiler looks explicitly for this extension so it should be used.

GNU Compilers

The command to invoke the GNU compiler for Fortran 70 is g77. The basic commands to compile Fortran code are the same for GNU Fortran and the Portland groups compiler.
  • Once again, the simplest command line is:
    % g77 hello.for
  • By default, the executable output is placed in the file a.out. The -o option specifies the output file for the executable program:

    % g77 -o hello hello.for

  • The standard file extension for GNU Fortran is .for.

APOGEE Compilers

Turing has APOGEE's Fortran 90 compiler and Fortran 77 compiler. The programs are called apf90 and apf77, respectively. The basic commands are the same as those for the Portland Compiler and the GNU compiler. Here is a quick summary:
  • The simplest command line is:

    % apf90 hello.for

  • By default, the executable output is placed in the file a.out. You can use the -o option to specify the output file.

    % apf90 -o hello hello.for

  • The commands are the same for the Fortran 77 compiler. Just substitute apf77 for apf90 on the command line.
GNU Fortran uses file extensions to tell what type of files it is looking at. If you use .for for GNU Fortran program source code everything should work fine.

Running your Program

  • To run the program you just created, type

    % ./hello

    or whatever filename you told the compiler to produce, with a ./ attached to the front. This tells the command shell that the executable is in the current directory. Remember, if you didn't use the -o switch, your file will be called a.out.

An important thing to note when using all of these compilers is that the actual program must be included in your path if you want to just type the name of the program on the command line. If you get an error message saying "Command not found" then the program most likely exists on Turing but isn't included in your path. If you type "whereis apf77" UNIX will give you the location of the program and then you can type the full pathname to run it.

Other resources

This page is not the only resource on the compilers. Try the man pages for information on compiler specific switches and other interesting facts. Below are a few good manuals found on the web that I used to write this qref. They contain much more in depth information about using Fortran.

The Portland Group maintains an excellent web site with a online manual. This manual covers everything a person every wanted to know about Fortran and much more. The manual is available at

http://www.pgroup.com/hpf_docs/pghpf_ug/hpfug03.htm

The man pages available with UNIX list all of the switches and options available for each compiler. These are a good reference for debugging commands and other switches.

When in doubt, ask someone. Some of the staff members know Fortran and can probably help you.


Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Tuesday, 22-May-2001 16:25:37 PDT