From ea7e9938edbadc13536b3bd791ea1b87015ed330 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 9 Nov 2020 10:58:49 +0100
Subject: [PATCH] Set default values for OMP_PROC_BIND and OMP_PLACES

If these environment variables are not set they are positioned to
recommended values for performance
  OMP_PROC_BIND=spread
  OMP_PLACES=treads
These variables are untouched if set by the user.
---
 src/utils/PugsUtils.cpp | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/utils/PugsUtils.cpp b/src/utils/PugsUtils.cpp
index 43e9cd20f..6186f6fdc 100644
--- a/src/utils/PugsUtils.cpp
+++ b/src/utils/PugsUtils.cpp
@@ -1,15 +1,13 @@
 #include <utils/PugsUtils.hpp>
 
+#include <algebra/PETScWrapper.hpp>
 #include <utils/BuildInfo.hpp>
-#include <utils/RevisionInfo.hpp>
-
-#include <utils/Messenger.hpp>
-
 #include <utils/ConsoleManager.hpp>
 #include <utils/FPEManager.hpp>
+#include <utils/Messenger.hpp>
+#include <utils/RevisionInfo.hpp>
 #include <utils/SignalManager.hpp>
-
-#include <algebra/PETScWrapper.hpp>
+#include <utils/pugs_build_info.hpp>
 
 #include <rang.hpp>
 
@@ -19,10 +17,6 @@
 
 #include <iostream>
 
-// LCOV_EXCL_START
-
-// This function cannot be unit-tested: run once when pugs starts
-
 std::string
 pugsVersion()
 {
@@ -64,6 +58,19 @@ pugsBuildInfo()
   return os.str();
 }
 
+void
+setDefaultOMPEnvironment()
+{
+  if constexpr (std::string_view{PUGS_BUILD_KOKKOS_DEVICES} == std::string_view{"OpenMP"}) {
+    setenv("OMP_PROC_BIND", "spread", 0);
+    setenv("OMP_PLACES", "treads", 0);
+  }
+}
+
+// LCOV_EXCL_START
+
+// This function cannot be unit-tested: run once when pugs starts
+
 std::string
 initialize(int& argc, char* argv[])
 {
@@ -115,11 +122,17 @@ initialize(int& argc, char* argv[])
 
   PETScWrapper::initialize(argc, argv);
 
+  setDefaultOMPEnvironment();
   Kokkos::initialize(argc, argv);
-  std::cout << "-------------------- " << rang::fg::green << "exec info" << rang::fg::reset
-            << " ------------------------" << '\n';
+  std::cout << "----------------- " << rang::fg::green << "pugs exec info" << rang::fg::reset
+            << " ----------------------" << '\n';
 
   std::cout << rang::style::bold;
+#ifdef PUGS_HAS_MPI
+  std::cout << "MPI number of ranks " << parallel::size() << '\n';
+#else    // PUGS_HAS_MPI
+  std::cout << "Sequential build\n";
+#endif   // PUGS_HAS_MPI
   Kokkos::DefaultExecutionSpace::print_configuration(std::cout);
   std::cout << rang::style::reset;
   std::cout << "-------------------------------------------------------\n";
-- 
GitLab