summaryrefslogtreecommitdiffstats
path: root/openmp/testsuite/c/omp_parallel_for_if.c
blob: 52886baa431ef143d10cac2b5d38c5e280a5880c (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
<ompts:test>
<ompts:testdescription>Test which checks the omp parallel for if directive. Needs at least two threads.</ompts:testdescription>
<ompts:ompversion>2.0</ompts:ompversion>
<ompts:directive>omp parallel for if</ompts:directive>
<ompts:dependences></ompts:dependences>
<ompts:testcode>
#include <stdio.h>
#include <math.h>
#include "omp_testsuite.h"

int <ompts:testcode:functionname>omp_parallel_for_if</ompts:testcode:functionname>(FILE * logFile){
    int known_sum;
    <ompts:orphan:vars>
    int num_threads;
    int sum, sum2;
    int i;
    int control;
    </ompts:orphan:vars>
    control = 0;
    num_threads=0;
    sum = 0;
    sum2 = 0;

#pragma omp parallel for private(i) <ompts:check>if (control==1)</ompts:check>
    <ompts:orphan>
    for (i=0; i <= LOOPCOUNT; i++)
    {
        num_threads = omp_get_num_threads();
	sum = sum + i;
    } /*end of for*/

    </ompts:orphan>
    known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
    fprintf (logFile, "Number of threads determined by omp_get_num_threads: %d\n", num_threads);
    return (known_sum == sum && num_threads == 1);
} /* end of check_parallel_for_private */
</ompts:testcode>
</ompts:test>
OpenPOWER on IntegriCloud