My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Compiling  
This is a tutorial explaining how to build Sunrise and the required libraries.
Phase-Deploy, UserGuide
Updated Dec 27, 2011 by CCHayw...@gmail.com

Necessary prerequisites

To build Sunrise, you first need to get the following 3rd party libraries:

  • The Blitz++ C++ matrix library, current Mercurial version. NOTE that blitz has switched to using Mercurial. Make sure you don't just update the cvs version, as that repo is no longer being used. The blitz repo is here.
  • The cfitsio FITS library. (If you are using a Fedora distribution, it's available as a yum package. On MacOX, you can get it through fink.)
  • The CCfits C++ FITS library, version 2.3 or higher. (Note that Fedora has a package but make sure it's the correct version as otherwise it likely won't work.)
  • The Boost C++ utility library. (If you are using a Fedora distribution, it's available as a yum package. On MacOX, you can get it through fink. It takes a long time to build, so if you can find a prebuild version, you should really do so.) Note that Sunrise requires version 1.40.0 or later.
  • If you want to be able to load Gadget HDF5 files, you need the HDF5 library and the HDF5 C++ library (libhdf5_cpp). (Again, you can get these with yum and fink.)
  • If you want to use the GPU-accelerated version, you need to install the CUDA library and SDK from Nvidia. Sunrise should work with versions 3.2 and higher, but CUDA changes pretty rapidly so it's possible newer versions won't work. Note that you need a compute capability 1.3 or higher device, ie at least a GT200 card. See further notes on building with GPU support at the bottom.

Finally, Sunrise depends on Patrik's utility library. This is now available via Mercurial from bitbucket.com. This library needs the GNU "units" program, in addition to the libraries above. (Actually, it only needs the units.dat file, but the easiest way to get it is to just install the package.)

Compiling Sunrise

Note that you need fairly recent versions of autotools for this to work. I use autoconf 2.61, automake 1.10 and libtool 1.5.24. If you have older and run into trouble, just download them from the gnu site yourself and build them, it takes a few minutes.

In this example, I've used $HOME as the install directory, so that stuff ends up in $HOME/include, $HOME/lib, etc. If you want a different directory, just change the prefix options to configure.

Also, if you are using a nonstandard compiler (ie intel icpc), remember to set the CXX environment variable before you start. Mixing compilers is a recipe for trouble, trust me...

Blitz:

First clone the Mercurial repository, see the SourceForge site for how to do this. (The version 0.9 tar file does NOT work, it's way old.)

NOTE If you are using the trunk as of Sept 2011, or the soon-to-be-released 3.04 version, you need to use the most recent version of blitz, which has switched to using Mercurial. Make sure you don't just update the cvs version, as that repo is no longer being used. Also note that this version of blitz is not backwards-compatible with Sunrise 3.03, and vice versa.

 autoreconf -fiv
 export CXX=icpc
 export CXXFLAGS='-g -O2 -pthread'
 export LDFLAGS=-pthread
 ./configure --prefix=$HOME --enable-threadsafe --disable-cxx-flags-preset
 make lib
 make install

The current version of blitz can use atomic data types from the Intel TBB library instead of mutex locking to make the array reference counts thread safe. If you have TBB installed, you can enable this with --with-tbb and get a slight performance increase.

cfitsio

Untar the files and do:

 export CFLAGS='-pthread -O3'
 export CC=icc
 ./configure --prefix=$HOME
 make
 make install

CCfits

Extract sources to a directory named CCfits (otherwise there will be trouble..)

 export CXXFLAGS='-pthread -O3'
 ./configure --prefix=$HOME --with-cfitsio=$HOME
 make
 make install

(Sometimes I've run into a weird error when linking the library with icpc. If it fails with something like _dso_locate in the message, and the link line has a bunch of gcc-3.3.3 or 3.4 .o files in it, libtool is confused and thinks that you are compiling with an old gcc. In that case you'll have to manually link by pasting the link line and removing all the .o files, and then copy the library which is in .libs/ to where you want it. Then copy the include files (all .h files and the file called just CCfits) to $PREFIX/include/CCfits/.)

Boost:

Download Boost from SourceForge. Cd to the directory where you put the distribution and do

./bootstrap.sh --without-libraries=python --with-toolset=intel-linux --prefix=$HOME --libdir=$HOME/lib/boost_1_41_0 --includedir=$HOME/include/boost_1_41_0
./bjam install

This will copy the Boost headers to $HOME/include/boost_1_41_0/boost and will build the libraries and put them in $HOME/lib/boost_1_41_0. You obviously need to set the toolset to whatever compiler you'll be using, see the "getting started" instructions "getting started" for more info or if you run into trouble.

If you use the above commands, Boost will install its include files in a directory $PREFIX/include/boost-<version>/boost. For the files to be found without specifically adding that directory to the include directives, I suggest you do ln -s $PREFIX/include/boost-<version>/boost $PREFIX/include/boost.

Note that the current Sunrise trunk requires Boost 1.40.0 or later.

HDF5

If you want HDF5 support and you can't get a package with the library, you'll have to build it, too. Don't forget to include C++ support.

./configure --enable-cxx --prefix=$HOME
make
make install

libPJutil:

First get libPJutil from bitbucket by doing hg clone https://bitbucket.org/lutorm/libpjutil. (It is usually fine to use the most recent version of this, as it doesn't change much.) Then go into this directory and do:

autoreconf -fiv
export CPPFLAGS=-I$HOME/include (or wherever you need it to point to find blitz; also use "-pthread" if you use it for blitz)
export CXXFLAGS="-O2 -pthread"
export LDFLAGS=-L$HOME/lib (or wherever)
./configure --prefix=$HOME --with-boost=$HOME (if boost is in $HOME/include and $HOME/lib)
make
make install

If your boost install is in some funny place, you can also use --with-boost-libdir=xxx to help the compiler find the libraries.

This library now contains an embedded copy of the GNU "units" program for units conversion. For this to work, the path to the file "units.dat" needs to be defined in the environment variable UNITSFILE. On standard linux systems, this file is in /usr/share/, so in that case you would add

export UNITSFILE=/usr/share/units.dat

to your bash_profile. If you don't have GNU units installed, you need to download it and put this file somewhere.

Sunrise:

Finally. Get sources from the repository. In general you should check out the current version, which is mentioned on the front page, not the trunk. The trunk may be unstable at any given time.

autoreconf -fiv

Then I usually make a little file called "build" that sets the config options because I have to redo it pretty often. It contains:

export CPPFLAGS="-I$HOME/include -I$HOME/include/libPJutil" (yes, you need to separately specify the libPJutil directory, sorry)
export CXXFLAGS="-ggdb  -O3"
export LDFLAGS="-L$HOME/lib"
export CXX=g++
./configure --prefix=$HOME --with-boost=$HOME (optionally: --with-boost-thread=mt --with-boost-program-options=mt)

The arguments to the --with-boost-xxx options depends on your compiler and system. These days the default boost install seems to install the libraries with no specific suffix, in which case you should only need --with-boost=xxx.

If you get a configure error that says something cryptic like "Error: could not link against!", it's not finding the boost libraries. Look in the directory where the boost libraries are located and you'll find libboost-thread-<yaddayadda>-<.so-stuff>. The <yaddayadda> is what you specify here, it can be blank, or gcc/it depending on which compiler you used. The --with-boost option obviously should point to the directory that contains the boost include and lib directories. If you run into trouble, search the Sunrise discussions and also the boost mail lists.

One final note: By default, Sunrise uses a lot of assertions to make sure nothing goes awry. This takes extra time. If you are doing a bunch of big runs, once you have made sure that it will run correctly, you can add -DNDEBUG to your CXXFLAGS. This will remove all assertions and can make the code run up to twice as fast.

TCmalloc

As most C++ programs, Sunrise allocates lots of very small objects on the heap. The standard system malloc/free calls are quite slow and do not scale well with large numbers of threads concurrently allocating, because it has to make use of a global mutex.

The TCmalloc library (Thread-caching malloc) implements a replacement malloc where each thread can allocate small objects without using any locks. Using this library results in a modest performance increase. The configure script searches for libtcmalloc_minimal and uses it if found, so just make sure the path to the library is in your LDFLAGS.

GPU acceleration

If you have a machine with a CUDA-enabled GPU with compute model 1.3 or later (GT200 and on), you can make use of it for the dust emission calculation with the option "--enable-cuda". This functionality is not extensively tested, but I believe it works on both CUDA version 3.2 and 4.0. You must also define the NVCXXFLAGS environment variable so that nvcc can find the location of the CUDA SDK. You also need to add the path to the SDK and CUDA libraries, so the build instructions then look like:

export CPPFLAGS="-I$HOME/include -I$HOME/include/libPJutil -I/usr/local/cuda/sdk/common/inc"
export CXXFLAGS="-ggdb  -O3"
export LDFLAGS="-L$HOME/lib -L/usr/local/cuda/sdk/lib -L/usr/local/cuda/lib"
export CXX=g++
export NVCXXFLAGS="-arch=sm_13 -I/usr/local/cuda/sdk/common/inc"
./configure --prefix=$HOME --with-boost-thread=mt --with-boost-program-options=mt --with-cuda

(The arch=sm_13 option is necessary.) Note to actually use the GPU it is also necessary to set the keyword "use_cuda" to true in the mcrx config file.

Finally, it's time to compile:

make
make install

success! (hopefully...) If you encounter problems, please let us know (and update the wiki).

Arepo

For processing Arepo snapshots directly in the Voronoi mesh, you need to use --enable-arepo when configuring Sunrise and make sure the paths to libarepo.a and the header files are in your LDFLAGS and CPPFLAGS, respectively. You also need to make sure the libraries needed by Arepo (like HDF5, fftw and MPI) are present. For more hints about using Arepo, see RunningWithArepo.

Additional hints

The old recommendation to not use -O3 with icpc no longer applies. There was a bug in the Blitz library that caused this problem which I have since fixed. -O3 should now work fine, whether it makes things significantly faster is more debatable.


Sign in to add a comment
Powered by Google Project Hosting