LLVM OpenMP
20.0.0git
runtime
test
worksharing
for
omp_for_schedule_auto.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <math.h>
5
#include "
omp_testsuite.h
"
6
7
int
sum1
;
8
#pragma omp threadprivate(sum1)
9
10
int
test_omp_for_auto
()
11
{
12
int
j
;
13
int
sum
;
14
int
sum0
;
15
int
known_sum;
16
int
threadsnum;
17
18
sum
= 0;
19
sum0
= 12345;
20
21
// array which keeps track of which threads participated in the for loop
22
// e.g., given 4 threads, [ 0 | 1 | 1 | 0 ] implies
23
// threads 0 and 3 did not, threads 1 and 2 did
24
int
max_threads =
omp_get_max_threads
();
25
int
* active_threads = (
int
*)malloc(
sizeof
(
int
)*max_threads);
26
for
(
j
= 0;
j
< max_threads;
j
++)
27
active_threads[
j
] = 0;
28
29
#pragma omp parallel
30
{
31
int
i
;
32
sum1
= 0;
33
#pragma omp for firstprivate(sum0) schedule(auto)
34
for
(
i
= 1;
i
<=
LOOPCOUNT
;
i
++) {
35
active_threads[omp_get_thread_num()] = 1;
36
sum0
=
sum0
+
i
;
37
sum1
=
sum0
;
38
}
39
40
#pragma omp critical
41
{
42
sum
=
sum
+
sum1
;
43
}
44
}
45
46
// count the threads that participated (sum is stored in threadsnum)
47
threadsnum=0;
48
for
(
j
= 0;
j
< max_threads;
j
++) {
49
if
(active_threads[
j
])
50
threadsnum++;
51
}
52
free(active_threads);
53
54
known_sum = 12345 * threadsnum + (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
55
return
(known_sum ==
sum
);
56
}
57
58
int
main
()
59
{
60
int
i
;
61
int
num_failed=0;
62
63
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
64
if
(!
test_omp_for_auto
()) {
65
num_failed++;
66
}
67
}
68
return
num_failed;
69
}
i
#define i
Definition:
kmp_stub.cpp:87
test_omp_for_auto
int test_omp_for_auto()
Definition:
omp_for_schedule_auto.c:10
sum1
int sum1
Definition:
omp_for_schedule_auto.c:7
main
int main()
Definition:
omp_for_schedule_auto.c:58
sum
int sum
Definition:
omp_for_schedule_runtime.c:19
j
int j
Definition:
omp_single_copyprivate.c:6
omp_testsuite.h
LOOPCOUNT
#define LOOPCOUNT
Definition:
omp_testsuite.h:12
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
sum0
static int sum0
Definition:
omp_threadprivate.c:14
omp_get_max_threads
int omp_get_max_threads()
Generated on Wed Feb 5 2025 10:57:22 for LLVM OpenMP by
1.9.6