1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4
5int test_omp_parallel_sections_lastprivate()
6{
7 int sum;
8 int sum0;
9 int i;
10 int i0;
11 int known_sum;
12 sum =0;
13 sum0 = 0;
14 i0 = -1;
15
16 #pragma omp parallel sections private(i,sum0) lastprivate(i0)
17 {
18 #pragma omp section
19 {
20 sum0=0;
21 for (i=1;i<400;i++) {
22 sum0=sum0+i;
23 i0=i;
24 }
25 #pragma omp critical
26 {
27 sum= sum+sum0;
28 }
29 }
30 #pragma omp section
31 {
32 sum0=0;
33 for(i=400;i<700;i++) {
34 sum0=sum0+i;
35 i0=i;
36 }
37 #pragma omp critical
38 {
39 sum= sum+sum0;
40 }
41 }
42 #pragma omp section
43 {
44 sum0=0;
45 for(i=700;i<1000;i++) {
46 sum0=sum0+i;
47 i0=i;
48 }
49 #pragma omp critical
50 {
51 sum= sum+sum0;
52 }
53 }
54 }
55
56 known_sum=(999*1000)/2;
57 return ((known_sum==sum) && (i0==999) );
58}
59
60int main()
61{
62 int i;
63 int num_failed=0;
64
65 for(i = 0; i < REPETITIONS; i++) {
66 if(!test_omp_parallel_sections_lastprivate()) {
67 num_failed++;
68 }
69 }
70 return num_failed;
71}
72

source code of openmp/runtime/test/worksharing/sections/omp_parallel_sections_lastprivate.c