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