FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
graphchi-cpp/example_apps/convert_to_adjacency.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
/
convert_to_adjacency.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
130 lines (106 loc) · 3.79 KB
Breadcrumbs
graphchi-cpp
/
example_apps
/
convert_to_adjacency.cpp
Copy path
File metadata and controls
130 lines (106 loc) · 3.79 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
/*
*
* @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
*
* Simple program that writes a graph into adjacency list
*/
#
include
<
iostream
>
#
include
"
graphchi_basic_includes.hpp
"
using
namespace
graphchi
;
/*
*
* Type definitions. Remember to create suitable graph shards using the
* Sharder-program.
*/
typedef
bool
VertexDataType;
typedef
bool
EdgeDataType;
FILE
* f;
#
define
MODE_ADJLIST
0
#
define
MODE_CASSOVARY_ADJ
1
int
mode;
struct
AdjConverter
:
public
GraphChiProgram
<VertexDataType, EdgeDataType> {
/*
*
* Vertex update function.
*/
void
update
(graphchi_vertex<VertexDataType, EdgeDataType> &vertex, graphchi_context &gcontext) {
if
(vertex.
id
() %
10000
==
0
) std::cout << vertex.
id
() << std::endl;
switch
(mode) {
case
MODE_ADJLIST
: {
fprintf
(f,
"
%d %d
"
, vertex.
id
(), vertex.
num_outedges
());
for
(
int
i=
0
; i<vertex.
num_outedges
(); i++)
fprintf
(f,
"
%d
"
, vertex.
outedge
(i)->
vertex_id
());
fprintf
(f,
"
\n
"
);
break
;
}
case
MODE_CASSOVARY_ADJ
: {
fprintf
(f,
"
%d %d
\n
"
, vertex.
id
(), vertex.
num_outedges
());
for
(
int
i=
0
; i<vertex.
num_outedges
(); i++)
fprintf
(f,
"
%d
\n
"
, vertex.
outedge
(i)->
vertex_id
());
break
;
}
}
}
/*
*
* 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
(
"
adjconverter
"
);
/*
Basic arguments for application
*/
std::string filename =
get_option_string
(
"
file
"
);
//
Base filename
/*
Detect the number of shards or preprocess an input to create them
*/
int
nshards = convert_if_notexists<EdgeDataType>(filename,
get_option_string
(
"
nshards
"
,
"
auto
"
));
mode =
get_option_int
(
"
mode
"
,
0
);
std::string outfile = filename +
"
.adj
"
;
f =
fopen
(outfile.
c_str
(),
"
w
"
);
/*
Run
*/
AdjConverter program;
graphchi_engine<VertexDataType, EdgeDataType>
engine
(filename, nshards,
false
, m);
engine.
set_exec_threads
(
1
);
engine.
run
(program,
1
);
fclose
(f);
/*
Report execution metrics
*/
metrics_report
(m);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL