Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Replay/Memory: Move tmp buffers from replay to memory
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Mon, 19 Mar 2018 16:34:57 +0000 (17:34 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 28 Mar 2018 15:31:40 +0000 (17:31 +0200)
This is not the best solution, especially since we need a new function
right now to free tmp buffers at the end of the replay. However, this
may make the replay a bit cleaner and we can find another solution during
this refactoring process.

src/smpi/include/private.hpp
src/smpi/internals/smpi_memory.cpp
src/smpi/internals/smpi_replay.cpp

index f095454..bf9b287 100644 (file)
@@ -104,6 +104,7 @@ XBT_PRIVATE void smpi_shared_destroy();
 XBT_PRIVATE void* smpi_get_tmp_sendbuffer(int size);
 XBT_PRIVATE void* smpi_get_tmp_recvbuffer(int size);
 XBT_PRIVATE void smpi_free_tmp_buffer(void* buf);
+XBT_PRIVATE void smpi_free_replay_tmp_buffers();
 
 // f77 wrappers
 void mpi_init_(int* ierr);
index be0e7da..e704823 100644 (file)
@@ -230,3 +230,40 @@ void smpi_destroy_global_memory_segments(){
 #endif
 }
 
+static int sendbuffer_size = 0;
+static char* sendbuffer    = nullptr;
+static int recvbuffer_size = 0;
+static char* recvbuffer    = nullptr;
+
+//allocate a single buffer for all sends, growing it if needed
+void* smpi_get_tmp_sendbuffer(int size)
+{
+  if (not smpi_process()->replaying())
+    return xbt_malloc(size);
+  if (sendbuffer_size<size){
+    sendbuffer=static_cast<char*>(xbt_realloc(sendbuffer,size));
+    sendbuffer_size=size;
+  }
+  return sendbuffer;
+}
+
+//allocate a single buffer for all recv
+void* smpi_get_tmp_recvbuffer(int size){
+  if (not smpi_process()->replaying())
+    return xbt_malloc(size);
+  if (recvbuffer_size<size){
+    recvbuffer=static_cast<char*>(xbt_realloc(recvbuffer,size));
+    recvbuffer_size=size;
+  }
+  return recvbuffer;
+}
+
+void smpi_free_tmp_buffer(void* buf){
+  if (not smpi_process()->replaying())
+    xbt_free(buf);
+}
+
+void smpi_free_replay_tmp_buffers(){
+  xbt_free(sendbuffer);
+  xbt_free(recvbuffer);
+}
index cab8ee5..60a487b 100644 (file)
@@ -27,10 +27,6 @@ static std::unordered_map<int, std::vector<MPI_Request>*> reqq;
 
 static MPI_Datatype MPI_DEFAULT_TYPE;
 
-static int sendbuffer_size = 0;
-static char* sendbuffer    = nullptr;
-static int recvbuffer_size = 0;
-static char* recvbuffer    = nullptr;
 
 class ReplayActionArg {
   ReplayActionArg() {}
@@ -54,34 +50,6 @@ static void set_reqq_self(std::vector<MPI_Request> *mpi_request)
    reqq.insert({Actor::self()->getPid(), mpi_request});
 }
 
-//allocate a single buffer for all sends, growing it if needed
-void* smpi_get_tmp_sendbuffer(int size)
-{
-  if (not smpi_process()->replaying())
-    return xbt_malloc(size);
-  if (sendbuffer_size<size){
-    sendbuffer=static_cast<char*>(xbt_realloc(sendbuffer,size));
-    sendbuffer_size=size;
-  }
-  return sendbuffer;
-}
-
-//allocate a single buffer for all recv
-void* smpi_get_tmp_recvbuffer(int size){
-  if (not smpi_process()->replaying())
-    return xbt_malloc(size);
-  if (recvbuffer_size<size){
-    recvbuffer=static_cast<char*>(xbt_realloc(recvbuffer,size));
-    recvbuffer_size=size;
-  }
-  return recvbuffer;
-}
-
-void smpi_free_tmp_buffer(void* buf){
-  if (not smpi_process()->replaying())
-    xbt_free(buf);
-}
-
 /* Helper function */
 static double parse_double(const char *string)
 {
@@ -887,8 +855,7 @@ void smpi_replay_main(int* argc, char*** argv)
   if(active_processes==0){
     /* Last process alive speaking: end the simulated timer */
     XBT_INFO("Simulation time %f", smpi_process()->simulated_elapsed());
-    xbt_free(sendbuffer);
-    xbt_free(recvbuffer);
+    smpi_free_replay_tmp_buffers();
   }
 
   TRACE_smpi_comm_in(Actor::self()->getPid(), "smpi_replay_run_finalize", new simgrid::instr::NoOpTIData("finalize"));