[Insight-users] Non thread-safe transform in itk::ResampleImageFilter

Luis Ibanez luis.ibanez at kitware.com
Wed Mar 5 17:32:37 EST 2008


Hi Julien,


    ITK Transforms are in general, not thread-safe.


The method added to the itkTransform in the Code/Review
directory was an attempt to make the Transforms thread-safe
for the purpose of using them in ImageMetrics that were
made multi-threaded for improving the performance of the
image registration framework.

The two methods added to the Transform were overloads of

               TransformPoint()
               GetJacobian()

with an integer providing a threadId.


Further exploration of the code showed that this approach
was not appropriate for solving the issues of the image
registration framework, and we dropped this experimental
API, in favor of using N clones of the Transform object
and using each clone for one thread.


Note that the itkThreadSafeTransform class is no longer
available in the Code/Review directory.


To summarize:

      The TransformPoint() method with thread-id
      is no longer available.


Your options at this point are:

   1) Set the Number of threads of the
      ResampleImageFilter  to 1.

      You can do this by calling the method:

         resampler->SetNumberOfThreads(1);

      This will prevent the crashes, but will not
      take advantage of your multi-processor machine.

or


    2) Modify the itkResampleImageFilter to use
       Transform clones per thread. An example on
       how to do this can be found in


       Insight/Code/Review/itkOptImageToImageMetric.txx

       look for the array of Transform m_ThreadedTransform[].

       This will help *IF* your helper library has objects
       that are themselves not thread safe, but do not use
       static variables.

       If your helper library use static variables, then
       this approach is of no help at all.


or

    3) using Mutex....
       but ...
       that will probably kill the performance of the
       resampling filter.


Unless you are dealing with very large images, I would
suggest to take option (1), which simply tells the
resample image filter to not use multiple threads.


Of course,
there may be other options,
that are escaping me at this point.



     Regards,


        Luis



---------------------
Julien Michel wrote:
> Dear itk users,
> 
> We have developped some sub-classes of itk::Transform, in which the 
> output point is computed using another library. Unfortunately, it 
> appears that the object and the method we use in this library are not 
> thread safe (it implies allocation and free of some members ...). So 
> using the itk::ResampleImageFilter with these transforms on a 
> multi-processors environnement leads to segmentation fault.
> 
> The best would be to allocate one instance of this external library 
> object per thread, but inside the TransformPoint() method from 
> itk::Transform, we do not know neither if we are multi-threaded nor the 
> thread id.
> 
> I found that the itk::Transform method has a version of the 
> TransformPoint() method taking a thread id as argument, but it is 
> wrapped  with an itkNotUsedMacro(), and the ResampleImageFilter does not 
> seem to use it. Comments say that this method is keeped to preserve 
> backward compatibility. Morover, the itk::ResampleImageFilter does not 
> use this implementation. Is their a way to use this TransformPoint() 
> with thread id ?
> 
> The other solution would be to maintain a pool of objects with 
> associated mutex inside our transform, but it is rather inelegant ...
> 
> Thanks a lot for you help,
> Best regards,
> 
> Julien Michel
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list