Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
authormlaurent <mathieu.laurent@ens-rennes.fr>
Wed, 15 Feb 2023 14:05:23 +0000 (15:05 +0100)
committermlaurent <mathieu.laurent@ens-rennes.fr>
Wed, 15 Feb 2023 14:05:23 +0000 (15:05 +0100)
60 files changed:
ChangeLog
MANIFEST.in
docs/source/Installing_SimGrid.rst
examples/cpp/network-ns3/s4u-network-ns3.cpp
examples/cpp/synchro-semaphore/s4u-synchro-semaphore.cpp
include/xbt/log.h
src/include/xbt/xbt_modinter.h
src/instr/instr_config.cpp
src/instr/instr_interface.cpp
src/instr/instr_private.hpp
src/kernel/EngineImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextThread.cpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/EmptyZone.cpp
src/kernel/routing/FatTreeZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetPoint.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/kernel/routing/StarZone.cpp
src/kernel/routing/TorusZone.cpp
src/kernel/routing/VivaldiZone.cpp
src/kernel/routing/WifiZone.cpp
src/plugins/chaos_monkey.cpp
src/plugins/host_load.cpp
src/plugins/link_load.cpp
src/s4u/s4u_Host.cpp
src/simgrid/module.cpp [new file with mode: 0644]
src/simgrid/module.hpp [new file with mode: 0644]
src/simgrid/sg_config.cpp
src/simgrid/sg_version.cpp
src/simix/libsmx.cpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_memory.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/internals/smpi_utils.cpp
src/smpi/mpi/smpi_f2c.cpp
src/surf/host_clm03.cpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_ib.cpp
src/surf/network_ns3.cpp
src/surf/sg_platf.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/xml/surfxml_parseplatf.cpp
src/surf/xml/surfxml_sax_cb.cpp
src/xbt/log.cpp
src/xbt/xbt_main.cpp
teshsuite/xbt/parmap_bench/parmap_bench.cpp
teshsuite/xbt/parmap_test/parmap_test.cpp
tools/cmake/DefinePackages.cmake

index 048fed7..99a7e6a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@ General:
  - Remove the Java bindings: they were limited to the MSG interface.
  - On Windows, you now need to install WSL2 as the native builds are now disabled.
    It was not really working anyway.
+ - Support for 32bits architecture is not tested anymore on our CI infrastructure.
+   It may break in the future, but we think that nobody's using SimGrid on 32 bits.
 
 S4U:
  - Activity::set_remaining() is not public anymore. Use for example
index 44e2d4e..3800775 100644 (file)
@@ -2217,6 +2217,8 @@ include src/s4u/s4u_Netzone.cpp
 include src/s4u/s4u_Semaphore.cpp
 include src/s4u/s4u_VirtualMachine.cpp
 include src/simgrid/Exception.cpp
+include src/simgrid/module.cpp
+include src/simgrid/module.hpp
 include src/simgrid/sg_config.cpp
 include src/simgrid/sg_version.cpp
 include src/simgrid/util.hpp
index 3d55d5a..86d9a60 100644 (file)
@@ -409,30 +409,3 @@ simgrid without downloading the source with pip:
 .. code-block:: console
 
   $ pip install simgrid
-
-Linux Multi-Arch specific instructions
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-On a multiarch x86_64 Linux, it should be possible to compile a 32-bit
-version of SimGrid with something like:
-
-.. code-block:: console
-
-  $ CFLAGS=-m32                                                      \
-    CXXFLAGS=-m32                                                    \
-    FFLAGS=-m32                                                      \
-    PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig/             \
-    cmake .                                                          \
-      -DCMAKE_SYSTEM_PROCESSOR=i386                                  \
-      -DCMAKE_Fortran_COMPILER=/some/path/to/i686-linux-gnu-gfortran \
-      -DGFORTRAN_EXE=/some/path/to/i686-linux-gnu-gfortran           \
-      -DSMPI_C_FLAGS=-m32                                            \
-      -DSMPI_CXX_FLAGS=-m32                                          \
-      -DSMPI_Fortran_FLAGS=-m32
-
-If needed, implement ``i686-linux-gnu-gfortran`` as a script:
-
-.. code-block:: shell
-
-  #!/usr/bin/env sh
-  exec gfortran -m32 "$@"
index a8a7f9d..e1c8b39 100644 (file)
@@ -32,7 +32,7 @@ static void master(MasterWorkerNamesMap& names, const std::vector<std::string>&
   int id          = std::stoi(args[3]); // unique id to control statistics
 
   /* master and worker names */
-  names.emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]});
+  names.try_emplace(id, MasterWorkerNames{sg4::Host::current()->get_name(), args[2]});
 
   sg4::Mailbox* mbox = sg4::Mailbox::by_name(args[3]);
 
index 4040407..b9b5e77 100644 (file)
@@ -14,24 +14,24 @@ namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(sem_test, "Simple test of the semaphore");
 
-static void producer(std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full,
+static void producer(std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full,
                      const std::vector<std::string>& args)
 {
   for (auto const& str : args) {
     sem_empty->acquire();
     XBT_INFO("Pushing '%s'", str.c_str());
-    buffer = str;
+    *buffer = str;
     sem_full->release();
   }
 
   XBT_INFO("Bye!");
 }
-static void consumer(const std::string& buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full)
+static void consumer(const std::string* buffer, sg4::SemaphorePtr sem_empty, sg4::SemaphorePtr sem_full)
 {
   std::string str;
   do {
     sem_full->acquire();
-    str = buffer;
+    str = *buffer;
     XBT_INFO("Receiving '%s'", str.c_str());
     sem_empty->release();
   } while (str != "");
@@ -49,9 +49,8 @@ int main(int argc, char **argv)
   auto sem_empty = sg4::Semaphore::create(1); /* indicates whether the buffer is empty */
   auto sem_full  = sg4::Semaphore::create(0); /* indicates whether the buffer is full */
 
-  sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, std::ref(buffer), sem_empty, sem_full,
-                     std::cref(args));
-  sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, std::cref(buffer), sem_empty, sem_full);
+  sg4::Actor::create("producer", e.host_by_name("Tremblay"), producer, &buffer, sem_empty, sem_full, std::cref(args));
+  sg4::Actor::create("consumer", e.host_by_name("Jupiter"), consumer, &buffer, sem_empty, sem_full);
   e.run();
 
   return 0;
index c2dbd35..49adae5 100644 (file)
@@ -308,8 +308,6 @@ XBT_PUBLIC void _xbt_log_event_log(xbt_log_event_t ev, const char* fmt, ...) XBT
 XBT_PUBLIC int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority);
 
 extern s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT);
-extern xbt_log_appender_t xbt_log_default_appender;
-extern xbt_log_layout_t xbt_log_default_layout;
 
 /* ********************** */
 /* Public functions again */
index 50178d6..5077da5 100644 (file)
@@ -14,7 +14,6 @@ SG_BEGIN_DECL
 
 /* Modules definitions */
 
-void xbt_log_preinit(void);
 void xbt_log_postexit(void);
 
 void xbt_dict_preinit(void);
index 19d9e9e..c13fdff 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used fo
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
 
 std::ofstream tracing_file;
-std::map<const simgrid::instr::Container*, std::ofstream*> tracing_files; // TI specific
+static std::map<const simgrid::instr::Container*, std::ofstream*> tracing_files; // TI specific
 
 constexpr char OPT_TRACING_BASIC[]             = "tracing/basic";
 constexpr char OPT_TRACING_COMMENT_FILE[]      = "tracing/comment-file";
@@ -206,7 +206,7 @@ void TRACE_help()
 namespace simgrid::instr {
 static bool trace_active = false;
 TraceFormat trace_format = TraceFormat::Paje;
-int trace_precision;
+static int trace_precision;
 
 /*************
  * Callbacks *
index 4ff4120..106acd4 100644 (file)
@@ -17,11 +17,11 @@ enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
 
-std::set<std::string, std::less<>> created_categories;
-std::set<std::string, std::less<>> declared_marks;
-std::set<std::string, std::less<>> user_host_variables;
-std::set<std::string, std::less<>> user_vm_variables;
-std::set<std::string, std::less<>> user_link_variables;
+static std::set<std::string, std::less<>> created_categories;
+static std::set<std::string, std::less<>> declared_marks;
+static std::set<std::string, std::less<>> user_host_variables;
+static std::set<std::string, std::less<>> user_vm_variables;
+static std::set<std::string, std::less<>> user_link_variables;
 
 static void instr_user_variable(double time, const std::string& resource, const std::string& variable_name,
                                 const std::string& parent_type, double value, InstrUserVariable what,
index c6b35da..091bbcc 100644 (file)
@@ -40,7 +40,6 @@ void dump_header(bool basic, bool display_sizes);
  */
 enum class TraceFormat { Paje, /*TimeIndependent*/ Ti };
 extern TraceFormat trace_format;
-extern int trace_precision;
 extern double last_timestamp_to_dump;
 
 void init();
@@ -233,12 +232,6 @@ public:
 
 XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc);
 
