forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (48 loc) · 1.39 KB
/
main.cpp
File metadata and controls
57 lines (48 loc) · 1.39 KB
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
// Microbenchmark for #pragma omp split counts(...).
#include <cstdlib>
#include <fstream>
#include <iostream>
#include "benchmark/benchmark.h"
// Large N for measurable runs; lit verification uses same kernel once.
#define N 200000000
// Kernel: sum 0..(N-1) with split into four segments.
static long run_split() {
long sum = 0;
#pragma omp split counts(50000000, 50000000, 50000000, omp_fill)
for (int i = 0; i < N; ++i)
sum += i;
return sum;
}
// Baseline: same loop without split (for comparison).
static long run_baseline() {
long sum = 0;
for (int i = 0; i < N; ++i)
sum += i;
return sum;
}
int main(int argc, char *argv[]) {
benchmark::Initialize(&argc, argv);
// Run kernel once and write result for lit verification.
std::ofstream myfile("LoopSplit.txt");
if (myfile.is_open()) {
long y = run_split();
myfile << "test1: " << y << "\n";
myfile.close();
} else {
return EXIT_FAILURE;
}
benchmark::RunSpecifiedBenchmarks();
return EXIT_SUCCESS;
}
static void BM_Split(benchmark::State &state) {
long x = 0;
for (auto _ : state)
benchmark::DoNotOptimize(x += run_split());
}
BENCHMARK(BM_Split)->Unit(benchmark::kMicrosecond)->MinTime(2.0);
static void BM_Baseline(benchmark::State &state) {
long x = 0;
for (auto _ : state)
benchmark::DoNotOptimize(x += run_baseline());
}
BENCHMARK(BM_Baseline)->Unit(benchmark::kMicrosecond)->MinTime(2.0);