Compiling and linking

Multiple compiler suites are available for building and linking application codes, and while they are all share many similarities, it is inevitable that there are also some differences.  For example, depending on the type of application, one set of compilers may produce code that performs better than another.  Or, certain types of syntax may be accepted by some compilers but not others.

The following compilers are currently available:

Compiling and linking is performed using wrapper scripts ftn, cc, and CC for source code written in Fortran, C, and C++, respectively.  These wrappers invoke the appropriate compiler based on the current Programming Environment and produce executables that can be run on the compute nodes.  These wrappers are fairly versatile, and automatically link in a wide variety of libraries as necessary, including Cray's Scientific Software Library (libsci) and MPI ( for instance, -lmpi is not required and will cause the link step to fail).  In other words, do NOT use mpicc (for instance) to compile MPI codes; the cc or CC wrapper already contains the proper compiler and library invocations.

There are numerous options that can be used to influence the compilation process.  Some of these may produce the same behavior across all compilers, but many of them are specific to a particular compiler.  Some of the more commonly-used options are listed here (see the compiler man pages or the Cray Application Developer's Environment User's Guide for more detailed information):

  • -c                     Produce object file only; do not make executable

  • -g                     Include symbol table and other information for debugging

  • -v                     Displays verbose compiler output

  • -r <list opt>    Produce a listing file

  • -o <name>     Specify the name of the executable

  • -O <opt>         Controls the level of compiler optimization

  • -I <dir>           Specifies additional location(s) of header files

  • -L <dir>          Specifies additional location(s) of library files

  • -l <lib>            Specifies additional libraries to be linked


The following table provides a comparison of common functionality across compilers.

Cray PGI GNU Intel Explanation
default -fast -O3 -ffast-math -fast High level optimization
-h omp (default) -mp=nonuma -fopenmp

-fopenmp

at runtime: aprun --cc=none ...

OpenMP directives and pragmas
-h byteswapio -byteswapio -fconvert=swap -convert big_endian Fortran unformatted data files as big-endian
-f fixed -Mfixed -ffixed-form -fixed Fortran fixed form
-f free -Mfree -ffree-form -free Fortran free form
-V -V --version -V Version information
-h zero not implemented -finit-local-zero -init=zero Zero fill all uninitialized variables.
-e m -J dir_name     -module dir_name Save .mod files to directory dir_name
-s integer64 -i8 -fdefault-integer8 -integer-size 64 64-bit integer
        RUNTIME OPTIONS For DEBUG/DEVELOPMENT
-fp0 -Kieee   -mieee-fp require IEEE precision for numeric ops
-K trap= -Ktrap=... -ffpe-trap=...  # fortran -fpe0 FP traps, see compiler man pages for further info.

-h bounds # c

-R b  # fortran

-Mbounds

-fbounds-check # fortran

-CB check array bounds

 

Dynamic Linking

There are two ways to enable dynamic linking when using the compiler wrapper scripts with any of the supported compilers.

The first way is to use the '-dynamic' flag. This works in principle but the user has to make sure they reproduce the right runtime environment (LD_LIBRARY_PATH) when running the program.

The second method is to use two environment variables that do both:

export CRAYPE_LINK_TYPE=dynamic
export CRAY_ADD_RPATH=yes
so that the application is linked dynamically and the paths to the libraries are preserved using the 'rpath' linker option.