From: Martin Quinson Date: Wed, 1 Feb 2017 01:10:12 +0000 (+0100) Subject: don't malloc tons of dynars in mpi_waitany X-Git-Tag: v3_15~500 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e553a03ec20f531e48fab905d2034551c58a683f don't malloc tons of dynars in mpi_waitany --- diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index ef7a555307..d9796b51f9 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -66,6 +66,7 @@ SG_BEGIN_DECL() typedef struct xbt_dynar_s *xbt_dynar_t; XBT_PUBLIC(xbt_dynar_t) xbt_dynar_new(const unsigned long elm_size, void_f_pvoid_t const free_f); +XBT_PUBLIC(void) xbt_dynar_init(xbt_dynar_t dynar, const unsigned long elmsize, void_f_pvoid_t const free_f); XBT_PUBLIC(void) xbt_dynar_free(xbt_dynar_t * dynar); XBT_PUBLIC(void) xbt_dynar_free_voidp(void *dynar); XBT_PUBLIC(void) xbt_dynar_free_container(xbt_dynar_t * dynar); diff --git a/src/smpi/smpi_base.cpp b/src/smpi/smpi_base.cpp index 24f5645c72..9bae432bef 100644 --- a/src/smpi/smpi_base.cpp +++ b/src/smpi/smpi_base.cpp @@ -837,7 +837,7 @@ void smpi_mpi_wait(MPI_Request * request, MPI_Status * status) int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status * status) { - xbt_dynar_t comms; + s_xbt_dynar_t comms; // Keep it on stack to save some extra mallocs int i; int size = 0; int index = MPI_UNDEFINED; @@ -845,14 +845,14 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status * status) if(count > 0) { // Wait for a request to complete - comms = xbt_dynar_new(sizeof(smx_activity_t), nullptr); + xbt_dynar_init(&comms, sizeof(smx_activity_t), nullptr); map = xbt_new(int, count); XBT_DEBUG("Wait for one of %d", count); for(i = 0; i < count; i++) { if (requests[i] != MPI_REQUEST_NULL && !(requests[i]->flags & PREPARED) && !(requests[i]->flags & FINISHED)) { if (requests[i]->action != nullptr) { XBT_DEBUG("Waiting any %p ", requests[i]); - xbt_dynar_push(comms, &requests[i]->action); + xbt_dynar_push(&comms, &requests[i]->action); map[size] = i; size++; }else{ @@ -867,7 +867,7 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status * status) } } if(size > 0) { - i = simcall_comm_waitany(comms, -1); + i = simcall_comm_waitany(&comms, -1); // not MPI_UNDEFINED, as this is a simix return code if (i != -1) { @@ -878,7 +878,6 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status * status) } } xbt_free(map); - xbt_dynar_free(&comms); } if (index==MPI_UNDEFINED) diff --git a/src/xbt/dynar.cpp b/src/xbt/dynar.cpp index 44ce025c6e..375b1c5ad6 100644 --- a/src/xbt/dynar.cpp +++ b/src/xbt/dynar.cpp @@ -102,6 +102,18 @@ xbt_dynar_t xbt_dynar_new(const unsigned long elmsize, void_f_pvoid_t const free return dynar; } +/** @brief Initialize a dynar structure that was not malloc'ed + * This can be useful to keep temporary dynars on the stack + */ +void xbt_dynar_init(xbt_dynar_t dynar, const unsigned long elmsize, void_f_pvoid_t const free_f) +{ + dynar->size = 0; + dynar->used = 0; + dynar->elmsize = elmsize; + dynar->data = nullptr; + dynar->free_f = free_f; +} + /** @brief Destructor of the structure not touching to the content * * \param dynar poor victim