<div dir="ltr">I do not understand why creating a wrapper function dynamically at run time creates a portability problem. Can you elaborate?<br><br>Thanks,<div><br>Jeff<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 10, 2017 at 2:23 AM, Phil Ruffwind <span dir="ltr"><<a href="mailto:rf@rufflewind.com" target="_blank">rf@rufflewind.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am experimenting with an interface for doing generic vector<br>
operations, which would have MPI as a potential backend. To implement a<br>
reduce over a user-provided function, I would wrap their function inside<br>
a wrapper compatible with the MPI_User_function signature, and then call<br>
MPI_Op_create. But I can only make a single wrapper as standard C does<br>
not provide a way to create function pointers out of thin air, so the<br>
pointer to user's original function needs to be somehow passed in as<br>
“context” into the wrapper.<br>
<br>
Normally, C APIs that accept callbacks also accept an opaque void<br>
pointer which is then passed into the callback function – this would<br>
serve as the context. But I do not see that in the declaration of<br>
MPI_User_function:<br>
<br>
typedef void MPI_User_function(void *invec,<br>
void *inoutvec,<br>
int *len,<br>
MPI_Datatype *datatype);<br>
<br>
This leaves me with several undesirable options:<br>
<br>
- Use global data, which, even ignoring the thread-safety implications,<br>
means that I can only wrap a single user function at any given time.<br>
<br>
- Use thread-local data, which I'm not sure is sensible either since<br>
there's no guarantee MPI is going to call my wrapper function on the<br>
same thread (and it still has the one-instance limitation).<br>
<br>
- Use invec or inoutvec to pass in the contextual data, which is awkward<br>
because it means now the data is complicated by the addition of<br>
unrelated contextual data, and it also slightly bloats the data with<br>
stuff that needn't be transmitted.<br>
<br>
- Create a wrapper function dynamically at run time, which means<br>
throwing away portability.<br>
<br>
Is there another more sensible option for this dilemma?<br>
<br>
Thanks,<br>
Phil<br>
______________________________<wbr>_________________<br>
mpi-forum mailing list<br>
<a href="mailto:mpi-forum@lists.mpi-forum.org">mpi-forum@lists.mpi-forum.org</a><br>
<a href="https://lists.mpi-forum.org/mailman/listinfo/mpi-forum" rel="noreferrer" target="_blank">https://lists.mpi-forum.org/<wbr>mailman/listinfo/mpi-forum</a></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Jeff Hammond<br><a href="mailto:jeff.science@gmail.com" target="_blank">jeff.science@gmail.com</a><br><a href="http://jeffhammond.github.io/" target="_blank">http://jeffhammond.github.io/</a></div>
</div></div></div>