58 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include "omp_testsuite.h"4 5int myit = 0;6#pragma omp threadprivate(myit)7int myresult = 0;8#pragma omp threadprivate(myresult)9 10int test_omp_single_private()11{12 int nr_threads_in_single;13 int result;14 int nr_iterations;15 int i;16 17 myit = 0;18 nr_threads_in_single = 0;19 nr_iterations = 0;20 result = 0;21 22 #pragma omp parallel private(i)23 {24 myresult = 0;25 myit = 0;26 for (i = 0; i < LOOPCOUNT; i++) {27 #pragma omp single private(nr_threads_in_single) nowait28 {29 nr_threads_in_single = 0;30 #pragma omp flush31 nr_threads_in_single++;32 #pragma omp flush33 myit++;34 myresult = myresult + nr_threads_in_single;35 }36 }37 #pragma omp critical38 {39 result += nr_threads_in_single;40 nr_iterations += myit;41 }42 }43 return ((result == 0) && (nr_iterations == LOOPCOUNT));44} /* end of check_single private */45 46int main()47{48 int i;49 int num_failed=0;50 51 for(i = 0; i < REPETITIONS; i++) {52 if(!test_omp_single_private()) {53 num_failed++;54 }55 }56 return num_failed;57}58