casacore
Loading...
Searching...
No Matches
FFTW.h
Go to the documentation of this file.
1//# Copyright (C) 1993,1994,1995,1997,1999,2000,2001
2//# Associated Universities, Inc. Washington DC, USA.
3//#
4//# This library is free software; you can redistribute it and/or modify it
5//# under the terms of the GNU Library General Public License as published by
6//# the Free Software Foundation; either version 2 of the License, or (at your
7//# option) any later version.
8//#
9//# This library is distributed in the hope that it will be useful, but WITHOUT
10//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12//# License for more details.
13//#
14//# You should have received a copy of the GNU Library General Public License
15//# along with this library; if not, write to the Free Software Foundation,
16//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17//#
18//# Correspondence concerning AIPS++ should be addressed as follows:
19//# Internet email: casa-feedback@nrao.edu.
20//# Postal address: AIPS++ Project Office
21//# National Radio Astronomy Observatory
22//# 520 Edgemont Road
23//# Charlottesville, VA 22903-2475 USA
24
25#ifndef SCIMATH_FFTW_H
26#define SCIMATH_FFTW_H
27
28#include <casacore/casa/aips.h>
29#include <casacore/casa/Arrays/IPosition.h>
30
31#include <complex>
32#include <memory>
33#include <mutex>
34
35namespace casacore {
36
37//# Forward Declarations.
38class FFTWPlan;
39class FFTWPlanf;
40
41// <summary> C++ interface to the FFTWw library </summary>
42// <reviewed reviewer="NONE" date="" tests="" demos="">
43// </reviewed>
44// <synopsis>
45// This is a wrapper of FFTW3.
46// It is only active if FFTW3 was found during the build.
47// If not found, all functions won't do anything at all.
48//
49// The interface is such that the presence of FFTW3 is only visible
50// in the implementation. The header file does not need to know.
51// In this way external code using this class does not need to set HAVE_FFTW.
52// </synopsis>
53
54class FFTW
55{
56public:
57 FFTW() ;
58
60
61 // overloaded interface to fftw[f]_plan...
62 void plan_r2c(const IPosition &size, float *in, std::complex<float> *out) ;
63 void plan_r2c(const IPosition &size, double *in, std::complex<double> *out) ;
64 void plan_c2r(const IPosition &size, std::complex<float> *in, float *out) ;
65 void plan_c2r(const IPosition &size, std::complex<double> *in, double *out) ;
66 void plan_c2c_forward(const IPosition &size, std::complex<double> *in) ;
67 void plan_c2c_forward(const IPosition &size, std::complex<float> *in) ;
68 void plan_c2c_backward(const IPosition &size, std::complex<double> *in) ;
69 void plan_c2c_backward(const IPosition &size, std::complex<float> *in) ;
70
71 // TODO These overloads do not use their parameters at all. This should
72 // be written to use an interface like plan_redft00().
73 // overloaded interface to fftw[f]_execute...
74 void r2c(const IPosition &size, float *in, std::complex<float> *out) ;
75 void r2c(const IPosition &size, double *in, std::complex<double> *out) ;
76 void c2r(const IPosition &size, std::complex<float> *in, float *out);
77 void c2r(const IPosition &size, std::complex<double> *in, double *out);
78 void c2c(const IPosition &size, std::complex<float> *in, bool forward);
79 void c2c(const IPosition &size, std::complex<double> *in, bool forward);
80
81 class Plan
82 {
83 public:
84 ~Plan() noexcept;
85 Plan(const Plan&) = delete;
87 Plan& operator=(const Plan&) = delete;
88 Plan& operator=(Plan&&);
89
90 // Perform the FFT associated with this plan with the given
91 // in data, and store it in the given out data.
92 // <group>
93 void Execute(float* in, float* out);
94 void Execute(double* in, double* out);
95 // </group>
96 private:
97 friend FFTW;
98 Plan(FFTWPlan* plan);
99 Plan(FFTWPlanf* plan);
100 std::unique_ptr<FFTWPlan> _plan;
101 std::unique_ptr<FFTWPlanf> _planf;
102 };
103
104 static Plan plan_redft00(const IPosition &size, float *in, float *out);
105 static Plan plan_redft00(const IPosition &size, double *in, double *out);
106
107private:
108 static void initialize_fftw();
109
110 std::unique_ptr<FFTWPlanf> itsPlanR2Cf;
111 std::unique_ptr<FFTWPlan> itsPlanR2C;
112
113 std::unique_ptr<FFTWPlanf> itsPlanC2Rf;
114 std::unique_ptr<FFTWPlan> itsPlanC2R;
115
116 std::unique_ptr<FFTWPlanf> itsPlanC2CFf; // forward
117 std::unique_ptr<FFTWPlan> itsPlanC2CF;
118
119 std::unique_ptr<FFTWPlanf> itsPlanC2CBf; // backward
120 std::unique_ptr<FFTWPlan> itsPlanC2CB;
121
122 std::unique_ptr<FFTWPlanf> itsPlanR2Rf;
123 std::unique_ptr<FFTWPlan> itsPlanR2R;
124
125 unsigned flags;
126
127 static bool is_initialized_fftw; // FFTW needs initialization
128 // only once per process,
129 // not once per object
130
131 // TODO this mutex does not make FFTW thread safe, because
132 // planning an FFT with FFTW is not thread safe either.
133 // So either the plan..() methods should take the mutex, or
134 // FFTW should leave synchronization fully to the user of
135 // this class: currently it's halfway in between.
136 static std::mutex theirMutex; // Initialization mutex
137};
138
139} //# NAMESPACE CASACORE - END
140
141#endif
std::unique_ptr< FFTWPlan > _plan
Definition FFTW.h:100
std::unique_ptr< FFTWPlanf > _planf
Definition FFTW.h:101
void Execute(float *in, float *out)
Perform the FFT associated with this plan with the given in data, and store it in the given out data.
std::unique_ptr< FFTWPlan > itsPlanR2C
Definition FFTW.h:111
void plan_c2r(const IPosition &size, std::complex< double > *in, double *out)
std::unique_ptr< FFTWPlanf > itsPlanC2CBf
Definition FFTW.h:119
void plan_c2c_backward(const IPosition &size, std::complex< double > *in)
std::unique_ptr< FFTWPlanf > itsPlanR2Rf
Definition FFTW.h:122
void plan_c2c_forward(const IPosition &size, std::complex< float > *in)
std::unique_ptr< FFTWPlan > itsPlanC2CB
Definition FFTW.h:120
void r2c(const IPosition &size, double *in, std::complex< double > *out)
void c2c(const IPosition &size, std::complex< float > *in, bool forward)
void c2c(const IPosition &size, std::complex< double > *in, bool forward)
std::unique_ptr< FFTWPlan > itsPlanR2R
Definition FFTW.h:123
void plan_r2c(const IPosition &size, float *in, std::complex< float > *out)
overloaded interface to fftw[f]_plan...
unsigned flags
Definition FFTW.h:125
void plan_c2c_forward(const IPosition &size, std::complex< double > *in)
void r2c(const IPosition &size, float *in, std::complex< float > *out)
TODO These overloads do not use their parameters at all.
void plan_r2c(const IPosition &size, double *in, std::complex< double > *out)
std::unique_ptr< FFTWPlan > itsPlanC2R
Definition FFTW.h:114
void plan_c2c_backward(const IPosition &size, std::complex< float > *in)
void plan_c2r(const IPosition &size, std::complex< float > *in, float *out)
std::unique_ptr< FFTWPlanf > itsPlanR2Cf
Definition FFTW.h:110
static Plan plan_redft00(const IPosition &size, float *in, float *out)
static std::mutex theirMutex
only once per process, not once per object
Definition FFTW.h:136
std::unique_ptr< FFTWPlan > itsPlanC2CF
Definition FFTW.h:117
std::unique_ptr< FFTWPlanf > itsPlanC2Rf
Definition FFTW.h:113
void c2r(const IPosition &size, std::complex< double > *in, double *out)
void c2r(const IPosition &size, std::complex< float > *in, float *out)
std::unique_ptr< FFTWPlanf > itsPlanC2CFf
Definition FFTW.h:116
static void initialize_fftw()
static bool is_initialized_fftw
Definition FFTW.h:127
this file contains all the compiler specific defines
Definition mainpage.dox:28
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Definition Complex.h:350