Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: [OMPI devel] RFC: Eliminate opal_round_up_to_nearest_pow2()
From: Eugene Loh (Eugene.Loh_at_[hidden])
Date: 2009-01-15 16:39:50


I don't know what scope of changes require RFCs, but here's a trivial
change.

==================================================

RFC: Eliminate opal_round_up_to_nearest_pow2().

WHAT: Eliminate the function opal_round_up_to_nearest_pow2().

WHY: It's poorly written. A clean rewrite would take only
one line of code, which is best written in-place rather than
making a function call. Currently, there is only one call
site, and I expect it to go away. Similar code already inlines
such computation rather than calling this obscure, unused function.

WHERE: opal/util

WHEN: Upon acceptance. For 1.4.

TIMEOUT: January 30, 2009.

==================================================

WHY (details):

The function opal_round_up_to_nearest_pow2() is defined in
opal/util/pow2.c and is declared in the corresponding include
file. It returns the calling argument rounded up to the
nearest power of 2.

This code is difficult to read. That is, it is difficult to
reason about the code's correctness or range of validity or
its behavior outside the range of validity. Meanwhile, it
offers no compelling advantage -- e.g., fast performance or
increased robustness. It is called by only one site, which
is going away.

To use the existing function, one must know of its existence,
include the proper header file, and make the appropriate function
call.

In contrast, a cleanly written version of this code takes only
one line of code. Hence, calling sites are cleaner and faster
if they simply in-line this computation. Further, such code is
customizable (e.g., round down to a power of 2). Most "round to
power of 2" computations in OMPI today already simply implement
this computation themselves rather than calling this obscure
function. E.g., search on "pow2" in
ompi/mca/coll/tuned/coll_tuned_decision_fixed.c.

WHAT (details):

- Remove the file opal/util/pow2.c.

- Remove the file opal/util/pow2.h.

- In opal/util/Makefile.am, remove pow2.h and pow2.c

- In ompi/class/ompi_circular_buffer_fifo.h, if the call
  to opal_round_up_to_nearest_pow2() has not already been
  removed, then remove

     #include "opal/util/pow2.h"

  and replace

     size = opal_round_up_to_nearest_pow2(size_of_fifo);

  with

     size = 1;
     while ( size < size_of_fifo)
         size <<= 1;

  or the even more compact

     for (size = 1; size < size_of_fifo; size <<= 1);