llvm-project/openmp/runtime/test
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
..
affinity [OpenMP] Fix misleading warning for OMP_PLACES 2021-01-27 14:27:24 -06:00
api [OpenMP] libomp: implement nteams-var and teams-thread-limit-var ICVs 2021-02-01 22:54:11 +03:00
atomic
barrier [OpenMP] Fix hierarchical barrier 2021-01-13 10:22:57 -06:00
critical
env [OpenMP] Limit number of dispatch buffers 2021-02-22 13:14:28 -06:00
flush Fix for bugzilla https://bugs.llvm.org/show_bug.cgi?id=39970 2018-12-13 10:04:10 +00:00
lock [OpenMP] NFC: Fix trivial typo 2020-04-04 12:06:54 +09:00
master
misc_bugs [OpenMP][Tests] Fix compiler warnings in OpenMP runtime tests 2020-11-11 20:13:21 +01:00
ompt [OpenMP] Add runtime interface for OpenMP 5.1 error directive 2021-03-16 08:55:25 -05:00
parallel [OpenMP 5.0] Add omp_get_supported_active_levels() 2019-02-19 18:51:11 +00:00
tasking [OpenMP] Fixed a crash in hidden helper thread 2021-03-18 18:25:36 -04:00
teams [OpenMP] NFC: fix test removing the target construct 2021-02-13 04:49:52 +03:00
threadprivate [OpenMP] NFC: Fix trivial typos in comments 2020-01-07 14:05:03 +08:00
worksharing [OpenMP] Fix potential integer overflow in dynamic schedule code 2021-03-08 09:43:05 -06:00
CMakeLists.txt [OpenMP][Tool] Extend reuse of OMPT testing 2020-06-14 15:55:32 +02:00
lit.cfg [OpenMP] Fix python3 compatibility in openmp's lit.cfg 2021-02-01 08:20:26 +01:00
lit.site.cfg.in [OpenMP] Add scaffolding for negative runtime tests 2020-04-21 17:10:50 -04:00
omp_my_sleep.h
omp_testsuite.h