Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement MPI_Keyval_create, MPI_Keyval_free, MPI_Attr_get, MPI_Attr_put, MPI_Attr_de...
[simgrid.git] / src / smpi / smpi_base.c
index 035c5ef..8398a13 100644 (file)
@@ -75,6 +75,8 @@ double smpi_wtime_sleep = 0.0;
 double smpi_iprobe_sleep = 1e-4;
 double smpi_test_sleep = 1e-4;
 
+xbt_dict_t smpi_keyvals = NULL;
+int keyval_id=MPI_TAG_UB+1;//avoid collisions
 
 // Methods used to parse and store the values for timing injections in smpi
 // These are taken from surf/network.c and generalized to have more factors
@@ -388,7 +390,8 @@ void smpi_mpi_start(MPI_Request request)
     smpi_comm_use(request->comm);
     request->action = simcall_comm_irecv(mailbox, request->buf,
                                          &request->real_size, &match_recv,
-                                         &smpi_comm_copy_buffer_callback,
+                                         !smpi_process_get_replaying()? &smpi_comm_copy_buffer_callback
+                                         : &smpi_comm_null_copy_buffer_callback,
                                          request, -1.0);
         XBT_DEBUG("recv simcall posted");
 
@@ -451,7 +454,7 @@ void smpi_mpi_start(MPI_Request request)
       request->refcount++;
       if(request->old_type->has_subtype == 0){
         oldbuf = request->buf;
-        if (!_xbt_replay_is_active() && oldbuf && request->size!=0){
+        if (!smpi_process_get_replaying() && oldbuf && request->size!=0){
           if((smpi_privatize_global_variables)
              && ((char*)request->buf >= start_data_exe)
              && ((char*)request->buf < start_data_exe + size_data_exe )){
@@ -474,7 +477,8 @@ void smpi_mpi_start(MPI_Request request)
                          buf, request->real_size,
                          &match_send,
                          &xbt_free_f, // how to free the userdata if a detached send fails
-                         &smpi_comm_copy_buffer_callback,
+                         !smpi_process_get_replaying()? &smpi_comm_copy_buffer_callback
+                         : &smpi_comm_null_copy_buffer_callback,
                          request,
                          // detach if msg size < eager/rdv switch limit
                          request->detached);
@@ -690,7 +694,7 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
     MPI_Datatype datatype = req->old_type;
 
     if((req->flags & ACCUMULATE) || (datatype->has_subtype == 1)){
-      if (!_xbt_replay_is_active()){
+      if (!smpi_process_get_replaying()){
         if( smpi_privatize_global_variables
             && ((char*)req->old_buf >= start_data_exe)
             && ((char*)req->old_buf < start_data_exe + size_data_exe )
@@ -1372,7 +1376,7 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
 
   char* sendtmpbuf = (char*) sendbuf;
   if( sendbuf == MPI_IN_PLACE ) {
-    sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+    sendtmpbuf = (char *)smpi_get_tmp_sendbuffer(count*smpi_datatype_get_extent(datatype));
     smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
   }
 
@@ -1403,7 +1407,7 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
       if(src != root) {
         // FIXME: possibly overkill we we have contiguous/noncontiguous data
         //  mapping...
-           if (!_xbt_replay_is_active())
+           if (!smpi_process_get_replaying())
           tmpbufs[index] = xbt_malloc(count * dataext);
            else
              tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
@@ -1433,7 +1437,7 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
     xbt_free(requests);
 
     if( sendbuf == MPI_IN_PLACE ) {
-      xbt_free(sendtmpbuf);
+      smpi_free_tmp_buffer(sendtmpbuf);
     }
   }
 }
@@ -1470,7 +1474,7 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
   for(other = 0; other < rank; other++) {
     // FIXME: possibly overkill we we have contiguous/noncontiguous data
     // mapping...
-    tmpbufs[index] = xbt_malloc(count * dataext);
+    tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
     requests[index] =
       smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
                       comm);
@@ -1505,7 +1509,7 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
     }
   }
   for(index = 0; index < rank; index++) {
-    xbt_free(tmpbufs[index]);
+    smpi_free_tmp_buffer(tmpbufs[index]);
   }
   for(index = 0; index < size-1; index++) {
     smpi_mpi_request_free(&requests[index]);
@@ -1536,7 +1540,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
   for(other = 0; other < rank; other++) {
     // FIXME: possibly overkill we we have contiguous/noncontiguous data
     // mapping...
-    tmpbufs[index] = xbt_malloc(count * dataext);
+    tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext);
     requests[index] =
       smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
                       comm);
@@ -1577,7 +1581,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
     }
   }
   for(index = 0; index < rank; index++) {
-    xbt_free(tmpbufs[index]);
+    smpi_free_tmp_buffer(tmpbufs[index]);
   }
   for(index = 0; index < size-1; index++) {
     smpi_mpi_request_free(&requests[index]);
@@ -1585,3 +1589,62 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
   xbt_free(tmpbufs);
   xbt_free(requests);
 }
+
+
+int smpi_keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state){
+
+  if(!smpi_keyvals)
+  smpi_keyvals = xbt_dict_new();
+  
+  smpi_key_elem value = (smpi_key_elem) xbt_new0(s_smpi_mpi_key_elem_t,1);
+  
+  value->copy_fn=copy_fn;
+  value->delete_fn=delete_fn;
+  
+  *keyval = keyval_id;
+  
+  xbt_dict_set(smpi_keyvals,(const char*)keyval,(void*)value, NULL);
+  keyval_id++;
+  return MPI_SUCCESS;
+}
+
+int smpi_keyval_free(int* keyval){
+  smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)keyval);
+  if(!elem)
+    return MPI_ERR_ARG;
+  xbt_dict_remove(smpi_keyvals, (const char*)keyval);
+  xbt_free(elem);
+  return MPI_SUCCESS;
+}
+
+int smpi_attr_delete(MPI_Comm comm, int keyval){
+  smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+  if(!elem)
+    return MPI_ERR_ARG;
+  if(elem->delete_fn!=MPI_NULL_DELETE_FN){
+    void * value;
+    int flag;
+    if(smpi_attr_get(comm, keyval, &value, &flag)==MPI_SUCCESS)
+      elem->delete_fn(comm, keyval, &value, &flag);
+  }  
+  return smpi_comm_attr_delete(comm, keyval);;
+}
+
+int smpi_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
+  smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+  if(!elem)
+    return MPI_ERR_ARG;
+  return smpi_comm_attr_get(comm, keyval, attr_value, flag);;
+}
+
+int smpi_attr_put(MPI_Comm comm, int keyval, void* attr_value){
+
+  if(!smpi_keyvals)
+  smpi_keyvals = xbt_dict_new();
+  
+  smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+  if(!elem )
+    return MPI_ERR_ARG;
+  return smpi_comm_attr_put(comm, keyval, attr_value);;
+}
+