FFTW高级布局 - inembed = n和inembed = NULL给出不同的结果? [英] FFTW advanced layout -- inembed=n and inembed=NULL give different results?

查看:766
本文介绍了FFTW高级布局 - inembed = n和inembed = NULL给出不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与使用FFTW先进的数据布局API批量2D的FFT工作。

I'm working with batched 2D FFTs using the FFTW advanced data layout API.

根据<一href=\"http://cluster.earlham.edu/bccd-ng/testing/mobeen/GALAXSEEHPC/fftw-3.3/doc/html/Advanced-Complex-DFTs.html\"相对=nofollow> FFTW高级复杂的DFT 文档:

传递的 NULL 作为一个nembed参数相当于通过的 N

Passing NULL for an nembed parameter is equivalent to passing n.

但是,在使用的时候我得到不同的结果 inembed = onembed = NULL inembed = onembed = N 什么引起的结果不匹配?

However, I'm getting different results when using inembed = onembed = NULL vs. inembed = onembed = n. What could be causing the results not to match?

让我们做一个例子...

Let's do an example...

设置

int howMany = 2;
int nRows = 4;
int nCols = 4;
int n[2] = {nRows, nCols};
float* h_in = (float*)malloc(sizeof(float) * nRows*nCols*howMany);
for(int i=0; i<(nRows*nCols*howMany); i++){ //initialize h_in to [0 1 2 3 4 ...]
    h_in[i] = (float)i;
    printf("h_in[%d] = %f \n", i, h_in[i]);
}

FFTW计划 inembed == onembed == NULL

fftwf_plan forwardPlan = fftwf_plan_many_dft_r2c(2, //rank
                            n, //dimensions = {nRows, nCols}
                            howMany, //howmany
                            h_in, //in
                            NULL, //inembed
                            howMany, //istride
                            1, //idist
                            h_freq, //out
                            NULL, //onembed
                            howMany, //ostride
                            1, //odist
                            FFTW_PATIENT /*flags*/);

我也跑了一个版本,这跟 inembed = onembed = N = {NROWS,NCOLS}

注意使用 NULL N 给出了相同的计算结果,但以不同的顺序内存

Notice that using NULL or n gives the same numerical results, but in a different order in memory:

版本1: inembed == onembed == NULL

Version 1: inembed == onembed == NULL

result[0][0,1] = 240, 0 
result[1][0,1] = 256, 0 
result[2][0,1] = -16, 16 
result[3][0,1] = -16, 16 
result[4][0,1] = -16, 0 
result[5][0,1] = -16, 0  //this line and above match the other version
result[6][0,1] = -64, 64  //this line and below don't match (data is in a different order)
result[7][0,1] = -64, 64  
result[8][0,1] = 0, 0 
result[9][0,1] = 0, 0 
result[10][0,1] = 0, 0 
result[11][0,1] = 0, 0 
result[12][0,1] = -64, 0 
result[13][0,1] = -64, 0 
result[14][0,1] = 0, 0 
result[15][0,1] = 0, 0 
result[16][0,1] = 0, 0 
result[17][0,1] = 0, 0 
result[18][0,1] = -64, -64 
result[19][0,1] = -64, -64 
result[20][0,1] = 0, 0 
result[21][0,1] = 0, 0 
result[22][0,1] = 0, 0 
result[23][0,1] = 0, 0 
result[24][0,1] = 0, 0 
result[25][0,1] = 0, 0 
result[26][0,1] = 0, 0 
result[27][0,1] = 0, 0 
result[28][0,1] = 0, 0 
result[29][0,1] = 0, 0 
result[30][0,1] = 0, 0 
result[31][0,1] = 0, 0 

版本2: inembed = onembed = N = {NROWS,NCOLS}

Version 2: inembed = onembed = n = {nRows, nCols}

