forked from GraphChi/graphchi-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_dynamicengine_smoketest.cpp
More file actions
152 lines (125 loc) · 4.84 KB
/
Copy pathbasic_dynamicengine_smoketest.cpp
File metadata and controls
152 lines (125 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* @file
* @author Aapo Kyrola <[email protected]>
* @version 1.0
*
* @section LICENSE
*
* Copyright [2012] [Aapo Kyrola, Guy Blelloch, Carlos Guestrin / Carnegie Mellon University]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @section DESCRIPTION
*
* Simple smoketest for the dynamic graph graphchi engine.
*/
#include <string>
#include "graphchi_basic_includes.hpp"
#include "engine/dynamic_graphs/graphchi_dynamicgraph_engine.hpp"
using namespace graphchi;
/**
* Type definitions. Remember to create suitable graph shards using the
* Sharder-program.
*/
typedef vid_t VertexDataType;
typedef vid_t EdgeDataType;
/**
* Smoke test. On every iteration, each vertex sets its id to be
* id + iteration number. Vertices check whether their neighbors were
* set correctly. This assumes that the vertices are executed in round-robin order.
*/
struct SmokeTestProgram : public GraphChiProgram<VertexDataType, EdgeDataType> {
/**
* Vertex update function.
*/
void update(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if (gcontext.iteration == 0) {
for(int i=0; i < vertex.num_outedges(); i++) {
vertex.outedge(i)->set_data(vertex.id());
}
} else {
for(int i=0; i < vertex.num_inedges(); i++) {
graphchi_edge<vid_t> * edge = vertex.inedge(i);
vid_t inedgedata = edge->get_data();
vid_t expected = edge->vertex_id() + gcontext.iteration - (edge->vertex_id() > vertex.id());
if (inedgedata != expected) {
assert(false);
}
}
for(int i=0; i < vertex.num_outedges(); i++) {
vertex.outedge(i)->set_data(vertex.id() + gcontext.iteration);
}
}
vertex.set_data(gcontext.iteration + 1);
}
/**
* Called before an iteration starts.
*/
void before_iteration(int iteration, graphchi_context &gcontext) {
}
/**
* Called after an iteration has finished.
*/
void after_iteration(int iteration, graphchi_context &gcontext) {
}
/**
* Called before an execution interval is started.
*/
void before_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &gcontext) {
}
/**
* Called after an execution interval has finished.
*/
void after_exec_interval(vid_t window_st, vid_t window_en, graphchi_context &gcontext) {
}
};
/**
* Vertex callback that checks the vertex data is ok.
*/
class VertexDataChecker : public VCallback<VertexDataType> {
int iters;
public:
size_t total;
VertexDataChecker(int iters) : iters(iters), total(0) {}
void callback(vid_t vertex_id, VertexDataType &vecvalue) {
assert(vecvalue == iters);
total += iters;
}
};
int main(int argc, const char ** argv) {
/* GraphChi initialization will read the command line
arguments and the configuration file. */
graphchi_init(argc, argv);
/* Metrics object for keeping track of performance counters
and other information. Currently required. */
metrics m("smoketest-dynamic-engine");
/* Basic arguments for application */
std::string filename = get_option_string("file"); // Base filename
int niters = get_option_int("niters", 4); // Number of iterations
bool scheduler = false; // Whether to use selective scheduling
/* Detect the number of shards or preprocess an input to creae them */
int nshards = convert_if_notexists<EdgeDataType>(filename,
get_option_string("nshards", "auto"));
/* Run */
SmokeTestProgram program;
graphchi_dynamicgraph_engine<VertexDataType, EdgeDataType> engine(filename, nshards, scheduler, m);
engine.run(program, niters);
/* Check also the vertex data is ok */
VertexDataChecker vchecker(niters);
foreach_vertices(filename, 0, engine.num_vertices(), vchecker);
assert(vchecker.total == engine.num_vertices() * niters);
/* Report execution metrics */
metrics_report(m);
logstream(LOG_INFO) << "Dynamic Engine Smoketest passed successfully! Your system is working!" << std::endl;
return 0;
}