0
我想通过使用boost mpi传递更复杂的数据类型。我正在实施示例代码http://theboostcpplibraries.com/boost.mpi-simple-data-exchange如何使用boost_mpi发送字符串类型?
首先,我尝试发送一个字符串作为字符数组,它可以从上述示例47.5中学习。的代码是:
#include <boost/mpi.hpp>
#include <iostream>
int main(int argc, char *argv[])
{
boost::mpi::environment env{argc, argv};
boost::mpi::communicator world;
if (world.rank() == 0)
{
char buffer[14];
world.recv(boost::mpi::any_source, 16, buffer, 13);
buffer[13] = '\0';
std::cout << buffer << '\n';
}
else
{
const char *c = "Hello, world!";
world.send(0, 16, c, 13);
}
}
我可以编译并用下面的命令细运行它:
mpic++ -std=c++0x 3.cpp -o 3 -lboost_mpi
mpiexec -np 3 ./3
然后,我试图改变类型的字符串(从相同的教程实施例47.5):
#include <boost/mpi.hpp>
#include <boost/serialization/string.hpp>
#include <string>
#include <iostream>
int main(int argc, char *argv[])
{
boost::mpi::environment env{argc, argv};
boost::mpi::communicator world;
if (world.rank() == 0)
{
std::string s;
world.recv(boost::mpi::any_source, 16, s);
std::cout << s << '\n';
}
else
{
std::string s = "Hello, world!";
world.send(0, 16, s);
}
}
当我编译和链接这段代码,我得到了以下错误:
> /usr/bin/ld: /tmp/ccRNu1AY.o: undefined reference to symbol '_ZTIN5boost7archive6detail14basic_iarchiveE'
> //usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.54.0: error adding symbols: DSO missing from command line
> collect2: error: ld returned 1 exit status
任何帮助将不胜感激。
奏效!谢谢。 如何在未来遇到与其他mpi函数类似的问题时列出boost库? – Mehrdad