GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
functional_api.hpp
Go to the documentation of this file.
1 
33 #ifndef GRAPHCHI_FUNCTIONALAPI_DEF
34 #define GRAPHCHI_FUNCTIONALAPI_DEF
35 
36 #include <assert.h>
37 
38 #include "api/graph_objects.hpp"
39 #include "api/graphchi_context.hpp"
41 #include "metrics/metrics.hpp"
42 #include "graphchi_types.hpp"
43 
48 
49 namespace graphchi {
50 
54  template <typename FVertexDataType, typename FEdgeDataType>
56 
57  typedef FVertexDataType VertexDataType;
58  typedef FEdgeDataType EdgeDataType;
59 
61 
62  /* Initial value - on first iteration */
63  virtual VertexDataType initial_value(graphchi_context &info, vertex_info& myvertex) = 0;
64  /* Called before first "gather" */
65  virtual VertexDataType reset() = 0;
66  // Note: Unweighted version, edge value should also be passed
67  // "Gather"
68  virtual EdgeDataType op_neighborval(graphchi_context &info, vertex_info& myvertex, vid_t nbid, EdgeDataType nbval)= 0;
69  // "Sum"
70  virtual EdgeDataType plus(VertexDataType curval, EdgeDataType toadd) = 0;
71  // "Apply"
72  virtual VertexDataType compute_vertexvalue(graphchi_context &ginfo, vertex_info& myvertex, EdgeDataType nbvalsum) = 0;
73  // "Scatter
74  virtual EdgeDataType value_to_neighbor(graphchi_context &info, vertex_info& myvertex, vid_t nbid, VertexDataType myval) = 0;
75  };
76 
77 
78 
93  template <class KERNEL>
94  void run_functional_unweighted_semisynchronous(std::string filename, int niters, metrics &_m) {
96 
97  /* Process input file - if not already preprocessed */
98  int nshards
99  = convert_if_notexists<typename FunctionalProgramProxySemisync<KERNEL>::EdgeDataType>(filename, get_option_string("nshards", "auto"));
101  typename FunctionalProgramProxySemisync<KERNEL>::EdgeDataType,
103  engine(filename, nshards, false, _m);
104 
105 
106  engine.set_modifies_inedges(false); // Important
107  engine.set_modifies_outedges(true); // Important
108  engine.run(program, niters);
109  }
110 
111 
122  template <class KERNEL>
123  void run_functional_unweighted_synchronous(std::string filename, int niters, metrics &_m) {
125  int nshards
126  = convert_if_notexists<typename FunctionalProgramProxyBulkSync<KERNEL>::EdgeDataType>(filename, get_option_string("nshards", "auto"));
130  engine(filename, nshards, false, _m);
131  engine.set_modifies_inedges(false); // Important
132  engine.set_modifies_outedges(true); // Important
133  engine.set_enable_deterministic_parallelism(false); // Bulk synchronous does not need consistency.
134  engine.run(program, niters);
135  }
136 
137 }
138 
139 #endif
140