Turing : Clang, GCC : Alternative compilers for C/C++

IBM compilers and the new C/C++ standards

The IBM XL C/C++ compilers are preferred on BG/Q for reasons of performance. However, they only support a very small portion of the new C11 and C++11 standards with the positioning of the following options:

LanguagesCommandsOptions SuffixesExplanations
Cmpixlc_r-qlanglvl=extc1x .c Allows using a subset of the C11 standard (ISO/IEC 9899:2011).
C++mpixlcxx_r-qlanglvl=extended0x .cc, .cxx, .c++, .C, .cp, .cpp Allow using a subset of the C++11 standard (ISO/IEC 14882:2011).

If your code contains features which are not supported by the IBM compilers, you have the possibility of using the LLVM Clang compilers.

LLVM Clang compilers

The experimental C/C++ compiler LLVM Clang is available for generating an executable file on the Turing compute nodes. It provides a more complete coverage of the C++11 standard than the IBM XL compiler.

Available versions

The available versions come from an SVN directory managed by Argonne National Laboratory. They are accessible on Turing via the module command :

$ module avail clang
clang/3.5.0          clang/3.6.0(default) clang/nightly

Attention : The clang/nightly is a test version which evolves very rapidly. It can be overwritten and modified by a newer version on a daily basis.

Usage

The Clang compiler must be utilised in the following way:

  1. Load the clang module (otherwise, the IBM compilers will be called upon by default),
  2. Use the mpicc or mpicxx commands to call upon (respectively) the C and C++ compilers.
Languages Commands Suffixes of the
source files
C mpicc .c
C++ mpicxx .cc, .cxx, .c++,
.C, .cp, .cpp

Comment: No LLVM Fortran compiler exists for BG/Q.

The following is an example of the creation of an executable file from a C++ code for the BG/Q compute nodes :

### Loading of the Clang compiler ###
$ module load clang

### Compiling ###
$ mpicxx -c main.cc functions.cc

### Linking ###
$ mpicxx main.o functions.o

Available options

Clang tries to keep its options compatible with those of gcc. You may access an on-line manual with the –help option.

### On-line manual ###
$ mpicxx --help

For more information

GNU compilers

Turing also has the GNU Fortran, C, C++ compilers available for use. The GNU compilers can help with the porting of applications, in particular those written in C et C++. However, in regard to the performance, it would be better to use the IBM or LLVM compilers as described above.

Available versions

Several versions are available via the module command. The 4.4.7 version is the official version supported by IBM. The other versions were compiled by l'IDRIS :

$ module avail gcc
gcc/4.4.7          gcc/4.7.2(default)

Usage

The GNU compilers must be used in the following way:

  1. Load the gcc module (otherwise, the IBM compilers will be called upon by default).
  2. Use the mpif90, mpicc or mpicxx commands to call upon (respectively) the Fortran, C and C++ compilers.
Languages Commands

^

Fortran mpif77, mpif90 .f, .f90
C mpicc .c
C++ mpicxx .cc, .cxx, .c++,
.C, .cp, .cpp

The following is an example of the creation of an executable file C++ code for the BG/Q compute nodes:

### Loading of the GNU compiler ###
$ module load gcc

### Compiling ###
$ mpicxx -c main.cc functions.cc

### Linking ###
$ mpicxx main.o functions.o

Available options

You may access an on-line manual with the principal option –help. Other options of assistance are available:

### General on-line manual ###
$ mpicxx --help

### Other options of assistance ###
$ mpicxx --help=common
$ mpicxx --help=warnings
$ mpicxx --help=optimizers

For more information