LLVM OpenMP
omp_num_threads_dev_resolve.c
Go to the documentation of this file.
1// RUN: %libomp-compile && \
2// RUN: env OMP_NUM_THREADS_ALL=8 OMP_NUM_THREADS_DEV=64 \
3// RUN: OMP_NUM_THREADS_DEV_0=128 %libomp-run
4//
5// OpenMP 6.0 non-host precedence: `_DEV_<d>` > `_DEV` > `_ALL` > default.
6
7#include <omp.h>
8#include <stdio.h>
9#include <string.h>
10
11extern const char *__kmpc_get_device_env(const char *name, int device_id);
12
13static int check(const char *got, int device_id, const char *expect) {
14 if (got == NULL || strcmp(got, expect) != 0) {
15 fprintf(stderr, "FAIL: device_id=%d resolved to '%s', expected '%s'\n",
16 device_id, got ? got : "(null)", expect);
17 return 1;
18 }
19 return 0;
20}
21
22int main(void) {
23 int rc = 0;
24 if (omp_get_max_threads() != 8) {
25 fprintf(stderr, "FAIL: host omp_get_max_threads()=%d, expected 8\n",
27 return 1;
28 }
29 rc |= check(__kmpc_get_device_env("OMP_NUM_THREADS", 0), 0, "128"); // _DEV_0
30 rc |= check(__kmpc_get_device_env("OMP_NUM_THREADS", 1), 1, "64"); // _DEV
31 rc |= check(__kmpc_get_device_env("OMP_NUM_THREADS", 2), 2, "64"); // _DEV
32 return rc;
33}
#define check(condition)
__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()