// 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;
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_);
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 {
// 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;
{
/* 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");
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 {
#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"
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)
#include "src/kernel/context/Context.hpp"
+#include <vector>
+
namespace simgrid {
namespace kernel {
namespace context {
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; }
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_;
// 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;
/* 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");
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 {