Skip to content

Commit c0db3d9

Browse files
authored
Merge pull request #9856 from EmmanuelBRELLE/fix_roundup_libnbc-4.1.x
v4.1.x: Patched libnbc to not round fractions based on float precision
2 parents 5c932e7 + 95dd739 commit c0db3d9

7 files changed

+15
-8
lines changed

ompi/mca/coll/libnbc/nbc_iallreduce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static inline int allred_sched_diss(int rank, int p, int count, MPI_Datatype dat
366366

367367
root = 0; /* this makes the code for ireduce and iallreduce nearly identical - could be changed to improve performance */
368368
RANK2VRANK(rank, vrank, root);
369-
maxr = (int)ceil((log((double)p)/LOG2));
369+
maxr = ceil_of_log2(p);
370370
/* ensure the result ends up in recvbuf on vrank 0 */
371371
if (0 == (maxr%2)) {
372372
rbuf = (void *)(-gap);

ompi/mca/coll/libnbc/nbc_ibarrier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int nbc_barrier_init(struct ompi_communicator_t *comm, ompi_request_t **
4545
return OMPI_ERR_OUT_OF_RESOURCE;
4646
}
4747

48-
maxround = (int)ceil((log((double)p)/LOG2)-1);
48+
maxround = ceil_of_log2(p) -1;
4949

5050
for (int round = 0 ; round <= maxround ; ++round) {
5151
sendpeer = (rank + (1 << round)) % p;

ompi/mca/coll/libnbc/nbc_ibcast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ int ompi_coll_libnbc_ibcast(void *buffer, int count, MPI_Datatype datatype, int
238238
static inline int bcast_sched_binomial(int rank, int p, int root, NBC_Schedule *schedule, void *buffer, int count, MPI_Datatype datatype) {
239239
int maxr, vrank, peer, res;
240240

241-
maxr = (int)ceil((log((double)p)/LOG2));
241+
maxr = ceil_of_log2(p);
242242

243243
RANK2VRANK(rank, vrank, root);
244244

ompi/mca/coll/libnbc/nbc_internal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@
5151
extern "C" {
5252
#endif
5353

54-
/* log(2) */
55-
#define LOG2 0.69314718055994530941
54+
/* Dividing very close floats may lead to unexpected roundings */
55+
static inline int
56+
ceil_of_log2 (int val) {
57+
int ret = 0;
58+
while (1 << ret < val) {
59+
ret ++;
60+
}
61+
return ret;
62+
}
5663

5764
/* true/false */
5865
#define true 1

ompi/mca/coll/libnbc/nbc_ireduce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static inline int red_sched_binomial (int rank, int p, int root, const void *sen
367367
vroot = 0;
368368
}
369369
RANK2VRANK(rank, vrank, vroot);
370-
maxr = (int)ceil((log((double)p)/LOG2));
370+
maxr = ceil_of_log2(p);
371371

372372
if (rank != root) {
373373
inplace = 0;

ompi/mca/coll/libnbc/nbc_ireduce_scatter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int nbc_reduce_scatter_init(const void* sendbuf, void* recvbuf, const int
8383
return nbc_get_noop_request(persistent, request);
8484
}
8585

86-
maxr = (int) ceil ((log((double) p) / LOG2));
86+
maxr = ceil_of_log2(p);
8787

8888
span = opal_datatype_span(&datatype->super, count, &gap);
8989
span_align = OPAL_ALIGN(span, datatype->super.align, ptrdiff_t);

ompi/mca/coll/libnbc/nbc_ireduce_scatter_block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int nbc_reduce_scatter_block_init(const void* sendbuf, void* recvbuf, int
6868
return OMPI_ERR_OUT_OF_RESOURCE;
6969
}
7070

71-
maxr = (int)ceil((log((double)p)/LOG2));
71+
maxr = ceil_of_log2(p);
7272

7373
count = p * recvcount;
7474

0 commit comments

Comments
 (0)