annotate src/fftw-3.3.5/threads/openmp.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
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 /* openmp.c: thread spawning via OpenMP */
Chris@42 22
Chris@42 23 #include "threads.h"
Chris@42 24
Chris@42 25 #if !defined(_OPENMP)
Chris@42 26 #error OpenMP enabled but not using an OpenMP compiler
Chris@42 27 #endif
Chris@42 28
Chris@42 29 int X(ithreads_init)(void)
Chris@42 30 {
Chris@42 31 return 0; /* no error */
Chris@42 32 }
Chris@42 33
Chris@42 34 /* Distribute a loop from 0 to loopmax-1 over nthreads threads.
Chris@42 35 proc(d) is called to execute a block of iterations from d->min
Chris@42 36 to d->max-1. d->thr_num indicate the number of the thread
Chris@42 37 that is executing proc (from 0 to nthreads-1), and d->data is
Chris@42 38 the same as the data parameter passed to X(spawn_loop).
Chris@42 39
Chris@42 40 This function returns only after all the threads have completed. */
Chris@42 41 void X(spawn_loop)(int loopmax, int nthr, spawn_function proc, void *data)
Chris@42 42 {
Chris@42 43 int block_size;
Chris@42 44 spawn_data d;
Chris@42 45 int i;
Chris@42 46
Chris@42 47 A(loopmax >= 0);
Chris@42 48 A(nthr > 0);
Chris@42 49 A(proc);
Chris@42 50
Chris@42 51 if (!loopmax) return;
Chris@42 52
Chris@42 53 /* Choose the block size and number of threads in order to (1)
Chris@42 54 minimize the critical path and (2) use the fewest threads that
Chris@42 55 achieve the same critical path (to minimize overhead).
Chris@42 56 e.g. if loopmax is 5 and nthr is 4, we should use only 3
Chris@42 57 threads with block sizes of 2, 2, and 1. */
Chris@42 58 block_size = (loopmax + nthr - 1) / nthr;
Chris@42 59 nthr = (loopmax + block_size - 1) / block_size;
Chris@42 60
Chris@42 61 THREAD_ON; /* prevent debugging mode from failing under threads */
Chris@42 62 #pragma omp parallel for private(d)
Chris@42 63 for (i = 0; i < nthr; ++i) {
Chris@42 64 d.max = (d.min = i * block_size) + block_size;
Chris@42 65 if (d.max > loopmax)
Chris@42 66 d.max = loopmax;
Chris@42 67 d.thr_num = i;
Chris@42 68 d.data = data;
Chris@42 69 proc(&d);
Chris@42 70 }
Chris@42 71 THREAD_OFF; /* prevent debugging mode from failing under threads */
Chris@42 72 }
Chris@42 73
Chris@42 74 void X(threads_cleanup)(void)
Chris@42 75 {
Chris@42 76 }
Chris@42 77
Chris@42 78 /* FIXME [Matteo Frigo 2015-05-25] What does "thread-safe"
Chris@42 79 mean for openmp? */
Chris@42 80 void X(threads_register_planner_hooks)(void)
Chris@42 81 {
Chris@42 82 }