Ada:Compile:Scalar
Contents
Compiling
Invoking the compiler
To compile your program and create an executable you need to invoke the correct compiler. The default output file name is a.out but this can be changed using the -o compiler flag. All compilers are capable of preprocessing, compiling, assembling, and linking. See table below for the correct compiler commands for the different languages.
Language | Compiler | Syntax |
---|---|---|
C | icc | icc [c compiler_flags] file1 [ file2 ]... |
C++ | icpc | icpc [c++ compiler_flags] file1 [ file2 ]... |
F90 | ifort | ifort [fortran compiler_flags] file1 [ file2 ]... |
F77 | ifort | ifort [fortran compiler_flags] file1 [ file2 ]... |
In the table above, fileN is an appropriate source file, assembly file, object file, object library, or other linkable file.
Basic compiler flags
The next sections introduce some of the most common compiler flags. These flags are accepted by all compilers (icc/icpc/ifort) with some notable exceptions. For a full description of all the compiler flags please consult the appropriate man pages.
Flag | Description |
---|---|
-help [category] | Displays all available compiler options or category of compiler options categories. |
-o <file> | Specifies the name for an output file. For an executable, name of output file will be <file> instead of a.out |
-c | Only compile the file, linking phase will be skipped |
-L <dir> | Tells the linker to search for libraries in directory <dir> ahead of the standard library directories. |
-l<name> | Tells the linker to search for library named libname.so or libname.a |
Optimization flags
The default optimization level for Intel compilers is -O2 (which enables optimizations like inlining, constant/copy propagation, loop unrolling,peephole optimizations, etc). The table below shows some addional commonly used optimization flags that can be used to improve run time.
Flag | Description |
---|---|
-O3 | Performs -O2 optimizations and enables more aggressive loop transformations. |
-xHost | Tells the compiler to generate vector instructions for the highest instruction set available on the host machine. |
-fast | Convenience flag. In linux this is shortcut for -ipo, -O3, -no-prec-div, -static, and -xHost |
-ip | Perform inter-procedural optimization within the same file |
-ipo | Perform inter-procedural optimization between files |
-parallel | enable automatic parallelization by the compiler (very conservative) |
-opt-report=[n] | generate optimization report. n represent the level of detail (0 ..3, 3 being most detailed) |
-vec-report[=n] | generate vectorization report. n represents the level of detail (0..7 , 7 being most detailed) |
NOTE: there is no guarantee that using a combination of the flags above will provide additional speedup compared to -O2. In some rare cases (e.g. floating point imprecision) using flags like -fast might result in code that might produce incorrect results.
Extra-Large Memory Nodes on Ada: These 15 nodes (11 with 1TB and 4 with 2TB of memory) are based on the Westmere INTEL architecture which lacks the AVX vectorization feature. The latter is a standard characteristic of all other (IvyBridge) nodes. For that reason, executables created using using AVX vectorization (e.g., via the -xHost or -xfast compiler flags) will fail. When intending to run on such nodes, recompile if need be, using instead the older vectorization option, -xSSE4.2.
Debugging flags
The table below shows some compiler flags that can be useful in debugging your program.
Flag | Description |
---|---|
-g | Produces symbolic debug information in the object file. |
-warn | Specifies diagnostic messages to be issued by the compiler. |
-traceback | Tells the compiler to generate extra information in the object file to provide source file traceback information when a severe error occurs at run time. |
-check | Checks for certain conditions at run time (e.g. uninitialized variables, array bounds). Note, since the resulting code includes additional run time checks it may affect run time significantly. THIS IS AN IFORT ONLY FLAG |
-fpe0 | throw exception for invalid, overflow, divide by zero. THIS IS AN IFORT ONLY FLAG |
Flags affecting floating point operations
Some optimization might affect how floating point arithmetic is performed. This might result in round off errors in certain cases. The table below shows a number of flags to instruct the compiler how to deal with floating point operations:
Flag | Description |
---|---|
-fp-model precise | disable optimizations that are not value safe on floating point data (See man page for other options) |
-fltconsistency | enables improved floating-point consistency. This might slightly reduce execution speed. |
-fp-speculation=strict | tells the compiler to disable speculation on floating-point operations (See man page for other options) |
Examples
Several examples of compile commands are listed below.
Example 1: Compile program consisting of c source files and an object file.
[ netID@cluster ~]$ icc objfile.o subroutine.c main.c
Example 2: Compile and link source files and an object file, rename the output myprog.x
[ netID@cluster ~]$ icc -o myprog.x subroutine.c myobjs.o main.c
Example 3: Compile and link source file and library libmyutils.so residing in directory mylibs
[ netID@cluster ~]$ icc -L mylibs -lmyutils main.c
Example 4: Compile and link program with aggressive optimization enabled, uses latest vector instructions, and print optimization report.
[ netID@cluster ~]$ icc -fast -xHost -opt-report -o myprog.x myprog.c
Running programs
To execute/run a program from the current directory just type the name of the executable (with carriage return).
Example 1: execute program myprog.x
[ netID@cluster ~]$ ./myprog.x
Note: the ./ in the command indicates that the executable resides in the current directory.
When the executable uses dynamic libraries that reside in non system locations (e.g. executable was compiled using the -L option mentioned before) set the LD_LIBRARY_PATH environmental variable to include these dynamic library directories.
Example 2: execute program myprog.x that depends on libraries residing in directory ~/mylibs
[ netID@cluster ~]$ export LD_LIBRARY_PATH=~/mylibs:${LD_LIBRARY_PATH} [ netID@cluster ~]$ ./myprog.x