Test which checks the omp for lastprivate clause by counting up a variable in a parallelized loop. Each thread saves the next summand in a lastprivate variable i0. At the end i0 is compared to the value of the expected last summand.
2.0
omp for lastprivate
omp critical,omp parallel firstprivate,omp schedule
#include
#include
#include "omp_testsuite.h"
int sum0;
#pragma omp threadprivate(sum0)
int omp_for_lastprivate (FILE * logFile)
{
int sum = 0;
int known_sum;
int i0;
i0 = -1;
#pragma omp parallel
{
sum0 = 0;
{ /* Begin of orphaned block */
int i;
#pragma omp for schedule(static,7) lastprivate(i0)
for (i = 1; i <= LOOPCOUNT; i++)
{
sum0 = sum0 + i;
i0 = i;
} /* end of for */
} /* end of orphaned block */
#pragma omp critical
{
sum = sum + sum0;
} /* end of critical */
} /* end of parallel */
known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
fprintf(logFile," known_sum = %d , sum = %d \n",known_sum,sum);
fprintf(logFile," LOOPCOUNT = %d , i0 = %d \n",LOOPCOUNT,i0);
return ((known_sum == sum) && (i0 == LOOPCOUNT) );
}