Chris@10: /* Chris@10: * Copyright (c) 2003, 2007-11 Matteo Frigo Chris@10: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology Chris@10: * Chris@10: * This program is free software; you can redistribute it and/or modify Chris@10: * it under the terms of the GNU General Public License as published by Chris@10: * the Free Software Foundation; either version 2 of the License, or Chris@10: * (at your option) any later version. Chris@10: * Chris@10: * This program is distributed in the hope that it will be useful, Chris@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@10: * GNU General Public License for more details. Chris@10: * Chris@10: * You should have received a copy of the GNU General Public License Chris@10: * along with this program; if not, write to the Free Software Chris@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@10: * Chris@10: */ Chris@10: Chris@10: #include "mpi-rdft2.h" Chris@10: Chris@10: static void destroy(problem *ego_) Chris@10: { Chris@10: problem_mpi_rdft2 *ego = (problem_mpi_rdft2 *) ego_; Chris@10: XM(dtensor_destroy)(ego->sz); Chris@10: MPI_Comm_free(&ego->comm); Chris@10: X(ifree)(ego_); Chris@10: } Chris@10: Chris@10: static void hash(const problem *p_, md5 *m) Chris@10: { Chris@10: const problem_mpi_rdft2 *p = (const problem_mpi_rdft2 *) p_; Chris@10: int i; Chris@10: X(md5puts)(m, "mpi-rdft2"); Chris@10: X(md5int)(m, p->I == p->O); Chris@10: /* don't include alignment -- may differ between processes Chris@10: X(md5int)(m, X(alignment_of)(p->I)); Chris@10: X(md5int)(m, X(alignment_of)(p->O)); Chris@10: ... note that applicability of MPI plans does not depend Chris@10: on alignment (although optimality may, in principle). */ Chris@10: XM(dtensor_md5)(m, p->sz); Chris@10: X(md5INT)(m, p->vn); Chris@10: X(md5int)(m, p->kind); Chris@10: X(md5int)(m, p->flags); Chris@10: MPI_Comm_size(p->comm, &i); X(md5int)(m, i); Chris@10: A(XM(md5_equal)(*m, p->comm)); Chris@10: } Chris@10: Chris@10: static void print(const problem *ego_, printer *p) Chris@10: { Chris@10: const problem_mpi_rdft2 *ego = (const problem_mpi_rdft2 *) ego_; Chris@10: int i; Chris@10: p->print(p, "(mpi-rdft2 %d %d %d ", Chris@10: ego->I == ego->O, Chris@10: X(alignment_of)(ego->I), Chris@10: X(alignment_of)(ego->O)); Chris@10: XM(dtensor_print)(ego->sz, p); Chris@10: p->print(p, " %D %d %d", ego->vn, (int) ego->kind, ego->flags); Chris@10: MPI_Comm_size(ego->comm, &i); p->print(p, " %d)", i); Chris@10: } Chris@10: Chris@10: static void zero(const problem *ego_) Chris@10: { Chris@10: const problem_mpi_rdft2 *ego = (const problem_mpi_rdft2 *) ego_; Chris@10: R *I = ego->I; Chris@10: dtensor *sz; Chris@10: INT i, N; Chris@10: int my_pe; Chris@10: Chris@10: sz = XM(dtensor_copy)(ego->sz); Chris@10: sz->dims[sz->rnk - 1].n = sz->dims[sz->rnk - 1].n / 2 + 1; Chris@10: MPI_Comm_rank(ego->comm, &my_pe); Chris@10: N = 2 * ego->vn * XM(total_block)(sz, IB, my_pe); Chris@10: XM(dtensor_destroy)(sz); Chris@10: for (i = 0; i < N; ++i) I[i] = K(0.0); Chris@10: } Chris@10: Chris@10: static const problem_adt padt = Chris@10: { Chris@10: PROBLEM_MPI_RDFT2, Chris@10: hash, Chris@10: zero, Chris@10: print, Chris@10: destroy Chris@10: }; Chris@10: Chris@10: problem *XM(mkproblem_rdft2)(const dtensor *sz, INT vn, Chris@10: R *I, R *O, Chris@10: MPI_Comm comm, Chris@10: rdft_kind kind, Chris@10: unsigned flags) Chris@10: { Chris@10: problem_mpi_rdft2 *ego = Chris@10: (problem_mpi_rdft2 *)X(mkproblem)(sizeof(problem_mpi_rdft2), &padt); Chris@10: int n_pes; Chris@10: Chris@10: A(XM(dtensor_validp)(sz) && FINITE_RNK(sz->rnk) && sz->rnk > 1); Chris@10: MPI_Comm_size(comm, &n_pes); Chris@10: A(vn >= 0); Chris@10: A(kind == R2HC || kind == HC2R); Chris@10: Chris@10: /* enforce pointer equality if untainted pointers are equal */ Chris@10: if (UNTAINT(I) == UNTAINT(O)) Chris@10: I = O = JOIN_TAINT(I, O); Chris@10: Chris@10: ego->sz = XM(dtensor_canonical)(sz, 0); Chris@10: #ifdef FFTW_DEBUG Chris@10: ego->sz->dims[sz->rnk - 1].n = sz->dims[sz->rnk - 1].n / 2 + 1; Chris@10: A(n_pes >= XM(num_blocks_total)(ego->sz, IB) Chris@10: && n_pes >= XM(num_blocks_total)(ego->sz, OB)); Chris@10: ego->sz->dims[sz->rnk - 1].n = sz->dims[sz->rnk - 1].n; Chris@10: #endif Chris@10: Chris@10: ego->vn = vn; Chris@10: ego->I = I; Chris@10: ego->O = O; Chris@10: ego->kind = kind; Chris@10: Chris@10: /* We only support TRANSPOSED_OUT for r2c and TRANSPOSED_IN for Chris@10: c2r transforms. */ Chris@10: Chris@10: ego->flags = flags; Chris@10: Chris@10: MPI_Comm_dup(comm, &ego->comm); Chris@10: Chris@10: return &(ego->super); Chris@10: } Chris@10: Chris@10: problem *XM(mkproblem_rdft2_d)(dtensor *sz, INT vn, Chris@10: R *I, R *O, Chris@10: MPI_Comm comm, Chris@10: rdft_kind kind, Chris@10: unsigned flags) Chris@10: { Chris@10: problem *p = XM(mkproblem_rdft2)(sz, vn, I, O, comm, kind, flags); Chris@10: XM(dtensor_destroy)(sz); Chris@10: return p; Chris@10: }