calling fftw in multi thread program

Deadly 提交于 2021-02-08 05:47:23

问题


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"


回答1:


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.

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.



来源:https://stackoverflow.com/questions/14318933/calling-fftw-in-multi-thread-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!