Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
examples to demonstrate bugs in sendrecv
authorgenaud <genaud@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Jul 2009 15:35:40 +0000 (15:35 +0000)
committergenaud <genaud@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Jul 2009 15:35:40 +0000 (15:35 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6506 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/smpi/pingpong.c [new file with mode: 0644]
examples/smpi/sendrecv.c [new file with mode: 0644]
src/smpi/smpi_base.c
src/smpi/smpi_mpi.c

diff --git a/examples/smpi/pingpong.c b/examples/smpi/pingpong.c
new file mode 100644 (file)
index 0000000..092423b
--- /dev/null
@@ -0,0 +1,60 @@
+/* A simple example pingpong pogram to test MPI_Send and MPI_Recv */
+
+
+
+#include <stdio.h>
+#include <mpi.h>
+
+main(int argc, char *argv[])
+{
+         const int tag1 = 42, tag2= 43;           /* Message tag */
+         int rank; 
+         int size; 
+         int msg=99;
+         int err;
+         int pivot;
+         MPI_Status status;
+
+         err = MPI_Init(&argc, &argv); /* Initialize MPI */
+         if (err != MPI_SUCCESS) {
+                   printf("MPI initialization failed!\n");
+                   exit(1);
+         }
+         err = MPI_Comm_size(MPI_COMM_WORLD, &size); /* Get nr of tasks */
+         err = MPI_Comm_rank(MPI_COMM_WORLD, &rank);     /* Get id of this process */
+         if ( size < 2 ) {
+                   printf("run this program with exactly 2 processes (-np 2)\n");
+                   MPI_Finalize();         
+                   exit(0);
+         }
+        if (0 == rank) {
+                               printf("\n    *** Ping-pong test (MPI_Send/MPI_Recv) ***\n\n");
+         }
+
+        /* start pingpong tests between several pairs */
+         for (pivot=0; pivot<size-1; pivot++) {
+
+                   if (pivot == rank) {           
+                               printf("\n== pivot=%d : pingpong [%d] <--> [%d]\n",pivot,pivot,pivot+1);
+
+                               int dst= rank + 1;
+                               printf("[%d] About to send 1st message '%d' to process [%d] \n", rank,msg, dst);
+                               err = MPI_Send(&msg, 1, MPI_INT, dst, tag1, MPI_COMM_WORLD);
+
+                               err = MPI_Recv(&msg, 1, MPI_INT, dst, tag2, MPI_COMM_WORLD, &status);    /* Receive a message */
+                               printf("[%d] Received relpy message '%d' from process [%d] \n", rank,msg, dst);
+
+                   }
+                   if ((pivot+1) == rank) {
+                               int src= rank - 1;
+                               err = MPI_Recv(&msg, 1, MPI_INT, src, tag1, MPI_COMM_WORLD, &status);    /* Receive a message */
+                               printf("[%d] Received 1st message '%d' from process [%d] \n", rank,msg, src);
+                               msg++;
+                               printf("[%d] increment message's value to  '%d'\n", rank,msg);
+                               printf("[%d] About to send back message '%d' to process [%d] \n", rank,msg, src);
+                               err = MPI_Send(&msg, 1, MPI_INT, src, tag2, MPI_COMM_WORLD);
+                   }
+         }
+         err = MPI_Finalize();         /* Terminate MPI */
+         return 0;
+}
diff --git a/examples/smpi/sendrecv.c b/examples/smpi/sendrecv.c
new file mode 100644 (file)
index 0000000..7b11ce0
--- /dev/null
@@ -0,0 +1,26 @@
+#include "mpi.h"
+#include <stdio.h>
+int main(int argc, char *argv[])
+{
+#define TAG_RCV 998
+#define TAG_SND 999
+    int myid, numprocs, left, right;
+    int buffer[10], buffer2[10];
+    MPI_Request request;
+    MPI_Status status;
+    MPI_Init(&argc,&argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
+    right = (myid + 1) % numprocs;
+    left = myid - 1;
+    if (left < 0)
+        left = numprocs - 1;
+    MPI_Sendrecv(buffer, 10, MPI_INT, left, TAG_SND, buffer2, 10, MPI_INT, right, TAG_RCV, MPI_COMM_WORLD, &status);
+    MPI_Finalize();
+    return 0;
+}
index 6c7952e..8057078 100644 (file)
@@ -315,7 +315,7 @@ int smpi_mpi_wait(smpi_mpi_request_t request, smpi_mpi_status_t * status)
     retval = MPI_ERR_INTERN;
   } else {
     SIMIX_mutex_lock(request->mutex);
     retval = MPI_ERR_INTERN;
   } else {
     SIMIX_mutex_lock(request->mutex);
-
+#define DEBUG_STEPH
 #ifdef DEBUG_STEPH
     print_req( request );  //@@
 #endif
 #ifdef DEBUG_STEPH
     print_req( request );  //@@
 #endif
index 3d60c4d..4934045 100644 (file)
@@ -206,20 +206,32 @@ smpi_mpi_request_t rrequest;
          rank = smpi_mpi_comm_rank(comm);
 
          /* send */
          rank = smpi_mpi_comm_rank(comm);
 
          /* send */
-         retval = smpi_create_request(sendbuf, sendcount, sendtype, 
+         /* -------------*/
+           retval = smpi_create_request(sendbuf, sendcount, sendtype, 
                                rank,dest,sendtag, 
                                comm, &srequest);
                                rank,dest,sendtag, 
                                comm, &srequest);
+         printf("[%d] isend request src=%d -> dst=%d (retval=%d)\n",rank,rank,dest,retval);
          smpi_mpi_isend(srequest);
          smpi_mpi_isend(srequest);
+        
+         
+         //retval = MPI_Isend( sendbuf, sendcount, sendtype, dest, sendtag, MPI_COMM_WORLD, &srequest);
 
 
          /* recv */
          retval = smpi_create_request(recvbuf, recvcount, recvtype, 
 
 
          /* recv */
          retval = smpi_create_request(recvbuf, recvcount, recvtype, 
-                               source,rank,recvtag, 
+                               source, rank,recvtag, 
                                comm, &rrequest);
                                comm, &rrequest);
+         printf("[%d] irecv request src=%d -> dst=%d (retval=%d)\n",rank,source,rank,retval);
          smpi_mpi_irecv(rrequest);
 
          smpi_mpi_irecv(rrequest);
 
+         //retval = MPI_Irecv( recvbuf, recvcount, recvtype, source, recvtag, MPI_COMM_WORLD, &rrequest);
+
+
          smpi_mpi_wait(srequest, MPI_STATUS_IGNORE);
          smpi_mpi_wait(srequest, MPI_STATUS_IGNORE);
+         printf("[%d] isend request src=%d dst=%d tag=%d COMPLETED (retval=%d) \n",rank,rank,dest,sendtag,retval);
+
          smpi_mpi_wait(rrequest, MPI_STATUS_IGNORE);
          smpi_mpi_wait(rrequest, MPI_STATUS_IGNORE);
+         printf("[%d] irecv request src=%d -> dst=%d tag=%d COMPLETED (retval=%d)\n",rank,source,rank,recvtag,retval);
 
          return(retval);
 }
 
          return(retval);
 }