Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename paje_event into PajeEvent (+cosmetics)
[simgrid.git] / src / smpi / smpi_pmpi.cpp
index 7569a88..a265c3f 100644 (file)
@@ -873,7 +873,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
   if (comm == MPI_COMM_NULL) {
     retval = MPI_ERR_COMM;
   } else if (src == MPI_PROC_NULL) {
-    smpi_empty_status(status);
+    Status::empty(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
   } else if (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0)){
@@ -1019,7 +1019,7 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
   } else if (!sendtype->is_valid() || !recvtype->is_valid()) {
     retval = MPI_ERR_TYPE;
   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
-    smpi_empty_status(status);
+    Status::empty(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval             = MPI_SUCCESS;
   }else if (dst >= comm->group()->size() || dst <0 ||
@@ -1095,7 +1095,7 @@ int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
     retval = MPI_ERR_ARG;
   } else if (*request == MPI_REQUEST_NULL) {
     *flag= true;
-    smpi_empty_status(status);
+    Status::empty(status);
     retval = MPI_SUCCESS;
   } else {
     int rank = ((*request)->comm() != MPI_COMM_NULL) ? smpi_process()->index() : -1;
@@ -1152,7 +1152,7 @@ int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
   } else if (comm == MPI_COMM_NULL) {
     retval = MPI_ERR_COMM;
   } else if (source == MPI_PROC_NULL) {
-    smpi_empty_status(status);
+    Status::empty(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
   } else {
@@ -1173,7 +1173,7 @@ int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* statu
     retval = MPI_ERR_COMM;
   } else if (source == MPI_PROC_NULL) {
     *flag=true;
-    smpi_empty_status(status);
+    Status::empty(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
   } else {
@@ -1190,7 +1190,7 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
 
   smpi_bench_end();
 
-  smpi_empty_status(status);
+  Status::empty(status);
 
   if (request == nullptr) {
     retval = MPI_ERR_ARG;
@@ -1410,6 +1410,10 @@ int PMPI_Barrier(MPI_Comm comm)
     TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
 
     Colls::barrier(comm);
+
+    //Barrier can be used to synchronize RMA calls. Finish all requests from comm before.
+    comm->finish_rma_calls();
+
     retval = MPI_SUCCESS;
 
     TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
@@ -2154,7 +2158,7 @@ int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
     } else if (status->count % size != 0) {
       return MPI_UNDEFINED;
     } else {
-      *count = smpi_mpi_get_count(status, datatype);
+      *count = Status::get_count(status, datatype);
       return MPI_SUCCESS;
     }
   }
@@ -2306,7 +2310,9 @@ int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int
   } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
     return MPI_ERR_ARG;
   } else{
-    new Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart);
+    Topo_Cart* topo = new Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart);
+    if(*comm_cart==MPI_COMM_NULL)
+      delete topo;
     return MPI_SUCCESS;
   }
 }
@@ -2409,6 +2415,8 @@ int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
     return MPI_ERR_ARG;
   }
   MPIR_Cart_Topology cart = topo->sub(remain_dims, comm_new);
+  if(*comm_new==MPI_COMM_NULL)
+      delete cart;
   if(cart==nullptr)
     return  MPI_ERR_ARG;
   return MPI_SUCCESS;
@@ -2676,6 +2684,43 @@ int PMPI_Win_wait(MPI_Win win){
   return retval;
 }
 
+int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win){
+  int retval = 0;
+  smpi_bench_end();
+  if (win == MPI_WIN_NULL) {
+    retval = MPI_ERR_WIN;
+  } else if (lock_type != MPI_LOCK_EXCLUSIVE && 
+             lock_type != MPI_LOCK_SHARED) {
+    retval = MPI_ERR_LOCKTYPE;
+  } else if (rank == MPI_PROC_NULL){ 
+    retval = MPI_SUCCESS;
+  } else {
+    int myrank = smpi_process()->index();
+    TRACE_smpi_collective_in(myrank, -1, __FUNCTION__, nullptr);
+    retval = win->lock(lock_type,rank,assert);
+    TRACE_smpi_collective_out(myrank, -1, __FUNCTION__);
+  }
+  smpi_bench_begin();
+  return retval;
+}
+
+int PMPI_Win_unlock(int rank, MPI_Win win){
+  int retval = 0;
+  smpi_bench_end();
+  if (win == MPI_WIN_NULL) {
+    retval = MPI_ERR_WIN;
+  } else if (rank == MPI_PROC_NULL){ 
+    retval = MPI_SUCCESS;
+  } else {
+    int myrank = smpi_process()->index();
+    TRACE_smpi_collective_in(myrank, -1, __FUNCTION__, nullptr);
+    retval = win->unlock(rank);
+    TRACE_smpi_collective_out(myrank, -1, __FUNCTION__);
+  }
+  smpi_bench_begin();
+  return retval;
+}
+
 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
   void *ptr = xbt_malloc(size);
   if(ptr==nullptr)