1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <math.h>
4#include "omp_testsuite.h"
5
6/*! Utility function to spend some time in a loop */
7static void do_some_work (void)
8{
9 int i;
10 double sum = 0;
11 for(i = 0; i < 1000; i++){
12 sum += sqrt (i);
13 }
14}
15
16int test_omp_parallel_for_private()
17{
18 int sum;
19 int i;
20 int i2;
21 int known_sum;
22
23 sum =0;
24 i2=0;
25
26 #pragma omp parallel for reduction(+:sum) schedule(static,1) private(i) private(i2)
27 for (i=1;i<=LOOPCOUNT;i++)
28 {
29 i2 = i;
30 #pragma omp flush
31 do_some_work ();
32 #pragma omp flush
33 sum = sum + i2;
34 } /*end of for*/
35 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
36 return (known_sum == sum);
37} /* end of check_parallel_for_private */
38
39int main()
40{
41 int i;
42 int num_failed=0;
43
44 for(i = 0; i < REPETITIONS; i++) {
45 if(!test_omp_parallel_for_private()) {
46 num_failed++;
47 }
48 }
49 return num_failed;
50}
51

source code of openmp/runtime/test/worksharing/for/omp_parallel_for_private.c