编译简单 boot_mpi 分散程序时出错:没有序列化元素

Posted

技术标签:

【中文标题】编译简单 boot_mpi 分散程序时出错:没有序列化元素【英文标题】:Error during compiling of simple boot_mpi scatter program: no serialize element 【发布时间】:2021-01-09 14:19:45 【问题描述】:

我目前正在评估一个简单的程序,该程序允许将行/字符串的数组/向量分散到多个进程中。我创建了一个无法编译的简单测试程序。我希望有人可以帮助我找到解决方案。这是程序:

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

namespace mpi = boost::mpi;

int main(int argc, char* argv[])

  mpi::environment env(argc, argv);
  mpi::communicator world;

  std::vector< std::vector < std::string > > all (3, std::vector < std::string >());
  std::vector< std::string > mine;
  
  if (world.rank() == 0) 
    all[0].push_back("String1");
    all[0].push_back("String2");
    all[1].push_back("String3");
    all[1].push_back("String4");
    all[2].push_back("String5");
    all[2].push_back("String6");

  
  mpi::scatter(world, all, mine, 0);
  for (int r = 0; r < world.size(); ++r) 
    world.barrier();
    if (r == world.rank()) 
      std::cout << "Rank " << r << " got " << mine[0] << std::endl;
    
  
  return 0;

我尝试了以下两个命令来编译它:

mpic++ scatter_mini.cpp -o scatter_mpi -lboost_mpi
mpic++ scatter_mini.cpp -o scatter_mpi -lboost_mpi -lboost_serialization

两者都会导致相同的错误,我在这里给你一个简短的版本(德语抱歉):

/usr/include/boost/serialization/access.hpp: In Instanziierung von »static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::mpi::packed_iarchive; T = std::vector<std::__cxx11::basic_string<char> >]«:
/usr/include/boost/serialization/serialization.hpp:68:22:   erfordert durch »void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::mpi::packed_iarchive; T = std::vector<std::__cxx11::basic_string<char> >]«
/usr/include/boost/serialization/serialization.hpp:118:14:   erfordert durch »void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::mpi::packed_iarchive; T = std::vector<std::__cxx11::basic_string<char> >]«
/usr/include/boost/archive/detail/iserializer.hpp:187:40:   erfordert durch »void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::mpi::packed_iarchive; T = std::vector<std::__cxx11::basic_string<char> >]«
/usr/include/boost/archive/detail/iserializer.hpp:121:1:   erfordert durch »class boost::archive::detail::iserializer<boost::mpi::packed_iarchive, std::vector<std::__cxx11::basic_string<char> > >«
/usr/include/boost/archive/detail/iserializer.hpp:409:27:   erfordert durch »static void boost::archive::detail::load_non_pointer_type<Archive>::load_standard::invoke(Archive&, const T&) [with T = std::vector<std::__cxx11::basic_string<char> >; Archive = boost::mpi::packed_iarchive]«
/usr/include/boost/archive/detail/iserializer.hpp:461:22:   [ 5 Instanziierungskontexte werden übersprungen, »-ftemplate-backtrace-limit=0« zum Ausschalten verwenden ]
/usr/include/boost/archive/detail/interface_iarchive.hpp:68:36:   erfordert durch »Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = std::vector<std::__cxx11::basic_string<char> >; Archive = boost::mpi::packed_iarchive]«
/usr/include/boost/mpi/collectives/scatter.hpp:124:14:   erfordert durch »void boost::mpi::detail::dispatch_scatter_sendbuf(const boost::mpi::communicator&, const buffer_type&, const std::vector<int>&, const T*, T*, int, int) [with T = std::vector<std::__cxx11::basic_string<char> >; boost::mpi::binary_buffer_oprimitive::buffer_type = std::vector<char, boost::mpi::allocator<char> >]«
/usr/include/boost/mpi/collectives/scatter.hpp:143:27:   erfordert durch »void boost::mpi::detail::scatter_impl(const boost::mpi::communicator&, const T*, T*, int, int, mpl_::false_) [with T = std::vector<std::__cxx11::basic_string<char> >; mpl_::false_ = mpl_::bool_<false>]«
/usr/include/boost/mpi/collectives/scatter.hpp:159:23:   erfordert durch »void boost::mpi::scatter(const boost::mpi::communicator&, const T*, T&, int) [with T = std::vector<std::__cxx11::basic_string<char> >]«
/usr/include/boost/mpi/collectives/scatter.hpp:168:27:   erfordert durch »void boost::mpi::scatter(const boost::mpi::communicator&, const std::vector<T>&, T&, int) [with T = std::vector<std::__cxx11::basic_string<char> >]«
scatter_mini.cpp:28:35:   von hier erfordert
/usr/include/boost/serialization/access.hpp:116:11: Fehler: »class std::vector<std::__cxx11::basic_string<char> >« hat kein Element namens »serialize«

我很确定我已经安装了所有必要的软件包,我还可以编译其他 boost mpi 程序,尤其是那些来自 boost mpi 教程/示例的程序。

【问题讨论】:

您可能缺少包含 &lt;boost/serialization/string.hpp&gt;&lt;boost/serialization/vector.hpp&gt; 标头。 是的,就是这样,谢谢... 我会把它写成答案,这样你就可以关闭这篇文章了。 (我之前不确定它是否能解决问题。) 【参考方案1】:

您的代码缺少必要的标头。尝试添加:

#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>

【讨论】:

以上是关于编译简单 boot_mpi 分散程序时出错:没有序列化元素的主要内容,如果未能解决你的问题,请参考以下文章

微信小程序开发出错,求指点!

为 ARM 交叉编译应用程序时与 sdl 链接时出错

尝试编译二叉树程序时出错

使用VS2013调试C语言时出错,连简单的Hello World都报错,调试时显示无法启动程序,无法访问

运行可执行文件时编译着色器时出错

arduino提示找不到编译器