0

我正在尝试使用 Eclipse (Kepler) 和 MinGW (gcc 4.7.2) 在 Windows 8 系统上的 C 程序中使用 FFTW .dll (v 3.3.3)。我怀疑有两个问题与我的配置有关:

  1. 数组大小小于 977,程序运行并产生预期的输出;如果 N>= 977 程序崩溃,没有输出。
  2. 尽管以 N<977 运行会产生预期的输出,但调试会给出完全不同的值。

谁能指出我正确的方向?

代码:

#include <stdio.h>
#include <stdlib.h>
#include <complexUtil.h>
#include <fftw3.h>

#define N 976

main()
{
    fftw_complex *in, *out;
    fftw_plan p;

    in =  (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);

    FILE* infile;
    float value;
    int i = 0;

    // Populate input array from file
    infile = fopen("testData.txt", "r");
    for (i=0; i<N; i++) {
        fscanf(infile, "%f", &value);
        (*(in + i)) = value + 0.0i;
    }
    fclose(infile);

    // Perform fft
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_execute(p);
    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);

    // Debug output
    printf("in\t\tout\n");
    for (i=0; i<N; i++) {
        printf("%f\t%f\n", 
                   creal((fftw_complex)* (in + i )), 
                   creal((fftw_complex)* (out + i )));
    }
    return(0);
}

编译器调用:

gcc "-IC:\\Users\\Brian\\workspace\\psd\\src" "-IC:\\Users\\Brian\\workspace\\psd\\lib" "-includeC:\\Users\\Brian\\workspace\\psd\\src\\complexUtil.h" "-includeC:\\Users\\Brian\\workspace\\psd\\src\\fftw3.h" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\psd.o" "..\\src\\psd.c" 
gcc "-LC:\\Users\\Brian\\workspace\\psd\\lib" -Wl,--stack,2048 -o psd.exe "src\\psd.o" -lfftw3-3

正常输出:

in          out
0.188000    348.455000
0.000000    29.738027
0.021000    -88.468551
0.021000    16.764387
0.021000    -48.056287
...

调试输出:

in          out
-2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000    -2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
-2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000    -2656984258037080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000
...

另一个症状:在调试模式下,当我单步执行时没有显示输出,直到通过输出循环进行一定次数的迭代。然后我得到一个输出块,Eclipse 中的步进功能是灰色的。

4

1 回答 1

0

977 是素数,因此它不会按照 FFTW 的要求分解为小素数的幂。所以fftw_plan_dft_1d会失败并返回 NULL,任何后续使用 p == NULL 调用 FFTW 都会崩溃。如果您尝试为 N > 976 设置一个合理的值,例如 N = 1024,那么这应该可以按预期工作,因为您的代码似乎没问题(除了完全没有错误检查)。

于 2013-07-13T10:20:57.063 回答