1010 * Copyright (c) 2004-2005 The Regents of the University of California.
1111 * All rights reserved.
1212 * Copyright (c) 2006-2010 University of Houston. All rights reserved.
13- * Copyright (c) 2015 Research Organization for Information Science
13+ * Copyright (c) 2015-2016 Research Organization for Information Science
1414 * and Technology (RIST). All rights reserved.
1515 * $COPYRIGHT$
1616 *
@@ -49,10 +49,7 @@ mca_coll_inter_allgatherv_inter(const void *sbuf, int scount,
4949{
5050 int i , rank , size , size_local , total = 0 , err ;
5151 int * count = NULL ,* displace = NULL ;
52- char * ptmp = NULL ;
53- MPI_Aint incr ;
54- MPI_Aint extent ;
55- MPI_Aint lb ;
52+ char * ptmp_free = NULL , * ptmp ;
5653 ompi_datatype_t * ndtype = NULL ;
5754 ompi_request_t * req [2 ];
5855
@@ -81,22 +78,19 @@ mca_coll_inter_allgatherv_inter(const void *sbuf, int scount,
8178 for (i = 1 ; i < size_local ; i ++ ) {
8279 displace [i ] = displace [i - 1 ] + count [i - 1 ];
8380 }
84- /* Perform the gatherv locally with the first process as root */
85- err = ompi_datatype_get_extent (sdtype , & lb , & extent );
86- if (OMPI_SUCCESS != err ) {
87- err = OMPI_ERROR ;
88- goto exit ;
89- }
90- incr = 0 ;
81+ total = 0 ;
9182 for (i = 0 ; i < size_local ; i ++ ) {
92- incr = incr + extent * count [i ];
83+ total = total + count [i ];
9384 }
94- if ( incr > 0 ) {
95- ptmp = (char * )malloc (incr );
96- if (NULL == ptmp ) {
85+ if ( total > 0 ) {
86+ ptrdiff_t gap , span ;
87+ span = opal_datatype_span (& sdtype -> super , total , & gap );
88+ ptmp_free = (char * )malloc (span );
89+ if (NULL == ptmp_free ) {
9790 err = OMPI_ERR_OUT_OF_RESOURCE ;
9891 goto exit ;
9992 }
93+ ptmp = ptmp_free - gap ;
10094 }
10195 }
10296 err = comm -> c_local_comm -> c_coll .coll_gatherv (sbuf , scount , sdtype ,
@@ -111,9 +105,6 @@ mca_coll_inter_allgatherv_inter(const void *sbuf, int scount,
111105 ompi_datatype_commit (& ndtype );
112106
113107 if (0 == rank ) {
114- for (i = 0 ; i < size_local ; i ++ ) {
115- total = total + count [i ];
116- }
117108 /* Exchange data between roots */
118109 err = MCA_PML_CALL (irecv (rbuf , 1 , ndtype , 0 ,
119110 MCA_COLL_BASE_TAG_ALLGATHERV , comm ,
@@ -144,8 +135,8 @@ mca_coll_inter_allgatherv_inter(const void *sbuf, int scount,
144135 if ( NULL != ndtype ) {
145136 ompi_datatype_destroy (& ndtype );
146137 }
147- if (NULL != ptmp ) {
148- free (ptmp );
138+ if (NULL != ptmp_free ) {
139+ free (ptmp_free );
149140 }
150141 if (NULL != displace ) {
151142 free (displace );
0 commit comments