33 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44 * University Research and Technology
55 * Corporation. All rights reserved.
6- * Copyright (c) 2004-2013 The University of Tennessee and The University
6+ * Copyright (c) 2004-2019 The University of Tennessee and The University
77 * of Tennessee Research Foundation. All rights
88 * reserved.
99 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
3434int32_t ompi_datatype_create_indexed ( int count , const int * pBlockLength , const int * pDisp ,
3535 const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
3636{
37- ompi_datatype_t * pdt ;
38- int i ;
3937 ptrdiff_t extent , disp , endat ;
38+ ompi_datatype_t * pdt ;
4039 size_t dLength ;
40+ int i ;
4141
42- if ( 0 == count ) {
42+ /* ignore all cases that lead to an empty type */
43+ ompi_datatype_type_size (oldType , & dLength );
44+ for ( i = 0 ; (i < count ) && (0 == pBlockLength [i ]); i ++ ); /* find first non zero */
45+ if ( (i == count ) || (0 == dLength ) ) {
4346 return ompi_datatype_duplicate ( & ompi_mpi_datatype_null .dt , newType );
4447 }
4548
46- disp = pDisp [0 ];
47- dLength = pBlockLength [0 ];
49+ disp = pDisp [i ];
50+ dLength = pBlockLength [i ];
4851 endat = disp + dLength ;
4952 ompi_datatype_type_extent ( oldType , & extent );
5053
51- pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
52- for ( i = 1 ; i < count ; i ++ ) {
53- if ( endat == pDisp [i ] ) {
54- /* contiguous with the previsious */
54+ pdt = ompi_datatype_create ( (count - i ) * (2 + oldType -> super .desc .used ) );
55+ for ( i += 1 ; i < count ; i ++ ) {
56+ if ( 0 == pBlockLength [i ] ) /* ignore empty length */
57+ continue ;
58+ if ( endat == pDisp [i ] ) { /* contiguous with the previsious */
5559 dLength += pBlockLength [i ];
5660 endat += pBlockLength [i ];
5761 } else {
@@ -71,26 +75,28 @@ int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const
7175int32_t ompi_datatype_create_hindexed ( int count , const int * pBlockLength , const ptrdiff_t * pDisp ,
7276 const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
7377{
74- ompi_datatype_t * pdt ;
75- int i ;
7678 ptrdiff_t extent , disp , endat ;
79+ ompi_datatype_t * pdt ;
7780 size_t dLength ;
81+ int i ;
7882
79- if ( 0 == count ) {
80- * newType = ompi_datatype_create ( 0 );
81- ompi_datatype_add ( * newType , & ompi_mpi_datatype_null .dt , 0 , 0 , 0 );
82- return OMPI_SUCCESS ;
83+ /* ignore all cases that lead to an empty type */
84+ ompi_datatype_type_size (oldType , & dLength );
85+ for ( i = 0 ; (i < count ) && (0 == pBlockLength [i ]); i ++ ); /* find first non zero */
86+ if ( (i == count ) || (0 == dLength ) ) {
87+ return ompi_datatype_duplicate ( & ompi_mpi_datatype_null .dt , newType );
8388 }
8489
8590 ompi_datatype_type_extent ( oldType , & extent );
86- pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
87- disp = pDisp [0 ];
88- dLength = pBlockLength [0 ];
91+ disp = pDisp [i ];
92+ dLength = pBlockLength [i ];
8993 endat = disp + dLength * extent ;
9094
91- for ( i = 1 ; i < count ; i ++ ) {
92- if ( endat == pDisp [i ] ) {
93- /* contiguous with the previsious */
95+ pdt = ompi_datatype_create ( (count - i ) * (2 + oldType -> super .desc .used ) );
96+ for ( i += 1 ; i < count ; i ++ ) {
97+ if ( 0 == pBlockLength [i ] ) /* ignore empty length */
98+ continue ;
99+ if ( endat == pDisp [i ] ) { /* contiguous with the previsious */
94100 dLength += pBlockLength [i ];
95101 endat += pBlockLength [i ] * extent ;
96102 } else {
@@ -110,21 +116,15 @@ int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const
110116int32_t ompi_datatype_create_indexed_block ( int count , int bLength , const int * pDisp ,
111117 const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
112118{
113- ompi_datatype_t * pdt ;
114- int i ;
115119 ptrdiff_t extent , disp , endat ;
120+ ompi_datatype_t * pdt ;
116121 size_t dLength ;
122+ int i ;
117123
118- ompi_datatype_type_extent ( oldType , & extent );
119124 if ( (count == 0 ) || (bLength == 0 ) ) {
120- if ( 0 == count ) {
121- return ompi_datatype_duplicate (& ompi_mpi_datatype_null .dt , newType );
122- } else {
123- * newType = ompi_datatype_create (1 );
124- ompi_datatype_add ( * newType , oldType , 0 , pDisp [0 ] * extent , extent );
125- return OMPI_SUCCESS ;
126- }
125+ return ompi_datatype_duplicate (& ompi_mpi_datatype_null .dt , newType );
127126 }
127+ ompi_datatype_type_extent ( oldType , & extent );
128128 pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
129129 disp = pDisp [0 ];
130130 dLength = bLength ;
@@ -150,34 +150,29 @@ int32_t ompi_datatype_create_indexed_block( int count, int bLength, const int* p
150150int32_t ompi_datatype_create_hindexed_block ( int count , int bLength , const ptrdiff_t * pDisp ,
151151 const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
152152{
153- ompi_datatype_t * pdt ;
154- int i ;
155153 ptrdiff_t extent , disp , endat ;
154+ ompi_datatype_t * pdt ;
156155 size_t dLength ;
156+ int i ;
157157
158- ompi_datatype_type_extent ( oldType , & extent );
159158 if ( (count == 0 ) || (bLength == 0 ) ) {
160- * newType = ompi_datatype_create (1 );
161- if ( 0 == count )
162- ompi_datatype_add ( * newType , & ompi_mpi_datatype_null .dt , 0 , 0 , 0 );
163- else
164- ompi_datatype_add ( * newType , oldType , 0 , pDisp [0 ] * extent , extent );
165- return OMPI_SUCCESS ;
159+ return ompi_datatype_duplicate (& ompi_mpi_datatype_null .dt , newType );
166160 }
161+ ompi_datatype_type_extent ( oldType , & extent );
167162 pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
168163 disp = pDisp [0 ];
169164 dLength = bLength ;
170- endat = disp + dLength ;
165+ endat = disp + dLength * extent ;
171166 for ( i = 1 ; i < count ; i ++ ) {
172167 if ( endat == pDisp [i ] ) {
173168 /* contiguous with the previsious */
174169 dLength += bLength ;
175- endat += bLength ;
170+ endat += bLength * extent ;
176171 } else {
177172 ompi_datatype_add ( pdt , oldType , dLength , disp , extent );
178173 disp = pDisp [i ];
179174 dLength = bLength ;
180- endat = disp + bLength ;
175+ endat = disp + bLength * extent ;
181176 }
182177 }
183178 ompi_datatype_add ( pdt , oldType , dLength , disp , extent );
0 commit comments