Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
init request real_src
[simgrid.git] / src / smpi / smpi_base.c
index ec16dbe..5ad3fa7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -219,6 +219,7 @@ static MPI_Request build_request(void *buf, int count,
   request->flags = flags;
   request->detached = 0;
   request->detached_sender = NULL;
+  request->real_src = 0;
 
   request->truncated = 0;
   request->real_size = 0;
@@ -320,6 +321,7 @@ void smpi_mpi_start(MPI_Request request)
   if(request->flags & PREPARED)request->flags &= ~PREPARED;
   if(request->flags & RECV) {
     print_request("New recv", request);
+    //FIXME: if receive is posted with a large size, but send is smaller, mailboxes may not match !
     if (request->size < sg_cfg_get_int("smpi/async_small_thres"))
       mailbox = smpi_process_mailbox_small();
     else
@@ -345,7 +347,7 @@ void smpi_mpi_start(MPI_Request request)
     #ifdef HAVE_TRACING
       int rank = smpi_process_index();
       if (TRACE_smpi_view_internals()) {
-        TRACE_smpi_send(rank, rank, receiver);
+        TRACE_smpi_send(rank, rank, receiver,request->size);
       }
     #endif
 /*    if(receiver == MPI_UNDEFINED) {*/
@@ -421,7 +423,6 @@ void smpi_mpi_startall(int count, MPI_Request * requests)
 
 void smpi_mpi_request_free(MPI_Request * request)
 {
-
   if((*request) != MPI_REQUEST_NULL){
     (*request)->refcount--;
     if((*request)->refcount<0) xbt_die("wrong refcount");
@@ -444,7 +445,7 @@ MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
 {
   MPI_Request request =
     build_request(buf==MPI_BOTTOM ? (void*)0 : buf , count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
-                  comm, NON_PERSISTENT | SEND | PREPARED);
+                  comm, NON_PERSISTENT | ISEND | SEND | PREPARED);
 
   return request;
 }
@@ -677,6 +678,8 @@ int smpi_mpi_testall(int count, MPI_Request requests[],
     if(requests[i]!= MPI_REQUEST_NULL){
       if (smpi_mpi_test(&requests[i], pstat)!=1){
         flag=0;
+      }else{
+          requests[i]=MPI_REQUEST_NULL;
       }
     }else{
       smpi_empty_status(pstat);
@@ -753,7 +756,7 @@ void smpi_mpi_wait(MPI_Request * request, MPI_Status * status)
     simcall_comm_wait((*request)->action, -1.0);
   }
   finish_wait(request, status);
-
+  request=MPI_REQUEST_NULL;
   // FIXME for a detached send, finish_wait is not called:
 }
 
@@ -882,7 +885,7 @@ int smpi_mpi_testsome(int incount, MPI_Request requests[], int *indices,
   for(i = 0; i < incount; i++) {
     if((requests[i] != MPI_REQUEST_NULL)) {
       if(smpi_mpi_test(&requests[i], pstat)) {
-         indices[count] = i;
+         indices[i] = 1;
          count++;
          if(status != MPI_STATUSES_IGNORE) {
            status[i] = *pstat;
@@ -1110,8 +1113,10 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     // FIXME: check for errors
     smpi_datatype_extent(sendtype, &lb, &sendext);
     // Local copy from root
-    smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
-                       sendcount, sendtype, recvbuf, recvcount, recvtype);
+    if(recvbuf!=MPI_IN_PLACE){
+        smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
+                           sendcount, sendtype, recvbuf, recvcount, recvtype);
+    }
     // Send buffers to receivers
     requests = xbt_new(MPI_Request, size - 1);
     index = 0;
@@ -1149,8 +1154,10 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
     // FIXME: check for errors
     smpi_datatype_extent(sendtype, &lb, &sendext);
     // Local copy from root
-    smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
+    if(recvbuf!=MPI_IN_PLACE){
+      smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
                        sendtype, recvbuf, recvcount, recvtype);
+    }
     // Send buffers to receivers
     requests = xbt_new(MPI_Request, size - 1);
     index = 0;
@@ -1179,9 +1186,11 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
   MPI_Request *requests;
   void **tmpbufs;
 
+
   char* sendtmpbuf = (char*) sendbuf;
   if( sendbuf == MPI_IN_PLACE ) {
-      sendtmpbuf = (char *)recvbuf;
+    sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+    smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
   }
 
   rank = smpi_comm_rank(comm);
@@ -1234,6 +1243,10 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
     }
     xbt_free(tmpbufs);
     xbt_free(requests);
+
+    if( sendbuf == MPI_IN_PLACE ) {
+      xbt_free(sendtmpbuf);
+    }
   }
 }
 
@@ -1366,7 +1379,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
       smpi_mpi_wait(&(requests[other]), MPI_STATUS_IGNORE);
       if(index < rank) {
           if(recvbuf_is_empty){
-            smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype);
+            smpi_datatype_copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
             recvbuf_is_empty=0;
           }else smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
       }