Fortran/C on HCC

This quick start demonstrates how to implement a Fortran/C program on HCC supercomputers. The sample codes and submit scripts can be downloaded from serial_dir.zip.

Login to a HCC Cluster

Connect to a HCC cluster and make a subdirectory called serial_dir under your $WORK directory. 

$ cd $WORK
$ mkdir serial_dir

In the subdirectory serial_dir, save all the relevant Fortran/C codes. Here we include two demo programs, demo_f_serial.f90 and demo_c_serial.c, that compute the sum from 1 to 20. 

demo_c_serial.c

demo_f_serial.f90


Compiling the Code

The compiling of a Fortran/C++ code to executable is usually done behind the scene in a Graphical User Interface (GUI) environment, such as Microsoft Visual Studio. In a HCC cluster, the compiling is done explicitly by first loading a choice compiler and then executing the corresponding compiling command. Here we will use the GNU Complier Collection, gcc, for demonstration. Other available compilers such as intel or pgi can be looked up using the command line module avail. Before compiling the code, make sure there is no dependency on any numerical library in the code. If invoking a numerical library is necessary, contact a HCC specialist (hcc-support@unl.edu) to discuss implementation options.

$ module load compiler/gcc/8.2
$ gfortran demo_f_serial.f90 -o demo_f_serial.x
$ gcc demo_c_serial.c -o demo_c_serial.x

The above commends load the gcc complier and use the compiling commands gfortran or gcc to compile the codes to.x files (executables). 

Creating a Submit Script

Create a submit script to request one core (default) and 1-min run time on the supercomputer. The name of the main program enters at the last line.

submit_f.serial

submit_c.serial

Submit the Job

The job can be submitted through the command sbatch. The job status can be monitored by entering squeue with the -u option.

$ sbatch submit_f.serial
$ sbatch submit_c.serial
$ squeue -u <username>

Replace <username> with your HCC username.

Sample Output

The sum from 1 to 20 is computed and printed to the .out files.