- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用 Intel MKL
计算一个数组的 3D FFT
about 300×200×200
元素。此 3D 数组以列方式存储为 double
类型的一维数组:
for( int k = 0; k < nk; k++ ) // Loop through the height.
for( int j = 0; j < nj; j++ ) // Loop through the rows.
for( int i = 0; i < ni; i++ ) // Loop through the columns.
{
ijk = i + ni * j + ni * nj * k;
my3Darray[ ijk ] = 1.0;
}
我想对输入数组执行 not-in-place
FFT 并防止它被修改(我需要稍后在我的代码中使用它)然后进行反向计算 就地
。我也想要零填充。
我的问题是:
FFT
函数使用的数组大小?这是我对这个问题的尝试,如果有任何评论、建议或提示,我将非常感谢。
#include <stdio.h>
#include "mkl.h"
int max(int a, int b, int c)
{
int m = a;
(m < b) && (m = b);
(m < c) && (m = c);
return m;
}
void FFT3D_R2C( // Real to Complex 3D FFT.
double *in, int nRowsIn , int nColsIn , int nHeightsIn ,
double *out )
{
int n = max( nRowsIn , nColsIn , nHeightsIn );
// Round up to the next highest power of 2.
unsigned int N = (unsigned int) n; // compute the next highest power of 2 of 32-bit n.
N--;
N |= N >> 1;
N |= N >> 2;
N |= N >> 4;
N |= N >> 8;
N |= N >> 16;
N++;
/* Strides describe data layout in real and conjugate-even domain. */
MKL_LONG rs[4], cs[4];
// DFTI descriptor.
DFTI_DESCRIPTOR_HANDLE fft_desc = 0;
// Variables needed for out-of-place computations.
MKL_Complex16 *in_fft = new MKL_Complex16 [ N*N*N ];
MKL_Complex16 *out_fft = new MKL_Complex16 [ N*N*N ];
double *out_ZeroPadded = new double [ N*N*N ];
/* Compute strides */
rs[3] = 1; cs[3] = 1;
rs[2] = (N/2+1)*2; cs[2] = (N/2+1);
rs[1] = N*(N/2+1)*2; cs[1] = N*(N/2+1);
rs[0] = 0; cs[0] = 0;
// Create DFTI descriptor.
MKL_LONG sizes[] = { N, N, N };
DftiCreateDescriptor( &fft_desc, DFTI_DOUBLE, DFTI_REAL, 3, sizes );
// Configure DFTI descriptor.
DftiSetValue( fft_desc, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX );
DftiSetValue( fft_desc, DFTI_PLACEMENT, DFTI_NOT_INPLACE ); // Out-of-place transformation.
DftiSetValue( fft_desc, DFTI_INPUT_STRIDES , rs );
DftiSetValue( fft_desc, DFTI_OUTPUT_STRIDES , cs );
DftiCommitDescriptor( fft_desc );
DftiComputeForward ( fft_desc, in , in_fft );
// Change strides to compute backward transform.
DftiSetValue ( fft_desc, DFTI_INPUT_STRIDES , cs);
DftiSetValue ( fft_desc, DFTI_OUTPUT_STRIDES, rs);
DftiCommitDescriptor( fft_desc );
DftiComputeBackward ( fft_desc, out_fft, out_ZeroPadded );
// Printing the zero padded 3D FFT result.
for( long long i = 0; i < (long long)N*N*N; i++ )
printf("%f\n", out_ZeroPadded[i] );
/* I don't know how to take out the zero padded results and
save the actual result in the variable named "out" */
DftiFreeDescriptor ( &fft_desc );
delete[] in_fft;
delete[] out_ZeroPadded ;
}
int main()
{
int n = 10;
double *a = new double [n*n*n]; // This array is real.
double *afft = new double [n*n*n];
// Fill the array with some 'real' numbers.
for( int i = 0; i < n*n*n; i++ )
a[ i ] = 1.0;
// Calculate FFT.
FFT3D_R2C( a, n, n, n, afft );
printf("FFT results:\n");
for( int i = 0; i < n*n*n; i++ )
printf( "%15.8f\n", afft[i] );
delete[] a;
delete[] afft;
return 0;
}
最佳答案
一些提示:
2 大小的幂
Nx,Ny,Nz
为输入矩阵的大小和nx,ny,nz
填充矩阵的大小
for (nx=1;nx<Nx;nx<<=1);
for (ny=1;ny<Ny;ny<<=1);
for (nz=1;nz<Nz;nz<<=1);
现在先通过 memset 零填充为零,然后复制矩阵行
N^3
而不是 nx*ny*nz
会导致大幅减速nx,ny,nz
彼此不靠近输出很复杂
a
是输入实矩阵afft
输出复数矩阵double *afft = new double [2*nx*ny*nz];
"\r\n"
之后的行将有利于查看3D 自由傅里叶变换
double lin[2*max(nx,ny,nz)];
关于c++ - 使用带零填充的英特尔 MKL 的 3D FFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27329467/
我尝试设置一个文件来使用 PyCharm 编写 AI。 我正在使用的教程:https://www.youtube.com/watch?v=ujTCoH21GlA 当我运行代码时: $ import t
我一直在寻找很长一段时间,似乎无法找到一个官方/结论性的数字来引用英特尔至强四核可以完成的单精度浮点运算/时钟周期的数量。我有一个 Intel Xeon 四核 E5530 CPU。 我希望用它来计算我
在深度学习与神经网络领域,研究人员通常离不开 GPU。得益于 GPU 极高内存带宽和较多核心数,研究人员可以更快地获得模型训练的结果。与此同时,CPU 受限于自身较少的核心数,计算运行需要较长的时间
我试图了解 TCS 启用的 SGX 线程与 SDK 提供的不受信任线程之间的区别. 如果我理解正确的话,TCS 允许多个逻辑处理器进入同一个飞地。每个逻辑处理器都有自己的 TCS,因此也有自己的入口点
我想通过 IACA 分析器运行一些代码以查看它使用了多少个 uops——我从一个简单的函数开始,看看它是否在工作。 不幸的是,当我插入 IACA 说要使用的宏时,生成的程序集非常不同,因此对它的任何分
是否有可能获得许可的开发人员证书,以在生产模式下签署经过安全审查、社区开发的开源 SGX 软件二进制文件,并将其发布在 apt 或 rpm 等开源存储库中? 我刚问过英特尔 SGX 团队,他们说只有经
我正在尝试模拟 Intel 8080 指令集,但我被这条指令卡住了 OUT D8 ,根据书Intel 8080/8085 Assembly Language Programming它说 OUT ins
我在使用一些现有的 FORTRAN 代码时发现了一个问题。尽管它已经预料到需要在重新分配之前释放数组,但这从来没有必要。我现在需要它来执行此操作,但它无法正常运行。 当前的伪代码大约是: MODULE
我正在尝试在内存中对齐以下类型的数据: type foo real, allocatable, dimension(:) :: bar1, bar2 !dir$ attributes al
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
似乎获得和释放语义的公认定义是这样的: (引自 http://msdn.microsoft.com/en-us/library/windows/hardware/ff540496(v=vs.85).a
这是我对英特尔 TBB 流图性能进行基准测试的尝试。这是设置: 一个广播节点发送continue_msg到 N 后继节点 (一broadcast_node) 每个后继节点执行一次计算,该计算需要 t
我有两个问题 第一个问题:我使用 css3、HTML5、JavaScript 开发应用程序。在我的应用程序中,我需要从数据库中获取数据。我该怎么做? 第二个问题:intel xdk 在构建 l 时必须
在英特尔手册的第 3 卷中,它包含硬件事件计数器的描述: BACLEAR_FORCE_IQ Counts number of times a BACLEAR was forced by the Ins
嘿,我正在使用 Intel xdk 开发混合应用程序。我已经创建了注册表,然后我将代码放在那里。我尝试使用 Php Mysql 将数据库插入我的数据库后。 如果我单击注册按钮,它会显示这样的错误 [
我想知道是否可以让英特尔 C++ 编译器(或其他编译器,如 gcc 或 clang)显示一些来自优化器的消息。我想知道优化器究竟对我的代码做了什么。默认情况下,编译器只打印非常基本的东西,比如未使用的
我正在使用 64 位架构的 Intel 程序集优化我的视频解码器。为了优化,我使用 AVX2 指令集。 我的开发环境:- 操作系统:- Win 7(64位) IDE:- MSVS 2008(教授) C
如果这是一个非常愚蠢的问题,我很抱歉;我的 Fortran 不太好。我正在移植一些旧的 Fortran 代码,并遇到了这个子例程定义: SUBROUTINE SET_HYDROMODULE(HYDRO
请问,我是否可以将 Intel XDK API 和 Phonegap API 集成到单个移动应用程序中?这是因为,某些 API 仅在 Phonegap 中可用,反之亦然。 最佳答案 是的,如果我正确理
在 x86 中查找任意操作码的含义(例如 0xC8 )的相对快速简便的方法是什么? Intel Software Developer's manual搜索起来不是很有趣...... 最佳答案 查询 t
我是一名优秀的程序员,十分优秀!