The National Institute for Computational Sciences

Compiling

Compilers on Darter

  • The default compiler is the Cray compiler (CCE)
  • The available compilers on Darter are : Cray (default), GNU and Intel.
  • The PGI and Pathscale compilers are no longer available

Overview

Cray provides a convenient set of compiler wrapper commands that should be used for compiling and linking programs to be run on the compute nodes. The wrapper invokes the corresponding back-end compiler in the currently loaded programming environment. Invoking the wrappers will automatically:

  • Import the path for key header files like 'mpi.h' and other libraries
  • Link in the MPI and other fundamental header files and libraries needed to run on Cray system
  • Automatically include and link in header files and libraries loaded via module
  • Specify the correct target processor arguments
  • Provides a common interface to all compilers.

The following table lists the compiler wrappers and the corresponding back-end compilers available on the system

Compiler Wrapper Cray GNU Intel
C cc craycc gcc icc
C++ CC crayCC g++ icpc
Fortran ftn crayftn gfortran ifort
When compiler wrapper is invoked, flags and options given to it are passed to the back-end compiler as appropriate. You can learn more about the wrappers from the man pages for cc, CC and ftn.

Note: It is crucial to use the compiler wrappers to build code intended for compute nodes. You may invoke back-end compilers directly for programs intended only for execution on login or service nodes.

The Programming Environment

All compilers on Darter -- Cray, GNU, and Intel -- are provided via three programming environments that are accessed via the modules software package. Each programming environment contains the full set of compatible compilers and libraries. To change from one compiler to the other, you need to change the programming environment via the 'module swap' command. Here is an example on how to change from the default Cray compiler to the Intel compiler:

module swap PrgEnv-cray PrgEnv-intel

OpenMP

OpenMP is supported in all three programming environments available on Darter; however, each compiler suite has a different syntax for enabling OpenMP support at compile time:

Compiler Option
Cray -h omp (It is on by default)
GNU -fopenmp
Intel -openmp

Common Compiler Options

The following table shows common compiler options for PGI, Cray, Intel, and GNU compilers. Although PGI compiler is not available on Darter, it is included here to aid user porting their Makefile and compiler option from PGI compiler on Kraken to one of the supported compilers on Darter.
PGI Cray Intel GNU Description
-fast optimized by default -fast -no-ipo -O3 -ffast-math standard optimization
-mp -homp -openmp -fopenmp enable OpenMP support
-byteswapio -hbyteswapio -convert big_endian
-convert little_endian
-fconvert=swap swap endian-ness of
unformatted files
-Mfixed
-Mfree
-ffixed
-ffree
-fixed
-free
-ffixed-form
-ffree-form
process Fortran source as
fixed or free format

Dynamic Linking

Darter supports the use of dynamic linking and shared libraries. For more information and examples, please see Dynamic Linking on Darter.

Examples

Example 1: Compiling a C program

The command compiles source code files progx.c and progy.c and links them against all default and required library functions, creating executable progxy.

% cc -o progxy progx.c progy.c

Example 2: Compiling a Fortran program with the default Cray Compiler

The command compiles source code file himeno_BMTxpr.f and links it to any required library functions, creating executable himeno_orig. The option -rm will produce a source listing file himenoBMTxpr.lst with loopmark information that can be used to understand what the Cray compiler did to improve performance, or, correlate with the output from CrayPAT when analyzing performance. Option -eF turns on the pre-processor before compiling the Fortran code.

% ftn -rm -eF himeno_BMTxpr.f -o himeno_orig

Example 3: Compiling a program requiring libraries provided by module

Using compiler wrappers compiles source code and automatically include the header files and link against any necessary libraries loaded via module. In the following example, HDF5 and METIS headers files and libraries are included and linked to the program automatically without the need for additional compile and linking flags:

% module load metis
% module load cray-hdf5
% cc  metis_hdf5_example.c -o metis_hdf5_example.exe
% ftn metis_hdf5_example.f -o metis_hdf5_example.exe  

Example 4: Compiling a Fortran program with the GNU compiler with optimization level O3

The command compiles source code file example.f90 with optimization level O3, then links it to any required library functions, creating executable example.x.

% module swap PrgEnv-cray PrgEnv-gnu
% ftn -O3 -o example.x example.f90

Example 5: Compiling a Fortran and a C program with the Intel compiler and the MKL library

The Intel Math Kernel Library (MKL) is available on Darter. This library offers both Fortran and C interfaces. The command compiles the source code file mycode.f, links it to any required library function using the MKL library to resolve numerical function calls, creating executable mycode.

% module swap PrgEnv-cray PrgEnv-intel
% module unload cray-libsci
% ftn -o mycode mycode.f -mkl
% cc -o mycode mycode.c -mkl

The option -mkl is the same as -mkl=parallel. But, this option can also be used as -mkl=cluster. Read Intel's documentation for more information.

Example 6: Compiling a Coarray Fortran (CAF) program

You can use CoArrays only with the Cray Programming Environment. The command compiles the source code file CAFhello.f90, then links it to any required library functions, creating executable CAFhello.

% ftn -h caf -o CAFhello CAFhello.f90

Example 7: Compiling a UPC program

You can use UPC only with the Cray Programming Environment. The command compiles the source code file UPCProg.c, then links it to any required library functions, creating executable UPCProg.

% cc -h upc -o UPCProg UPCProg.c

Example 8: Compiling a "HelloWorld.c" program

Click here for an example of Compiling and Running a Job on Darter