1// RUN: %libomp-cxx-compile-and-run
2
3#include <omp.h>
4
5#include <algorithm>
6#include <cassert>
7#include <limits>
8#include <vector>
9
10// AIX runs out of resource in 32-bit if 4*omp_get_max_threads() is more
11// than 64 threads with the default stacksize.
12#if defined(_AIX) && !__LP64__
13#define MAX_THREADS 64
14#endif
15
16int main(int argc, char *argv[]) {
17 int N = std::min(a: std::max(a: std::max(a: 32, b: 4 * omp_get_max_threads()),
18 b: 4 * omp_get_num_procs()),
19 b: std::numeric_limits<int>::max());
20
21#if defined(_AIX) && !__LP64__
22 if (N > MAX_THREADS)
23 N = MAX_THREADS;
24#endif
25
26 std::vector<int> data(N);
27
28#pragma omp parallel for num_threads(N)
29 for (unsigned i = 0; i < N; ++i) {
30 data[i] = i;
31 }
32
33#pragma omp parallel for num_threads(N + 1)
34 for (unsigned i = 0; i < N; ++i) {
35 data[i] += i;
36 }
37
38 for (unsigned i = 0; i < N; ++i) {
39 assert(data[i] == 2 * i);
40 }
41
42 return 0;
43}
44

source code of openmp/runtime/test/tasking/hidden_helper_task/capacity_nthreads.cpp