-extern XBT_PRIVATE std::set<std::string, std::less<>> created_categories;
-extern XBT_PRIVATE std::set<std::string, std::less<>> declared_marks;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_host_variables;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_vm_variables;
-extern XBT_PRIVATE std::set<std::string, std::less<>> user_link_variables;
-
 /* from instr_config.c */
 XBT_PRIVATE bool TRACE_needs_platform();
 XBT_PRIVATE bool TRACE_is_enabled();
index e769b07..c27e814 100644 (file)
@@ -99,7 +99,7 @@ static void segvhandler(int signum, siginfo_t* siginfo, void* /*context*/)
             "If you think you've found a bug in SimGrid, please report it along with a\n"
             "Minimal Working Example (MWE) reproducing your problem and a full backtrace\n"
             "of the fault captured with gdb or valgrind.\n",
-            simgrid::kernel::context::stack_size / 1024);
+            simgrid::kernel::context::Context::stack_size / 1024);
   } else if (siginfo->si_signo == SIGSEGV) {
     fprintf(stderr, "Segmentation fault.\n");
 #if HAVE_SMPI
index 23c3e71..148982f 100644 (file)
@@ -38,7 +38,7 @@ ActorImpl::ActorImpl(const std::string& name, s4u::Host* host, aid_t ppid)
     : ActorIDTrait(name, ppid), host_(host), piface_(this)
 {
   simcall_.issuer_ = this;
-  stacksize_       = context::stack_size;
+  stacksize_       = context::Context::stack_size;
 }
 
 ActorImpl::~ActorImpl()
index 040d783..0229296 100644 (file)
@@ -18,64 +18,21 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_context, kernel, "Context switching mechanis
 
 namespace simgrid::kernel::context {
 
-static e_xbt_parmap_mode_t parallel_synchronization_mode = XBT_PARMAP_DEFAULT;
-static int parallel_contexts                             = 1;
-unsigned stack_size;
-unsigned guard_size;
-
-/** @brief Returns whether some parallel threads are used for the user contexts. */
-bool is_parallel()
-{
-  return parallel_contexts > 1;
-}
-
-/**
- * @brief Returns the number of parallel threads used for the user contexts.
- * @return the number of threads (1 means no parallelism)
- */
-int get_nthreads()
-{
-  return parallel_contexts;
-}
-
-/**
- * @brief Sets the number of parallel threads to use  for the user contexts.
- *
- * This function should be called before initializing SIMIX.
- * A value of 1 means no parallelism (1 thread only).
- * If the value is greater than 1, the thread support must be enabled.
- *
- * @param nb_threads the number of threads to use
- */
-void set_nthreads(int nb_threads)
+void Context::set_nthreads(int nb_threads)
 {
   if (nb_threads <= 0) {
     nb_threads = std::thread::hardware_concurrency();
     XBT_INFO("Auto-setting contexts/nthreads to %d", nb_threads);
   }
-  parallel_contexts = nb_threads;
-}
-
-/**
- * @brief Sets the synchronization mode to use when actors are run in parallel.
- * @param mode how to synchronize threads if actors are run in parallel
- */
-void set_parallel_mode(e_xbt_parmap_mode_t mode)
-{
-  parallel_synchronization_mode = mode;
-}
-
-/**
- * @brief Returns the synchronization mode used when actors are run in parallel.
- * @return how threads are synchronized if actors are run in parallel
- */
-e_xbt_parmap_mode_t get_parallel_mode()
-{
-  return parallel_synchronization_mode;
+  Context::parallel_contexts = nb_threads;
 }
 
 ContextFactory::~ContextFactory() = default;
 
+e_xbt_parmap_mode_t Context::parallel_mode = XBT_PARMAP_DEFAULT;
+int Context::parallel_contexts             = 1;
+unsigned Context::stack_size;
+unsigned Context::guard_size;
 thread_local Context* Context::current_context_ = nullptr;
 
 /* Install or disable alternate signal stack, for SIGSEGV handler. */
index 25d8113..1961399 100644 (file)
@@ -15,8 +15,6 @@
 #include <functional>
 
 namespace simgrid::kernel::context {
-extern unsigned stack_size;
-extern unsigned guard_size;
 
 class XBT_PUBLIC ContextFactory {
 public:
@@ -45,6 +43,7 @@ protected:
 class XBT_PUBLIC Context {
   friend ContextFactory;
 
+  static int parallel_contexts;
   static thread_local Context* current_context_;
 
   std::function<void()> code_;
@@ -53,6 +52,10 @@ class XBT_PUBLIC Context {
   void declare_context(std::size_t size);
 
 public:
+  static e_xbt_parmap_mode_t parallel_mode;
+  static unsigned stack_size;
+  static unsigned guard_size;
+
   static int install_sigsegv_stack(bool enable);
 
   Context(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro);
@@ -65,6 +68,22 @@ public:
   bool has_code() const { return static_cast<bool>(code_); }
   actor::ActorImpl* get_actor() const { return this->actor_; }
 
+  /** @brief Returns whether some parallel threads are used for the user contexts. */
+  static bool is_parallel() { return parallel_contexts > 1; }
+  /** @brief Returns the number of parallel threads used for the user contexts (1 means no parallelism). */
+  static int get_nthreads() { return parallel_contexts; }
+  /**
+   * @brief Sets the number of parallel threads to use  for the user contexts.
+   *
+   * This function should be called before initializing SIMIX.
+   * A value of 1 means no parallelism (1 thread only).
+   * If the value is greater than 1, the thread support must be enabled.
+   * If the value is less than 1, the optimal number of threads is chosen automatically.
+   *
+   * @param nb_threads the number of threads to use
+   */
+  static void set_nthreads(int nb_threads);
+
   // Scheduling methods
   virtual void stop();
   virtual void suspend() = 0;
@@ -98,11 +117,6 @@ XBT_PRIVATE ContextFactory* sysv_factory();
 XBT_PRIVATE ContextFactory* raw_factory();
 XBT_PRIVATE ContextFactory* boost_factory();
 
-XBT_PUBLIC bool is_parallel();
-XBT_PUBLIC int get_nthreads();
-XBT_PUBLIC void set_nthreads(int nb_threads);
-XBT_PUBLIC void set_parallel_mode(e_xbt_parmap_mode_t mode);
-XBT_PUBLIC e_xbt_parmap_mode_t get_parallel_mode();
 } // namespace simgrid::kernel::context
 
 #endif
index 350b686..a197791 100644 (file)
@@ -191,10 +191,11 @@ void SwappedContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors
    * stuff It is much easier to understand what happens if you see the working threads as bodies that swap their soul
    * for the ones of the simulated processes that must run.
    */
-  if (is_parallel()) {
+  if (Context::is_parallel()) {
     // We lazily create the parmap so that all options are actually processed when doing so.
     if (parmap_ == nullptr)
-      parmap_ = std::make_unique<simgrid::xbt::Parmap<actor::ActorImpl*>>(get_nthreads(), get_parallel_mode());
+      parmap_ =
+          std::make_unique<simgrid::xbt::Parmap<actor::ActorImpl*>>(Context::get_nthreads(), Context::parallel_mode);
 
     // Usually, Parmap::apply() executes the provided function on all elements of the array.
     // Here, the executed function does not return the control to the parmap before all the array is processed:
index c6901c9..9106a3c 100644 (file)
@@ -24,21 +24,21 @@ namespace simgrid::kernel::context {
 
 ThreadContextFactory::ThreadContextFactory() : ContextFactory()
 {
-  if (stack_size != 8 * 1024 * 1024)
+  if (Context::stack_size != 8 * 1024 * 1024)
     XBT_INFO("Stack size modifications are ignored by thread factory.");
-  if (is_parallel())
+  if (Context::is_parallel())
     ParallelThreadContext::initialize();
 }
 
 ThreadContextFactory::~ThreadContextFactory()
 {
-  if (is_parallel())
+  if (Context::is_parallel())
     ParallelThreadContext::finalize();
 }
 
 ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro)
 {
-  if (is_parallel())
+  if (Context::is_parallel())
     return this->new_context<ParallelThreadContext>(std::move(code), actor, maestro);
   else
     return this->new_context<SerialThreadContext>(std::move(code), actor, maestro);
@@ -46,7 +46,7 @@ ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code
 
 void ThreadContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  if (is_parallel())
+  if (Context::is_parallel())
     ParallelThreadContext::run_all(actors_list);
 
   else
index bb269eb..72f6dca 100644 (file)
@@ -7,7 +7,7 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "src/kernel/resource/StandardLinkImpl.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_cluster, ker_routing, "Kernel Cluster Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_cluster, ker_platform, "Kernel Cluster Routing");
 
 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
  * Note that a router is created, easing the interconnection with the rest of the world. */
index 06a7d19..2169610 100644 (file)
@@ -13,7 +13,7 @@
 #include <queue>
 #include <vector>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dijkstra, ker_routing, "Kernel Dijkstra Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dijkstra, ker_platform, "Kernel Dijkstra Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index e8e4b9a..7afec19 100644 (file)
@@ -12,7 +12,7 @@
 #include <numeric>
 #include <string>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dragonfly, ker_routing, "Kernel Dragonfly Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_dragonfly, ker_platform, "Kernel Dragonfly Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index 26fc80c..fc89682 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "simgrid/kernel/routing/EmptyZone.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_none, ker_routing, "Kernel No Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_none, ker_platform, "Kernel No Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index d537bb6..0c33475 100644 (file)
@@ -17,7 +17,7 @@
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_fat_tree, ker_routing, "Kernel Fat-Tree Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_fat_tree, ker_platform, "Kernel Fat-Tree Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index 85ae467..350ce04 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <climits>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_floyd, ker_routing, "Kernel Floyd Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_floyd, ker_platform, "Kernel Floyd Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index 4e862cc..1ae50c5 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "src/kernel/resource/NetworkModel.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_routing, "Kernel Full Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_full, ker_platform, "Kernel Full Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index d3d72aa..ee3d0da 100644 (file)
@@ -9,7 +9,7 @@
 #include "simgrid/s4u/Host.hpp"
 #include "xbt/log.h"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_netpoint, ker_routing, "Kernel implementation of netpoints");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_netpoint, ker_platform, "Kernel implementation of netpoints");
 
 namespace simgrid {
 
index f8db982..fa210c3 100644 (file)
@@ -20,7 +20,7 @@
 #include "src/kernel/resource/VirtualMachineImpl.hpp"
 #include "src/surf/HostImpl.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing, kernel, "Kernel routing-related information");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_platform, kernel, "Kernel platform-related information");
 
 namespace simgrid::kernel::routing {
 
@@ -45,24 +45,16 @@ static void surf_config_models_setup()
     xbt_enforce(not disk_model_name.empty(), "Set a disk model to use with the 'compound' host model");
     xbt_enforce(not network_model_name.empty(), "Set a network model to use with the 'compound' host model");
 
-    const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name);
-    cpu_model->model_init_preparse();
-
-    const auto* disk_model = find_model_description(surf_disk_model_description, disk_model_name);
-    disk_model->model_init_preparse();
-
-    const auto* network_model = find_model_description(surf_network_model_description, network_model_name);
-    network_model->model_init_preparse();
+    surf_cpu_model_description.by_name(cpu_model_name).init();
+    surf_disk_model_description.by_name(disk_model_name).init();
+    simgrid_network_models().by_name(network_model_name).init();
   }
 
-  XBT_DEBUG("Call host_model_init");
-  const auto* host_model = find_model_description(surf_host_model_description, host_model_name);
-  host_model->model_init_preparse();
+  surf_host_model_description.by_name(host_model_name).init();
 
   XBT_DEBUG("Call vm_model_init");
-  /* ideally we should get back the pointer to CpuModel from model_init_preparse(), but this
-   * requires changing the declaration of surf_cpu_model_description.
-   * To be reviewed in the future */
+  /* TODO: ideally we should get back the pointer to CpuModel from init(), but this
+   * requires changing the declaration of surf_cpu_model_description. */
   surf_vm_model_init_HL13(
       simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->get_cpu_pm_model().get());
 }
index d5790d7..8457254 100644 (file)
@@ -12,7 +12,7 @@
 #include "xbt/sysdep.h"
 #include "xbt/asserts.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_routing, "Kernel Generic Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_platform, "Kernel Generic Routing");
 
 /* ***************************************************************** */
 /* *********************** GENERIC METHODS ************************* */
index ada9bb6..3ccb888 100644 (file)
@@ -8,7 +8,7 @@
 #include "src/kernel/resource/NetworkModel.hpp"
 #include "xbt/string.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_star, ker_routing, "Kernel Star Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_star, ker_platform, "Kernel Star Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index 4f3652f..11fd3b4 100644 (file)
@@ -14,7 +14,7 @@
 #include <string>
 #include <vector>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_torus, ker_routing, "Kernel Torus Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_torus, ker_platform, "Kernel Torus Routing");
 
 namespace simgrid {
 namespace kernel ::routing {
index e9c2ccb..e7429d8 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <boost/algorithm/string.hpp>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_vivaldi, ker_routing, "Kernel Vivaldi Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_vivaldi, ker_platform, "Kernel Vivaldi Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index d6cb94f..b6d4083 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "src/kernel/resource/NetworkModel.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_wifi, ker_routing, "Kernel Wifi Routing");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_wifi, ker_platform, "Kernel Wifi Routing");
 
 namespace simgrid {
 namespace kernel::routing {
index 0e0938f..45f4df6 100644 (file)
@@ -10,7 +10,7 @@
 #include <simgrid/s4u/Host.hpp>
 #include <xbt/config.hpp>
 
-#include "src/surf/surf_interface.hpp" // SIMGRID_REGISTER_PLUGIN
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
 
 namespace sg4 = simgrid::s4u;
 static simgrid::config::Flag<bool> cfg_tell{"cmonkey/tell", "Request the Chaos Monkey to display all timestamps",
index 6c926ad..2ea7c47 100644 (file)
@@ -10,7 +10,7 @@
 #include <simgrid/s4u/VirtualMachine.hpp>
 
 #include "src/kernel/activity/ExecImpl.hpp"
-#include "src/surf/surf_interface.hpp"
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
 
 // Makes sure that this plugin can be activated from the command line with ``--cfg=plugin:host_load``
 SIMGRID_REGISTER_PLUGIN(host_load, "Cpu load", &sg_host_load_plugin_init)
@@ -32,7 +32,7 @@ It attaches an extension to each host to store some data, and places callbacks i
   @endrst
 */
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, kernel, "Logging specific to the HostLoad plugin");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, plugin, "Logging specific to the HostLoad plugin");
 
 namespace simgrid::plugin {
 
index 025c83f..1afdd6e 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/resource/NetworkModel.hpp"
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
 
 #include <limits>
 
index b762e63..bfd02d9 100644 (file)
@@ -21,7 +21,7 @@
 #include <string>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_host, s4u, "Logging specific to the S4U hosts");
-XBT_LOG_EXTERNAL_CATEGORY(ker_routing);
+XBT_LOG_EXTERNAL_CATEGORY(ker_platform);
 
 namespace simgrid {
 
@@ -169,11 +169,11 @@ void Host::route_to(const Host* dest, std::vector<Link*>& links, double* latency
 void Host::route_to(const Host* dest, std::vector<kernel::resource::StandardLinkImpl*>& links, double* latency) const
 {
   kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint_, dest->get_netpoint(), links, latency);
-  if (XBT_LOG_ISENABLED(ker_routing, xbt_log_priority_debug)) {
-    XBT_CDEBUG(ker_routing, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(),
+  if (XBT_LOG_ISENABLED(ker_platform, xbt_log_priority_debug)) {
+    XBT_CDEBUG(ker_platform, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(),
                (latency == nullptr ? -1 : *latency));
     for (auto const* link : links)
-      XBT_CDEBUG(ker_routing, "  Link '%s'", link->get_cname());
+      XBT_CDEBUG(ker_platform, "  Link '%s'", link->get_cname());
   }
 }
 
diff --git a/src/simgrid/module.cpp b/src/simgrid/module.cpp
new file mode 100644 (file)
index 0000000..f4ee704
--- /dev/null
@@ -0,0 +1,78 @@
+/* Copyright (c) 2004-2023. 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. */
+
+#include <xbt/asserts.h>
+#include <xbt/log.h>
+
+#include "src/simgrid/module.hpp"
+#include "src/surf/surf_interface.hpp"
+
+#include <sstream>
+
+XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins");
+XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
+
+using namespace simgrid;
+
+ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
+{
+  table_.emplace_back(Module(id, desc, init));
+  return *this;
+}
+
+Module const& ModuleGroup::by_name(const std::string& name) const
+{
+  if (auto pos = std::find_if(table_.begin(), table_.end(), [&name](const Module& item) { return item.name_ == name; });
+      pos != table_.end())
+    return *pos;
+
+  xbt_die("Unable to find %s '%s'. Valid values are: %s.", kind_.c_str(), name.c_str(), existing_values().c_str());
+}
+/** Displays the long description of all registered models, and quit */
+void ModuleGroup::help() const
+{
+  XBT_HELP("Long description of the %s accepted by this simulator:", kind_.c_str());
+  for (auto const& item : table_)
+    XBT_HELP("  %s: %s", item.name_, item.description_);
+}
+std::string ModuleGroup::existing_values() const
+{
+  std::stringstream ss;
+  std::string sep;
+  for (auto const& item : table_) {
+    ss << sep + item.name_;
+    sep = ", ";
+  }
+  return ss.str();
+}
+
+/* -------------------------------------------------------------------------------------------------------------- */
+simgrid::ModuleGroup surf_optimization_mode_description("optimization mode");
+simgrid::ModuleGroup surf_cpu_model_description("CPU model");
+simgrid::ModuleGroup surf_disk_model_description("disk model");
+simgrid::ModuleGroup surf_host_model_description("host model");
+
+void simgrid_create_models()
+{
+  surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01);
+  surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19);
+
+  surf_host_model_description
+      .add("default",
+           "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
+           &surf_host_model_init_current_default)
+      .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
+           &surf_host_model_init_compound)
+      .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
+           &surf_host_model_init_ptask_L07);
+
+  surf_optimization_mode_description
+      .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
+      .add("TI",
+           "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
+           "model for now).",
+           nullptr)
+      .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);
+}
diff --git a/src/simgrid/module.hpp b/src/simgrid/module.hpp
new file mode 100644 (file)
index 0000000..2e83c16
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (c) 2004-2023. 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 SIMGRID_MODULE_HPP
+#define SIMGRID_MODULE_HPP
+
+#include <xbt/base.h>
+
+#include <functional>
+#include <string>
+#include <vector>
+
+namespace simgrid {
+
+struct Module {
+  const char* name_;
+  const char* description_;
+  std::function<void()> init;
+  Module(const char* id, const char* desc, std::function<void()> init_fun)
+      : name_(id), description_(desc), init(init_fun)
+  {
+  }
+};
+
+class ModuleGroup {
+  std::vector<Module> table_;
+  const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only
+public:
+  ModuleGroup(std::string kind) : kind_(kind) {}
+
+  ModuleGroup& add(const char* id, const char* desc, std::function<void()> init);
+  Module const& by_name(const std::string& name) const;
+  void help() const;
+  const std::string get_kind() const { return kind_; }
+  std::string existing_values() const;
+};
+
+}; // namespace simgrid
+
+#define SIMGRID_REGISTER_PLUGIN(id, desc, init)                                                                        \
+  static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)()                               \
+  {                                                                                                                    \
+    simgrid_plugins().add(_XBT_STRINGIFY(id), (desc), (init));                                                         \
+  }
+
+/** @brief The list of all available plugins */
+inline auto& simgrid_plugins() // Function to avoid static initialization order fiasco
+{
+  static simgrid::ModuleGroup plugins("plugin");
+  return plugins;
+}
+
+#define SIMGRID_REGISTER_NETWORK_MODEL(id, desc, init)                                                                 \
+  static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _network_model_register)()                        \
+  {                                                                                                                    \
+    simgrid_network_models().add(_XBT_STRINGIFY(id), (desc), (init));                                                  \
+  }
+/** @brief The list of all available network model (pick one with --cfg=network/model) */
+inline auto& simgrid_network_models() // Function to avoid static initialization order fiasco
+{
+  static simgrid::ModuleGroup plugins("network model");
+  return plugins;
+}
+
+#endif
\ No newline at end of file
index 1e25468..fa7446e 100644 (file)
 #include "src/kernel/resource/NetworkModel.hpp"
 #include "src/mc/mc_config.hpp"
 #include "src/mc/mc_replay.hpp"
+#include "src/simgrid/module.hpp"
 #include "src/smpi/include/smpi_config.hpp"
 #include "src/surf/surf_interface.hpp"
 
 #include <string_view>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(config, kernel, "About the configuration of SimGrid");
 
 static simgrid::config::Flag<bool> cfg_continue_after_help
   {"help-nostop", "Do not stop the execution when --help is found", false};
@@ -94,14 +95,13 @@ static void sg_config_cmd_line(int *argc, char **argv)
       XBT_HELP("Please consider using the recent names");
       shall_exit = true;
     } else if (parse_args && not strcmp(argv[i], "--help-models")) {
-      model_help("host", surf_host_model_description);
+      surf_host_model_description.help();
       XBT_HELP("%s", "");
-      model_help("CPU", surf_cpu_model_description);
+      surf_cpu_model_description.help();
       XBT_HELP("%s", "");
-      model_help("network", surf_network_model_description);
+      simgrid_network_models().help();
       XBT_HELP("\nLong description of all optimization levels accepted by the models of this simulator:");
-      for (auto const& item : surf_optimization_mode_description)
-        XBT_HELP("  %s: %s", item.name, item.description);
+      surf_optimization_mode_description.help();
       XBT_HELP("Both network and CPU models have 'Lazy' as default optimization level\n");
       shall_exit = true;
     } else if (parse_args && not strcmp(argv[i], "--help-tracing")) {
@@ -128,12 +128,11 @@ static void _sg_cfg_cb__plugin(const std::string& value)
     return;
 
   if (value == "help") {
-    model_help("plugin", surf_plugin_description());
+    simgrid_plugins().help();
     exit(0);
   }
 
-  const auto* plugin = find_model_description(surf_plugin_description(), value);
-  plugin->model_init_preparse();
+  simgrid_plugins().by_name(value).init();
 }
 
 /* callback of the host/model variable */
@@ -142,12 +141,12 @@ static void _sg_cfg_cb__host_model(const std::string& value)
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
   if (value == "help") {
-    model_help("host", surf_host_model_description);
+    surf_host_model_description.help();
     exit(0);
   }
 
   /* Make sure that the model exists */
-  find_model_description(surf_host_model_description, value);
+  surf_host_model_description.by_name(value);
 }
 
 /* callback of the cpu/model variable */
@@ -156,12 +155,12 @@ static void _sg_cfg_cb__cpu_model(const std::string& value)
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
   if (value == "help") {
-    model_help("CPU", surf_cpu_model_description);
+    surf_cpu_model_description.help();
     exit(0);
   }
 
-  /* New Module missing */
-  find_model_description(surf_cpu_model_description, value);
+  /* Make sure that the model exists */
+  surf_cpu_model_description.by_name(value);
 }
 
 /* callback of the cpu/model variable */
@@ -170,12 +169,12 @@ static void _sg_cfg_cb__optimization_mode(const std::string& value)
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
   if (value == "help") {
-    model_help("optimization", surf_optimization_mode_description);
+    surf_optimization_mode_description.help();
     exit(0);
   }
 
-  /* New Module missing */
-  find_model_description(surf_optimization_mode_description, value);
+  /* Make sure that the model exists */
+  surf_optimization_mode_description.by_name(value);
 }
 
 static void _sg_cfg_cb__disk_model(const std::string& value)
@@ -183,11 +182,11 @@ static void _sg_cfg_cb__disk_model(const std::string& value)
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
   if (value == "help") {
-    model_help("disk", surf_disk_model_description);
+    surf_disk_model_description.help();
     exit(0);
   }
 
-  find_model_description(surf_disk_model_description, value);
+  surf_disk_model_description.by_name(value);
 }
 
 /* callback of the network_model variable */
@@ -196,22 +195,21 @@ static void _sg_cfg_cb__network_model(const std::string& value)
   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
 
   if (value == "help") {
-    model_help("network", surf_network_model_description);
+    simgrid_network_models().help();
     exit(0);
   }
 
-  /* New Module missing */
-  find_model_description(surf_network_model_description, value);
+  simgrid_network_models().by_name(value); // Simply ensure that it exists
 }
 
 static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name)
 {
   if (mode_name == "posix") {
-    simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_POSIX);
+    simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_POSIX;
   } else if (mode_name == "futex") {
-    simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_FUTEX);
+    simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_FUTEX;
   } else if (mode_name == "busy_wait") {
-    simgrid::kernel::context::set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
+    simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_BUSY_WAIT;
   } else {
     xbt_die("Command line setting of the parallel synchronization mode should "
             "be one of \"posix\", \"futex\" or \"busy_wait\"");
@@ -221,15 +219,11 @@ static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name)
 /* build description line with possible values */
 static void declare_model_flag(const std::string& name, const std::string& value,
                                const std::function<void(std::string const&)>& callback,
-                               const std::vector<surf_model_description_t>& model_description, const std::string& type,
+                               const simgrid::ModuleGroup& model_description, const std::string& type,
                                const std::string& descr)
 {
-  std::string description = descr + ". Possible values: ";
-  std::string sep         = "";
-  for (auto const& item : model_description) {
-    description += sep + item.name;
-    sep = ", ";
-  }
+  std::string description = descr + ". Possible values (other compilation flags may activate more " +
+                            model_description.get_kind() + "): " + model_description.existing_values();
   description += ".\n       (use 'help' as a value to see the long description of each " + type + ")";
   simgrid::config::declare_flag<std::string>(name, description, value, callback);
 }
