From: pini Date: Wed, 22 Sep 2010 12:07:21 +0000 (+0000) Subject: Added RAM folding to SMPI. X-Git-Tag: v3_5~626 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/930a31488b75c8969603b0b36666e8fdcdcfd3a7 Added RAM folding to SMPI. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8198 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index a48f3db3d2..fc4e0873e7 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -251,5 +251,11 @@ XBT_PUBLIC(void) smpi_do_once_3(void); #define SMPI_DO_ONCE for (smpi_do_once_1(__FILE__, __LINE__); smpi_do_once_2(); smpi_do_once_3()) */ +XBT_PUBLIC(void*) smpi_shared_malloc(size_t size, const char* file, int line); +#define SMPI_SHARED_MALLOC(size) smpi_shared_malloc(size, __FILE__, __LINE__) + +XBT_PUBLIC(void) smpi_shared_free(void* data); +#define SMPI_SHARED_FREE(data) smpi_shared_free(data) + SG_END_DECL() #endif diff --git a/src/smpi/private.h b/src/smpi/private.h index a604da4463..91d84892bb 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -120,6 +120,7 @@ int smpi_coll_tuned_alltoall_pairwise(void* sendbuf, int sendcount, MPI_Datatype int smpi_coll_basic_alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm); // utilities +void smpi_bench_destroy(void); void smpi_bench_begin(int rank, const char* mpi_call); void smpi_bench_end(int rank, const char* mpi_call); diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index c449dfb784..4792346912 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -5,10 +5,29 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "private.h" +#include "xbt/dict.h" +#include "xbt/sysdep.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, "Logging specific to SMPI (benchmarking)"); +xbt_dict_t allocs = NULL; /* Allocated on first use */ + +typedef struct { + int count; + char data[]; +} shared_data_t; + +static void free_shared_data(void* ptr) { + free(ptr); +} + +void smpi_bench_destroy(void) { + if (allocs) { + xbt_dict_free(&allocs); + } +} + static void smpi_execute(double duration) { smx_host_t host; smx_action_t action; @@ -103,3 +122,41 @@ void smpi_do_once_3() *(smpi_global->do_once_duration) = smpi_stop_timer(); } */ + +void* smpi_shared_malloc(size_t size, const char* file, int line) { + char* loc = bprintf("%s:%d", file, line); + shared_data_t* data; + + if (!allocs) { + allocs = xbt_dict_new(); + } + data = xbt_dict_get_or_null(allocs, loc); + if (!data) { + data = (shared_data_t*)xbt_malloc0(sizeof(int) + size); + data->count = 1; + xbt_dict_set(allocs, loc, data, &free_shared_data); + } else { + data->count++; + } + free(loc); + return data->data; +} + +void smpi_shared_free(void* ptr) { + shared_data_t* data = (shared_data_t*)((int*)ptr - 1); + char* loc; + + if (!allocs) { + WARN0("Cannot free: nothing was allocated"); + return; + } + loc = xbt_dict_get_key(allocs, data); + if (!loc) { + WARN1("Cannot free: %p was not shared-allocated by SMPI", ptr); + return; + } + data->count--; + if (data->count <= 0) { + xbt_dict_remove(allocs, loc); + } +} diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 6c9f390148..55e4894312 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -146,6 +146,7 @@ void smpi_global_destroy(void) { int count = smpi_process_count(); int i; + smpi_bench_destroy(); smpi_comm_destroy(MPI_COMM_WORLD); MPI_COMM_WORLD = MPI_COMM_NULL; for(i = 0; i < count; i++) {