HPC Grid Tutorial: How to compile with Fortran

Follow the steps below to compile a program with a Fortran compiler.

1. Log on to the Grid.

2. Start an interactive job. Type: srun -q debug -t 10:0 --pty bash

Image

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

3. Let's create a simple program to practice compiling. Type: vim hello.f

Image

4. Press i to insert. Type the following lines into the editor; each line has a tab (eight spaces) before it starts:

program hello

! This is a comment line that is ignored by the compiler

print *, 'Hello, World!'

end program hello

Image

Save the file and exit. Press Esc and type :wq, then Enter.

Image

7. Now compile the program. Type gfortran hello.f -o hello

Image

8. Now let's practice creating a job script to submit that will execute the program. Type vim fortran_jobscript

Image

9. Press i to insert. Enter the following into the editor:

#!/bin/bash

# Job name

#SBATCH --job-name fortran_job

# Submit to the primary QoS

#SBATCH -q primary

# Request one node

#SBATCH -N 1

# Total number of cores, in this example it will 1 node with 1 core each.

#SBATCH -n 1

# Request memory

#SBATCH --mem=5G

# Mail when the job begins, ends, fails, requeues

#SBATCH --mail-type=ALL

# Where to send email alerts

#SBATCH --mail-user=xxyyyy@wayne.edu

# Create an output file that will be output_<jobid>.out

#SBATCH -o output_%j.out

# Create an error file that will be error_<jobid>.out

#SBATCH -e errors_%j.err

# Set maximum time limit

#SBATCH -t 1:0:0

cd $TMPDIR

cp /wsu/home/zz/zz99/zz9992/hello .

$TMPDIR/hello

Image

NOTE: Be sure to modify the script using the AccessID and directories specific to your account.

Save the file and exit the editor. Press Esc, and type :wq then Enter.

Image

10. Make sure that the file is executable. You can do this by changing the permissions with the chmod command.

Type: chmod x fortran_jobscript

Image

The file permissions can be checked by entering: ls -alt

11. Submit the job script. Type sbatch fortran_jobscript

Image

The output file shows the program was executed.