GNU Compilers

GNU Compilers

GNU, a recursive acronym for "GNU is Not Unix", compilers from GCC (GNU Compiler Collection) consists of many compilers such as C, C++, Java, FORTRAN etc.

Important Notes

Compiler Version

To check the version of GNU Compilers, type:

gcc --version

output:

gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

Copyright (C) 2010 Free Software Foundation, Inc.

Compiling a Code & Executing

Compiling a C or C++ Program

Interactive:

Request the compute node:

srun -t 1:00:00 --mem=4gb --pty /bin/bash

Note: GNU compilers use different commands for compiling C and C++ source files.

Compiling a FORTRAN Program

To compile the FORTRAN 77 source file "test.f" with the GNU FORTRAN 77 compiler, use the command

g77 -o test test.f

To compile Fortran 90/95 source file "test.f90" with GNU Fortran compiler, use the command

gfortran -o test test.f90

Using BATCH

We are going to compile and execute our C++ code in hello.cpp using BATCH:

Copy the following code in a file called "hello.slurm":

#!/bin/bash

#SBATCH -o hello.o%j

#SBATCH --time=00:02:00

#SBATCH -N 1

#SBATCH -n 1

#Compiling section

module load gcc

g++ -o hello hello.cpp

#Copying files to scratch

cp -r hello $PFSDIR

#Running job

cd $PFSDIR

./hello

cp -ru * $SLURM_SUBMIT_DIR

Submit the job:

sbatch hello.slurm

You will find the output at "hello.o<jobid>"

References: