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_imp_firstprivate()
8{
9 int i=5;
10 int k = 0;
11 int result = 0;
12 int task_result = 1;
13 #pragma omp parallel firstprivate(i)
14 {
15 #pragma omp single
16 {
17 for (k = 0; k < NUM_TASKS; k++) {
18 #pragma omp task shared(result , task_result)
19 {
20 int j;
21 //check if i is private
22 if(i != 5)
23 task_result = 0;
24 for(j = 0; j < NUM_TASKS; j++)
25 i++;
26 //this should be firstprivate implicitly
27 }
28 }
29 #pragma omp taskwait
30 result = (task_result && i==5);
31 }
32 }
33 return result;
34}
35
36int main()
37{
38 int i;
39 int num_failed=0;
40
41 for(i = 0; i < REPETITIONS; i++) {
42 if(!test_omp_task_imp_firstprivate()) {
43 num_failed++;
44 }
45 }
46 return num_failed;
47}
48

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