-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_graphone_bugfixes.cpp
168 lines (138 loc) · 5.45 KB
/
test_graphone_bugfixes.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Copyright (C) 2019 Dean De Leo, email: dleo[at]cwi.nl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "gtest/gtest.h"
#if defined(HAVE_GRAPHONE)
#include <cstdlib>
#include <iostream>
#include <memory>
#include <thread>
#include <vector>
#include "common/system.hpp"
#include "configuration.hpp"
#include "graph/edge.hpp"
#include "graph/edge_stream.hpp"
#if defined(HAVE_LLAMA) // to cross check with the implementation of LLAMA
#include "library/llama/llama_class.hpp"
#include "library/llama-dv/llama-dv.hpp"
#endif
#include "library/graphone/graphone.hpp"
#include "utility/graphalytics_validate.hpp"
// Log to stdout
#undef LOG
#define LOG(message) { std::cout << "\033[0;32m" << "[ ] " << "\033[0;0m" << message << std::endl; }
using namespace common::concurrency;
using namespace gfe::graph;
using namespace gfe::library;
using namespace std;
[[maybe_unused]] static std::unique_ptr<gfe::graph::WeightedEdgeStream> generate_edge_stream(uint64_t max_vector_id = 8){
vector<gfe::graph::WeightedEdge> edges;
for(uint64_t i = 1; i < max_vector_id; i++){
for(uint64_t j = i + 2; j < max_vector_id; j+=2){
edges.push_back(gfe::graph::WeightedEdge{i, j, static_cast<double>(j * 1000 + i)});
}
}
return make_unique<gfe::graph::WeightedEdgeStream>(edges);
}
// Get the path to non existing temporary file
[[maybe_unused]] static string temp_file_path(){
char pattern[] = "/tmp/gfe_XXXXXX";
int fd = mkstemp(pattern);
if(fd < 0){ ERROR("Cannot obtain a temporary file"); }
close(fd); // we're going to overwrite this file anyway
return string(pattern);
}
#if defined(HAVE_LLAMA)
/**
* Check whether the results of GraphOne for the PageRank yield the same results of LLAMA, as they rely on the same algorithm
*/
TEST(GraphOne, PageRank) {
LLAMAClass llama { /* directed = */ false };
GraphOne graphone { /* directed = */ false, /* vertex dict = */ true, /* blind writes = */ true, /* ignore build = */ false, /* GAP BS impl ?*/ false, /* num vertices */ 64 * 1024 * 1024 };
uint64_t num_vertices = 128;
LOG("Init stream");
auto stream = generate_edge_stream(num_vertices);
stream->permute();
LOG("Insert vertices ...")
for(uint64_t i = 1; i < num_vertices; i++){
llama.add_vertex(i);
graphone.add_vertex(i);
}
LOG("Insert edges ...");
for(uint64_t i =0; i < stream->num_edges(); i++){
auto edge = stream->get(i);
llama.add_edge(edge);
graphone.add_edge(edge);
}
LOG("Build ...");
llama.build();
graphone.build();
// llama.dump();
// graphone.dump();
auto llama_results = temp_file_path();
LOG("LLAMA PageRank: " << llama_results);
uint64_t num_iterations = 1;
llama.pagerank(num_iterations, 0.85, llama_results.c_str());
auto graphone_results = temp_file_path();
LOG("GraphOne PageRank: " << graphone_results);
graphone.pagerank(num_iterations, 0.85, graphone_results.c_str());
LOG("Validate the result ...");
gfe::utility::GraphalyticsValidate::pagerank(graphone_results, llama_results);
LOG("Validation succeeded");
}
#endif
TEST(GraphOne, ConcurrentUpdates) {
GraphOne graphone { /* directed = */ false, /* vertex dict = */ true, /* blind writes = */ true, /* ignore build = */ false, /* GAP BS impl ?*/ false, /* num vertices */ 64 * 1024 * 1024 };
uint64_t num_vertices = 1<<14;
uint64_t num_threads = 8;
LOG("Init stream");
auto stream = generate_edge_stream(num_vertices);
stream->permute();
LOG("Insert " << num_vertices << " vertices ... ");
for(uint64_t i = 1; i < num_vertices; i++){
graphone.add_vertex(i);
}
LOG("Insert " << stream->num_edges() << " edges with " << num_threads << " threads ...");
auto worker_insert = [&graphone, &stream](uint64_t start, uint64_t end){
for(uint64_t i = start; i < end; i++){
auto edge = stream->get(i);
graphone.add_edge(edge);
}
};
uint64_t partition_sz = stream->num_edges() / num_threads;
uint64_t partition_mod = stream->num_edges() % num_threads;
uint64_t partition_start = 0;
vector<thread> workers;
for(uint64_t i = 0; i < num_threads; i++){
uint64_t partition_end = partition_start + partition_sz + (i < partition_mod);
workers.emplace_back(worker_insert, partition_start, partition_end);
partition_start = partition_end; // next iteration
}
for(auto& w: workers) w.join();
workers.clear();
LOG("Num levels (before build): " << graphone.num_levels());
LOG("Build ...");
graphone.build();
LOG("Num levels (after build): " << graphone.num_levels());
// It's enough it does not end with a seg fault...
LOG("Done");
}
#else
#include <iostream>
TEST(GraphOne, Disabled) {
std::cout << "Tests disabled as the build does not contain the support for GraphOne." << std::endl;
}
#endif