在多线程程序中调用 fftw [英] calling fftw in multi thread program

查看:151
本文介绍了在多线程程序中调用 fftw的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在线程中使用 fftw3.但是粘贴在 http://codepad.org/lIjdGF5z 的代码会导致双重释放或损坏"错误.如何在线程中正确调用 fftw3 例程.谢谢!可以通过命令g++ test.cpp -lfftw3_threads -lfftw3 -lboost_thread"编译代码

I want to use fftw3 in threads. But the code pasted at http://codepad.org/lIjdGF5z causes "double free or corruption" error. How to call fftw3 routines in threads properly. Thanks! You can compile the code through command "g++ test.cpp -lfftw3_threads -lfftw3 -lboost_thread"

推荐答案

我相信对 fftw_plan_dft_2d 的调用是不可重入的,这意味着它不能同时在多个线程中调用,即使你正在制定不同的计划.根据 文档的线程安全页面.

I believe the call to fftw_plan_dft_2d is not reentrant, meaning that it can't be called in multiple threads simultaneously, even if you are creating different plans. The only fftw functions that are thread-safe are fftw_execute variants according to paragraph 2 of the Thread Safety page of the documentation.

此外,正如 Paul R. 在评论中提到的,您应该在开始时只创建一次计划,然后一遍又一遍地使用它们.它会快得多.此外,根据线程安全文档页面的第 3 段,您可以在对 fftw_execute 的多个同时调用中使用相同的计划.因此,如果您的转换大小相同,则所有线程只需要一个计划.

Additionally as Paul R. mentioned in the comments, you should only create the plan/s once at the beginning and then use them over and over. It will be much faster. Also, according to paragraph 3 of the Thread Safety documentation page, you can use the same plan in multiple simultaneous calls to fftw_execute. So if your transforms are the same size, you will only need one plan for all the threads.

这篇关于在多线程程序中调用 fftw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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