Skip to content

Commit 6799142

Browse files
committed
Use the req_flags to clean the temporary arrays of the Fortran API.
Also clean the count and disp arrays. Signed-off-by: George Bosilca <[email protected]>
1 parent ec98496 commit 6799142

File tree

3 files changed

+101
-58
lines changed

3 files changed

+101
-58
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,37 @@ int ompi_rounddown(int num, int factor)
127127
return num * factor; /* floor(num / factor) * factor */
128128
}
129129

130+
static inline
131+
release_other_arrays(struct ompi_coll_base_nbc_request_t *request)
132+
{
133+
if( OMPI_REQ_NB_RELEASE_DISPLS ) {
134+
assert(NULL != request->data.sdispls);
135+
free(request->data.sdispls);
136+
request->data.sdispls = NULL;
137+
assert(NULL != request->data.rdispls);
138+
free(request->data.rdispls);
139+
request->data.rdispls = NULL;
140+
}
141+
if( OMPI_REQ_NB_RELEASE_COUNTS ) {
142+
assert(NULL != request->data.scounts);
143+
free(request->data.scounts);
144+
request->data.scounts = NULL;
145+
assert(NULL != request->data.rcounts);
146+
free(request->data.rcounts);
147+
request->data.rcounts = NULL;
148+
}
149+
}
150+
130151
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;
152+
if (NULL != request->data.refcounted.objs.objs[0]) {
153+
OBJ_RELEASE(request->data.refcounted.objs.objs[0]);
154+
request->data.refcounted.objs.objs[0] = NULL;
134155
}
135-
if (NULL != request->data.objs.objs[1]) {
136-
OBJ_RELEASE(request->data.objs.objs[1]);
137-
request->data.objs.objs[1] = NULL;
156+
if (NULL != request->data.refcounted.objs.objs[1]) {
157+
OBJ_RELEASE(request->data.refcounted.objs.objs[1]);
158+
request->data.refcounted.objs.objs[1] = NULL;
138159
}
160+
release_other_arrays(request);
139161
}
140162

