Skip to content

Commit

Permalink
OpenMP: Use omp_get_nested for older gcc versions (kokkos#6685)
Browse files Browse the repository at this point in the history
* OpenMP: fix for issue 6670.

* OpenMP: Update gcc version when using max_active_level.

* OpenMP: Edit execute_in_serial.

* Apply suggestions from code review

Co-authored-by: Daniel Arndt <arndtd@ornl.gov>

* clang-format

---------

Co-authored-by: Rahulkumar Gayatri <rgayatri@lbl.gov>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Co-authored-by: Daniel Arndt <arndtd@ornl.gov>
  • Loading branch information
4 people committed Dec 22, 2023
1 parent fe06b6f commit cbbe09b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/OpenMP/Kokkos_OpenMP_Instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ namespace Kokkos {
namespace Impl {

inline bool execute_in_serial(OpenMP const& space = OpenMP()) {
return (OpenMP::in_parallel(space) && !(
#if _OPENMP >= 201511
(omp_get_max_active_levels() > 1)
// The default value returned by `omp_get_max_active_levels` with gcc version
// lower than 11.1.0 is 2147483647 instead of 1.
#if (!defined(KOKKOS_COMPILER_GNU) || KOKKOS_COMPILER_GNU >= 1110) && \
_OPENMP >= 201511
bool is_nested = omp_get_max_active_levels() > 1;
#else
omp_get_nested()
bool is_nested = static_cast<bool>(omp_get_nested());
#endif
&& (omp_get_level() == 1)));
return (OpenMP::in_parallel(space) && !(is_nested && (omp_get_level() == 1)));
}

} // namespace Impl
Expand Down

0 comments on commit cbbe09b

Please sign in to comment.