@@ -242,9 +236,9 @@ void sg_config_init(int *argc, char **argv)
     XBT_WARN("Call to sg_config_init() after initialization ignored");
     return;
   }
-
+  simgrid_create_models();
   /* Plugins configuration */
-  declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, surf_plugin_description(), "plugin", "The plugins");
+  declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, simgrid_plugins(), "plugin", "The plugins");
 
   declare_model_flag("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, surf_cpu_model_description, "model",
                      "The model to use for the CPU");
@@ -252,7 +246,7 @@ void sg_config_init(int *argc, char **argv)
   declare_model_flag("disk/model", "S19", &_sg_cfg_cb__disk_model, surf_disk_model_description, "model",
                      "The model to use for the disk");
 
-  declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, surf_network_model_description, "model",
+  declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, simgrid_network_models(), "model",
                      "The model to use for the network");
 
   declare_model_flag("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, surf_optimization_mode_description,
@@ -304,7 +298,7 @@ void sg_config_init(int *argc, char **argv)
 
   static simgrid::config::Flag<int> cfg_context_stack_size{
       "contexts/stack-size", "Stack size of contexts in KiB (not with threads)", 8 * 1024,
-      [](int value) { simgrid::kernel::context::stack_size = value * 1024; }};
+      [](int value) { simgrid::kernel::context::Context::stack_size = value * 1024; }};
 
   /* guard size for contexts stacks in memory pages */
 #if (PTH_STACKGROWTH != -1)
