[Mpi-forum] Question about MPI_Alloc_mem
wgropp at illinois.edu
Wed Oct 14 13:52:52 CDT 2020
To be more specific as to the reason, this is the C idiom - it you pass it as a pointer to a pointer, you have to cast it as a void pointer to a pointer. If it is just a void *, C views this as an anonymous pointer, and you can use the address - as in
MPI_Alloc_mem(1000, MPI_INFO_NULL, &intp);
If baseptr is a void**, you need to do this:
MPI_Alloc_mem(1000, MPI_INFO_NULL, (void **)&intp);
I don’t like it either, but this is the choice in C.
Director and Chief Scientist, NCSA
Thomas M. Siebel Chair in Computer Science
University of Illinois Urbana-Champaign
> On Oct 14, 2020, at 12:01 PM, Anthony Skjellum via mpi-forum <mpi-forum at lists.mpi-forum.org> wrote:
> Folks, I know we have had this function for a long time, and I've implemented ports of MPI that actually use it (e.g., with pre-pinned memory). But, I am trying to understand the logic for why baseptr is passed by value, instead of by reference. In C, everything is by value, so the last argument in normal C programs would be void **baseptr.
> The standard has:
> int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr);
> Now, MPICC/GCC takes this with
> void *memory = (void *)0;
> int error = MPI_Alloc_mem(1024, MPI_INFO_NULL, &memory);
> and you get the memory allocated properly.
> What is more, this is incorrect:
> int error = MPI_Alloc_mem(1024, MPI_INFO_NULL, memory);
> although it compiles fine because that is, indeed, the API.
> Why would we have the pointer going in by value, when it is coming out
> as an OUT argument?
> Isn't this plain wrong? void **baseptr means ---> I am passing you the
> address of a void pointer.
> Every viable implementation must do *(void **)baseptr = ...
> when providing the "malloc'd/special" memory. So... why did we fudge
> the C API. Is there some tie-in with the Fortran API?
> Thanks in advance,
> Tony Skjellum
> Anthony Skjellum, PhD
> skjellum at gmail.com <mailto:skjellum at gmail.com>
> Cell: +1-205-807-4968
> mpi-forum mailing list
> mpi-forum at lists.mpi-forum.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mpi-forum