Compiling QHG

In this documentation we describe compilation with a gnu c++ compiler. QHG4 has been compiled and tested on several linux flavours, but so far not on Windows or Mac.

If anybody manages to compile and run QHG4 on Windows computer or on a Mac please let us know

Dependencies

To compile and run QHG4, several libraries need to be installed:

  • libm: the math library (is usually already installed)

  • the HDF5 library to handle HDF files

  • zlib library for zipping and unzipping

  • crypto library

Library Installation for gentoo linux:

sudo emerge sci-libs/hdf5 sys-libs/zlib dev-libs/openssl sci-libs/gsl media-libs/libpng

Library Installation for CentOS:

sudo yum install zlib-devel.x86_64
sudo yum install openssl-devel.x86_64
sudo yum install hdf5-devel.x86_64 hdf5.x86_64
sudo yum install gsl-devel.x86_64 gsl.x86_64

Library Installation for ubuntu:

sudo apt-get install zlib1g-dev libssl-dev
sudo apt-get install libgsl0-dev
sudo apt-get install libhdf5-serial-dev

For some tools to work the python modules h5py, netcdf4-python, and numpy are required.

Installing module for gentoo:

sudo emerge dev-python/h5py
sudo emerge dev-python/netcdf4-python
sudo emerge dev-python/numpy

Installing modules for CentOS

sudo yum install h5py.x86_64
sudo yum install numpy.x86_64
sudo yum install netcdf4-python.x86_64

Installing modules for ubuntu

sudo apt-get install libhdf5-dev
sudo apt-get install python3-numpy
sudo apt-get install python-netcdf4

Required Environment Variables

Make sure that the vairable QHG4_DIR is set to the root of the directory containing the QHG4 download.

On the commandline this can be done by

export QHG4_DIR=/home/user17/progs/QHG4

But this would have to be done every time a new terminal is opened. For this reason, it makes more sense to put this line into a file which is executed when a shell is opened (e.g. ~/.bash_rc for bash shells)

Compile targets

There are various targets to compile:

clean

Clean all directories.

QHGMain

The QHG simulator.

plugins

Build populaztion plugins.

tools_n

Recompile all tools.

Example

make QHGMain

Only compiles new and depending files and builds QHGMain.

make clean QHGMain

Compiles QHG from scratch.

Compile options

OPT

If set to 1, optimize the compilation (-O3). Recognized by all targets.

SHORT

Sets the prefix for alternative population and action directories. Used by targets QHGMain and plugins.

OUT

Sets the output name. Used by targets QHGMain and plugins

DYNAMIC_POPS

Creates a version of QHGMain without statically linked actions or populations, which can load plugins. To run actual simulations you must provide it with compiled plugins (see “make plugins” below). Used by target QHGMain

Examples

OUT=QHGTest OPT=1 make clean QHGMain

Build an optimized QHG from scratch and name the executable QHGTest

SHORT=tut OPT=1 make clean QHGMain

Build an optimized QHG from scratch, but use the alternative population and action directories tut_pop and tut_mod.

DYNAMIC_POPS=1 OPT=1 make clean QHGMain

Build an optimized QHG for the use with plugins from scratch.

SHORT=tut_08 make plugins

Build plugins for the populations found in the alternative compilation directory tut_08.

Alternative Populations and Action Directories

If there are many files for population classes in the populations subdirectory, it can be useful to set up alternative directories containing only the minimum number of files required to build QHG with a particular population class.

There is a script in the subdirectory useful_stuff which you can use for this:

${QHG4_DIR}/build_alt_modpop.py <prefix> <pop_name>+

prefix is used to create the names of the alternatove directories, pop_name is the name of a population class in populations. The script expects that <pop_name>.h and <pop_name>.cpp exist in populations

Example:

build_alt_modpop.py tut tut_StaticPop tut_MovePop

This will create the directories tut_pop and tut_mod which are filled with the required files from actions and population:

$ ls tut_mod/
Action.cpp  Action.h  GetOld.cpp  GetOld.h  Makefile  OldAgeDeath.cpp  OldAgeDeath.h  RandomMove.cpp  RandomMove.h
$ ls tut_pop/
DynPopFactory.cpp  DynPopFactory.h  ids.cpp  ids.h_for_configure  Makefile  PopulationFactory.h  StatPopFactory.cpp_for_configure  StatPopFactory.h  tut_MovePop.cpp  tut_MovePop.h  tut_StaticPop.cpp  tut_StaticPop.h

Now you can compile QHGMain like this:

SHORT=tut make clean QHGMain