Chris@10
|
1 /*
|
Chris@10
|
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
|
Chris@10
|
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
|
Chris@10
|
4 *
|
Chris@10
|
5 * This program is free software; you can redistribute it and/or modify
|
Chris@10
|
6 * it under the terms of the GNU General Public License as published by
|
Chris@10
|
7 * the Free Software Foundation; either version 2 of the License, or
|
Chris@10
|
8 * (at your option) any later version.
|
Chris@10
|
9 *
|
Chris@10
|
10 * This program is distributed in the hope that it will be useful,
|
Chris@10
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@10
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@10
|
13 * GNU General Public License for more details.
|
Chris@10
|
14 *
|
Chris@10
|
15 * You should have received a copy of the GNU General Public License
|
Chris@10
|
16 * along with this program; if not, write to the Free Software
|
Chris@10
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Chris@10
|
18 *
|
Chris@10
|
19 */
|
Chris@10
|
20
|
Chris@10
|
21 #include "fftw3-mpi.h"
|
Chris@10
|
22 #include "ifftw-mpi.h"
|
Chris@10
|
23 #include <string.h>
|
Chris@10
|
24
|
Chris@10
|
25 #if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_INT
|
Chris@10
|
26 # define FFTW_MPI_SIZE_T MPI_UNSIGNED
|
Chris@10
|
27 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG
|
Chris@10
|
28 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG
|
Chris@10
|
29 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG
|
Chris@10
|
30 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG_LONG
|
Chris@10
|
31 #else
|
Chris@10
|
32 # error MPI type for size_t is unknown
|
Chris@10
|
33 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG
|
Chris@10
|
34 #endif
|
Chris@10
|
35
|
Chris@10
|
36 /* Import wisdom from all processes to process 0, as prelude to
|
Chris@10
|
37 exporting a single wisdom file (this is convenient when we are
|
Chris@10
|
38 running on identical processors, to avoid the annoyance of having
|
Chris@10
|
39 per-process wisdom files). In order to make the time for this
|
Chris@10
|
40 operation logarithmic in the number of processors (rather than
|
Chris@10
|
41 linear), we employ a tree reduction algorithm. This means that the
|
Chris@10
|
42 wisdom is modified on processes other than root, which shouldn't
|
Chris@10
|
43 matter in practice. */
|
Chris@10
|
44 void XM(gather_wisdom)(MPI_Comm comm_)
|
Chris@10
|
45 {
|
Chris@10
|
46 MPI_Comm comm, comm2;
|
Chris@10
|
47 int my_pe, n_pes;
|
Chris@10
|
48 char *wis;
|
Chris@10
|
49 size_t wislen;
|
Chris@10
|
50 MPI_Status status;
|
Chris@10
|
51
|
Chris@10
|
52 MPI_Comm_dup(comm_, &comm);
|
Chris@10
|
53 MPI_Comm_rank(comm, &my_pe);
|
Chris@10
|
54 MPI_Comm_size(comm, &n_pes);
|
Chris@10
|
55
|
Chris@10
|
56 if (n_pes > 2) { /* recursively split into even/odd processes */
|
Chris@10
|
57 MPI_Comm_split(comm, my_pe % 2, my_pe, &comm2);
|
Chris@10
|
58 XM(gather_wisdom)(comm2);
|
Chris@10
|
59 MPI_Comm_free(&comm2);
|
Chris@10
|
60 }
|
Chris@10
|
61 if (n_pes > 1 && my_pe < 2) { /* import process 1 -> 0 */
|
Chris@10
|
62 if (my_pe == 1) {
|
Chris@10
|
63 wis = X(export_wisdom_to_string)();
|
Chris@10
|
64 wislen = strlen(wis) + 1;
|
Chris@10
|
65 MPI_Send(&wislen, 1, FFTW_MPI_SIZE_T, 0, 111, comm);
|
Chris@10
|
66 MPI_Send(wis, wislen, MPI_CHAR, 0, 222, comm);
|
Chris@10
|
67 free(wis);
|
Chris@10
|
68 }
|
Chris@10
|
69 else /* my_pe == 0 */ {
|
Chris@10
|
70 MPI_Recv(&wislen, 1, FFTW_MPI_SIZE_T, 1, 111, comm, &status);
|
Chris@10
|
71 wis = (char *) MALLOC(wislen * sizeof(char), OTHER);
|
Chris@10
|
72 MPI_Recv(wis, wislen, MPI_CHAR, 1, 222, comm, &status);
|
Chris@10
|
73 if (!X(import_wisdom_from_string)(wis))
|
Chris@10
|
74 MPI_Abort(comm, 1);
|
Chris@10
|
75 X(ifree)(wis);
|
Chris@10
|
76 }
|
Chris@10
|
77 }
|
Chris@10
|
78 MPI_Comm_free(&comm);
|
Chris@10
|
79 }
|
Chris@10
|
80
|
Chris@10
|
81 /* broadcast wisdom from process 0 to all other processes; this
|
Chris@10
|
82 is useful so that we can import wisdom once and not worry
|
Chris@10
|
83 about parallel I/O or process-specific wisdom, although of
|
Chris@10
|
84 course it assumes that all the processes have identical
|
Chris@10
|
85 performance characteristics (i.e. identical hardware). */
|
Chris@10
|
86 void XM(broadcast_wisdom)(MPI_Comm comm_)
|
Chris@10
|
87 {
|
Chris@10
|
88 MPI_Comm comm;
|
Chris@10
|
89 int my_pe;
|
Chris@10
|
90 char *wis;
|
Chris@10
|
91 size_t wislen;
|
Chris@10
|
92
|
Chris@10
|
93 MPI_Comm_dup(comm_, &comm);
|
Chris@10
|
94 MPI_Comm_rank(comm, &my_pe);
|
Chris@10
|
95
|
Chris@10
|
96 if (my_pe != 0) {
|
Chris@10
|
97 MPI_Bcast(&wislen, 1, FFTW_MPI_SIZE_T, 0, comm);
|
Chris@10
|
98 wis = (char *) MALLOC(wislen * sizeof(char), OTHER);
|
Chris@10
|
99 MPI_Bcast(wis, wislen, MPI_CHAR, 0, comm);
|
Chris@10
|
100 if (!X(import_wisdom_from_string)(wis))
|
Chris@10
|
101 MPI_Abort(comm, 1);
|
Chris@10
|
102 X(ifree)(wis);
|
Chris@10
|
103 }
|
Chris@10
|
104 else /* my_pe == 0 */ {
|
Chris@10
|
105 wis = X(export_wisdom_to_string)();
|
Chris@10
|
106 wislen = strlen(wis) + 1;
|
Chris@10
|
107 MPI_Bcast(&wislen, 1, FFTW_MPI_SIZE_T, 0, comm);
|
Chris@10
|
108 MPI_Bcast(wis, wislen, MPI_CHAR, 0, comm);
|
Chris@10
|
109 X(free)(wis);
|
Chris@10
|
110 }
|
Chris@10
|
111 MPI_Comm_free(&comm);
|
Chris@10
|
112 }
|