Skip to content

Commit a91fab8

Browse files
common/ompio: possible rounding issue
Similar to #6286 rounding number of bytes into a single precision floating point value to round up the result of a division is a potential risk due to rounding errors. - remove floating point operations for `round up` - removes floating point conversion for round down (native behavior of integer division) Signed-off-by: René Widera <r.widera@hzdr.de>
1 parent 387b2ff commit a91fab8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ompi/mca/common/ompio/common_ompio_aggregators.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,14 @@ int mca_common_ompio_split_initial_groups(ompio_file_t *fh,
896896
int size_smallest_group = 0;
897897
int num_groups = 0;
898898
int ret = OMPI_SUCCESS;
899+
OMPI_MPI_COUNT_TYPE bytes_per_agg_group = 0;
899900

900901
OMPI_MPI_OFFSET_TYPE max_cci = 0;
901902
OMPI_MPI_OFFSET_TYPE min_cci = 0;
902903

903-
size_new_group = ceil ((float)OMPIO_MCA_GET(fh, bytes_per_agg) * fh->f_init_procs_per_group/ bytes_per_group);
904+
bytes_per_agg_group = (OMPI_MPI_COUNT_TYPE)OMPIO_MCA_GET(fh, bytes_per_agg);
905+
// integer round up
906+
size_new_group = (int)(bytes_per_agg_group / bytes_per_group + (bytes_per_agg_group % bytes_per_group ? 1u : 0u));
904907
size_old_group = fh->f_init_procs_per_group;
905908

906909
ret = mca_common_ompio_split_a_group(fh,
@@ -948,7 +951,7 @@ int mca_common_ompio_split_initial_groups(ompio_file_t *fh,
948951
if((max_cci < OMPIO_CONTG_THRESHOLD) &&
949952
(size_new_group < size_old_group)){
950953

951-
size_new_group = floor( (float) (size_new_group + size_old_group ) / 2 );
954+
size_new_group = (size_new_group + size_old_group ) / 2;
952955
ret = mca_common_ompio_split_a_group(fh,
953956
start_offsets_lens,
954957
end_offsets,
@@ -976,7 +979,9 @@ int mca_common_ompio_split_initial_groups(ompio_file_t *fh,
976979
(size_new_group < size_old_group)){ //can be a better condition
977980
//monitor the previous iteration
978981
//break if it has not changed.
979-
size_new_group = ceil( (float) (size_new_group + size_old_group ) / 2 );
982+
size_new_group = size_new_group + size_old_group;
983+
// integer round up
984+
size_new_group = size_new_group / 2 + (size_new_group % 2 ? 1 : 0);
980985
ret = mca_common_ompio_split_a_group(fh,
981986
start_offsets_lens,
982987
end_offsets,

0 commit comments

Comments
 (0)