1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <math.h>
4#include "omp_testsuite.h"
5
6int sum1;
7#pragma omp threadprivate(sum1)
8
9int test_omp_for_firstprivate()
10{
11 int sum;
12 int sum0;
13 int known_sum;
14 int threadsnum;
15
16 sum = 0;
17 sum0 = 12345;
18 sum1 = 0;
19
20 #pragma omp parallel
21 {
22 #pragma omp single
23 {
24 threadsnum=omp_get_num_threads();
25 }
26 /* sum0 = 0; */
27
28 int i;
29 #pragma omp for firstprivate(sum0)
30 for (i = 1; i <= LOOPCOUNT; i++) {
31 sum0 = sum0 + i;
32 sum1 = sum0;
33 } /* end of for */
34
35 #pragma omp critical
36 {
37 sum = sum + sum1;
38 } /* end of critical */
39 } /* end of parallel */
40 known_sum = 12345* threadsnum+ (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
41 return (known_sum == sum);
42}
43
44int main()
45{
46 int i;
47 int num_failed=0;
48
49 for(i = 0; i < REPETITIONS; i++) {
50 if(!test_omp_for_firstprivate()) {
51 num_failed++;
52 }
53 }
54 return num_failed;
55}
56

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