1// RUN: %libomp-compile-and-run
2#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 parallel
17 {
18 #pragma omp single
19 {
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 0
25 sum = 0;
26 for (j = 0; j <= LOOPCOUNT; j++) {
27 #pragma omp flush
28 sum += j;
29 }
30 /* check if calculated sum was right */
31 if (sum != known_sum) {
32 #pragma omp critical
33 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

source code of openmp/runtime/test/tasking/omp_task_private.c