Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[smpi] reduce the amount of memory used with the detached communication and non-conti...
authorjean-noel quintin <jnquintin@dhcp-892b9b4c.ucd.ie>
Thu, 4 Oct 2012 15:08:14 +0000 (16:08 +0100)
committerjean-noel quintin <jnquintin@dhcp-892b9b4c.ucd.ie>
Thu, 4 Oct 2012 15:08:14 +0000 (16:08 +0100)
src/smpi/private.h
src/smpi/smpi_base.c
src/smpi/smpi_mpi_dt.c

index ed59446..b969e6b 100644 (file)
@@ -73,6 +73,7 @@ typedef struct s_smpi_mpi_request {
   MPI_Comm comm;
   smx_action_t action;
   unsigned flags;
+  int detached;
 #ifdef HAVE_TRACING
   int send;
   int recv;
index d29b237..9993cb4 100644 (file)
@@ -70,6 +70,7 @@ static MPI_Request build_request(void *buf, int count,
   request->comm = comm;
   request->action = NULL;
   request->flags = flags;
+  request->detached = 0;
 #ifdef HAVE_TRACING
   request->send = 0;
   request->recv = 0;
@@ -145,7 +146,6 @@ MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
 void smpi_mpi_start(MPI_Request request)
 {
   smx_rdv_t mailbox;
-  int detached = 0;
 
   xbt_assert(!request->action,
              "Cannot (re)start a non-finished communication");
@@ -173,11 +173,14 @@ void smpi_mpi_start(MPI_Request request)
       mailbox = smpi_process_remote_mailbox(receiver);
     }
     if (request->size < 64*1024 ) { //(FIXME: this limit should be configurable)
-      void *oldbuf = request->buf;
-      detached = 1;
-      request->buf = malloc(request->size);
-      if (oldbuf)
-        memcpy(request->buf,oldbuf,request->size);
+      void *oldbuf = NULL;
+      if(request->old_type->has_subtype == 0){
+        oldbuf = request->buf;
+        request->detached = 1;
+        request->buf = malloc(request->size);
+        if (oldbuf)
+          memcpy(request->buf,oldbuf,request->size);
+      }
       XBT_DEBUG("Send request %p is detached; buf %p copied into %p",request,oldbuf,request->buf);
     }
 
@@ -188,7 +191,7 @@ void smpi_mpi_start(MPI_Request request)
                          &smpi_mpi_request_free_voidp, // how to free the userdata if a detached send fails
                          request,
                          // detach if msg size < eager/rdv switch limit
-                         detached);
+                         request->detached);
 
 #ifdef HAVE_TRACING
     /* FIXME: detached sends are not traceable (request->action == NULL) */
@@ -325,9 +328,7 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
     if(req->flags & RECV) {
       subtype->unserialize(req->buf, req->old_buf, req->size/smpi_datatype_size(datatype) , datatype->substruct);
     }
-    //FIXME: I am not sure that if the send is detached we have to free
-    //the sender buffer thus I do it only for the reciever
-    if(req->flags & RECV) free(req->buf);
+    if(req->detached == 0) free(req->buf);
   }
 
   if(req->flags & NON_PERSISTENT) {
index ec3015c..255e5ca 100644 (file)
@@ -201,6 +201,7 @@ void serialize_vector( const void *noncontiguous_vector,
     noncontiguous_vector_char += type_c->block_stride*type_c->size_oldtype;
   }
 }
+
 /*
  *  Copies contiguous data into noncontiguous memory.
  *  @param noncontiguous_vector - output vector
@@ -255,12 +256,12 @@ s_smpi_mpi_vector_t* smpi_datatype_vector_create( int block_stride,
 void smpi_datatype_create(MPI_Datatype* new_type, int size, int has_subtype,
                           void *struct_type, int flags){
   MPI_Datatype new_t= xbt_new(s_smpi_mpi_datatype_t,1);
-  new_t->size=size;
-  new_t->has_subtype=has_subtype;
-  new_t->lb=0;
-  new_t->ub=size;
-  new_t->flags=flags;
-  new_t->substruct=struct_type;
+  new_t->size = size;
+  new_t->has_subtype = has_subtype;
+  new_t->lb = 0;
+  new_t->ub = size;
+  new_t->flags = flags;
+  new_t->substruct = struct_type;
   *new_type = new_t;
 }
 
@@ -384,9 +385,7 @@ int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Dat
 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
 {
   int i;
-  size_t size; //Khalid added this
-
-  size = 0;
+  size_t size = 0;
   for(i=0; i< count; i++){
     if (blocklens[i]<=0)
       return MPI_ERR_ARG;