Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Graph I/O and Utility Tools

Graph Input and Output

Reading Graphs

Read in graphs by using galois::graphs::readGraph, which expects the following parameters:

The file representing the graph should be a binary representation consistent with the in-memory representation of the graph object to be loaded in. An example can be seen in lonestar/tutorial_examples/GraphTraversalSerial.cpp:

Graph g;
galois::graphs::readGraph(g, argv[1]); // argv[1] is the file name for graph

If you want to load a .gr (binary Galois graph) into your own graph types, then you need to read in graphs through galois::graphs::FileGraph. Specifically, use galois::graphs::FileGraph::fromFile to mmap a binary format of graphs into a galois::graphs::FileGraph object, and then construct your graph from the galois::graphs::FileGraph object. galois::graphs::LC_CSR_Graph::constructFrom implements exactly this functionality for galois::graphs::LC_CSR_Graph.

Writing Graphs

Use galois::graphs::FileGraph::toFile to write a galois::graphs::FileGraph to a binary file. Use galois::graphs::FileGraphWriter to construct a galois::graphs::FileGraph by the following steps:

  1. Set the number of nodes by calling galois::graphs::FileGraphWriter::setNumNodes.
  2. Set the number of edges by calling galois::graphs::FileGraphWriter::setNumEdges.
  3. Set the size of edge data by calling galois::graphs::FileGraphWriter::setSizeofEdgeData.
  4. Call galois::graphs::FileGraphWriter::phase1 to allocate space for arrays of row pointers, edge destination and edge data.
  5. Set the degree of each node by calling galois::graphs::FileGraphWriter::incrementDegree for each node.
  6. Call galois::graphs::FileGraphWriter::phase2 to calculate the prefix sum of node degree to have row pointers.
  7. Add edges by calling galois::graphs::FileGraphWriter::addNeighbor for each edge. The function returns for the edge the index into the edge destination array, which can be used to maintain the edge data array if required.
  8. Call galois::graphs::FileGraphWriter::finish to get a pointer which points to the memory location where the edge data can be saved. Copy the edge data array to the space pointed by the pointer.

Utility Tools for Graphs

Tools to Convert Graphs Among Different Formats

Use graph-convert in the directory of tools/graph-convert to convert the graph files among different formats. Launch graph-convert with -help parameter will give the detailed parameters for converting and supported formats. In particular, graph-convert can convert a few ASCII-format graph files, e.g. edge list, into binary format which can be directly loaded in by galois::graphs::readGraph or galois::graphs::FileGraph::fromFile.

Tools to Get Graph Statistics

Use graph-stats in the directory of tools/graph-stats to get the statistics of a given graph in .gr format (Galois binary graph). Launch graph-stats with -help parameter to get the detailed parameters for reporting statistics, e.g. number of nodes and edges, out-degree/in-degree histogram, etc.