将输出写入Graphchi中的文件 [英] writing output to a file in Graphchi

查看:133
本文介绍了将输出写入Graphchi中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Graphchi中写了一个最短路径代码,我想把它的输出打印在一个文件中。我试图使用示例中显示的模板,但如果使用与其他示例相同的方式写入文件,则会出错。
我在这里卡住了。作为输出,我只是想打印(顶点id,它距离源头的最小距离)。
我该怎么做。

解决方案

下面是如何将所有顶点的值输出到控制台的示例。很容易修改它将输出写入文件。请注意,如果您可以处理二进制文件,GraphChi已经在文件中包含顶点值:.B.vout,其中sizeof(VertexDataType)。
$ b $ 1您需要定义一个回调函数,它将采用顶点id和值作为参数

  class OutputVertexCallback:public VCallback< VertexDataType> {
public:

virtual void callback(vid_t vertex_id,VertexDataType& value){
std :: cout<< vertex_id<< =<<值<<的std :: ENDL;
}
};



<2>然后你需要调用foreach_vertices()来得到输出:

  OutputVertexCallback回调; 
foreach_vertices< VertexDataType>(filename,0,engine.num_vertices(),callback);


I wrote a shortest path code in Graphchi and I wanted to print the output of that in a file. I was trying to use the template shown in the examples but I get error if I use the sameway of writing to a file as in other examples. I have got stuck here. As the output I just want to print (vertex id,its minimum distance from source). How can i do that.

解决方案

Here is example how you can output values of all vertices to the console. It is easy to modify it to write the output to a file. Note that if you can handle binary files, GraphChi already has the vertex values in a file: .B.vout, where is sizeof(VertexDataType).

1) You need to define a callback-function, which will take vertex id and value as parameter

class OutputVertexCallback : public VCallback<VertexDataType> {
public:

virtual void callback(vid_t vertex_id, VertexDataType &value) {
  std::cout << vertex_id << "=" << value << std::endl;
}
 };

2) Then you need to call foreach_vertices() as follows to get the output:

OutputVertexCallback callback;
foreach_vertices<VertexDataType>(filename, 0, engine.num_vertices(), callback);

这篇关于将输出写入Graphchi中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