From bf6ed47fe662e71174b6c034e66fbe176c390eb9 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Thu, 25 Oct 2012 17:55:58 +0200 Subject: [PATCH] correct some issues with MPI_Sendrecv_replace, to avoid segfaults. I should implement it more cleanly, to handle complex datatypes as well. For now they exit. --- src/smpi/smpi_pmpi.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/smpi/smpi_pmpi.c b/src/smpi/smpi_pmpi.c index f10a36f6a0..5f4e6a2eea 100644 --- a/src/smpi/smpi_pmpi.c +++ b/src/smpi/smpi_pmpi.c @@ -1152,16 +1152,24 @@ int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, MPI_Comm comm, MPI_Status * status) { //TODO: suboptimal implementation - // void *recvbuf; + void *recvbuf; int retval; + if ((datatype == MPI_DATATYPE_NULL)||(datatype->has_subtype==1)) { + retval = MPI_ERR_TYPE; + } else if (count < 0) { + retval = MPI_ERR_COUNT; + } else { + int size = smpi_datatype_size(datatype) * count; + recvbuf = xbt_new(char, size); + retval = + MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, + datatype, src, recvtag, comm, status); + if(retval==MPI_SUCCESS){ + memcpy(buf, recvbuf, size * sizeof(char)); + } + xbt_free(recvbuf); -// size = smpi_datatype_size(datatype) * count; -// recvbuf = xbt_new(char, size); - retval = - MPI_Sendrecv(buf, count, datatype, dst, sendtag, buf, count, - datatype, src, recvtag, comm, status); -/*memcpy(buf, recvbuf, size * sizeof(char)); - xbt_free(recvbuf);*/ + } return retval; } -- 2.20.1