Compiling and Running Serial/Scalar Programs
Last modified: Saturday July 16, 2011 3:26 PM
- Compiling Serial Code
- Running Serial Code
- Common Compiler Options
- Filename Extensions
- Compiler Documentation
Compiling Serial Code
The commands icc, icpc, and ifort invoke, respectively, the Intel C, C++, and Fortran compilers. All are capable of preprocessing, compiling, assembling, and linking.
Prior to using any Intel compiler, you must "load" the appropriate module:
module load intel/compilers
The command line form for invoking a compiler is:
icc [C compiler options] -o prog.exe file1 file2 ... icpc [C++ compiler options] -o prog.exe file1 file2 ... ifort [Fortran compiler options] -o prog.exe file1, file2 ... where file1, file2, ... are any appropriate source, assembly, object, object library, or other (linkable) files that are linked to generate the executable file, prog.exe. The specified input files file1, file2, ... must have, in each language, appropriate file extensions. See below the table on valid file extensions. All generated executables are, by default, 64-bit.
Examples. Below the C and Fortran compilers, using different code optimization options, are run to obtain executables (the .exe's) by compiling and linking source (the .c's or .f90's), as well as object files (the .o's).
icc -O2 -o progC.exe prog.c fun1.o fun2.o ifort -O3 -xHost -o progF.exe main.f90 sub1.f90 sub2.o
Running Scalar Code
To execute/run a program just type (with carriage return) at the command line the name of the executable as shown below.
Below we show a very limited subset of the available options. For further exploration, see the man page of each compiler.
|-help||Displays all available compiler options and option categories (e.g., optimization, code generation, etc.).|
|-c||Generates only object files (file.o) for each source or preprocessed source file specified.|
|-g||Generates full debugging information in the object file.|
|-traceback||Generates extra information in the object file to provide source file traceback information when a severe error occurs at run time. This option increases the size of the executable program, but has no impact on run-time execution speeds. It functions independently of the debug option.|
|-O[n]||Enables different code optimization levels, n=0-3; n=1, enables some optimizations for speed; n=2 (or just -O) is the default. It enables, among other, inlining and software pipelining; n=3, same as -O2, plus loop transformations and data prefetching for improved memory-usage efficiency.|
|-fast||Activates the -xHOST -O3 -ipo -no-prec-div -static options which typically improve run-time performance, but also create a statically linked executable file. Static linking makes for an executable with a larger memory footprint, since now all code, including system libs, are contained within the executable. Experiment with this option before you decide to adopt it permanently.|
|-xHost||Generates instructions for the highest instruction set and processor available on the host machine, a Nehalem or Westmere node. In vectorizable loops, the compiler will use (SSE4.2) vector instructions to carry out computation. This will result in a significant speedup if the loops involved contain a significant amount of computation.|
|-opt-report||Generates a report about compiler optimizations on stderr.|
|-l name||Links the library libname.so or libname.a to the executable.|
|-L dir||Tells the linker to search for libraries in the specified directory, dir, before searching for them in the standard directories. This option is often used in tandem with the preceding one, -l name.|
|-heap-arrays [minimum_size in KB]||(Fortran) Causes memory space for all automatic and temporary arrays to be allocated on the heap instead of the runtime stack (the default). If, in addition, size is specified, say, 10, heap allocation is used only for automatic and temporary arrays that are larger than 10 KB.|
|-auto||(Fortran) Places local variables (scalars and arrays of all types), except those declared with the SAVE or ALLOCATABLE attribute, on the run-time stack.|
|-r8 or -r16||(Fortran) Sets the default size of real numbers to 8 or 16 bytes respectively.|
|-assume buffered_io||(Fortran) Sets the default for opening sequential output files to BUFFERED='YES', so that writes to disk will be buffered. The default is -assume nobuffered_io, which means that data will be immediately written to disk. This option will typically improve I/O performance substantially.|
Specific filename extensions are meant to identify files with different programming language contents, thereby enabling the compiler script to hand these files to the appropriate compiling subsystem: preprocessor, compiler proper, linker, etc.
NOTE: The icpc command ("C++" compiler) uses the same compiler options as the icc ("C" compiler) command. Invoking the compiler using icpc compiles '.c', and '.i' files as C++. Invoking the compiler using icc compiles '.c' and '.i' files as C. Using icpc always links in C++ libraries. Using icc only links in C++ libraries if C++ source is provided on the command line.
|.c||C source code passed to the compiler.|
|.C, .CC, .cc, .cpp, .cxx||C++ source code passed to the compiler.|
|.f, .for, .ftn||fixed form Fortran source code passd to the compiler.|
|.fpp||Fortran fixed form source code that can be preprocessed by the Intel Fortran preprocessor fpp.|
|.f90||free form Fortran 90/95 source code passed to the compiler.|
|.F||Fortran fixed form source code, will be passed to preprocessor (fpp) and then passed to the Fortran compiler.|
|.o||compiled object file--generated with the -c option--passed to the linker.|
|.a, .so||library file passed to the linker.|
The man page of each compiler (e.g., man ifort) has almost everything you will need. Fuller documentation can be found on our website at the Intel Software Documentation page.