Skip to content

Commit 73001e5

Browse files
committed
coll/han: allocate reorder buffer with gaps in gatherv/scatterv
This is a bugfix for derived datatypes with gaps. The reorder buffer should match the type signature and be large enough to hold gaps in addition to the actual entries. Signed-off-by: Wenduo Wang <wenduwan@amazon.com>
1 parent 02bc0c5 commit 73001e5

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

ompi/mca/coll/han/coll_han_gatherv.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,8 @@ int mca_coll_han_gatherv_intra(const void *sbuf, int scount, struct ompi_datatyp
149149
root_low_rank, low_comm,
150150
low_comm->c_coll->coll_gatherv_module);
151151

152-
size_t rdsize;
153152
char *tmp_rbuf = rbuf;
154153

155-
ompi_datatype_type_size(rdtype, &rdsize);
156-
157154
up_rcounts = calloc(up_size, sizeof(int));
158155
up_displs = malloc(up_size * sizeof(int));
159156
up_peer_ub = calloc(up_size, sizeof(int));
@@ -210,7 +207,9 @@ int mca_coll_han_gatherv_intra(const void *sbuf, int scount, struct ompi_datatyp
210207
}
211208

212209
if (need_bounce_buf) {
213-
bounce_buf = malloc(rdsize * total_up_rcounts);
210+
ptrdiff_t rsize, rgap;
211+
rsize = opal_datatype_span(&rdtype->super, total_up_rcounts, &rgap);
212+
bounce_buf = malloc(rsize);
214213
if (!bounce_buf) {
215214
err = OMPI_ERR_OUT_OF_RESOURCE;
216215
goto root_out;
@@ -222,7 +221,7 @@ int mca_coll_han_gatherv_intra(const void *sbuf, int scount, struct ompi_datatyp
222221
: 0;
223222
}
224223

225-
tmp_rbuf = bounce_buf;
224+
tmp_rbuf = bounce_buf - rgap;
226225
}
227226

228227
/* Up Gatherv */
@@ -231,7 +230,8 @@ int mca_coll_han_gatherv_intra(const void *sbuf, int scount, struct ompi_datatyp
231230

232231
/* Use a temp buffer to reorder the output buffer if needed */
233232
if (need_bounce_buf) {
234-
ptrdiff_t offset = 0;
233+
ptrdiff_t offset = 0, rdext;
234+
ompi_datatype_type_extent(rdtype, &rdext);
235235

236236
for (int i = 0; i < w_size; ++i) {
237237
up_peer = topo[2 * i];
@@ -242,10 +242,9 @@ int mca_coll_han_gatherv_intra(const void *sbuf, int scount, struct ompi_datatyp
242242
w_peer = topo[2 * i + 1];
243243

244244
ompi_datatype_copy_content_same_ddt(rdtype, (size_t) rcounts[w_peer],
245-
(char *) rbuf
246-
+ (size_t) displs[w_peer] * rdsize,
245+
(char *) rbuf + (size_t) displs[w_peer] * rdext,
247246
bounce_buf + offset);
248-
offset += rdsize * (size_t) rcounts[w_peer];
247+
offset += rdext * (size_t) rcounts[w_peer];
249248
}
250249
}
251250

ompi/mca/coll/han/coll_han_scatterv.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ int mca_coll_han_scatterv_intra(const void *sbuf, const int *scounts, const int
125125
int need_bounce_buf = 0, total_up_scounts = 0, *up_displs = NULL, *up_scounts = NULL,
126126
*up_peer_lb = NULL, *up_peer_ub = NULL;
127127
char *reorder_sbuf = (char *) sbuf, *bounce_buf = NULL;
128-
size_t sdsize;
129128

130129
low_scounts = malloc(low_size * sizeof(int));
131130
low_displs = malloc(low_size * sizeof(int));
@@ -144,8 +143,6 @@ int mca_coll_han_scatterv_intra(const void *sbuf, const int *scounts, const int
144143
low_scounts[low_peer] = scounts[w_peer];
145144
}
146145

147-
ompi_datatype_type_size(sdtype, &sdsize);
148-
149146
up_scounts = calloc(up_size, sizeof(int));
150147
up_displs = malloc(up_size * sizeof(int));
151148
up_peer_ub = calloc(up_size, sizeof(int));
@@ -201,11 +198,14 @@ int mca_coll_han_scatterv_intra(const void *sbuf, const int *scounts, const int
201198
}
202199

203200
if (need_bounce_buf) {
204-
bounce_buf = malloc(sdsize * total_up_scounts);
201+
ptrdiff_t ssize, sgap;
202+
ssize = opal_datatype_span(&rdtype->super, total_up_scounts, &sgap);
203+
bounce_buf = malloc(ssize);
205204
if (!bounce_buf) {
206205
err = OMPI_ERR_OUT_OF_RESOURCE;
207206
goto root_out;
208207
}
208+
reorder_sbuf = bounce_buf - sgap;
209209

210210
/* Calculate displacements for the inter-node scatterv */
211211
for (up_peer = 0; up_peer < up_size; ++up_peer) {
@@ -214,7 +214,8 @@ int mca_coll_han_scatterv_intra(const void *sbuf, const int *scounts, const int
214214
}
215215

216216
/* Use a temp buffer to reorder the send buffer if needed */
217-
ptrdiff_t offset = 0;
217+
ptrdiff_t offset = 0, sdext;
218+
ompi_datatype_type_extent(sdtype, &sdext);
218219

219220
for (int i = 0; i < w_size; ++i) {
220221
up_peer = topo[2 * i];
@@ -225,13 +226,11 @@ int mca_coll_han_scatterv_intra(const void *sbuf, const int *scounts, const int
225226
w_peer = topo[2 * i + 1];
226227

227228
ompi_datatype_copy_content_same_ddt(sdtype, (size_t) scounts[w_peer],
228-
bounce_buf + offset,
229+
reorder_sbuf + offset,
229230
(char *) sbuf
230-
+ (size_t) displs[w_peer] * sdsize);
231-
offset += sdsize * (size_t) scounts[w_peer];
231+
+ (size_t) displs[w_peer] * sdext);
232+
offset += sdext * (size_t) scounts[w_peer];
232233
}
233-
234-
reorder_sbuf = bounce_buf;
235234
}
236235

237236
/* Up Iscatterv */

0 commit comments

Comments
 (0)