brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 6f2bf2a Raw
67 lines · cpp
1// RUN: %libomp-cxx-compile-and-run2 3#include <assert.h>4#include <stdio.h>5#include <stdlib.h>6#include <omp.h>7 8// The number of times to run each test9#define NTIMES 210 11// Every thread creates a single "increment" task12void test_tasks() {13  for (int i = 0; i < 100; ++i)14#pragma omp task15  {16    int tid = omp_get_thread_num();17  }18}19 20// Testing single level of parallelism with increment tasks21void test_base(int nthreads) {22#ifdef VERBOSE23#pragma omp master24  printf("    test_base(%d)\n", nthreads);25#endif26#pragma omp parallel num_threads(nthreads)27  { test_tasks(); }28}29 30// Testing nested parallel with increment tasks31// first = nthreads of outer parallel32// second = nthreads of nested parallel33void test_nest(int first, int second) {34#ifdef VERBOSE35#pragma omp master36  printf("   test_nest(%d, %d)\n", first, second);37#endif38#pragma omp parallel num_threads(first)39  {40    for (int i = 0; i < 100; ++i)41#pragma omp task42    {43      int tid = omp_get_thread_num();44    }45    test_base(second);46  }47}48 49template <typename... Args>50void run_ntimes(int n, void (*func)(Args...), Args... args) {51  for (int i = 0; i < n; ++i) {52    func(args...);53  }54}55 56int main() {57  omp_set_max_active_levels(5);58 59  for (int i = 0; i < 100; ++i) {60    run_ntimes(NTIMES, test_nest, 4, 3);61    run_ntimes(NTIMES, test_nest, 2, 1);62  }63 64  printf("PASS\n");65  return EXIT_SUCCESS;66}67