X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6b214e9de5705ca77332bab116b2f23dba415f50..8aadc030761bd8e52324ec1dffe53dd335c67dd8:/src/smpi/internals/smpi_process.cpp diff --git a/src/smpi/internals/smpi_process.cpp b/src/smpi/internals/smpi_process.cpp index dc764faaf9..e090be0b66 100644 --- a/src/smpi/internals/smpi_process.cpp +++ b/src/smpi/internals/smpi_process.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -15,36 +15,20 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_process, smpi, "Logging specific to SMPI (kernel)"); -#define MAILBOX_NAME_MAXLEN (5 + sizeof(int) * 2 + 1) - -static char *get_mailbox_name(char *str, int index) -{ - snprintf(str, MAILBOX_NAME_MAXLEN, "SMPI-%0*x", static_cast(sizeof(int) * 2), static_cast(index)); - return str; -} - -static char *get_mailbox_name_small(char *str, int index) -{ - snprintf(str, MAILBOX_NAME_MAXLEN, "small%0*x", static_cast(sizeof(int) * 2), static_cast(index)); - return str; -} - namespace simgrid{ namespace smpi{ +using simgrid::s4u::Actor; using simgrid::s4u::ActorPtr; Process::Process(ActorPtr actor, msg_bar_t finalization_barrier) - : finalization_barrier_(finalization_barrier) + : finalization_barrier_(finalization_barrier), process_(actor) { - 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(); - timer_ = xbt_os_timer_new(); - state_ = SMPI_UNINITIALIZED; + mailbox_ = simgrid::s4u::Mailbox::byName("SMPI-" + std::to_string(process_->getPid())); + mailbox_small_ = simgrid::s4u::Mailbox::byName("small-" + std::to_string(process_->getPid())); + mailboxes_mutex_ = xbt_mutex_init(); + timer_ = xbt_os_timer_new(); + state_ = SMPI_UNINITIALIZED; if (MC_is_active()) MC_ignore_heap(timer_, xbt_os_timer_size()); @@ -66,52 +50,57 @@ Process::Process(ActorPtr actor, msg_bar_t finalization_barrier) #endif } -void Process::set_data(int index, int* argc, char*** argv) +Process::~Process() { - char* instance_id = (*argv)[1]; - comm_world_ = smpi_deployment_comm_world(instance_id); - 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; - - process_ = simgrid::s4u::Actor::self(); - static_cast(process_->getImpl()->userdata)->data = this; - - if (*argc > 3) { - memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2)); - (*argv)[(*argc) - 1] = nullptr; - (*argv)[(*argc) - 2] = nullptr; - } - (*argc)-=2; - argc_ = argc; - argv_ = argv; - // set the process attached to the mailbox - mailbox_small_->setReceiver(simgrid::s4u::Actor::self()); - XBT_DEBUG("<%d> New process in the game: %p", index_, process_); + if (comm_self_ != MPI_COMM_NULL) + simgrid::smpi::Comm::destroy(comm_self_); + if (comm_intra_ != MPI_COMM_NULL) + simgrid::smpi::Comm::destroy(comm_intra_); + xbt_os_timer_free(timer_); + xbt_mutex_destroy(mailboxes_mutex_); +} + +void Process::set_data(int* argc, char*** argv) +{ + instance_id_ = std::string((*argv)[1]); + comm_world_ = smpi_deployment_comm_world(instance_id_.c_str()); + msg_bar_t barrier = smpi_deployment_finalization_barrier(instance_id_.c_str()); + if (barrier != nullptr) // don't overwrite the current one if the instance has none + finalization_barrier_ = barrier; + + process_ = simgrid::s4u::Actor::self(); + static_cast(process_->getImpl()->userdata)->data = this; + + if (*argc > 3) { + memmove(&(*argv)[0], &(*argv)[2], sizeof(char*) * (*argc - 2)); + (*argv)[(*argc) - 1] = nullptr; + (*argv)[(*argc) - 2] = nullptr; + } + (*argc) -= 2; + argc_ = argc; + argv_ = argv; + // set the process attached to the mailbox + mailbox_small_->setReceiver(process_); + XBT_DEBUG("<%lu> SMPI process has been initialized: %p", process_->getPid(), process_.get()); } /** @brief Prepares the current process for termination. */ void Process::finalize() { state_ = SMPI_FINALIZED; - XBT_DEBUG("<%d> Process left the game", index_); + XBT_DEBUG("<%lu> Process left the game", process_->getPid()); - // This leads to an explosion of the search graph which cannot be reduced: - if(MC_is_active() || MC_record_replay_is_active()) - return; - // wait for all pending asynchronous comms to finish - MSG_barrier_wait(finalization_barrier_); + // This leads to an explosion of the search graph which cannot be reduced: + if(MC_is_active() || MC_record_replay_is_active()) + return; + // wait for all pending asynchronous comms to finish + MSG_barrier_wait(finalization_barrier_); } /** @brief Check if a process is finalized */ int Process::finalized() { - if (index_ != MPI_UNDEFINED) - return (state_ == SMPI_FINALIZED); - else - return 0; + return (state_ == SMPI_FINALIZED); } /** @brief Check if a process is initialized */ @@ -119,26 +108,23 @@ int Process::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)); + return (state_ == SMPI_INITIALIZED); } /** @brief Mark a process as initialized (=MPI_Init called) */ void Process::mark_as_initialized() { - if ((index_ != MPI_UNDEFINED) && (state_ != SMPI_FINALIZED)) + if (state_ != SMPI_FINALIZED) state_ = SMPI_INITIALIZED; } void Process::set_replaying(bool value){ - if ((index_ != MPI_UNDEFINED) && (state_ != SMPI_FINALIZED)) + if (state_ != SMPI_FINALIZED) replaying_ = value; } bool Process::replaying(){ - if (index_ != MPI_UNDEFINED) - return replaying_; - else - return false; + return replaying_; } void Process::set_user_data(void *data) @@ -175,11 +161,6 @@ smpi_privatization_region_t Process::privatized_region() return privatized_region_; } -int Process::index() -{ - return index_; -} - MPI_Comm Process::comm_world() { return comm_world_==nullptr ? MPI_COMM_NULL : *comm_world_; @@ -278,8 +259,6 @@ void Process::init(int *argc, char ***argv){ simgrid::s4u::ActorPtr proc = simgrid::s4u::Actor::self(); proc->getImpl()->context->set_cleanup(&MSG_process_cleanup_from_SIMIX); - int my_proc_id = proc->getPid() - 1; // The maestro process has always ID 0 but we don't need that process here - char* instance_id = (*argv)[1]; try { int rank = std::stoi(std::string((*argv)[2])); @@ -291,15 +270,15 @@ void Process::init(int *argc, char ***argv){ // cheinrich: I'm not sure what the impact of the SMPI_switch_data_segment on this call is. I moved // this up here so that I can set the privatized region before the switch. Process* process = smpi_process_remote(proc); + int my_proc_id = proc->getPid(); if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ /* Now using the segment index of this process */ - my_proc_id = proc->getImpl()->segment_index; process->set_privatized_region(smpi_init_global_memory_segment_process()); /* Done at the process's creation */ SMPI_switch_data_segment(my_proc_id); } - process->set_data(my_proc_id, argc, argv); + process->set_data(argc, argv); } xbt_assert(smpi_process(), "smpi_process() returned nullptr. You probably gave a nullptr parameter to MPI_Init. "