Compiling code

Modules

VSC-4:

To use the Intel Compiler load either of:

VSC-4> module load intel/19
VSC-4> module load intel/19.1.3

and to use the GCC compiler:

VSC-4> module load gcc/9.1.0-gcc-4.8.5-mj7s6dg

Modules

VSC-3:

To use the Intel compiler on VSC-3/VSC-3plus use either of:

VSC-3> module load intel/18
VSC-3> module load intel/18.0.4

and to use a specific GCC compiler use:

VSC-3> module load gcc/7.3
VSC-3> module load gcc/7.3.0

Compiler names

icc       # Intel C compiler
icpc      # Intel C++ compiler
ifort     # Intel Fortran compiler
gcc       # GNU C compiler
g++/c++   # GNU C++ compiler
gfortran  # GNU Fortran compiler

Compiler versions

VSC-3/4> icc --version
icc (ICC) 19.1.3.304 20200925
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.
VSC-3/4> gcc --version
gcc (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.

Examples: compiling serial code

VSC-3> module purge
VSC-3> module load intel/18.0.4
VSC-4> module purge
VSC-4> module load intel/19.1.3

Compile without optimization:

VSC-3/4> icc -O0 hello.c -o hello_c
VSC-3/4> ./hello_c
Hello World

Compile with optimization:

VSC-3/4> icc -O3 -xHost hello.c -o hello_c
VSC-3/4> ./hello_c
Hello World

Examples: compiling serial code

VSC-3> module purge
VSC-3> module load gcc/7.3
VSC-4> module purge
VSC-4> module load gcc/9.1.0-gcc-4.8.5-mj7s6dg

Compile without optimization:

VSC-3/4> gcc -O0 hello.c -o hello_c
VSC-3/4> ./hello_c
Hello World

Compile with optimization:

VSC-3> gcc -O2 -march=ivybridge hello.c -o hello_c
VSC-4> gcc -O2 -march=skylake hello.c -o hello_c
VSC-3/4> ./hello_c
Hello World

Examples: compiling OPENMP code:

VSC-3/4> icc -qopenmp hello_openmp.c hello_openmp_c
VSC-3/4> export OMP_NUM_THREADS=2
VSC-3/4> ./hello_openmp_c
Hello World... from thread = 0
Hello World... from thread = 1
VSC-3/4> gcc -fopenmp hello_openmp.c hello_openmp_c
VSC-3/4> export OMP_NUM_THREADS=2
VSC-3/4> ./hello_openmp_c
Hello World... from thread = 0
Hello World... from thread = 1

Compiling MPI code:

Compiling MPI code: Intel MPI

mpiicc              # C
mpiicpc             # C++
mpiifort            # Fortran
mpicc/mpigcc        # C
mpicxx/mpigxx       # C++
mpif90/mpif77/mpifc # Fortran

Compiling MPI code: Intel MPI

VSC-4> module purge
VSC-4> module load intel/19.1.3 intel-mpi/2019.7
VSC-4> mpiicc -show
VSC-4> module purge
VSC-4> module load gcc/9.1.0-gcc-4.8.5-mj7s6dg intel-mpi/2019.7
VSC-4> mpicc -show
VSC-3> module purge
VSC-3> module load intel/18.0.4 intel-mpi/2018.4
VSC-3> mpiicc -show
VSC-3> module purge
VSC-3> module load gcc/7.3 intel-mpi/2018.4
VSC-3> mpicc -show

Compiling MPI code: OpenMPI

VSC-4> module load openmpi/4.0.3-intel-19.1.1.217-vbnpf6h
VSC-4> module load openmpi/4.0.3-gcc-9.1.0-it4lnqb

VSC-3> module load intel/18 openmpi/4.0.4
VSC-3> module load gcc/7.3 openmpi/4.0.4
mpicc                    # C
mpic++/mpiCC/mpicxx      # C++
mpif77/mpif90/mpifort    # Fortran

Examples: compiling MPI code

VSC-3> module purge
VSC-3> module load intel/18.0.4 intel-mpi/2018.4
VSC-4> module purge
VSC-4> module load intel/19.1.3 intel-mpi/2019.7

Compile without optimization:

VSC-3/4> mpiicc -O0 hello-mpi.c -o hello-mpi_c
VSC-3/4> mpirun -np 2 ./hello-mpi_c
Hello world from processor l41, rank 1 out of 2 processors
Hello world from processor l41, rank 0 out of 2 processors

Compile with optimization:

VSC-3/4> mpiicc -O3 -xHost hello-mpi.c -o hello-mpi_c
VSC-3/4> mpirun -np 2 ./hello-mpi_c
Hello world from processor l41, rank 1 out of 2 processors
Hello world from processor l41, rank 0 out of 2 processors