-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduction_bench.cc
191 lines (161 loc) · 5.86 KB
/
reduction_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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <algorithm>
#include "commons.h"
#include "reduction_bench.h"
// Runs all Benchmarks
void RunBenchmarks();
std::string bench_name = "REDUCTION";
unsigned long long num_tasks = 1;
unsigned long long grainsize = 1;
int main(int argc, char **argv) {
ParseArgs(argc, argv);
PrintCompilerVersion();
if (SAVE_FOR_EXTRAP) {
RemoveBench(bench_name);
}
RunBenchmarks();
return 0;
}
void RunBenchmarks() {
unsigned long long minimum_iterations = *std::min_element(NUMBER_OF_ITERATIONS.begin(), NUMBER_OF_ITERATIONS.end());
for (unsigned long long i = 1; i <= minimum_iterations; i = i * 2) {
num_tasks = i;
grainsize = i;
Benchmark(bench_name, "TASKLOOP_NUM_TASKS_" + std::to_string(num_tasks), ReductionTaskloopNumTasks,
Reference);
Benchmark(bench_name, "TASKLOOP_GRAINSIZE_" + std::to_string(grainsize), ReductionTaskloopGrainsize,
Reference);
}
Benchmark(bench_name, "FOR", ReductionFor, Reference);
Benchmark(bench_name, "TASKLOOP", ReductionTaskloop, Reference);
Benchmark(bench_name, "TASK", ReductionTask, Reference);
Benchmark(bench_name, "TASKGROUP", ReductionTaskgroup, Reference);
}
// allocate variables right away to reduce measured work
unsigned int threads;
unsigned long long int iterations;
unsigned long workload;
unsigned long directive;
void ReductionFor(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
float var = 0;
#pragma omp parallel for reduction(+ : var) shared(iterations, workload) default(none) num_threads(threads)
for (int i = 0; i < iterations; i++) {
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
void ReductionTask(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
float var = 0;
#pragma omp parallel for reduction(task, + : var) shared(iterations, workload) default(none) num_threads(threads)
for (int i = 0; i < iterations; i++) {
#pragma omp task in_reduction(+ : var) default(none) shared(i, workload)
{
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
}
void ReductionTaskgroup(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
directive = data.directive; // TODO this assignment is not in the reference!!
#pragma omp parallel shared(iterations, workload, directive) default(none) num_threads(threads)
{
#pragma omp master
{
for (int rep = 0; rep < directive; rep++) {
float var = 0.0;
#pragma omp taskgroup task_reduction(+ : var)
for (int i = 0; i < iterations; i++) {
#pragma omp task in_reduction(+ : var) default(none) shared(i, workload)
{
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
}
}
}
void ReductionTaskloop(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
directive = data.directive; // TODO this assignment is not in the reference
#pragma omp parallel default(none) shared(directive, iterations, workload) num_threads(threads)
{
#pragma omp master
{
for (int rep = 0; rep < directive; rep++) {
float var = 0;
#pragma omp taskloop reduction(+ : var) shared(iterations, workload) default(none)
for (int i = 0; i < iterations; i++) {
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
}
}
void ReductionTaskloopNumTasks(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
directive = data.directive; // TODO this assignment is not in the reference
#pragma omp parallel default(none) shared(directive, iterations, workload, num_tasks) num_threads(threads)
{
#pragma omp master
{
for (int rep = 0; rep < directive; rep++) {
float var = 0;
#pragma omp taskloop reduction(+ : var) shared(iterations, workload) default(none) num_tasks(num_tasks)
for (int i = 0; i < iterations; i++) {
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
}
}
void ReductionTaskloopGrainsize(const DataPoint& data) {
threads = data.threads;
iterations = data.iterations;
workload = data.workload;
directive = data.directive; // TODO this assignment is not in the reference
#pragma omp parallel default(none) shared(directive, iterations, workload, grainsize) num_threads(threads)
{
#pragma omp master
{
for (int rep = 0; rep < directive; rep++) {
float var = 0;
#pragma omp taskloop reduction(+ : var) shared(iterations, workload) default(none) grainsize(grainsize)
for (int i = 0; i < iterations; i++) {
DELAY(workload, i)
var = var + DELAY_A;
}
}
}
}
}
void Reference(const DataPoint& data) {
threads = data.threads; // not used, only here for equal amount of work in Test and Reference
iterations = data.iterations;
workload = data.workload;
for (int rep = 0; rep < data.directive; rep++) {
float var = 0;
for (int i = 0; i < iterations; i++) {
DELAY(workload, i)
var = var + DELAY_A;
}
}
}