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