LLVM OpenMP
22.0.0git
runtime
test
worksharing
for
omp_for_dynamic_large_chunk.c
Go to the documentation of this file.
1
// RUN: %libomp-compile
2
// RUN: env OMP_WAIT_POLICY=passive OMP_NUM_THREADS=32 %libomp-run 0 134217728 1 134217728
3
//
4
// This test makes sure that large chunks sizes are handled correctly
5
// including internal runtime calculations which incorporate the chunk size
6
// Only one thread should execute all iterations.
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include "
omp_testsuite.h
"
10
11
typedef
unsigned
long
long
ull_t
;
12
13
int
main
(
int
argc,
char
**argv) {
14
int
i
,
j
, lb, ub, stride, nthreads, actual_nthreads, chunk;
15
ull_t
num_iters = 0;
16
ull_t
counted_iters = 0;
17
int
errs = 0;
18
if
(argc != 5) {
19
fprintf(stderr,
"error: incorrect number of arguments\n"
);
20
fprintf(stderr,
"usage: %s <lb> <ub> <stride> <chunk>\n"
, argv[0]);
21
exit(EXIT_FAILURE);
22
}
23
lb = atoi(argv[1]);
24
ub = atoi(argv[2]);
25
stride = atoi(argv[3]);
26
chunk = atoi(argv[4]);
27
nthreads =
omp_get_max_threads
();
28
if
(lb >= ub) {
29
fprintf(stderr,
"error: lb must be less than ub\n"
);
30
exit(EXIT_FAILURE);
31
}
32
if
(stride <= 0) {
33
fprintf(stderr,
"error: stride must be positive integer\n"
);
34
exit(EXIT_FAILURE);
35
}
36
if
(chunk <= 0) {
37
fprintf(stderr,
"error: chunk must be positive integer\n"
);
38
exit(EXIT_FAILURE);
39
}
40
for
(
i
= lb;
i
< ub;
i
+= stride)
41
num_iters++;
42
43
#pragma omp parallel num_threads(nthreads)
44
{
45
#pragma omp single
46
actual_nthreads =
omp_get_num_threads
();
47
48
if
(actual_nthreads != nthreads) {
49
printf(
"did not create enough threads, skipping test.\n"
);
50
}
else
{
51
#pragma omp for schedule(dynamic, chunk)
52
for
(
i
= lb;
i
< ub;
i
+= stride) {
53
counted_iters++;
54
}
55
}
56
}
57
58
// Check that the number of iterations executed is correct
59
if
(actual_nthreads == nthreads && counted_iters != num_iters) {
60
fprintf(stderr,
"error: wrong number of final iterations counted! "
61
"num_iters=%llu, counted_iters=%llu\n"
,
62
num_iters, counted_iters);
63
exit(EXIT_FAILURE);
64
}
65
66
return
EXIT_SUCCESS;
67
}
i
#define i
Definition
kmp_stub.cpp:87
ull_t
unsigned long long ull_t
Definition
omp_for_dynamic_large_chunk.c:11
j
int j
Definition
omp_single_copyprivate.c:6
omp_testsuite.h
omp_get_max_threads
int omp_get_max_threads()
omp_get_num_threads
int omp_get_num_threads()
main
int main()
Definition
test-touch.c:21
Generated on
for LLVM OpenMP by
1.14.0