Skip to content

How to Install Boost

K M Masum Habib edited this page Oct 6, 2016 · 1 revision

This article is collected from Dr. Masum Habib's personal [site] [site]: http://masumhabib.com/how-to-install-the-boost-library-with-mpi-and-without-root-access/ "How to Install the Boost Library with MPI and without Root Access"

Boost is huge collection of C++ libraries. It is complementary to the standard C++ library. Like all other libraries, you’ll need root access to install the Boost library on Unix and Unix like systems. If you are not the system admin, you can compile and install it in your home folder. In this tutorial I’ll show how to compile and install Boost in your home directory without root access.

Boost library has a C++ wrapper (boost::mpi) for lower level MPI routines. By default, the MPI libraries are not enabled in boost. In this tutorial, we will discuss how to enable and compile boost::mpi or any other libraries that needs compilation.

In this tutorial I assume that you are familiar with command line and GNU/Linux. The following procedure should be similar in other Unix like operating systems.

Download the latest version of boost source code from here, put it under /home/username/usr/src folder and untar the archive.

#!bash
cd ~/usr/src/
tar -xvf boost_1_56_0.tar.gz

A new folder named boost_1_56_0 will be created. To configure boost for your host/cluster, change directory to boost_1_56_0 and use bootstrap.sh command.

#!bash
cd boost_1_56_0
./bootstrap.sh --help
./bootstrap.sh --show-libraries

In order to install Boost in your home directory, use --prefix option for bootstrap.sh. You can enable or disable libraries using --with-libraries or --without-libraries options, respectively. To build Boost with MPI, use:

#!bash
./bootstrap.sh --prefix=/home/username/usr --with-libraries=mpi

If you want to build everything issue the following command:

#!bash
./bootstrap.sh --prefix=/home/username/usr --without-libraries=

To compile boost::mpi, we need to find out the MPI wrapper for C++ compiler (mpic++). The mpic++ script comes with MPICH2 (and probably with OpenMPI) library. To find the path of mpic++, issue the following command:

#!bash
which mpic++

In standard GNU/Linux installations, mpic++ is located at either /usr/local/bin or /usr/bin. To build MPI add full path to mpic++ or just mpic++ at the end of boost_1_56_0/project-config.jam file:

#!bash
# MPI
using mpi : /usr/bin/mpic++ ;
#!bash
# MPI
using mpi : mpic++ ;

Configuration is done, let’s make and install it:

#!bash
./b2 install | tee install.log

the log will be saved in install.log file so that you can go back and check if something goes wrong.

Boost libraries will be installed in /home/username/usr/lib and the header files will be installed in /home/username/usr/include/boost folder.

Include boost in your program using:

#include <boost/mpi.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/split_free.hpp>
namespace mpi = boost::mpi;

etc. To compile your program, you will need to add - I/home/username/usr/include option while invoking the compiler.

Note for compiling Boost.MPI with OpenMPI

Due to a bug in OpenMPI, the python wrapper of Boost.MPI ( import mpi) does not work. Fortunately there is a workaround. Add the following lines to your python script before importing mpi:

import DLFCN as dl
import sys
sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)  

# now import mpi
import mpi