[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / openmp / runtime / test / worksharing / sections / omp_section_lastprivate.c
blob0dbbea9e19933ea5cb4589abddf6718d64273bac
1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include "omp_testsuite.h"
5 int test_omp_section_lastprivate()
7 int i0 = -1;
8 int sum = 0;
9 int i;
10 int sum0 = 0;
11 int known_sum;
13 i0 = -1;
14 sum = 0;
16 #pragma omp parallel
18 #pragma omp sections lastprivate(i0) private(i,sum0)
20 #pragma omp section
22 sum0 = 0;
23 for (i = 1; i < 400; i++)
25 sum0 = sum0 + i;
26 i0 = i;
28 #pragma omp critical
30 sum = sum + sum0;
31 } /*end of critical*/
32 } /* end of section */
33 #pragma omp section
35 sum0 = 0;
36 for(i = 400; i < 700; i++)
38 sum0 = sum0 + i;
39 i0 = i;
41 #pragma omp critical
43 sum = sum + sum0;
44 } /*end of critical*/
46 #pragma omp section
48 sum0 = 0;
49 for(i = 700; i < 1000; i++)
51 sum0 = sum0 + i;
52 i0 = i;
54 #pragma omp critical
56 sum = sum + sum0;
57 } /*end of critical*/
58 } /* end of section */
59 } /* end of sections*/
60 } /* end of parallel*/
61 known_sum = (999 * 1000) / 2;
62 return ((known_sum == sum) && (i0 == 999) );
65 int main()
67 int i;
68 int num_failed=0;
70 for(i = 0; i < REPETITIONS; i++) {
71 if(!test_omp_section_lastprivate()) {
72 num_failed++;
75 return num_failed;