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

Jed Brown jedbrown at mcs.anl.gov
Tue Oct 20 12:50:34 CDT 2015


"Balaji, Pavan" <balaji at anl.gov> writes:

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

MPI-3.0 p184: "MPI_ABORT may be called inside the function in case of an error."

> 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.

Jeff said "user code increments evil once between every call to this
function so that it should never fail in single-threaded execution".

A self-contained rendition:

void User_reduce(void* invec, void* inoutvec, int *len, MPI_Datatype *datatype)
{
  static int evil = 0;
  double * in = (double*)invec;
  double * out = (double*)inoutvec;
  if (*datatype == MPI_DOUBLE && (++evil%2) == 1) {
    for (int i=0; i<*len; i++) out[i] = evil*in[i];
    evil++;
  } else {
    MPI_Abort(1,MPI_COMM_WORLD);
  }
}

The results certainly depend on how an implementation segments a buffer
and on which process the reduction is called.  Additionally, calling the
reduction from multiple threads may cause a non-deterministic abort.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20151020/86e33911/attachment-0001.pgp>


More information about the mpi-forum mailing list