1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <stdlib.h>
4#include "omp_testsuite.h"
5
6//static int sum1 = 789;
7
8int test_omp_parallel_firstprivate()
9{
10 int sum, num_threads,sum1;
11 int known_sum;
12
13 sum = 0;
14 sum1=7;
15 num_threads = 0;
16
17 #pragma omp parallel firstprivate(sum1)
18 {
19 /*printf("sum1=%d\n",sum1);*/
20 int i;
21 #pragma omp for
22 for (i = 1; i < 1000; i++) {
23 sum1 = sum1 + i;
24 } /*end of for*/
25 #pragma omp critical
26 {
27 sum = sum + sum1;
28 num_threads++;
29 } /*end of critical*/
30 } /* end of parallel*/
31 known_sum = (999 * 1000) / 2 + 7 * num_threads;
32 return (known_sum == sum);
33}
34
35int main()
36{
37 int i;
38 int num_failed=0;
39
40 for(i = 0; i < REPETITIONS; i++) {
41 if(!test_omp_parallel_firstprivate()) {
42 num_failed++;
43 }
44 }
45 return num_failed;
46}
47

source code of openmp/runtime/test/parallel/omp_parallel_firstprivate.c