60 likes | 231 Views
const in the C bindings. MPI Forum meeting 1/2008. Background:
E N D
const in the C bindings MPI Forum meeting1/2008
Background: The const keyword in C defines a contract between the library implementer and the library user. Using the const keyword the library contracts that it will not change its input object. This contract enables some compile-time optimization, but more important it provides clearer and const-correct interface to the library user. (more on http://en.wikipedia.org/wiki/Const_correctness) The MPI C bindings as defined by the MPI 1.1 & 2.0 standards are missing the const keyword for many of the input only parameters. • Proposal: Add the const keyword to the API’s listed below.
Why not? • It is a change, and as a change to the standard requires a good reason • This change can break existing application at compile time • No runtime or link-time break
myth • Compiler optimization would break correct (and incorrect code) Buf[3] MPI_Irecv(buf[2]) X = exp(buf[2]) MPI_Send(buf[1]&buf[3]) y = exp(buf[2]) • consider Buf[3] MPI_Irecv(buf[2]) X = exp(buf[2]) foo(); y = exp(buf[2])
Why yes? • Better contract for the interface • Developers don’t like to cast away their const’ness • Enables better static analysis tools • Enables sending constants in the .TEXT section (read only) (without casting) • Example, MPI_Add_error_string(77, “my error”) • Will be placed in the writable .DATA section (initialized data)
Work group list • Erez Haba erezh@microsoft.com • David Gingold david.gingold@sicortex.com • Quincey Koziol koziol@hdfgroup.org • George Bosilca bosilca@eecs.utk.edu • Darius Buntinas buntinas@mcs.anl.gov • Dries Kimpe Dries.Kimpe@cs.kuleuven.be • Pavan Balaji balaji@mcs.anl.gov