(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
task-detach-10.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 in a taskgroup, that can then
       8     be executed by any available thread.  */
       9  
      10  int main (void)
      11  {
      12    int x = 0, y = 0, z = 0;
      13    int thread_count;
      14    omp_event_handle_t detach_event1, detach_event2;
      15  
      16    #pragma omp target map (tofrom: x, y, z) map (from: thread_count)
      17      #pragma omp parallel private (detach_event1, detach_event2)
      18        #pragma omp taskgroup
      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  
      42    assert (x == thread_count);
      43    assert (y == thread_count);
      44    assert (z == thread_count);
      45  }