blob: a529c07346a5375ea569c119a030702bbd40c22c [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the omp_set_lock and the omp_unset_lock function by counting the threads entering and exiting a single region with locks.</ompts:testdescription>
3<ompts:ompversion>2.0</ompts:ompversion>
4<ompts:directive>omp_lock</ompts:directive>
5<ompts:dependences>omp flush</ompts:dependences>
6<ompts:testcode>
7#include <stdio.h>
8#include "omp_testsuite.h"
9
10omp_lock_t lck;
11
12int <ompts:testcode:functionname>omp_lock</ompts:testcode:functionname>(FILE * logFile)
13{
14 int nr_threads_in_single = 0;
15 int result = 0;
16 int nr_iterations = 0;
17 int i;
18 omp_init_lock (&lck);
19
20#pragma omp parallel shared(lck)
21 {
22 #pragma omp for
23 for(i = 0; i < LOOPCOUNT; i++)
24 {
25 <ompts:orphan>
26 <ompts:check>omp_set_lock (&lck);</ompts:check>
27 </ompts:orphan>
28#pragma omp flush
29 nr_threads_in_single++;
30#pragma omp flush
31 nr_iterations++;
32 nr_threads_in_single--;
33 result = result + nr_threads_in_single;
34 <ompts:orphan>
35 <ompts:check>omp_unset_lock(&lck);</ompts:check>
36 </ompts:orphan>
37 }
38 }
39 omp_destroy_lock (&lck);
40
41 return ((result == 0) && (nr_iterations == LOOPCOUNT));
42
43}
44</ompts:testcode>
45</ompts:test>