From 81618987978a30cc7b397dab4158ffd5ed8ef96a Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Mon, 19 Mar 2018 17:34:57 +0100 Subject: [PATCH 1/1] [SMPI] Replay/Memory: Move tmp buffers from replay to memory 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 | 1 + src/smpi/internals/smpi_memory.cpp | 37 ++++++++++++++++++++++++++++++ src/smpi/internals/smpi_replay.cpp | 35 +--------------------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index f0954541f9..bf9b287d5a 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -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); diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index be0e7da7b8..e70482319a 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -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(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(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); +} diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index cab8ee5773..60a487b7aa 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -27,10 +27,6 @@ static std::unordered_map*> 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) 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(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(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")); -- 2.20.1