Skip to content

Commit 918fe01

Browse files
authored
Merge pull request #10288 from awlauria/awlauria_nb_leaks
Release the temporary arrays for nonblocking collectives.
2 parents e292636 + a3c06e0 commit 918fe01

22 files changed

+377
-159
lines changed

ompi/include/ompi/memchecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static inline int memchecker_request(MPI_Request *request)
308308
opal_memchecker_base_isdefined (&(*request)->req_status._ucount, sizeof(size_t));
309309
#endif
310310

311-
opal_memchecker_base_isdefined ((void*)&(*request)->req_complete, sizeof(volatile _Bool));
311+
opal_memchecker_base_isdefined ((void*)&(*request)->req_complete, sizeof(volatile void*));
312312
opal_memchecker_base_isdefined ((void*)&(*request)->req_state, sizeof(volatile ompi_request_state_t));
313313
opal_memchecker_base_isdefined (&(*request)->req_persistent, sizeof(_Bool));
314314
opal_memchecker_base_isdefined (&(*request)->req_f_to_c_index, sizeof(int));

ompi/mca/coll/base/coll_base_util.c

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2020 The University of Tennessee and The University
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -127,14 +127,29 @@ int ompi_rounddown(int num, int factor)
127127
return num * factor; /* floor(num / factor) * factor */
128128
}
129129

