44 lines · cpp
1// RUN: %libomp-cxx-compile-and-run2 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 more11// than 64 threads with the default stacksize.12#if defined(_AIX) && !__LP64__13#define MAX_THREADS 6414#endif15 16int main(int argc, char *argv[]) {17 int N = std::min(std::max(std::max(32, 4 * omp_get_max_threads()),18 4 * omp_get_num_procs()),19 std::numeric_limits<int>::max());20 21#if defined(_AIX) && !__LP64__22 if (N > MAX_THREADS)23 N = MAX_THREADS;24#endif25 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