[Instrumentation] Fix a warning
[llvm-project.git] / openmp / runtime / test / tasking / issue-94260-1.cpp
blob6f2bf2ae0a8597b6e555fc1e3080535698aa5c45
1 // RUN: %libomp-cxx-compile-and-run
3 #include <assert.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <omp.h>
8 // The number of times to run each test
9 #define NTIMES 2
11 // Every thread creates a single "increment" task
12 void test_tasks() {
13 for (int i = 0; i < 100; ++i)
14 #pragma omp task
16 int tid = omp_get_thread_num();
20 // Testing single level of parallelism with increment tasks
21 void test_base(int nthreads) {
22 #ifdef VERBOSE
23 #pragma omp master
24 printf(" test_base(%d)\n", nthreads);
25 #endif
26 #pragma omp parallel num_threads(nthreads)
27 { test_tasks(); }
30 // Testing nested parallel with increment tasks
31 // first = nthreads of outer parallel
32 // second = nthreads of nested parallel
33 void test_nest(int first, int second) {
34 #ifdef VERBOSE
35 #pragma omp master
36 printf(" test_nest(%d, %d)\n", first, second);
37 #endif
38 #pragma omp parallel num_threads(first)
40 for (int i = 0; i < 100; ++i)
41 #pragma omp task
43 int tid = omp_get_thread_num();
45 test_base(second);
49 template <typename... Args>
50 void run_ntimes(int n, void (*func)(Args...), Args... args) {
51 for (int i = 0; i < n; ++i) {
52 func(args...);
56 int main() {
57 omp_set_max_active_levels(5);
59 for (int i = 0; i < 100; ++i) {
60 run_ntimes(NTIMES, test_nest, 4, 3);
61 run_ntimes(NTIMES, test_nest, 2, 1);
64 printf("PASS\n");
65 return EXIT_SUCCESS;