Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
n-th cleanup on datatype refcount handling
authordegomme <augustin.degomme@unibas.ch>
Mon, 25 Apr 2016 21:19:11 +0000 (23:19 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Mon, 25 Apr 2016 21:19:38 +0000 (23:19 +0200)
src/smpi/smpi_base.cpp
src/smpi/smpi_mpi_dt.cpp
src/smpi/smpi_rma.cpp

index dac899c..62699a1 100644 (file)
@@ -252,10 +252,12 @@ static MPI_Request build_request(void *buf, int count, MPI_Datatype datatype, in
   request->old_type = datatype;
 
   request->size = smpi_datatype_size(datatype) * count;
+  smpi_datatype_use(datatype);
   request->src = src;
   request->dst = dst;
   request->tag = tag;
   request->comm = comm;
+  smpi_comm_use(request->comm);
   request->action = NULL;
   request->flags = flags;
   request->detached = 0;
@@ -272,7 +274,6 @@ static MPI_Request build_request(void *buf, int count, MPI_Datatype datatype, in
   request->op = MPI_REPLACE;
   request->send = 0;
   request->recv = 0;
- // if (flags & SEND) smpi_datatype_unuse(datatype);
 
   return request;
 }
@@ -382,8 +383,6 @@ void smpi_mpi_start(MPI_Request request)
 
     // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
     request->real_size=request->size;
-    smpi_datatype_use(request->old_type);
-    smpi_comm_use(request->comm);
     request->action = simcall_comm_irecv(SIMIX_process_self(), mailbox, request->buf, &request->real_size, &match_recv,
                                          !smpi_process_get_replaying()? &smpi_comm_copy_buffer_callback
                                          : &smpi_comm_null_copy_buffer_callback, request, -1.0);
@@ -472,8 +471,6 @@ void smpi_mpi_start(MPI_Request request)
 
     // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
     request->real_size=request->size;
-    smpi_datatype_use(request->old_type);
-    smpi_comm_use(request->comm);
     request->action = simcall_comm_isend(SIMIX_process_from_PID(request->src+1), mailbox, request->size, -1.0,
                                          buf, request->real_size, &match_send,
                          &xbt_free_f, // how to free the userdata if a detached send fails
@@ -508,6 +505,8 @@ void smpi_mpi_request_free(MPI_Request * request)
     if((*request)->refcount<0) xbt_die("wrong refcount");
 
     if((*request)->refcount==0){
+        smpi_datatype_unuse((*request)->old_type);
+        smpi_comm_unuse((*request)->comm);
         print_request("Destroying", (*request));
         xbt_free(*request);
         *request = MPI_REQUEST_NULL;
@@ -530,6 +529,7 @@ MPI_Request smpi_rma_send_init(void *buf, int count, MPI_Datatype datatype, int
     request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype,  src, dst, tag,
                             comm, RMA | NON_PERSISTENT | ISEND | SEND | PREPARED | ACCUMULATE);
     request->op = op;
+//    smpi_datatype_use(datatype);
   }
   return request;
 }
@@ -545,6 +545,7 @@ MPI_Request smpi_rma_recv_init(void *buf, int count, MPI_Datatype datatype, int
     request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype,  src, dst, tag,
                             comm, RMA | NON_PERSISTENT | RECV | PREPARED | ACCUMULATE);
     request->op = op;
+//    smpi_datatype_use(datatype);
   }
   return request;
 }
@@ -692,8 +693,6 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
           smpi_op_apply(req->op, req->buf, req->old_buf, &n, &datatype);
       }
     }
-    smpi_comm_unuse(req->comm);
-    smpi_datatype_unuse(req->old_type);
   }
 
   if (TRACE_smpi_view_internals()) {
@@ -705,8 +704,6 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
   }
 
   if(req->detached_sender!=NULL){
-    smpi_datatype_unuse(req->detached_sender->old_type);
-    smpi_comm_unuse(req->detached_sender->comm);
     smpi_mpi_request_free(&(req->detached_sender));
   }
   if(req->flags & PERSISTENT)
