Grappa  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Grappa::Graph< V, E > Struct Template Reference

Distributed graph data structure, with customizable vertex and edge data. More...

#include <Graph.hpp>

Classes

struct  Edge
 

Public Types

using Vertex = impl::Vertex< V, E >
 
using EdgeState = E
 

Public Member Functions

 Graph (GlobalAddress< Graph > self, GlobalAddress< Vertex > vs, int64_t nv)
 
 ~Graph ()
 
void destroy ()
 
template<int LEVEL = 0, typename F = nullptr_t>
void dump (F print_vertex)
 
template<typename VV , typename F = decltype(nullptr)>
GlobalAddress< Graph< VV, E > > transform (F f)
 Change the data associated with each vertex, keeping the same connectivity structure and allowing the user to intialize the new data type using the old vertex. More...
 
VertexID id (Vertex &v)
 
Edge edge (Vertex &v, size_t i)
 

Static Public Member Functions

template<int LEVEL = 0>
static void dump (GlobalAddress< Graph > g)
 
static GlobalAddress< Graphcreate (const TupleGraph &tg, bool directed=false, bool solo_invalid=true)
 Construct a distributed adjacency-list Graph. More...
 
static GlobalAddress< GraphUndirected (const TupleGraph &tg)
 
static GlobalAddress< GraphDirected (const TupleGraph &tg)
 

Public Attributes

GlobalAddress< Vertexvs
 
int64_t nv
 
int64_t nadj
 
int64_t nadj_local
 
VertexIDadj_buf
 
EdgeStateedge_storage
 
void * scratch
 
GlobalAddress< Graphself
 

Detailed Description

template<typename V = Empty, typename E = Empty>
struct Grappa::Graph< V, E >

Distributed graph data structure, with customizable vertex and edge data.

This is Grappa's primary graph data structure. Graph is a symmetric data structure, so a Graph proxy object will be allocated on all cores, providing local access to common data and methods to access the entirety of the graph.

The Graph class defines two types based on the specified template parameters: Vertex and Edge. Vertex holds information about an individual vertex, such as the degree (nadj), and the associated data whose type is specified by the V template parameter. Edge holds the two global addresses to its source and destination vertices, as well as data associated with this edge, of the type specified by the E parameter.

A typical use of Graph will define a custom graph type, construct it, and then use the returned symmetric pointer to refer to the graph, possibly looking something like this:

// define the graph type:
struct VertexData { double rank; };
struct EdgeData { double weight; };
using G = Graph<VertexData,EdgeData>;
// load tuples from a file:
TupleGraph tuples = TupleGraph::Load("twitter.bintsv4", "bintsv4");
// after constructing a graph, we get a symmetric pointer back
GlobalAddress<G> g = G::create(tuples);
// we can easily get info such as the number of vertices out by
// using the local proxy directly through the global address:
LOG(INFO) << "graph has " << g->nv << " vertices";
// or we can use the global address itself as an iterator over vertices:
forall(g, [](G::Vertex& v){ });

Graph Structure

This Graph structure is constructed from a TupleGraph (a simple list of edge tuples – source & dest) using Graph::create().

Vertices are randomly distributed among cores (using a simple global heap allocation). Edges are placed on the core of their source vertex. Therefore, iterating over outgoing edges is very efficient, but a vertex's incoming edges must be found the hard way (in practice, we just avoid doing it entirely if using this graph structure).

Parallel Iterators

A number of parallel iterators are available for Graphs, to iterate over vertices or edges using forall. Specialization is done based on which parameters are requested, sometimes resulting in different iteration schemes.

Full graph iteration:

using G = Graph<VertexData,EdgeData>;
GlobalAddress<G> g = /* initialize graph */;
// simple iteration over vertices
forall(g, [](G::Vertex& v){});
// simple iteration over vertices with index
forall(g, [](VertexID i, G::Vertex& v){});
// iterate over all adjacencies of all vertices
// (at the source vertex and edge, so both may be modified)
forall(g, [](G::Vertex& src, G::Edge& e){ ... });
// (equivalent to)
forall(g, [](G::Vertex& src){
forall(adj(g,src), [](G::Edge& adj){
...
});
});
// iterate over edges from the destination vertex,
// must be **non-blocking**
// (edge no longer modifiable, but a copy is carried along)
forall(g, [](const G::Edge& e, G::Vertex& dst){ ... });

