[Insight-users] FFTW thread safety
Simon Rit
simon.rit at creatis.insa-lyon.fr
Wed Nov 14 09:48:20 EST 2012
Hi,
I have experienced problems with FFTW in ITK 4. I am doing many
parallel FFT filters, each parallel thread having the piece of the
image defined by ThreadedGenerateData. This is a filter part of
www.openrtk.org which code is here:
https://github.com/SimonRit/RTK/blob/master/code/rtkFFTRampImageFilter.txx
I have originally done that with the code of Gaëtan Lehmann
(http://www.insight-journal.org/browse/publication/717) but I had to
fix it then for thread safety. I have now moved to ITK4 but I think
that the thread safety issue is still here since I have random
crashes. The problem is that the destroy functions are not protected
by the mutex although they are not thread safe
(http://www.fftw.org/doc/Thread-safety.html). So a lock / unlock must
be added around it in itkFFTWCommon.h.
The patch is below, let me know what you think.
Simon
PS: It is also worth of note that I have added a Lock/Unlock in the
BeforeThreadedGenerateData function of my filter to ensure that the
mutex is initialized.
The patch:
@@ -351,7 +350,9 @@ public:
}
static void DestroyPlan(PlanType p)
{
+ FFTWGlobalConfiguration::Lock();
fftwf_destroy_plan(p);
+ FFTWGlobalConfiguration::Unlock();
}
};
@@ -653,7 +654,9 @@ public:
}
static void DestroyPlan(PlanType p)
{
+ FFTWGlobalConfiguration::Lock();
fftw_destroy_plan(p);
+ FFTWGlobalConfiguration::Unlock();
}
};
More information about the Insight-users
mailing list