forked from lbfm-rwth/GaussParallel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure_contention.g
72 lines (67 loc) · 2.64 KB
/
measure_contention.g
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
Read("read_hpc.g");
Read("main_full_par_trafo.g");
nrAvailableThreads := GAPInfo.KernelInfo.NUM_CPUS;
chopSize := 0; n := 0; q := 0;
A := "";
bench := "";
Print("-----------------------------------------------------\n");
Print("Make sure you called GAP with sufficient\n");
Print("preallocated memory via `-m`\n");
Print("Call:\n");
Print("n := 4000;; chopSize := 8;; q := 5;;\n");
Print("A := RandomMat(n, n, GF(q));;\n");
Print("prepare();; compute();; evaluate();;\n");
Print("-----------------------------------------------------\n");
prepareCounters := function()
Sleep(1);
THREAD_COUNTERS_ENABLE();
THREAD_COUNTERS_RESET();
return ThreadID(CurrentThread());
end;
getCountersForTaskThreads := function()
local counters;
Sleep(1);
counters := [ThreadID(CurrentThread())];
Append(counters, THREAD_COUNTERS_GET());
return counters;
end;
prepare := function()
local tasks, taskNumbers;
tasks := List([1..nrAvailableThreads],
x -> RunTask(prepareCounters));
taskNumbers := List(tasks, TaskResult);
if Size(Set(taskNumbers)) <> GAPInfo.KernelInfo.NUM_CPUS then
ErrorNoReturn("GaussPar: Unable to activate counters for all threads");
fi;
end;
compute := function()
bench := GET_REAL_TIME_OF_FUNCTION_CALL(ChiefParallel,
[GF(q), A, chopSize, chopSize]);
end;
evaluate := function()
local CPUTimeCompute, resPar, benchStd, resStd, correct, counters,
totalAcquired, totalContended, factor;
CPUTimeCompute := time;
resPar := bench.result;
Print("Wall time parallel execution: ", bench.time, "\n");
Print("CPU time parallel execution: ", CPUTimeCompute*1000, "\n");
benchStd := GET_REAL_TIME_OF_FUNCTION_CALL(EchelonMatTransformation, [A]);
resStd := benchStd.result;
correct := -1 * resStd.vectors = resPar.remnant
and -1 * resStd.coeffs = resPar.transformation;
if not correct then
ErrorNoReturn("GaussPar: Result incorrect!");
fi;
Print("Wall time Gauss pkg execution: ", benchStd.time, "\n");
counters := List([1..nrAvailableThreads], x -> RunTask(getCountersForTaskThreads));
counters := List(counters, TaskResult);
SortParallel(List(counters, x -> x[1]), counters);
Print("Lock statistics(estimates):\n");
totalAcquired := Sum(List(counters, x -> x[2]));
totalContended := Sum(List(counters, x -> x[3]));
Print("acquired - ", totalAcquired, ", contended - ", totalContended);
factor := Round(totalContended / totalAcquired * 100.);
Print(", factor - ", factor, "%\n");
Print("Locks acquired and contention counters per thread:\n");
Print(counters, "\n");
end;