问题
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