4

「/apps/boost_1_56_0/libs/graph/test」のコード「serialize.cpp」を変更し、ブースト MPI を介してネットワーク経由でブースト グラフ オブジェクトを送信することでテストを行っています。

正常にコンパイルされましたが、mpirun を使用して実行可能ファイルを実行すると、次のエラーが発生しました。

terminate called after throwing an instance of 'boost::archive::archive_exception'
    what(): input stream error.

空のバッファを読んでいると思いますが、修正方法がわかりません。

#include <boost/config.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/tuple/tuple.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <map>
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <vector>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>

std::stringstream ss;

struct vertex_properties {
  std::string name;

  template<class Archive>
  void serialize(Archive & ar, const unsigned int /*version*/) {
    ar & BOOST_SERIALIZATION_NVP(name);
  }  
};

struct edge_properties {
  std::string name;

  template<class Archive>
  void serialize(Archive & ar, const unsigned int /*version*/) {
    ar & BOOST_SERIALIZATION_NVP(name);
  }  
};

using namespace boost;

typedef adjacency_list<vecS, vecS, undirectedS, 
           vertex_properties, edge_properties> Graph;

typedef graph_traits<Graph>::vertex_descriptor vd_type;


typedef adjacency_list<vecS, vecS, undirectedS, 
           vertex_properties> Graph_no_edge_property;

int main()
{

  mpi::environment env;
  mpi::communicator world;
  using namespace std;

  if (world.rank() == 0) {

    archive::text_oarchive oa(ss);
    Graph g;
    vertex_properties vp;
    vp.name = "A";
    vd_type A = add_vertex( vp, g );
    vp.name = "B";
    vd_type B = add_vertex( vp, g );
    edge_properties ep;
    ep.name = "a";
    add_edge( A, B, ep, g);

    oa << BOOST_SERIALIZATION_NVP(g);

    world.send(1, 0, g);

  } else if (world.rank() == 1) { 

    archive::text_iarchive ia(ss);
    Graph g;
    ia >> BOOST_SERIALIZATION_NVP(g);

    if  (!( g[*(vertices( g ).first)].name == "A" )) return -1;

    world.recv(0, 0, g);
    cout << "number of vertices received from graph g is " <<  
     num_vertices(g) << " edges is " << num_edges(g) << endl; 
  }
  return 0;
}                                                    ^
4

1 に答える 1