1 /*
2  * Copyright (c) 2003, 2007-14 Matteo Frigo
3  * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  */
20 
21 #include "ifftw-mpi.h"
22 
23 /* During planning, if any process fails to create a plan then
24    all of the processes must fail.  This synchronization is implemented
25    by the following routine.
26 
27    Instead of
28         if (failure) goto nada;
29    we instead do:
30         if (any_true(failure, comm)) goto nada;
31 */
32 
XM(any_true)33 int XM(any_true)(int condition, MPI_Comm comm)
34 {
35      int result;
36      MPI_Allreduce(&condition, &result, 1, MPI_INT, MPI_LOR, comm);
37      return result;
38 }
39 
40 /***********************************************************************/
41 
42 #if defined(FFTW_DEBUG)
43 /* for debugging, we include an assertion to make sure that
44    MPI problems all produce equal hashes, as checked by this routine: */
45 
XM(md5_equal)46 int XM(md5_equal)(md5 m, MPI_Comm comm)
47 {
48      unsigned long s0[4];
49      int i, eq_me, eq_all;
50 
51      X(md5end)(&m);
52      for (i = 0; i < 4; ++i) s0[i] = m.s[i];
53      MPI_Bcast(s0, 4, MPI_UNSIGNED_LONG, 0, comm);
54      for (i = 0; i < 4 && s0[i] == m.s[i]; ++i) ;
55      eq_me = i == 4;
56      MPI_Allreduce(&eq_me, &eq_all, 1, MPI_INT, MPI_LAND, comm);
57      return eq_all;
58 }
59 #endif
60