[Mpi-22] please review - Send Buffer Access (ticket #45)

Dave Goodell goodell at [hidden]
Wed Dec 10 14:43:26 CST 2008



On Dec 10, 2008, at 12:44 PM, Richard Treumann wrote:
> I also think putting the compiler attribute "const" on a send buffer  
> parameter should be voted down.
>
> The formal argument to a send seen by the compiler may or may not  
> correspond to the buffer. The datatype offsets play a role too. This  
> most obvious case is when MPI_BOTTOM is the send argument but there  
> are other examples.
> MPI_Send(&(array[0]) ...)
> MPI_Send(array,....)
> MPI_Send(&var, ....)
> MPI_Send(MPI_BOTTOM, ......)
> are all valid ways of sending the content of array[10] when combined  
> with a suitable datatype.
> (for the "var" example we would need a datatype that set MPI_LB at  
> addr(var) and used ( addr(array[10]-addr(var) ) as a displacement.  
> Weird but valid.)
>
> The complier optimizations that can come from adding "const" are  
> probably small. The const attribute is semantically inaccurate if we  
> consider MPI_BOTTOM to represent the entire memory array. Every  
> subroutine call alters some portions of memory. I presume the  
> compiler just recognizes that it has no idea what range MPI_BOTTOM  
> represents and ignores the "const".
>
Dick,

IMO the most compelling reason to add const to the the C bindings has  
nothing to do with compiler optimizations.  This is a usability issue  
for compilers that enforce const-correctness.  If our bindings are  
incorrectly missing const this will force callers to cast away any  
const-qualifier prior to the call to MPI_Send (and similar).  This is  
extremely irritating to users and tends to make the code look a fair  
bit uglier.  As const is more commonly used by programmers and  
enforced by compilers this will be a barrier to MPI adoption and use,  
particularly by library writers.

Also our lack of const-ness is worse than the send buffer restriction  
in the sense that this is more likely to frustrate experienced  
programmers who are "doing the right thing" rather than MPI rookies.

As Erez has already mentioned, all of your examples should be  
compatible with a const-ified MPI C binding.

-Dave



More information about the Mpi-22 mailing list