(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
task-detach-8.c
       1  /* { dg-do run } */
       2  
       3  #include <omp.h>
       4  #include <assert.h>
       5  
       6  /* Test tasks with detach clause on an offload device.  Each device
       7     thread spawns off a chain of tasks, that can then be executed by
       8     any available thread.  Each thread uses taskwait to wait for the
       9     child tasks to complete.  */
      10  
      11  int main (void)
      12  {
      13    int x = 0, y = 0, z = 0;
      14    int thread_count;
      15    omp_event_handle_t detach_event1, detach_event2;
      16  
      17    #pragma omp target map (tofrom: x, y, z) map (from: thread_count)
      18      #pragma omp parallel private (detach_event1, detach_event2)
      19        {
      20  	#pragma omp single
      21  	  thread_count = omp_get_num_threads ();
      22  
      23  	#pragma omp task detach (detach_event1) untied
      24  	  #pragma omp atomic update
      25  	    x++;
      26  
      27  	#pragma omp task detach (detach_event2) untied
      28  	{
      29  	  #pragma omp atomic update
      30  	    y++;
      31  	  omp_fulfill_event (detach_event1);
      32  	}
      33  
      34  	#pragma omp task untied
      35  	{
      36  	  #pragma omp atomic update
      37  	    z++;
      38  	  omp_fulfill_event (detach_event2);
      39  	}
      40  
      41  	#pragma omp taskwait
      42        }
      43  
      44    assert (x == thread_count);
      45    assert (y == thread_count);
      46    assert (z == thread_count);
      47  }