LLVM OpenMP
omp_num_threads_dev_overflow.c
Go to the documentation of this file.
1// RUN: %libomp-compile
2// RUN: env KMP_WARNINGS=1 OMP_NUM_THREADS_DEV_2147483647=10 \
3// RUN: OMP_NUM_THREADS_DEV_99999999999=20 \
4// RUN: OMP_NUM_THREADS_DEV_000000000001=10 \
5// RUN: OMP_NUM_THREADS_DEV0=30 OMP_NUM_THREADS_ALLEY=40 \
6// RUN: OMP_NUM_THREADS_ALL=4 \
7// RUN: %libomp-run 2>&1 | FileCheck %s
8//
9// (a) `_DEV_<huge>` rejected with a warning;
10// (b) similar-looking names (`_DEV0`, `_ALLEY`) silently ignored, no warning;
11// (c) leading zeros are a valid device id (`000000000001` is device 1);
12// (d) sibling valid `_ALL=4` still applies.
13
14#include <omp.h>
15#include <stdio.h>
16#include <string.h>
17
18extern const char *__kmpc_get_device_env(const char *name, int device_id);
19
20int main(void) {
21 if (omp_get_max_threads() != 4) {
22 fprintf(stderr, "FAIL: host got %d, expected 4\n", omp_get_max_threads());
23 return 1;
24 }
25 const char *q = __kmpc_get_device_env("OMP_NUM_THREADS", 2147483646);
26 if (q == NULL || strcmp(q, "4") != 0) {
27 fprintf(stderr, "FAIL: large valid id expected '4', got %s\n",
28 q ? q : "(null)");
29 return 1;
30 }
31 q = __kmpc_get_device_env("OMP_NUM_THREADS", 1);
32 if (q == NULL || strcmp(q, "10") != 0) {
33 fprintf(stderr, "FAIL: padded device id expected '10', got %s\n",
34 q ? q : "(null)");
35 return 1;
36 }
37 printf("DONE\n");
38 return 0;
39}
40
41// CHECK: {{^OMP: Warning #[0-9]+:.*OMP_NUM_THREADS_DEV_2147483647.*}}
42// CHECK: {{^OMP: Warning #[0-9]+:.*OMP_NUM_THREADS_DEV_99999999999.*}}
43// CHECK-NOT: {{^OMP: Warning #[0-9]+:.*OMP_NUM_THREADS_DEV_000000000001.*}}
44// CHECK-NOT: {{^OMP: Warning #[0-9]+:.*OMP_NUM_THREADS_DEV0.*}}
45// CHECK-NOT: {{^OMP: Warning #[0-9]+:.*OMP_NUM_THREADS_ALLEY.*}}
46// CHECK: DONE
__itt_string_handle * name
Definition ittnotify.h:3305
int main(void)
const char * __kmpc_get_device_env(const char *name, int device_id)
int omp_get_max_threads()