From db17323a11a3089f492c2cae1be7913673689d5c Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 12 Jul 2013 18:27:59 +0200 Subject: [PATCH] change some behaviors with MPI_IN_PLACE --- src/smpi/colls/smpi_mpich_selector.c | 7 +++++++ src/smpi/colls/smpi_openmpi_selector.c | 5 +++++ src/smpi/smpi_base.c | 19 ++++++++++++++----- src/smpi/smpi_pmpi.c | 25 +++++++------------------ 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/smpi/colls/smpi_mpich_selector.c b/src/smpi/colls/smpi_mpich_selector.c index 2c6ab2dc40..a2a44ae779 100644 --- a/src/smpi/colls/smpi_mpich_selector.c +++ b/src/smpi/colls/smpi_mpich_selector.c @@ -426,6 +426,8 @@ int smpi_coll_tuned_reduce_scatter_mpich( void *sbuf, void *rbuf, int comm_size, i; size_t total_message_size; + if(sbuf==rbuf)sbuf=MPI_IN_PLACE; //restore MPI_IN_PLACE as these algos handle it + XBT_DEBUG("smpi_coll_tuned_reduce_scatter_mpich"); comm_size = smpi_comm_size(comm); @@ -689,6 +691,11 @@ int smpi_coll_tuned_scatter_mpich(void *sbuf, int scount, int root, MPI_Comm comm ) { + if(smpi_comm_rank(comm)!=root){ + sbuf=xbt_malloc(rcount*smpi_datatype_get_extent(rdtype)); + scount=rcount; + sdtype=rdtype; + } return smpi_coll_tuned_scatter_ompi_binomial (sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm); diff --git a/src/smpi/colls/smpi_openmpi_selector.c b/src/smpi/colls/smpi_openmpi_selector.c index e092bdd693..23196335e9 100644 --- a/src/smpi/colls/smpi_openmpi_selector.c +++ b/src/smpi/colls/smpi_openmpi_selector.c @@ -596,6 +596,11 @@ int smpi_coll_tuned_scatter_ompi(void *sbuf, int scount, if ((communicator_size > small_comm_size) && (block_size < small_block_size)) { + if(rank!=root){ + sbuf=xbt_malloc(rcount*smpi_datatype_get_extent(rdtype)); + scount=rcount; + sdtype=rdtype; + } return smpi_coll_tuned_scatter_ompi_binomial (sbuf, scount, sdtype, rbuf, rcount, rdtype, root, comm); diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index 04f665f30c..88e93074d0 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -421,7 +421,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"); @@ -1110,8 +1109,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 +1150,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 +1182,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 +1239,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); + } } } diff --git a/src/smpi/smpi_pmpi.c b/src/smpi/smpi_pmpi.c index 8feabeee1b..7859738e24 100644 --- a/src/smpi/smpi_pmpi.c +++ b/src/smpi/smpi_pmpi.c @@ -1865,9 +1865,9 @@ int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) { retval = MPI_ERR_TYPE; } else { - - if(recvbuf==MPI_IN_PLACE){ - recvcount=0; + if (recvbuf == MPI_IN_PLACE) { + recvtype=sendtype; + recvcount=sendcount; } mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm); @@ -1902,11 +1902,10 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs, || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) { retval = MPI_ERR_TYPE; } else { - - if(recvbuf==MPI_IN_PLACE){ - recvcount=0; + if (recvbuf == MPI_IN_PLACE) { + recvtype=sendtype; + recvcount=sendcounts[smpi_comm_rank(comm)]; } - smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm); retval = MPI_SUCCESS; @@ -1937,17 +1936,7 @@ int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, retval = MPI_ERR_ARG; } else { - char* sendtmpbuf = (char*) sendbuf; - if( sendbuf == MPI_IN_PLACE ) { - sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype)); - smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype); - } - - mpi_coll_reduce_fun(sendtmpbuf, recvbuf, count, datatype, op, root, comm); - - if( sendbuf == MPI_IN_PLACE ) { - xbt_free(sendtmpbuf); - } + mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm); retval = MPI_SUCCESS; } -- 2.20.1