annotate src/fftw-3.3.5/mpi/wisdom-api.c @ 43:5ea0608b923f

Current zlib source
author Chris Cannam
date Tue, 18 Oct 2016 14:33:52 +0100
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21 #include "fftw3-mpi.h"
Chris@42 22 #include "ifftw-mpi.h"
Chris@42 23 #include <string.h>
Chris@42 24
Chris@42 25 #if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_INT
Chris@42 26 # define FFTW_MPI_SIZE_T MPI_UNSIGNED
Chris@42 27 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG
Chris@42 28 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG
Chris@42 29 #elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG
Chris@42 30 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG_LONG
Chris@42 31 #else
Chris@42 32 # error MPI type for size_t is unknown
Chris@42 33 # define FFTW_MPI_SIZE_T MPI_UNSIGNED_LONG
Chris@42 34 #endif
Chris@42 35
Chris@42 36 /* Import wisdom from all processes to process 0, as prelude to
Chris@42 37 exporting a single wisdom file (this is convenient when we are
Chris@42 38 running on identical processors, to avoid the annoyance of having
Chris@42 39 per-process wisdom files). In order to make the time for this
Chris@42 40 operation logarithmic in the number of processors (rather than
Chris@42 41 linear), we employ a tree reduction algorithm. This means that the
Chris@42 42 wisdom is modified on processes other than root, which shouldn't
Chris@42 43 matter in practice. */
Chris@42 44 void XM(gather_wisdom)(MPI_Comm comm_)
Chris@42 45 {
Chris@42 46 MPI_Comm comm, comm2;
Chris@42 47 int my_pe, n_pes;
Chris@42 48 char *wis;
Chris@42 49 size_t wislen;
Chris@42 50 MPI_Status status;
Chris@42 51
Chris@42 52 MPI_Comm_dup(comm_, &comm);
Chris@42 53 MPI_Comm_rank(comm, &my_pe);
Chris@42 54 MPI_Comm_size(comm, &n_pes);
Chris@42 55
Chris@42 56 if (n_pes > 2) { /* recursively split into even/odd processes */
Chris@42 57 MPI_Comm_split(comm, my_pe % 2, my_pe, &comm2);
Chris@42 58 XM(gather_wisdom)(comm2);
Chris@42 59 MPI_Comm_free(&comm2);
Chris@42 60 }
Chris@42 61 if (n_pes > 1 && my_pe < 2) { /* import process 1 -> 0 */
Chris@42 62 if (my_pe == 1) {
Chris@42 63 wis = X(export_wisdom_to_string)();
Chris@42 64 wislen = strlen(wis) + 1;
Chris@42 65 MPI_Send(&wislen, 1, FFTW_MPI_SIZE_T, 0, 111, comm);
Chris@42 66 MPI_Send(wis, wislen, MPI_CHAR, 0, 222, comm);
Chris@42 67 free(wis);
Chris@42 68 }
Chris@42 69 else /* my_pe == 0 */ {
Chris@42 70 MPI_Recv(&wislen, 1, FFTW_MPI_SIZE_T, 1, 111, comm, &status);
Chris@42 71 wis = (char *) MALLOC(wislen * sizeof(char), OTHER);
Chris@42 72 MPI_Recv(wis, wislen, MPI_CHAR, 1, 222, comm, &status);
Chris@42 73 if (!X(import_wisdom_from_string)(wis))
Chris@42 74 MPI_Abort(comm, 1);
Chris@42 75 X(ifree)(wis);
Chris@42 76 }
Chris@42 77 }
Chris@42 78 MPI_Comm_free(&comm);
Chris@42 79 }
Chris@42 80
Chris@42 81 /* broadcast wisdom from process 0 to all other processes; this
Chris@42 82 is useful so that we can import wisdom once and not worry
Chris@42 83 about parallel I/O or process-specific wisdom, although of
Chris@42 84 course it assumes that all the processes have identical
Chris@42 85 performance characteristics (i.e. identical hardware). */
Chris@42 86 void XM(broadcast_wisdom)(MPI_Comm comm_)
Chris@42 87 {
Chris@42 88 MPI_Comm comm;
Chris@42 89 int my_pe;
Chris@42 90 char *wis;
Chris@42 91 size_t wislen;
Chris@42 92
Chris@42 93 MPI_Comm_dup(comm_, &comm);
Chris@42 94 MPI_Comm_rank(comm, &my_pe);
Chris@42 95
Chris@42 96 if (my_pe != 0) {
Chris@42 97 MPI_Bcast(&wislen, 1, FFTW_MPI_SIZE_T, 0, comm);
Chris@42 98 wis = (char *) MALLOC(wislen * sizeof(char), OTHER);
Chris@42 99 MPI_Bcast(wis, wislen, MPI_CHAR, 0, comm);
Chris@42 100 if (!X(import_wisdom_from_string)(wis))
Chris@42 101 MPI_Abort(comm, 1);
Chris@42 102 X(ifree)(wis);
Chris@42 103 }
Chris@42 104 else /* my_pe == 0 */ {
Chris@42 105 wis = X(export_wisdom_to_string)();
Chris@42 106 wislen = strlen(wis) + 1;
Chris@42 107 MPI_Bcast(&wislen, 1, FFTW_MPI_SIZE_T, 0, comm);
Chris@42 108 MPI_Bcast(wis, wislen, MPI_CHAR, 0, comm);
Chris@42 109 X(free)(wis);
Chris@42 110 }
Chris@42 111 MPI_Comm_free(&comm);
Chris@42 112 }