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