Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert xbt_cfg_is_default_value -> simgrid::config::is_default.
[simgrid.git] / src / smpi / internals / smpi_global.cpp
index ebf13d8..21f8e09 100644 (file)
@@ -5,26 +5,17 @@
 
 #include "SmpiHost.hpp"
 #include "mc/mc.h"
-#include "private.hpp"
 #include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Host.hpp"
-#include "simgrid/s4u/Mailbox.hpp"
-#include "simgrid/s4u/forward.hpp"
 #include "smpi_coll.hpp"
-#include "smpi_comm.hpp"
-#include "smpi_group.hpp"
-#include "smpi_info.hpp"
 #include "smpi_process.hpp"
 #include "src/msg/msg_private.hpp"
 #include "src/simix/smx_private.hpp"
-#include "src/surf/surf_interface.hpp"
 #include "xbt/config.hpp"
 
 #include <cfloat> /* DBL_MAX */
 #include <dlfcn.h>
 #include <fcntl.h>
 #include <fstream>
-#include <sys/stat.h>
 
 #if HAVE_SENDFILE
 #include <sys/sendfile.h>
@@ -50,8 +41,8 @@ struct papi_process_data {
   papi_counter_t counter_data;
   int event_set;
 };
-
 #endif
+
 using simgrid::s4u::Actor;
 using simgrid::s4u::ActorPtr;
 std::unordered_map<std::string, double> location2speedup;
@@ -96,7 +87,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->getImpl()->userdata);
+  simgrid::msg::ActorExt* msgExt = static_cast<simgrid::msg::ActorExt*>(me->get_impl()->userdata);
   return static_cast<simgrid::smpi::Process*>(msgExt->data);
 }
 
