blob: 1f28e389bb913443da581cef46d1d8f6744c1932 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the shared option of the parallel construct.</ompts:testdescription>
3<ompts:ompversion>3.0</ompts:ompversion>
4<ompts:directive>omp parallel shared</ompts:directive>
5<ompts:testcode>
6#include <stdio.h>
7#include <unistd.h>
8
9#include "omp_testsuite.h"
10
11int <ompts:testcode:functionname>omp_parallel_shared</ompts:testcode:functionname> (FILE * logFile)
12{
13 <ompts:orphan:vars>
14 int i;
15 int sum;
16 </ompts:orphan:vars>
17 sum = 0;
18 int known_sum;
19 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 ;
20
21#pragma omp parallel private(i) <ompts:check>shared(sum)</ompts:check> <ompts:crosscheck>firstprivate(sum)</ompts:crosscheck>
22 {
23 <ompts:orphan>
24 int mysum = 0;
25#pragma omp for
26 for (i = 1; i <= LOOPCOUNT; i++)
27 {
28 mysum = mysum + i;
29 }
30#pragma omp critical
31 {
32 sum = sum + mysum;
33 } /* end of critical */
34</ompts:orphan>
35
36 } /* end of parallel */
37 if (known_sum != sum) {
38 fprintf(logFile, "KNOWN_SUM = %d; SUM = %d\n", known_sum, sum);
39 }
40 return (known_sum == sum);
41}
42</ompts:testcode>
43</ompts:test>