Skip to content

Commit 880e184

Browse files
committed
io/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 <[email protected]> Note: a direct cherry pick of commit a91fab8 is not possible, due to structural differences between the the 3.1.x and the master/v4.0.x branch. This commit is the equivalent of commit a91fab8. Signed-off-by: Edgar Gabriel <[email protected]>
1 parent fbb1112 commit 880e184

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ompi/mca/io/ompio/io_ompio_aggregators.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,12 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
865865
int size_smallest_group = 0;
866866
int num_groups = 0;
867867
int ret = OMPI_SUCCESS;
868-
868+
869869
OMPI_MPI_OFFSET_TYPE max_cci = 0;
870870
OMPI_MPI_OFFSET_TYPE min_cci = 0;
871871

872-
size_new_group = ceil ((float)mca_io_ompio_bytes_per_agg * fh->f_init_procs_per_group/ bytes_per_group);
872+
// integer round up
873+
size_new_group = (int)(mca_io_ompio_bytes_per_agg / bytes_per_group + (mca_io_ompio_bytes_per_agg % bytes_per_group ? 1u : 0u));
873874
size_old_group = fh->f_init_procs_per_group;
874875

875876
ret = mca_io_ompio_split_a_group(fh,
@@ -917,7 +918,7 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
917918
if((max_cci < OMPIO_CONTG_THRESHOLD) &&
918919
(size_new_group < size_old_group)){
919920

920-
size_new_group = floor( (float) (size_new_group + size_old_group ) / 2 );
921+
size_new_group = (size_new_group + size_old_group ) / 2;
921922
ret = mca_io_ompio_split_a_group(fh,
922923
start_offsets_lens,
923924
end_offsets,
@@ -945,7 +946,9 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
945946
(size_new_group < size_old_group)){ //can be a better condition
946947
//monitor the previous iteration
947948
//break if it has not changed.
948-
size_new_group = ceil( (float) (size_new_group + size_old_group ) / 2 );
949+
size_new_group = size_new_group + size_old_group;
950+
// integer round up
951+
size_new_group = size_new_group / 2 + (size_new_group % 2 ? 1 : 0);
949952
ret = mca_io_ompio_split_a_group(fh,
950953
start_offsets_lens,
951954
end_offsets,

0 commit comments

Comments
 (0)