Skip to content

Commit b5328be

Browse files
authored
Merge pull request #12434 from gkatev/han_root_node_rbuf_fix
coll/han: Fix issue in reduce leading to invalid rbuf pointer
2 parents 984944d + 0f0727e commit b5328be

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ompi/mca/coll/han/coll_han_reduce.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* reserved.
55
* Copyright (c) 2020 Bull S.A.S. All rights reserved.
66
* Copyright (c) 2022 IBM Corporation. All rights reserved
7+
* Copyright (c) 2024 Computer Architecture and VLSI Systems (CARV)
8+
* Laboratory, ICS Forth. All rights reserved.
79
* $COPYRIGHT$
810
*
911
* Additional copyrights may follow
@@ -139,11 +141,18 @@ mca_coll_han_reduce_intra(const void *sbuf,
139141
"[%d]: root_low_rank %d root_up_rank %d\n", w_rank, root_low_rank,
140142
root_up_rank));
141143

142-
void *tmp_rbuf = rbuf;
144+
/* node leaders require a buffer to store intermediate results */
145+
void *tmp_rbuf = NULL;
143146
void *tmp_rbuf_to_free = NULL;
144-
if (low_rank == root_low_rank && root_up_rank != up_rank) {
145-
/* allocate 2 segments on node leaders that are not the global root */
147+
if (w_rank == root) {
148+
/* the global root already has one */
149+
tmp_rbuf = rbuf;
150+
} else if (low_rank == root_low_rank) {
151+
/* allocate 2 temporary segments on node leaders that are not the global root */
146152
tmp_rbuf = malloc(2*extent*seg_count);
153+
if (NULL == tmp_rbuf) {
154+
return OMPI_ERR_OUT_OF_RESOURCE;
155+
}
147156
tmp_rbuf_to_free = tmp_rbuf;
148157
}
149158

@@ -176,7 +185,7 @@ mca_coll_han_reduce_intra(const void *sbuf,
176185
t->sbuf = (char *) t->sbuf + extent * t->seg_count;
177186
}
178187

179-
if (up_rank == root_up_rank) {
188+
if (w_rank == root) {
180189
t->rbuf = (char *) t->rbuf + extent * t->seg_count;
181190
}
182191
t->cur_seg = t->cur_seg + 1;

0 commit comments

Comments
 (0)