Iteration over adjacencies of single Vertex:

// usually done inside another iteration over vertices, like so:
forall(g, [=](Vertex& v){
// variations exist for constructing a parallel iterator over
// a vertex's outgoing edges (adjacency list, or `adj`):
// - from a Vertex&: adj(g,v)
// - or a VertexID: adj(g, v.id)
// `forall` has various specializations for `adj`, including:
forall<async>(adj(g,v), [&v](Edge& e){
LOG(INFO) << v.id << " -> " << e.id;
});
// or this form, which provides the index within the adj list [0,v.nadj)
forall<async>(adj(g,v), [&v](int64_t ei, Edge& e){
LOG(INFO) << "v.adj[" << ei << "] = " << e.id;
});
});

Definition at line 241 of file Graph.hpp.

Member Typedef Documentation

template<typename V = Empty, typename E = Empty>
using Grappa::Graph< V, E >::EdgeState = E

Definition at line 244 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
using Grappa::Graph< V, E >::Vertex = impl::Vertex<V,E>

Definition at line 243 of file Graph.hpp.

Constructor & Destructor Documentation

template<typename V = Empty, typename E = Empty>
Grappa::Graph< V, E >::Graph ( GlobalAddress< Graph< V, E > >  self,
GlobalAddress< Vertex vs,
int64_t  nv 
)
inline

Definition at line 277 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
Grappa::Graph< V, E >::~Graph ( )
inline

Definition at line 287 of file Graph.hpp.

Member Function Documentation

template<typename V = Empty, typename E = Empty>
void Grappa::Graph< V, E >::destroy ( )
inline

Definition at line 298 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
static GlobalAddress<Graph> Grappa::Graph< V, E >::Directed ( const TupleGraph< V, E > &  tg)
inlinestatic

Definition at line 362 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
template<int LEVEL = 0>
static void Grappa::Graph< V, E >::dump ( GlobalAddress< Graph< V, E > >  g)
inlinestatic

Definition at line 306 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
template<int LEVEL = 0, typename F = nullptr_t>
void Grappa::Graph< V, E >::dump ( print_vertex)
inline

Definition at line 318 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
Edge Grappa::Graph< V, E >::edge ( Vertex v,
size_t  i 
)
inline

Definition at line 368 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
VertexID Grappa::Graph< V, E >::id ( Vertex v)
inline

Definition at line 364 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
template<typename VV , typename F = decltype(nullptr)>
GlobalAddress<Graph<VV,E> > Grappa::Graph< V, E >::transform ( f)
inline

Change the data associated with each vertex, keeping the same connectivity structure and allowing the user to intialize the new data type using the old vertex.

Parameters
fvoid (Vertex<OldData>& v, NewData& d) {}

Example:

struct A { int64_t parent; }
struct B { double value; };
auto gnew = g->transform<B>([](Graph<A>::Vertex& v, B& b){
b.value = v->weight / v.nadj;
});

Definition at line 345 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
static GlobalAddress<Graph> Grappa::Graph< V, E >::Undirected ( const TupleGraph< V, E > &  tg)
inlinestatic

Definition at line 361 of file Graph.hpp.

Member Data Documentation

template<typename V = Empty, typename E = Empty>
VertexID* Grappa::Graph< V, E >::adj_buf

Definition at line 269 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
EdgeState* Grappa::Graph< V, E >::edge_storage

Definition at line 270 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
int64_t Grappa::Graph< V, E >::nadj

Definition at line 266 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
int64_t Grappa::Graph< V, E >::nadj_local

Definition at line 266 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
int64_t Grappa::Graph< V, E >::nv

Definition at line 266 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
void* Grappa::Graph< V, E >::scratch

Definition at line 273 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
GlobalAddress<Graph> Grappa::Graph< V, E >::self

Definition at line 275 of file Graph.hpp.

template<typename V = Empty, typename E = Empty>
GlobalAddress<Vertex> Grappa::Graph< V, E >::vs

Definition at line 256 of file Graph.hpp.


The documentation for this struct was generated from the following file: