diff --git a/openmp/runtime/src/kmp_settings.cpp b/openmp/runtime/src/kmp_settings.cpp --- a/openmp/runtime/src/kmp_settings.cpp +++ b/openmp/runtime/src/kmp_settings.cpp @@ -3272,6 +3272,7 @@ } __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format); } + // OMP_ALLOCATOR sets default allocator static void __kmp_stg_parse_allocator(char const *name, char const *value, void *data) { @@ -3289,104 +3290,65 @@ */ const char *buf = value; const char *next; - int num; SKIP_WS(buf); - if ((*buf > '0') && (*buf < '9')) { - next = buf; - SKIP_DIGITS(next); - num = __kmp_str_to_int(buf, *next); - KMP_ASSERT(num > 0); - switch (num) { - case 4: + next = buf; + // check HBW first as the only non-default supported + if (__kmp_match_str("omp_high_bw_mem_alloc", buf, &next) || + __kmp_match_str("4", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { if (__kmp_memkind_available) { __kmp_def_allocator = omp_high_bw_mem_alloc; + return; } else { - __kmp_msg(kmp_ms_warning, - KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; + KMP_WARNING(OmpNoAllocator, "omp_high_bw_mem_alloc"); } - break; - case 1: - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 2: - __kmp_msg(kmp_ms_warning, - KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 3: - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 5: - __kmp_msg(kmp_ms_warning, - KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 6: - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 7: - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; - case 8: - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - break; } - return; - } - next = buf; - if (__kmp_match_str("omp_high_bw_mem_alloc", buf, &next)) { - if (__kmp_memkind_available) { - __kmp_def_allocator = omp_high_bw_mem_alloc; - } else { - __kmp_msg(kmp_ms_warning, - KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; + } else if (__kmp_match_str("omp_default_mem_alloc", buf, &next) || + __kmp_match_str("1", buf, &next)) { + // default requested + SKIP_WS(next); + } else if (__kmp_match_str("omp_large_cap_mem_alloc", buf, &next) || + __kmp_match_str("2", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_large_cap_mem_alloc"); + } + } else if (__kmp_match_str("omp_const_mem_alloc", buf, &next) || + __kmp_match_str("3", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_const_mem_alloc"); + } + } else if (__kmp_match_str("omp_low_lat_mem_alloc", buf, &next) || + __kmp_match_str("5", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_low_lat_mem_alloc"); + } + } else if (__kmp_match_str("omp_cgroup_mem_alloc", buf, &next) || + __kmp_match_str("6", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_cgroup_mem_alloc"); + } + } else if (__kmp_match_str("omp_pteam_mem_alloc", buf, &next) || + __kmp_match_str("7", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_pteam_mem_alloc"); + } + } else if (__kmp_match_str("omp_thread_mem_alloc", buf, &next) || + __kmp_match_str("8", buf, &next)) { + SKIP_WS(next); + if (*next == '\0') { + KMP_WARNING(OmpNoAllocator, "omp_thread_mem_alloc"); } - } else if (__kmp_match_str("omp_default_mem_alloc", buf, &next)) { - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_large_cap_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, - KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_const_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_low_lat_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_cgroup_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_pteam_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; - } else if (__kmp_match_str("omp_thread_mem_alloc", buf, &next)) { - __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"), - __kmp_msg_null); - __kmp_def_allocator = omp_default_mem_alloc; } - buf = next; - SKIP_WS(buf); - if (*buf != '\0') { - KMP_WARNING(ParseExtraCharsWarn, name, buf); + __kmp_def_allocator = omp_default_mem_alloc; + if (next == buf || *next != '\0') { + // either no match or extra symbols present after the matched token + KMP_WARNING(StgInvalidValue, name, value); } } diff --git a/openmp/runtime/test/env/omp_alloc_env_invalid.c b/openmp/runtime/test/env/omp_alloc_env_invalid.c new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/env/omp_alloc_env_invalid.c @@ -0,0 +1,16 @@ +// RUN: %libomp-compile +// RUN: env OMP_ALLOCATOR=111 %libomp-run 2>&1 | FileCheck %s +// RUN: env OMP_ALLOCATOR=omp_default_mem_alloc_xyz %libomp-run 2>&1 | FileCheck %s +// UNSUPPORTED: gcc + +// Both invocations of the test should produce (different) warnings: +// OMP: Warning #42: OMP_ALLOCATOR: "111" is an invalid value; ignored. +// OMP: Warning #189: Allocator omp_const_mem_alloc is not available, will use default allocator. +#include +#include +int main() { + volatile int n = omp_get_max_threads(); // causes library initialization + return 0; +} + +// CHECK: {{^OMP: Warning #[0-9]+}}: {{.*$}}