cmake: linking software to boost::mpi (with mpich2)

2.5k views Asked by At

For this simple code (taken from the boost-mpi documentation):

#include <boost/serialization/string.hpp>
#include <iostream>
#include <string>
#include <boost/mpi.hpp>

namespace mpi = boost::mpi;

int main(int argc, char *argv[])
{
    mpi::environment env(argc, argv);
    mpi::communicator world;

    if (world.rank() == 0) {
      world.send(1, 0, std::string("Hello"));
      std::string msg;
      world.recv(1, 1, msg);
      std::cout << msg << "!" << std::endl;
    } else if (world.rank() == 1) {
      std::string msg;
      world.recv(0, 0, msg);
      std::cout << msg << ", ";
      std::cout.flush();
      world.send(0, 1, std::string("world"));
    };

  return 0;
};

And for such CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(mpi-tests CXX)
FIND_PACKAGE(Boost 1.4 COMPONENTS mpi serialization REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})

It cannot find boost_mpi:

CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1135 (message):
  Unable to find the requested Boost libraries.
  Boost version: 1.47.0
  Boost include path: /usr/include
  The following Boost libraries could not be found:
          boost_mpi

But! I have installed next packages:

boost-graph-mpich2
boost-mpich2
boost-mpich2-devel
boost-mpich2-python
mpich2
mpich2-devel

Why it can't find? There are a plenty examples over Internet where people use FIND_PACKAGE(Boost 1.4 COMPONENTS mpi REQUIRED).

1

There are 1 answers

0
KlingonJoe On BEST ANSWER

Boost might not be installed in a location that the module FindBoost searches. You can specify the prefix where Boost was installed by setting the variable BOOST_ROOT to your Boost installation prefix.

To your code I would add:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(mpi-tests CXX)
set( BOOST_ROOT "/path/to/boost/install/prefix" )
FIND_PACKAGE(Boost 1.4 COMPONENTS mpi serialization REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})