Skip to content

Compilation Help

william-dawson edited this page Sep 13, 2017 · 10 revisions

On this page we go into detail about the compilation procedure for NTPoly.

Building NTPoly requires the following software:

  • CMake (version 3.2 and up)
  • MPI (Version 3 API)
  • SWIG (optional, version 3 and up)
  • Python 2.7+ (optional)

CMake is used for the build system. SWIG is used to expose an interface to languages other than Fortran, C, and C++. Python is used for testing NTPoly. SWIG is required to run the python tests, so it is definitely encouraged.

Here we will go into detail about building for a few sample systems.

Our group maintains a cluster that uses the intel compilers. Here is a look at the configuration options.

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_Fortran_COMPILER mpiifort)
set(CMAKE_C_COMPILER mpiicc)
set(CMAKE_CXX_COMPILER mpiicpc)

set(CXX_TOOLCHAINFLAGS "-openmp -lgomp")
set(F_TOOLCHAINFLAGS "-check bounds -O0 -fpp -qopenmp")

Fortunately, in this case things aren't so difficult. We specify that it's a linux machine. We specify the MPI wrappers for C, C++, and Fortran. After the compilers are set, we set the compiler options. Here we have some debugging settings like -check bounds and -O0. -fpp is needed to use the Fortran preprocessor, and -qopenmp for openmp parallelization.

This isn't pretty. Here we go.

set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_Fortran_COMPILER mpif90)
set(CMAKE_CXX_COMPILER mpicxx)

set(PYTHON_EXECUTABLE python2)
set(PYTHON_INCLUDE_DIRS /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/Headers)
set(PYTHON_INCLUDE_PATH /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Headers/ /usr/local/lib/python2.7/site-packages/mpi4py/include)
set(PYTHON_LIBRARIES /usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib)

set(CXX_TOOLCHAINFLAGS "-openmp -lgomp")
set(F_TOOLCHAINFLAGS "-fbounds-check -O0 -cpp -fopenmp")

Unfortunately, the flavor of python that comes with the Mac doesn't have all the features we want. The solution is to install a newer version using the brew package manager. However, CMake gets very confused by all these versions of python sitting around, so we have to manually specify a lot. There is also a separate Mac target file that works for python3.

The flags are similar to the intel case.

Now for the K computer.

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER mpifccpx)
set(CMAKE_Fortran_COMPILER mpifrtpx)
set(CMAKE_CXX_COMPILER mpiFCCpx)
set(CXX_TOOLCHAINFLAGS "-Kfast,-Kparallel,openmp,optmsg=2 --linkfortran")
set(F_TOOLCHAINFLAGS "-Kfast,-Kparallel,openmp,optmsg=2 -Cpp")
set(PYTHON_INCLUDE_PATH "/path/to/home/include/python2.7")

The compiler wrappers are supplied by Fujitsu. In this case, we show optimized flags such as -Kfast. -Cpp is for the preprocessor, and --linkfortran is necessary to call Fortran from C++. I had to install my own version of python locally.

Most of the linking details are hidden by CMake, so here we will explicitly discuss how to manually link your code with NTPoly. These details are also discussed in the ReadMe files in the Examples directory.

Linking against a Fortran code is the simplest case. After NTPoly has been compiled, the compiled module files are stored in Build/include, and the compiled object files are stored in a library in Build/lib. Thus, you should add the include line -I/path/to/Build/include and the link directory line -L/path/to/Build/lib. The Fortran library is libNTPoly.a, so link against it with -lNTPoly. NTPoly also requires openmp, so be sure to use the appropriate compiler flags.

For a C++ code, you need both a C++ and Fortran compilers. First, compile your code to object files using the C++ compiler. The necessary header files can be included with -I/path/to/Source/CPlusPlus -I/path/to/Source/C.

Next, you need to link your code against NTPoly. To link, we recommend using a Fortrancompiler. The library files are all located in /path/to/Build/lib , and you need to link against all the library files in that directory. The following link line should work -L/path/to/Build/lib -lNTPolyCPP -lNTPolyWrapper -lNTPoly.

Since we are linking C++ code with a Fortran compiler, the basic C++ libraries need to be manually linked. For gfortran -lstdc++ should suffice. For the Intel compiler, you need to use -cxxlib -nofor_main.

As with Fortran code, openmp is a requirement, so be sure to pass the appropriate compiler flags.

The only necessary step for linking your python code is to set the environment variable PYTHONPATH to include /path/to/Build/python.

If you encounter difficulties with python, check to make sure there aren't multiple versions of python on your computer. Sometimes SWIG will generate python code that is compatible with the wrong version. You can look at the MacBook pro compilation section of this page to learn how to specify which python version NTPoly is linked against.

As a last resort of compilation help, I think the Travis CI build can be instructive. You can read the .travis.yml file to see in detail what steps are performed to compile NTPoly from scratch on Ubuntu Trusty Tahr.

Using aptitude, we install gfortran, the python development environment, doxygen, and cmake. Depending on your version of Linux, you might also be able to install openmpi and swig using aptitude, but we install from source because we need to use newer versions than are in the Trusty Tahr repositories.

We also install scipy, numpy, and mpi4py using pip. From there, we can follow the basic installation instructions using the Linux.cmake toolchain file.