Skip to content

Commit bc791a2

Browse files
committed
Release the temporary arrays for nonblocking collectives.
If Fortran and C integers have different sizes we allocate the storage for the C objects in the MPI API. For nonblocking functions we need to release these temporary arrays upon completion of the request in order to avoid memory leaks. Signed-off-by: George Bosilca <[email protected]> Conflicts: ompi/mca/coll/base/coll_base_util.c ompi/mpi/fortran/mpif-h/ialltoallw_f.c
1 parent 6a6ff56 commit bc791a2

21 files changed

+322
-122
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ static void release_objs_callback(struct ompi_coll_base_nbc_request_t *request)
132132
OBJ_RELEASE(request->data.objs.objs[0]);
133133
request->data.objs.objs[0] = NULL;
134134
}
135-
if (NULL != request->data.objs.objs[1]) {
136-
OBJ_RELEASE(request->data.objs.objs[1]);
137-
request->data.objs.objs[1] = NULL;
135+
for(int i = 0; i < OMPI_REQ_NB_RELEASE_ARRAYS; i++ ) {
136+
if (NULL == request->data.release_arrays[i])
137+
break;
138+
free(request->data.release_arrays[i]);
139+
request->data.release_arrays[i] = NULL;
138140
}
139141
}
140142

ompi/mca/coll/base/coll_base_util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

ompi/mca/coll/hcoll/coll_hcoll_rte.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ static void* get_coll_handle(void)
346346
}
347347
ompi_req = (ompi_coll_base_nbc_request_t *)item;
348348
OMPI_REQUEST_INIT(&ompi_req->super,false);
349-
ompi_req->super.req_complete_cb = NULL;
350-
ompi_req->super.req_complete_cb_data = NULL;
351-
ompi_req->super.req_status.MPI_ERROR = MPI_SUCCESS;
352-
ompi_req->super.req_state = OMPI_REQUEST_ACTIVE;
353-
ompi_req->super.req_free = request_free;
354-
ompi_req->super.req_type = OMPI_REQUEST_COLL;
355-
ompi_req->data.objs.objs[0] = NULL;
356-
ompi_req->data.objs.objs[1] = NULL;
349+
ompi_req->super.req_complete_cb = NULL;
350+
ompi_req->super.req_complete_cb_data = NULL;
351+
ompi_req->super.req_status.MPI_ERROR = MPI_SUCCESS;
352+
ompi_req->super.req_state = OMPI_REQUEST_ACTIVE;
353+
ompi_req->super.req_free = request_free;
354+
ompi_req->super.req_type = OMPI_REQUEST_COLL;
355+
ompi_req->refcounted.data.objs.objs[0] = NULL;
356+
ompi_req->refcounted.data.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
}

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

Lines changed: 15 additions & 3 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_gatherv_init_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
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(recvcounts);
8182
OMPI_ARRAY_NAME_DECL(displs);
8283

@@ -101,5 +102,16 @@ void ompi_gatherv_init_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
101102
OMPI_FINT_2_INT(*root),
102103
c_comm, c_info, &c_request);
103104
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
104-
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
105+
if (MPI_SUCCESS == c_ierr) {
106+
*request = PMPI_Request_c2f(c_request);
107+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
108+
if (recvcounts != OMPI_ARRAY_NAME_CONVERT(recvcounts)) {
109+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
110+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(displs);
111+
}
112+
nb_request->data.release_arrays[idx] = NULL;
113+
} else {
114+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
115+
OMPI_ARRAY_FINT_2_INT_CLEANUP(displs);
116+
}
105117
}

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

Lines changed: 14 additions & 4 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
@@ -75,7 +76,7 @@ void ompi_iallgatherv_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
7576
MPI_Comm c_comm;
7677
MPI_Datatype c_sendtype, c_recvtype;
7778
MPI_Request c_request;
78-
int size, ierr_c;
79+
int size, idx = 0, ierr_c;
7980
OMPI_ARRAY_NAME_DECL(recvcounts);
8081
OMPI_ARRAY_NAME_DECL(displs);
8182

@@ -102,6 +103,15 @@ void ompi_iallgatherv_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
102103
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(ierr_c);
103104
if (MPI_SUCCESS == ierr_c) *request = PMPI_Request_c2f(c_request);
104105

105-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
106-
OMPI_ARRAY_FINT_2_INT_CLEANUP(displs);
106+
if ( REQUEST_COMPLETE(c_request)) {
107+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
108+
OMPI_ARRAY_FINT_2_INT_CLEANUP(displs);
109+
} else {
110+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
111+
if (recvcounts != OMPI_ARRAY_NAME_CONVERT(recvcounts)) {
112+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
113+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(displs);
114+
}
115+
nb_request->data.release_arrays[idx] = NULL;
116+
}
107117
}

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

Lines changed: 18 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
@@ -75,7 +76,7 @@ void ompi_ialltoallv_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispls,
7576
MPI_Comm c_comm;
7677
MPI_Datatype c_sendtype, c_recvtype;
7778
MPI_Request c_request;
78-
int size, c_ierr;
79+
int size, idx = 0, c_ierr;
7980
OMPI_ARRAY_NAME_DECL(sendcounts);
8081
OMPI_ARRAY_NAME_DECL(sdispls);
8182
OMPI_ARRAY_NAME_DECL(recvcounts);
@@ -106,8 +107,19 @@ void ompi_ialltoallv_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispls,
106107
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
107108
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
108109

109-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
110-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
111-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
112-
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
110+
if ( REQUEST_COMPLETE(c_request)) {
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);
115+
} else {
116+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
117+
if (sendcounts != OMPI_ARRAY_NAME_CONVERT(sendcounts)) {
118+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sendcounts);
119+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(sdispls);
120+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(recvcounts);
121+
nb_request->data.release_arrays[idx++] = OMPI_ARRAY_NAME_CONVERT(rdispls);
122+
}
123+
nb_request->data.release_arrays[idx] = NULL;
124+
}
113125
}

0 commit comments

Comments
 (0)