aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/icv-9.c
blob: 21b874f8ae9296084ab5e93e1d980192ffd0b51f (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* { dg-do run } */

/* This tests usage of ICVs on the host and on devices if no corresponding
   environment variables are configured.  */

#include <omp.h>
#include <stdlib.h>

int
main ()
{
  if (omp_get_max_teams () != 0
      || omp_get_teams_thread_limit () != 0)
    abort ();

  omp_set_num_teams (9);
  omp_set_teams_thread_limit (2);
  if (omp_get_max_teams () != 9
      || omp_get_teams_thread_limit () != 2)
    abort ();

  #pragma omp teams
  if (omp_get_num_teams () > 9
      || omp_get_team_num () >= 9)
    abort ();

  #pragma omp teams num_teams(5)
  if (omp_get_num_teams () > 5
      || omp_get_team_num () >= 5)
    abort ();

  int num_devices = omp_get_num_devices () > 3 ? 3 : omp_get_num_devices ();
  for (int i = 0; i < num_devices; i++)
    {
      #pragma omp target device (i)
      if (omp_get_max_teams () != 0
	  || omp_get_teams_thread_limit () != 0)
	abort ();

      #pragma omp target device (i)
      {
	omp_set_num_teams (8 + i);
	omp_set_teams_thread_limit (3 + i);
	if (omp_get_max_teams () != 8 + i
	    || omp_get_teams_thread_limit () != 3 + i)
	  abort ();
      }

     /* omp_set_num_teams above set the value of nteams-var ICV on device 'i',
	 which has scope 'device' and should be avaible in subsequent target
	 regions.  */
      #pragma omp target device (i)
      if (omp_get_max_teams () != 8 + i
	  || omp_get_teams_thread_limit () != 3 + i)
	abort ();

      #pragma omp target device (i)
      #pragma omp teams
      if (omp_get_num_teams () > 8 + i
	  || omp_get_team_num () >= 8 + i)
	abort ();

      /* NUM_TEAMS clause has priority over previously set NUM_TEAMS value.  */
      #pragma omp target device (i)
      #pragma omp teams num_teams(5 + i)
      if (omp_get_num_teams () > 5 + i
	  || omp_get_team_num () >= 5 + i)
	abort ();
    }

  return 0;
}