@@ -114,7 +105,7 @@ void smpi_process_init(int *argc, char ***argv){
 }
 
 int smpi_process_index(){
-  return simgrid::s4u::this_actor::getPid();
+  return simgrid::s4u::this_actor::get_pid();
 }
 
 void * smpi_process_get_user_data(){
@@ -223,21 +214,23 @@ void smpi_comm_null_copy_buffer_callback(smx_activity_t comm, void *buff, size_t
   /* nothing done in this version */
 }
 
-static void smpi_check_options(){
+static void smpi_check_options()
+{
   //check correctness of MPI parameters
 
-   xbt_assert(xbt_cfg_get_int("smpi/async-small-thresh") <= xbt_cfg_get_int("smpi/send-is-detached-thresh"));
+  xbt_assert(simgrid::config::get_value<int>("smpi/async-small-thresh") <=
+             simgrid::config::get_value<int>("smpi/send-is-detached-thresh"));
 
-   if (xbt_cfg_is_default_value("smpi/host-speed")) {
-     XBT_INFO("You did not set the power of the host running the simulation.  "
-              "The timings will certainly not be accurate.  "
-              "Use the option \"--cfg=smpi/host-speed:<flops>\" to set its value."
-              "Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.");
-   }
+  if (simgrid::config::is_default("smpi/host-speed")) {
+    XBT_INFO("You did not set the power of the host running the simulation.  "
+             "The timings will certainly not be accurate.  "
+             "Use the option \"--cfg=smpi/host-speed:<flops>\" to set its value."
+             "Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.");
+  }
 
-   xbt_assert(xbt_cfg_get_double("smpi/cpu-threshold") >=0,
-       "The 'smpi/cpu-threshold' option cannot have negative values [anymore]. If you want to discard "
-       "the simulation of any computation, please use 'smpi/simulate-computation:no' instead.");
+  xbt_assert(simgrid::config::get_value<double>("smpi/cpu-threshold") >= 0,
+             "The 'smpi/cpu-threshold' option cannot have negative values [anymore]. If you want to discard "
+             "the simulation of any computation, please use 'smpi/simulate-computation:no' instead.");
 }
 
 int smpi_enabled() {
@@ -251,7 +244,7 @@ void smpi_global_init()
     xbt_os_walltimer_start(global_timer);
   }
 
-  std::string filename = xbt_cfg_get_string("smpi/comp-adjustment-file");
+  std::string filename = simgrid::config::get_value<std::string>("smpi/comp-adjustment-file");
   if (not filename.empty()) {
     std::ifstream fstream(filename);
     if (not fstream.is_open()) {
@@ -278,7 +271,7 @@ void smpi_global_init()
   // and the (computed) event_set.
   std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
 
-  if (not xbt_cfg_get_string("smpi/papi-events").empty()) {
+  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",
@@ -286,7 +279,7 @@ void smpi_global_init()
 
     typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
     boost::char_separator<char> separator_units(";");
-    std::string str = xbt_cfg_get_string("smpi/papi-events");
+    std::string str = simgrid::config::get_value<std::string>("smpi/papi-events");
     Tokenizer tokens(str, separator_units);
 
     // Iterate over all the computational units. This could be processes, hosts, threads, ranks... You name it.
@@ -367,10 +360,10 @@ static void smpi_init_options(){
     return;
   simgrid::smpi::Colls::set_collectives();
   simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
-  smpi_cpu_threshold                               = xbt_cfg_get_double("smpi/cpu-threshold");
-  smpi_host_speed                                  = xbt_cfg_get_double("smpi/host-speed");
+  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);
-  std::string smpi_privatize_option                = xbt_cfg_get_string("smpi/privatization");
+  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;
   else if (smpi_privatize_option == "yes" || smpi_privatize_option == "1")
@@ -396,7 +389,7 @@ static void smpi_init_options(){
     if (smpi_cpu_threshold < 0)
       smpi_cpu_threshold = DBL_MAX;
 
-    std::string val = xbt_cfg_get_string("smpi/shared-malloc");
+    std::string val = simgrid::config::get_value<std::string>("smpi/shared-malloc");
     if ((val == "yes") || (val == "1") || (val == "on") || (val == "global")) {
       smpi_cfg_shared_malloc = shmalloc_global;
     } else if (val == "local") {
@@ -536,7 +529,7 @@ int smpi_main(const char* executable, int argc, char *argv[])
         // Load the copy and resolve the entry point:
         void* handle = dlopen(target_executable.c_str(), RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
         int saved_errno = errno;
-        if (xbt_cfg_get_boolean("smpi/keep-temps") == false)
+        if (simgrid::config::get_value<bool>("smpi/keep-temps") == false)
           unlink(target_executable.c_str());
         if (handle == nullptr)
           xbt_die("dlopen failed: %s (errno: %d -- %s)", dlerror(), saved_errno, strerror(saved_errno));
@@ -549,6 +542,8 @@ int smpi_main(const char* executable, int argc, char *argv[])
     };
   }
   else {
+    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);
     if (handle == nullptr)
@@ -556,7 +551,8 @@ int smpi_main(const char* executable, int argc, char *argv[])
     smpi_entry_point_type entry_point = smpi_resolve_function(handle);
     if (not entry_point)
       xbt_die("main not found in %s", executable);
-    // TODO, register the executable for SMPI privatization
+    if (smpi_privatize_global_variables == SmpiPrivStrategies::Mmap)
+      smpi_backup_global_memory_segment();
 
     // Execute the same entry point for each simulated process:
     simix_global->default_function = [entry_point](std::vector<std::string> args) {
@@ -585,7 +581,7 @@ int smpi_main(const char* executable, int argc, char *argv[])
     SIMIX_run();
 
     xbt_os_walltimer_stop(global_timer);
-    if (xbt_cfg_get_boolean("smpi/display-timing")){
+    if (simgrid::config::get_value<bool>("smpi/display-timing")) {
       double global_time = xbt_os_timer_elapsed(global_timer);
       XBT_INFO("Simulated time: %g seconds. \n\n"
           "The simulation took %g seconds (after parsing and platform setup)\n"
@@ -622,10 +618,7 @@ void SMPI_init(){
   smpi_init_options();
   smpi_global_init();
   smpi_check_options();
-  TRACE_smpi_alloc();
   simgrid::s4u::onSimulationEnd.connect(TRACE_smpi_release);
-  if (smpi_privatize_global_variables == SmpiPrivStrategies::Mmap)
-    smpi_backup_global_memory_segment();
 }
 
 void SMPI_finalize(){