brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 2fece5c Raw
61 lines · c
1// RUN: %libomp-compile-and-run2#include "omp_testsuite.h"3 4#define DEBUG_TEST 05 6int j;7#pragma omp threadprivate(j)8 9int test_omp_single_copyprivate()10{11  int result;12  int nr_iterations;13 14  result = 0;15  nr_iterations = 0;16  #pragma omp parallel num_threads(4)17  {18    int i;19    for (i = 0; i < LOOPCOUNT; i++)20    {21#if DEBUG_TEST22         int thread;23         thread = omp_get_thread_num ();24#endif25      #pragma omp single copyprivate(j)26      {27        nr_iterations++;28        j = i;29#if DEBUG_TEST30        printf ("thread %d assigns, j = %d, i = %d\n", thread, j, i);31#endif32      }33#if DEBUG_TEST34      #pragma omp barrier35#endif36      #pragma omp critical37      {38#if DEBUG_TEST39        printf ("thread = %d, j = %d, i = %d\n", thread, j, i);40#endif41        result = result + j - i;42      }43      #pragma omp barrier44    } /* end of for */45  } /* end of parallel */46  return ((result == 0) && (nr_iterations == LOOPCOUNT));47}48 49int main()50{51  int i;52  int num_failed=0;53 54  for(i = 0; i < REPETITIONS; i++) {55    if(!test_omp_single_copyprivate()) {56      num_failed++;57    }58  }59  return num_failed;60}61