Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 010b663

Browse files
authored
Merge pull request #1295 from ggouaillardet/topic/v2.x/libnbc_fixes
v2.x: misc coll/libnbc fixes
2 parents 00e9277 + c65a1e3 commit 010b663

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

ompi/mca/coll/libnbc/nbc_ireduce.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
*
1515
*/
1616

17+
#include "opal/include/opal/align.h"
1718
#include "ompi/op/op.h"
1819

1920
#include "nbc_internal.h"
2021

21-
static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, int count, MPI_Datatype datatype,
22+
static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, char tmpredbuf, int count, MPI_Datatype datatype,
2223
MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle);
2324
static inline int red_sched_chain (int rank, int p, int root, const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2425
MPI_Op op, int ext, size_t size, NBC_Schedule *schedule, NBC_Handle *handle, int fragsize);
@@ -55,6 +56,7 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
5556
MPI_Aint ext;
5657
NBC_Schedule *schedule;
5758
char *redbuf=NULL, inplace;
59+
char tmpredbuf = 0;
5860
enum { NBC_RED_BINOMIAL, NBC_RED_CHAIN } alg;
5961
NBC_Handle *handle;
6062
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
@@ -104,8 +106,10 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
104106
redbuf = recvbuf;
105107
} else {
106108
/* recvbuf may not be valid on non-root nodes */
107-
handle->tmpbuf = malloc (2*span);
108-
redbuf = (char*) handle->tmpbuf + span - gap;
109+
ptrdiff_t span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t);
110+
handle->tmpbuf = malloc (span_align + span);
111+
redbuf = (char*)span_align - gap;
112+
tmpredbuf = 1;
109113
}
110114
} else {
111115
handle->tmpbuf = malloc (span);
@@ -142,7 +146,7 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
142146

143147
switch(alg) {
144148
case NBC_RED_BINOMIAL:
145-
res = red_sched_binomial(rank, p, root, sendbuf, redbuf, count, datatype, op, inplace, schedule, handle);
149+
res = red_sched_binomial(rank, p, root, sendbuf, redbuf, tmpredbuf, count, datatype, op, inplace, schedule, handle);
146150
break;
147151
case NBC_RED_CHAIN:
148152
res = red_sched_chain(rank, p, root, sendbuf, recvbuf, count, datatype, op, ext, size, schedule, handle, segsize);
@@ -289,10 +293,10 @@ int ompi_coll_libnbc_ireduce_inter(const void* sendbuf, void* recvbuf, int count
289293
if (vrank == 0) rank = root; \
290294
if (vrank == root) rank = 0; \
291295
}
292-
static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, int count, MPI_Datatype datatype,
296+
static inline int red_sched_binomial (int rank, int p, int root, const void *sendbuf, void *redbuf, char tmpredbuf, int count, MPI_Datatype datatype,
293297
MPI_Op op, char inplace, NBC_Schedule *schedule, NBC_Handle *handle) {
294298
int vroot, vrank, vpeer, peer, res, maxr;
295-
char *rbuf, *lbuf, *buf;
299+
char *rbuf, *lbuf, *buf, tmpbuf;
296300
int tmprbuf, tmplbuf;
297301
ptrdiff_t gap;
298302
(void)opal_datatype_span(&datatype->super, count, &gap);
@@ -310,12 +314,12 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
310314
rbuf = (void *)(-gap);
311315
tmprbuf = true;
312316
lbuf = redbuf;
313-
tmplbuf = false;
317+
tmplbuf = tmpredbuf;
314318
} else {
315319
lbuf = (void *)(-gap);
316320
tmplbuf = true;
317321
rbuf = redbuf;
318-
tmprbuf = false;
322+
tmprbuf = tmpredbuf;
319323
if (inplace) {
320324
res = NBC_Copy(rbuf, count, datatype, ((char *)handle->tmpbuf)-gap, count, datatype, MPI_COMM_SELF);
321325
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
@@ -352,7 +356,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
352356
}
353357
/* swap left and right buffers */
354358
buf = rbuf; rbuf = lbuf ; lbuf = buf;
355-
tmprbuf ^= 1; tmplbuf ^= 1;
359+
tmpbuf = tmprbuf; tmprbuf = tmplbuf; tmplbuf = tmpbuf;
356360
}
357361
} else {
358362
/* we have to send this round */
@@ -377,9 +381,9 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
377381
/* send to root if vroot ! root */
378382
if (vroot != root) {
379383
if (0 == rank) {
380-
res = NBC_Sched_send (redbuf, false, count, datatype, root, schedule, false);
384+
res = NBC_Sched_send (redbuf, tmpredbuf, count, datatype, root, schedule, false);
381385
} else if (root == rank) {
382-
res = NBC_Sched_recv (redbuf, false, count, datatype, vroot, schedule, false);
386+
res = NBC_Sched_recv (redbuf, tmpredbuf, count, datatype, vroot, schedule, false);
383387
}
384388
}
385389

ompi/mca/coll/libnbc/nbc_ireduce_scatter.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Author(s): Torsten Hoefler <[email protected]>
1717
*
1818
*/
19+
#include "opal/include/opal/align.h"
20+
1921
#include "nbc_internal.h"
2022

2123
/* an reduce_csttare schedule can not be cached easily because the contents
@@ -40,7 +42,7 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i
4042
struct mca_coll_base_module_2_1_0_t *module) {
4143
int peer, rank, maxr, p, res, count;
4244
MPI_Aint ext;
43-
ptrdiff_t gap, span;
45+
ptrdiff_t gap, span, span_align;
4446
char *sbuf, inplace;
4547
NBC_Schedule *schedule;
4648
NBC_Handle *handle;
@@ -84,14 +86,15 @@ int ompi_coll_libnbc_ireduce_scatter(const void* sendbuf, void* recvbuf, const i
8486
maxr = (int) ceil ((log((double) p) / LOG2));
8587

8688
span = opal_datatype_span(&datatype->super, count, &gap);
87-
handle->tmpbuf = malloc (span * 2);
89+
span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t);
90+
handle->tmpbuf = malloc (span_align + span);
8891
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
8992
NBC_Return_handle (handle);
9093
return OMPI_ERR_OUT_OF_RESOURCE;
9194
}
9295

9396
rbuf = (char *)(-gap);
94-
lbuf = (char *)(span - gap);
97+
lbuf = (char *)(span_align - gap);
9598

9699
schedule = OBJ_NEW(NBC_Schedule);
97100
if (OPAL_UNLIKELY(NULL == schedule)) {
@@ -205,7 +208,7 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf,
205208
struct mca_coll_base_module_2_1_0_t *module) {
206209
int rank, res, count, lsize, rsize;
207210
MPI_Aint ext;
208-
ptrdiff_t gap, span;
211+
ptrdiff_t gap, span, span_align;
209212
NBC_Schedule *schedule;
210213
NBC_Handle *handle;
211214
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
@@ -226,14 +229,15 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf,
226229
}
227230

228231
span = opal_datatype_span(&datatype->super, count, &gap);
232+
span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t);
229233

230234
res = NBC_Init_handle(comm, &handle, libnbc_module);
231235
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
232236
return res;
233237
}
234238

235239
if (count > 0) {
236-
handle->tmpbuf = malloc (2 * span);
240+
handle->tmpbuf = malloc (span_align + span);
237241
if (OPAL_UNLIKELY(NULL == handle->tmpbuf)) {
238242
NBC_Return_handle (handle);
239243
return OMPI_ERR_OUT_OF_RESOURCE;
@@ -259,7 +263,7 @@ int ompi_coll_libnbc_ireduce_scatter_inter (const void* sendbuf, void* recvbuf,
259263
if (0 == rank) {
260264
char *lbuf, *rbuf;
261265
lbuf = (char *)(-gap);
262-
rbuf = (char *)(span-gap);
266+
rbuf = (char *)(span_align-gap);
263267
res = NBC_Sched_recv (lbuf, true, count, datatype, 0, schedule, true);
264268
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
265269
NBC_Return_handle (handle);

ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* Author(s): Torsten Hoefler <[email protected]>
1515
*
1616
*/
17+
#include "opal/include/opal/align.h"
18+
1719
#include "nbc_internal.h"
1820

1921
/* an reduce_csttare schedule can not be cached easily because the contents
@@ -75,18 +77,20 @@ int ompi_coll_libnbc_ireduce_scatter_block(const void* sendbuf, void* recvbuf, i
7577

7678
if (0 < count) {
7779
char *rbuf, *lbuf, *buf;
80+
ptrdiff_t span_align;
7881

7982
span = opal_datatype_span(&datatype->super, count, &gap);
80-
handle->tmpbuf = malloc (2*span);
83+
span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t);
84+
handle->tmpbuf = malloc (span_align + span);
8185
if (NULL == handle->tmpbuf) {
8286
OMPI_COLL_LIBNBC_REQUEST_RETURN(handle);
8387
OBJ_RELEASE(schedule);
8488
return OMPI_ERR_OUT_OF_RESOURCE;
8589
}
8690

8791
rbuf = (void *)(-gap);
88-
lbuf = (char *)(span - gap);
89-
redbuf = (char *) handle->tmpbuf + span - gap;
92+
lbuf = (char *)(span_align - gap);
93+
redbuf = (char *) handle->tmpbuf + span_align - gap;
9094

9195
/* copy data to redbuf if we only have a single node */
9296
if ((p == 1) && !inplace) {
@@ -206,7 +210,7 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv
206210
ompi_request_t **request, struct mca_coll_base_module_2_1_0_t *module) {
207211
int rank, res, count, lsize, rsize;
208212
MPI_Aint ext;
209-
ptrdiff_t gap, span;
213+
ptrdiff_t gap, span, span_align;
210214
NBC_Schedule *schedule;
211215
NBC_Handle *handle;
212216
ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
@@ -229,9 +233,10 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv
229233
count = rcount * lsize;
230234

231235
span = opal_datatype_span(&dtype->super, count, &gap);
236+
span_align = OPAL_ALIGN(span, dtype->super.align, ptrdiff_t);
232237

233238
if (count > 0) {
234-
handle->tmpbuf = malloc (2 * span);
239+
handle->tmpbuf = malloc (span_align + span);
235240
if (NULL == handle->tmpbuf) {
236241
NBC_Return_handle (handle);
237242
return OMPI_ERR_OUT_OF_RESOURCE;
@@ -257,7 +262,7 @@ int ompi_coll_libnbc_ireduce_scatter_block_inter(const void *sendbuf, void *recv
257262
if (0 == rank) {
258263
char *lbuf, *rbuf;
259264
lbuf = (char *)(-gap);
260-
rbuf = (char *)(span-gap);
265+
rbuf = (char *)(span_align-gap);
261266
res = NBC_Sched_recv (lbuf, true, count, dtype, 0, schedule, true);
262267
if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
263268
NBC_Return_handle (handle);

0 commit comments

Comments
 (0)