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 @@ -1245,13 +1245,25 @@ // task if (__kmp_hidden_helper_threads_num == 0) { __kmp_enable_hidden_helper = FALSE; + } else { + // Since the main thread of hidden helper team dooes not participate + // in tasks execution let's increment the number of threads by one + // so that requested number of threads do actual job. + __kmp_hidden_helper_threads_num++; } } // __kmp_stg_parse_num_hidden_helper_threads static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer, char const *name, void *data) { - __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num); + if (__kmp_hidden_helper_threads_num == 0) { + __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num); + } else { + KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1); + // Let's exclude the main thread of hidden helper team and print + // number of worker threads those do actual job. + __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1); + } } // __kmp_stg_print_num_hidden_helper_threads static void __kmp_stg_parse_use_hidden_helper(char const *name, diff --git a/openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c b/openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c @@ -0,0 +1,21 @@ +// RUN: %libomp-compile && env LIBOMP_NUM_HIDDEN_HELPER_THREADS=1 %libomp-run + +// The test checks that "devide-by-0" bug fixed in runtime. +// The fix is to increment number of threads by 1 if positive, +// so that operation +// (gtid) % (__kmp_hidden_helper_threads_num - 1) +// does not cause crash. + +#include +#include + +int main(){ +#pragma omp target nowait + { + printf("----- in target region\n"); + } + printf("------ before taskwait\n"); +#pragma omp taskwait + printf("passed\n"); + return 0; +}