From: genaud Date: Wed, 15 Jul 2009 15:35:40 +0000 (+0000) Subject: examples to demonstrate bugs in sendrecv X-Git-Tag: SVN~1142 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ab6013dda2f80b21aff83d529738b048e508828f examples to demonstrate bugs in sendrecv git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6506 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/smpi/pingpong.c b/examples/smpi/pingpong.c new file mode 100644 index 0000000000..092423bb78 --- /dev/null +++ b/examples/smpi/pingpong.c @@ -0,0 +1,60 @@ +/* A simple example pingpong pogram to test MPI_Send and MPI_Recv */ + + + +#include +#include + +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 [%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 index 0000000000..7b11ce0bac --- /dev/null +++ b/examples/smpi/sendrecv.c @@ -0,0 +1,26 @@ +#include "mpi.h" +#include + +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; +} diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index 6c7952eab5..8057078215 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -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); - +#define DEBUG_STEPH #ifdef DEBUG_STEPH print_req( request ); //@@ #endif diff --git a/src/smpi/smpi_mpi.c b/src/smpi/smpi_mpi.c index 3d60c4d404..4934045cba 100644 --- a/src/smpi/smpi_mpi.c +++ b/src/smpi/smpi_mpi.c @@ -206,20 +206,32 @@ smpi_mpi_request_t rrequest; 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); + printf("[%d] isend request src=%d -> dst=%d (retval=%d)\n",rank,rank,dest,retval); smpi_mpi_isend(srequest); + + + //retval = MPI_Isend( sendbuf, sendcount, sendtype, dest, sendtag, MPI_COMM_WORLD, &srequest); /* recv */ retval = smpi_create_request(recvbuf, recvcount, recvtype, - source,rank,recvtag, + source, rank,recvtag, comm, &rrequest); + printf("[%d] irecv request src=%d -> dst=%d (retval=%d)\n",rank,source,rank,retval); smpi_mpi_irecv(rrequest); + //retval = MPI_Irecv( recvbuf, recvcount, recvtype, source, recvtag, MPI_COMM_WORLD, &rrequest); + + 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); + printf("[%d] irecv request src=%d -> dst=%d tag=%d COMPLETED (retval=%d)\n",rank,source,rank,recvtag,retval); return(retval); }