comparison src/fftw-3.3.3/threads/api.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "api.h"
22 #include "threads.h"
23
24 static int threads_inited = 0;
25
26 static void threads_register_hooks(void)
27 {
28 X(mksolver_ct_hook) = X(mksolver_ct_threads);
29 X(mksolver_hc2hc_hook) = X(mksolver_hc2hc_threads);
30 }
31
32 static void threads_unregister_hooks(void)
33 {
34 X(mksolver_ct_hook) = 0;
35 X(mksolver_hc2hc_hook) = 0;
36 }
37
38 /* should be called before all other FFTW functions! */
39 int X(init_threads)(void)
40 {
41 if (!threads_inited) {
42 planner *plnr;
43
44 if (X(ithreads_init)())
45 return 0;
46
47 threads_register_hooks();
48
49 /* this should be the first time the_planner is called,
50 and hence the time it is configured */
51 plnr = X(the_planner)();
52 X(threads_conf_standard)(plnr);
53
54 threads_inited = 1;
55 }
56 return 1;
57 }
58
59
60 void X(cleanup_threads)(void)
61 {
62 X(cleanup)();
63 if (threads_inited) {
64 X(threads_cleanup)();
65 threads_unregister_hooks();
66 threads_inited = 0;
67 }
68 }
69
70 void X(plan_with_nthreads)(int nthreads)
71 {
72 planner *plnr;
73
74 if (!threads_inited) {
75 X(cleanup)();
76 X(init_threads)();
77 }
78 A(threads_inited);
79 plnr = X(the_planner)();
80 plnr->nthr = X(imax)(1, nthreads);
81 }