void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) { smx_ctx_base_factory_init(factory); XBT_VERB("Activating SYSV context factory"); (*factory)->finalize = smx_ctx_sysv_factory_finalize; (*factory)->create_context = smx_ctx_sysv_create_context; /* Do not overload that method (*factory)->finalize */ (*factory)->free = smx_ctx_sysv_free; (*factory)->name = "smx_sysv_context_factory"; if (SIMIX_context_is_parallel()) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ int nthreads = SIMIX_context_get_nthreads(); sysv_parmap = xbt_parmap_new(nthreads, SIMIX_context_get_parallel_mode()); sysv_workers_context = xbt_new(smx_ctx_sysv_t, nthreads); sysv_maestro_context = NULL; xbt_os_thread_key_create(&sysv_worker_id_key); (*factory)->stop = smx_ctx_sysv_stop_parallel; (*factory)->suspend = smx_ctx_sysv_suspend_parallel; (*factory)->runall = smx_ctx_sysv_runall_parallel; #else THROWF(arg_error, 0, "No thread support for parallel context execution"); #endif } else { (*factory)->stop = smx_ctx_sysv_stop_serial; (*factory)->suspend = smx_ctx_sysv_suspend_serial; (*factory)->runall = smx_ctx_sysv_runall_serial; } }
void RawContextFactory::run_all_parallel() { #if HAVE_THREAD_CONTEXTS raw_threads_working = 0; if (raw_parmap == nullptr) raw_parmap = xbt_parmap_new( SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode()); xbt_parmap_apply(raw_parmap, [](void* arg) { smx_process_t process = static_cast<smx_process_t>(arg); RawContext* context = static_cast<RawContext*>(process->context); context->resume_parallel(); }, simix_global->process_to_run); #else xbt_die("You asked for a parallel execution, but you don't have any threads."); #endif }