Skip to content

Commit 9f1d313

Browse files
committed
Fix predefined datatype initialization/finalization
There were three bugs. - `ompi_datatype_number_of_predefined_data` was one less because it tracked the last f2c index number which starts with zero. (`ompi_datatype_number_of_predefined_data` is used in the `ompi_datatype_match_size` function and it expects the number, not the index.) - Two `for` loops did not visit `ompi_mpi_count` because the comparison is `<` for the index, not `<=`. - Two `for` loops did not visit four datatypes which were added after `ompi_mpi_count`. And, allow us to add the datatypes not in the monotonically increasing order. Signed-off-by: KAWASHIMA Takahiro <t-kawashima@fujitsu.com>
1 parent 7948278 commit 9f1d313

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ompi/datatype/ompi_datatype_module.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,13 @@ int32_t ompi_datatype_init( void )
543543

544544
#define MOOG(name, index) \
545545
do { \
546-
ompi_mpi_##name.dt.d_f_to_c_index = \
547-
opal_pointer_array_add(&ompi_datatype_f_to_c_table, &ompi_mpi_##name); \
548-
if( ompi_datatype_number_of_predefined_data < (ompi_mpi_##name).dt.d_f_to_c_index ) \
549-
ompi_datatype_number_of_predefined_data = (ompi_mpi_##name).dt.d_f_to_c_index; \
550-
assert( (index) == ompi_mpi_##name.dt.d_f_to_c_index ); \
546+
int rc; \
547+
ompi_mpi_##name.dt.d_f_to_c_index = index; \
548+
rc = opal_pointer_array_set_item(&ompi_datatype_f_to_c_table, \
549+
index, &ompi_mpi_##name); \
550+
assert( rc == OPAL_SUCCESS ); \
551+
if( ompi_datatype_number_of_predefined_data < (ompi_mpi_##name).dt.d_f_to_c_index + 1 ) \
552+
ompi_datatype_number_of_predefined_data = (ompi_mpi_##name).dt.d_f_to_c_index + 1; \
551553
} while(0)
552554

553555
/*
@@ -653,7 +655,7 @@ int32_t ompi_datatype_init( void )
653655
/**
654656
* Now make sure all non-contiguous types are marked as such.
655657
*/
656-
for( i = 0; i < ompi_mpi_count.dt.d_f_to_c_index; i++ ) {
658+
for( i = 0; i < ompi_datatype_number_of_predefined_data; i++ ) {
657659
opal_datatype_t* datatype = (opal_datatype_t*)opal_pointer_array_get_item(&ompi_datatype_f_to_c_table, i );
658660

659661
if( (datatype->ub - datatype->lb) == (ptrdiff_t)datatype->size ) {
@@ -676,7 +678,7 @@ int32_t ompi_datatype_finalize( void )
676678
/* As they are statically allocated they cannot be released.
677679
* But we can call OBJ_DESTRUCT, just to free all internally allocated ressources.
678680
*/
679-
for( int i = 0; i < ompi_mpi_count.dt.d_f_to_c_index; i++ ) {
681+
for( int i = 0; i < ompi_datatype_number_of_predefined_data; i++ ) {
680682
opal_datatype_t* datatype = (opal_datatype_t*)opal_pointer_array_get_item(&ompi_datatype_f_to_c_table, i );
681683
OBJ_DESTRUCT(datatype);
682684
}

0 commit comments

Comments
 (0)