Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add libssh2 to exclusions to please manjaro
[simgrid.git] / src / smpi / internals / smpi_global.cpp
index 6013aa6..7cd5672 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -128,17 +128,18 @@ void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, s
   static void (*saved_callback)(smx_activity_t, void*, size_t);
   saved_callback               = callback;
   smpi_comm_copy_data_callback = [](simgrid::kernel::activity::CommImpl* comm, void* buff, size_t size) {
-    saved_callback(smx_activity_t(comm), buff, size);
+    saved_callback(comm, buff, size);
   };
 }
 
-static void memcpy_private(void* dest, const void* src, std::vector<std::pair<size_t, size_t>>& private_blocks)
+static void memcpy_private(void* dest, const void* src, const std::vector<std::pair<size_t, size_t>>& private_blocks)
 {
   for (auto const& block : private_blocks)
     memcpy((uint8_t*)dest+block.first, (uint8_t*)src+block.first, block.second-block.first);
 }
 
-static void check_blocks(std::vector<std::pair<size_t, size_t>> &private_blocks, size_t buff_size) {
+static void check_blocks(const std::vector<std::pair<size_t, size_t>>& private_blocks, size_t buff_size)
+{
   for (auto const& block : private_blocks)
     xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc.");
 }
@@ -252,17 +253,14 @@ static void smpi_init_papi()
       }
 
       // NOTE: We cannot use a map here, as we must obey the order of the counters
-      // This is important for PAPI: We need to map the values of counters back
-      // to the event_names (so, when PAPI_read() has finished)!
+      // This is important for PAPI: We need to map the values of counters back to the event_names (so, when PAPI_read()
+      // has finished)!
       papi_counter_t counters2values;
 
-      // Iterate over all counters that were specified for this specific
-      // unit.
-      // Note that we need to remove the name of the unit
-      // (that could also be the "default" value), which always comes first.
-      // Hence, we start at ++(events.begin())!
+      // Iterate over all counters that were specified for this specific unit.
+      // Note that we need to remove the name of the unit (that could also be the "default" value), which always comes
+      // first. Hence, we start at ++(events.begin())!
       for (Tokenizer::iterator events_it = ++(event_tokens.begin()); events_it != event_tokens.end(); ++events_it) {
-
         int event_code   = PAPI_NULL;
         char* event_name = const_cast<char*>((*events_it).c_str());
         if (PAPI_event_name_to_code(event_name, &event_code) != PAPI_OK) {
@@ -277,7 +275,7 @@ static void smpi_init_papi()
 
         counters2values.push_back(
             // We cannot just pass *events_it, as this is of type const basic_string
-            std::make_pair<std::string, long long>(std::string(*events_it), 0));
+            std::make_pair(std::string(*events_it), 0LL));
       }
 
       std::string unit_name    = *(event_tokens.begin());
@@ -386,7 +384,7 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of
     if (got == -1) {
       xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str());
     } else {
-      char* p  = buf;
+      const char* p = buf;
       int todo = got;
       while (int done = write(fdout, p, todo)) {
         if (done == -1) {
@@ -448,7 +446,7 @@ static void smpi_init_privatization_dlopen(const std::string& executable)
     }
   }
 
-  simix_global->default_function = [executable, fdin_size](std::vector<std::string> args) {
+  simgrid::s4u::Engine::get_instance()->register_default([executable, fdin_size](std::vector<std::string> args) {
     return std::function<void()>([executable, fdin_size, args] {
       static std::size_t rank = 0;
       // Copy the dynamic library:
@@ -503,7 +501,7 @@ static void smpi_init_privatization_dlopen(const std::string& executable)
       xbt_assert(entry_point, "Could not resolve entry point");
       smpi_run_entry_point(entry_point, executable, args);
     });
-  };
+  });
 }
 
 static void smpi_init_privatization_no_dlopen(const std::string& executable)
@@ -522,10 +520,10 @@ static void smpi_init_privatization_no_dlopen(const std::string& executable)
     smpi_backup_global_memory_segment();
 
   // Execute the same entry point for each simulated process:
-  simix_global->default_function = [entry_point, executable](std::vector<std::string> args) {
+  simgrid::s4u::Engine::get_instance()->register_default([entry_point, executable](std::vector<std::string> args) {
     return std::function<void()>(
         [entry_point, executable, args] { smpi_run_entry_point(entry_point, executable, args); });
-  };
+  });
 }
 
 int smpi_main(const char* executable, int argc, char* argv[])
@@ -560,7 +558,7 @@ int smpi_main(const char* executable, int argc, char* argv[])
 
   /* This is a ... heavy way to count the MPI ranks */
   int rank_counts = 0;
-  simgrid::s4u::Actor::on_creation.connect([&rank_counts](simgrid::s4u::Actor& actor) {
+  simgrid::s4u::Actor::on_creation.connect([&rank_counts](const simgrid::s4u::Actor& actor) {
     if (not actor.is_daemon())
       rank_counts++;
   });
@@ -576,7 +574,6 @@ int smpi_main(const char* executable, int argc, char* argv[])
   if (MC_is_active()) {
     MC_run();
   } else {
-
     SIMIX_run();
 
     xbt_os_walltimer_stop(global_timer);
@@ -643,3 +640,7 @@ void smpi_mpi_init() {
   if(smpi_init_sleep > 0)
     simgrid::s4u::this_actor::sleep_for(smpi_init_sleep);
 }
+
+void SMPI_thread_create() {
+  TRACE_smpi_init(simgrid::s4u::this_actor::get_pid());
+}