@@ -314,7 +308,7 @@ void sg_config_init(int *argc, char **argv)
 #endif
   static simgrid::config::Flag<int> cfg_context_guard_size{
       "contexts/guard-size", "Guard size for contexts stacks in memory pages", default_guard_size,
-      [](int value) { simgrid::kernel::context::guard_size = value * xbt_pagesize; }};
+      [](int value) { simgrid::kernel::context::Context::guard_size = value * xbt_pagesize; }};
 
   static simgrid::config::Flag<int> cfg_context_nthreads{
       "contexts/nthreads", "Number of parallel threads used to execute user contexts", 1, [](int nthreads) {
@@ -324,7 +318,7 @@ void sg_config_init(int *argc, char **argv)
             "Parallel simulation is forbidden in the verified program, as there is no protection against race "
             "conditions in mmalloc itself. Please don't be so greedy and show some mercy for our implementation.");
 #endif
-        simgrid::kernel::context::set_nthreads(nthreads);
+        simgrid::kernel::context::Context::set_nthreads(nthreads);
       }};
 
   /* synchronization mode for parallel user contexts */
@@ -354,7 +348,7 @@ void sg_config_init(int *argc, char **argv)
 
   sg_config_cmd_line(argc, argv);
 
-  xbt_mallocator_initialization_is_done(simgrid::kernel::context::is_parallel());
+  xbt_mallocator_initialization_is_done(simgrid::kernel::context::Context::is_parallel());
 }
 
 void sg_config_finalize()
