how to save graph in adj format?

User 270 | 5/5/2014, 3:09:34 AM

I want to write an APP to convert a directed graph to an undirected graph.

The input format is adj, which means "vid nunofneighbors neighbor0 neighbor1 ..."

The output format I desired is directed adj, which means "vid numofincomingneighbors inneighbor0 inneighbor1 ... numofoutcomingneighbors outneighbor0 outneighbor1 ..."

I find I can load a graph using loadformat function and pass "adj" as a parameter. However, how can I store a graph using adj format? Is there a method to iterate all the incoming and outgoing edges when implementing savevertex function?



User 6 | 5/5/2014, 5:25:01 AM

If I got you correctly you wan to convert an undirected graph into directed (and not as you wrote). GraphLab's savevertex and saveedge are not guaranteed to have the ordering you like to have. I suggest writing an update function that will go over each node and save the edges. You will need to run using --ncpus=1 for not writing in parallel into the same file. It will be fairly easy to do so with the warp engine:

User 270 | 5/5/2014, 5:38:50 AM

Oh, sorry for my previous statement, fortunately, you got me right.

In my understanding, I have to disable multi-threading in graphlab. However, if I want to do some heavy computation before writing the results to HDFS, then I have to lose multi-threading in the computation, right?

Thanks for your reply.

User 6 | 5/5/2014, 5:45:20 AM

Hi, GraphLab assumes the graph is known before computation. You can write one graphlab program that saves the graph in another format and then another graphlablab program that does computation on the output graph in parallel.

User 270 | 5/5/2014, 6:28:57 AM

Give the following function definition: void pagerankupdatefunction(enginetype::context& context, graphtype::vertex_type vertex);

I do not quite understand how to save edges in the update function. Do I need to stored edge inforation on vertex first? Thanks

User 6 | 5/5/2014, 9:39:00 AM

Hi, I did not compile this code, unless there are minor typos it should work

struct pagerankwriter { std::string savevertex(graphtype::vertextype v) { std::stringstream strm; strm << << "\t"; warp::tranformneighborhood(vertex, INEDGES, tranform_function, strm); return strm.str(); }

void tranformfunction(graphtype::edgetype edge, graphtype::vertex_type other, std::stringstream & strm ) { return strm << << "\t"; }