diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -1124,7 +1124,10 @@ #define KMP_MAX_CHUNK (INT_MAX - 1) #define KMP_DEFAULT_CHUNK 1 +#define KMP_MIN_DISP_NUM_BUFF 1 #define KMP_DFLT_DISP_NUM_BUFF 7 +#define KMP_MAX_DISP_NUM_BUFF 4096 + #define KMP_MAX_ORDERED 8 #define KMP_MAX_FIELDS 32 diff --git a/openmp/runtime/src/kmp_csupport.cpp b/openmp/runtime/src/kmp_csupport.cpp --- a/openmp/runtime/src/kmp_csupport.cpp +++ b/openmp/runtime/src/kmp_csupport.cpp @@ -1988,8 +1988,10 @@ void kmpc_set_disp_num_buffers(int arg) { // ignore after initialization because some teams have already // allocated dispatch buffers - if (__kmp_init_serial == 0 && arg > 0) + if (__kmp_init_serial == FALSE && arg >= KMP_MIN_DISP_NUM_BUFF && + arg <= KMP_MAX_DISP_NUM_BUFF) { __kmp_dispatch_num_buffers = arg; + } } int kmpc_set_affinity_mask_proc(int proc, void **mask) { diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/openmp/runtime/src/kmp_ftn_entry.h @@ -202,8 +202,11 @@ #else // ignore after initialization because some teams have already // allocated dispatch buffers - if (__kmp_init_serial == 0 && (KMP_DEREF arg) > 0) - __kmp_dispatch_num_buffers = KMP_DEREF arg; + int num_buffers = KMP_DEREF arg; + if (__kmp_init_serial == FALSE && num_buffers >= KMP_MIN_DISP_NUM_BUFF && + num_buffers <= KMP_MAX_DISP_NUM_BUFF) { + __kmp_dispatch_num_buffers = num_buffers; + } #endif } 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 @@ -1389,7 +1389,8 @@ KMP_WARNING(EnvSerialWarn, name); return; } // read value before serial initialization only - __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers); + __kmp_stg_parse_int(name, value, KMP_MIN_DISP_NUM_BUFF, KMP_MAX_DISP_NUM_BUFF, + &__kmp_dispatch_num_buffers); } // __kmp_stg_parse_disp_buffers static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer, diff --git a/openmp/runtime/test/env/kmp_dispatch_buf_range.c b/openmp/runtime/test/env/kmp_dispatch_buf_range.c new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/env/kmp_dispatch_buf_range.c @@ -0,0 +1,18 @@ +// RUN: %libomp-compile +// RUN: env KMP_DISP_NUM_BUFFERS=0 %libomp-run 2>&1 | FileCheck --check-prefix=SMALL %s +// RUN: env KMP_DISP_NUM_BUFFERS=4097 %libomp-run 2>&1 | FileCheck --check-prefix=LARGE %s +// SMALL: OMP: Warning +// SMALL-SAME: KMP_DISP_NUM_BUFFERS +// SMALL-SAME: too small +// LARGE: OMP: Warning +// LARGE-SAME: KMP_DISP_NUM_BUFFERS +// LARGE-SAME: too large +#include +#include + +int main() { + int i; + #pragma omp parallel for + for (i = 0; i < 1000; i++) {} + return EXIT_SUCCESS; +}