Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fixed several problems in gather, gatherv, allgather, allgatherv, and scan
[simgrid.git] / src / smpi / smpi_base.c
index 16eaeb9..4f5c96e 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "private.h"
 #include "xbt/time.h"
+#include "mc/mc.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi,
                                 "Logging specific to SMPI (base)");
@@ -23,10 +24,9 @@ static int match_recv(void* a, void* b) {
    MPI_Request ref = (MPI_Request)a;
    MPI_Request req = (MPI_Request)b;
 
-   xbt_assert0(ref, "Cannot match recv against null reference");
-   xbt_assert0(req, "Cannot match recv against null request");
-   return req->comm == ref->comm
-          && (ref->src == MPI_ANY_SOURCE || req->src == ref->src)
+   xbt_assert(ref, "Cannot match recv against null reference");
+   xbt_assert(req, "Cannot match recv against null request");
+   return (ref->src == MPI_ANY_SOURCE || req->src == ref->src)
           && (ref->tag == MPI_ANY_TAG || req->tag == ref->tag);
 }
 
@@ -34,10 +34,9 @@ static int match_send(void* a, void* b) {
    MPI_Request ref = (MPI_Request)a;
    MPI_Request req = (MPI_Request)b;
 
-   xbt_assert0(ref, "Cannot match send against null reference");
-   xbt_assert0(req, "Cannot match send against null request");
-   return req->comm == ref->comm
-          && (req->src == MPI_ANY_SOURCE || req->src == ref->src)
+   xbt_assert(ref, "Cannot match send against null reference");
+   xbt_assert(req, "Cannot match send against null request");
+   return (req->src == MPI_ANY_SOURCE || req->src == ref->src)
           && (req->tag == MPI_ANY_TAG || req->tag == ref->tag);
 }
 
