简体   繁体   English

使用fftw库时C ++代码无法运行

[英]C++ code doesn't run while using fftw library

I am trying to implement a DFT using the fftw library ( link to FFTW documentation ). 我正在尝试使用fftw库实现DFT( 链接到FFTW文档 )。

All the libraries have been correctly linked, and the project builds just fine. 所有库均已正确链接,并且项目构建良好。 However, the code doesn't run the moment any function from the fftw library is called. 但是,该代码不会在调用fftw库中的任何函数时运行。

#include <iostream>
#include <fftw3.h>

using namespace std;

int main() {

    int vectorSize = 100;
    cout << vectorSize << endl;

    fftw_complex vec[vectorSize], vecOut[vectorSize];

    for(int i = 0; i < vectorSize; i++) {
        vec[i][0] = i;
        vec[i][1] = 1;
    }

    // Call to function to create an FFT plan
    fftw_plan plan = fftw_plan_dft_1d(vectorSize, vec, vecOut, FFTW_FORWARD, FFTW_ESTIMATE);

    cout << "test" << endl;

    return 0;
}

If I comment the line where the fftw_plan is instantiated, the code outputs 100 and "test" as expected. 如果我注释fftw_plan实例化的行,则代码将按预期输出100和“ test”。 There are no issues in the build, as far as I can tell. 据我所知,构建没有任何问题。 I haven't really been able to find any post which describes a similar problem. 我还没有真正找到描述类似问题的帖子。

I am running this on eclipse, using MinGW and the 32 bit version of the pre-compiled binary available for windows ( download link ). 我在Eclipse上运行此程序,使用的是MinGW和可用于Windows的32位版本的预编译二进制文件( 下载链接 )。

Any help would be really appreciated :) 任何帮助将非常感激 :)

Fftw requires input/output to be 16-byte aligned. Fftw要求输入/输出必须对齐16字节。 When you declare the arrays on stack, this can't be guaranteed. 当您在堆栈上声明数组时,无法保证。 So you need to call fftw_malloc or other function to allocate the arrays. 因此,您需要调用fftw_malloc或其他函数来分配数组。 Also, your code only creates the plan but doesn't execute it, thus no fft is carried out on the input data. 另外,您的代码仅创建计划,但不执行计划,因此不会对输入数据执行fft。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM