(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
icv-9.c
       1  /* { dg-do run } */
       2  
       3  /* This tests usage of ICVs on the host and on devices if no corresponding
       4     environment variables are configured.  */
       5  
       6  #include <omp.h>
       7  #include <stdlib.h>
       8  
       9  int
      10  main ()
      11  {
      12    if (omp_get_max_teams () != 0
      13        || omp_get_teams_thread_limit () != 0)
      14      abort ();
      15  
      16    omp_set_num_teams (9);
      17    omp_set_teams_thread_limit (2);
      18    if (omp_get_max_teams () != 9
      19        || omp_get_teams_thread_limit () != 2)
      20      abort ();
      21  
      22    #pragma omp teams
      23    if (omp_get_num_teams () > 9
      24        || omp_get_team_num () >= 9)
      25      abort ();
      26  
      27    #pragma omp teams num_teams(5)
      28    if (omp_get_num_teams () > 5
      29        || omp_get_team_num () >= 5)
      30      abort ();
      31  
      32    int num_devices = omp_get_num_devices () > 3 ? 3 : omp_get_num_devices ();
      33    for (int i = 0; i < num_devices; i++)
      34      {
      35        #pragma omp target device (i)
      36        if (omp_get_max_teams () != 0
      37  	  || omp_get_teams_thread_limit () != 0)
      38  	abort ();
      39  
      40        #pragma omp target device (i)
      41        {
      42  	omp_set_num_teams (8 + i);
      43  	omp_set_teams_thread_limit (3 + i);
      44  	if (omp_get_max_teams () != 8 + i
      45  	    || omp_get_teams_thread_limit () != 3 + i)
      46  	  abort ();
      47        }
      48  
      49       /* omp_set_num_teams above set the value of nteams-var ICV on device 'i',
      50  	 which has scope 'device' and should be avaible in subsequent target
      51  	 regions.  */
      52        #pragma omp target device (i)
      53        if (omp_get_max_teams () != 8 + i
      54  	  || omp_get_teams_thread_limit () != 3 + i)
      55  	abort ();
      56  
      57        #pragma omp target device (i)
      58        #pragma omp teams
      59        if (omp_get_num_teams () > 8 + i
      60  	  || omp_get_team_num () >= 8 + i)
      61  	abort ();
      62  
      63        /* NUM_TEAMS clause has priority over previously set NUM_TEAMS value.  */
      64        #pragma omp target device (i)
      65        #pragma omp teams num_teams(5 + i)
      66        if (omp_get_num_teams () > 5 + i
      67  	  || omp_get_team_num () >= 5 + i)
      68  	abort ();
      69      }
      70  
      71    return 0;
      72  }