Skip to content

Commit 5b1cc1d

Browse files
committed
mpi: retain datatypes in non blocking collectives
MPI standard states user MPI_Datatype(s) can be free'd after a call to a non blocking collective and before the non-blockin collective completes. Retain user (only) MPI_Datatype(s) when the non blocking call is invoked, and set a request callback so they are free'd when the MPI_Request completes.
1 parent ec7f940 commit 5b1cc1d

17 files changed

+171
-18
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ struct retain_op_data {
3636
ompi_datatype_t *datatype;
3737
};
3838

39+
struct retain_datatypes_data {
40+
ompi_request_complete_fn_t req_complete_cb;
41+
void *req_complete_cb_data;
42+
ompi_datatype_t *stype;
43+
ompi_datatype_t *rtype;
44+
};
45+
46+
struct retain_datatypes_w_data {
47+
ompi_request_complete_fn_t req_complete_cb;
48+
void *req_complete_cb_data;
49+
int count;
50+
ompi_datatype_t *types[];
51+
};
52+
3953
int ompi_coll_base_sendrecv_nonzero_actual( void* sendbuf, size_t scount,
4054
ompi_datatype_t* sdatatype,
4155
int dest, int stag,
@@ -94,7 +108,7 @@ int ompi_coll_base_sendrecv_nonzero_actual( void* sendbuf, size_t scount,
94108
return (err);
95109
}
96110

97-
static int release_callback(struct ompi_request_t *request) {
111+
static int release_op_callback(struct ompi_request_t *request) {
98112
struct retain_op_data * p = (struct retain_op_data *)request->req_complete_cb_data;
99113
int rc = OMPI_SUCCESS;
100114
assert (NULL != p);
@@ -132,8 +146,104 @@ int ompi_coll_base_retain_op( ompi_request_t *request, ompi_op_t *op,
132146
}
133147
p->req_complete_cb = request->req_complete_cb;
134148
p->req_complete_cb_data = request->req_complete_cb_data;
135-
request->req_complete_cb = release_callback;
149+
request->req_complete_cb = release_op_callback;
136150
request->req_complete_cb_data = p;
137151
}
138152
return OMPI_SUCCESS;
139153
}
154+
155+
static int release_datatypes_callback(struct ompi_request_t *request) {
156+
struct retain_datatypes_data * p = (struct retain_datatypes_data *)request->req_complete_cb_data;
157+
int rc = OMPI_SUCCESS;
158+
assert (NULL != p);
159+
if (NULL != p->req_complete_cb) {
160+
request->req_complete_cb = p->req_complete_cb;
161+
request->req_complete_cb_data = p->req_complete_cb_data;
162+
rc = request->req_complete_cb(request);
163+
}
164+
if (NULL != p->stype) {
165+
OBJ_RELEASE(p->stype);
166+
}
167+
if (NULL != p->rtype) {
168+
OBJ_RELEASE(p->rtype);
169+
}
170+
free(p);
171+
return rc;
172+
}
173+
174+
int ompi_coll_base_retain_datatypes( ompi_request_t *request, ompi_datatype_t *stype,
175+
ompi_datatype_t *rtype) {
176+
bool retain = NULL != stype && !ompi_datatype_is_predefined(stype);
177+
retain |= NULL != rtype && !ompi_datatype_is_predefined(rtype);
178+
if (OPAL_UNLIKELY(retain)) {
179+
struct retain_datatypes_data *p = (struct retain_datatypes_data *)calloc(1, sizeof(struct retain_datatypes_data));
180+
if (OPAL_UNLIKELY(NULL == p)) {
181+
return OMPI_ERR_OUT_OF_RESOURCE;
182+
}
183+
if (NULL != stype && !ompi_datatype_is_predefined(stype)) {
184+
OBJ_RETAIN(stype);
185+
p->stype = stype;
186+
}
187+
if (NULL != rtype && !ompi_datatype_is_predefined(rtype)) {
188+
OBJ_RETAIN(rtype);
189+
p->rtype = rtype;
190+
}
191+
p->req_complete_cb = request->req_complete_cb;
192+
p->req_complete_cb_data = request->req_complete_cb_data;
193+
request->req_complete_cb = release_datatypes_callback;
194+
request->req_complete_cb_data = p;
195+
}
196+
return OMPI_SUCCESS;
197+
}
198+
199+
static int release_datatypes_w_callback(struct ompi_request_t *request) {
200+
struct retain_datatypes_w_data * p = (struct retain_datatypes_w_data *)request->req_complete_cb_data;
201+
int rc = OMPI_SUCCESS;
202+
assert (NULL != p);
203+
if (NULL != p->req_complete_cb) {
204+
request->req_complete_cb = p->req_complete_cb;
205+
request->req_complete_cb_data = p->req_complete_cb_data;
206+
rc = request->req_complete_cb(request);
207+
}
208+
for (int i=0; i<p->count; i++) {
209+
OBJ_RELEASE(p->types[i]);
210+
}
211+
free(p);
212+
return rc;
213+
}
214+
215+
int ompi_coll_base_retain_datatypes_w( ompi_request_t *request, int count,
216+
ompi_datatype_t *const stypes[], ompi_datatype_t *const rtypes[]) {
217+
int datatypes = 0;
218+
for (int i=0; i<count; i++) {
219+
if (NULL != stypes[i] && !ompi_datatype_is_predefined(stypes[i])) {
220+
datatypes++;
221+
}
222+
if (NULL != rtypes[i] && !ompi_datatype_is_predefined(rtypes[i])) {
223+
datatypes++;
224+
}
225+
}
226+
if (OPAL_UNLIKELY(0 < datatypes)) {
227+
struct retain_datatypes_w_data *p = (struct retain_datatypes_w_data *)calloc(1, sizeof(struct retain_datatypes_data)+(datatypes-1)*sizeof(ompi_datatype_t *));
228+
if (OPAL_UNLIKELY(NULL == p)) {
229+
return OMPI_ERR_OUT_OF_RESOURCE;
230+
}
231+
datatypes = 0;
232+
for (int i=0; i<count; i++) {
233+
if (NULL != stypes[i] && !ompi_datatype_is_predefined(stypes[i])) {
234+
p->types[datatypes++] = stypes[i];
235+
OBJ_RETAIN(stypes[i]);
236+
}
237+
if (NULL != rtypes[i] && !ompi_datatype_is_predefined(rtypes[i])) {
238+
p->types[datatypes++] = rtypes[i];
239+
OBJ_RETAIN(rtypes[i]);
240+
}
241+
}
242+
p->req_complete_cb = request->req_complete_cb;
243+
p->req_complete_cb_data = request->req_complete_cb_data;
244+
request->req_complete_cb = release_datatypes_w_callback;
245+
request->req_complete_cb_data = p;
246+
}
247+
return OMPI_SUCCESS;
248+
}
249+

ompi/mca/coll/base/coll_base_util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,12 @@ ompi_coll_base_sendrecv( void* sendbuf, size_t scount, ompi_datatype_t* sdatatyp
7373

7474
int ompi_coll_base_retain_op( ompi_request_t *request, ompi_op_t *op,
7575
ompi_datatype_t *type);
76+
77+
int ompi_coll_base_retain_datatypes( ompi_request_t *request, ompi_datatype_t *stype,
78+
ompi_datatype_t *rtype);
79+
80+
int ompi_coll_base_retain_datatypes_w( ompi_request_t *request, int count,
81+
ompi_datatype_t *const stypes[],
82+
ompi_datatype_t *const rtypes[]);
7683
END_C_DECLS
7784
#endif /* MCA_COLL_BASE_UTIL_EXPORT_H */

ompi/mpi/c/iallgather.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2012 Oak Ridge National Laboratory. All rights reserved.
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2015 Research Organization for Information Science
17+
* Copyright (c) 2015-2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -99,6 +100,7 @@ int MPI_Iallgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
99100
err = comm->c_coll.coll_iallgather(sendbuf, sendcount, sendtype,
100101
recvbuf, recvcount, recvtype, comm,
101102
request, comm->c_coll.coll_iallgather_module);
103+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
102104

103105
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
104106
}

ompi/mpi/c/iallgatherv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
1515
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2015 Research Organization for Information Science
17+
* Copyright (c) 2015-2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -123,6 +124,7 @@ int MPI_Iallgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
123124
recvbuf, recvcounts, displs,
124125
recvtype, comm, request,
125126
comm->c_coll.coll_iallgatherv_module);
127+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
126128
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
127129
}
128130

