blob: 59e26dd7481f966bb8413a646eca5a47d33aeee4 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the private clause of the task directive. We create a set of tasks in a single region. We defines a variable named sum which gets declared private for each task. Now each task calcualtes a sum using this private variable. Before each calcualation step we introduce a flush command so that maybe the private variabel gets bad. At the end we check if the calculated sum was right.</ompts:testdescription>
3<ompts:ompversion>3.0</ompts:ompversion>
4<ompts:directive>omp task private</ompts:directive>
5<ompts:dependences>omp single,omp flush,omp critical</ompts:dependences>
6<ompts:testcode>
7#include <stdio.h>
8#include <math.h>
9#include "omp_testsuite.h"
10
11/* Utility function do spend some time in a loop */
12int <ompts:testcode:functionname>omp_task_private</ompts:testcode:functionname> (FILE * logFile)
13{
14 int i;
15 <ompts:orphan:vars>
16 int known_sum;
17 int sum = 0;
18 int result = 0; /* counts the wrong sums from tasks */
19 </ompts:orphan:vars>
20
21 known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
22
23#pragma omp parallel
24 {
25#pragma omp single
26 {
27 for (i = 0; i < NUM_TASKS; i++)
28 {
29 <ompts:orphan>
30#pragma omp task <ompts:check>private(sum)</ompts:check> shared(result, known_sum)
31 {
32 int j;
33 //if sum is private, initialize to 0
34 <ompts:check>sum = 0;</ompts:check>
35 for (j = 0; j <= LOOPCOUNT; j++) {
36#pragma omp flush
37 sum += j;
38 }
39 /* check if calculated sum was right */
40 if (sum != known_sum) {
41#pragma omp critical
42 result++;
43 }
44 } /* end of omp task */
45 </ompts:orphan>
46 } /* end of for */
47 } /* end of single */
48 } /* end of parallel*/
49
50 return (result == 0);
51}
52</ompts:testcode>
53</ompts:test>