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