Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #190 from Takishipp/clean_events
[simgrid.git] / src / smpi / smpi_process.cpp
index 5fc634e..41dd614 100644 (file)
@@ -1,18 +1,22 @@
+/* Copyright (c) 2009-2017. 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. */
+
 #include "mc/mc.h"
-#include "private.h"
-#include "simgrid/s4u/Mailbox.hpp"
-#include "src/kernel/activity/SynchroComm.hpp"
-#include "src/mc/mc_record.h"
 #include "src/mc/mc_replay.h"
 #include "src/msg/msg_private.h"
 #include "src/simix/smx_private.h"
-#include "surf/surf.h"
-#include "xbt/replay.hpp"
+#include "src/smpi/private.h"
+#include "src/smpi/smpi_process.hpp"
+#include "src/smpi/smpi_group.hpp"
+#include "src/smpi/smpi_comm.hpp"
+
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_process, smpi, "Logging specific to SMPI (kernel)");
 
 //TODO : replace
-extern Process **process_data;
+extern simgrid::smpi::Process **process_data;
 extern int* index_to_process_data;
 
 #define MAILBOX_NAME_MAXLEN (5 + sizeof(int) * 2 + 1)
@@ -32,25 +36,17 @@ static char *get_mailbox_name_small(char *str, int index)
 namespace simgrid{
 namespace smpi{
 
-Process::Process(int index)
+Process::Process(int index, msg_bar_t finalization_barrier)
+  : finalization_barrier_(finalization_barrier)
 {
   char name[MAILBOX_NAME_MAXLEN];
-  index_ = MPI_UNDEFINED;
-  argc_                 = nullptr;
-  argv_                 = nullptr;
   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;
   if (MC_is_active())
     MC_ignore_heap(timer_, xbt_os_timer_size());
-  comm_self_            = MPI_COMM_NULL;
-  comm_intra_           = MPI_COMM_NULL;
-  comm_world_           = nullptr;
-  state_                = SMPI_UNINITIALIZED;
-  sampling_             = 0;
-  finalization_barrier_ = nullptr;
-  return_value_         = 0;
 
 #if HAVE_PAPI
   if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0') {
@@ -70,19 +66,17 @@ Process::Process(int index)
 #endif
 }
 
-void Process::set_data(int index, int *argc, char ***argv)
+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 default one
       finalization_barrier_ = bar;
-    index_       = index;
     instance_id_ = instance_id;
-    replaying_   = false;
+    index_ = index;
 
-    static_cast<simgrid::MsgActorExt*>(SIMIX_process_self()->data)->data = this;
+    static_cast<simgrid::msg::ActorExt*>(SIMIX_process_self()->data)->data = this;
 
     if (*argc > 3) {
       memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2));
@@ -94,21 +88,16 @@ 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());
-    XBT_DEBUG("<%d> New process in the game: %p", index, SIMIX_process_self());
+    process_ = SIMIX_process_self();
+    XBT_DEBUG("<%d> New process in the game: %p", index_, SIMIX_process_self());
 }
 
-void Process::destroy()
+/** @brief Prepares the current process for termination. */
+void Process::finalize()
 {
-  if(smpi_privatize_global_variables){
-    smpi_switch_data_segment(index_);
-  }
   state_ = SMPI_FINALIZED;
   XBT_DEBUG("<%d> Process left the game", index_);
-}
 
-/** @brief Prepares the current process for termination. */
-void Process::finalize()
-{
     // This leads to an explosion of the search graph which cannot be reduced:
     if(MC_is_active() || MC_record_replay_is_active())
       return;
@@ -164,6 +153,10 @@ void *Process::get_user_data()
   return data_;
 }
 
+smx_actor_t Process::process(){
+  return process_;
+}
+
 
 /**
  * \brief Returns a structure that stores the location (filename + linenumber)
@@ -202,12 +195,12 @@ xbt_mutex_t Process::mailboxes_mutex()
 }
 
 #if HAVE_PAPI
-int Process::papi_event_set(void)
+int Process::papi_event_set()
 {
   return papi_event_set_;
 }
 
-papi_counter_t& smpi_process_papi_counters(void)
+papi_counter_t& smpi_process_papi_counters()
 {
   return papi_counter_data_;
 }
@@ -258,10 +251,6 @@ int Process::sampling()
   return sampling_;
 }
 
-void Process::set_finalization_barrier(msg_bar_t bar){
-  finalization_barrier_=bar;
-}
-
 msg_bar_t Process::finalization_barrier(){
   return finalization_barrier_;
 }
@@ -294,7 +283,7 @@ void Process::init(int *argc, char ***argv){
     int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s");
     smpi_deployment_register_process(instance_id, rank, index);
 
-    if(smpi_privatize_global_variables){
+    if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){
       /* Now using segment index of the process  */
       index = proc->segment_index;
       /* Done at the process's creation */