无法编译简单的Boost MPI示例 [英] Unable to compile simple Boost MPI example

查看:93
本文介绍了无法编译简单的Boost MPI示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过以下代码将MPI与C ++ Boost结合使用:

I was trying to use MPI with C++ Boost using the following code:

#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() << "on " << world.size() << "." << std::endl;
  return 0;
}

我已经编译并安装了boost mpi:

And I have boost mpi compiled and installed:

 ~ ls /usr/local/include/boost | grep mpi
mpi
mpi.hpp
~ ls /usr/local/lib | grep mpi   
libboost_mpi.a
libboost_mpi.so
libboost_mpi.so.1.62.0

 ~ ls /usr/local/lib | grep serialization                                                                                 
libboost_serialization.a
libboost_serialization.so
libboost_serialization.so.1.62.0
libboost_wserialization.a
libboost_wserialization.so
libboost_wserialization.so.1.62.0

使用

mpic++ -L/usr/local/lib -I/usr/local/include/boost/mpi -lboost_mpi-gcc-mt-1_35 -lboost_serialization MPIBoostBindingExample.cpp -o MPIBoostBindingExample

但仍然有错误提示:

/tmp/ccKVwnKR.o: In function `main':
MPIBoostBindingExample.cpp:(.text+0x27): undefined reference to `boost::mpi::environment::environment(bool)'
MPIBoostBindingExample.cpp:(.text+0x33): undefined reference to `boost::mpi::communicator::communicator()'
MPIBoostBindingExample.cpp:(.text+0x3f): undefined reference to `boost::mpi::communicator::size() const'
MPIBoostBindingExample.cpp:(.text+0x4d): undefined reference to `boost::mpi::communicator::rank() const'
MPIBoostBindingExample.cpp:(.text+0xb8): undefined reference to `boost::mpi::environment::~environment()'
MPIBoostBindingExample.cpp:(.text+0xeb): undefined reference to `boost::mpi::environment::~environment()'
collect2: error: ld returned 1 exit status

有帮助吗?

推荐答案

如果我只添加 -lboost_mpi ,对我有用(Ubuntu 16.04).

Works for me (Ubuntu 16.04) if I just add -lboost_mpi.

您的代码(进行少量修改):

Your code (modulo minor edits):

edd@max:/tmp$ cat boostmpi.cpp 
#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() 
            << " on " << world.size() << "." << std::endl;
  return 0;
}
edd@max:/tmp$ 

我们只是使用上述库进行编译(默认情况下, mpic ++ 不知道)

And we just compile with the aforementioned library (which mpic++ does not know about by default)

edd@max:/tmp$ mpic++ -o boostmpi boostmpi.cpp -lboost_mpi
edd@max:/tmp$ orterun ./boostmpi
I am process 2 on 4.
I am process 3 on 4.
I am process 0 on 4.
I am process 1 on 4.
edd@max:/tmp$ 

Boost标头和其他库具有系统"状态,即可以通过附加的 -I -L 标志进行访问.

This is helped by the fact that Boost headers and other libraries have 'system' status, ie are accessible with additional -I or -L flags.

这篇关于无法编译简单的Boost MPI示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