LLVM OpenMP
omp_nteams_api_restriction.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run 2>&1 | FileCheck %s
2// Verify that omp_set_num_teams() and omp_set_teams_thread_limit() are
3// ignored when called from within a parallel or teams region.
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <omp.h>
8
9int main(int argc, char **argv) {
10 int err = 0;
11
12 // Set initial values outside any region.
13 omp_set_num_teams(5);
14 omp_set_teams_thread_limit(7);
15
16 if (omp_get_max_teams() != 5) {
17 fprintf(stderr, "error: nteams-var not set correctly\n");
18 exit(1);
19 }
20 if (omp_get_teams_thread_limit() != 7) {
21 fprintf(stderr, "error: teams-thread-limit-var not set correctly\n");
22 exit(1);
23 }
24
25 // Call from inside a teams region -- should be ignored.
26 // Use num_teams(1) to ensure exactly one team and deterministic warning
27 // count.
28#pragma omp teams num_teams(1)
29 {
30 omp_set_num_teams(99);
31 omp_set_teams_thread_limit(99);
32 }
33
34 if (omp_get_max_teams() != 5) {
35 fprintf(stderr, "error: nteams-var modified inside teams region\n");
36 err++;
37 }
38 if (omp_get_teams_thread_limit() != 7) {
39 fprintf(stderr, "error: teams-thread-limit-var modified inside teams "
40 "region\n");
41 err++;
42 }
43
44 // Call from inside a parallel region -- should be ignored.
45#pragma omp parallel num_threads(1)
46 {
47 omp_set_num_teams(99);
48 omp_set_teams_thread_limit(99);
49 }
50
51 if (omp_get_max_teams() != 5) {
52 fprintf(stderr, "error: nteams-var modified inside parallel region\n");
53 err++;
54 }
55 if (omp_get_teams_thread_limit() != 7) {
56 fprintf(stderr, "error: teams-thread-limit-var modified inside parallel "
57 "region\n");
58 err++;
59 }
60
61 if (err == 0) {
62 printf("passed\n");
63 }
64 return err;
65}
66
67// CHECK: OMP: Warning{{.*}}omp_set_num_teams{{.*}}call ignored
68// CHECK: OMP: Warning{{.*}}omp_set_teams_thread_limit{{.*}}call ignored
69// CHECK: OMP: Warning{{.*}}omp_set_num_teams{{.*}}call ignored
70// CHECK: OMP: Warning{{.*}}omp_set_teams_thread_limit{{.*}}call ignored
71// CHECK: passed
static int err
int main()
Definition test-touch.c:21