ompi/mpi/c/ialltoall.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2012 Oak Ridge National Laboratory. All rights reserved.
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2014-2015 Research Organization for Information Science
17+
* Copyright (c) 2014-2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -103,5 +104,6 @@ int MPI_Ialltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
103104
err = comm->c_coll.coll_ialltoall(sendbuf, sendcount, sendtype,
104105
recvbuf, recvcount, recvtype, comm,
105106
request, comm->c_coll.coll_ialltoall_module);
107+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
106108
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
107109
}

ompi/mpi/c/ialltoallv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2014-2015 Research Organization for Information Science
16+
* Copyright (c) 2014-2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -30,6 +30,7 @@
3030
#include "ompi/communicator/communicator.h"
3131
#include "ompi/errhandler/errhandler.h"
3232
#include "ompi/datatype/ompi_datatype.h"
33+
#include "ompi/mca/coll/base/coll_base_util.h"
3334
#include "ompi/memchecker.h"
3435

3536
#if OMPI_BUILD_MPI_PROFILING
@@ -132,6 +133,7 @@ int MPI_Ialltoallv(const void *sendbuf, const int sendcounts[], const int sdispl
132133
err = comm->c_coll.coll_ialltoallv(sendbuf, sendcounts, sdispls,
133134
sendtype, recvbuf, recvcounts, rdispls,
134135
recvtype, comm, request, comm->c_coll.coll_ialltoallv_module);
136+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
135137
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
136138
}
137139

ompi/mpi/c/ialltoallw.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2014-2015 Research Organization for Information Science
16+
* Copyright (c) 2014-2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -30,6 +30,7 @@
3030
#include "ompi/communicator/communicator.h"
3131
#include "ompi/errhandler/errhandler.h"
3232
#include "ompi/datatype/ompi_datatype.h"
33+
#include "ompi/mca/coll/base/coll_base_util.h"
3334
#include "ompi/memchecker.h"
3435