index ed34374..3463eb8 100644 (file)
@@ -178,6 +178,7 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
   int ret=MPI_SUCCESS;
   *new_t= xbt_new(s_smpi_mpi_datatype_t,1);
   memcpy(*new_t, datatype, sizeof(s_smpi_mpi_datatype_t));
+  (*new_t)->in_use=1;
   if (datatype->sizeof_substruct){
     (*new_t)->substruct=xbt_malloc(datatype->sizeof_substruct);
     memcpy((*new_t)->substruct, datatype->substruct, datatype->sizeof_substruct);
@@ -197,6 +198,7 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
         if(elem && elem->copy_fn!=MPI_NULL_COPY_FN){
           ret = elem->copy_fn(datatype, *key, NULL, value_in, &value_out, &flag );
           if(ret!=MPI_SUCCESS){
+            smpi_datatype_unuse(*new_t);
             *new_t=MPI_DATATYPE_NULL;
             return ret;
           }
@@ -776,7 +778,6 @@ s_smpi_mpi_indexed_t* smpi_datatype_indexed_create( int* block_lengths, int* blo
   new_t->base.unserialize = &unserialize_indexed;
   new_t->base.subtype_free = &free_indexed;
   new_t->base.subtype_use = &use_indexed;
- //TODO : add a custom function for each time to clean these 
   new_t->block_lengths= xbt_new(int, block_count);
   new_t->block_indices= xbt_new(int, block_count);
   int i;
@@ -927,7 +928,6 @@ s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths, MPI_Ai
   new_t->base.unserialize = &unserialize_hindexed;
   new_t->base.subtype_free = &free_hindexed;
   new_t->base.subtype_use = &use_hindexed;
- //TODO : add a custom function for each time to clean these 
   new_t->block_lengths= xbt_new(int, block_count);
   new_t->block_indices= xbt_new(MPI_Aint, block_count);
   int i;
@@ -1084,7 +1084,6 @@ s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths, MPI_Aint*
   new_t->base.unserialize = &unserialize_struct;
   new_t->base.subtype_free = &free_struct;
   new_t->base.subtype_use = &use_struct;
- //TODO : add a custom function for each time to clean these 
   new_t->block_lengths= xbt_new(int, block_count);
   new_t->block_indices= xbt_new(MPI_Aint, block_count);
   new_t->old_types=  xbt_new(MPI_Datatype, block_count);
@@ -1095,10 +1094,7 @@ s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths, MPI_Aint*
     new_t->old_types[i]=old_types[i];
     smpi_datatype_use(new_t->old_types[i]);
   }
-  //new_t->block_lengths = block_lengths;
-  //new_t->block_indices = block_indices;
   new_t->block_count = block_count;
-  //new_t->old_types = old_types;
   return new_t;
 }
 
index a546474..98d3ae5 100644 (file)
@@ -142,8 +142,6 @@ int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datat
   MPI_Win recv_win = win->connected_wins[target_rank];
 
   void* recv_addr = (void*) ( ((char*)recv_win->base) + target_disp * recv_win->disp_unit);
-  smpi_datatype_use(origin_datatype);
-  smpi_datatype_use(target_datatype);
   XBT_DEBUG("Entering MPI_Put to %d", target_rank);
 
   if(target_rank != smpi_comm_rank(win->comm)){
@@ -179,8 +177,6 @@ int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datat
   MPI_Win send_win = win->connected_wins[target_rank];
 
   void* send_addr = (void*)( ((char*)send_win->base) + target_disp * send_win->disp_unit);
-  smpi_datatype_use(origin_datatype);
-  smpi_datatype_use(target_datatype);
   XBT_DEBUG("Entering MPI_Get from %d", target_rank);
 
   if(target_rank != smpi_comm_rank(win->comm)){
@@ -225,9 +221,6 @@ int smpi_mpi_accumulate( void *origin_addr, int origin_count, MPI_Datatype origi
   void* recv_addr = (void*)( ((char*)recv_win->base) + target_disp * recv_win->disp_unit);
   XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank);
 
-  smpi_datatype_use(origin_datatype);
-  smpi_datatype_use(target_datatype);
-
     //prepare send_request
     MPI_Request sreq = smpi_rma_send_init(origin_addr, origin_count, origin_datatype,
         smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), RMA_TAG+3, win->comm, op);