gpt4 book ai didi

c++ - 如何使用 boost_mpi 发送字符串类型?

转载 作者:行者123 更新时间:2023-11-28 05:39:09 26 4
gpt4 key购买 nike

<分区>

我正在尝试使用 boost mpi 传递更复杂的数据类型。我正在执行 http://theboostcpplibraries.com/boost.mpi-simple-data-exchange 中的示例代码

首先,我尝试将字符串作为字符数组发送,这在上述教程示例 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

如有任何帮助,我们将不胜感激。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com