X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/923cb2164ea8c0f542cf2c82cd6bacfdc6432228..dbcf720995035476f8fda570bd5ab0926cacc799:/src/smpi/internals/smpi_process.cpp diff --git a/src/smpi/internals/smpi_process.cpp b/src/smpi/internals/smpi_process.cpp index bb4f482f5d..280e5e94ac 100644 --- a/src/smpi/internals/smpi_process.cpp +++ b/src/smpi/internals/smpi_process.cpp @@ -8,16 +8,12 @@ #include "private.hpp" #include "smpi_comm.hpp" #include "smpi_group.hpp" -#include "src/mc/mc_replay.h" +#include "src/mc/mc_replay.hpp" #include "src/msg/msg_private.hpp" #include "src/simix/smx_private.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_process, smpi, "Logging specific to SMPI (kernel)"); -//TODO : replace -extern simgrid::smpi::Process **process_data; -extern int* index_to_process_data; - #define MAILBOX_NAME_MAXLEN (5 + sizeof(int) * 2 + 1) static char *get_mailbox_name(char *str, int index) @@ -35,10 +31,14 @@ static char *get_mailbox_name_small(char *str, int index) namespace simgrid{ namespace smpi{ -Process::Process(int index, msg_bar_t finalization_barrier) +using simgrid::s4u::ActorPtr; + +Process::Process(ActorPtr actor, msg_bar_t finalization_barrier) : finalization_barrier_(finalization_barrier) { char name[MAILBOX_NAME_MAXLEN]; + process_ = actor; + int index = actor->getPid() - 1; // TODO cheinrich: This needs to be removed! Just a quick hack to make the following 2 lines work mailbox_ = simgrid::s4u::Mailbox::byName(get_mailbox_name(name, index)); mailbox_small_ = simgrid::s4u::Mailbox::byName(get_mailbox_name_small(name, index)); mailboxes_mutex_ = xbt_mutex_init(); @@ -69,13 +69,14 @@ void Process::set_data(int index, int* argc, char*** argv) { char* instance_id = (*argv)[1]; comm_world_ = smpi_deployment_comm_world(instance_id); - msg_bar_t bar = smpi_deployment_finalization_barrier(instance_id); - if (bar != nullptr) // don't overwrite the current one if the instance has none - finalization_barrier_ = bar; + msg_bar_t barrier = smpi_deployment_finalization_barrier(instance_id); + if (barrier != nullptr) // don't overwrite the current one if the instance has none + finalization_barrier_ = barrier; instance_id_ = instance_id; index_ = index; - static_cast(SIMIX_process_self()->userdata)->data = this; + process_ = simgrid::s4u::Actor::self(); + static_cast(process_->getImpl()->userdata)->data = this; if (*argc > 3) { memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2)); @@ -87,8 +88,7 @@ void Process::set_data(int index, int* argc, char*** argv) argv_ = argv; // set the process attached to the mailbox mailbox_small_->setReceiver(simgrid::s4u::Actor::self()); - process_ = SIMIX_process_self(); - XBT_DEBUG("<%d> New process in the game: %p", index_, SIMIX_process_self()); + XBT_DEBUG("<%d> New process in the game: %p", index_, process_); } /** @brief Prepares the current process for termination. */ @@ -116,11 +116,9 @@ int Process::finalized() /** @brief Check if a process is initialized */ int Process::initialized() { - if (index_to_process_data == nullptr){ - return false; - } else{ - return ((index_ != MPI_UNDEFINED) && (state_ == SMPI_INITIALIZED)); - } + // TODO cheinrich: Check if we still need this. This should be a global condition, not for a + // single process ... ? + return ((index_ != MPI_UNDEFINED) && (state_ == SMPI_INITIALIZED)); } /** @brief Mark a process as initialized (=MPI_Init called) */ @@ -152,7 +150,7 @@ void *Process::get_user_data() return data_; } -smx_actor_t Process::process(){ +ActorPtr Process::process(){ return process_; } @@ -272,19 +270,14 @@ void Process::set_return_value(int val){ void Process::init(int *argc, char ***argv){ - if (process_data == nullptr){ - printf("SimGrid was not initialized properly before entering MPI_Init. Aborting, please check compilation process and use smpirun\n"); - exit(1); + if (smpi_process_count() == 0) { + xbt_die("SimGrid was not initialized properly before entering MPI_Init. Aborting, please check compilation process and use smpirun\n"); } if (argc != nullptr && argv != nullptr) { - smx_actor_t proc = SIMIX_process_self(); - proc->context->set_cleanup(&MSG_process_cleanup_from_SIMIX); - - int index = proc->pid - 1; // The maestro process has always ID 0 but we don't need that process here + simgrid::s4u::ActorPtr proc = simgrid::s4u::Actor::self(); + proc->getImpl()->context->set_cleanup(&MSG_process_cleanup_from_SIMIX); - if(index_to_process_data == nullptr){ - index_to_process_data=static_cast(xbt_malloc(SIMIX_process_count()*sizeof(int))); - } + int index = proc->getPid() - 1; // The maestro process has always ID 0 but we don't need that process here char* instance_id = (*argv)[1]; try { @@ -298,8 +291,8 @@ void Process::init(int *argc, char ***argv){ // this up here so that I can set the privatized region before the switch. Process* process = smpi_process_remote(index); if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ - /* Now using segment index of the process */ - index = proc->segment_index; + /* Now using the segment index of this process */ + index = proc->getImpl()->segment_index; process->set_privatized_region(smpi_init_global_memory_segment_process()); /* Done at the process's creation */ SMPI_switch_data_segment(index);