Skip to content

Commit 0e39319

Browse files
committed
coll/base: fix [all]reduce with non zero lower bound datatypes
Offset temporary buffer when a non zero lower bound datatype is used. Thanks Hristo Iliev for the report
1 parent f8957f2 commit 0e39319

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

ompi/mca/coll/base/coll_base_allreduce.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2009 University of Houston. All rights reserved.
1414
* Copyright (c) 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
*
@@ -134,7 +134,7 @@ ompi_coll_base_allreduce_intra_recursivedoubling(const void *sbuf, void *rbuf,
134134
{
135135
int ret, line, rank, size, adjsize, remote, distance;
136136
int newrank, newremote, extra_ranks;
137-
char *tmpsend = NULL, *tmprecv = NULL, *tmpswap = NULL, *inplacebuf = NULL;
137+
char *tmpsend = NULL, *tmprecv = NULL, *tmpswap = NULL, *inplacebuf_free = NULL, *inplacebuf;
138138
ompi_request_t *reqs[2] = {NULL, NULL};
139139
OPAL_PTRDIFF_TYPE span, gap;
140140

@@ -155,8 +155,9 @@ ompi_coll_base_allreduce_intra_recursivedoubling(const void *sbuf, void *rbuf,
155155

156156
/* Allocate and initialize temporary send buffer */
157157
span = opal_datatype_span(&dtype->super, count, &gap);
158-
inplacebuf = (char*) malloc(span);
159-
if (NULL == inplacebuf) { ret = -1; line = __LINE__; goto error_hndl; }
158+
inplacebuf_free = (char*) malloc(span);
159+
if (NULL == inplacebuf_free) { ret = -1; line = __LINE__; goto error_hndl; }
160+
inplacebuf = inplacebuf_free - gap;
160161

161162
if (MPI_IN_PLACE == sbuf) {
162163
ret = ompi_datatype_copy_content_same_ddt(dtype, count, inplacebuf, (char*)rbuf);
@@ -263,7 +264,7 @@ ompi_coll_base_allreduce_intra_recursivedoubling(const void *sbuf, void *rbuf,
263264
if (ret < 0) { line = __LINE__; goto error_hndl; }
264265
}
265266

266-
if (NULL != inplacebuf) free(inplacebuf);
267+
if (NULL != inplacebuf_free) free(inplacebuf_free);
267268
return MPI_SUCCESS;
268269

269270
error_hndl:

ompi/mca/coll/base/coll_base_reduce.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2013 Los Alamos National Security, LLC. All Rights
1414
* reserved.
15-
* Copyright (c) 2015 Research Organization for Information Science
15+
* Copyright (c) 2015-2016 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
1717
* $COPYRIGHT$
1818
*
@@ -485,6 +485,7 @@ int ompi_coll_base_reduce_intra_in_order_binary( const void *sendbuf, void *recv
485485
int ret, rank, size, io_root, segcount = count;
486486
void *use_this_sendbuf = NULL;
487487
void *use_this_recvbuf = NULL;
488+
char *tmpbuf_free = NULL;
488489
size_t typelng;
489490
mca_coll_base_module_t *base_module = (mca_coll_base_module_t*) module;
490491
mca_coll_base_comm_t *data = base_module->base_data;
@@ -515,24 +516,26 @@ int ompi_coll_base_reduce_intra_in_order_binary( const void *sendbuf, void *recv
515516
use_this_recvbuf = recvbuf;
516517
if (io_root != root) {
517518
ptrdiff_t dsize, gap;
518-
char *tmpbuf = NULL;
519+
char *tmpbuf;
519520

520521
dsize = opal_datatype_span(&datatype->super, count, &gap);
521522

522523
if ((root == rank) && (MPI_IN_PLACE == sendbuf)) {
523-
tmpbuf = (char *) malloc(dsize);
524-
if (NULL == tmpbuf) {
524+
tmpbuf_free = (char *) malloc(dsize);
525+
if (NULL == tmpbuf_free) {
525526
return MPI_ERR_INTERN;
526527
}
528+
tmpbuf = tmpbuf_free - gap;
527529
ompi_datatype_copy_content_same_ddt(datatype, count,
528530
(char*)tmpbuf,
529531
(char*)recvbuf);
530532
use_this_sendbuf = tmpbuf;
531533
} else if (io_root == rank) {
532-
tmpbuf = (char *) malloc(dsize);
533-
if (NULL == tmpbuf) {
534+
tmpbuf_free = (char *) malloc(dsize);
535+
if (NULL == tmpbuf_free) {
534536
return MPI_ERR_INTERN;
535537
}
538+
tmpbuf = tmpbuf_free - gap;
536539
use_this_recvbuf = tmpbuf;
537540
}
538541
}
@@ -552,19 +555,18 @@ int ompi_coll_base_reduce_intra_in_order_binary( const void *sendbuf, void *recv
552555
MCA_COLL_BASE_TAG_REDUCE, comm,
553556
MPI_STATUS_IGNORE));
554557
if (MPI_SUCCESS != ret) { return ret; }
555-
if (MPI_IN_PLACE == sendbuf) {
556-
free(use_this_sendbuf);
557-
}
558558

559559
} else if (io_root == rank) {
560560
/* Send result from use_this_recvbuf to root */
561561
ret = MCA_PML_CALL(send(use_this_recvbuf, count, datatype, root,
562562
MCA_COLL_BASE_TAG_REDUCE,
563563
MCA_PML_BASE_SEND_STANDARD, comm));
564564
if (MPI_SUCCESS != ret) { return ret; }
565-
free(use_this_recvbuf);
566565
}
567566
}
567+
if (NULL != tmpbuf_free) {
568+
free(tmpbuf_free);
569+
}
568570

569571
return MPI_SUCCESS;
570572
}

0 commit comments

Comments
 (0)