141163
static int complete_objs_callback(struct ompi_request_t *req) {
@@ -168,12 +190,12 @@ int ompi_coll_base_retain_op( ompi_request_t *req, ompi_op_t *op,
168190
}
169191
if (!ompi_op_is_intrinsic(op)) {
170192
OBJ_RETAIN(op);
171-
request->data.op.op = op;
193+
request->data.refcounted.op.op = op;
172194
retain = true;
173195
}
174196
if (!ompi_datatype_is_predefined(type)) {
175197
OBJ_RETAIN(type);
176-
request->data.op.datatype = type;
198+
request->data.refcounted.op.datatype = type;
177199
retain = true;
178200
}
179201
if (OPAL_UNLIKELY(retain)) {
@@ -207,12 +229,12 @@ int ompi_coll_base_retain_datatypes( ompi_request_t *req, ompi_datatype_t *stype
207229
}
208230
if (NULL != stype && !ompi_datatype_is_predefined(stype)) {
209231
OBJ_RETAIN(stype);
210-
request->data.types.stype = stype;
232+
request->data.refcounted.types.stype = stype;
211233
retain = true;
212234
}
213235
if (NULL != rtype && !ompi_datatype_is_predefined(rtype)) {
214236
OBJ_RETAIN(rtype);
215-
request->data.types.rtype = rtype;
237+
request->data.refcounted.types.rtype = rtype;
216238
retain = true;
217239
}
218240
if (OPAL_UNLIKELY(retain)) {
@@ -237,27 +259,27 @@ static void release_vecs_callback(ompi_coll_base_nbc_request_t *request) {
237259
} else {
238260
scount = rcount = OMPI_COMM_IS_INTER(comm)?ompi_comm_remote_size(comm):ompi_comm_size(comm);
239261
}
240-
if (NULL != request->data.vecs.stypes) {
262+
if (NULL != request->data.refcounted.vecs.stypes) {
241263
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]);
264+
if (NULL != request->data.refcounted.vecs.stypes[i]) {
265+
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.refcounted.vecs.stypes[i]);
244266
}
245267
}
246-
if( request->super.req_flags & OMPI_REQ_NB_RELEASE_DATA ) {
247-
free((void*)request->data.vecs.stypes);
268+
if( request->super.req_flags & OMPI_REQ_NB_RELEASE_DATATYPES ) {
269+
free((void*)request->data.refcounted.vecs.stypes);
248270
}
249-
request->data.vecs.stypes = NULL;
271+
request->data.refcounted.vecs.stypes = NULL;
250272
}
251-
if (NULL != request->data.vecs.rtypes) {
273+
if (NULL != request->data.refcounted.vecs.rtypes) {
252274
for (int i=0; i<rcount; i++) {
253-
if (NULL != request->data.vecs.rtypes[i]) {
254-
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.vecs.rtypes[i]);
275+
if (NULL != request->data.refcounted.vecs.rtypes[i]) {
276+
OMPI_DATATYPE_RELEASE_NO_NULLIFY(request->data.refcounted.vecs.rtypes[i]);
255277
}
256278
}
257-
if( request->super.req_flags & OMPI_REQ_NB_RELEASE_DATA ) {
258-
free((void*)request->data.vecs.rtypes);
279+
if( request->super.req_flags & OMPI_REQ_NB_RELEASE_DATATYPES ) {
280+
free((void*)request->data.refcounted.vecs.rtypes);
259281
}
260-
request->data.vecs.rtypes = NULL;
282+
request->data.refcounted.vecs.rtypes = NULL;
261283
}
262284
}
263285

@@ -310,8 +332,8 @@ int ompi_coll_base_retain_datatypes_w( ompi_request_t *req,
310332
}
311333
}
312334
if (OPAL_UNLIKELY(retain)) {
313-
request->data.vecs.stypes = (ompi_datatype_t **) stypes;
314-
request->data.vecs.rtypes = (ompi_datatype_t **) rtypes;
335+
request->data.refcounted.vecs.stypes = (ompi_datatype_t **) stypes;
336+
request->data.refcounted.vecs.rtypes = (ompi_datatype_t **) rtypes;
315337
if (OMPI_REQ_IS_PERSISTENT(req)) {
316338
request->cb.req_free = req->req_free;
317339
req->req_free = free_vecs_callback;
@@ -329,8 +351,8 @@ static void nbc_req_cons(ompi_coll_base_nbc_request_t *req)
329351
{
330352
req->cb.req_complete_cb = NULL;
331353
req->req_complete_cb_data = NULL;
332-
req->data.objs.objs[0] = NULL;
333-
req->data.objs.objs[1] = NULL;
354+
req->data.refcounted.objs.objs[0] = NULL;
355+
req->data.refcounted.objs.objs[1] = NULL;
334356
}
335357

336358
OBJ_CLASS_INSTANCE(ompi_coll_base_nbc_request_t, ompi_request_t, nbc_req_cons, NULL);

ompi/mca/coll/base/coll_base_util.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,28 @@ struct ompi_coll_base_nbc_request_t {
4545
ompi_request_free_fn_t req_free;
4646
} cb;
4747
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;
48+
struct {
49+
union {
50+
struct {
51+
ompi_op_t *op;
52+
ompi_datatype_t *datatype;
53+
} op;
54+
struct {
55+
ompi_datatype_t *stype;
56+
ompi_datatype_t *rtype;
57+
} types;
58+
struct {
59+
opal_object_t *objs[2];
60+
} objs;
61+
struct {
62+
ompi_datatype_t * const *stypes;
63+
ompi_datatype_t * const *rtypes;
64+
} vecs;
65+
} refcounted;
66+
void* scounts;
67+
void* sdispls;
68+
void* rcounts;
69+
void* rdispls;
6470
} data;
6571
};
6672

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
2626
#include "ompi/communicator/communicator.h"
27+
#include "ompi/mca/coll/base/coll_base_util.h"
2728

2829
#if OMPI_BUILD_MPI_PROFILING
2930
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -107,22 +108,36 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
107108
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);
108109

109110
c_ierr = PMPI_Ialltoallw(sendbuf,
110-
OMPI_ARRAY_NAME_CONVERT(sendcounts),
111-
OMPI_ARRAY_NAME_CONVERT(sdispls),
112-
c_sendtypes,
113-
recvbuf,
114-
OMPI_ARRAY_NAME_CONVERT(recvcounts),
115-
OMPI_ARRAY_NAME_CONVERT(rdispls),
116-
c_recvtypes, c_comm, &c_request);
111+
OMPI_ARRAY_NAME_CONVERT(sendcounts),
112+
OMPI_ARRAY_NAME_CONVERT(sdispls),
113+
c_sendtypes,
114+
recvbuf,
115+
OMPI_ARRAY_NAME_CONVERT(recvcounts),
116+
OMPI_ARRAY_NAME_CONVERT(rdispls),
117+
c_recvtypes, c_comm, &c_request);
117118
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
118-
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
119-
120-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
121-
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
122-
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
123-
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
124-
if (NULL != c_sendtypes) {
125-
free(c_sendtypes);
119+
if ( REQUEST_COMPLETE(c_request)) {
120+
if (NULL != c_sendtypes) {
121+
free(c_sendtypes);
122+
}
123+
free(c_recvtypes);
124+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
125+
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
126+
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
127+
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
128+
} else {
129+
ompi_coll_base_nbc_request_t* nb_request = (ompi_coll_base_nbc_request_t*)c_request;
130+
c_request->req_flags |= OMPI_REQ_NB_RELEASE_DATATYPES;
131+
if (sendcounts == OMPI_ARRAY_NAME_CONVERT(sendcounts)) {
132+
c_request->req_flags |= OMPI_REQ_NB_RELEASE_COUNTS;
133+
nb_request->data.scounts = OMPI_ARRAY_NAME_CONVERT(sendcounts);
134+
nb_request->data.rcounts = OMPI_ARRAY_NAME_CONVERT(recvcounts);
135+
}
136+
if (sdispls == OMPI_ARRAY_NAME_CONVERT(sdispls)) {
137+
c_request->req_flags |= OMPI_REQ_NB_RELEASE_DISPLS;
138+
nb_request->data.sdispls = OMPI_ARRAY_NAME_CONVERT(sdispls);
139+
nb_request->data.rdispls = OMPI_ARRAY_NAME_CONVERT(rdispls);
140+
}
126141
}
127-
free(c_recvtypes);
142+
if (MPI_SUCCESS == c_ierr) *request = PMPI_Request_c2f(c_request);
128143
}

0 commit comments

Comments
 (0)