Skip to content

Commit 41e6f55

Browse files
committed
Small optimization on the datatype commit.
This patch fixes the merge of contiguous elements into larger but more compact datatypes, and allows for contiguous elements to have thir blocklen increasing instead of the count. The idea is to always maximize the blocklen, aka. the contiguous part of the datatype. Signed-off-by: George Bosilca <[email protected]>
1 parent c4d0752 commit 41e6f55

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

opal/datatype/opal_datatype_optimize.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ opal_datatype_optimize_short( opal_datatype_t* pData,
163163
if( 0 == last.count ) { /* first data of the datatype */
164164
last = *current;
165165
continue; /* next data */
166+
} else { /* can we merge it in order to decrease count */
167+
if( (ptrdiff_t)last.blocklen * (ptrdiff_t)opal_datatype_basicDatatypes[last.common.type]->size == last.extent ) {
168+
last.extent *= last.count;
169+
last.blocklen *= last.count;
170+
last.count = 1;
171+
}
166172
}
167173

168174
/* are the two elements compatible: aka they have very similar values and they
@@ -176,27 +182,27 @@ opal_datatype_optimize_short( opal_datatype_t* pData,
176182
last.common.type = OPAL_DATATYPE_UINT1;
177183
}
178184

179-
if( 1 == last.count ) {
180-
/* we can ignore the extent of the element with count == 1 and merge them together if their displacements match */
185+
if( (last.extent * (ptrdiff_t)last.count + last.disp) == current->disp ) {
181186
if( 1 == current->count ) {
182-
last.extent = current->disp - last.disp;
183187
last.count++;
184188
continue;
185189
}
186-
/* can we compute a matching displacement ? */
187-
if( (last.disp + current->extent) == current->disp ) {
188-
last.extent = current->extent;
189-
last.count = current->count + 1;
190+
if( last.extent == current->extent ) {
191+
last.count += current->count;
190192
continue;
191193
}
192194
}
193-
if( (last.extent * (ptrdiff_t)last.count + last.disp) == current->disp ) {
195+
if( 1 == last.count ) {
196+
/* we can ignore the extent of the element with count == 1 and merge them together if their displacements match */
194197
if( 1 == current->count ) {
198+
last.extent = current->disp - last.disp;
195199
last.count++;
196200
continue;
197201
}
198-
if( last.extent == current->extent ) {
199-
last.count += current->count;
202+
/* can we compute a matching displacement ? */
203+
if( (last.disp + current->extent) == current->disp ) {
204+
last.extent = current->extent;
205+
last.count = current->count + last.count;
200206
continue;
201207
}
202208
}

opal/datatype/opal_datatype_pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ opal_pack_homogeneous_contig_with_gaps_function( opal_convertor_t* pConv,
121121
* how much we should jump between elements.
122122
*/
123123
assert( (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && ((ptrdiff_t)pData->size != extent) );
124+
assert( pData->opt_desc.used <= 1 );
124125
DO_DEBUG( opal_output( 0, "pack_homogeneous_contig( pBaseBuf %p, iov_count %d )\n",
125126
(void*)pConv->pBaseBuf, *out_size ); );
126127
if( stack[1].type != opal_datatype_uint1.id ) {

0 commit comments

Comments
 (0)