Skip to content

Compiling software

This page describes how to compile custom code for the HPC or other RCC systems using compilers on our login and compute nodes.

Although the RCC provides a large number of built-in, precompiled software packages on our systems, many users will need to compile custom code into an executable program before submitting it to the Slurm scheduler. For this, we provide compiler libraries on our systems.

The three most commonly used compilers on our systems include:

  1. Intel compilers
  2. GNU compilers
  3. NVHPC Compilers

Note

For a comprehensive list of compilers that the RCC supports, refer to our software catalog

Each compiler includes executables to compile C, C++, and Fortran sourcecode. These are the three most commonly used languages for HPC computing. We also support Java, Python (which can be compiled to C using cython), and other languages.

In addition, we provide commonly used libraries for each of the compilers, including OpenMPI, NetCDF, and others.

Compilation Overview#

The general workflow for compiling an application on our systems is as follows:

  1. Copy source files into your home directory on our system.
  2. Import compiler paths using environment modules
  3. Load linked libraries
  4. Compile code using Intel, GNU, or NVHPC compiler
  5. Run application or submit job

Tutorial: trap.c#

Below is a tutorial for compiling a C program on the HPC login node using the Intel compiler with the MPI libraries for a simple program, trap.c. This script is a convenient example of how parallel execution on the HPC works.

The trap.c script is a classical trapezoid integration that uses MPI. The script calculates the integral of a function using a composite trapezium rule, and each node calculates it subpart for the entire domain. You do not need to understand the mechanics of what the script does in order to follow this tutorial.

Login to the HPC and copy the example trap.c and trap.sh files into your home directory:

$ cp /gpfs/research/software/examples/trap.c .
$ cp /gpfs/research/software/examples/trap.sh .

trap.c is the source code file for the trapezoid integration program, and trap.sh is a shell script that submits the program to the HPC job scheduler.

First, import the GNU compiler module into your environment using environment modules. This will enable access to the GNU compiler executable commands:

$ module load gnu

After running this command, try running gcc --version. You should see something similar to the following:

1
2
3
$ gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)
Copyright (C) 2018 Free Software Foundation, Inc.

Warning

If you see a Command not found error, ensure that you have run the module load gnu command first.

Next, load the MPI libraries:

$ module load gnu openmpi

With both the compiler module and the parallelization libraries loaded, you can now compile your trap.c code into an executable:

$ mpicc -o trap trap.c -lm

This command will show no output when run, but if your run ls after it completes, you will see a new executable file appear: trap.

This file is ready to be executed in an MPI environment, specifically the HPC.

To submit your compiled program, you can use the sbatch command on .sh files. In our example:

$ sbatch trap.sh
Submitted batch job <jobid>

After submitting the job, you can expect an email upon the start and end of the job. Results will be in the slurm-<jobid>.out file. Furthermore, you can check the status of your job using the squeue command:

$ squeue --me

For more information on running compiled programs on the HPC, see our tutorial for submitting HPC jobs.

Compiler Reference#

This page provides an example using the GNU compiler. For a more comprehensive overview of all the compiler commands and options available, refer to our software documentation