PHASTA/Compiling PHASTA With CMake

From PHASTA Wiki
(Redirected from Compiling PHASTA With CMake)
Jump to: navigation, search
NOTE: This page is quite out of date. See the README.md in phasta repository for more up-to-date instructions

There is an unofficial, but popular version of the PHASTA solver which uses a [CMake] based build system. Generally, an out-of-source build is used, meaning that you have a separate directory for your executables and intermediate files.

Assuming you have your desired compiler and a current version of CMake (2.8.5 or newer) in your path, you must first create and change into an empty directory to store your build

 mkdir build
 cd build

You can then run cmake to create your makefile

If you're using the Intel compiler suite: WARNING: The Intel compilers on the viz nodes are outdated and broken. They are maintained only for use with MKL. If you need the Intel toolchain please talk to Ken and/or Ben

 CC=icc CXX=icpc FC=ifort ccmake ../phasta

If you're using the PGI compiler suite:

 CC=pgcc CXX=pgCC FC=pgfortran ccmake ../phasta

If you're using the GNU toolchain:

 CC=gcc CXX=g++ FC=gfortran ccmake ../phasta

If you're using the Clang toolchain for C and C++:

 CC=clang CXX=clang++ FC=gfortran ccmake ../phasta

This will open a "GUI" of sorts. You can use the arrow keys to navigate. Press enter to edit the highlighted field, and then enter again to save your change. Press the "c" key to compute the options. Press "g" to write out the makefile and quit. You'll need to press "c" several times, and fill in any desired options before you can generate your makefile.

You may want to set the "CMAKE_BUILD_TYPE" field to either "Release" or "Debug" to get an optimized build or a debugable build respectively.

Once you've completed this process, you can simply run "make" to build the code. The executable will be in the "bin" sub-directory of your build directory.

 make

Tips

on the viz nodes, run "soft add +cmake" to get an appropriate version of CMake.

on Janus, run "module load cmake" to get an appropriate version of CMake

If you run into trouble, it may be useful to see how the compiler is being invoked. You can do this by running:

 make VERBOSE=1

(after having already run cmake)

To add additional compiler flags, use the CMAKE_C_FLAGS, CMAKE_CXX_FLAGS and CMAKE_Fortran_FLAGS fields when you configure


The build options are in a (somewhat) human readable format in a file called "CMakeCache.txt" in the root of your build directory - this can be very useful if you need to figure out which options were used for a particular build.

If you add a new file, you need to tell CMake that the source has changed (this is not usually necessary if you've simply edited an existing source file). You can do this as follows (from your build directory):

 touch CMakeCache.txt

CMake uses the MPI wrappers to find your MPI install by default - mpicc and mpif90 must be in your PATH prior to running ccmake

If you'd like to use CMake in a non-interactive fashion, you can use "cmake" instead of "ccmake" and specify and options on the command line by prepending them with "-D". For example:

 cmake -DCMAKE_BUILD_TYPE=Release -DPHASTA_INCOMPRESSIBLE=ON -DACUSOLVE_LIB=$HOME/libles.a ../phasta
 make

The incompressible solver is disabled by default. You'll need to set the PHASTA_INCOMPRESSIBLE option to "ON" and specify the full path to the Acusolve library when prompted.


A fairly generic version of PHASTA, which includes this build system, can be found on the viz nodes in /users/matthb2/phasta-tocmake/phasta


CMake supports generating scripts for other build tools, for example Xcode, Eclipse and Ninja. See the "cmake" manpage for more information.

Some compilers which can perform inter-procedural analysis have a hard time with PHASTA. See the Compilers page for information on disabling this optimization if linking takes too long

Cross Compiling with CMake

CMake can cross compile PHASTA, for example on a BlueGene or Cray system. To do this, you simply need to provide an appropriate toolchain file specifying the path to the cross compilers and then build as normal.

 ccmake -DCMAKE_TOOLCHAIN_FILE=some_file.cmake ../phasta

There are some toolchain files for systems that we commonly use available [here] (note that the BlueGene/Q toolchain files provided here expect a [patched version] of CMake -- see below)

Kitware has some documentation on cross compiling with CMake [here].

Also ensure that the MPI wrappers for the target platform are in your PATH (on mira: "soft add +mpiwrapper-xl", q.ccni: "module load xl") or specified explicitly in your toolchain file.

Cross Compiling on IBM's BlueGene/Q

Currently, CMake doesn't officially have explicit support for BlueGene/Q (BlueGene/P is supported). While you should be able to use a toolchain file expecting one of the generic system types, we've modified the BG/P platform files for /Q, based on the setup used on [ALCF's] systems (should work with most /Q systems). To use them, you need to add two files [1] [2] to your CMake install. For a normal install, these files should be placed in $prefix/share/cmake-2.8/Modules/Platform/

If you prefer, you can just directly install the "bgq" branch of [this repository]

 git clone https://github.com/matthb2/CMake.git
 git checkout -b bgq origin/bgq
 cd CMake
 ./configure --prefix=/some/path
 make
 make install
 export PATH=/some/path:$PATH

You can then proceed as above, using [this toolchain file


Currently, the system software is changing very quickly. If you need a build of the proprietary library used for PHASTA's incompressible solver, please ask Ben or Michel (and tell them which Bluegene driver version you have)

With gprof

(gnu compilers)

 CC=gcc CXX=g++ FC=gfortran ccmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-pg" -DCMAKE_CXX_FLAGS="-pg" -DCMAKE_Fortran_FLAGS="-pg" ../phasta