Esempio n. 1
0
void BoostParallelContext::suspend()
{
  smx_process_t next_work = (smx_process_t) xbt_parmap_next(parmap_);
  BoostParallelContext* next_context = nullptr;

  if (next_work != nullptr) {
    XBT_DEBUG("Run next process");
    next_context = static_cast<BoostParallelContext*>(next_work->context);
  }
  else {
    XBT_DEBUG("No more processes to run");
    unsigned long worker_id =
      (unsigned long) xbt_os_thread_get_specific(worker_id_key_);
    next_context = static_cast<BoostParallelContext*>(
      workers_context_[worker_id]);
  }

  SIMIX_context_set_current((smx_context_t) next_context);
#if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    this->fc_, next_context->fc_, (intptr_t)next_context);
#else
  boost::context::jump_fcontext(
    &this->fc_, next_context->fc_, (intptr_t)next_context);
#endif
}
Esempio n. 2
0
void RawContext::suspend_parallel()
{
#if HAVE_THREAD_CONTEXTS
  /* determine the next context */
  smx_process_t next_work = (smx_process_t) xbt_parmap_next(raw_parmap);
  RawContext* next_context = nullptr;

  if (next_work != NULL) {
    /* there is a next process to resume */
    XBT_DEBUG("Run next process");
    next_context = (RawContext*) next_work->context;
  }
  else {
    /* all processes were run, go to the barrier */
    XBT_DEBUG("No more processes to run");
    uintptr_t worker_id = (uintptr_t)
      xbt_os_thread_get_specific(raw_worker_id_key);
    next_context = (RawContext*) raw_workers_context[worker_id];
    XBT_DEBUG("Restoring worker stack %zu (working threads = %zu)",
        worker_id, raw_threads_working);
  }

  SIMIX_context_set_current(next_context);
  raw_swapcontext(&this->stack_top_, next_context->stack_top_);
#endif
}
Esempio n. 3
0
static void smx_ctx_boost_suspend_parallel(smx_context_t context)
{
  smx_process_t next_work = (smx_process_t) xbt_parmap_next(boost_parmap);
  smx_ctx_boost_t next_context;

  if (next_work != NULL) {
    XBT_DEBUG("Run next process");
    next_context = (smx_ctx_boost_t) next_work->context;
  }
  else {
    XBT_DEBUG("No more processes to run");
    unsigned long worker_id =
        (unsigned long) xbt_os_thread_get_specific(boost_worker_id_key);
    next_context = boost_workers_context[worker_id];
  }

  SIMIX_context_set_current((smx_context_t) next_context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(
    ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#else
  boost::context::jump_fcontext(
    &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#endif
}
Esempio n. 4
0
void BoostSerialContext::suspend()
{
  /* determine the next context */
  BoostSerialContext* next_context = nullptr;
  unsigned long int i = process_index_++;

  if (i < xbt_dynar_length(simix_global->process_to_run)) {
    /* execute the next process */
    XBT_DEBUG("Run next process");
    next_context = static_cast<BoostSerialContext*>(xbt_dynar_get_as(
        simix_global->process_to_run, i, smx_process_t)->context);
  }
  else {
    /* all processes were run, return to maestro */
    XBT_DEBUG("No more process to run");
    next_context = static_cast<BoostSerialContext*>(
      maestro_context_);
  }
  SIMIX_context_set_current((smx_context_t) next_context);
  #if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    this->fc_, next_context->fc_, (intptr_t) next_context);
  #else
  boost::context::jump_fcontext(
    &this->fc_, next_context->fc_, (intptr_t) next_context);
  #endif
}
Esempio n. 5
0
static void smx_ctx_boost_suspend_serial(smx_context_t context)
{
  /* determine the next context */
  smx_ctx_boost_t next_context;
  unsigned long int i = boost_process_index++;

  if (i < xbt_dynar_length(simix_global->process_to_run)) {
    /* execute the next process */
    XBT_DEBUG("Run next process");
    next_context = (smx_ctx_boost_t) xbt_dynar_get_as(
        simix_global->process_to_run, i, smx_process_t)->context;
  }
  else {
    /* all processes were run, return to maestro */
    XBT_DEBUG("No more process to run");
    next_context = (smx_ctx_boost_t) boost_maestro_context;
  }
  SIMIX_context_set_current((smx_context_t) next_context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(
    ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#else
  boost::context::jump_fcontext(
    &((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
#endif
}
Esempio n. 6
0
Context::Context(std::function<void()> code,
                 void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
    : code_(std::move(code)), process_(process), iwannadie(false)
{
    /* If the user provided a function for the process then use it.
       Otherwise, it is the context for maestro and we should set it as the
       current context */
    if (has_code())
        this->cleanup_func_ = cleanup_func;
    else
        SIMIX_context_set_current(this);
}
Esempio n. 7
0
static void smx_ctx_boost_resume_serial(smx_process_t first_process)
{
  smx_ctx_boost_t context = (smx_ctx_boost_t) first_process->context;
  SIMIX_context_set_current((smx_context_t) context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(boost_maestro_context->fc, context->fc,
    (intptr_t)context);
#else
  boost::context::jump_fcontext(&boost_maestro_context->fc, context->fc,
    (intptr_t)context);
#endif
}
Esempio n. 8
0
void BoostContext::resume()
{
  SIMIX_context_set_current(this);
#if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    maestro_context_->fc_, this->fc_,
    (intptr_t) this);
#else
  boost::context::jump_fcontext(
    &maestro_context_->fc_, this->fc_,
    (intptr_t) this);
#endif
}
Esempio n. 9
0
void RawContext::resume_parallel()
{
#if HAVE_THREAD_CONTEXTS
  uintptr_t worker_id = __sync_fetch_and_add(&raw_threads_working, 1);
  xbt_os_thread_set_specific(raw_worker_id_key, (void*) worker_id);
  RawContext* worker_context = (RawContext*) SIMIX_context_self();
  raw_workers_context[worker_id] = worker_context;
  XBT_DEBUG("Saving worker stack %zu", worker_id);
  SIMIX_context_set_current(this);
  raw_swapcontext(&worker_context->stack_top_, this->stack_top_);
#else
  xbt_die("Parallel execution disabled");
#endif
}
Esempio n. 10
0
void BoostParallelContext::resume()
{
  unsigned long worker_id = __sync_fetch_and_add(&threads_working_, 1);
  xbt_os_thread_set_specific(worker_id_key_, (void*) worker_id);

  BoostParallelContext* worker_context =
    static_cast<BoostParallelContext*>(SIMIX_context_self());
  workers_context_[worker_id] = worker_context;

  SIMIX_context_set_current(this);
#if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    worker_context->fc_, this->fc_, (intptr_t) this);
#else
  boost::context::jump_fcontext(
    &worker_context->fc_, this->fc_, (intptr_t) this);
#endif
}
Esempio n. 11
0
static void smx_ctx_boost_resume_parallel(smx_process_t process)
{
  unsigned long worker_id = __sync_fetch_and_add(&boost_threads_working, 1);
  xbt_os_thread_set_specific(boost_worker_id_key, (void*) worker_id);

  smx_ctx_boost_t worker_context = (smx_ctx_boost_t)SIMIX_context_self();
  boost_workers_context[worker_id] = worker_context;
  smx_ctx_boost_t context = (smx_ctx_boost_t) process->context;

  SIMIX_context_set_current((smx_context_t) context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(worker_context->fc, context->fc,
    (intptr_t)context);
#else
  boost::context::jump_fcontext(&worker_context->fc, context->fc,
    (intptr_t)context);
#endif
}
Esempio n. 12
0
void RawContext::suspend_serial()
{
  /* determine the next context */
  RawContext* next_context = nullptr;
  unsigned long int i;
  i = raw_process_index++;
  if (i < xbt_dynar_length(simix_global->process_to_run)) {
    /* execute the next process */
    XBT_DEBUG("Run next process");
    next_context = (RawContext*) xbt_dynar_get_as(
        simix_global->process_to_run, i, smx_process_t)->context;
  }
  else {
    /* all processes were run, return to maestro */
    XBT_DEBUG("No more process to run");
    next_context = (RawContext*) raw_maestro_context;
  }
  SIMIX_context_set_current(next_context);
  raw_swapcontext(&this->stack_top_, next_context->stack_top_);
}
Esempio n. 13
0
void RawContext::resume_serial()
{
  SIMIX_context_set_current(this);
  raw_swapcontext(&raw_maestro_context->stack_top_, this->stack_top_);
}