Secondary navigation

Compiling Programs (and using the optimization flags)

Compiling

Compiler Usage Example Notes on Example
C/C++
GNU C  gcc myprogram.c -o myprogram.exe The gcc compiler will compile the myprogram.c "c" code to the executable myprogram.exe
GNU C++ g++ myprogram.cpp -o myprogram.exe The g++ compiler will compile the myprogram.cpp C++ code to the executable myprogram.exe
Intel C  icc myprogram.c -o myprogram.exe The icc compiler will compile the myprogram.c "C" code to the executable myprogram.exe
Intel C++  icc myprogram.cpp -o myprogram.exe The icc compiler will compile the myprogram.cpp c++ code to the executable myprogram.exe
FORTRAN
Intel Fortran

ifort myprogram.f -o myprogram.exe

ifort myprogram.f90 -o myprogram.exe

ifort myprogram.f95 -o myprogram.exe

The ifort compiler will compile the myprogram.f (or *.90 or *.95) fortran code to the executable myprogram.exe

GNU Fortran

Note: you will need to load
the gnu-gcc-4.8.1 or gcc-fortran
module, before the gfortran compiler is available.

gfortran myprogram.f -o myprogram.exe

gfortran myprogram.f90 -o myprogram.exe

gfortran myprogram.f95 -o myprogram.exe

The gfortran compiler will compile the myprogram.f (or *.90 or *.95) fortran code to the executable myprogram.exe
MPI
C/C++ for MPI (GNU Compiler)

mpicc myprogram.c -o myprogram.exe

The gcc compiler will compile the myprogram.c "C" code to the executable myprogram.exe using the mpi wrapper mpicc 
C/C++ for MPI (Intel Compiler) icc myprogram.c -o myprogram.exe -lmpi The icc compiler will compile the myprogram.c "C" code to the executable myprogram.exe using the mpi wrapper mpiicc
ADA

GNU ADA

(Note - ADA not currently available on Login Node)

Can provide access to compiler if needed

gnatmake myprogram -o myprogram.exe The gcc compiler will compile the myprogram.adb ADA code to the executable myprogram.exe using the gnatmake program

Optimization

The selection and modification of variables and options during the compile process can have a significant effect on program execution and results. One simple technique is to use optimization flags when compiling the code. Optimization flags encourage the compiler to improve upon performance (however this can come at the expense of correct results). Optimization flags are represented in syntax as "-O#" (The letter O and then a number), which are the compiling flag option used to select the level of optimization applied to produce an executable.

An example of compile syntax would be:

g++ (or icc) -O2 myprogram.cpp -o myprogram.exe

Programs initially compiled using the default compile options for each compiler are set to the following levels of optimization, GNU compilers use no optimization ("-O0") and the Intel compiler uses level 2 optimization ("-O2").

Example compile syntax include:

Optimization levelFlag Compiling Example
GNU Compiler
No Optimization -O0 g++ -O0 myprogram.cpp -o myprogram.exe.
Level 1 -O1 g++ -O1 myprogram.cpp -o myprogram.exe.
Level 2 -O2 g++ -O2 myprogram.cpp -o myprogram.exe.
Level 3 -O3 g++ -O3 myprogram.cpp -o myprogram.exe.
Fast -fast g++ -fast myprogram.cpp -o myprogram.exe.
Intel Compiler
No Optimization -O0 icc -O0 myprogram.cpp -o myprogram.exe.
Level 1 -O1 icc -O1 myprogram.cpp -o myprogram.exe.
Level 2 -O2 icc -O2 myprogram.cpp -o myprogram.exe.
Level 3 -O3 icc -O3 myprogram.cpp -o myprogram.exe.
Fast -fast icc -fast myprogram.cpp -o myprogram.exe.