generated from puzzlef/leiden-communities-openmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cxx
91 lines (74 loc) · 2.42 KB
/
main.cxx
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
#include <utility>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include "inc/main.hxx"
using namespace std;
#pragma region CONFIGURATION
#ifndef TYPE
/** Type of edge weights. */
#define TYPE float
#endif
#ifndef MAX_THREADS
/** Maximum number of threads to use. */
#define MAX_THREADS 64
#endif
#ifndef REPEAT_METHOD
/** Number of times to repeat each method. */
#define REPEAT_METHOD 5
#endif
#pragma endregion
// HELPERS
// -------
template <class G, class R>
inline double getModularity(const G& x, const R& a, double M) {
auto fc = [&](auto u) { return a.membership[u]; };
return modularityByOmp(x, fc, M, 1.0);
}
// PERFORM EXPERIMENT
// ------------------
template <class G>
void runExperiment(const G& x) {
int repeat = REPEAT_METHOD;
double M = edgeWeightOmp(x)/2;
// Follow a specific result logging format, which can be easily parsed later.
auto flog = [&](const auto& ans, const char *technique, size_t numSlots=0) {
printf(
"{%09.1fms, %09.1fms mark, %09.1fms init, %09.1fms firstpass, %09.1fms locmove, %09.1fms refine, %09.1fms aggr, %.3e slots, %04d iters, %03d passes, %01.9f modularity, %zu/%zu disconnected} %s\n",
ans.time, ans.markingTime, ans.initializationTime, ans.firstPassTime, ans.localMoveTime, ans.refinementTime, ans.aggregationTime,
double(numSlots), ans.iterations, ans.passes, getModularity(x, ans, M),
countValue(communitiesDisconnectedOmp(x, ans.membership), char(1)),
communities(x, ans.membership).size(), technique
);
};
// Get community memberships on original graph (static).
{
auto b0 = leidenStaticOmp(x, {repeat});
flog(b0, "leidenStaticOmp");
}
// Get community memberships on original graph (low memory).
{
auto b1 = leidenLowmemStaticOmp(x, {repeat});
flog(b1, "leidenLowmemStaticOmpMajorities", 64);
}
}
int main(int argc, char **argv) {
using K = uint32_t;
using V = TYPE;
install_sigsegv();
char *file = argv[1];
bool symmetric = argc>2? stoi(argv[2]) : false;
bool weighted = argc>3? stoi(argv[3]) : false;
omp_set_num_threads(MAX_THREADS);
LOG("OMP_NUM_THREADS=%d\n", MAX_THREADS);
LOG("Loading graph %s ...\n", file);
DiGraph<K, None, V> x;
readMtxOmpW(x, file, weighted); LOG(""); println(x);
if (!symmetric) { symmetrizeOmpU(x); LOG(""); print(x); printf(" (symmetrize)\n"); }
runExperiment(x);
printf("\n");
return 0;
}