1// RUN: %libomp-compile && env OMP_DYNAMIC=true KMP_DYNAMIC_MODE=random %libomp-run
2
3// gcc/icc target offloading is incompatible with libomp
4// UNSUPPORTED: icc, gcc
5
6// This is a super simple unit test to see that teams behave properly when
7// parallel regions inside the teams construct cannot allocate teams of
8// thread_limit size.
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <omp.h>
13
14#define NUM_TIMES 10
15
16int main(int argc, char **argv) {
17 int num_procs = omp_get_max_threads();
18 int num_teams, thread_limit, i;
19 num_teams = 2;
20 thread_limit = num_procs / num_teams;
21 for (i = 0; i < NUM_TIMES; ++i) {
22#pragma omp target teams num_teams(num_teams) thread_limit(thread_limit)
23 {
24#pragma omp parallel num_threads(thread_limit)
25 {
26 int my_num_threads = omp_get_num_threads();
27 int my_num_teams = omp_get_num_teams();
28 int my_team_id = omp_get_team_num();
29 int my_thread_id = omp_get_thread_num();
30 if (my_num_teams < 0 || my_num_teams > num_teams) {
31 fprintf(stderr, format: "error: my_num_teams (%d) invalid\n", my_num_teams);
32 exit(status: 1);
33 }
34 if (my_team_id < 0 || my_team_id >= my_num_teams) {
35 fprintf(stderr, format: "error: my_team_id (%d) invalid (nteams = %d)\n",
36 my_team_id, my_num_teams);
37 exit(status: 1);
38 }
39 if (my_thread_id < 0 || my_thread_id >= my_num_threads) {
40 fprintf(stderr,
41 format: "error: my_thread_id (%d) invalid (my_num_threads = %d)\n",
42 my_thread_id, my_num_threads);
43 exit(status: 1);
44 }
45 }
46 }
47 }
48 return 0;
49}
50

source code of openmp/runtime/test/teams/teams_resize.c