[Insight-developers] BSplineInterpolateImageFunction

Miller, James V (Research) millerjv at crd . ge . com
Thu, 18 Dec 2003 20:32:15 -0500


I think is Lydia is right.  If these local variables are made 
ivars then the methods would not be thread safe. 

I favor erring on the side of being too thread safe. It is just too
hard to find threading errors when they occur to promote being 
non-thread safe.

Another approach is to provide an API where the matrices 
can be passed into the routine.  This is equivalent to the 
netlib routines where you have to pass in the "scratch" space.
This approach would allow each thread in an algorithm to pass 
its own scratch space down to the method on each call.  The 
scratch space would then only have to be allocated once 
per thread instead of once per call.


-----Original Message-----
From: Lydia Ng [mailto:lng at insightful . com]
Sent: Thursday, December 18, 2003 7:09 PM
To: Brad King; Insight Developers
Subject: RE: [Insight-developers] BSplineInterpolateImageFunction


Question: if I make these member data and mutable does that mean one can't
use the same interpolator in different threads of a filter?

In the past we had several discussions of const-ness and thread safety
regarding the interpolators. To make everyone happy - the function is both
const and thread safe - the lowest common denominator even though it is at
the expense of dynamic memory allocation.

Perhaps we need to make some of sort of community decision of what objects
and what methods need const and/or thread safe.

- Lydia

> -----Original Message-----
> From: Brad King [mailto:brad . king at kitware . com]
> Sent: Thursday, December 18, 2003 1:40 PM
> To: Insight Developers
> Subject: [Insight-developers] BSplineInterpolateImageFunction
> 
> Hello,
> 
> While tracking down a recent test failure, I noticed that
> BSplineInterpolateImageFunction has vnl_matrix local variables in its
> EvaluateAtContinuousIndex and EvaluateDerivativeAtContinuousIndex methods.
> When used in a registration method, this effectively does a dynamic memory
> allocation and free per pixel!
> 
> I think these variables should be changed to member data for the class.
> Since EvaluateAtContinuousIndex and EvaluateDerivativeAtContinuousIndex
> are const methods, the matrices will have to be mutable (whether these
> methods should be const is a separate discussion).  I expect a substantial
> speed improvement will be achieved by this relatively simple change.
> 
> Will the author of this class please look at making the change?
> 
> Thanks,
> -Brad
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk . org
> http://www . itk . org/mailman/listinfo/insight-developers
_______________________________________________
Insight-developers mailing list
Insight-developers at itk . org
http://www . itk . org/mailman/listinfo/insight-developers