-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathomp_checks.cpp
More file actions
57 lines (46 loc) · 1.37 KB
/
Copy pathomp_checks.cpp
File metadata and controls
57 lines (46 loc) · 1.37 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
#include <omp.h>
#include <stdio.h>
/**
* Note - this function is designed to test basic OpenMP functionality.
* The loop must include both globally and locally shared variables.
*/
int main(int argc, char* argv[])
{
bool failed = false;
int nThreads = omp_get_max_threads();
if (nThreads < 2) {
printf("Need 2 or more threads but got %i\n", nThreads);
return 1;
}
int mainThreadNum = omp_get_thread_num();
if (mainThreadNum != 0) {
printf("Main thread is not zero\n");
return 1;
}
bool* flags = new bool[nThreads];
#pragma omp parallel default(none) shared(flags, failed, nThreads)
{
int thisThreadNum = omp_get_thread_num();
flags[thisThreadNum] = true;
unsigned int currentThreads = omp_get_num_threads();
if (currentThreads != nThreads) {
printf("Only running %i threads but expected %i\n",
currentThreads,
nThreads);
failed = true;
}
}
if (failed) {
printf("Did not get expected number of threads in parallel section\n");
return 1;
}
for (int i = 0; i < nThreads; i++) {
if (!flags[i]) {
printf("Did not get a true flag for thread %i\n", i);
return 1;
}
}
printf("OpenMP checks succeeded\n");
delete[] flags;
return 0;
}