llvm-project/openmp/runtime/test/tasking/hidden_helper_task
Shilei Tian 2df65f87c1 [OpenMP] Fixed a crash in hidden helper thread
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
2021-03-18 18:25:36 -04:00
..
capacity_mix_threads.cpp [OpenMP] Fixed a crash in hidden helper thread 2021-03-18 18:25:36 -04:00
capacity_nthreads.cpp [OpenMP] Fixed a crash in hidden helper thread 2021-03-18 18:25:36 -04:00
common.h [OpenMP] Added the support for hidden helper task in RTL 2021-01-25 22:16:17 -05:00
depend.cpp [OpenMP] Added the support for hidden helper task in RTL 2021-01-25 22:16:17 -05:00
gtid.cpp [OpenMP] Added the support for hidden helper task in RTL 2021-01-25 22:16:17 -05:00
taskgroup.cpp [OpenMP] Added the support for hidden helper task in RTL 2021-01-25 22:16:17 -05:00