From 108c3fbdb1514ab48a94b6a174fae1422c6d1786 Mon Sep 17 00:00:00 2001 From: degomme Date: Wed, 3 Apr 2019 16:09:39 +0200 Subject: [PATCH] Don't fill array with garbage when it won't be needed. Thanks agier (and ubsan). --- src/smpi/bindings/smpi_f77_coll.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/smpi/bindings/smpi_f77_coll.cpp b/src/smpi/bindings/smpi_f77_coll.cpp index 64f89ddcba..761ed293c6 100644 --- a/src/smpi/bindings/smpi_f77_coll.cpp +++ b/src/smpi/bindings/smpi_f77_coll.cpp @@ -120,13 +120,14 @@ void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, in void mpi_alltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* old_sendtypes, void *recvbuf, int *recvcnts, int *rdispls, int* old_recvtypes, int* comm, int* ierr){ int size = simgrid::smpi::Comm::f2c(*comm)->size(); - sendbuf = static_cast( FORT_IN_PLACE(sendbuf)); MPI_Datatype* sendtypes = new MPI_Datatype[size]; MPI_Datatype* recvtypes = new MPI_Datatype[size]; for(int i=0; i< size; i++){ - sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]); + if(FORT_IN_PLACE(sendbuf)!=MPI_IN_PLACE) + sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]); recvtypes[i] = simgrid::smpi::Datatype::f2c(old_recvtypes[i]); } + sendbuf = static_cast( FORT_IN_PLACE(sendbuf)); *ierr = MPI_Alltoallw( sendbuf, sendcnts, sdispls, sendtypes, recvbuf, recvcnts, rdispls, recvtypes, simgrid::smpi::Comm::f2c(*comm)); delete[] sendtypes; @@ -301,13 +302,14 @@ void mpi_ialltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* old_send int *rdispls, int* old_recvtypes, int* comm, int* request, int* ierr){ MPI_Request req; int size = simgrid::smpi::Comm::f2c(*comm)->size(); - sendbuf = static_cast( FORT_IN_PLACE(sendbuf)); MPI_Datatype* sendtypes = new MPI_Datatype[size]; MPI_Datatype* recvtypes = new MPI_Datatype[size]; for(int i=0; i< size; i++){ - sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]); + if(FORT_IN_PLACE(sendbuf)!=MPI_IN_PLACE) + sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]); recvtypes[i] = simgrid::smpi::Datatype::f2c(old_recvtypes[i]); } + sendbuf = static_cast( FORT_IN_PLACE(sendbuf)); *ierr = MPI_Ialltoallw( sendbuf, sendcnts, sdispls, sendtypes, recvbuf, recvcnts, rdispls, recvtypes, simgrid::smpi::Comm::f2c(*comm), &req); if(*ierr == MPI_SUCCESS) { -- 2.20.1