Skip to content

Commit

Permalink
🥭 w/ expt
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfram77 committed Jul 29, 2022
1 parent efca1c2 commit 9e25055
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
44 changes: 40 additions & 4 deletions main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <cstdio>
#include <iostream>
#include <omp.h>
#include "src/main.hxx"

using namespace std;
Expand All @@ -13,17 +14,52 @@ using namespace std;
template <class G>
void runLouvain(const G& x, int repeat) {
using K = typename G::key_type;
using V = typename G::edge_value_type;
int maxThreads = 12;
V resolution = V(1);
V tolerance = V(1e-2);
V passTolerance = V(0);
V toleranceDeclineFactor = V(10);
omp_set_num_threads(maxThreads);
printf("OMP_NUM_THREADS=%d\n", maxThreads);
auto M = edgeWeight(x)/2;
auto Q = modularity(x, M, 1.0f);
printf("[%01.6f modularity] noop\n", Q);

// Run louvain algorithm.
// Run louvain sequential algorithm.
do {
LouvainResult<K> a = louvainSeq(x, {repeat});
LouvainResult<K> a = louvainSeq<false>(x, {repeat, resolution, tolerance, passTolerance, toleranceDeclineFactor});
auto fc = [&](auto u) { return a.membership[u]; };
auto Q = modularity(x, fc, M, 1.0f);
printf("[%09.3f ms; %01.6f modularity] louvainSeq\n", a.time, Q);
printf("[%09.3f ms; %04d iterations; %03d passes; %01.6f modularity] louvainSeq\n", a.time, a.iterations, a.passes, Q);
} while(0);
for (int chunkSize=1; chunkSize<=65536; chunkSize*=2) {
omp_set_schedule(omp_sched_static, chunkSize);
LouvainResult<K> a = louvainOmp<false>(x, {repeat, resolution, tolerance, passTolerance, toleranceDeclineFactor});
auto fc = [&](auto u) { return a.membership[u]; };
auto Q = modularity(x, fc, M, 1.0f);
printf("[%09.3f ms; %04d iterations; %03d passes; %01.6f modularity] louvainOmp {sch_kind: static, chunk_size: %d}\n", a.time, a.iterations, a.passes, Q, chunkSize);
}
for (int chunkSize=1; chunkSize<=65536; chunkSize*=2) {
omp_set_schedule(omp_sched_dynamic, chunkSize);
LouvainResult<K> a = louvainOmp<false>(x, {repeat, resolution, tolerance, passTolerance, toleranceDeclineFactor});
auto fc = [&](auto u) { return a.membership[u]; };
auto Q = modularity(x, fc, M, 1.0f);
printf("[%09.3f ms; %04d iterations; %03d passes; %01.6f modularity] louvainOmp {sch_kind: dynamic, chunk_size: %d}\n", a.time, a.iterations, a.passes, Q, chunkSize);
}
for (int chunkSize=1; chunkSize<=65536; chunkSize*=2) {
omp_set_schedule(omp_sched_guided, chunkSize);
LouvainResult<K> a = louvainOmp<false>(x, {repeat, resolution, tolerance, passTolerance, toleranceDeclineFactor});
auto fc = [&](auto u) { return a.membership[u]; };
auto Q = modularity(x, fc, M, 1.0f);
printf("[%09.3f ms; %04d iterations; %03d passes; %01.6f modularity] louvainOmp {sch_kind: guided, chunk_size: %d}\n", a.time, a.iterations, a.passes, Q, chunkSize);
}
for (int chunkSize=1; chunkSize<=65536; chunkSize*=2) {
omp_set_schedule(omp_sched_auto, chunkSize);
LouvainResult<K> a = louvainOmp<false>(x, {repeat, resolution, tolerance, passTolerance, toleranceDeclineFactor});
auto fc = [&](auto u) { return a.membership[u]; };
auto Q = modularity(x, fc, M, 1.0f);
printf("[%09.3f ms; %04d iterations; %03d passes; %01.6f modularity] louvainOmp {sch_kind: auto, chunk_size: %d}\n", a.time, a.iterations, a.passes, Q, chunkSize);
}
}


Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://www.kaggle.com/wolfram77/puzzlef-louvain-static-approaches
# https://www.kaggle.com/wolfram77/puzzlef-louvain-openmp-adjust-schedule
import os
from IPython.display import FileLink
src="louvain-static-approaches"
src="louvain-openmp-adjust-schedule"
inp="/kaggle/input/graphs"
out="{}.txt".format(src)
!printf "" > "$out"
Expand All @@ -14,7 +14,7 @@
!echo ""

# Run
!g++ -std=c++17 -O3 main.cxx
!g++ -std=c++17 -O3 -fopenmp main.cxx
!stdbuf --output=L ./a.out $inp/web-Stanford.mtx 2>&1 | tee -a "$out"
!stdbuf --output=L ./a.out $inp/web-BerkStan.mtx 2>&1 | tee -a "$out"
!stdbuf --output=L ./a.out $inp/web-Google.mtx 2>&1 | tee -a "$out"
Expand Down
4 changes: 2 additions & 2 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
src="louvain-static-approaches"
src="louvain-openmp-adjust-schedule"
out="/home/resources/Documents/subhajit/$src.log"
ulimit -s unlimited
printf "" > "$out"
Expand All @@ -10,7 +10,7 @@ git clone https://github.com/puzzlef/$src
cd $src

# Run
g++ -std=c++17 -O3 main.cxx
g++ -std=c++17 -O3 -fopenmp main.cxx
stdbuf --output=L ./a.out ~/data/web-Stanford.mtx 2>&1 | tee -a "$out"
stdbuf --output=L ./a.out ~/data/web-BerkStan.mtx 2>&1 | tee -a "$out"
stdbuf --output=L ./a.out ~/data/web-Google.mtx 2>&1 | tee -a "$out"
Expand Down
1 change: 0 additions & 1 deletion src/main.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
#include "properties.hxx"
#include "modularity.hxx"
#include "louvain.hxx"
#include "louvainSeq.hxx"
#include "louvainOmp.hxx"

0 comments on commit 9e25055

Please sign in to comment.