Clang at NSC

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++ 2011 standard.

Beware! Clang is not integrated with the NSC compiler wrappers, and the MPIs are untested against Clang. It is mainly intended for testing and static code analysis. OpenMP support is also absent.

Currently, you can find Clang and LLVM installed on Triolith under /software/apps/llvm+clang. To put the clang and llvm- commands in your PATH, load the clang module:

module load clang/3.3

How to use

To compile normally:

clang -o myprogram.exe myprogram.c

To compile with Intel's MKL for BLAS, LAPACK, and FFTW3 functionality:

clang -o myprogram.exe -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_gf_lp64 -lmkl_core -lmkl_sequential -lpthread -lm  myprogram.c

To run it, you need to set the LD_LIBRARY_PATH, because NSC's linker wrapper does not work for clang yet.

LD_LIBRARY_PATH=$MKLROOT/lib/intel64 ./myprogram.exe

Compiler flag recommendations

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

clang -O3 -march=native -mtune=native ...

Currently, the link-time optimization (-O4 level) does not seem to work on Triolith.

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