我正在通过修改“/apps/boost_1_56_0/libs/graph/test”中的代码“serialize.cpp”并尝试通过boost MPI通过网络发送boost图对象来进行测试。
它编译得很好,但是当我使用 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;
} ^