Skip to content

Commit 2fd2a12

Browse files
authored
Merge pull request #6344 from edgargabriel/pr/v3.1.x-floating-point-division-problem
Pr/v3.1.x floating point division problem
2 parents 6061a45 + 880e184 commit 2fd2a12

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

ompi/mca/common/ompio/common_ompio_file_read.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
12+
* Copyright (c) 2008-2019 University of Houston. All rights reserved.
13+
* Copyright (c) 2018 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -34,6 +36,7 @@
3436
#include "ompi/mca/io/ompio/io_ompio_request.h"
3537
#include "math.h"
3638
#include <unistd.h>
39+
#include <math.h>
3740

3841
/* Read and write routines are split into two interfaces.
3942
** The
@@ -99,8 +102,8 @@ int mca_common_ompio_file_read (mca_io_ompio_file_t *fh,
99102
else {
100103
bytes_per_cycle = mca_io_ompio_cycle_buffer_size;
101104
}
102-
cycles = ceil((float)max_data/bytes_per_cycle);
103-
105+
cycles = ceil((double)max_data/bytes_per_cycle);
106+
104107
#if 0
105108
printf ("Bytes per Cycle: %d Cycles: %d max_data:%d \n",bytes_per_cycle, cycles, max_data);
106109
#endif

ompi/mca/common/ompio/common_ompio_file_write.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
13-
* Copyright (c) 2015-2017 Research Organization for Information Science
12+
* Copyright (c) 2008-2019 University of Houston. All rights reserved.
13+
* Copyright (c) 2015-2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* $COPYRIGHT$
1616
*
@@ -34,6 +34,7 @@
3434
#include "ompi/mca/io/ompio/io_ompio_request.h"
3535
#include "math.h"
3636
#include <unistd.h>
37+
#include <math.h>
3738

3839
int mca_common_ompio_file_write (mca_io_ompio_file_t *fh,
3940
const void *buf,
@@ -76,7 +77,7 @@ int mca_common_ompio_file_write (mca_io_ompio_file_t *fh,
7677
else {
7778
bytes_per_cycle = mca_io_ompio_cycle_buffer_size;
7879
}
79-
cycles = ceil((float)max_data/bytes_per_cycle);
80+
cycles = ceil((double)max_data/bytes_per_cycle);
8081

8182
#if 0
8283
printf ("Bytes per Cycle: %d Cycles: %d\n", bytes_per_cycle, cycles);

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)