GNU Compilers

GNU C/C++/Fortran on the HPC3

Pick a Version

To list the available versions:

qlogin
module avail gcc
--------------------------------------------------- /etc/modulefiles ---------------------------------------------------
gcc/12.2.0

Note: there may be more-recent versions, as well.

To use these newer version (and recommended latest GCC compiler), please modify your ~/.bashrc file as follows:

## START MODULE SELECTION
if [[ ! $(echo $TAGNAME |egrep "^hpc3-(login|desktop|qmaster)*$") ]]; then
... other modules ...
    module load gcc/12.2.0
fi
## END MODULE SELECTION

If you don’t want to permanently set your GCC versions for all sessions (qlogin or qsub), which could be useful in the long term for different projects, you can instead use those commands after qlogin, or within your qsub job script file before you run gcc / gfortran.

Create C Program File

Create a .c file with your commands, for example:

#include<stdio.h>
main()
{
printf("Hello world.n");
}

Submit gcc compile job

qrsh gcc -o myHelloWorld hello.c

Create a Job Script to run the compiled program

If the compiler successfully compiled the source code into an executable (myhw), the executable will be placed in your working directory. This executable is meant to be run on the cluster’s compute nodes — the head node is to be used exclusively for creating programs and scripts and to interact with the cluster. Executables should not be run on the head node!

Create a .sh file (myHelloWorld.sh in this case) with the following contents:

#!/bin/bash
./myHelloWorld

Submit the executable

qsub myHelloWorld.sh

SHORT Jobs

If the executable above is a short job (yes, that’s subjective! :)), you could also run it with qrsh:

qrsh ./myHelloWorld