annotate src/fftw-3.3.3/threads/openmp.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 89f5e221ed7b
children
rev   line source
cannam@95 1 /*
cannam@95 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
cannam@95 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
cannam@95 4 *
cannam@95 5 * This program is free software; you can redistribute it and/or modify
cannam@95 6 * it under the terms of the GNU General Public License as published by
cannam@95 7 * the Free Software Foundation; either version 2 of the License, or
cannam@95 8 * (at your option) any later version.
cannam@95 9 *
cannam@95 10 * This program is distributed in the hope that it will be useful,
cannam@95 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@95 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@95 13 * GNU General Public License for more details.
cannam@95 14 *
cannam@95 15 * You should have received a copy of the GNU General Public License
cannam@95 16 * along with this program; if not, write to the Free Software
cannam@95 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@95 18 *
cannam@95 19 */
cannam@95 20
cannam@95 21 /* openmp.c: thread spawning via OpenMP */
cannam@95 22
cannam@95 23 #include "threads.h"
cannam@95 24
cannam@95 25 #if !defined(_OPENMP)
cannam@95 26 #error OpenMP enabled but not using an OpenMP compiler
cannam@95 27 #endif
cannam@95 28
cannam@95 29 int X(ithreads_init)(void)
cannam@95 30 {
cannam@95 31 return 0; /* no error */
cannam@95 32 }
cannam@95 33
cannam@95 34 /* Distribute a loop from 0 to loopmax-1 over nthreads threads.
cannam@95 35 proc(d) is called to execute a block of iterations from d->min
cannam@95 36 to d->max-1. d->thr_num indicate the number of the thread
cannam@95 37 that is executing proc (from 0 to nthreads-1), and d->data is
cannam@95 38 the same as the data parameter passed to X(spawn_loop).
cannam@95 39
cannam@95 40 This function returns only after all the threads have completed. */
cannam@95 41 void X(spawn_loop)(int loopmax, int nthr, spawn_function proc, void *data)
cannam@95 42 {
cannam@95 43 int block_size;
cannam@95 44 spawn_data d;
cannam@95 45 int i;
cannam@95 46
cannam@95 47 A(loopmax >= 0);
cannam@95 48 A(nthr > 0);
cannam@95 49 A(proc);
cannam@95 50
cannam@95 51 if (!loopmax) return;
cannam@95 52
cannam@95 53 /* Choose the block size and number of threads in order to (1)
cannam@95 54 minimize the critical path and (2) use the fewest threads that
cannam@95 55 achieve the same critical path (to minimize overhead).
cannam@95 56 e.g. if loopmax is 5 and nthr is 4, we should use only 3
cannam@95 57 threads with block sizes of 2, 2, and 1. */
cannam@95 58 block_size = (loopmax + nthr - 1) / nthr;
cannam@95 59 nthr = (loopmax + block_size - 1) / block_size;
cannam@95 60
cannam@95 61 THREAD_ON; /* prevent debugging mode from failing under threads */
cannam@95 62 #pragma omp parallel for private(d)
cannam@95 63 for (i = 0; i < nthr; ++i) {
cannam@95 64 d.max = (d.min = i * block_size) + block_size;
cannam@95 65 if (d.max > loopmax)
cannam@95 66 d.max = loopmax;
cannam@95 67 d.thr_num = i;
cannam@95 68 d.data = data;
cannam@95 69 proc(&d);
cannam@95 70 }
cannam@95 71 THREAD_OFF; /* prevent debugging mode from failing under threads */
cannam@95 72 }
cannam@95 73
cannam@95 74 void X(threads_cleanup)(void)
cannam@95 75 {
cannam@95 76 }