Skip to content

Commit 541a868

Browse files
committed
checkpoint
Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent e4dcf83 commit 541a868

32 files changed

+280
-169
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 114 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -104,142 +104,159 @@ int ompi_rounddown(int num, int factor)
104104
return num * factor; /* floor(num / factor) * factor */
105105
}
106106

107-
static int release_op_callback(struct ompi_request_t *request) {
108-
struct ompi_coll_base_nbc_request_t * p = (ompi_coll_base_nbc_request_t *)request;
109-
int rc = OMPI_SUCCESS;
110-
assert (NULL != p);
111-
if (NULL != p->req_complete_cb) {
112-
request->req_complete_cb = p->req_complete_cb;
113-
request->req_complete_cb_data = p->req_complete_cb_data;
114-
rc = request->req_complete_cb(request->req_complete_cb_data);
107+
static void release_objs_callback(struct ompi_coll_base_nbc_request_t *request) {
108+
if (NULL != request->data.objs.objs[0]) {
109+
OBJ_RELEASE(request->data.objs.objs[0]);
110+
}
111+
if (NULL != request->data.objs.objs[1]) {
112+
OBJ_RELEASE(request->data.objs.objs[1]);
115113
}
116-
if (NULL != p->op) {
117-
OBJ_RELEASE(p->op);
114+
}
115+
116+
static int complete_objs_callback(struct ompi_request_t *req) {
117+
struct ompi_coll_base_nbc_request_t *request = (ompi_coll_base_nbc_request_t *)req;
118+
int rc = OMPI_SUCCESS;
119+
assert (NULL != request);
120+
if (NULL != request->cb.req_complete_cb) {
121+
rc = request->cb.req_complete_cb(request->req_complete_cb_data);
118122
}
119-
if (NULL != p->datatype) {
120-
OBJ_RELEASE(p->datatype);
123+
release_objs_callback(request);
124+
return rc;
125+
}
126+
127+
static int free_objs_callback(struct ompi_request_t **rptr) {
128+
struct ompi_coll_base_nbc_request_t *request = *(ompi_coll_base_nbc_request_t **)rptr;
129+
int rc = OMPI_SUCCESS;
130+
if (NULL != request->cb.req_free) {
131+
rc = request->cb.req_free(rptr);
121132
}
133+
release_objs_callback(request);
122134
return rc;
123135
}
124136

125137
int ompi_coll_base_retain_op( ompi_request_t *req, ompi_op_t *op,
126138
ompi_datatype_t *type) {
127139
ompi_coll_base_nbc_request_t *request = (ompi_coll_base_nbc_request_t *)req;
128-
bool retain = !ompi_op_is_intrinsic(op);
129-
retain |= !ompi_datatype_is_predefined(type);
140+
bool retain = false;
141+
if (!ompi_op_is_intrinsic(op)) {
142+
OBJ_RETAIN(op);
143+
request->data.op.op = op;
144+
retain = true;
145+
}
146+
if (!ompi_datatype_is_predefined(type)) {
147+
OBJ_RETAIN(type);
148+
request->data.op.datatype = type;
149+
retain = true;
150+
}
130151
if (OPAL_UNLIKELY(retain)) {
131-
if (!ompi_op_is_intrinsic(op)) {
132-
OBJ_RETAIN(op);
133-
request->op = op;
134-
} else {
135-
request->op = NULL;
136-
}
137-
if (!ompi_datatype_is_predefined(type)) {
138-
OBJ_RETAIN(type);
139-
request->datatype = type;
152+
if (req->req_persistent) {
153+
request->cb.req_free = req->req_free;
154+
req->req_free = free_objs_callback;
140155
} else {
141-
request->datatype = NULL;
156+
request->cb.req_complete_cb = req->req_complete_cb;
157+
request->req_complete_cb_data = req->req_complete_cb_data;
158+
req->req_complete_cb = complete_objs_callback;
159+
req->req_complete_cb_data = request;
142160
}
143-
request->req_complete_cb = request->super.req_complete_cb;
144-
request->req_complete_cb_data = request->super.req_complete_cb_data;
145-
req->req_complete_cb = release_op_callback;
146-
req->req_complete_cb_data = request;
147161
}
148162
return OMPI_SUCCESS;
149163
}
150164

151-
static int release_datatypes_callback(struct ompi_request_t *request) {
152-
struct ompi_coll_base_nbc_request_t * p = (ompi_coll_base_nbc_request_t *)request;
153-
int rc = OMPI_SUCCESS;
154-
assert (NULL != p);
155-
if (NULL != p->req_complete_cb) {
156-
request->req_complete_cb = p->req_complete_cb;
157-
request->req_complete_cb_data = p->req_complete_cb_data;
158-
rc = request->req_complete_cb(request->req_complete_cb_data);
159-
}
160-
if (NULL != p->stype) {
161-
OBJ_RELEASE(p->stype);
162-
}
163-
if (NULL != p->rtype) {
164-
OBJ_RELEASE(p->rtype);
165-
}
166-
return rc;
167-
}
168-
169165
int ompi_coll_base_retain_datatypes( ompi_request_t *req, ompi_datatype_t *stype,
170166
ompi_datatype_t *rtype) {
171167
ompi_coll_base_nbc_request_t *request = (ompi_coll_base_nbc_request_t *)req;
172-
bool retain = NULL != stype && !ompi_datatype_is_predefined(stype);
173-
retain |= NULL != rtype && !ompi_datatype_is_predefined(rtype);
168+
bool retain = false;
169+
if (NULL != stype && !ompi_datatype_is_predefined(stype)) {
170+
OBJ_RETAIN(stype);
171+
request->data.types.stype = stype;
172+
retain = true;
173+
}
174+
if (NULL != rtype && !ompi_datatype_is_predefined(rtype)) {
175+
OBJ_RETAIN(rtype);
176+
request->data.types.rtype = rtype;
177+
retain = true;
178+
}
174179
if (OPAL_UNLIKELY(retain)) {
175-
if (NULL != stype && !ompi_datatype_is_predefined(stype)) {
176-
OBJ_RETAIN(stype);
177-
request->stype = stype;
180+
if (req->req_persistent) {
181+
request->cb.req_free = req->req_free;
182+
req->req_free = free_objs_callback;
178183
} else {
179-
request->stype = NULL;
184+
request->cb.req_complete_cb = req->req_complete_cb;
185+
request->req_complete_cb_data = req->req_complete_cb_data;
186+
req->req_complete_cb = complete_objs_callback;
187+
req->req_complete_cb_data = request;
180188
}
181-
if (NULL != rtype && !ompi_datatype_is_predefined(rtype)) {
182-
OBJ_RETAIN(rtype);
183-
request->rtype = rtype;
184-
} else {
185-
request->rtype = NULL;
186-
}
187-
request->req_complete_cb = req->req_complete_cb;
188-
request->req_complete_cb_data = req->req_complete_cb_data;
189-
req->req_complete_cb = release_datatypes_callback;
190-
req->req_complete_cb_data = request;
191189
}
192190
return OMPI_SUCCESS;
193191
}
194192

195-
static int release_datatypes_w_callback(struct ompi_request_t *request) {
196-
ompi_coll_base_nbc_request_t *p = (ompi_coll_base_nbc_request_t *)request;
193+
static void release_vecs_callback(ompi_coll_base_nbc_request_t *request) {
194+
for (int i=0; i<ompi_comm_size(request->super.req_mpi_object.comm); i++) {
195+
if (NULL != request->data.vecs.stypes && NULL != request->data.vecs.stypes[i]) {
196+
OMPI_DATATYPE_RELEASE(request->data.vecs.stypes[i]);
197+
}
198+
if (NULL != request->data.vecs.rtypes && NULL != request->data.vecs.rtypes[i]) {
199+
OMPI_DATATYPE_RELEASE(request->data.vecs.rtypes[i]);
200+
}
201+
}
202+
}
203+
204+
static int complete_vecs_callback(struct ompi_request_t *req) {
205+
ompi_coll_base_nbc_request_t *request = (ompi_coll_base_nbc_request_t *)req;
197206
int rc = OMPI_SUCCESS;
198-
assert (NULL != p);
199-
if (NULL != request->req_complete_cb) {
200-
request->req_complete_cb = p->req_complete_cb;
201-
request->req_complete_cb_data = p->req_complete_cb_data;
202-
rc = request->req_complete_cb(request->req_complete_cb_data);
207+
assert (NULL != request);
208+
if (NULL != request->cb.req_complete_cb) {
209+
rc = request->cb.req_complete_cb(request->req_complete_cb_data);
203210
}
204-
for (int i=0; i<p->count; i++) {
205-
OBJ_RELEASE(p->types[i]);
211+
release_vecs_callback(request);
212+
return rc;
213+
}
214+
215+
static int free_vecs_callback(struct ompi_request_t **rptr) {
216+
struct ompi_coll_base_nbc_request_t *request = *(ompi_coll_base_nbc_request_t **)rptr;
217+
int rc = OMPI_SUCCESS;
218+
if (NULL != request->cb.req_free) {
219+
rc = request->cb.req_free(rptr);
206220
}
207-
free(p->types);
221+
release_vecs_callback(request);
208222
return rc;
209223
}
210224

211225
int ompi_coll_base_retain_datatypes_w( ompi_request_t *req, int count,
212-
ompi_datatype_t *const stypes[], ompi_datatype_t *const rtypes[]) {
226+
ompi_datatype_t *stypes[], ompi_datatype_t *rtypes[]) {
213227
ompi_coll_base_nbc_request_t *request = (ompi_coll_base_nbc_request_t *)req;
214-
int datatypes = 0;
228+
bool retain = false;
215229
for (int i=0; i<count; i++) {
216-
if (NULL != stypes[i] && !ompi_datatype_is_predefined(stypes[i])) {
217-
datatypes++;
230+
if (NULL != stypes && NULL != stypes[i] && !ompi_datatype_is_predefined(stypes[i])) {
231+
OBJ_RETAIN(stypes[i]);
232+
retain = true;
218233
}
219-
if (NULL != rtypes[i] && !ompi_datatype_is_predefined(rtypes[i])) {
220-
datatypes++;
234+
if (NULL != rtypes && NULL != rtypes[i] && !ompi_datatype_is_predefined(rtypes[i])) {
235+
OBJ_RETAIN(rtypes[i]);
236+
retain = true;
221237
}
222238
}
223-
if (OPAL_UNLIKELY(0 < datatypes)) {
224-
request->types = (ompi_datatype_t **)calloc(datatypes, sizeof(ompi_datatype_t *));
225-
if (OPAL_UNLIKELY(NULL == request->types)) {
226-
return OMPI_ERR_OUT_OF_RESOURCE;
227-
}
228-
datatypes = 0;
229-
for (int i=0; i<count; i++) {
230-
if (NULL != stypes[i] && !ompi_datatype_is_predefined(stypes[i])) {
231-
request->types[datatypes++] = stypes[i];
232-
OBJ_RETAIN(stypes[i]);
233-
}
234-
if (NULL != rtypes[i] && !ompi_datatype_is_predefined(rtypes[i])) {
235-
request->types[datatypes++] = rtypes[i];
236-
OBJ_RETAIN(rtypes[i]);
237-
}
239+
if (OPAL_UNLIKELY(retain)) {
240+
request->data.vecs.stypes = stypes;
241+
request->data.vecs.rtypes = stypes;
242+
if (req->req_persistent) {
243+
request->cb.req_free = req->req_free;
244+
req->req_free = free_vecs_callback;
245+
} else {
246+
request->cb.req_complete_cb = req->req_complete_cb;
247+
request->req_complete_cb_data = req->req_complete_cb_data;
248+
req->req_complete_cb = complete_vecs_callback;
249+
req->req_complete_cb_data = request;
238250
}
239-
request->req_complete_cb = req->req_complete_cb;
240-
request->req_complete_cb_data = req->req_complete_cb_data;
241-
req->req_complete_cb = release_datatypes_w_callback;
242-
req->req_complete_cb_data = request;
243251
}
244252
return OMPI_SUCCESS;
245253
}
254+
255+
static void nbc_req_cons(ompi_coll_base_nbc_request_t *req) {
256+
req->cb.req_complete_cb = NULL;
257+
req->req_complete_cb_data = NULL;
258+
req->data.objs.objs[0] = NULL;
259+
req->data.objs.objs[1] = NULL;
260+
}
261+
262+
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: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,32 @@ BEGIN_C_DECLS
3434

3535
struct ompi_coll_base_nbc_request_t {
3636
ompi_request_t super;
37-
ompi_request_complete_fn_t req_complete_cb;
37+
union {
38+
ompi_request_complete_fn_t req_complete_cb;
39+
ompi_request_free_fn_t req_free;
40+
} cb;
3841
void *req_complete_cb_data;
39-
ompi_op_t *op;
40-
ompi_datatype_t *datatype;
41-
ompi_datatype_t *stype;
42-
ompi_datatype_t *rtype;
43-
ompi_datatype_t **types;
44-
int count;
42+
union {
43+
struct {
44+
ompi_op_t *op;
45+
ompi_datatype_t *datatype;
46+
} op;
47+
struct {
48+
ompi_datatype_t *stype;
49+
ompi_datatype_t *rtype;
50+
} types;
51+
struct {
52+
opal_object_t *objs[2];
53+
} objs;
54+
struct {
55+
ompi_datatype_t **stypes;
56+
ompi_datatype_t **rtypes;
57+
} vecs;
58+
} data;
4559
};
4660

61+
OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_coll_base_nbc_request_t);
62+
4763
typedef struct ompi_coll_base_nbc_request_t ompi_coll_base_nbc_request_t;
4864

4965
/**
@@ -106,8 +122,8 @@ int ompi_coll_base_retain_datatypes( ompi_request_t *request, ompi_datatype_t *s
106122
ompi_datatype_t *rtype);
107123

108124
int ompi_coll_base_retain_datatypes_w( ompi_request_t *request, int count,
109-
ompi_datatype_t *const stypes[],
110-
ompi_datatype_t *const rtypes[]);
125+
ompi_datatype_t *stypes[],
126+
ompi_datatype_t *rtypes[]);
111127

112128
END_C_DECLS
113129
#endif /* MCA_COLL_BASE_UTIL_EXPORT_H */

ompi/mpi/c/iallgather.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int MPI_Iallgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
104104
recvbuf, recvcount, recvtype, comm,
105105
request, comm->c_coll->coll_iallgather_module);
106106
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
107-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
107+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
108108
}
109109

110110
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);

ompi/mpi/c/iallgatherv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int MPI_Iallgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
128128
recvtype, comm, request,
129129
comm->c_coll->coll_iallgatherv_module);
130130
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
131-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
131+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
132132
}
133133
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
134134
}

ompi/mpi/c/ialltoall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int MPI_Ialltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
103103
recvbuf, recvcount, recvtype, comm,
104104
request, comm->c_coll->coll_ialltoall_module);
105105
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
106-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
106+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
107107
}
108108
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
109109
}

ompi/mpi/c/ialltoallv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int MPI_Ialltoallv(const void *sendbuf, const int sendcounts[], const int sdispl
132132
sendtype, recvbuf, recvcounts, rdispls,
133133
recvtype, comm, request, comm->c_coll->coll_ialltoallv_module);
134134
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
135-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
135+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
136136
}
137137
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
138138
}

ompi/mpi/c/ialltoallw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int MPI_Ialltoallw(const void *sendbuf, const int sendcounts[], const int sdispl
131131
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
132132
ompi_coll_base_retain_datatypes_w(*request,
133133
OMPI_COMM_IS_INTER(comm)?ompi_comm_remote_size(comm):ompi_comm_size(comm),
134-
sendtypes,
134+
(MPI_IN_PLACE==sendbuf)?NULL:sendtypes,
135135
recvtypes);
136136
}
137137
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);

