-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cxx
109 lines (94 loc) · 2.48 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <cstdint>
#include <cstdio>
#include <utility>
#include <random>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <omp.h>
#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
#pragma region METHODS
#pragma region HELPERS
/**
* Obtain the modularity of community structure on a graph.
* @param x original graph
* @param a rak result
* @param M sum of edge weights
* @returns modularity
*/
template <class G, class K>
inline double getModularity(const G& x, const RakResult<K>& a, double M) {
auto fc = [&](auto u) { return a.membership[u]; };
return modularityBy(x, fc, M, 1.0);
}
#pragma endregion
#pragma region PERFORM EXPERIMENT
/**
* Perform the experiment.
* @param x original graph
*/
template <class G>
void runExperiment(const G& x) {
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) {
printf(
"{%03d threads} -> "
"{%09.1fms, %09.1fms mark, %09.1fms init, %04d iters, %01.9f modularity} %s\n",
MAX_THREADS,
ans.time, ans.markingTime, ans.initializationTime,
ans.iterations, getModularity(x, ans, M), technique
);
};
// Find static RAK, using OpenMP.
{
auto b0 = rakStaticOmp(x, {REPEAT_METHOD});
flog(b0, "rakStaticOmp");
}
// Find static RAK, using CUDA.
{
auto b0 = rakStaticCuda(x, {REPEAT_METHOD});
flog(b0, "rakStaticCuda");
}
}
/**
* Main function.
* @param argc argument count
* @param argv argument values
* @returns zero on success, non-zero on failure
*/
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;
}
#pragma endregion
#pragma endregion