Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move Parallel{Boost,Raw,U}Context::{initialize,finalize} to SwappedContext
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 22:12:40 +0000 (23:12 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 5 Jan 2019 22:12:40 +0000 (23:12 +0100)
src/kernel/context/ContextBoost.cpp
src/kernel/context/ContextBoost.hpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextRaw.hpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp
src/kernel/context/ContextUnix.cpp
src/kernel/context/ContextUnix.hpp

index ac33134..b2e2331 100644 (file)
@@ -136,25 +136,6 @@ void BoostContext::stop()
 
 // ParallelBoostContext
 
-simgrid::xbt::Parmap<smx_actor_t>* ParallelBoostContext::parmap_;
-std::atomic<uintptr_t> ParallelBoostContext::threads_working_;
-thread_local uintptr_t ParallelBoostContext::worker_id_;
-std::vector<ParallelBoostContext*> ParallelBoostContext::workers_context_;
-
-void ParallelBoostContext::initialize()
-{
-  parmap_ = nullptr;
-  workers_context_.clear();
-  workers_context_.resize(SIMIX_context_get_nthreads(), nullptr);
-}
-
-void ParallelBoostContext::finalize()
-{
-  delete parmap_;
-  parmap_ = nullptr;
-  workers_context_.clear();
-}
-
 void ParallelBoostContext::run_all()
 {
   threads_working_ = 0;
@@ -171,7 +152,7 @@ void ParallelBoostContext::run_all()
 void ParallelBoostContext::suspend()
 {
   boost::optional<smx_actor_t> next_work = parmap_->next();
-  ParallelBoostContext* next_context;
+  SwappedContext* next_context;
   if (next_work) {
     XBT_DEBUG("Run next process");
     next_context = static_cast<ParallelBoostContext*>(next_work.get()->context_);
index 643549c..580ec7e 100644 (file)
@@ -69,15 +69,7 @@ public:
   void suspend() override;
   void resume() override;
 
-  static void initialize();
-  static void finalize();
   static void run_all();
-
-private:
-  static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
-  static std::vector<ParallelBoostContext*> workers_context_;
-  static std::atomic<uintptr_t> threads_working_;
-  static thread_local uintptr_t worker_id_;
 };
 
 class BoostContextFactory : public ContextFactory {
index 31b2aaf..6898c5f 100644 (file)
@@ -277,26 +277,6 @@ void RawContext::stop()
 
 // ParallelRawContext
 
-simgrid::xbt::Parmap<smx_actor_t>* ParallelRawContext::parmap_;
-std::atomic<uintptr_t> ParallelRawContext::threads_working_; /* number of threads that have started their work */
-uintptr_t thread_local ParallelRawContext::worker_id_;       /* thread-specific storage for the thread id */
-std::vector<ParallelRawContext*> ParallelRawContext::workers_context_; /* space to save the worker context
-                                                                          in each thread */
-
-void ParallelRawContext::initialize()
-{
-  parmap_ = nullptr;
-  workers_context_.clear();
-  workers_context_.resize(SIMIX_context_get_nthreads(), nullptr);
-}
-
-void ParallelRawContext::finalize()
-{
-  delete parmap_;
-  parmap_ = nullptr;
-  workers_context_.clear();
-}
-
 void ParallelRawContext::run_all()
 {
   threads_working_ = 0;
@@ -314,7 +294,7 @@ void ParallelRawContext::suspend()
 {
   /* determine the next context */
   boost::optional<smx_actor_t> next_work = parmap_->next();
-  ParallelRawContext* next_context;
+  SwappedContext* next_context;
   if (next_work) {
     /* there is a next process to resume */
     XBT_DEBUG("Run next process");
index f1b7914..e14877c 100644 (file)
@@ -56,15 +56,7 @@ public:
   void suspend() override;
   void resume() override;
 
-  static void initialize();
-  static void finalize();
   static void run_all();
-
-private:
-  static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
-  static std::vector<ParallelRawContext*> workers_context_;
-  static std::atomic<uintptr_t> threads_working_;
-  static uintptr_t thread_local worker_id_;
 };
 
 class RawContextFactory : public ContextFactory {
index 437fce0..be10ff8 100644 (file)
@@ -8,6 +8,7 @@
 #include "src/kernel/context/context_private.hpp"
 #include "src/simix/ActorImpl.hpp"
 #include "src/simix/smx_private.hpp"
+#include "xbt/parmap.hpp"
 
 #include "src/kernel/context/ContextSwapped.hpp"
 
@@ -33,8 +34,29 @@ namespace simgrid {
 namespace kernel {
 namespace context {
 
+/* Sequential execution */
 unsigned long SwappedContext::process_index_;
 
+/* Parallel execution */
+simgrid::xbt::Parmap<smx_actor_t>* SwappedContext::parmap_;
+std::atomic<uintptr_t> SwappedContext::threads_working_;       /* number of threads that have started their work */
+thread_local uintptr_t SwappedContext::worker_id_;             /* thread-specific storage for the thread id */
+std::vector<SwappedContext*> SwappedContext::workers_context_; /* space to save the worker's context in each thread */
+
+void SwappedContext::initialize()
+{
+  parmap_ = nullptr;
+  workers_context_.clear();
+  workers_context_.resize(SIMIX_context_get_nthreads(), nullptr);
+}
+
+void SwappedContext::finalize()
+{
+  delete parmap_;
+  parmap_ = nullptr;
+  workers_context_.clear();
+}
+
 SwappedContext* SwappedContext::maestro_context_ = nullptr;
 
 SwappedContext::SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
index e132621..9c15dc6 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "src/kernel/context/Context.hpp"
 
+#include <vector>
+
 namespace simgrid {
 namespace kernel {
 namespace context {
@@ -17,12 +19,15 @@ public:
   SwappedContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process);
   virtual ~SwappedContext();
 
+  static void initialize(); // Initialize the module, using the options
+  static void finalize();   // Finalize the module
+
   virtual void suspend();
   virtual void resume();
 
   static void run_all();
 
-  virtual void swap_into(SwappedContext* to) = 0;
+  virtual void swap_into(SwappedContext* to) = 0; // Defined in subclasses
 
   static SwappedContext* get_maestro() { return maestro_context_; }
   static void set_maestro(SwappedContext* maestro) { maestro_context_ = maestro; }
@@ -30,6 +35,12 @@ public:
 protected:
   void* stack_ = nullptr; /* the thread stack */
 
+  /* For the parallel execution */
+  static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
+  static std::vector<SwappedContext*> workers_context_;
+  static std::atomic<uintptr_t> threads_working_;
+  static thread_local uintptr_t worker_id_;
+
 private:
   static unsigned long process_index_;
   static SwappedContext* maestro_context_;
index 2d4bf3b..4e204b0 100644 (file)
@@ -148,26 +148,6 @@ void UContext::stop()
 
 // ParallelUContext
 
-simgrid::xbt::Parmap<smx_actor_t>* ParallelUContext::parmap_;
-std::atomic<uintptr_t> ParallelUContext::threads_working_;         /* number of threads that have started their work */
-thread_local uintptr_t ParallelUContext::worker_id_;               /* thread-specific storage for the thread id */
-std::vector<ParallelUContext*> ParallelUContext::workers_context_; /* space to save the worker's context
-                                                                    * in each thread */
-
-void ParallelUContext::initialize()
-{
-  parmap_ = nullptr;
-  workers_context_.clear();
-  workers_context_.resize(SIMIX_context_get_nthreads(), nullptr);
-}
-
-void ParallelUContext::finalize()
-{
-  delete parmap_;
-  parmap_ = nullptr;
-  workers_context_.clear();
-}
-
 void ParallelUContext::run_all()
 {
   threads_working_ = 0;
@@ -198,7 +178,7 @@ void ParallelUContext::suspend()
   /* determine the next context */
   // Get the next soul to embody now:
   boost::optional<smx_actor_t> next_work = parmap_->next();
-  ParallelUContext* next_context;
+  SwappedContext* next_context;
   if (next_work) {
     // There is a next soul to embody (ie, a next process to resume)
     XBT_DEBUG("Run next process");
index 1fcbc33..70852d0 100644 (file)
@@ -55,15 +55,7 @@ public:
   void suspend() override;
   void resume() override;
 
-  static void initialize();
-  static void finalize();
   static void run_all();
-
-private:
-  static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
-  static std::vector<ParallelUContext*> workers_context_;
-  static std::atomic<uintptr_t> threads_working_;
-  static thread_local uintptr_t worker_id_;
 };
 
 class UContextFactory : public ContextFactory {