FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
graphchi-cpp/example_apps/application_template.cpp at master · GraphChi/graphchi-cpp · GitHub
GraphChi
graphchi-cpp
Repository navigation
Code
Issues
25
(25)
Pull requests
8
(8)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
graphchi-cpp
/
example_apps
/
application_template.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
139 lines (111 loc) · 4.37 KB
Breadcrumbs
graphchi-cpp
/
example_apps
/
application_template.cpp
Copy path
File metadata and controls
139 lines (111 loc) · 4.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
*
* @file
* @author Aapo Kyrola <akyrola@cs.cmu.edu>
* @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
*
* Template for GraphChi applications. To create a new application, duplicate
* this template.
*/
#
include
<
string
>
#
include
"
graphchi_basic_includes.hpp
"
using
namespace
graphchi
;
/*
*
* Type definitions. Remember to create suitable graph shards using the
* Sharder-program.
*/
typedef
my_vertex_type VertexDataType;
typedef
my_edge_type EdgeDataType;
/*
*
* GraphChi programs need to subclass GraphChiProgram<vertex-type, edge-type>
* class. The main logic is usually in the update function.
*/
struct
MyGraphChiProgram
:
public
GraphChiProgram
<VertexDataType, EdgeDataType> {
/*
*
* Vertex update function.
*/
void
update
(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if
(ginfo.
iteration
==
0
) {
/*
On first iteration, initialize vertex (and its edges). This is usually required, because
on each run, GraphChi will modify the data files. To start from scratch, it is easiest
do initialize the program in code. Alternatively, you can keep a copy of initial data files.
*/
//
vertex.set_data(init_value);
}
else
{
/*
Do computation
*/
/*
Loop over in-edges (example)
*/
for
(
int
i=
0
; i < vertex.
num_inedges
(); i++) {
//
Do something
//
value += vertex.inedge(i).get_data();
}
/*
Loop over out-edges (example)
*/
for
(
int
i=
0
; i < vertex.
num_outedges
(); i++) {
//
Do something
//
vertex.outedge(i).set_data(x)
}
/*
Loop over all edges (ignore direction)
*/
for
(
int
i=
0
; i < vertex.
num_edges
(); i++) {
//
vertex.edge(i).get_data()
}
//
v.set_data(new_value);
}
}
/*
*
* 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) {
}
};
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
(
"
my-application-name
"
);
/*
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 =
get_option_int
(
"
scheduler
"
,
0
);
//
Whether to use selective scheduling
/*
Detect the number of shards or preprocess an input to create them
*/
int
nshards = convert_if_notexists<EdgeDataType>(filename,
get_option_string
(
"
nshards
"
,
"
auto
"
));
/*
Run
*/
MyGraphChiProgram program;
graphchi_engine<VertexDataType, EdgeDataType>
engine
(filename, nshards, scheduler, m);
engine.
run
(program, niters);
/*
Report execution metrics
*/
metrics_report
(m);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL