LLVM OpenMP
omp_num_threads_host_overrides_all.c
Go to the documentation of this file.
1// RUN: %libomp-compile && \
2// RUN: env OMP_NUM_THREADS=4 OMP_NUM_THREADS_ALL=8 %libomp-run
3//
4// Host OMP_NUM_THREADS beats _ALL; sibling `_ALL` still applies on devices.
5
6#include <omp.h>
7#include <stdio.h>
8#include <string.h>
9
10extern const char *__kmpc_get_device_env(const char *name, int device_id);
11
12int main(void) {
13 int max = omp_get_max_threads();
14 if (max != 4) {
15 fprintf(stderr, "FAIL: omp_get_max_threads()=%d, expected 4\n", max);
16 return 1;
17 }
18 // Sibling `_ALL` must still resolve for non-host devices.
19 const char *dev0 = __kmpc_get_device_env("OMP_NUM_THREADS", 0);
20 if (dev0 == NULL || strcmp(dev0, "8") != 0) {
21 fprintf(stderr, "FAIL: dev 0 query expected '8' got '%s'\n",
22 dev0 ? dev0 : "(null)");
23 return 1;
24 }
25 return 0;
26}
__itt_string_handle * name
Definition ittnotify.h:3305
const char * __kmpc_get_device_env(const char *name, int device_id)
int omp_get_max_threads()