LLVM OpenMP
20.0.0git
runtime
test
parallel
omp_parallel_num_threads.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
#include <stdio.h>
3
#include "
omp_testsuite.h
"
4
5
int
test_omp_parallel_num_threads
()
6
{
7
int
num_failed;
8
int
threads;
9
int
nthreads;
10
int
max_threads = 0;
11
12
num_failed = 0;
13
14
/* first we check how many threads are available */
15
#pragma omp parallel
16
{
17
#pragma omp master
18
max_threads =
omp_get_num_threads
();
19
}
20
21
/* we increase the number of threads from one to maximum:*/
22
for
(threads = 1; threads <= max_threads; threads++) {
23
nthreads = 0;
24
#pragma omp parallel reduction(+:num_failed) num_threads(threads)
25
{
26
num_failed = num_failed + !(threads ==
omp_get_num_threads
());
27
#pragma omp atomic
28
nthreads += 1;
29
}
30
num_failed = num_failed + !(nthreads == threads);
31
}
32
return
(!num_failed);
33
}
34
35
int
main
()
36
{
37
int
i
;
38
int
num_failed=0;
39
40
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
41
if
(!
test_omp_parallel_num_threads
()) {
42
num_failed++;
43
}
44
}
45
return
num_failed;
46
}
i
#define i
Definition:
kmp_stub.cpp:87
test_omp_parallel_num_threads
int test_omp_parallel_num_threads()
Definition:
omp_parallel_num_threads.c:5
main
int main()
Definition:
omp_parallel_num_threads.c:35
omp_testsuite.h
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
omp_get_num_threads
int omp_get_num_threads()
Generated on Wed Jan 29 2025 20:58:01 for LLVM OpenMP by
1.9.6