@@ -88,7 +87,7 @@ void smpi_mpi_start(MPI_Request request)
 {
   smx_rdv_t mailbox;
 
-  xbt_assert0(!request->action,
+  xbt_assert(!request->action,
               "Cannot (re)start a non-finished communication");
   if(request->flags & RECV) {
     print_request("New recv", request);
@@ -98,7 +97,7 @@ void smpi_mpi_start(MPI_Request request)
     print_request("New send", request);
     mailbox = smpi_process_remote_mailbox(request->dst);
     request->action = SIMIX_req_comm_isend(mailbox, request->size, -1.0,
-                                           request->buf, request->size, &match_send, request);
+                                           request->buf, request->size, &match_send, request, 0);
 #ifdef HAVE_TRACING
     SIMIX_req_set_category (request->action, TRACE_internal_smpi_get_category());
 #endif
@@ -211,9 +210,8 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
     status->MPI_SOURCE = req->src;
     status->MPI_TAG = req->tag;
     status->MPI_ERROR = MPI_SUCCESS;
-    status->count = SIMIX_req_comm_get_dst_buff_size(req->action);
+    status->count = req->size;
   }
-  SIMIX_req_comm_destroy(req->action);
   print_request("Finishing", req);
   if(req->flags & NON_PERSISTENT) {
     smpi_mpi_request_free(request);
@@ -286,7 +284,7 @@ int smpi_mpi_waitany(int count, MPI_Request requests[],
     comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
     map = xbt_new(int, count);
     size = 0;
-    DEBUG0("Wait for one of");
+    XBT_DEBUG("Wait for one of");
     for(i = 0; i < count; i++) {
       if(requests[i] != MPI_REQUEST_NULL) {
         print_request("   ", requests[i]);
@@ -313,16 +311,19 @@ void smpi_mpi_waitall(int count, MPI_Request requests[],
   MPI_Status stat;
   MPI_Status *pstat = status == MPI_STATUS_IGNORE ? MPI_STATUS_IGNORE : &stat;
 
-  c = count;
-  while(c > 0) {
-    index = smpi_mpi_waitany(count, requests, pstat);
-    if(index == MPI_UNDEFINED) {
-      break;
+  for(c = 0; c < count; c++) {
+    if(MC_IS_ENABLED) {
+      smpi_mpi_wait(&requests[c], pstat);
+      index = c;
+    } else {
+      index = smpi_mpi_waitany(count, requests, pstat);
+      if(index == MPI_UNDEFINED) {
+        break;
+      }
     }
     if(status != MPI_STATUS_IGNORE) {
-      memcpy(&status[index], pstat, sizeof *pstat);
+      memcpy(&status[index], pstat, sizeof(*pstat));
     }
-    c--;
   }
 }
 
@@ -397,7 +398,7 @@ void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
                       MPI_Datatype recvtype, int root, MPI_Comm comm)
 {
   int system_tag = 666;
-  int rank, size, src, index, sendsize;
+  int rank, size, src, index, sendsize, recvsize;
   MPI_Request *requests;
 
   rank = smpi_comm_rank(comm);
@@ -407,8 +408,9 @@ void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm);
   } else {
     sendsize = smpi_datatype_size(sendtype);
+    recvsize = smpi_datatype_size(recvtype);
     // Local copy from root
-    memcpy(&((char *) recvbuf)[displs[root]], sendbuf,
+    memcpy(&((char *) recvbuf)[displs[root] * recvsize], sendbuf,
            sendcount * sendsize * sizeof(char));
     // Receive buffers from senders
     requests = xbt_new(MPI_Request, size - 1);
@@ -416,7 +418,7 @@ void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     for(src = 0; src < size; src++) {
       if(src != root) {
         requests[index] =
-            smpi_irecv_init(&((char *) recvbuf)[displs[src]],
+            smpi_irecv_init(&((char *) recvbuf)[displs[src] * recvsize],
                             recvcounts[src], recvtype, src, system_tag,
                             comm);
         index++;
@@ -481,7 +483,7 @@ void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
   sendsize = smpi_datatype_size(sendtype);
   recvsize = smpi_datatype_size(recvtype);
   // Local copy from self
-  memcpy(&((char *) recvbuf)[displs[rank]], sendbuf,
+  memcpy(&((char *) recvbuf)[displs[rank] * recvsize], sendbuf,
          sendcount * sendsize * sizeof(char));
   // Send buffers to others;
   requests = xbt_new(MPI_Request, 2 * (size - 1));
@@ -493,7 +495,7 @@ void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
                           comm);
       index++;
       requests[index] =
-          smpi_irecv_init(&((char *) recvbuf)[displs[other]],
+          smpi_irecv_init(&((char *) recvbuf)[displs[other] * recvsize],
                           recvcounts[other], recvtype, other, system_tag,
                           comm);
       index++;
@@ -562,7 +564,7 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
     sendsize = smpi_datatype_size(sendtype);
     recvsize = smpi_datatype_size(recvtype);
     // Local copy from root
-    memcpy(recvbuf, &((char *) sendbuf)[displs[root]],
+    memcpy(recvbuf, &((char *) sendbuf)[displs[root] * sendsize],
            recvcount * recvsize * sizeof(char));
     // Send buffers to receivers
     requests = xbt_new(MPI_Request, size - 1);
@@ -570,7 +572,7 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
     for(dst = 0; dst < size; dst++) {
       if(dst != root) {
         requests[index] =
-            smpi_isend_init(&((char *) sendbuf)[displs[dst]],
+            smpi_isend_init(&((char *) sendbuf)[displs[dst] * sendsize],
                             sendcounts[dst], sendtype, dst, system_tag,
                             comm);
         index++;
@@ -726,7 +728,7 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
       smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
     }
   }
-  for(index = 0; index < size - 1; index++) {
+  for(index = 0; index < rank; index++) {
     xbt_free(tmpbufs[index]);
   }
   xbt_free(tmpbufs);