Skip to content

Commit f1a065f

Browse files
authored
Merge pull request #6945 from bosilca/topic/ddt_optimize
Small optimization on the datatype commit.
2 parents c4d0752 + 82d6322 commit f1a065f

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
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 ) {

test/datatype/to_self.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ extern void ompi_datatype_dump( MPI_Datatype ddt );
2424
#define MPI_DDT_DUMP(ddt)
2525
#endif /* OPEN_MPI */
2626

27+
static MPI_Datatype
28+
create_merged_contig_with_gaps(int count) /* count of the basic datatype */
29+
{
30+
int array_of_blocklengths[] = {1, 1, 1};
31+
MPI_Aint array_of_displacements[] = {0, 8, 16};
32+
MPI_Datatype array_of_types[] = {MPI_DOUBLE, MPI_LONG, MPI_CHAR};
33+
MPI_Datatype type;
34+
35+
MPI_Type_create_struct(3, array_of_blocklengths,
36+
array_of_displacements, array_of_types,
37+
&type);
38+
if( 1 < count ) {
39+
MPI_Datatype temp = type;
40+
MPI_Type_contiguous(count, temp, &type);
41+
}
42+
MPI_Type_commit(&type);
43+
MPI_DDT_DUMP( type );
44+
return type;
45+
}
46+
2747
/* Create a non-contiguous resized datatype */
2848
struct structure {
2949
double not_transfered;
@@ -183,11 +203,12 @@ create_indexed_gap_optimized_ddt( void )
183203
/********************************************************************
184204
*******************************************************************/
185205

186-
#define DO_CONTIG 0x00000001
187-
#define DO_CONSTANT_GAP 0x00000002
188-
#define DO_INDEXED_GAP 0x00000004
189-
#define DO_OPTIMIZED_INDEXED_GAP 0x00000008
190-
#define DO_STRUCT_CONSTANT_GAP_RESIZED 0x00000010
206+
#define DO_CONTIG 0x00000001
207+
#define DO_CONSTANT_GAP 0x00000002
208+
#define DO_INDEXED_GAP 0x00000004
209+
#define DO_OPTIMIZED_INDEXED_GAP 0x00000008
210+
#define DO_STRUCT_CONSTANT_GAP_RESIZED 0x00000010
211+
#define DO_STRUCT_MERGED_WITH_GAP_RESIZED 0x00000020
191212

192213
#define DO_PACK 0x01000000
193214
#define DO_UNPACK 0x02000000
@@ -483,7 +504,7 @@ static int do_test_for_ddt( int doop, MPI_Datatype sddt, MPI_Datatype rddt, int
483504

484505
int main( int argc, char* argv[] )
485506
{
486-
int run_tests = 0xffff; /* do all datatype tests by default */
507+
int run_tests = DO_STRUCT_MERGED_WITH_GAP_RESIZED; /* do all datatype tests by default */
487508
int rank, size;
488509
MPI_Datatype ddt;
489510

@@ -544,6 +565,14 @@ int main( int argc, char* argv[] )
544565
MPI_Type_free( &ddt );
545566
}
546567

568+
if( run_tests & DO_STRUCT_MERGED_WITH_GAP_RESIZED ) {
569+
printf( "\nstruct constant gap resized\n\n" );
570+
ddt = create_merged_contig_with_gaps( 1 );
571+
MPI_DDT_DUMP( ddt );
572+
do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH );
573+
MPI_Type_free( &ddt );
574+
}
575+
547576
MPI_Finalize ();
548577
exit(0);
549578
}

0 commit comments

Comments
 (0)