| 1 |
! { dg-do run } |
| 2 |
|
| 3 |
! Test tasks with detach clause. Each thread spawns off a chain of tasks |
| 4 |
! in a taskgroup, that can then be executed by any available thread. |
| 5 |
|
| 6 |
program task_detach_9 |
| 7 |
use omp_lib |
| 8 |
|
| 9 |
integer (kind=omp_event_handle_kind) :: detach_event1, detach_event2 |
| 10 |
integer :: x = 0, y = 0, z = 0 |
| 11 |
integer :: thread_count |
| 12 |
|
| 13 |
!$omp parallel private (detach_event1, detach_event2) |
| 14 |
!$omp taskgroup |
| 15 |
!$omp single |
| 16 |
thread_count = omp_get_num_threads () |
| 17 |
!$omp end single |
| 18 |
|
| 19 |
!$omp task detach (detach_event1) untied |
| 20 |
!$omp atomic update |
| 21 |
x = x + 1 |
| 22 |
!$omp end task |
| 23 |
|
| 24 |
!$omp task detach (detach_event2) untied |
| 25 |
!$omp atomic update |
| 26 |
y = y + 1 |
| 27 |
call omp_fulfill_event (detach_event1); |
| 28 |
!$omp end task |
| 29 |
|
| 30 |
!$omp task untied |
| 31 |
!$omp atomic update |
| 32 |
z = z + 1 |
| 33 |
call omp_fulfill_event (detach_event2); |
| 34 |
!$omp end task |
| 35 |
!$omp end taskgroup |
| 36 |
!$omp end parallel |
| 37 |
|
| 38 |
if (x /= thread_count) stop 1 |
| 39 |
if (y /= thread_count) stop 2 |
| 40 |
if (z /= thread_count) stop 3 |
| 41 |
end program |