blob: 2aa94c402b5559059bdbd89661a9593a4e770c00 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the omp taskwait directive. First we generate a set of tasks, which set the elements of an array to a specific value. Then we do a taskwait and check if all tasks finished meaning all array elements contain the right value. Then we generate a second set setting the array elements to another value. After the parallel region we check if all tasks of the second set finished and were executed after the tasks of the first set.</ompts:testdescription>
3<ompts:ompversion>3.0</ompts:ompversion>
4<ompts:directive>omp taskwait</ompts:directive>
5<ompts:dependences>omp single,omp task</ompts:dependences>
6<ompts:testcode>
7 INCLUDE "omp_my_sleep.f"
8
9 INTEGER FUNCTION <ompts:testcode:functionname>omp_taskwait</ompts:testcode:functionname>()
10 IMPLICIT NONE
11 INCLUDE "omp_testsuite.f"
12 INTEGER result1, result2
13 INTEGER array(NUM_TASKS)
14 INTEGER i, myi
15 <ompts:orphan:vars>
16 external my_sleep
17 </ompts:orphan:vars>
18
19 result1 = 0
20 result2 = 0
21
22 ! fill array
23 do i = 1, NUM_TASKS
24 array(i) = 0
25 end do
26
27!$omp parallel shared(i) private(myi)
28!$omp single
29 do i=1, NUM_TASKS
30 ! First we have to store the value of the loop index in a new variable
31 ! which will be private for each task because otherwise it will be
32 ! overwritten if the execution of the task takes longer than the time
33 ! which is needed to enter the next step of the loop!
34
35 myi = i
36
37!$omp task
38 call my_sleep(SLEEPTIME)
39 array(myi) = 1
40!$omp end task
41 end do
42
43 <ompts:orphan>
44 <ompts:check>
45!$omp taskwait
46 </ompts:check>
47 </ompts:orphan>
48
49 ! check if all tasks were finished
50 do i=1, NUM_TASKS
51 if (array(i) .ne. 1) then
52 result1 = result1 + 1
53 end if
54 end do
55
56 ! generate some more tasks which now shall overwrite the valuesin the
57 ! array
58 do i=1, NUM_TASKS
59 myi = i
60!$omp task
61 array(myi) = 2
62!$omp end task
63 end do
64
65!$omp end single
66!$omp end parallel
67
68 ! final check, if all array elements contain the right values
69 do i=1, NUM_TASKS
70 if (array(i) .ne. 2) then
71 result2 = result2 + 1
72 end if
73 end do
74
75 if ( (result1 .eq. 0) .and. (result2 .eq. 0) ) then
76 <testfunctionname></testfunctionname> = 1
77 else
78 <testfunctionname></testfunctionname> = 0
79 end if
80
81 END FUNCTION
82</ompts:testcode>
83</ompts:test>