Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / internals / smpi_global.cpp
index a2bdbe1..bb67c34 100644 (file)
 #include <cfloat> /* DBL_MAX */
 #include <dlfcn.h>
 #include <fcntl.h>
+#include <fstream>
+
 #if not defined(__APPLE__)
 #include <link.h>
 #endif
-#include <fstream>
+
+#if defined(__APPLE__)
+# include <AvailabilityMacros.h>
+# ifndef MAC_OS_X_VERSION_10_12
+#   define MAC_OS_X_VERSION_10_12 101200
+# endif
+# define HAVE_WORKING_MMAP (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
+#elif defined(__FreeBSD__)
+# define HAVE_WORKING_MMAP 0
+#else
+# define HAVE_WORKING_MMAP 1
+#endif
 
 #if HAVE_SENDFILE
 #include <sys/sendfile.h>
@@ -38,12 +51,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (ke
 
 #if HAVE_PAPI
 #include "papi.h"
-const char* papi_default_config_name = "default";
-
-struct papi_process_data {
-  papi_counter_t counter_data;
-  int event_set;
-};
+std::string papi_default_config_name = "default";
+std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
 #endif
 
 using simgrid::s4u::Actor;
@@ -91,7 +100,7 @@ simgrid::smpi::Process* smpi_process()
   ActorPtr me = Actor::self();
   if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...)
     return nullptr;
-  simgrid::msg::ActorExt* msgExt = static_cast<simgrid::msg::ActorExt*>(me->get_impl()->getUserData());
+  simgrid::msg::ActorExt* msgExt = static_cast<simgrid::msg::ActorExt*>(me->get_impl()->get_user_data());
   return static_cast<simgrid::smpi::Process*>(msgExt->data);
 }
 
@@ -266,13 +275,11 @@ void smpi_global_init()
   // This map holds for each computation unit (such as "default" or "process1" etc.)
   // the configuration as given by the user (counter data as a pair of (counter_name, counter_counter))
   // and the (computed) event_set.
-  std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
 
   if (not simgrid::config::get_value<std::string>("smpi/papi-events").empty()) {
     if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
       XBT_ERROR("Could not initialize PAPI library; is it correctly installed and linked?"
-                " Expected version is %i",
-                PAPI_VER_CURRENT);
+                " Expected version is %u", PAPI_VER_CURRENT);
 
     typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
     boost::char_separator<char> separator_units(";");
@@ -359,7 +366,7 @@ static void smpi_init_options(){
   simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
   smpi_cpu_threshold                               = simgrid::config::get_value<double>("smpi/cpu-threshold");
   smpi_host_speed                                  = simgrid::config::get_value<double>("smpi/host-speed");
-  xbt_assert(smpi_host_speed >= 0, "You're trying to set the host_speed to a negative value (%f)", smpi_host_speed);
+  xbt_assert(smpi_host_speed > 0.0, "You're trying to set the host_speed to a non-positive value (given: %f)", smpi_host_speed);
   std::string smpi_privatize_option = simgrid::config::get_value<std::string>("smpi/privatization");
   if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
     smpi_privatize_global_variables = SmpiPrivStrategies::NONE;
@@ -376,9 +383,9 @@ static void smpi_init_options(){
     XBT_DEBUG("Running without smpi_main(); disable smpi/privatization.");
     smpi_privatize_global_variables = SmpiPrivStrategies::NONE;
   }
-#if defined(__FreeBSD__)
+#if !HAVE_WORKING_MMAP
   if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) {
-    XBT_INFO("mmap privatization is broken on FreeBSD, switching to dlopen privatization instead.");
+    XBT_INFO("mmap privatization is broken on this platform, switching to dlopen privatization instead.");
     smpi_privatize_global_variables = SmpiPrivStrategies::DLOPEN;
   }
 #endif
@@ -492,13 +499,11 @@ static int visit_libs(struct dl_phdr_info* info, size_t, void* data)
 }
 #endif
 
-static void smpi_init_privatization_dlopen(const char* executable)
+static void smpi_init_privatization_dlopen(std::string executable)
 {
-  std::string executable_copy = executable;
-
   // Prepare the copy of the binary (get its size)
   struct stat fdin_stat;
-  stat(executable_copy.c_str(), &fdin_stat);
+  stat(executable.c_str(), &fdin_stat);
   off_t fdin_size         = fdin_stat.st_size;
   static std::size_t rank = 0;
 
@@ -528,14 +533,14 @@ static void smpi_init_privatization_dlopen(const char* executable)
     }
   }
 
-  simix_global->default_function = [executable_copy, fdin_size](std::vector<std::string> args) {
-    return std::function<void()>([executable_copy, fdin_size, args] {
+  simix_global->default_function = [executable, fdin_size](std::vector<std::string> args) {
+    return std::function<void()>([executable, fdin_size, args] {
 
       // Copy the dynamic library:
       std::string target_executable =
-          executable_copy + "_" + std::to_string(getpid()) + "_" + std::to_string(rank) + ".so";
+          executable + "_" + std::to_string(getpid()) + "_" + std::to_string(rank) + ".so";
 
-      smpi_copy_file(executable_copy, target_executable, fdin_size);
+      smpi_copy_file(executable, target_executable, fdin_size);
       // if smpi/privatize-libs is set, duplicate pointed lib and link each executable copy to a different one.
       std::string target_lib;
       for (auto const& libpath : privatize_libs_paths) {
@@ -587,17 +592,17 @@ static void smpi_init_privatization_dlopen(const char* executable)
   };
 }
 
-static void smpi_init_privatization_no_dlopen(const char* executable)
+static void smpi_init_privatization_no_dlopen(std::string executable)
 {
   if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP)
     smpi_prepare_global_memory_segment();
   // Load the dynamic library and resolve the entry point:
-  void* handle = dlopen(executable, RTLD_LAZY | RTLD_LOCAL);
+  void* handle = dlopen(executable.c_str(), RTLD_LAZY | RTLD_LOCAL);
   if (handle == nullptr)
-    xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable, dlerror(), errno, strerror(errno));
+    xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable.c_str(), dlerror(), errno, strerror(errno));
   smpi_entry_point_type entry_point = smpi_resolve_function(handle);
   if (not entry_point)
-    xbt_die("main not found in %s", executable);
+    xbt_die("main not found in %s", executable.c_str());
   if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP)
     smpi_backup_global_memory_segment();
 
@@ -620,7 +625,7 @@ int smpi_main(const char* executable, int argc, char* argv[])
   TRACE_global_init();
 
   SIMIX_global_init(&argc, argv);
-  MSG_init(&argc, argv);
+  MSG_init(&argc, argv); // FIXME Remove this MSG call. Once it's removed, we can remove the msg header include as well
 
   SMPI_switch_data_segment = &smpi_switch_data_segment;