aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/task-detach-7.f90
blob: 32e715e0f81acff868051ef3c1edbc443537be5b (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
39
40
41
42
! { dg-do run }

! Test tasks with detach clause.  Each thread spawns off a chain of tasks,
! that can then be executed by any available thread.  Each thread uses
! taskwait to wait for the child tasks to complete.

program task_detach_7
  use omp_lib

  integer (kind=omp_event_handle_kind) :: detach_event1, detach_event2
  integer :: x = 0, y = 0, z = 0
  integer :: thread_count

  !$omp parallel private (detach_event1, detach_event2)
    !$omp single
      thread_count = omp_get_num_threads()
    !$omp end single

    !$omp task detach (detach_event1) untied
      !$omp atomic update
	x = x + 1
    !$omp end task

    !$omp task detach (detach_event2) untied
      !$omp atomic update
	y = y + 1
      call omp_fulfill_event (detach_event1)
    !$omp end task

    !$omp task untied
      !$omp atomic update
	z = z + 1
      call omp_fulfill_event (detach_event2)
    !$omp end task

    !$omp taskwait
  !$omp end parallel

  if (x /= thread_count) stop 1
  if (y /= thread_count) stop 2
  if (z /= thread_count) stop 3
end program