LLVM OpenMP
20.0.0git
runtime
test
tasking
omp_task.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
#include <stdio.h>
3
#include <math.h>
4
#include "
omp_testsuite.h
"
5
#include "
omp_my_sleep.h
"
6
7
int
test_omp_task
()
8
{
9
int
tids[
NUM_TASKS
];
10
int
i
;
11
12
#pragma omp parallel
13
{
14
#pragma omp single
15
{
16
for
(
i
= 0;
i
<
NUM_TASKS
;
i
++) {
17
/* First we have to store the value of the loop index in a new variable
18
* which will be private for each task because otherwise it will be overwritten
19
* if the execution of the task takes longer than the time which is needed to
20
* enter the next step of the loop!
21
*/
22
int
myi;
23
myi =
i
;
24
#pragma omp task
25
{
26
my_sleep
(
SLEEPTIME
);
27
tids[myi] = omp_get_thread_num();
28
}
/* end of omp task */
29
}
/* end of for */
30
}
/* end of single */
31
}
/*end of parallel */
32
33
/* Now we ckeck if more than one thread executed the tasks. */
34
for
(
i
= 1;
i
<
NUM_TASKS
;
i
++) {
35
if
(tids[0] != tids[
i
])
36
return
1;
37
}
38
return
0;
39
}
/* end of check_parallel_for_private */
40
41
int
main
()
42
{
43
int
i
;
44
int
num_failed=0;
45
46
if
(
omp_get_max_threads
() < 2)
47
omp_set_num_threads
(8);
48
49
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
50
if
(!
test_omp_task
()) {
51
num_failed++;
52
}
53
}
54
return
num_failed;
55
}
i
#define i
Definition:
kmp_stub.cpp:87
omp_set_num_threads
#define omp_set_num_threads
Definition:
kmp_stub.cpp:34
omp_my_sleep.h
my_sleep
static void my_sleep(double sleeptime)
Utility function to have a sleep function with better resolution and which only stops one thread.
Definition:
omp_my_sleep.h:24
test_omp_task
int test_omp_task()
Definition:
omp_task.c:7
main
int main()
Definition:
omp_task.c:41
omp_testsuite.h
SLEEPTIME
#define SLEEPTIME
Definition:
omp_testsuite.h:16
NUM_TASKS
#define NUM_TASKS
Definition:
omp_testsuite.h:20
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
omp_get_max_threads
int omp_get_max_threads()
Generated on Wed Jan 29 2025 20:58:02 for LLVM OpenMP by
1.9.6