GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
functional_semisync.hpp
Go to the documentation of this file.
1 
29 #ifndef GRAPHCHI_FUNCTIONAL_SEMISYNC_DEF
30 #define GRAPHCHI_FUNCTIONAL_SEMISYNC_DEF
31 
32 #include <assert.h>
33 
34 
35 #include "api/graph_objects.hpp"
36 #include "api/graphchi_context.hpp"
38 
39 #include "metrics/metrics.hpp"
40 #include "graphchi_types.hpp"
41 
42 namespace graphchi {
43 
44 template <typename KERNEL>
45 class functional_vertex_unweighted_semisync : public graphchi_vertex<typename KERNEL::VertexDataType, typename KERNEL::EdgeDataType> {
46 public:
47 
48  typedef typename KERNEL::VertexDataType VT;
49  typedef typename KERNEL::EdgeDataType ET;
50 
51  VT cumval;
52 
53  KERNEL kernel;
54  vertex_info vinfo;
55  graphchi_context * gcontext;
56 
58 
59  functional_vertex_unweighted_semisync(graphchi_context &ginfo, vid_t _id, int indeg, int outdeg) :
60  graphchi_vertex<VT, ET> (_id, NULL, NULL, indeg, outdeg) {
61  vinfo.indegree = indeg;
62  vinfo.outdegree = outdeg;
63  vinfo.vertexid = _id;
64  cumval = kernel.reset();
65  gcontext = &ginfo;
66  }
67 
69  graphchi_edge<ET> * iptr,
70  graphchi_edge<ET> * optr,
71  int indeg,
72  int outdeg) {
73  assert(false); // This should never be called.
74  }
75 
76  void first_iteration(graphchi_context &gcontext_) {
77  this->set_data(kernel.initial_value(gcontext_, vinfo));
78  }
79 
80  // Optimization: as only memshard (not streaming shard) creates inedgers,
81  // we do not need atomic instructions here!
82  inline void add_inedge(vid_t src, ET * ptr, bool special_edge) {
83  if (gcontext->iteration > 0) {
84  cumval = kernel.plus(cumval, kernel.op_neighborval(*gcontext, vinfo, src, *ptr));
85  }
86  }
87 
88  void ready(graphchi_context &gcontext_) {
89  this->set_data(kernel.compute_vertexvalue(gcontext_, vinfo, cumval));
90  }
91 
92  inline void add_outedge(vid_t dst, ET * ptr, bool special_edge) {
93  *ptr = kernel.value_to_neighbor(*gcontext, vinfo, dst, this->get_data());
94  }
95 
96  bool computational_edges() {
97  return true;
98  }
99 
100  /* Outedges do not need to be read, they just need to be written */
101  static bool read_outedges() {
102  return false;
103  }
104 
105 
106 };
107 
108 
109 
110 template <typename KERNEL>
111  class FunctionalProgramProxySemisync : public GraphChiProgram<typename KERNEL::VertexDataType, typename KERNEL::EdgeDataType, functional_vertex_unweighted_semisync<KERNEL> > {
112  public:
113  typedef typename KERNEL::VertexDataType VertexDataType;
114  typedef typename KERNEL::EdgeDataType EdgeDataType;
116 
120  void before_iteration(int iteration, graphchi_context &info) {
121  }
122 
126  void after_iteration(int iteration, graphchi_context &ginfo) {
127  }
128 
132  void before_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &ginfo) {
133  }
134 
138  void update(fvertex_t &v, graphchi_context &ginfo) {
139  if (ginfo.iteration == 0) {
140  v.first_iteration(ginfo);
141  } else {
142  v.ready(ginfo);
143  }
144  }
145 
146 };
147 
148 }
149 
150 
151 #endif
152 
153