From 93d31a3e9bb7abb3f49cd8fca2f539aa873179a5 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 9 Jun 2021 17:21:48 +0200 Subject: [PATCH] Add memset(0) for shared calloc. Add missing barrier to auto-shared test. --- src/smpi/internals/smpi_shared.cpp | 15 ++++++++------- teshsuite/smpi/auto-shared/auto-shared.c | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 9cd9c42d2a..4af2c2f0f1 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -319,17 +319,18 @@ void* smpi_shared_malloc_intercept(size_t size, const char* file, int line) void* smpi_shared_calloc_intercept(size_t num_elm, size_t elem_size, const char* file, int line) { - if( smpi_cfg_auto_shared_malloc_thresh() == 0 || elem_size*num_elm < smpi_cfg_auto_shared_malloc_thresh()){ - void* ptr = ::operator new(elem_size*num_elm); + size_t size = elem_size * num_elm; + if (smpi_cfg_auto_shared_malloc_thresh() == 0 || size < smpi_cfg_auto_shared_malloc_thresh()) { + void* ptr = ::operator new(size); if(not smpi_cfg_trace_call_use_absolute_path()) - simgrid::smpi::utils::account_malloc_size(elem_size*num_elm, simgrid::xbt::Path(file).get_base_name(), line, ptr); + simgrid::smpi::utils::account_malloc_size(size, simgrid::xbt::Path(file).get_base_name(), line, ptr); else - simgrid::smpi::utils::account_malloc_size(elem_size*num_elm, file, line, ptr); - memset(ptr, 0, elem_size*num_elm); + simgrid::smpi::utils::account_malloc_size(size, file, line, ptr); + memset(ptr, 0, size); return ptr; } else { - simgrid::smpi::utils::account_shared_size(elem_size*num_elm); - return smpi_shared_malloc(elem_size*num_elm, file, line); + simgrid::smpi::utils::account_shared_size(size); + return memset(smpi_shared_malloc(size, file, line), 0, size); } } diff --git a/teshsuite/smpi/auto-shared/auto-shared.c b/teshsuite/smpi/auto-shared/auto-shared.c index 9bc350f5b7..b32153e8ae 100644 --- a/teshsuite/smpi/auto-shared/auto-shared.c +++ b/teshsuite/smpi/auto-shared/auto-shared.c @@ -34,6 +34,8 @@ int main(int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &size); //Let's Allocate a memory buffer uint64_t* buf = calloc(1, sizeof(uint64_t)); + + MPI_Barrier(MPI_COMM_WORLD); //one writes data in it if(rank==0){ *buf=size; -- 2.20.1