From: Arnaud Giersch Date: Thu, 5 Dec 2019 12:40:33 +0000 (+0100) Subject: Declare variables and allocate memory when needed (plug a memory leak). X-Git-Tag: v3.25~336^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/62e402534114158ba1e6ed29f9766b3e248cb394 Declare variables and allocate memory when needed (plug a memory leak). --- diff --git a/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp b/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp index db5e79aaba..37008f75d5 100644 --- a/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-ompi-basic-linear.cpp @@ -22,22 +22,16 @@ int alltoallv__ompi_basic_linear(const void *sbuf, const int *scounts, const int MPI_Datatype rdtype, MPI_Comm comm) { - int i, size, rank; - char *psnd, *prcv; - int nreqs; - ptrdiff_t sext, rext; - MPI_Request* preq; - size = comm->size(); - rank = comm->rank(); - MPI_Request* ireqs = new MPI_Request[size * 2]; + int size = comm->size(); + int rank = comm->rank(); XBT_DEBUG("coll:tuned:alltoallv_intra_basic_linear rank %d", rank); - sext = sdtype->get_extent(); - rext = rdtype->get_extent(); + ptrdiff_t sext = sdtype->get_extent(); + ptrdiff_t rext = rdtype->get_extent(); /* Simple optimization - handle send to self first */ - psnd = ((char*)sbuf) + (sdisps[rank] * sext); - prcv = ((char*)rbuf) + (rdisps[rank] * rext); + char* psnd = ((char*)sbuf) + (sdisps[rank] * sext); + char* prcv = ((char*)rbuf) + (rdisps[rank] * rext); if (0 != scounts[rank]) { Datatype::copy(psnd, scounts[rank], sdtype, prcv, rcounts[rank], rdtype); } @@ -48,11 +42,12 @@ int alltoallv__ompi_basic_linear(const void *sbuf, const int *scounts, const int } /* Now, initiate all send/recv to/from others. */ - nreqs = 0; - preq = ireqs; + MPI_Request* ireqs = new MPI_Request[size * 2]; + int nreqs = 0; + MPI_Request* preq = ireqs; /* Post all receives first */ - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (i == rank) { continue; } @@ -65,7 +60,7 @@ int alltoallv__ompi_basic_linear(const void *sbuf, const int *scounts, const int } /* Now post all sends */ - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (i == rank) { continue; } @@ -88,7 +83,7 @@ int alltoallv__ompi_basic_linear(const void *sbuf, const int *scounts, const int Request::waitall(nreqs, ireqs, MPI_STATUSES_IGNORE); /* Free the requests. */ - for (i = 0; i < nreqs; ++i) { + for (int i = 0; i < nreqs; ++i) { if (ireqs[i] != MPI_REQUEST_NULL) Request::unref(&ireqs[i]); }