comparison src/fftw-3.3.3/mpi/transpose-problem.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 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 "mpi-transpose.h"
22
23 static void destroy(problem *ego_)
24 {
25 problem_mpi_transpose *ego = (problem_mpi_transpose *) ego_;
26 MPI_Comm_free(&ego->comm);
27 X(ifree)(ego_);
28 }
29
30 static void hash(const problem *p_, md5 *m)
31 {
32 const problem_mpi_transpose *p = (const problem_mpi_transpose *) p_;
33 int i;
34 X(md5puts)(m, "mpi-transpose");
35 X(md5int)(m, p->I == p->O);
36 /* don't include alignment -- may differ between processes
37 X(md5int)(m, X(alignment_of)(p->I));
38 X(md5int)(m, X(alignment_of)(p->O));
39 ... note that applicability of MPI plans does not depend
40 on alignment (although optimality may, in principle). */
41 X(md5INT)(m, p->vn);
42 X(md5INT)(m, p->nx);
43 X(md5INT)(m, p->ny);
44 X(md5INT)(m, p->block);
45 X(md5INT)(m, p->tblock);
46 MPI_Comm_size(p->comm, &i); X(md5int)(m, i);
47 A(XM(md5_equal)(*m, p->comm));
48 }
49
50 static void print(const problem *ego_, printer *p)
51 {
52 const problem_mpi_transpose *ego = (const problem_mpi_transpose *) ego_;
53 int i;
54 MPI_Comm_size(ego->comm, &i);
55 p->print(p, "(mpi-transpose %d %d %d %D %D %D %D %D %d)",
56 ego->I == ego->O,
57 X(alignment_of)(ego->I),
58 X(alignment_of)(ego->O),
59 ego->vn,
60 ego->nx, ego->ny,
61 ego->block, ego->tblock,
62 i);
63 }
64
65 static void zero(const problem *ego_)
66 {
67 const problem_mpi_transpose *ego = (const problem_mpi_transpose *) ego_;
68 R *I = ego->I;
69 INT i, N = ego->vn * ego->ny;
70 int my_pe;
71
72 MPI_Comm_rank(ego->comm, &my_pe);
73 N *= XM(block)(ego->nx, ego->block, my_pe);
74
75 for (i = 0; i < N; ++i) I[i] = K(0.0);
76 }
77
78 static const problem_adt padt =
79 {
80 PROBLEM_MPI_TRANSPOSE,
81 hash,
82 zero,
83 print,
84 destroy
85 };
86
87 problem *XM(mkproblem_transpose)(INT nx, INT ny, INT vn,
88 R *I, R *O,
89 INT block, INT tblock,
90 MPI_Comm comm,
91 unsigned flags)
92 {
93 problem_mpi_transpose *ego =
94 (problem_mpi_transpose *)X(mkproblem)(sizeof(problem_mpi_transpose), &padt);
95
96 A(nx > 0 && ny > 0 && vn > 0);
97 A(block > 0 && XM(num_blocks_ok)(nx, block, comm)
98 && tblock > 0 && XM(num_blocks_ok)(ny, tblock, comm));
99
100 /* enforce pointer equality if untainted pointers are equal */
101 if (UNTAINT(I) == UNTAINT(O))
102 I = O = JOIN_TAINT(I, O);
103
104 ego->nx = nx;
105 ego->ny = ny;
106 ego->vn = vn;
107 ego->I = I;
108 ego->O = O;
109 ego->block = block > nx ? nx : block;
110 ego->tblock = tblock > ny ? ny : tblock;
111
112 /* canonicalize flags: we can freely assume that the data is
113 "transposed" if one of the dimensions is 1. */
114 if (ego->block == 1)
115 flags |= TRANSPOSED_IN;
116 if (ego->tblock == 1)
117 flags |= TRANSPOSED_OUT;
118 ego->flags = flags;
119
120 MPI_Comm_dup(comm, &ego->comm);
121
122 return &(ego->super);
123 }