From 56ada3046889443aed9c69154cf10062873af785 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 4 Jun 2022 10:38:17 +0200 Subject: [PATCH] Use xbt_malloc that never return null. --- .../smpi/replay-ti-colls/replay-ti-colls.c | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/teshsuite/smpi/replay-ti-colls/replay-ti-colls.c b/teshsuite/smpi/replay-ti-colls/replay-ti-colls.c index ff300cb51a..c14b802d10 100644 --- a/teshsuite/smpi/replay-ti-colls/replay-ti-colls.c +++ b/teshsuite/smpi/replay-ti-colls/replay-ti-colls.c @@ -1,5 +1,4 @@ #include "mpi.h" -#include #include #include @@ -8,14 +7,13 @@ static void setup_recvbuf(int nprocs, int** recvbuf, int** displs, int** counts, int** rcounts) { - *recvbuf = malloc(BUFSIZE * nprocs * sizeof(int)); - assert(*recvbuf != NULL); + *recvbuf = xbt_malloc(BUFSIZE * nprocs * sizeof(int)); for (int i = 0; i < BUFSIZE * nprocs; i++) (*recvbuf)[i] = i; - *displs = malloc(nprocs * sizeof(int)); - *counts = malloc(nprocs * sizeof(int)); - *rcounts = malloc(nprocs * sizeof(int)); + *displs = xbt_malloc(nprocs * sizeof(int)); + *counts = xbt_malloc(nprocs * sizeof(int)); + *rcounts = xbt_malloc(nprocs * sizeof(int)); for (int i = 0; i < nprocs; i++) { (*displs)[i] = i * BUFSIZE; (*counts)[i] = BOUNDED(i); @@ -33,15 +31,15 @@ int main(int argc, char** argv) MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - int* sendbuf = malloc(BUFSIZE * nprocs * sizeof(int)); + int* sendbuf = xbt_malloc(BUFSIZE * nprocs * sizeof(int)); for (int i = 0; i < BUFSIZE * nprocs; i++) sendbuf[i] = rank; - int* alltoallvcounts = malloc(nprocs * sizeof(int)); + int* alltoallvcounts = xbt_malloc(nprocs * sizeof(int)); for (int i = 0; i < nprocs; i++) alltoallvcounts[i] = BOUNDED(i + rank); - int* dummy_buffer = malloc(sizeof(int)); + int* dummy_buffer = xbt_malloc(sizeof(int)); // initialize buffers with an invalid value (we want to trigger a valgrind error if they are used) int* recvbuf = dummy_buffer + 1; int* displs = dummy_buffer + 1; @@ -59,7 +57,7 @@ int main(int argc, char** argv) MPI_Scatterv(recvbuf, counts, displs, MPI_INT, sendbuf, BOUNDED(rank), MPI_INT, 0, MPI_COMM_WORLD); MPI_Reduce(sendbuf, recvbuf, BUFSIZE, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD); - free(dummy_buffer); + xbt_free(dummy_buffer); if (rank != 0) setup_recvbuf(nprocs, &recvbuf, &displs, &counts, &rcounts); @@ -80,12 +78,12 @@ int main(int argc, char** argv) MPI_Exscan(sendbuf, recvbuf, BUFSIZE, MPI_INT, MPI_MAX, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); - free(alltoallvcounts); - free(sendbuf); - free(recvbuf); - free(displs); - free(counts); - free(rcounts); + xbt_free(alltoallvcounts); + xbt_free(sendbuf); + xbt_free(recvbuf); + xbt_free(displs); + xbt_free(counts); + xbt_free(rcounts); MPI_Finalize(); return 0; -- 2.20.1