130-
static void release_objs_callback(struct ompi_coll_base_nbc_request_t *request) {
131-
if (NULL != request->data.objs.objs[0]) {
132-
OBJ_RELEASE(request->data.objs.objs[0]);
133-
request->data.objs.objs[0] = NULL;
130+
/**
131+
* Release all objects and arrays stored into the nbc_request.
132+
* The release_arrays are temporary memory to stored the values
133+
* converted from Fortran, and should dissapear in same time as the
134+
* request itself.
135+
*/
136+
static void
137+
release_objs_callback(struct ompi_coll_base_nbc_request_t *request)
138+
{
139+
if (NULL != request->data.refcounted.objs.objs[0]) {
140+
OBJ_RELEASE(request->data.refcounted.objs.objs[0]);
141+
request->data.refcounted.objs.objs[0] = NULL;
134142
}
135-
if (NULL != request->data.objs.objs[1]) {
136-
OBJ_RELEASE(request->data.objs.objs[1]);
137-
request->data.objs.objs[1] = NULL;
143+
if (NULL != request->data.refcounted.objs.objs[1]) {
144+
OBJ_RELEASE(request->data.refcounted.objs.objs[1]);
145+
request->data.refcounted.objs.objs[1] = NULL;
146+
}
147+
for(int i = 0; i < OMPI_REQ_NB_RELEASE_ARRAYS; i++ ) {
148+
if (NULL == request->data.release_arrays[i]) {
149+
break;
150+
}
151+
free(request->data.release_arrays[i]);
152+
request->data.release_arrays[i] = NULL;
138153
}
139154
}
140155

@@ -168,12 +183,12 @@ int ompi_coll_base_retain_op( ompi_request_t *req, ompi_op_t *op,
168183
}
169184
if (!ompi_op_is_intrinsic(op)) {
170185
OBJ_RETAIN(op);
171-
request->data.op.op = op;
186+
request->data.refcounted.op.op = op;
172187
retain = true;
173188
}
174189
if (!ompi_datatype_is_predefined(type)) {
175190
OBJ_RETAIN(type);
176-
request->data.op.datatype = type;
191+
request->data.refcounted.op.datatype = type;
177192
retain = true;
178193
}
179194
if (OPAL_UNLIKELY(retain)) {
@@ -207,12 +222,12 @@ int ompi_coll_base_retain_datatypes( ompi_request_t *req, ompi_datatype_t *stype
207222
}
208223
if (NULL != stype && !ompi_datatype_is_predefined(stype)) {
209224
OBJ_RETAIN(stype);
210-
request->data.types.stype = stype;
225+
request->data.refcounted.types.stype = stype;
211226
retain = true;
212227
}
213228
if (NULL != rtype && !ompi_datatype_is_predefined(rtype)) {
214229
OBJ_RETAIN(rtype);
215-
request->data.types.rtype = rtype;
230+
request->data.refcounted.types.rtype = rtype;
216231
retain = true;
217232
}
218233
if (OPAL_UNLIKELY(retain)) {
@@ -237,21 +252,21 @@ static void release_vecs_callback(ompi_coll_base_nbc_request_t *request) {
237252
} else {
238253
scount = rcount = OMPI_COMM_IS_INTER(comm)?ompi_comm_remote_size(comm):ompi_comm_size(comm);
239254
}
240-
if (NULL != request->data.vecs.stypes) {
255+
if (NULL != request->data.refcounted.vecs.stypes) {
241256
for (int i=0; i<scount; i++) {
242-
if (NULL != request->data.vecs.stypes[i]) {
243-
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.vecs.stypes[i]);
257+
if (NULL != request->data.refcounted.vecs.stypes[i]) {
258+
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.refcounted.vecs.stypes[i]);
244259
}
245260
}
246-
request->data.vecs.stypes = NULL;
261+
request->data.refcounted.vecs.stypes = NULL;
247262
}
248-
if (NULL != request->data.vecs.rtypes) {
263+
if (NULL != request->data.refcounted.vecs.rtypes) {
249264
for (int i=0; i<rcount; i++) {
250-
if (NULL != request->data.vecs.rtypes[i]) {
251-
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.vecs.rtypes[i]);
265+
if (NULL != request->data.refcounted.vecs.rtypes[i]) {
266+
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.refcounted.vecs.rtypes[i]);
252267
}
253268
}
254-
request->data.vecs.rtypes = NULL;
269+
request->data.refcounted.vecs.rtypes = NULL;
255270
}
256271
}
257272

@@ -304,8 +319,8 @@ int ompi_coll_base_retain_datatypes_w( ompi_request_t *req,
304319
}
305320
}
306321
if (OPAL_UNLIKELY(retain)) {
307-
request->data.vecs.stypes = (ompi_datatype_t **) stypes;
308-
request->data.vecs.rtypes = (ompi_datatype_t **) rtypes;
322+
request->data.refcounted.vecs.stypes = (ompi_datatype_t **) stypes;
323+
request->data.refcounted.vecs.rtypes = (ompi_datatype_t **) rtypes;
309324
if (req->req_persistent) {
310325
request->cb.req_free = req->req_free;
311326
req->req_free = free_vecs_callback;
@@ -319,15 +334,16 @@ int ompi_coll_base_retain_datatypes_w( ompi_request_t *req,
319334
return OMPI_SUCCESS;
320335
}
321336

322-
static void nbc_req_cons(ompi_coll_base_nbc_request_t *req)
337+
static void nbc_req_constructor(ompi_coll_base_nbc_request_t *req)
323338
{
324339
req->cb.req_complete_cb = NULL;
325340
req->req_complete_cb_data = NULL;
326-
req->data.objs.objs[0] = NULL;
327-
req->data.objs.objs[1] = NULL;
341+
req->data.refcounted.objs.objs[0] = NULL;
342+
req->data.refcounted.objs.objs[1] = NULL;
343+
req->data.release_arrays[0] = NULL;
328344
}
329345

330-
OBJ_CLASS_INSTANCE(ompi_coll_base_nbc_request_t, ompi_request_t, nbc_req_cons, NULL);
346+
OBJ_CLASS_INSTANCE(ompi_coll_base_nbc_request_t, ompi_request_t, nbc_req_constructor, NULL);
331347

332348
/* File reading functions */
333349
static void skiptonewline (FILE *fptr, int *fileline)

ompi/mca/coll/base/coll_base_util.h

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2020 The University of Tennessee and The University
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
@@ -34,6 +34,13 @@
3434

3535
BEGIN_C_DECLS
3636

37+
/**
38+
* The largest array we need to track collective temporary memory. Right now
39+
* the record is for ialltoallw, for the array of send and receive types,
40+
* count and displacements.
41+
*/
42+
#define OMPI_REQ_NB_RELEASE_ARRAYS 7
43+
3744
/**
3845
* Request structure to be returned by non-blocking
3946
* collective operations.
@@ -45,22 +52,25 @@ struct ompi_coll_base_nbc_request_t {
4552
ompi_request_free_fn_t req_free;
4653
} cb;
4754
void *req_complete_cb_data;
48-
union {
49-
struct {
50-
ompi_op_t *op;
51-
ompi_datatype_t *datatype;
52-
} op;
53-
struct {
54-
ompi_datatype_t *stype;
55-
ompi_datatype_t *rtype;
56-
} types;
57-
struct {
58-
opal_object_t *objs[2];
59-
} objs;
60-
struct {
61-
ompi_datatype_t * const *stypes;
62-
ompi_datatype_t * const *rtypes;
63-
} vecs;
55+
struct {
56+
union {
57+
struct {
58+
ompi_op_t *op;
59+
ompi_datatype_t *datatype;
60+
} op;
61+
struct {
62+
ompi_datatype_t *stype;
63+
ompi_datatype_t *rtype;
64+
} types;
65+
struct {
66+
opal_object_t *objs[2];
67+
} objs;
68+
struct {
69+
ompi_datatype_t * const *stypes;
70+
ompi_datatype_t * const *rtypes;
71+
} vecs;
72+
} refcounted;
73+
void* release_arrays[OMPI_REQ_NB_RELEASE_ARRAYS];
6474
} data;
6575
};
6676

ompi/mca/coll/hcoll/coll_hcoll_rte.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ static void* get_coll_handle(void)
352352
ompi_req->super.req_state = OMPI_REQUEST_ACTIVE;
353353
ompi_req->super.req_free = request_free;
354354
ompi_req->super.req_type = OMPI_REQUEST_COLL;
355-
ompi_req->data.objs.objs[0] = NULL;
356-
ompi_req->data.objs.objs[1] = NULL;
355+
ompi_req->data.refcounted.objs.objs[0] = NULL;
356+
ompi_req->data.refcounted.objs.objs[1] = NULL;
357357
return (void *)ompi_req;
358358
}
359359

ompi/mpi/fortran/mpif-h/allgatherv_init_f.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -23,6 +23,7 @@
2323

2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
26+
#include "ompi/mca/coll/base/coll_base_util.h"
2627

2728
#if OMPI_BUILD_MPI_PROFILING
2829
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -76,7 +77,7 @@ void ompi_allgatherv_init_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendty
7677
MPI_Datatype c_sendtype, c_recvtype;
7778
MPI_Request c_request;
7879
MPI_Info c_info;
79-
int size, ierr_c;
80+
int size, idx = 0, ierr_c;
8081
OMPI_ARRAY_NAME_DECL(recvcounts);
8182
OMPI_ARRAY_NAME_DECL(displs);
8283

@@ -102,8 +103,16 @@ void ompi_allgatherv_init_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendty
102103
c_recvtype, c_comm, c_info, &c_request);
103104

104105
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(ierr_c);
105-
if (MPI_SUCCESS == ierr_c) *request = PMPI_Request_c2f(c_request);
106-
107-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
108-
OMPI_ARRAY_FINT_2_INT_CLEANUP(displs);
106+
if (MPI_SUCCESS == ierr_c) {
107+
*request = PMPI_Request_c2f(c_request);
108+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
109+
if (recvcounts != OMPI_ARRAY_NAME_CONVERT(recvcounts)) {
110+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
111+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(displs);
112+
}
113+
nb_request->data.release_arrays[idx] = NULL;
114+
} else {
115+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
116+
OMPI_ARRAY_FINT_2_INT_CLEANUP(displs);
117+
}
109118
}

ompi/mpi/fortran/mpif-h/alltoallv_init_f.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -23,6 +23,7 @@
2323

2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
26+
#include "ompi/mca/coll/base/coll_base_util.h"
2627

2728
#if OMPI_BUILD_MPI_PROFILING
2829
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -76,7 +77,7 @@ void ompi_alltoallv_init_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispl
7677
MPI_Datatype c_sendtype, c_recvtype;
7778
MPI_Info c_info;
7879
MPI_Request c_request;
79-
int size, c_ierr;
80+
int size, idx = 0, c_ierr;
8081
OMPI_ARRAY_NAME_DECL(sendcounts);
8182
OMPI_ARRAY_NAME_DECL(sdispls);
8283
OMPI_ARRAY_NAME_DECL(recvcounts);
@@ -106,10 +107,20 @@ void ompi_alltoallv_init_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispl
106107
OMPI_ARRAY_NAME_CONVERT(rdispls),
107108
c_recvtype, c_comm, c_info, &c_request);
108109
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
109-
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
110-
111-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
112-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
113-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
114-
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
110+
if (MPI_SUCCESS == c_ierr) {
111+
*request = PMPI_Request_c2f(c_request);
112+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
113+
if (sendcounts != OMPI_ARRAY_NAME_CONVERT(sendcounts)) {
114+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sendcounts);
115+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sdispls);
116+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
117+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(rdispls);
118+
}
119+
nb_request->data.release_arrays[idx] = NULL;
120+
} else {
121+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
122+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
123+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
124+
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
125+
}
115126
}

ompi/mpi/fortran/mpif-h/alltoallw_init_f.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2021 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -23,7 +23,7 @@
2323

2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
26-
#include "ompi/communicator/communicator.h"
26+
#include "ompi/mca/coll/base/coll_base_util.h"
2727

2828
#if OMPI_BUILD_MPI_PROFILING
2929
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -78,7 +78,7 @@ void ompi_alltoallw_init_f(char *sendbuf, MPI_Fint *sendcounts,
7878
MPI_Datatype *c_sendtypes = NULL, *c_recvtypes;
7979
MPI_Info c_info;
8080
MPI_Request c_request;
81-
int size, c_ierr;
81+
int size, idx = 0, c_ierr;
8282
OMPI_ARRAY_NAME_DECL(sendcounts);
8383
OMPI_ARRAY_NAME_DECL(sdispls);
8484
OMPI_ARRAY_NAME_DECL(recvcounts);
@@ -117,14 +117,30 @@ void ompi_alltoallw_init_f(char *sendbuf, MPI_Fint *sendcounts,
117117
OMPI_ARRAY_NAME_CONVERT(rdispls),
118118
c_recvtypes, c_comm, c_info, &c_request);
119119
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
120-
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
121-
122-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
123-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
124-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
125-
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
126-
if (NULL != c_sendtypes) {
127-
free(c_sendtypes);
120+
if (MPI_SUCCESS == c_ierr) {
121+
*request = PMPI_Request_c2f(c_request);
122+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
123+
nb_request->data.release_arrays[idx++] = c_recvtypes;
124+
if (recvcounts != OMPI_ARRAY_NAME_CONVERT(recvcounts)) {
125+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
126+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(rdispls);
127+
}
128+
if (NULL != c_sendtypes) {
129+
nb_request->data.release_arrays[idx++] = c_sendtypes;
130+
if (sendcounts != OMPI_ARRAY_NAME_CONVERT(sendcounts)) {
131+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sendcounts);
132+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sdispls);
133+
}
134+
}
135+
nb_request->data.release_arrays[idx] = NULL;
136+
} else {
137+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
138+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
139+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
140+
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
141+
if (NULL != c_sendtypes) {
142+
free(c_sendtypes);
143+
}
144+
free(c_recvtypes);
128145
}
129-
free(c_recvtypes);
130146
}

0 commit comments

Comments
 (0)