| Issue |
181784
|
| Summary |
[libomp] Possible inconsistency between `OMP_WAIT_POLICY` and `KMP_USE_YIELD`
|
| Labels |
openmp:libomp
|
| Assignees |
|
| Reporter |
kasuga-fj
|
I'm not an expert on libomp so I'm pretty sure I'm missing something. However, I'm under the impression that when `OMP_WAIT_POLICY=ACTIVE` is set, `KMP_USE_YIELD=2`, which means threads only yield when oversubscribed, should also be implied.
First, there is a function `__kmp_aux_set_library`. In this function, the variable `__kmp_use_yield`, which reflects the value of `KMP_USE_YIELD`, is set to 2 when `__kmp_library` is `library_turnaround`, which corresponds to `OMP_WAIT_POLICY=ACTIVE`: https://github.com/llvm/llvm-project/blob/530c938485d7c4119e8df3f57e288f9f20a183cd/openmp/runtime/src/kmp_runtime.cpp#L8473-L8491 . There seems to be no way for users to call this function directly (perhaps it's intended for the compiler frontend?), but based on this code, it appears that the original intention was to set `KMP_USE_YIELD=2` when `OMP_WAIT_POLICY=ACTIVE` is specified.
Second, [in Section 4.3.3 in the OpenMP 6.0 Specification](https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf), the following is stated about `OMP_WAIT_POLICY=ACTIVE`:
> The active value specifies that waiting native threads should mostly be active, consuming processor cycles, while waiting. A compliant implementation may, for example, make waiting native threads spin.
Given this, it seems reasonable not to yield aggressively when `OMP_WAIT_POLICY=ACTIVE` is set.
In the current implementation, `__kmp_dflt_blocktime` would be set to "infinity" when `OMP_WAIT_POLICY=ACTIVE` is set and `KMP_BLOCKTIME` is not explicitly set https://github.com/llvm/llvm-project/blob/530c938485d7c4119e8df3f57e288f9f20a183cd/openmp/runtime/src/kmp_settings.cpp#L826-L831 . Likewise, I think it would be reasonable to set `__kmp_use_yield` to 2 when `OMP_WAIT_POLICY=ACTIVE` is set and `KMP_USE_YIELD` is not explicitly set. I ran some benchmarks (including [EPCC OpenMP Microbenchmarks](https://github.com/EPCCed/epcc-openmp-microbenchmarks)), and observed performance improvements when `KMP_USE_YIELD=2` (or `KMP_USE_YIELD=0`) is used together with `OMP_WAIT_POLICY=ACTIVE`.
slightly off-topic: I also noticed that there are several environment variables that are not documented in https://openmp.llvm.org/design/Runtimes.html. Is there a reason for this? Or is it just that the documentation has not been updated?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs