Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get rid of simix_global and smx_private.hpp
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Fri, 17 Sep 2021 09:17:19 +0000 (11:17 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Fri, 17 Sep 2021 09:17:19 +0000 (11:17 +0200)
32 files changed:
MANIFEST.in
src/include/xbt/parmap.hpp
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/IoImpl.cpp
src/kernel/activity/SleepImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/context/Context.cpp
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextUnix.cpp
src/mc/Session.cpp
src/mc/mc_base.cpp
src/mc/remote/RemotePtr.hpp
src/simix/libsmx.cpp
src/simix/popping.cpp
src/simix/popping_bodies.cpp
src/simix/popping_generated.cpp
src/simix/simcalls.py
src/simix/smx_context.cpp
src/simix/smx_global.cpp
src/simix/smx_private.hpp [deleted file]
src/smpi/internals/smpi_actor.cpp
src/smpi/internals/smpi_config.cpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_utils.cpp
src/smpi/mpi/smpi_status.cpp
src/surf/sg_platf.cpp
tools/cmake/DefinePackages.cmake

index 6fe2661..fe26eda 100644 (file)
@@ -2444,7 +2444,6 @@ include src/simix/simcalls.in
 include src/simix/simcalls.py
 include src/simix/smx_context.cpp
 include src/simix/smx_global.cpp
-include src/simix/smx_private.hpp
 include src/smpi/bindings/smpi_f77.cpp
 include src/smpi/bindings/smpi_f77_coll.cpp
 include src/smpi/bindings/smpi_f77_comm.cpp
index ae03c0c..5b9d583 100644 (file)
@@ -9,8 +9,8 @@
 #define XBT_PARMAP_HPP
 
 #include "src/internal_config.h" // HAVE_FUTEX_H
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/context/Context.hpp"
-#include "src/simix/smx_private.hpp" /* simix_global */
 
 #include <boost/optional.hpp>
 #include <condition_variable>
@@ -286,10 +286,10 @@ template <typename T> typename Parmap<T>::Synchro* Parmap<T>::new_synchro(e_xbt_
 /** @brief Main function of a worker thread */
 template <typename T> void Parmap<T>::worker_main(ThreadData* data)
 {
+  auto engine                       = simgrid::kernel::EngineImpl::get_instance();
   Parmap<T>& parmap     = data->parmap;
   unsigned round        = 0;
-  kernel::context::Context* context =
-      simix_global->get_context_factory()->create_context(std::function<void()>(), nullptr);
+  kernel::context::Context* context = engine->get_context_factory()->create_context(std::function<void()>(), nullptr);
   kernel::context::Context::set_current(context);
 
   XBT_CDEBUG(xbt_parmap, "New worker thread created");
index 4a8ebad..30a790f 100644 (file)
@@ -16,7 +16,6 @@
 #include "src/kernel/resource/profile/Profile.hpp"
 #include "src/mc/mc_record.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/smpi/include/smpi_actor.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
@@ -194,10 +193,6 @@ void EngineImpl::shutdown()
   if (already_cleaned_up)
     return; // to avoid double cleaning by java and C
   already_cleaned_up = true;
-  if (not instance_) {
-    simix_global->destroy_context_factory();
-    return; // Nothing more to shutdown
-  }
   XBT_DEBUG("EngineImpl::shutdown() called. Simulation's over.");
   if (instance_->has_actors_to_run() && simgrid_get_clock() <= 0.0) {
     XBT_CRITICAL("   ");
@@ -226,7 +221,7 @@ void EngineImpl::shutdown()
   instance_->destroy_maestro();
 
   /* Finish context module and SURF */
-  simix_global->destroy_context_factory();
+  instance_->destroy_context_factory();
 
   while (not timer::kernel_timers().empty()) {
     delete timer::kernel_timers().top().second;
@@ -236,7 +231,6 @@ void EngineImpl::shutdown()
   tmgr_finalize();
   sg_platf_exit();
 
-  simix_global = nullptr;
   delete instance_;
   instance_ = nullptr;
 }
@@ -332,7 +326,7 @@ void EngineImpl::wake_all_waiting_actors() const
  */
 void EngineImpl::run_all_actors()
 {
-  simix_global->get_context_factory()->run_all();
+  instance_->get_context_factory()->run_all();
 
   actors_to_run_.swap(actors_that_ran_);
   actors_to_run_.clear();
index 3808724..a7affcf 100644 (file)
@@ -72,6 +72,7 @@ class EngineImpl {
   std::mutex mutex_;
   static EngineImpl* instance_;
   actor::ActorImpl* maestro_ = nullptr;
+  context::ContextFactory* context_factory_ = nullptr;
 
   std::unique_ptr<void, std::function<int(void*)>> platf_handle_; //!< handle for platform library
   friend s4u::Engine;
@@ -101,6 +102,16 @@ public:
     delete maestro_;
     maestro_ = nullptr;
   }
+
+  context::ContextFactory* get_context_factory() const { return context_factory_; }
+  void set_context_factory(context::ContextFactory* factory) { context_factory_ = factory; }
+  bool has_context_factory() const { return context_factory_ != nullptr; }
+  void destroy_context_factory()
+  {
+    delete context_factory_;
+    context_factory_ = nullptr;
+  }
+
   /**
    * @brief Add a model to engine list
    *
index 70e8032..2bf2409 100644 (file)
@@ -6,9 +6,9 @@
 #include "src/kernel/activity/ActivityImpl.hpp"
 #include "simgrid/modelchecker.h"
 #include "src/kernel/activity/SynchroRaw.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
 #include "src/kernel/actor/SimcallObserver.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 #include <boost/range/algorithm.hpp>
 #include <cmath> // isfinite()
 
index 5cd665c..dd4b9bc 100644 (file)
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Io.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
 #include "src/kernel/actor/SimcallObserver.hpp"
+#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/cpu_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
index 6316b12..5a13593 100644 (file)
@@ -7,9 +7,9 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
 #include "src/kernel/context/Context.hpp"
 #include "src/simix/popping_private.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/surf_interface.hpp"
 
index 4a59ebd..d3b4ebf 100644 (file)
@@ -15,7 +15,6 @@
 #include "src/kernel/activity/SynchroRaw.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/mc/remote/AppSide.hpp"
-#include "src/simix/smx_private.hpp"
 #if HAVE_SMPI
 #include "src/smpi/include/private.hpp"
 #endif
@@ -74,7 +73,7 @@ ActorImpl::ActorImpl(xbt::string name, s4u::Host* host) : host_(host), name_(std
 
 ActorImpl::~ActorImpl()
 {
-  if (simix_global != nullptr && not EngineImpl::get_instance()->is_maestro(this))
+  if (not EngineImpl::get_instance()->is_maestro(this))
     s4u::Actor::on_destruction(*get_ciface());
 }
 
@@ -103,8 +102,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h
   actor->code_ = nullptr;
 
   XBT_VERB("Create context %s", actor->get_cname());
-  xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
-  actor->context_.reset(simix_global->get_context_factory()->attach(actor));
+  actor->context_.reset(engine->get_context_factory()->attach(actor));
 
   /* Add the actor to it's host actor list */
   host->get_impl()->add_actor(actor);
@@ -474,7 +472,7 @@ ActorImpl* ActorImpl::start(const ActorCode& code)
 
   this->code_ = code;
   XBT_VERB("Create context %s", get_cname());
-  context_.reset(simix_global->get_context_factory()->create_context(ActorCode(code), this));
+  context_.reset(engine->get_context_factory()->create_context(ActorCode(code), this));
 
   XBT_DEBUG("Start context '%s'", get_cname());
 
@@ -509,13 +507,14 @@ ActorImplPtr ActorImpl::create(const std::string& name, const ActorCode& code, v
 
 void create_maestro(const std::function<void()>& code)
 {
+  auto* engine = EngineImpl::get_instance();
   /* Create maestro actor and initialize it */
   auto* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
 
   if (not code) {
-    maestro->context_.reset(simix_global->get_context_factory()->create_context(ActorCode(), maestro));
+    maestro->context_.reset(engine->get_context_factory()->create_context(ActorCode(), maestro));
   } else {
-    maestro->context_.reset(simix_global->get_context_factory()->create_maestro(ActorCode(code), maestro));
+    maestro->context_.reset(engine->get_context_factory()->create_maestro(ActorCode(code), maestro));
   }
 
   maestro->simcall_.issuer_ = maestro;
index 9109f6b..ae03b1b 100644 (file)
@@ -8,7 +8,6 @@
 #include "simgrid/s4u/Host.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/context/Context.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/surf_interface.hpp"
 
 #include <vector>
index 2b66cb5..fb94d61 100644 (file)
@@ -6,7 +6,6 @@
 #include "ContextBoost.hpp"
 #include "simgrid/Exception.hpp"
 #include "src/internal_config.h"
-#include "src/simix/smx_private.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
index cdae042..9dedc92 100644 (file)
@@ -6,7 +6,6 @@
 #include "ContextRaw.hpp"
 #include "mc/mc.h"
 #include "simgrid/Exception.hpp"
-#include "src/simix/smx_private.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
index 5c9f34b..5716b0c 100644 (file)
@@ -8,7 +8,6 @@
 #include "src/internal_config.h"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/simix/smx_private.hpp"
 #include "xbt/parmap.hpp"
 
 #include "src/kernel/context/ContextSwapped.hpp"
index 4399d82..7cb10dd 100644 (file)
@@ -8,7 +8,6 @@
 #include "simgrid/Exception.hpp"
 #include "src/internal_config.h" /* loads context system definitions */
 #include "src/kernel/EngineImpl.hpp"
-#include "src/simix/smx_private.hpp"
 #include "xbt/function_types.h"
 #include "xbt/xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */
 
index 50722e8..2e0394f 100644 (file)
@@ -9,7 +9,6 @@
 #include "simgrid/Exception.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
 #include "src/mc/mc_ignore.hpp"
-#include "src/simix/smx_private.hpp"
 
 #include "ContextUnix.hpp"
 
index 1bba77a..09d209d 100644 (file)
@@ -16,6 +16,7 @@
 #include "xbt/log.h"
 #include "xbt/system_error.hpp"
 
+#include "signal.h"
 #include <array>
 #include <memory>
 #include <string>
index 2f7aa44..9341466 100644 (file)
@@ -11,7 +11,6 @@
 #include "src/kernel/actor/SimcallObserver.hpp"
 #include "src/mc/mc_config.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 
 #include "xbt/random.hpp"
 
index 4211542..c17823e 100644 (file)
@@ -6,7 +6,7 @@
 #ifndef SIMGRID_MC_REMOTE_PTR_HPP
 #define SIMGRID_MC_REMOTE_PTR_HPP
 
-#include "src/simix/smx_private.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
 
 namespace simgrid {
 namespace mc {
index 5d323db..57b965c 100644 (file)
@@ -238,11 +238,6 @@ bool simcall_comm_test(simgrid::kernel::activity::ActivityImpl* comm)
  */
 smx_mutex_t simcall_mutex_init() // XBT_ATTRIB_DEPRECATED_v330
 {
-  if (simix_global == nullptr) {
-    fprintf(stderr, "You must initialize the SimGrid engine before using it\n"); // We can't use xbt_die since we may
-                                                                                 // get there before the initialization
-    xbt_abort();
-  }
   return simgrid::kernel::actor::simcall([] { return new simgrid::kernel::activity::MutexImpl(); });
 }
 
index f51d40d..e356ea2 100644 (file)
@@ -3,7 +3,8 @@
 /* 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. */
 
-#include "smx_private.hpp"
+#include "src/simix/popping_private.hpp"
+#include "xbt/log.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_popping, simix,
                                 "Popping part of SIMIX (transmuting from user request into kernel handlers)");
index 4b4a084..d24df42 100644 (file)
@@ -14,7 +14,6 @@
  * That's not about http://en.wikipedia.org/wiki/Poop, despite the odor :)
  */
 
-#include "smx_private.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/mc/mc_forward.hpp"
 #include "xbt/ex.h"
index 20efc2d..c536c05 100644 (file)
@@ -14,7 +14,6 @@
  * That's not about http://en.wikipedia.org/wiki/Poop, despite the odor :)
  */
 
-#include "smx_private.hpp"
 #include <simgrid/host.h>
 #include <xbt/base.h>
 #if SIMGRID_HAVE_MC
@@ -22,6 +21,7 @@
 #endif
 #include "src/kernel/activity/ConditionVariableImpl.hpp"
 #include "src/kernel/actor/SimcallObserver.hpp"
+#include "src/kernel/context/Context.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping);
 
index 4d1a9ba..a98b947 100755 (executable)
@@ -307,7 +307,6 @@ if __name__ == '__main__':
 
     fd = header("popping_generated.cpp")
 
-    fd.write('#include "smx_private.hpp"\n')
     fd.write('#include <simgrid/host.h>\n')
     fd.write('#include <xbt/base.h>\n')
     fd.write('#if SIMGRID_HAVE_MC\n')
@@ -315,6 +314,7 @@ if __name__ == '__main__':
     fd.write('#endif\n')
     fd.write('#include "src/kernel/activity/ConditionVariableImpl.hpp"\n')
     fd.write('#include "src/kernel/actor/SimcallObserver.hpp"\n')
+    fd.write('#include "src/kernel/context/Context.hpp"\n')
 
     fd.write('\n')
     fd.write('XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping);\n\n')
@@ -362,7 +362,6 @@ if __name__ == '__main__':
     # popping_bodies.cpp
     #
     fd = header('popping_bodies.cpp')
-    fd.write('#include "smx_private.hpp"\n')
     fd.write('#include "src/mc/mc_forward.hpp"\n')
     fd.write('#include "src/kernel/EngineImpl.hpp"\n')
     fd.write('#include "xbt/ex.h"\n')
index 2d40401..4d9f6ea 100644 (file)
@@ -6,7 +6,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/internal_config.h"
-#include "src/simix/smx_private.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/smpi/include/private.hpp"
 #include "xbt/config.hpp"
 
@@ -58,7 +58,8 @@ static e_xbt_parmap_mode_t smx_parallel_synchronization_mode = XBT_PARMAP_DEFAUL
  */
 void SIMIX_context_mod_init()
 {
-  xbt_assert(not simix_global->has_context_factory());
+  auto* engine = simgrid::kernel::EngineImpl::get_instance();
+  xbt_assert(not engine->has_context_factory());
 
 #if HAVE_SMPI && (defined(__APPLE__) || defined(__NetBSD__))
   smpi_init_options_internal(false);
@@ -79,17 +80,17 @@ void SIMIX_context_mod_init()
 
   /* select the context factory to use to create the contexts */
   if (simgrid::kernel::context::factory_initializer != nullptr) { // Give Java a chance to hijack the factory mechanism
-    simix_global->set_context_factory(simgrid::kernel::context::factory_initializer());
+    engine->set_context_factory(simgrid::kernel::context::factory_initializer());
     return;
   }
   /* use the factory specified by --cfg=contexts/factory:value */
   for (auto const& factory : context_factories)
     if (context_factory_name == factory.first) {
-      simix_global->set_context_factory(factory.second());
+      engine->set_context_factory(factory.second());
       break;
     }
 
-  if (not simix_global->has_context_factory()) {
+  if (not engine->has_context_factory()) {
     XBT_ERROR("Invalid context factory specified. Valid factories on this machine:");
 #if HAVE_RAW_CONTEXTS
     XBT_ERROR("  raw: high performance context factory implemented specifically for SimGrid");
index d049500..25b7577 100644 (file)
@@ -13,7 +13,6 @@
 #include "src/kernel/EngineImpl.hpp"
 #include "src/mc/mc_record.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/xml/platf.hpp"
 
 #include "simgrid/kernel/resource/Model.hpp"
@@ -23,8 +22,6 @@
 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, "Logging specific to SIMIX (kernel)");
 
-std::unique_ptr<simgrid::simix::Global> simix_global;
-
 namespace simgrid {
 namespace simix {
 
@@ -61,10 +58,6 @@ void SIMIX_set_maestro(void (*code)(void*), void* data)
 
 void SIMIX_global_init(int* argc, char** argv)
 {
-  if (simix_global != nullptr)
-    return;
-
-  simix_global = std::make_unique<simgrid::simix::Global>();
 
   SIMIX_context_mod_init();
 
@@ -91,8 +84,6 @@ void SIMIX_run() // XBT_ATTRIB_DEPRECATED_v332
 
 int SIMIX_is_maestro()
 {
-  if (simix_global == nullptr) // SimDag
-    return true;
   const simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self();
   return self == nullptr || simgrid::kernel::EngineImpl::get_instance()->is_maestro(self);
 }
diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp
deleted file mode 100644 (file)
index e948598..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (c) 2007-2021. 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. */
-
-#ifndef SIMIX_PRIVATE_HPP
-#define SIMIX_PRIVATE_HPP
-
-#include "simgrid/s4u/Actor.hpp"
-#include "src/kernel/actor/ActorImpl.hpp"
-#include "src/kernel/context/Context.hpp"
-
-/********************************** Simix Global ******************************/
-
-namespace simgrid {
-namespace simix {
-
-class Global {
-  kernel::context::ContextFactory* context_factory_ = nullptr;
-
-public:
-  kernel::context::ContextFactory* get_context_factory() const { return context_factory_; }
-  void set_context_factory(kernel::context::ContextFactory* factory) { context_factory_ = factory; }
-  bool has_context_factory() const { return context_factory_ != nullptr; }
-  void destroy_context_factory()
-  {
-    delete context_factory_;
-    context_factory_ = nullptr;
-  }
-};
-}
-}
-
-XBT_PUBLIC_DATA std::unique_ptr<simgrid::simix::Global> simix_global;
-
-#endif
index 0758414..9169d0a 100644 (file)
@@ -10,7 +10,6 @@
 #include "smpi_comm.hpp"
 #include "smpi_info.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 
 #if HAVE_PAPI
 #include "papi.h"
index 2c9cd03..a79eaed 100644 (file)
@@ -7,7 +7,6 @@
 #include "mc/mc.h"
 #include "private.hpp"
 #include "smpi_coll.hpp"
-#include "src/simix/smx_private.hpp"
 #include "xbt/parse_units.hpp"
 
 #include <cfloat> /* DBL_MAX */
index 6f6056b..ff31723 100644 (file)
@@ -12,7 +12,6 @@
 #include "smpi_host.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/smpi/include/smpi_actor.hpp"
 #include "xbt/config.hpp"
 #include "xbt/file.hpp"
index bff153d..4b82f5d 100644 (file)
@@ -13,7 +13,6 @@
 #include "xbt/file.hpp"
 #include <boost/tokenizer.hpp>
 #include "smpi_config.hpp"
-#include "src/simix/smx_private.hpp"
 #include <algorithm>
 #include "private.hpp"
 
index f057400..1c43dbc 100644 (file)
@@ -6,7 +6,6 @@
 #include "smpi_status.hpp"
 #include "private.hpp"
 #include "smpi_datatype.hpp"
-#include "src/simix/smx_private.hpp"
 
 namespace simgrid{
 namespace smpi{
index 48b2c01..bbe48f2 100644 (file)
@@ -22,7 +22,6 @@
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf_private.hpp"
 
index 3533acd..ef3d323 100644 (file)
@@ -27,7 +27,6 @@ set(EXTRA_DIST
   src/simix/popping_generated.cpp
   src/simix/popping_enum.hpp
   src/simix/popping_accessors.hpp
-  src/simix/smx_private.hpp
   src/smpi/colls/coll_tuned_topo.hpp
   src/smpi/colls/colls_private.hpp
   src/smpi/colls/smpi_mvapich2_selector_stampede.hpp