3536
#if OMPI_BUILD_MPI_PROFILING
@@ -129,6 +130,10 @@ int MPI_Ialltoallw(const void *sendbuf, const int sendcounts[], const int sdispl
129130
sendtypes, recvbuf, recvcounts,
130131
rdispls, recvtypes, comm, request,
131132
comm->c_coll.coll_ialltoallw_module);
133+
ompi_coll_base_retain_datatypes_w(*request,
134+
OMPI_COMM_IS_INTER(comm)?ompi_comm_remote_size(comm):ompi_comm_size(comm),
135+
sendtypes,
136+
recvtypes);
132137
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
133138
}
134139

ompi/mpi/c/ibcast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2012 Oak Rigde National Laboratory. All rights reserved.
3-
* Copyright (c) 2015 Research Organization for Information Science
2+
* Copyright (c) 2012 Oak Rigde National Laboratory. All rights reserved.
3+
* Copyright (c) 2015-2016 Research Organization for Information Science
44
* and Technology (RIST). All rights reserved.
55
* $COPYRIGHT$
66
*
@@ -16,6 +16,7 @@
1616
#include "ompi/communicator/communicator.h"
1717
#include "ompi/errhandler/errhandler.h"
1818
#include "ompi/datatype/ompi_datatype.h"
19+
#include "ompi/mca/coll/base/coll_base_util.h"
1920
#include "ompi/memchecker.h"
2021

2122
#if OMPI_BUILD_MPI_PROFILING
@@ -80,5 +81,6 @@ int MPI_Ibcast(void *buffer, int count, MPI_Datatype datatype,
8081
err = comm->c_coll.coll_ibcast(buffer, count, datatype, root, comm,
8182
request,
8283
comm->c_coll.coll_ibcast_module);
84+
ompi_coll_base_retain_datatypes(*request, datatype, NULL);
8385
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
8486
}

ompi/mpi/c/igather.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1717
* reserved.
18-
* Copyright (c) 2015 Research Organization for Information Science
18+
* Copyright (c) 2015-2016 Research Organization for Information Science
1919
* and Technology (RIST). All rights reserved.
2020
* $COPYRIGHT$
2121
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -170,5 +171,6 @@ int MPI_Igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
170171
err = comm->c_coll.coll_igather(sendbuf, sendcount, sendtype, recvbuf,
171172
recvcount, recvtype, root, comm, request,
172173
comm->c_coll.coll_igather_module);
174+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
173175
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
174176
}

ompi/mpi/c/igatherv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2006-2012 Cisco Systems, Inc. All rights reserved.
1414
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2016 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* $COPYRIGHT$
1919
*
@@ -29,6 +29,7 @@
2929
#include "ompi/communicator/communicator.h"
3030
#include "ompi/errhandler/errhandler.h"
3131
#include "ompi/datatype/ompi_datatype.h"
32+
#include "ompi/mca/coll/base/coll_base_util.h"
3233
#include "ompi/memchecker.h"
3334

3435
#if OMPI_BUILD_MPI_PROFILING
@@ -195,5 +196,6 @@ int MPI_Igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
195196
err = comm->c_coll.coll_igatherv(sendbuf, sendcount, sendtype, recvbuf,
196197
recvcounts, displs, recvtype,
197198
root, comm, request, comm->c_coll.coll_igatherv_module);
199+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
198200
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
199201
}

ompi/mpi/c/ineighbor_allgather.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2012 Oak Rigde National Laboratory. All rights reserved.
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2015 Research Organization for Information Science
17+
* Copyright (c) 2015-2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -100,6 +101,7 @@ int MPI_Ineighbor_allgather(const void *sendbuf, int sendcount, MPI_Datatype sen
100101
err = comm->c_coll.coll_ineighbor_allgather(sendbuf, sendcount, sendtype, recvbuf,
101102
recvcount, recvtype, comm, request,
102103
comm->c_coll.coll_ineighbor_allgather_module);
104+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
103105

104106
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
105107
}

ompi/mpi/c/ineighbor_allgatherv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
1515
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2015 Research Organization for Information Science
17+
* Copyright (c) 2015-2016 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -31,6 +31,7 @@
3131
#include "ompi/communicator/communicator.h"
3232
#include "ompi/errhandler/errhandler.h"
3333
#include "ompi/datatype/ompi_datatype.h"
34+
#include "ompi/mca/coll/base/coll_base_util.h"
3435
#include "ompi/memchecker.h"
3536

3637
#if OMPI_BUILD_MPI_PROFILING
@@ -123,6 +124,7 @@ int MPI_Ineighbor_allgatherv(const void *sendbuf, int sendcount, MPI_Datatype se
123124
recvbuf, (int *) recvcounts, (int *) displs,
124125
recvtype, comm, request,
125126
comm->c_coll.coll_ineighbor_allgatherv_module);
127+
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
126128
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
127129
}
128130

0 commit comments

Comments
 (0)