Compiling Programs (and using the optimization flags)

Compiling

COMPILERUSAGE EXAMPLENOTES ON EXAMPLE
C/C++
GNU C gcc myprogram.c -o myprogram.exeThe gcc compiler will compile the myprogram.c "c" code to the executable myprogram.exe
GNU C++g++ myprogram.cpp -o myprogram.exeThe g++ compiler will compile the myprogram.cpp C++ code to the executable myprogram.exe
Intel C icc myprogram.c -o myprogram.exeThe icc compiler will compile the myprogram.c "C" code to the executable myprogram.exe
Intel C++ icc myprogram.cpp -o myprogram.exeThe icc compiler will compile the myprogram.cpp c++ code to the executable myprogram.exe

Fortran

ntel 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.exeThe 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 -lmpiThe 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.exeThe 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 LEVELFLAGCOMPILING EXAMPLE
GNU COMPILER
No Optimization-O0g++ -O0 myprogram.cpp -o myprogram.exe.
Level 1-O1g++ -O1 myprogram.cpp -o myprogram.exe.
Level 2-O2g++ -O2 myprogram.cpp -o myprogram.exe.
Level 3-O3g++ -O3 myprogram.cpp -o myprogram.exe.
Fast-fastg++ -fast myprogram.cpp -o myprogram.exe.

Intel Compiler

No Optimization-O0icc -O0 myprogram.cpp -o myprogram.exe.
Level 1-O1icc -O1 myprogram.cpp -o myprogram.exe.
Level 2-O2icc -O2 myprogram.cpp -o myprogram.exe.
Level 3-O3icc -O3 myprogram.cpp -o myprogram.exe.
Fast-fasticc -fast myprogram.cpp -o myprogram.exe.