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

Jeff Hammond jeff.science at gmail.com
Tue Oct 20 13:04:24 CDT 2015


Thanks Jed for clarifying. I agree with your modified example. 

The fundamental question here remains: can an implementation internally call user-defined reduction operators from multiple threads at the same time?

Jeff 

Sent from my iPhone

> On Oct 20, 2015, at 10:50 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> 
> "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.
> _______________________________________________
> mpi-forum mailing list
> mpi-forum at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpi-forum



More information about the mpi-forum mailing list