-/* 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. */
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 process_id)
-{
- snprintf(str, MAILBOX_NAME_MAXLEN, "SMPI-%0*x", static_cast<int>(sizeof(int) * 2), static_cast<unsigned>(process_id));
- return str;
-}
-
-static char* get_mailbox_name_small(char* str, int process_id)
-{
- snprintf(str, MAILBOX_NAME_MAXLEN, "small%0*x", static_cast<int>(sizeof(int) * 2), static_cast<unsigned>(process_id));
- return str;
-}
-
namespace simgrid{
namespace smpi{
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;
- mailbox_ = simgrid::s4u::Mailbox::byName(get_mailbox_name(name, process_->getPid()));
- mailbox_small_ = simgrid::s4u::Mailbox::byName(get_mailbox_name_small(name, process_->getPid()));
- 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());
#endif
}
+Process::~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]);
argc_ = argc;
argv_ = argv;
// set the process attached to the mailbox
- mailbox_small_->setReceiver(simgrid::s4u::Actor::self());
- XBT_DEBUG("<%lu> New process in the game: %p", process_->getPid(), process_);
+ mailbox_small_->setReceiver(process_);
+ XBT_DEBUG("<%lu> SMPI process has been initialized: %p", process_->getPid(), process_.get());
}
/** @brief Prepares the current process for termination. */