ompi/mpi/c/igather.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int MPI_Igather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
175175
recvcount, recvtype, root, comm, request,
176176
comm->c_coll->coll_igather_module);
177177
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
178-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
178+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
179179
}
180180
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
181181
}

ompi/mpi/c/igatherv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int MPI_Igatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
198198
recvcounts, displs, recvtype,
199199
root, comm, request, comm->c_coll->coll_igatherv_module);
200200
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
201-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
201+
ompi_coll_base_retain_datatypes(*request, (MPI_IN_PLACE==sendbuf)?NULL:sendtype, recvtype);
202202
}
203203
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
204204
}

ompi/mpi/c/iscatter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int MPI_Iscatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
158158
recvcount, recvtype, root, comm, request,
159159
comm->c_coll->coll_iscatter_module);
160160
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
161-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
161+
ompi_coll_base_retain_datatypes(*request, sendtype, (MPI_IN_PLACE==recvbuf)?NULL:recvtype);
162162
}
163163
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
164164
}

ompi/mpi/c/iscatterv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int MPI_Iscatterv(const void *sendbuf, const int sendcounts[], const int displs[
198198
sendtype, recvbuf, recvcount, recvtype, root, comm,
199199
request, comm->c_coll->coll_iscatterv_module);
200200
if (OPAL_LIKELY(OMPI_SUCCESS == err)) {
201-
ompi_coll_base_retain_datatypes(*request, sendtype, recvtype);
201+
ompi_coll_base_retain_datatypes(*request, sendtype, (MPI_IN_PLACE==recvbuf)?NULL:recvtype);
202202
}
203203
OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
204204
}

0 commit comments

Comments
 (0)