3
3
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4
4
* University Research and Technology
5
5
* 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
7
7
* of Tennessee Research Foundation. All rights
8
8
* reserved.
9
9
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
34
34
int32_t ompi_datatype_create_indexed ( int count , const int * pBlockLength , const int * pDisp ,
35
35
const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
36
36
{
37
- ompi_datatype_t * pdt ;
38
- int i ;
39
37
ptrdiff_t extent , disp , endat ;
38
+ ompi_datatype_t * pdt ;
40
39
size_t dLength ;
40
+ int i ;
41
41
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 ) ) {
43
46
return ompi_datatype_duplicate ( & ompi_mpi_datatype_null .dt , newType );
44
47
}
45
48
46
- disp = pDisp [0 ];
47
- dLength = pBlockLength [0 ];
49
+ disp = pDisp [i ];
50
+ dLength = pBlockLength [i ];
48
51
endat = disp + dLength ;
49
52
ompi_datatype_type_extent ( oldType , & extent );
50
53
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 */
55
59
dLength += pBlockLength [i ];
56
60
endat += pBlockLength [i ];
57
61
} else {
@@ -71,26 +75,28 @@ int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const
71
75
int32_t ompi_datatype_create_hindexed ( int count , const int * pBlockLength , const ptrdiff_t * pDisp ,
72
76
const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
73
77
{
74
- ompi_datatype_t * pdt ;
75
- int i ;
76
78
ptrdiff_t extent , disp , endat ;
79
+ ompi_datatype_t * pdt ;
77
80
size_t dLength ;
81
+ int i ;
78
82
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 );
83
88
}
84
89
85
- 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 ];
90
+ disp = pDisp [i ];
91
+ dLength = pBlockLength [i ];
89
92
endat = disp + dLength * extent ;
93
+ ompi_datatype_type_extent ( oldType , & extent );
90
94
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 */
94
100
dLength += pBlockLength [i ];
95
101
endat += pBlockLength [i ] * extent ;
96
102
} else {
@@ -110,21 +116,15 @@ int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const
110
116
int32_t ompi_datatype_create_indexed_block ( int count , int bLength , const int * pDisp ,
111
117
const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
112
118
{
113
- ompi_datatype_t * pdt ;
114
- int i ;
115
119
ptrdiff_t extent , disp , endat ;
120
+ ompi_datatype_t * pdt ;
116
121
size_t dLength ;
122
+ int i ;
117
123
118
- ompi_datatype_type_extent ( oldType , & extent );
119
124
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 );
127
126
}
127
+ ompi_datatype_type_extent ( oldType , & extent );
128
128
pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
129
129
disp = pDisp [0 ];
130
130
dLength = bLength ;
@@ -150,20 +150,15 @@ int32_t ompi_datatype_create_indexed_block( int count, int bLength, const int* p
150
150
int32_t ompi_datatype_create_hindexed_block ( int count , int bLength , const ptrdiff_t * pDisp ,
151
151
const ompi_datatype_t * oldType , ompi_datatype_t * * newType )
152
152
{
153
- ompi_datatype_t * pdt ;
154
- int i ;
155
153
ptrdiff_t extent , disp , endat ;
154
+ ompi_datatype_t * pdt ;
156
155
size_t dLength ;
156
+ int i ;
157
157
158
- ompi_datatype_type_extent ( oldType , & extent );
159
158
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 );
166
160
}
161
+ ompi_datatype_type_extent ( oldType , & extent );
167
162
pdt = ompi_datatype_create ( count * (2 + oldType -> super .desc .used ) );
168
163
disp = pDisp [0 ];
169
164
dLength = bLength ;
0 commit comments