fftw_plan_dft_2d优化
【摘要】 fftw_plan_dft_2d优化方法,
fftw_plan_dft_2d的输入和输出都是
fftwf_complex * *
经过测试发现,
fftw_plan_dft_2d创建以后,把输入数据换掉(不是重新实例化,把数据内容更新),重新执行后,结果也会更新,
这样,输入输出的数组大小类型不变,就可以反复使用,不用每次执行时创建与释放,效率能提高...
fftw_plan_dft_2d优化方法,
fftw_plan_dft_2d的输入和输出都是
fftwf_complex *
*
经过测试发现,
fftw_plan_dft_2d创建以后,把输入数据换掉(不是重新实例化,把数据内容更新),重新执行后,结果也会更新,
这样,输入输出的数组大小类型不变,就可以反复使用,不用每次执行时创建与释放,效率能提高好几倍乃至好几十倍。
加上参数FFTW_WISDOM_ONLY,分配内存为空。
fftPlan = fftwf_plan_dft_r2c_2d(row, col, (float *) xtv[0].data,
(fftwf_complex *) xtfv[0].data, FFTW_WISDOM_ONLY|FFTW_PATIENT);
-
#include "fftw3.h"
-
#include <iostream>
-
#include <string>
-
#include <cassert>
-
using namespace std;
-
int main(int argc,char * argv[]) {
-
-
int row=10;
-
int col;
-
float * realInput;
-
fftwf_complex * complexOutput;
-
-
fftwf_complex * complexInput;
-
float * realOutput;
-
-
for(int i= 1;i<argc;i++){
-
row = col;
-
realInput = (float *) fftwf_malloc(sizeof (float) * row * col );
-
assert(realInput!=nullptr);
-
complexOutput = (fftwf_complex *) fftwf_malloc(sizeof (fftwf_complex) * row * (col/2+1));
-
assert(complexOutput!=nullptr);
-
fftwf_plan r2c = fftwf_plan_dft_r2c_2d(row, col, realInput, complexOutput, FFTW_PATIENT);
-
-
if(r2c == nullptr ){
-
cout << "fftwf create r2c plan failed!" << endl;
-
cout << "plan row: " << row << " col: " << col << endl;
-
exit(1);
-
} else {
-
cout << "fftwf success to create fft r2c!" << endl;
-
cout << "plan row: " << row << " col: " << col << endl;
-
}
-
-
complexInput = (fftwf_complex *) fftwf_malloc(sizeof (fftwf_complex) * row * (col/2+1) );
-
assert(complexInput!=nullptr);
-
realOutput = (float *) fftwf_malloc(sizeof (float) * row * col);
-
assert(realOutput!=nullptr);
-
fftwf_plan c2r = fftwf_plan_dft_c2r_2d(row, col, complexInput, realOutput, FFTW_PATIENT);
-
-
if(c2r == nullptr){
-
cout << "fftwf create c2r failed!" << endl;
-
cout << "plan row: " << row << " col: " << col << endl;
-
exit(1);
-
} else {
-
cout << "fftwf success to create c2r!" << endl;
-
cout << "plan row: " << row << " col: " << col << endl;
-
}
-
}
-
-
string wisdomFile = "wisdom";
-
if(1==fftwf_export_wisdom_to_filename(wisdomFile.c_str()))
-
cout << "fftwf_export_wisdom_to_filename wisdom success" << endl;
-
else
-
cout << "fftwf_export_wisdom_to_filename wisdom fail" << endl;
-
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/65446955
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)