我正在通过修改“/apps/boost_1_56_0/libs/graph/test”中的代码“serialize.cpp”并尝试通过 boost MPI 通过网络发送一个 boost graph 对象来进行测试。
它编译得很好,但是当我使用 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;
} ^
最佳答案
也许这只是部分地解决了问题,但这里是:
Q. @sehe I use the bundled properties, they are not automatically serialized from what I have tested. – user3658306 1 hour ago
A. 不正确:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/random.hpp>
#include <random>
static std::mt19937 prng { std::random_device{} () };
std::string random_word(int len=7) {
std::string s;
static std::uniform_int_distribution<> chars('a', 'z');
generate_n(back_inserter(s), len, bind(chars, ref(prng)));
return s;
}
struct Vertex {
std::string name = random_word();
template <typename Ar> void serialize(Ar& ar, unsigned) { ar & BOOST_SERIALIZATION_NVP(name); }
};
struct Edge {
std::string label = random_word();
template <typename Ar> void serialize(Ar& ar, unsigned) { ar & BOOST_SERIALIZATION_NVP(label); }
};
using namespace boost;
using Graph = adjacency_list<vecS, vecS, undirectedS, Vertex, Edge>;
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <iostream>
int main() {
Graph g;
generate_random_graph(g, 20, 40, prng);
boost::archive::xml_oarchive oa(std::cout);
oa << BOOST_SERIALIZATION_NVP(g);
}
以 XML 形式完成属性打印随机图,例如:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="12">
<g class_id="0" tracking_level="0" version="0">
<V>20</V>
<E>40</E>
<vertex_property class_id="1" tracking_level="0" version="0">
<name>pjfpjir</name>
</vertex_property>
<vertex_property>
<name>yimnobr</name>
</vertex_property>
<vertex_property>
<name>wshvrpl</name>
</vertex_property>
<vertex_property>
<name>lckoymw</name>
</vertex_property>
<vertex_property>
<name>bqovgzi</name>
</vertex_property>
<vertex_property>
<name>thxvqzm</name>
</vertex_property>
<vertex_property>
<name>aczdbtl</name>
</vertex_property>
<vertex_property>
<name>mqwayyk</name>
</vertex_property>
<vertex_property>
<name>xarqhaq</name>
</vertex_property>
<vertex_property>
<name>qsismjs</name>
</vertex_property>
<vertex_property>
<name>makkpqi</name>
</vertex_property>
<vertex_property>
<name>ekklaes</name>
</vertex_property>
<vertex_property>
<name>cxyzrhz</name>
</vertex_property>
<vertex_property>
<name>xetrxco</name>
</vertex_property>
<vertex_property>
<name>flwqnns</name>
</vertex_property>
<vertex_property>
<name>dlzoglu</name>
</vertex_property>
<vertex_property>
<name>viumusv</name>
</vertex_property>
<vertex_property>
<name>bktdobe</name>
</vertex_property>
<vertex_property>
<name>pxsoxdj</name>
</vertex_property>
<vertex_property>
<name>cldlbtp</name>
</vertex_property>
<u>15</u>
<v>4</v>
<edge_property class_id="2" tracking_level="0" version="0">
<label>zssnhpu</label>
</edge_property>
<u>17</u>
<v>0</v>
<edge_property>
<label>pzivbjs</label>
</edge_property>
<u>1</u>
<v>0</v>
<edge_property>
<label>ueeoqft</label>
</edge_property>
<u>9</u>
<v>7</v>
<edge_property>
<label>jdidntq</label>
</edge_property>
<u>8</u>
<v>4</v>
<edge_property>
<label>tfpvuqx</label>
</edge_property>
<u>2</u>
<v>10</v>
<edge_property>
<label>ccycjyf</label>
</edge_property>
<u>19</u>
<v>12</v>
<edge_property>
<label>bcuuatp</label>
</edge_property>
<u>5</u>
<v>12</v>
<edge_property>
<label>okezxdc</label>
</edge_property>
<u>0</u>
<v>5</v>
<edge_property>
<label>qxugnbw</label>
</edge_property>
<u>5</u>
<v>1</v>
<edge_property>
<label>sxerbxx</label>
</edge_property>
<u>1</u>
<v>4</v>
<edge_property>
<label>diziick</label>
</edge_property>
<u>19</u>
<v>7</v>
<edge_property>
<label>lufsvfb</label>
</edge_property>
<u>19</u>
<v>3</v>
<edge_property>
<label>siwrshv</label>
</edge_property>
<u>13</u>
<v>3</v>
<edge_property>
<label>rtiihnd</label>
</edge_property>
<u>18</u>
<v>17</v>
<edge_property>
<label>nllpszz</label>
</edge_property>
<u>15</u>
<v>7</v>
<edge_property>
<label>qbvxdtx</label>
</edge_property>
<u>12</u>
<v>14</v>
<edge_property>
<label>zyclorw</label>
</edge_property>
<u>10</u>
<v>3</v>
<edge_property>
<label>xdjhxht</label>
</edge_property>
<u>10</u>
<v>0</v>
<edge_property>
<label>hwanuvt</label>
</edge_property>
<u>5</u>
<v>12</v>
<edge_property>
<label>nzrwayu</label>
</edge_property>
<u>4</u>
<v>12</v>
<edge_property>
<label>nselbtl</label>
</edge_property>
<u>7</u>
<v>8</v>
<edge_property>
<label>eflgiho</label>
</edge_property>
<u>19</u>
<v>6</v>
<edge_property>
<label>kadepsb</label>
</edge_property>
<u>9</u>
<v>4</v>
<edge_property>
<label>xfpiijv</label>
</edge_property>
<u>15</u>
<v>19</v>
<edge_property>
<label>aooxlov</label>
</edge_property>
<u>8</u>
<v>1</v>
<edge_property>
<label>kaemqfa</label>
</edge_property>
<u>14</u>
<v>12</v>
<edge_property>
<label>fxkcjma</label>
</edge_property>
<u>10</u>
<v>2</v>
<edge_property>
<label>urewqkq</label>
</edge_property>
<u>0</u>
<v>18</v>
<edge_property>
<label>vdskttr</label>
</edge_property>
<u>6</u>
<v>9</v>
<edge_property>
<label>ejlncwe</label>
</edge_property>
<u>2</u>
<v>3</v>
<edge_property>
<label>upsbqeq</label>
</edge_property>
<u>1</u>
<v>9</v>
<edge_property>
<label>hdsmlsg</label>
</edge_property>
<u>17</u>
<v>2</v>
<edge_property>
<label>okiovwn</label>
</edge_property>
<u>10</u>
<v>16</v>
<edge_property>
<label>pbutvzu</label>
</edge_property>
<u>5</u>
<v>4</v>
<edge_property>
<label>szuhnuf</label>
</edge_property>
<u>10</u>
<v>11</v>
<edge_property>
<label>sztnmxa</label>
</edge_property>
<u>7</u>
<v>16</v>
<edge_property>
<label>pxknohn</label>
</edge_property>
<u>1</u>
<v>2</v>
<edge_property>
<label>ezmuunb</label>
</edge_property>
<u>6</u>
<v>16</v>
<edge_property>
<label>jtzsxfv</label>
</edge_property>
<u>16</u>
<v>15</v>
<edge_property>
<label>ijnaybi</label>
</edge_property>
<graph_property class_id="3" tracking_level="0" version="0"></graph_property>
</g>
</boost_serialization>
现在我们已经揭穿了其中一个假设,也许我们可以弄清楚应该如何使用 MPI 发送/接收(提示:可能不使用手动序列化)
关于c++ - 通过 boost :MPI got error 发送一个简单的 boost 图形对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641226/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信