Wayne State University

AIM HIGHER

Wayne State University

High Performance Computing Services

Fortran

HOW TO COMPILE SOMETHING WITH FORTRAN

Follow these steps to compile a program with a Fortran compiler.
Log on to the grid.

Start an interactive job. Type: qsub -I

Input: qsub -I

This puts you on a compute node for you to do compiling on. Never run jobs or do compiling on the head node.

Job is ready. Running on vii3 in this example.

Type:
nano hello.f

  Input: nano hello.f
Type the following lines into the editor:
      print *, "Hello World"
      end`

(The spaces may be important, depending upon the compiler. There are six spaces (a tab) before each line.)

Text in nano editor

Save the file and exit (Press Ctrl + X, then Y for Yes and keep the name hello.f)

Choose a Fortran compiler (A list of Fortran compilers can be found here). In this example we will use gfortran.

Load the module. Type:
module load gnu-4.7.2/compiler

Input: module load gnu-4.7.2/compiler

To see the pathname of the gfortran compiler you will be using type: which gfortran

Input: which gfortran

This shows you the first instance of g77 in your path.

Result: Shows first instance of gfortran in path.

Type:
gfortran hello.f -o hello_fortran_example

Input: : gfortran hello.f -o hello_fortran_example

Now create the job script. Type:
nano fortran_job_script

nano fortran_job_script

Enter the following into the editor:

#!/bin/bash

#PBS -q wsuq
#PBS -l ncpus=1
#PBS -o /wsu/home/zz/zz99/zz9992/output_file
#PBS -e /wsu/home/zz/zz99/zz9992/error_file

cd $TMPDIR
cp /wsu/home/zz/zz99/zz9992/hello_fortran_example $TMPDIR

$TMPDIR/hello_fortran_example

Script typed into nano

Save the file and exit the editor.

NOTE: zz9992 is the account used in this example, but you will have to modify the script using the Access ID and directories specific to your account.

Make sure that the file is executable. You can do this by changing the permissions. Type:
chmod +x fortran_job_script

Input: chmod +x fortran_job_script

Execute the job script. Type: ./fortran_job_script

Input: ./fortran_job_script

The job has been executed.

Output: Hello World
Computer Center Services * 5925 Woodward Avenue Detroit, Michigan 48202