[Mpi-forum] user-defined reductions and re-entrancy

Balaji, Pavan balaji at anl.gov
Tue Oct 20 11:15:13 CDT 2015

You can't call MPI functions in there, but you can replace the abort with an exit(1).

Each user function is called once per process, so "evil" will always be 1, isn't it?  I'm not sure why reentrance is an issue here.

  -- Pavan

From: mpi-forum on behalf of Jeff Hammond
Reply-To: Main MPI Forum mailing list
Date: Tuesday, October 20, 2015 at 11:02 AM
To: Main MPI Forum mailing list
Subject: [Mpi-forum] user-defined reductions and re-entrancy

Is there anything in the MPI standard preventing this sort of disgusting behavior?

/* user code increments evil once between every call to this function so that it should never fail in single-threaded execution */
static int evil = 0;
MPI_User_function(void* invec, void* inoutvec, int *len, MPI_Datatype *datatype)
  double * in = (double*)invec;
  double * out = (double*)inoutvec;
  if (*datatype == MPI_DOUBLE && (evil%2)==0) {
    for (int i=0; i<*len; i++) out[i] = evil*in[i];
  } else {

My goal is to illustrate a user-defined reduction that is not reentrant.  If you dislike my example, then please mentally replace it with a better one of your own creation :-)

The more general question is, are there any constraints on whether implementations may internally use multiple threads to call user-defined reductions?  I do not see any, but perhaps this is an oversight on my part.



Jeff Hammond
jeff.science at gmail.com<mailto:jeff.science at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20151020/a16b9c7e/attachment-0001.html>

More information about the mpi-forum mailing list