Subject: Re: [OMPI docs] Small note about MPI_Buffer_detach
From: Jeff Squyres (jsquyres) (jsquyres_at_[hidden])
Date: 2015-02-21 09:54:58


The MPI 3.0 standard gives some illumination here -- see section 3.6, page 45, right after the description of MPI_BUFFER_DETACH (note that the C++ bindings have been removed from MPI-3.0, which is why they are not described here):

-----
Advice to users. Even though the C functions MPI_Buffer_attach and MPI_Buffer_detach both have a first argument of type void*, these arguments are used differently: A pointer to the buffer is passed to MPI_Buffer_attach; the address of the pointer is passed to MPI_Buffer_detach, so that this call can return the pointer value. In Fortran with the mpi module or mpif.h, the type of the buffer_addr argument is wrongly defined and the argument is therefore unused. In Fortran with the mpi_f08 module, the address of the buffer is returned as TYPE(C_PTR), see also Example 8.1 on page 341 about the use of C_PTR pointers. (End of advice to users.)

Rationale. Both arguments are defined to be of type void* (rather than
void* and void**, respectively), so as to avoid complex type casts. E.g., in the last example, &buff, which is of type char**, can be passed as argument to MPI_Buffer_detach without type casting. If the formal parameter had type void** then we would need a type cast before and after the call. (End of rationale.)
-----

> On Feb 20, 2015, at 9:00 AM, Maximilian <maxinator333_at_[hidden]> wrote:
>
> Hello,
>
> I understand, that MPI_Buffer_detach returns the buffer address in buf. For that I do understand the C++ syntax:
> int Detach_buffer(void*& buffer)
> which is a call by reference of a void*. But I find the C-Syntax misleading:
> int MPI_Buffer_detach(void *buf, int *size)
> Here a void pointer is given. It could be thought that the void* to the buffer is copied to that function, meaning there would be no return of the buffer address. I think it should read:
> int MPI_Buffer_detach(void **buf, int *size)
> for that reason.
>
>
> _______________________________________________
> docs mailing list
> docs_at_[hidden]
> Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/docs
> Searchable archives: http://www.open-mpi.org/community/lists/docs/2015/02/index.php

-- 
Jeff Squyres
jsquyres_at_[hidden]
For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/