GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
functional_bulksync.hpp
Go to the documentation of this file.
1 
35 #ifndef GRAPHCHI_FUNCTIONAL_BULKSYNC_DEF
36 #define GRAPHCHI_FUNCTIONAL_BULKSYNC_DEF
37 
38 #include <assert.h>
39 
40 
41 #include "api/graph_objects.hpp"
42 #include "api/graphchi_context.hpp"
44 
45 #include "metrics/metrics.hpp"
46 #include "graphchi_types.hpp"
47 
48 namespace graphchi {
49 
50  template <typename KERNEL>
51  class functional_vertex_unweighted_bulksync : public graphchi_vertex<typename KERNEL::VertexDataType, PairContainer<typename KERNEL::EdgeDataType> > {
52  public:
53 
54  typedef typename KERNEL::VertexDataType VT;
56 
57  KERNEL kernel;
58 
59  VT cumval;
60 
61  vertex_info vinfo;
62  graphchi_context * gcontext;
63 
65 
66  functional_vertex_unweighted_bulksync(graphchi_context &ginfo, vid_t _id, int indeg, int outdeg) :
67  graphchi_vertex<VT, ET> (_id, NULL, NULL, indeg, outdeg) {
68  vinfo.indegree = indeg;
69  vinfo.outdegree = outdeg;
70  vinfo.vertexid = _id;
71  cumval = kernel.reset();
72  gcontext = &ginfo;
73  }
74 
76  graphchi_edge<ET> * iptr,
77  graphchi_edge<ET> * optr,
78  int indeg,
79  int outdeg) {
80  assert(false); // This should never be called.
81  }
82 
83  void first_iteration(graphchi_context &ginfo) {
84  this->set_data(kernel.initial_value(ginfo, vinfo));
85  gcontext = &ginfo;
86  }
87 
88  // Optimization: as only memshard (not streaming shard) creates inedgers,
89  // we do not need atomic instructions here!
90  inline void add_inedge(vid_t src, ET * ptr, bool special_edge) {
91  if (gcontext->iteration > 0) {
92  cumval = kernel.plus(cumval, kernel.op_neighborval(*gcontext,
93  vinfo,
94  src,
95  ptr->oldval(gcontext->iteration)));
96  }
97  }
98 
99  void ready(graphchi_context &ginfo) {
100  this->set_data(kernel.compute_vertexvalue(*gcontext, vinfo, cumval));
101  }
102 
103  inline void add_outedge(vid_t dst, ET * ptr, bool special_edge) {
104  typename KERNEL::EdgeDataType newval =
105  kernel.value_to_neighbor(*gcontext, vinfo, dst, this->get_data());
106  ET paircont = *ptr;
107  paircont.set_newval(gcontext->iteration, newval);
108  *ptr = paircont;
109  }
110 
111  bool computational_edges() {
112  return true;
113  }
114 
119  static bool read_outedges() {
120  return true;
121  }
122  };
123 
124 
125 
126  template <typename KERNEL>
127  class FunctionalProgramProxyBulkSync : public GraphChiProgram<typename KERNEL::VertexDataType, PairContainer<typename KERNEL::EdgeDataType>, functional_vertex_unweighted_bulksync<KERNEL> > {
128  public:
129 
130  typedef typename KERNEL::VertexDataType VertexDataType;
133 
137  void before_iteration(int iteration, graphchi_context &info) {
138  }
139 
143  void after_iteration(int iteration, graphchi_context &ginfo) {
144  }
145 
149  void before_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &ginfo) {
150  }
151 
152 
156  void update(fvertex_t &v, graphchi_context &ginfo) {
157  if (ginfo.iteration == 0) {
158  v.first_iteration(ginfo);
159  } else {
160  v.ready(ginfo);
161  }
162 
163  }
164 
165  };
166 
167 }
168 
169 
170 #endif
171