result[0][0,1] = 240, 0 
result[1][0,1] = 256, 0 
result[2][0,1] = -16, 16 
result[3][0,1] = -16, 16 
result[4][0,1] = -16, 0 
result[5][0,1] = -16, 0 
result[6][0,1] = 0, 0  
result[7][0,1] = 0, 0  
result[8][0,1] = -64, 64 
result[9][0,1] = -64, 64 
result[10][0,1] = 0, 0 
result[11][0,1] = 0, 0 
result[12][0,1] = 0, 0 
result[13][0,1] = 0, 0 
result[14][0,1] = 0, 0 
result[15][0,1] = 0, 0 
result[16][0,1] = -64, 0 
result[17][0,1] = -64, 0 
result[18][0,1] = 0, 0 
result[19][0,1] = 0, 0 
result[20][0,1] = 0, 0 
result[21][0,1] = 0, 0 
result[22][0,1] = 0, 0 
result[23][0,1] = 0, 0 
result[24][0,1] = -64, -64 
result[25][0,1] = -64, -64 
result[26][0,1] = 0, 0 
result[27][0,1] = 0, 0 
result[28][0,1] = 0, 0 
result[29][0,1] = 0, 0 
result[30][0,1] = 0, 0 
result[31][0,1] = 0, 0 


下面是一个<一个href=\"https://github.com/forresti/stackoverflow_examples/tree/master/cufft_fftw_batched/fftw_experiments\"相对=nofollow>这个实验工作落实。

推荐答案

解决方案:结果
外的地方例如用嵌入!= NULL 在上面的例子中是通过设置 inembed = {NROWS,NCOLS} onembed = {NROWS,(NCOLS / 2 + 1)}
结果

Solution:
The out-of-place example with embed != NULL in the above example is solved by setting inembed = {nRows, nCols} and onembed = {nRows, (nCols/2 + 1)}.

详细内容:

我解决了这个后的非常仔细阅读FFTW文档和得到一些帮助利玛窦弗里戈的。你可以在这里追溯我的步骤:

I resolved this after very carefully reading the FFTW documentation and getting some help from Matteo Frigo. You can retrace my steps here:

根据 4.4.2高级实时数据的DFT 在FFTW手册:如果nembed参数为NULL,这是因为PTED它是在基本界面间$ p $

According to 4.4.2 Advanced Real-data DFTs in the FFTW manual: If an nembed parameter is NULL, it is interpreted as what it would be in the basic interface.

让我们假设我们的输入真实的数据是维 NX * NY
对于FFTW基本接口,真实数据2.4多维的DFT 介绍以下 inembed onembed 约定2D即时到复杂的FFT:

Let's assume our input real data is of dimension nx * ny. For the FFTW basic interface, 2.4 Multi-Dimensional DFTs of Real Data explains the following inembed and onembed conventions for 2D real-to-complex FFTs:

if out-of-place:
    inembed = [ny, nx]
    onembed = [ny, (nx/2 + 1)]

if in-place:
    inembed = [ny, 2(nx/2 + 1)]
    onembed = [ny, (nx/2 + 1)]

所以,当我们用简单的FFTW R2C 界面或使用高级接口嵌入= NULL ,FFTW默认为上述嵌入参数。我们可以通过使用上述嵌入参数再现从嵌入= NULL 数值结果。

So, when we use the simple FFTW r2c interface or use the advanced interface with embed=NULL, FFTW defaults to the above embed parameters. We can reproduce the numerical results from embed=NULL by using the above embed parameters.

原来,该语句为nembed参数传递null,相当于将ñ来自的 FFTW复杂到复杂手册页。但是,我们正在做的实到复杂的转换< /一>在上面的例子。实到复杂的转换比复杂到复杂变换不同的约定为 inembed onembed

It turns out that the statement Passing NULL for an nembed parameter is equivalent to passing n comes from the FFTW complex-to-complex manual page. But, we're doing real-to-complex transforms in the examples above. Real-to-complex transforms have a different convention than complex-to-complex transforms for inembed and onembed.

这篇关于FFTW高级布局 - inembed = n和inembed = NULL给出不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