Reputation: 16240
I am trying to run the basic "Hello, World!" example:
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <iostream>
namespace mpi = boost::mpi;
int main()
{
mpi::environment env;
mpi::communicator world;
std::cout << "I am process " << world.rank() << " of " << world.size()
<< "." << std::endl;
return 0;
}
I have tried numerous variants for running this program:
mpic++ -I /usr/local/include/ test.cpp -o test -lboost_system
also:
mpic++ -I /usr/local/include/boost test.cpp -o test -lboost_system
and using mpicc
, and clang++
as a substitute. Each combination gives the follow error:
Undefined symbols for architecture x86_64:
"boost::mpi::environment::environment(bool)", referenced from:
_main in test-b0215f.o
"boost::mpi::environment::~environment()", referenced from:
_main in test-b0215f.o
"boost::mpi::communicator::communicator()", referenced from:
_main in test-b0215f.o
"boost::mpi::communicator::rank() const", referenced from:
_main in test-b0215f.o
"boost::mpi::communicator::size() const", referenced from:
_main in test-b0215f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Homebrew says that both MPICH2 and boost1.63.0 are installed. I can confirm that mpic++
runs by compiling and then running this program:
// required MPI include file
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
int numtasks, rank, len, rc;
char hostname[MPI_MAX_PROCESSOR_NAME];
// initialize MPI
MPI_Init(&argc,&argv);
// get number of tasks
MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
// get my rank
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
// this one is obvious
MPI_Get_processor_name(hostname, &len);
printf ("Number of tasks= %d My rank= %d Running on %s\n", numtasks,rank,hostname);
// do some work with message passing
// done with MPI
MPI_Finalize();
}
Which produces the correct output.
I have also verified that (at least part of) Boost is installed by compiling and successfully running the Boost "Hello, World!"
//
// timer.cpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello, world!" << std::endl;
return 0;
}
with:
clang++ -I /usr/local/include/ timer.cpp -o timer -lboost_system
How can I get the Boost.MPI example to run?
Upvotes: 0
Views: 837
Reputation: 1731
When you get linker errors from boost, you usually forgot to link against a boost library.
There is also a boost_mpi library, so you should compile with
clang++ -I /usr/local/include/ timer.cpp -o timer -lboost_system -lboost_mpi
Note that you need a boost version with support for mpi.
Upvotes: 1