summaryrefslogtreecommitdiffstats
path: root/openmp/testsuite/c/omp_critical.c
blob: cb3f26433005a74832ecf4fd121f4c4f27239775 (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
<ompts:test>
<ompts:testdescription>Test which checks the omp critical directive by counting up a variable in a parallelized loop within a critical section.</ompts:testdescription>
<ompts:ompversion>2.0</ompts:ompversion>
<ompts:directive>omp critical</ompts:directive>
<ompts:testcode>
#include <stdio.h>
#include <unistd.h>

#include "omp_testsuite.h"
#include "omp_my_sleep.h"

int <ompts:testcode:functionname>omp_critical</ompts:testcode:functionname> (FILE * logFile)
{
    <ompts:orphan:vars>
	int sum;
    </ompts:orphan:vars>
    sum=0;
    int known_sum;
	  
    <ompts:orphan>
    #pragma omp parallel
    {
      int mysum=0;
      int i;
      
      #pragma omp for
	    for (i = 0; i < 1000; i++)
	      mysum = mysum + i;

    <ompts:check>#pragma omp critical</ompts:check>
	    sum = mysum +sum;
        
    }	/* end of parallel */
    </ompts:orphan>
    
    printf("sum=%d\n",sum);
    known_sum = 999 * 1000 / 2;
    return (known_sum == sum);

}
</ompts:testcode>
</ompts:test>
OpenPOWER on IntegriCloud