Using Clang on Tetralith

Clang is a C/ObjC/C++ compiler based on the LLVM infrastructure. Its main advantages over other compilers are very fast compile times and "expressive" error messages and diagnostics. Clang also implements all of the ISO C++ standards up to 2014. Almost all of C++ 2017 is also covered, except structured bindings. There is even some experimental support for C++2a features. The most up to date info is available on the CXX status web page.

Beware! Using Clang for regular C/C++ code should work on Tetralith, but OpenMP and MPI support are considered experimental. We do not do much testing of it. See instructions below on how to use Intel MPI with Clang.

Currently, you can find Clang and LLVM installed on Tetralith under /software/sse/manual/clang. The LLVM modules installed by EasyBuild typically do not include Clang. To put the clang and llvm- commands in your PATH, simply load the clang module:

module load clang/6.0.1

Installed versions

  • Module clang/6.0.1: LLVM 6.0.1 release bootstrapped using itself, including Clang, Clang extra tools, compiler-rt, libc++abi, libc++, and OpenMP.

Basic use

To compile normally:

clang -o myprogram.exe myprogram.c

Clang and Intel MKL

To compile with Intel's MKL for BLAS, LAPACK, and FFTW3 functionality, it is easier if you first load an Intel build environment module, to set up $MKLROOT and similar environment variables. Note the order of loading modules, it is important that you load the clang/6.0.1 module after the Intel module.

module load buildenv-intel/2018.u1-bare
module load clang/6.0.1

clang -o myprogram.exe -I$MKLROOT/include -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl  myprogram.c

Intel's MKL linking advisor is a good tool to figure out how to link MKL. When using Clang, try selecting GNU C/C++ as the compiler. Remember that NSC's compiler wrappers hard-codes the path to the MKL libraries using RPATH, so there is no need to set LD_LIBRARY_PATH

Clang and Intel MPI

We have tested Intel's MPI with clang, and it seems to work. There are special MPI compiler wrappers for clang called mpiclang and mpiclang++. Use these to compile your MPI.

module load buildenv-intel/2018.u1-bare
module load clang/6.0.1

mpiclang -o myprogram.exe myprogram.c

And then launch with mpprun as usual.

mpprun ./myprogram.exe

Compiler flag recommendations

Clang has the usual optimization levels (-O1,-O2,-O3,-Ofast,-Os). They roughly correspond to the ones for gcc, but are not identical. There is auto-vectorization in Clang, but it may not be as efficient as in gcc or Intel's compiler, so your mileage may very. For high optimzation, try:

clang -O3 -march=skylake-avx512 -mtune=skylake-avx512 ...

Currently, the link-time optimization (-flto) does not seem to work.

Static analysis

Clang is useful just for the extensive set of warnings and static checks of C code. The simplest way is just to compile your code with all warnings enabled:

clang -Weverything ...

Please note that this is different from the -Wall option, which does not actually enable all warnings. If you want to run Clang only as a static checker and not compile the files, add -fsyntax-only

clang -fsyntax-only -Weverything ...

If you want to go beyond running clang on a single file, there is utility called scan-buildthat can run static analysis over your whole project while building it. If you have a makefile for your project, the following should work:

scan-build make

User Area

User support

Guides, documentation and FAQ.

Getting access

Applying for projects and login accounts.

System status

Everything OK!

No reported problems

Self-service

SUPR
NSC Express