1919
2020#include "nbc_internal.h"
2121
22- 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 ,
2323 MPI_Op op , char inplace , NBC_Schedule * schedule , NBC_Handle * handle );
2424static inline int red_sched_chain (int rank , int p , int root , const void * sendbuf , void * recvbuf , int count , MPI_Datatype datatype ,
2525 MPI_Op op , int ext , size_t size , NBC_Schedule * schedule , NBC_Handle * handle , int fragsize );
@@ -56,6 +56,7 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
5656 MPI_Aint ext ;
5757 NBC_Schedule * schedule ;
5858 char * redbuf = NULL , inplace ;
59+ char tmpredbuf = 0 ;
5960 enum { NBC_RED_BINOMIAL , NBC_RED_CHAIN } alg ;
6061 NBC_Handle * handle ;
6162 ompi_coll_libnbc_module_t * libnbc_module = (ompi_coll_libnbc_module_t * ) module ;
@@ -107,7 +108,8 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
107108 /* recvbuf may not be valid on non-root nodes */
108109 ptrdiff_t span_align = OPAL_ALIGN (span , datatype -> super .align , ptrdiff_t );
109110 handle -> tmpbuf = malloc (span_align + span );
110- redbuf = (char * ) handle -> tmpbuf + span_align - gap ;
111+ redbuf = (char * )span_align - gap ;
112+ tmpredbuf = 1 ;
111113 }
112114 } else {
113115 handle -> tmpbuf = malloc (span );
@@ -144,7 +146,7 @@ int ompi_coll_libnbc_ireduce(const void* sendbuf, void* recvbuf, int count, MPI_
144146
145147 switch (alg ) {
146148 case NBC_RED_BINOMIAL :
147- 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 );
148150 break ;
149151 case NBC_RED_CHAIN :
150152 res = red_sched_chain (rank , p , root , sendbuf , recvbuf , count , datatype , op , ext , size , schedule , handle , segsize );
@@ -291,10 +293,10 @@ int ompi_coll_libnbc_ireduce_inter(const void* sendbuf, void* recvbuf, int count
291293 if (vrank == 0) rank = root; \
292294 if (vrank == root) rank = 0; \
293295}
294- 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 ,
295297 MPI_Op op , char inplace , NBC_Schedule * schedule , NBC_Handle * handle ) {
296298 int vroot , vrank , vpeer , peer , res , maxr ;
297- char * rbuf , * lbuf , * buf ;
299+ char * rbuf , * lbuf , * buf , tmpbuf ;
298300 int tmprbuf , tmplbuf ;
299301 ptrdiff_t gap ;
300302 (void )opal_datatype_span (& datatype -> super , count , & gap );
@@ -312,12 +314,12 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
312314 rbuf = (void * )(- gap );
313315 tmprbuf = true;
314316 lbuf = redbuf ;
315- tmplbuf = false ;
317+ tmplbuf = tmpredbuf ;
316318 } else {
317319 lbuf = (void * )(- gap );
318320 tmplbuf = true;
319321 rbuf = redbuf ;
320- tmprbuf = false ;
322+ tmprbuf = tmpredbuf ;
321323 if (inplace ) {
322324 res = NBC_Copy (rbuf , count , datatype , ((char * )handle -> tmpbuf )- gap , count , datatype , MPI_COMM_SELF );
323325 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -354,7 +356,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
354356 }
355357 /* swap left and right buffers */
356358 buf = rbuf ; rbuf = lbuf ; lbuf = buf ;
357- tmprbuf ^= 1 ; tmplbuf ^= 1 ;
359+ tmpbuf = tmprbuf ; tmprbuf = tmplbuf ; tmplbuf = tmpbuf ;
358360 }
359361 } else {
360362 /* we have to send this round */
@@ -379,9 +381,9 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
379381 /* send to root if vroot ! root */
380382 if (vroot != root ) {
381383 if (0 == rank ) {
382- res = NBC_Sched_send (redbuf , false , count , datatype , root , schedule , false);
384+ res = NBC_Sched_send (redbuf , tmpredbuf , count , datatype , root , schedule , false);
383385 } else if (root == rank ) {
384- res = NBC_Sched_recv (redbuf , false , count , datatype , vroot , schedule , false);
386+ res = NBC_Sched_recv (redbuf , tmpredbuf , count , datatype , vroot , schedule , false);
385387 }
386388 }
387389
0 commit comments