From 5f30f31253629200892746ad9d086d03bbec48a5 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Mon, 8 Jul 2013 14:28:07 +0200 Subject: [PATCH] add a reference counter in order to avoide deleting MPI_Comm, and MPI_Group, too soon --- src/smpi/private.h | 2 ++ src/smpi/smpi_base.c | 3 +++ src/smpi/smpi_comm.c | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/smpi/private.h b/src/smpi/private.h index 9c40250103..1e2a3c2142 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -173,6 +173,8 @@ int smpi_comm_size(MPI_Comm comm); void smpi_comm_get_name(MPI_Comm comm, char* name, int* len); int smpi_comm_rank(MPI_Comm comm); MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key); +void smpi_comm_use(MPI_Comm comm); +void smpi_comm_unuse(MPI_Comm comm); MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index ee947cc2ef..df76fc2b0e 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -327,6 +327,7 @@ void smpi_mpi_start(MPI_Request request) // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later request->real_size=request->size; smpi_datatype_use(request->old_type); + smpi_comm_use(request->comm); request->action = simcall_comm_irecv(mailbox, request->buf, &request->real_size, &match_recv, request); //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0 @@ -375,6 +376,7 @@ void smpi_mpi_start(MPI_Request request) // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later request->real_size=request->size; smpi_datatype_use(request->old_type); + smpi_comm_use(request->comm); //if we are giving back the control to the user without waiting for completion, we have to inject timings double sleeptime =0.0; @@ -582,6 +584,7 @@ static void finish_wait(MPI_Request * request, MPI_Status * status) } if(req->detached == 0) free(req->buf); } + smpi_comm_unuse(req->comm); smpi_datatype_unuse(datatype); } diff --git a/src/smpi/smpi_comm.c b/src/smpi/smpi_comm.c index 611690a5e4..dac6ac341e 100644 --- a/src/smpi/smpi_comm.c +++ b/src/smpi/smpi_comm.c @@ -14,6 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, typedef struct s_smpi_mpi_communicator { MPI_Group group; + int refcount; } s_smpi_mpi_communicator_t; static int smpi_compare_rankmap(const void *a, const void *b) @@ -43,12 +44,14 @@ MPI_Comm smpi_comm_new(MPI_Group group) comm = xbt_new(s_smpi_mpi_communicator_t, 1); comm->group = group; smpi_group_use(comm->group); + smpi_comm_use(comm); return comm; } void smpi_comm_destroy(MPI_Comm comm) { - xbt_free(comm); + smpi_group_unuse(comm->group); + smpi_comm_unuse(comm); } MPI_Group smpi_comm_group(MPI_Comm comm) @@ -152,3 +155,15 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key) } return group_out ? smpi_comm_new(group_out) : MPI_COMM_NULL; } + +void smpi_comm_use(MPI_Comm comm){ + comm->refcount++; + smpi_group_use(comm->group); +} + +void smpi_comm_unuse(MPI_Comm comm){ + comm->refcount--; + smpi_group_unuse(comm->group); + if(comm->refcount==0) + xbt_free(comm); +} -- 2.20.1