Skip to content

Commit

Permalink
Improve OpenMP affinity warning to include MPI concerns (kokkos#6185)
Browse files Browse the repository at this point in the history
* Detect MPI execution environment

* Do not warn about OMP_PROC_BIND not being set when MPI is used

* Improve warning message and is_mpi_exec -> mpi_detected
  • Loading branch information
dalg24 committed Jun 9, 2023
1 parent e200ba1 commit 6ca60c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/OpenMP/Kokkos_OpenMP_Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,19 @@ void OpenMPInternal::initialize(int thread_count) {
}

{
if (Kokkos::show_warnings() && nullptr == std::getenv("OMP_PROC_BIND")) {
if (Kokkos::show_warnings() && !std::getenv("OMP_PROC_BIND")) {
std::cerr
<< R"WARNING(Kokkos::OpenMP::initialize WARNING: OMP_PROC_BIND environment variable not set
In general, for best performance with OpenMP 4.0 or better set OMP_PROC_BIND=spread and OMP_PLACES=threads
For best performance with OpenMP 3.1 set OMP_PROC_BIND=true
For unit testing set OMP_PROC_BIND=false
)WARNING" << std::endl;

if (mpi_detected()) {
std::cerr
<< R"WARNING(MPI detected: For OpenMP binding to work as intended, MPI ranks must be bound to exclusive CPU sets.
)WARNING" << std::endl;
}
}

OpenMP::memory_space space;
Expand Down
2 changes: 2 additions & 0 deletions core/src/impl/Kokkos_CPUDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ int Kokkos::Impl::mpi_local_rank_on_node() {
}
return -1;
}

bool Kokkos::Impl::mpi_detected() { return mpi_local_rank_on_node() != -1; }
2 changes: 2 additions & 0 deletions core/src/impl/Kokkos_CPUDiscovery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Impl {

int mpi_ranks_per_node();
int mpi_local_rank_on_node();
// returns true if MPI execution environment is detected, false otherwise.
bool mpi_detected();

} // namespace Impl
} // namespace Kokkos

0 comments on commit 6ca60c3

Please sign in to comment.