index 5435290..3452c3b 100644 (file)
@@ -9,8 +9,6 @@
 #include "xbt/misc.h"
 #include "xbt/sysdep.h"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_version, surf, "About the versioning of SimGrid");
-
 void sg_version_check(int lib_version_major, int lib_version_minor, int lib_version_patch)
 {
   if ((lib_version_major != SIMGRID_VERSION_MAJOR) || (lib_version_minor != SIMGRID_VERSION_MINOR)) {
index 8840045..febed11 100644 (file)
@@ -175,7 +175,7 @@ void simcall_run_object_access(std::function<void()> const& code, simgrid::kerne
   // We only need a simcall if the order of the setters is important (parallel run or MC execution).
   // Otherwise, just call the function with no simcall
 
-  if (simgrid::kernel::context::is_parallel()
+  if (simgrid::kernel::context::Context::is_parallel()
 #if SIMGRID_HAVE_MC
       || MC_is_active() || MC_record_replay_is_active()
 #endif
index 7174872..2133849 100644 (file)
@@ -54,14 +54,12 @@ constexpr int SMPI_RMA_TAG            = -6666;
 #define MPI_REQUEST_IGNORED ((MPI_Request*)-100)
 
 /* Bindings for MPI special values */
-extern XBT_PUBLIC int mpi_in_place_;
-extern XBT_PUBLIC int mpi_bottom_;
-extern XBT_PUBLIC int mpi_status_ignore_;
-extern XBT_PUBLIC int mpi_statuses_ignore_;
+extern XBT_PUBLIC const int mpi_in_place_;
+extern XBT_PUBLIC const int mpi_bottom_;
+extern XBT_PUBLIC const int mpi_status_ignore_;
+extern XBT_PUBLIC const int mpi_statuses_ignore_;
 /* Convert between Fortran and C */
-#define FORT_ADDR(addr, val, val2)                                         \
-  (((void *)(addr) == (void*) &(val2))                  \
-   ? (val) : (void *)(addr))
+#define FORT_ADDR(addr, val, val2) (((const void*)(addr) == (const void*)&(val2)) ? (val) : (void*)(addr))
 #define FORT_BOTTOM(addr) FORT_ADDR((addr), MPI_BOTTOM, mpi_bottom_)
 #define FORT_IN_PLACE(addr) FORT_ADDR((addr), MPI_IN_PLACE, mpi_in_place_)
 #define FORT_STATUS_IGNORE(addr) static_cast<MPI_Status*>(FORT_ADDR((addr), MPI_STATUS_IGNORE, mpi_status_ignore_))
@@ -120,9 +118,6 @@ XBT_PRIVATE bool smpi_cfg_display_alloc();
 // utilities
 XBT_PRIVATE void smpi_init_options_internal(bool called_by_smpi_main);
 
-extern XBT_PRIVATE char* smpi_data_exe_start; // start of the data+bss segment of the executable
-extern XBT_PRIVATE size_t smpi_data_exe_size; // size of the data+bss segment of the executable
-
 XBT_PRIVATE bool smpi_switch_data_segment(simgrid::s4u::ActorPtr actor, const void* addr = nullptr);
 
 XBT_PRIVATE void smpi_prepare_global_memory_segment();
index 13e44ca..fce781e 100644 (file)
@@ -72,7 +72,7 @@ std::map</* computation unit name */ std::string, papi_process_data, std::less<>
 std::unordered_map<std::string, double> location2speedup;
 
 static int smpi_exit_status = 0;
-xbt_os_timer_t global_timer;
+static xbt_os_timer_t global_timer;
 static std::vector<std::string> privatize_libs_paths;
 
 // No instance gets manually created; check also the smpirun.in script as
index b9b81f6..d2d121e 100644 (file)
@@ -26,9 +26,9 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI");
 
-char* smpi_data_exe_start = nullptr;
-size_t smpi_data_exe_size = 0;
-SmpiPrivStrategies smpi_privatize_global_variables;
+static char* smpi_data_exe_start = nullptr; // start of the data+bss segment of the executable
+static size_t smpi_data_exe_size = 0;       // size of the data+bss segment of the executable
+static SmpiPrivStrategies smpi_privatize_global_variables;
 static void* smpi_data_exe_copy;
 
 // Initialized by smpi_prepare_global_memory_segment().
index 95067dd..10ab0ad 100644 (file)
@@ -58,7 +58,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_shared, smpi, "Logging specific to SMPI (shared memory macros)");
 
-namespace{
+namespace {
 /** Some location in the source code
  *
  *  This information is used by SMPI_SHARED_MALLOC to allocate  some shared memory for all simulated processes.
@@ -94,7 +94,7 @@ std::map<std::string, void*, std::less<>> calls;
 int smpi_shared_malloc_bogusfile           = -1;
 int smpi_shared_malloc_bogusfile_huge_page = -1;
 unsigned long smpi_shared_malloc_blocksize = 1UL << 20;
-}
+} // namespace
 
 void smpi_shared_destroy()
 {
index 94060e9..4624971 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
 
-extern std::string surf_parsed_filename;
-extern int surf_parse_lineno;
-
-namespace simgrid::smpi::utils {
+namespace {
 
 double total_benched_time=0;
 unsigned long total_malloc_size=0;
@@ -41,7 +38,7 @@ struct current_buffer_metadata_t {
 };
 
 alloc_metadata_t max_malloc;
-F2C* current_handle = nullptr;
+simgrid::smpi::F2C* current_handle = nullptr;
 current_buffer_metadata_t current_buffer1;
 current_buffer_metadata_t current_buffer2;
 
@@ -49,6 +46,10 @@ std::unordered_map<const void*, alloc_metadata_t> allocs;
 
 std::unordered_map<int, std::vector<std::string>> collective_calls;
 
+} // namespace
+
+namespace simgrid::smpi::utils {
+
 void add_benched_time(double time){
   total_benched_time += time;
 }
index dc4c5f5..bdec55b 100644 (file)
@@ -8,10 +8,10 @@
 #include "src/smpi/include/smpi_actor.hpp"
 #include "src/instr/instr_smpi.hpp"
 
-int mpi_in_place_;
-int mpi_bottom_;
-int mpi_status_ignore_;
-int mpi_statuses_ignore_;
+const int mpi_in_place_        = -222;
+const int mpi_bottom_          = -111;
+const int mpi_status_ignore_   = 0;
+const int mpi_statuses_ignore_ = 0;
 
 namespace simgrid::smpi {
 
index 27deae6..acac620 100644 (file)
@@ -23,7 +23,7 @@ void surf_host_model_init_current_default()
   engine->get_netzone_root()->set_host_model(host_model);
   surf_cpu_model_init_Cas01();
   surf_disk_model_init_S19();
-  surf_network_model_init_LegrandVelho();
+  simgrid_network_models().by_name("LV08").init();
 }
 
 void surf_host_model_init_compound()
index 5cc26f4..57a7efd 100644 (file)
@@ -26,9 +26,9 @@ static simgrid::config::Flag<std::string> cfg_network_solver("network/solver",
                                                              "Set linear equations solver used by network model",
                                                              "maxmin", &simgrid::kernel::lmm::System::validate_solver);
 
-/************************************************************************/
-/* New model based on optimizations discussed during Pedro Velho's thesis*/
-/************************************************************************/
+/******************************************************************************/
+/* Network model based on optimizations discussed during Pedro Velho's thesis */
+/******************************************************************************/
 /* @techreport{VELHO:2011:HAL-00646896:1, */
 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
 /*      title = {{Flow-level network models: have we reached the limits?}}, */
@@ -40,21 +40,24 @@ static simgrid::config::Flag<std::string> cfg_network_solver("network/solver",
 /*      month = Nov, */
 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
 /*  } */
-void surf_network_model_init_LegrandVelho()
-{
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_LegrandVelho");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-
-  simgrid::config::set_default<std::string>("network/latency-factor", "13.01");
-  simgrid::config::set_default<std::string>("network/bandwidth-factor", "0.97");
-  simgrid::config::set_default<double>("network/weight-S", 20537);
-}
-
-/***************************************************************************/
-/* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
-/***************************************************************************/
+SIMGRID_REGISTER_NETWORK_MODEL(
+    LV08,
+    "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
+    "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
+    []() {
+      auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_LegrandVelho");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+
+      simgrid::config::set_default<std::string>("network/latency-factor", "13.01");
+      simgrid::config::set_default<std::string>("network/bandwidth-factor", "0.97");
+      simgrid::config::set_default<double>("network/weight-S", 20537);
+    });
+
+/****************************************************************************/
+/* The older TCP sharing model designed by Loris Marchal and Henri Casanova */
+/****************************************************************************/
 /* @TechReport{      rr-lip2002-40, */
 /*   author        = {Henri Casanova and Loris Marchal}, */
 /*   institution   = {LIP}, */
@@ -63,17 +66,20 @@ void surf_network_model_init_LegrandVelho()
 /*   month         = {oct}, */
 /*   year          = {2002} */
 /* } */
-void surf_network_model_init_CM02()
-{
-  simgrid::config::set_default<std::string>("network/latency-factor", "1.0");
-  simgrid::config::set_default<std::string>("network/bandwidth-factor", "1.0");
-  simgrid::config::set_default<double>("network/weight-S", 0.0);
-
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_CM02");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-}
+SIMGRID_REGISTER_NETWORK_MODEL(
+    CM02,
+    "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
+    "small messages are thus poorly modeled).",
+    []() {
+      simgrid::config::set_default<std::string>("network/latency-factor", "1.0");
+      simgrid::config::set_default<std::string>("network/bandwidth-factor", "1.0");
+      simgrid::config::set_default<double>("network/weight-S", 0.0);
+
+      auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_CM02");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+    });
 
 /********************************************************************/
 /* Model based on LV08 and experimental results of MPI ping-pongs   */
@@ -87,21 +93,24 @@ void surf_network_model_init_CM02()
 /*  month=may, */
 /*  year={2011} */
 /*  } */
-void surf_network_model_init_SMPI()
-{
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_SMPI");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-
-  simgrid::config::set_default<double>("network/weight-S", 8775);
-  simgrid::config::set_default<std::string>("network/bandwidth-factor",
-                                            "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;"
-                                            "1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
-  simgrid::config::set_default<std::string>("network/latency-factor",
-                                            "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;"
-                                            "1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
-}
+SIMGRID_REGISTER_NETWORK_MODEL(
+    SMPI,
+    "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
+    "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
+    []() {
+      auto net_model = std::make_shared<simgrid::kernel::resource::NetworkCm02Model>("Network_SMPI");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+
+      simgrid::config::set_default<double>("network/weight-S", 8775);
+      simgrid::config::set_default<std::string>("network/bandwidth-factor",
+                                                "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;"
+                                                "1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
+      simgrid::config::set_default<std::string>("network/latency-factor",
+                                                "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;"
+                                                "1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
+    });
 
 namespace simgrid::kernel::resource {
 
index 2fc1acd..6183b2d 100644 (file)
@@ -15,13 +15,17 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 /*********
  * Model *
  *********/
-void surf_network_model_init_Constant()
-{
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>("Network_Constant");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-}
+SIMGRID_REGISTER_NETWORK_MODEL(
+    Constant,
+    "Simplistic network model where all communication take a constant time (one second). This model "
+    "provides the lowest realism, but is (marginally) faster. It is mostly useful when studying theoretical "
+    "distributed algorithms where the network is usually abstracted away.",
+    []() {
+      auto net_model = std::make_shared<simgrid::kernel::resource::NetworkConstantModel>("Network_Constant");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+    });
 
 namespace simgrid::kernel::resource {
 
index 5d80bd8..04fba51 100644 (file)
@@ -30,20 +30,23 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
 /*  month=june, */
 /*  year={2010} */
 /*  } */
-void surf_network_model_init_IB()
-{
-  using simgrid::kernel::resource::NetworkIBModel;
-
-  auto net_model = std::make_shared<NetworkIBModel>("Network_IB");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
-
-  simgrid::s4u::Link::on_communication_state_change_cb(NetworkIBModel::IB_action_state_changed_callback);
-  simgrid::kernel::activity::CommImpl::on_start.connect(NetworkIBModel::IB_comm_start_callback);
-  simgrid::s4u::Host::on_creation_cb(NetworkIBModel::IB_create_host_callback);
-  simgrid::config::set_default<double>("network/weight-S", 8775);
-}
+SIMGRID_REGISTER_NETWORK_MODEL(
+    IB,
+    "Realistic network model specifically tailored for HPC settings, with Infiniband contention model as described in "
+    "http://mescal.imag.fr/membres/jean-marc.vincent/index.html/PhD/Vienne.pdf",
+    []() {
+      using simgrid::kernel::resource::NetworkIBModel;
+
+      auto net_model = std::make_shared<NetworkIBModel>("Network_IB");
+      auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+      engine->add_model(net_model);
+      engine->get_netzone_root()->set_network_model(net_model);
+
+      simgrid::s4u::Link::on_communication_state_change_cb(NetworkIBModel::IB_action_state_changed_callback);
+      simgrid::kernel::activity::CommImpl::on_start.connect(NetworkIBModel::IB_comm_start_callback);
+      simgrid::s4u::Host::on_creation_cb(NetworkIBModel::IB_create_host_callback);
+      simgrid::config::set_default<double>("network/weight-S", 8775);
+    });
 
 namespace simgrid::kernel::resource {
 
index 5ab5965..aaa77ed 100644 (file)
@@ -51,8 +51,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_ns3, res_network, "Network model based on ns
 extern std::map<std::string, SgFlow*, std::less<>> flow_from_sock;
 extern std::map<std::string, ns3::ApplicationContainer, std::less<>> sink_from_sock;
 
-static ns3::InternetStackHelper stack;
-
 static int number_of_links    = 1;
 static int number_of_networks = 1;
 
@@ -67,6 +65,7 @@ static std::string transformIpv4Address(ns3::Ipv4Address from)
 
 NetPointNs3::NetPointNs3()
 {
+  static ns3::InternetStackHelper stack;
   stack.Install(ns3_node_);
 }
 
@@ -276,12 +275,16 @@ static void routeCreation_cb(bool symmetrical, const simgrid::kernel::routing::N
 /*********
  * Model *
  *********/
-void surf_network_model_init_NS3()
+// We can't use SIMGRID_REGISTER_NETWORK_MODEL here because ns-3 has a dash in its name
+static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_ns3_network_model_register()
 {
-  auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>("NS3 network model");
-  auto* engine   = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model(net_model);
-  engine->get_netzone_root()->set_network_model(net_model);
+  simgrid_network_models().add(
+      "ns-3", "Network pseudo-model using the real ns-3 simulator instead of an analytic model", []() {
+        auto net_model = std::make_shared<simgrid::kernel::resource::NetworkNS3Model>("NS3 network model");
+        auto* engine   = simgrid::kernel::EngineImpl::get_instance();
+        engine->add_model(net_model);
+        engine->get_netzone_root()->set_network_model(net_model);
+      });
 }
 
 static simgrid::config::Flag<std::string>
index 59c6007..9f2a198 100644 (file)
@@ -29,7 +29,7 @@
 #include <algorithm>
 #include <string>
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(platf_parse);
 
 namespace simgrid::kernel::routing {
 xbt::signal<void(ClusterCreationArgs const&)> on_cluster_creation;
index b0721c7..b22836e 100644 (file)
 #include <fstream>
 #include <string>
 
-XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)");
-
 /*********
  * Utils *
  *********/
 
-simgrid::kernel::profile::FutureEvtSet future_evt_set;
 std::vector<std::string> surf_path;
-
-const std::vector<surf_model_description_t> surf_network_model_description = {
-    {"LV08",
-     "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
-     "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
-     &surf_network_model_init_LegrandVelho},
-    {"Constant",
-     "Simplistic network model where all communication take a constant time (one second). This model "
-     "provides the lowest realism, but is (marginally) faster.",
-     &surf_network_model_init_Constant},
-    {"SMPI",
-     "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
-     "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
-     &surf_network_model_init_SMPI},
-    {"IB", "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
-     &surf_network_model_init_IB},
-    {"CM02",
-     "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
-     "small messages are thus poorly modeled).",
-     &surf_network_model_init_CM02},
-    {"ns-3", "Network pseudo-model using the ns-3 tcp model instead of an analytic model",
-     &surf_network_model_init_NS3},
-};
-
-#if !HAVE_SMPI
-void surf_network_model_init_IB()
-{
-  xbt_die("Please activate SMPI support in cmake to use the IB network model.");
-}
-#endif
-#if !SIMGRID_HAVE_NS3
-void surf_network_model_init_NS3()
-{
-  xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
-}
-#endif
-
-const std::vector<surf_model_description_t> surf_cpu_model_description = {
-    {"Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01},
-};
-
-const std::vector<surf_model_description_t> surf_disk_model_description = {
-    {"S19", "Simplistic disk model.", &surf_disk_model_init_S19},
-};
-
-const std::vector<surf_model_description_t> surf_host_model_description = {
-    {"default", "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
-     &surf_host_model_init_current_default},
-    {"compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
-     &surf_host_model_init_compound},
-    {"ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
-     &surf_host_model_init_ptask_L07},
-};
-
-const std::vector<surf_model_description_t> surf_optimization_mode_description = {
-    {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
-    {"TI",
-     "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
-     "model for now).",
-     nullptr},
-    {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
-};
-
-/** Displays the long description of all registered models, and quit */
-void model_help(const char* category, const std::vector<surf_model_description_t>& table)
-{
-  XBT_HELP("Long description of the %s models accepted by this simulator:", category);
-  for (auto const& item : table)
-    XBT_HELP("  %s: %s", item.name, item.description);
-}
-
-const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
-                                                       const std::string& name)
-{
-  if (auto pos = std::find_if(table.begin(), table.end(),
-                              [&name](const surf_model_description_t& item) { return item.name == name; });
-      pos != table.end())
-    return &*pos;
-
-  std::string sep;
-  std::string name_list;
-  for (auto const& item : table) {
-    name_list += sep + item.name;
-    sep = ", ";
-  }
-  xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
-}
index 7907a68..0a48400 100644 (file)
@@ -6,10 +6,12 @@
 #ifndef SURF_MODEL_H_
 #define SURF_MODEL_H_
 
+#include "src/simgrid/module.hpp"
 #include <xbt/asserts.h>
 #include <xbt/function_types.h>
 
 #include "src/internal_config.h"
+#include "src/kernel/resource/profile/Profile.hpp"
 
 #include <cfloat>
 #include <cmath>
@@ -74,79 +76,12 @@ XBT_PUBLIC void surf_cpu_model_init_Cas01();
 
 XBT_PUBLIC void surf_disk_model_init_S19();
 
-/** @ingroup SURF_models
- *  @brief Same as network model 'LagrangeVelho', only with different correction factors.
- *
- * This model is proposed by Pierre-Nicolas Clauss and Martin Quinson and Stéphane Génaud based on the model 'LV08' and
- * different correction factors depending on the communication size (< 1KiB, < 64KiB, >= 64KiB).
- * See comments in the code for more information.
- *
- *  @see surf_host_model_init_SMPI()
- */
-XBT_PUBLIC void surf_network_model_init_SMPI();
-
-/** @ingroup SURF_models
- *  @brief Same as network model 'LagrangeVelho', only with different correction factors.
- *
- * This model implements a variant of the contention model on Infiniband networks based on
- * the works of Jérôme Vienne : http://mescal.imag.fr/membres/jean-marc.vincent/index.html/PhD/Vienne.pdf
- *
- *  @see surf_host_model_init_IB()
- */
-#if !HAVE_SMPI
-XBT_ATTRIB_NORETURN
-#endif
-XBT_PUBLIC void surf_network_model_init_IB();
-
-/** @ingroup SURF_models
- *  @brief Initializes the platform with the network model 'LegrandVelho'
- *
- * This model is proposed by Arnaud Legrand and Pedro Velho based on the results obtained with the GTNets simulator for
- * onelink and dogbone sharing scenarios. See comments in the code for more information.
- *
- *  @see surf_host_model_init_LegrandVelho()
- */
-XBT_PUBLIC void surf_network_model_init_LegrandVelho();
-
-/** @ingroup SURF_models
- *  @brief Initializes the platform with the network model 'Constant'
- *
- *  In this model, the communication time between two network cards is constant, hence no need for a routing table.
- *  This is particularly useful when simulating huge distributed algorithms where scalability is really an issue. This
- *  function is called in conjunction with surf_host_model_init_compound.
- *
- *  @see surf_host_model_init_compound()
- */
-XBT_PUBLIC void surf_network_model_init_Constant();
-
-/** @ingroup SURF_models
- *  @brief Initializes the platform with the network model CM02
- *
- *  You should call this function by yourself only if you plan using surf_host_model_init_compound.
- *  See comments in the code for more information.
- */
-XBT_PUBLIC void surf_network_model_init_CM02();
-
-/** @ingroup SURF_models
- *  @brief Initializes the platform with the network model NS3
- *
- *  This function is called by surf_host_model_init_NS3 or by yourself only if you plan using
- *  surf_host_model_init_compound
- *
- *  @see surf_host_model_init_NS3()
- */
-#if !SIMGRID_HAVE_NS3
-XBT_ATTRIB_NORETURN
-#endif
-XBT_PUBLIC void surf_network_model_init_NS3();
-
 /** @ingroup SURF_models
  *  @brief Initializes the VM model used in the platform
  *
  *  A VM model depends on the physical CPU model to share the resources inside the VM
  *  It will also creates the CPU model for actions running inside the VM
  *
- *  Such model is subject to modification with warning in the ChangeLog so monitor it!
  */
 XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model);
 
@@ -178,39 +113,17 @@ XBT_PUBLIC void surf_host_model_init_ptask_L07();
 /* --------------------
  *  Model Descriptions
  * -------------------- */
-/** @brief Resource model description */
-struct surf_model_description_t {
-  const char* name;
-  const char* description;
-  std::function<void()> model_init_preparse;
-};
-
-XBT_PUBLIC const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
-                                                                  const std::string& name);
-XBT_PUBLIC void model_help(const char* category, const std::vector<surf_model_description_t>& table);
-
-#define SIMGRID_REGISTER_PLUGIN(id, desc, init)                                                                        \
-  static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)()                               \
-  {                                                                                                                    \
-    surf_plugin_description().emplace_back(surf_model_description_t{_XBT_STRINGIFY(id), (desc), (init)});              \
-  }
 
-/** @brief The list of all available plugins */
-inline auto& surf_plugin_description() // Function to avoid static initialization order fiasco
-{
-  static std::vector<surf_model_description_t> plugin_description_table;
-  return plugin_description_table;
-}
 /** @brief The list of all available optimization modes (both for cpu and networks).
  *  These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_optimization_mode_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_optimization_mode_description;
 /** @brief The list of all cpu models (pick one with --cfg=cpu/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_cpu_model_description;
-/** @brief The list of all network models (pick one with --cfg=network/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_network_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_cpu_model_description;
 /** @brief The list of all disk models (pick one with --cfg=disk/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_disk_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_disk_model_description;
 /** @brief The list of all host models (pick one with --cfg=host/model:) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_host_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_host_model_description;
+
+void simgrid_create_models();
 
 #endif /* SURF_MODEL_H_ */
index 5cfc7f2..951b12a 100644 (file)
 
 #include <vector>
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
-
 /* Trace related stuff */
 XBT_PRIVATE std::unordered_map<std::string, simgrid::kernel::profile::Profile*> traces_set_list;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_avail;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_host_speed;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_avail;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_bw;
-XBT_PRIVATE std::unordered_map<std::string, std::string> trace_connect_list_link_lat;
+static std::unordered_map<std::string, std::string> trace_connect_list_host_avail;
+static std::unordered_map<std::string, std::string> trace_connect_list_host_speed;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_avail;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_bw;
+static std::unordered_map<std::string, std::string> trace_connect_list_link_lat;
 
 void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect)
 {
index 567a2b2..ad0431a 100644 (file)
 
 #include "simgrid_dtd.c"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(platf_parse, ker_platform, "Logging specific to the parsing of platform files");
 
 std::string surf_parsed_filename; // Currently parsed file (for the error messages)
-std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
+static std::vector<simgrid::s4u::LinkInRoute> parsed_link_list; /* temporary store of current link list of a route */
 
 /* Helping functions */
 void surf_parse_assert(bool cond, const std::string& msg)
@@ -127,9 +127,9 @@ static void explodesRadical(const std::string& radicals, std::vector<int>* explo
 
 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
 
-std::vector<std::unordered_map<std::string, std::string>> property_sets;
+static std::vector<std::unordered_map<std::string, std::string>> property_sets;
 
-FILE *surf_file_to_parse = nullptr;
+static FILE* surf_file_to_parse = nullptr;
 
 /* Stuff relative to storage */
 void STag_surfxml_storage()
@@ -826,7 +826,7 @@ void ETag_surfxml_argument(){/* Nothing to do */}
 void ETag_surfxml_model___prop(){/* Nothing to do */}
 
 /* Open and Close parse file */
-YY_BUFFER_STATE surf_input_buffer;
+static YY_BUFFER_STATE surf_input_buffer;
 
 void surf_parse_open(const std::string& file)
 {
index 642fe2a..88726a9 100644 (file)
 #include <vector>
 
 int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */
-static std::recursive_mutex* log_cat_init_mutex = nullptr;
-
-xbt_log_appender_t xbt_log_default_appender = nullptr; /* set in log_init */
-xbt_log_layout_t xbt_log_default_layout     = nullptr; /* set in log_init */
 
 struct xbt_log_setting_t {
   std::string catname;
@@ -58,17 +54,6 @@ s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = {
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism itself");
 
-/* create the default appender and install it in the root category,
-   which were already created (damnit. Too slow little beetle) */
-void xbt_log_preinit(void)
-{
-  xbt_log_default_appender             = xbt_log_appender_stream(stderr);
-  xbt_log_default_layout               = xbt_log_layout_simple_new(nullptr);
-  _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender;
-  _XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout;
-  log_cat_init_mutex                   = new std::recursive_mutex();
-}
-
 static void xbt_log_help();
 static void xbt_log_help_categories();
 
@@ -132,7 +117,6 @@ static void log_cat_exit(const s_xbt_log_category_t* cat)
 void xbt_log_postexit(void)
 {
   XBT_VERB("Exiting log");
-  delete log_cat_init_mutex;
   log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT));
 }
 
@@ -246,8 +230,8 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority
   if (category->initialized)
     return priority >= category->threshold;
 
-  if (log_cat_init_mutex != nullptr)
-    log_cat_init_mutex->lock();
+  static std::recursive_mutex log_cat_init_mutex;
+  log_cat_init_mutex.lock();
 
   XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name,
          (category->firstChild ? category->firstChild->name : "none"),
@@ -255,8 +239,8 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority
 
   if (category == &_XBT_LOGV(XBT_LOG_ROOT_CAT)) {
     category->threshold = xbt_log_priority_info;
-    category->appender = xbt_log_default_appender;
-    category->layout = xbt_log_default_layout;
+    category->appender  = xbt_log_appender_stream(stderr);
+    category->layout    = xbt_log_layout_simple_new(nullptr);
   } else {
     if (not category->parent)
       category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT);
@@ -291,8 +275,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority
   }
 
   category->initialized = 1;
-  if (log_cat_init_mutex != nullptr)
-    log_cat_init_mutex->unlock();
+  log_cat_init_mutex.unlock();
   return priority >= category->threshold;
 }
 
index 4d41e07..8e70ab9 100644 (file)
@@ -64,7 +64,6 @@ XBT_ATTRIB_NOINLINE void sthread_disable()
 
 static void xbt_preinit()
 {
-  xbt_log_preinit();
   xbt_dict_preinit();
   atexit(xbt_postexit);
 }
index 09a186e..ccab38b 100644 (file)
@@ -133,7 +133,7 @@ int main(int argc, char* argv[])
   XBT_INFO("Parmap benchmark with %d workers (modes = %#x)...", nthreads, modes);
   XBT_INFO("%s", "");
 
-  simgrid::kernel::context::set_nthreads(nthreads);
+  simgrid::kernel::context::Context::set_nthreads(nthreads);
 
   XBT_INFO("Benchmark for parmap create+apply+destroy (small comp):");
   bench_all_modes(nthreads, timeout, modes, true, &fun_small_comp);
index c7558c9..e79cb39 100644 (file)
@@ -88,7 +88,7 @@ int main(int argc, char** argv)
   int status = 0;
   xbt_log_control_set("parmap_test.fmt:[%c/%p]%e%m%n");
   simgrid::s4u::Engine e(&argc, argv);
-  simgrid::kernel::context::set_nthreads(16); // dummy value > 1
+  simgrid::kernel::context::Context::set_nthreads(16); // dummy value > 1
 
   XBT_INFO("Basic testing posix");
   status += test_parmap_basic(XBT_PARMAP_POSIX);
index 3711fbd..4310792 100644 (file)
@@ -469,6 +469,8 @@ set(S4U_SRC
 
 set(SIMGRID_SRC
   src/simgrid/Exception.cpp
+  src/simgrid/module.cpp
+  src/simgrid/module.hpp
   src/simgrid/sg_config.cpp
   src/simgrid/sg_version.cpp
   src/simgrid/util.hpp