-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoall_bench.cc
172 lines (140 loc) · 5.11 KB
/
doall_bench.cc
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
169
170
171
172
#include <algorithm>
#include "doall_bench.h"
#include "commons.h"
// In case this doesn't get compiled with the Environment Variables set by CMake and Make
#ifndef ARRAY_SIZE
int ARRAY_SIZE = 1
#endif
// Runs all microbenchmarks
void RunBenchmarks();
float array[ARRAY_SIZE];
float array_thread_private[ARRAY_SIZE];
#pragma omp threadprivate (array_thread_private)
std::string bench_name = "DOALL_" + std::to_string(ARRAY_SIZE);
int main(int argc, char **argv) {
ParseArgs(argc, argv);
PrintCompilerVersion();
if (SAVE_FOR_EXTRAP) {
RemoveBench(bench_name);
}
RunBenchmarks();
return 0;
}
void RunBenchmarks() {
Benchmark(bench_name, "DOALL", TestDoAll, ReferenceWithoutArray);
Benchmark(bench_name, "SHARED", TestDoAllShared, ReferenceWithArray);
Benchmark(bench_name, "SEPARATED", TestDoallSeparated, ReferenceWithArray);
Benchmark(bench_name, "FIRSTPRIVATE", TestDoallFirstprivate, ReferenceWithArray);
Benchmark(bench_name, "PRIVATE", TestDoallPrivate, ReferenceWithArray);
Benchmark(bench_name, "COPYIN", TestCopyin, ReferenceWithArray);
Benchmark(bench_name, "COPY_PRIVATE", TestCopyPrivate, ReferenceWithArray);
}
// allocate variables right away to reduce measured work
unsigned int threads;
unsigned long long int iterations;
unsigned long workload;
unsigned long directive;
void TestDoallFirstprivate(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel for num_threads(threads) default(none) shared(iterations, workload) firstprivate(array)
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
void TestDoallPrivate(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel for num_threads(threads) default(none) shared(iterations, workload) private(array)
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
void TestDoallSeparated(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
directive = data.directive; // TODO this assignment is not in the reference, so there is some imbalance here
#pragma omp parallel num_threads(threads) default(none) shared(directive, iterations, workload, array)
for (int rep = 0; rep < directive; rep++) {
#pragma omp for
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
void TestDoAllShared(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel for num_threads(threads) default(none) shared(iterations, workload, array)
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
void TestDoAll(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel for num_threads(threads) default(none) shared(iterations, workload, array)
for (int i = 0; i < iterations; i++) {
DELAY(workload, i);
}
}
}
void TestCopyin(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel for num_threads(threads) default(none) copyin(array_thread_private) shared(iterations, workload)
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array_thread_private);
}
}
}
void TestCopyPrivate(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
#pragma omp parallel num_threads(threads) default(none) shared(iterations, workload) private(array)
{
#pragma omp single copyprivate(array)
{
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
}
}
void ReferenceWithArray(const DataPoint& data) {
threads = data.threads; // not used, only here for equal work in Test and Reference
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
for (int i = 0; i < iterations; i++) {
ARRAY_DELAY(workload, i, array);
}
}
}
void ReferenceWithoutArray(const DataPoint& data) {
threads = data.threads; // not used, only here for equal work in Test and Reference
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
for (int i = 0; i < iterations; i++) {
DELAY(workload, i);
}
}
}