summarylogtreecommitdiffstats
path: root/fftw3.diff
blob: 02885b6b9ec3c0317fc00e00af646200a93ec4ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Description: Switch dependency from FFTW2 to FFTW3
Author: Ionut Georgescu
Bug: http://bugs.debian.org/264201
Index: grace-5.1.24-patch/src/fourier.c
===================================================================
--- grace-5.1.24-patch.orig/src/fourier.c
+++ grace-5.1.24-patch/src/fourier.c
@@ -230,7 +230,8 @@ static int bit_swap(int i, int nu)
 #else
 /* Start of new FFTW-based transforms by Marcus H. Mendenhall */
 
-#include <fftw.h>
+#include <complex.h>
+#include <fftw3.h>
 #include <string.h>
 
 static char  *wisdom_file=0;
@@ -258,7 +259,7 @@ void dft(double *jr, double *ji, int n,
   fftw_plan plan;
   int i;
   double ninv;
-  FFTW_COMPLEX *cbuf;
+  fftw_complex *cbuf;
   static int wisdom_inited=0;
   char *ram_cache_wisdom;
   int plan_flags;
@@ -274,7 +275,7 @@ void dft(double *jr, double *ji, int n,
     if(wisdom_file && wisdom_file[0] ) {
       /* if a file was specified in GRACE_FFTW_WISDOM_FILE, try to read it */
       FILE *wf;
-      fftw_status fstat;
+      int fstat;
       wf=fopen(wisdom_file,"r");
       if(wf) {
 	fstat=fftw_import_wisdom_from_file(wf);
@@ -286,30 +287,35 @@ void dft(double *jr, double *ji, int n,
     }
   }
 
-  plan_flags=using_wisdom? (FFTW_USE_WISDOM | FFTW_MEASURE) : FFTW_ESTIMATE;
-
-  plan=fftw_create_plan(n, iflag?FFTW_BACKWARD:FFTW_FORWARD,
-		   plan_flags | FFTW_IN_PLACE);
-  cbuf=xcalloc(n, sizeof(*cbuf));
+  /* fftw_malloc behaves like malloc except that it properly aligns the array
+   * when SIMD instructions (such as SSE and Altivec) are available.
+   */
+  cbuf=(fftw_complex *)fftw_malloc(n*sizeof(fftw_complex));
   if(!cbuf) return;
+
   for(i=0; i<n; i++) {
-    cbuf[i].re=jr[i]; cbuf[i].im=ji[i];
+    cbuf[i] = jr[i] + I * ji[i];
   }
-  fftw(plan, 1, cbuf, 1, 1, 0, 1, 1);
+
+  plan_flags=using_wisdom? (FFTW_MEASURE) : FFTW_ESTIMATE;
+  plan=fftw_plan_dft_1d(n, cbuf, cbuf, iflag?FFTW_BACKWARD:FFTW_FORWARD,
+		   plan_flags);
+
+  fftw_execute(plan);
   fftw_destroy_plan(plan);
 
   if(!iflag) {
     ninv=1.0/n;
     for(i=0; i<n; i++) {
-    jr[i]=cbuf[i].re*ninv; ji[i]=cbuf[i].im*ninv;
+    jr[i]=creal(cbuf[i])*ninv; ji[i]=cimag(cbuf[i])*ninv;
     }
   } else {
     for(i=0; i<n; i++) {
-      jr[i]=cbuf[i].re; ji[i]=cbuf[i].im;
+      jr[i]=creal(cbuf[i]); ji[i]=cimag(cbuf[i]);
     }
   }
 
-  XCFREE(cbuf);
+  fftw_free(cbuf);
   
 }
 
Index: grace-5.1.24-patch/ac-tools/configure.in
===================================================================
--- grace-5.1.24-patch.orig/ac-tools/configure.in
+++ grace-5.1.24-patch/ac-tools/configure.in
@@ -554,8 +554,17 @@ fi
 
 if test $fftw = true
 then
-  ACX_CHECK_FFTW(2.1.3, AC_DEFINE(HAVE_FFTW),
-                 AC_MSG_RESULT(--> using legacy unoptimized FFT code))
+  AC_CHECK_HEADERS(fftw3.h,
+  [
+	AC_CHECK_LIB(fftw3, fftw_execute,
+	[
+		FFTW_LIB="-lfftw3"
+		AC_DEFINE(HAVE_FFTW)
+	],
+	[AC_MSG_RESULT([--> using legacy unoptimized FFT code])]
+	)
+  ],
+  [AC_MSG_RESULT([--> using legacy unoptimized FFT code])])
 fi
 
 dnl **** check for libz - needed for PDF and PNG drivers and XmHTML
Index: grace-5.1.24-patch/configure
===================================================================
--- grace-5.1.24-patch.orig/configure
+++ grace-5.1.24-patch/configure
@@ -748,7 +748,6 @@ with_printcmd
 enable_debug
 enable_maintainer
 with_netcdf_libraries
-with_fftw_library
 with_zlib_library
 with_jpeg_library
 with_png_library
@@ -1412,7 +1411,6 @@ Optional Packages:
   --with-helpviewer=COMMAND    define help viewer command ["mozilla %s"]
   --with-printcmd=PROG         use PROG for printing
   --with-netcdf-libraries=OBJ  use OBJ as netCDF libraries [-lnetcdf]
-  --with-fftw-library=OBJ      use OBJ as FFTW library [-lfftw]
   --with-zlib-library=OBJ      use OBJ as ZLIB library [-lz]
   --with-jpeg-library=OBJ      use OBJ as JPEG library [-ljpeg]
   --with-png-library=OBJ       use OBJ as PNG library [-lpng]
@@ -8225,84 +8223,69 @@ fi
 
 if test $fftw = true
 then
+  for ac_header in fftw3.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "fftw3.h" "ac_cv_header_fftw3_h" "$ac_includes_default"
+if test "x$ac_cv_header_fftw3_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_FFTW3_H 1
+_ACEOF
 
-
-# Check whether --with-fftw_library was given.
-if test "${with_fftw_library+set}" = set; then :
-  withval=$with_fftw_library; fftw_library="$withval"
-fi
-
-  if test "x$fftw_library" = "x"
-  then
-    fftw_library=-lfftw
-  fi
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FFTW library >= 2.1.3" >&5
-$as_echo_n "checking for FFTW library >= 2.1.3... " >&6; }
-if ${acx_cv_fftw+:} false; then :
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fftw_execute in -lfftw3" >&5
+$as_echo_n "checking for fftw_execute in -lfftw3... " >&6; }
+if ${ac_cv_lib_fftw3_fftw_execute+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if ${acx_cv_fftw_library+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  acx_cv_fftw_library=$fftw_library
-fi
-
-
-    save_CFLAGS=$CFLAGS
-    save_CPPFLAGS=$CPPFLAGS
-    save_LDFLAGS=$LDFLAGS
-    save_LIBS=$LIBS
-
-    LIBS="$acx_cv_fftw_library $LIBS"
-    if test "$cross_compiling" = yes; then :
-  acx_cv_fftw="no"
-
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lfftw3  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
-#include <fftw.h>
-#include <string.h>
-      int main(void) {
-        char *vlib = (char *) fftw_version;
-        if (strcmp(vlib, "2.1.3") < 0) {
-          exit(1);
-        }
-        exit(0);
-      }
-
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char fftw_execute ();
+int
+main ()
+{
+return fftw_execute ();
+  ;
+  return 0;
+}
 _ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  acx_cv_fftw="yes"
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_fftw3_fftw_execute=yes
 else
-  acx_cv_fftw="no"
+  ac_cv_lib_fftw3_fftw_execute=no
 fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fftw3_fftw_execute" >&5
+$as_echo "$ac_cv_lib_fftw3_fftw_execute" >&6; }
+if test "x$ac_cv_lib_fftw3_fftw_execute" = xyes; then :
 
+		FFTW_LIB="-lfftw3"
+		$as_echo "#define HAVE_FFTW 1" >>confdefs.h
 
 
-    CFLAGS=$save_CFLAGS
-    CPPFLAGS=$save_CPPFLAGS
-    LDFLAGS=$save_LDFLAGS
-    LIBS=$save_LIBS
-
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: --> using legacy unoptimized FFT code" >&5
+$as_echo "--> using legacy unoptimized FFT code" >&6; }
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_cv_fftw" >&5
-$as_echo "$acx_cv_fftw" >&6; }
-  if test "$acx_cv_fftw" = "yes"
-  then
-    FFTW_LIB="$acx_cv_fftw_library"
-    $as_echo "#define HAVE_FFTW 1" >>confdefs.h
 
-  else
-    FFTW_LIB=
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: --> using legacy unoptimized FFT code" >&5
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: --> using legacy unoptimized FFT code" >&5
 $as_echo "--> using legacy unoptimized FFT code" >&6; }
-  fi
+fi
+
+done
 
 fi