forked from OSchip/llvm-project
2df65f87c1
It is reported that after enabling hidden helper thread, the program can hit the assertion `new_gtid < __kmp_threads_capacity` sometimes. The root cause is explained as follows. Let's say the default `__kmp_threads_capacity` is `N`. If hidden helper thread is enabled, `__kmp_threads_capacity` will be offset to `N+8` by default. If the number of threads we need exceeds `N+8`, e.g. via `num_threads` clause, we need to expand `__kmp_threads`. In `__kmp_expand_threads`, the expansion starts from `__kmp_threads_capacity`, and repeatedly doubling it until the new capacity meets the requirement. Let's assume the new requirement is `Y`. If `Y` happens to meet the constraint `(N+8)*2^X=Y` where `X` is the number of iterations, the new capacity is not enough because we have 8 slots for hidden helper threads. Here is an example. ``` #include <vector> int main(int argc, char *argv[]) { constexpr const size_t N = 1344; std::vector<int> data(N); #pragma omp parallel for for (unsigned i = 0; i < N; ++i) { data[i] = i; } #pragma omp parallel for num_threads(N) for (unsigned i = 0; i < N; ++i) { data[i] += i; } return 0; } ``` My CPU is 20C40T, then `__kmp_threads_capacity` is 160. After offset, `__kmp_threads_capacity` becomes 168. `1344 = (160+8)*2^3`, then the assertions hit. Reviewed By: protze.joachim Differential Revision: https://reviews.llvm.org/D98838 |
||
---|---|---|
.. | ||
hidden_helper_task | ||
bug_36720.c | ||
bug_nested_proxy_task.c | ||
bug_proxy_task_dep_waiting.c | ||
bug_serial_taskgroup.c | ||
bug_taskwait_detach.cpp | ||
kmp_detach_tasks_t1.c | ||
kmp_detach_tasks_t2.c | ||
kmp_detach_tasks_t3.c | ||
kmp_task_modifier_simple_par_new.cpp | ||
kmp_task_modifier_simple_par_old.cpp | ||
kmp_task_modifier_simple_ws_new.cpp | ||
kmp_task_modifier_simple_ws_old.cpp | ||
kmp_task_reduction_nest.cpp | ||
kmp_taskloop.c | ||
kmp_taskloop_5.c | ||
nested_parallel_tasking.c | ||
nested_task_creation.c | ||
omp50_task_depend_mtx.c | ||
omp50_task_depend_mtx2.c | ||
omp50_task_depend_mtx3.c | ||
omp50_taskwait_depend.c | ||
omp_detach_taskwait.c | ||
omp_fill_taskqueue.c | ||
omp_task.c | ||
omp_task_depend_resize_hashmap.c | ||
omp_task_final.c | ||
omp_task_firstprivate.c | ||
omp_task_if.c | ||
omp_task_imp_firstprivate.c | ||
omp_task_priority.c | ||
omp_task_private.c | ||
omp_task_red_taskloop.c | ||
omp_task_shared.c | ||
omp_taskloop_grainsize.c | ||
omp_taskloop_num_tasks.c | ||
omp_taskloop_taskwait.c | ||
omp_taskwait.c | ||
omp_taskyield.c | ||
taskdep_if0.c | ||
taskdep_if0_2.c |