/* * Copyright (c) 2010-2013 Michael Pippig * * This file is part of PFFT. * * PFFT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * PFFT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PFFT. If not, see . * */ #include "pfft.h" #include "ipfft.h" #include "util.h" static void extract_comm_1d( int dim, MPI_Comm comm_cart, MPI_Comm *comm_1d); static void factorize( int q, int *ptr_q0, int *ptr_q1); static void factorize_equal( int p0, int p1, int q, int *ptr_q0, int *ptr_q1); int PX(create_procmesh)( int rnk, MPI_Comm comm, const int *np, MPI_Comm *comm_cart ) { int *periods, reorder=1, num_procs=1, ret = 0, size; int *dims; dims = (int*) malloc(sizeof(int) * (size_t) rnk); for(int t=0; t min */ static void factorize( int q, int *ptr_q0, int *ptr_q1 ) { for(int t = 1; t <= sqrt(q); t++) if(t * (q/t) == q) *ptr_q1 = t; *ptr_q0 = q / (*ptr_q1); } /* factorize an integer q into q0*q1 with * abs(p0*q0 - p1*q1) -> min */ static void factorize_equal( int p0, int p1, int q, int *ptr_q0, int *ptr_q1 ) { int q0, q1; int opt_q0 = 1; int opt_q1 = q; R min_err = pfft_fabs(p0 * q - p1 * 1.0); for(q1 = 1; q1 <= sqrt(q); q1++){ q0 = q/q1; if(q0*q1 == q){ R err = pfft_fabs(p0*q0 - p1*q1); if(err < min_err){ min_err = err; opt_q0 = q0; opt_q1 = q1; } } } *ptr_q0 = opt_q0; *ptr_q1 = opt_q1; }