Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added RAM folding to SMPI.
authorpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 22 Sep 2010 12:07:21 +0000 (12:07 +0000)
committerpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 22 Sep 2010 12:07:21 +0000 (12:07 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8198 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.h
src/smpi/private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c

index a48f3db..fc4e087 100644 (file)
@@ -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())
 */
 
 #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
 SG_END_DECL()
 #endif
index a604da4..91d8489 100644 (file)
@@ -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
 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);
 
 void smpi_bench_begin(int rank, const char* mpi_call);
 void smpi_bench_end(int rank, const char* mpi_call);
 
index c449dfb..4792346 100644 (file)
@@ -5,10 +5,29 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "private.h"
   * 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_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;
 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();
 }
 */
   *(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);
+   }
+}
index 6c9f390..55e4894 100644 (file)
@@ -146,6 +146,7 @@ void smpi_global_destroy(void) {
   int count = smpi_process_count();
   int i;
 
   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++) {
   smpi_comm_destroy(MPI_COMM_WORLD);
   MPI_COMM_WORLD = MPI_COMM_NULL;
   for(i = 0; i < count; i++) {