Skip to content

Commit b072453

Browse files
edgargabrielax3l
authored andcommitted
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 8ed533b commit b072453

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
@@ -738,11 +738,12 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
738738
int size_smallest_group = 0;
739739
int num_groups = 0;
740740
int ret = OMPI_SUCCESS;
741-
741+
742742
OMPI_MPI_OFFSET_TYPE max_cci = 0;
743743
OMPI_MPI_OFFSET_TYPE min_cci = 0;
744744

745-
size_new_group = ceil ((float)mca_io_ompio_bytes_per_agg * fh->f_init_procs_per_group/ bytes_per_group);
745+
// integer round up
746+
size_new_group = (int)(mca_io_ompio_bytes_per_agg / bytes_per_group + (mca_io_ompio_bytes_per_agg % bytes_per_group ? 1u : 0u));
746747
size_old_group = fh->f_init_procs_per_group;
747748

748749
ret = mca_io_ompio_split_a_group(fh,
@@ -790,7 +791,7 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
790791
if((max_cci < OMPIO_CONTG_THRESHOLD) &&
791792
(size_new_group < size_old_group)){
792793

793-
size_new_group = floor( (float) (size_new_group + size_old_group ) / 2 );
794+
size_new_group = (size_new_group + size_old_group ) / 2;
794795
ret = mca_io_ompio_split_a_group(fh,
795796
start_offsets_lens,
796797
end_offsets,
@@ -818,7 +819,9 @@ int mca_io_ompio_split_initial_groups(mca_io_ompio_file_t *fh,
818819
(size_new_group < size_old_group)){ //can be a better condition
819820
//monitor the previous iteration
820821
//break if it has not changed.
821-
size_new_group = ceil( (float) (size_new_group + size_old_group ) / 2 );
822+
size_new_group = size_new_group + size_old_group;
823+
// integer round up
824+
size_new_group = size_new_group / 2 + (size_new_group % 2 ? 1 : 0);
822825
ret = mca_io_ompio_split_a_group(fh,
823826
start_offsets_lens,
824827
end_offsets,

0 commit comments

Comments
 (0)