brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 7a93716 Raw
54 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include <math.h>4#include "omp_testsuite.h"5 6/* Utility function do spend some time in a loop */7int test_omp_task_private()8{9  int i;10  int known_sum;11  int sum = 0;12  int result = 0; /* counts the wrong sums from tasks */13 14  known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;15 16  #pragma omp parallel17  {18    #pragma omp single19    {20      for (i = 0; i < NUM_TASKS; i++) {21        #pragma omp task private(sum) shared(result, known_sum)22        {23          int j;24          //if sum is private, initialize to 025          sum = 0;26          for (j = 0; j <= LOOPCOUNT; j++) {27            #pragma omp flush28            sum += j;29          }30          /* check if calculated sum was right */31          if (sum != known_sum) {32            #pragma omp critical33            result++;34          }35        } /* end of omp task */36      } /* end of for */37    } /* end of single */38  } /* end of parallel*/39  return (result == 0);40}41 42int main()43{44  int i;45  int num_failed=0;46 47  for(i = 0; i < REPETITIONS; i++) {48    if(!test_omp_task_private()) {49      num_failed++;50    }51  }52  return num_failed;53}54