Breadcrumb Links:

Compiling Programs (and using the optimization flags) on the Einstein Cluster

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  The ifortcompiler will compile the myprogram.f 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)  mpiicc myprogram.c -o myprogram.exe  The icc compiler will compile the myprogram.c c code to the executable myprogram.exe using the mpi wrapper mpiicc 
ADA
GNU ADA
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 than a number) and are the compiling flag option used to select the level of optimization which may be applied to produce the 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 level  Flag   Compiling Example 
No Optimization  -O0  g++ (or icc) -O0 myprogram.cpp -o myprogram.exe. 
Level 1  -O1 g++ (or icc) -O1 myprogram.cpp -o myprogram.exe. 
Level 2  -O2  g++ (or icc) -O2 myprogram.cpp -o myprogram.exe. 
Level 3  -O3  g++ (or icc) -O3 myprogram.cpp -o myprogram.exe. 
Fast  -fast  g++ (or icc) -fast myprogram.cpp -o myprogram.exe.