<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">My previous email (probably crossing paths with Tony’s reply) addressed most of this.  The one thing that I want to add is that the API choice made in MPI for the C binding, both in the MPI-1 attribute get functions and here, has nothing to do with the Fortran binding.  These were made to match C’s limitations on anonymous pointers, and to avoid requiring pointer casts. <div class=""><div class=""><br class=""></div><div class="">Bill</div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">William Gropp<br class="">Director and Chief Scientist, NCSA<br class="">Thomas M. Siebel Chair in Computer Science<br class="">University of Illinois Urbana-Champaign</div><br class="Apple-interchange-newline"></div></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Oct 14, 2020, at 2:42 PM, Skjellum, Anthony via mpi-forum <<a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Rolf, the rationale is not clear at all to me: "to facilitate type casting" is self-understood or a canonical term of art. I've been programming in C for 40 years... and I never would write the API as we have done it there.  </div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">For pointers, out arguments are literally truthful: void **ptr is an out argument of a void pointer, and void *ptr is an in argument of a void pointer.</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">{Years ago, before there was void *, we would have written char **ptr for a char out argument (and cast it to whatever type we wanted), and char *ptr for an in point argument. }</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">The fact that a void ** can stand in the place of a void * is clearly a weakened typing in the language, because void * can point at anything (unknown).  Since a void * is a pointer, it can also hold a pointer to a pointer to void, sure.   But the intent of the second * is to remind you that you have an out argument.  And you *must* pass a pointer to a pointer for the API to work in C.</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Somehow this is helping the Fortran and C_PTR API of Fortran, as it states.  So the C API is made this way for convenience of Fortran.</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">The rationale shows the argument with the & to pass the pointer to the API by reference.  But, the rationale is not necessarily normative.  A reasonable person reads the standard,  sees void * and passes the baseptr without the &.  </div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Seems like a bad API to me.</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Tony</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div id="Signature" class=""><div class=""><div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class="">Anthony Skjellum, PhD</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Professor of Computer Science and Chair of Excellence</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">Director, SimCenter</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">University of Tennessee at Chattanooga (UTC)</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><a href="mailto:tony-skjellum@utc.edu" class="">tony-skjellum@utc.edu</a><span class="Apple-converted-space"> </span> [or<span class="Apple-converted-space"> </span><a href="mailto:skjellum@gmail.com" class="">skjellum@gmail.com</a>]</div><div style="margin-top: 0px; margin-bottom: 0px;" class="">cell: 205-807-4968</div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div></div></div></div></div><div id="appendonsend" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div><hr tabindex="-1" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline-block; width: 662.46875px;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span><div id="divRplyFwdMsg" dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>mpi-forum <<a href="mailto:mpi-forum-bounces@lists.mpi-forum.org" class="">mpi-forum-bounces@lists.mpi-forum.org</a>> on behalf of Rolf Rabenseifner via mpi-forum <<a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, October 14, 2020 1:32 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Main MPI Forum mailing list <<a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Rolf Rabenseifner <<a href="mailto:rabenseifner@hlrs.de" class="">rabenseifner@hlrs.de</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [Mpi-forum] Question about MPI_Alloc_mem</font><div class=""> </div></div><div class="BodyFragment" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><font size="2" class=""><span style="font-size: 11pt;" class=""><div class="PlainText">Dear Tony,<span class="Apple-converted-space"> </span><br class=""><br class="">please read MPI-3.1 page 338, lines 36-41.<br class="">Do these lines resolve your question?<br class=""><br class="">Best regards<br class="">Rolf<span class="Apple-converted-space"> </span><br class=""><br class="">----- Original Message -----<br class="">> From: "Main MPI Forum mailing list" <<a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a>><br class="">> To: "Main MPI Forum mailing list" <<a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a>><br class="">> Cc: "Anthony Skjellum" <<a href="mailto:skjellum@gmail.com" class="">skjellum@gmail.com</a>><br class="">> Sent: Wednesday, October 14, 2020 7:01:54 PM<br class="">> Subject: [Mpi-forum] Question about MPI_Alloc_mem<br class=""><br class="">> Folks, I know we have had this function for a long time, and I've implemented<br class="">> ports of MPI that actually use it (e.g., with pre-pinned memory). But, I am<br class="">> trying to understand the logic for why baseptr is passed by value, instead of<br class="">> by reference. In C, everything is by value, so the last argument in normal C<br class="">> programs would be void **baseptr.<br class="">><span class="Apple-converted-space"> </span><br class="">> The standard has:<br class="">> int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr);<br class="">> Now, MPICC/GCC takes this with<br class="">> void *memory = (void *)0;<br class="">> int error = MPI_Alloc_mem(1024, MPI_INFO_NULL, &memory);<br class="">> and you get the memory allocated properly.<br class="">> What is more, this is incorrect:<br class="">> int error = MPI_Alloc_mem(1024, MPI_INFO_NULL, memory);<br class="">> although it compiles fine because that is, indeed, the API.<br class="">> Why would we have the pointer going in by value, when it is coming out<br class="">> as an OUT argument?<br class="">> Isn't this plain wrong?  void **baseptr means ---> I am passing you the<br class="">> address of a void pointer.<br class="">> Every viable implementation must do *(void **)baseptr = ...<br class="">> when providing the "malloc'd/special" memory.  So... why did we fudge<br class="">> the C API.  Is there some tie-in with the Fortran API?<br class="">> Thanks in advance,<br class="">> Tony Skjellum<br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">> --<br class="">> Anthony Skjellum, PhD<br class="">> [<span class="Apple-converted-space"> </span><a href="mailto:skjellum@gmail.com" class="">mailto:skjellum@gmail.com</a><span class="Apple-converted-space"> </span>|<span class="Apple-converted-space"> </span><a href="mailto:skjellum@gmail.com" class="">skjellum@gmail.com</a><span class="Apple-converted-space"> </span>]<br class="">> Cell: +1-205-807-4968<br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">> _______________________________________________<br class="">> mpi-forum mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a><br class="">><span class="Apple-converted-space"> </span><a href="https://lists.mpi-forum.org/mailman/listinfo/mpi-forum" class="">https://lists.mpi-forum.org/mailman/listinfo/mpi-forum</a><br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">Dr. Rolf Rabenseifner . . . . . . . . . .. email<span class="Apple-converted-space"> </span><a href="mailto:rabenseifner@hlrs.de" class="">rabenseifner@hlrs.de</a><span class="Apple-converted-space"> </span>.<br class="">High Performance Computing Center (HLRS) . phone ++49(0)711/685-65530 .<br class="">University of Stuttgart . . . . . . . . .. fax ++49(0)711 / 685-65832 .<br class="">Head of Dpmt Parallel Computing . . .<span class="Apple-converted-space"> </span><a href="http://www.hlrs.de/people/rabenseifner" class="">www.hlrs.de/people/rabenseifner</a><span class="Apple-converted-space"> </span>.<br class="">Nobelstr. 19, D-70550 Stuttgart, Germany . . . . (Office: Room 1.307) .<br class="">_______________________________________________<br class="">mpi-forum mailing list<br class=""><a href="mailto:mpi-forum@lists.mpi-forum.org" class="">mpi-forum@lists.mpi-forum.org</a><br class=""><a href="https://lists.mpi-forum.org/mailman/listinfo/mpi-forum" class="">https://lists.mpi-forum.org/mailman/listinfo/mpi-forum</a><br class=""></div></span></font></div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">mpi-forum mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="mailto:mpi-forum@lists.mpi-forum.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">mpi-forum@lists.mpi-forum.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="https://lists.mpi-forum.org/mailman/listinfo/mpi-forum" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.mpi-forum.org/mailman/listinfo/mpi-forum</a></div></blockquote></div><br class=""></div></div></body></html>