[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / openmp / runtime / test / tasking / hidden_helper_task / capacity_mix_threads.cpp
blob776aee9d8e2cac91c9df3582e64b0189163dd19f
1 // RUN: %libomp-cxx-compile-and-run
3 #include <omp.h>
5 #include <algorithm>
6 #include <cassert>
7 #include <chrono>
8 #include <thread>
9 #include <vector>
11 void dummy_root() {
12 // omp_get_max_threads() will do middle initialization
13 int nthreads = omp_get_max_threads();
14 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
17 int main(int argc, char *argv[]) {
18 const int N = std::min(std::max(std::max(32, 4 * omp_get_max_threads()),
19 4 * omp_get_num_procs()),
20 std::numeric_limits<int>::max());
22 std::vector<int> data(N);
24 // Create a new thread to initialize the OpenMP RTL. The new thread will not
25 // be taken as the "initial thread".
26 std::thread root(dummy_root);
28 #pragma omp parallel for num_threads(N)
29 for (unsigned i = 0; i < N; ++i) {
30 data[i] = i;
33 #pragma omp parallel for num_threads(N + 1)
34 for (unsigned i = 0; i < N; ++i) {
35 data[i] += i;
38 for (unsigned i = 0; i < N; ++i) {
39 assert(data[i] == 2 * i);
42 root.join();
44 return 0;