summaryrefslogtreecommitdiffstats
path: root/openmp/testsuite/c/omp_for_lastprivate.c
blob: c2080a21432d5b93052ce6662e612276705acd34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<ompts:test>
<ompts:testdescription>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.</ompts:testdescription>
<ompts:ompversion>2.0</ompts:ompversion>
<ompts:directive>omp for lastprivate</ompts:directive>
<ompts:dependences>omp critical,omp parallel firstprivate,omp schedule</ompts:dependences>
<ompts:testcode>
#include <stdio.h>
#include <math.h>

#include "omp_testsuite.h"

int sum0;
#pragma omp threadprivate(sum0)

int <ompts:testcode:functionname>omp_for_lastprivate</ompts:testcode:functionname> (FILE * logFile)
{
	int sum = 0;
	int known_sum;
	<ompts:orphan:vars>
	    int i0;
	</ompts:orphan:vars>

	i0 = -1;

#pragma omp parallel
	{
	    sum0 = 0;
	    {	/* Begin of orphaned block */
	    <ompts:orphan>
		int i;
#pragma omp for schedule(static,7) <ompts:check>lastprivate(i0)</ompts:check>
		for (i = 1; i <= LOOPCOUNT; i++)
		{
		    sum0 = sum0 + i;
		    i0 = i;
		}	/* end of for */
	    </ompts:orphan>
	    }	/* 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) );
}
</ompts:testcode>
</ompts:test>
OpenPOWER on IntegriCloud