[Insight-users] Re: pointers and memory allocation...
Luis Ibanez
luis.ibanez@kitware.com
Tue, 03 Dec 2002 09:38:04 -0500
Hi digvijay,
From your description I understand that you are
changing the number of parameters in the cost
function at run time. Is that correct ?
How are you initializing the second stage of the
optimization if you need extra parameters ?
You may probably want to use two instances of
the optimizer.
If you need to track memory problems in your
application, "valgrind" can be a very useful
tool. It is quite easy to install on Linux.
"ddd" can also be very helpful for keeping
track of access to variables.
Hope this helps,
Luis
=============================================
digvijay singh wrote:
>
> hi luis !!
> i was trying to run an optimization routine
> successively ... five optimizations with a single
> variable to optimize and followed by once with four
> variables. The first five optimizations run smoothly
> but then on the sixth occasion(4 parameters) the
> program terminates giving a segmentation fault.
> The optimizer when called starts the optimization
> evaluates no of parameters , goes to calculate error
> in get value , moves on to calculate derivative,
> reasseses the no. of parameters and after doing that
> does not go to get value , giving instead the
> segmentation fault.
> the error on doing a backtrace looks like
> *****************************
> #0 0xff1c2164 in realfree () from /usr/lib/libc.so.1
> #1 0xff1c2a70 in cleanfree () from /usr/lib/libc.so.1
> #2 0xff1c1ba4 in _malloc_unlocked () from
> /usr/lib/libc.so.1
> #3 0xff1c1a98 in malloc () from /usr/lib/libc.so.1
> #4 0x000cc838 in __builtin_new (sz=32) at
> ../../gcc/cp/new1.cc:84
> #5 0x000cc92c in __builtin_vec_new (sz=32) at
> ../../gcc/cp/new2.cc:39
> #6 0x00025860 in vnl_c_vector<double>::allocate_T
> (n=4)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Numerics/vxl/vnl/vnl_c_vector.txx:270
> #7 0x0001dd4c in vnl_vector<double>::vnl_vector
> (this=0xffb79760, v=@0x1430fc)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Numerics/vxl/vnl/vnl_vector.txx:149
> #8 0x0006dd30 in itk::Optimizer::GetScales
> (this=0x1430b0)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Common/itkArray.h:73
> #9 0x00068b9c in
> itk::GradientDescentOptimizer::AdvanceOneStep
> (this=0x1430b0)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Numerics/itkGradientDescentOptimizer.cxx:178
> #10 0x0006850c in
> itk::GradientDescentOptimizer::ResumeOptimization
> (this=0x1430b0)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Numerics/itkGradientDescentOptimizer.cxx:123
> #11 0x0006841c in
> itk::GradientDescentOptimizer::StartOptimization
> (this=0x1430b0)
> at
> /opt/tools/itk/Insight_Nightly/Insight/Code/Numerics/itkGradientDescentOptimizer.cxx:81
> #12 0x00014b48 in _end ()
> at
> /home/vertebra/digvijay/itk/proj_1/Optimizers/itkGradientDescentOptimizerTest.cxx:1010
> #13 0x00015120 in
> gradientCostFunction::itkGradientDescentOptimizerTest
> (this=0xffba0ae8,
> argc=3, argv=0xffbeee4c)
> at
> /home/vertebra/digvijay/itk/proj_1/Optimizers/itkGradientDescentOptimizerTest.cxx:1122
> #14 0x00019490 in main (argc=3, argv=0xffbeee4c)
> at
> /home/vertebra/digvijay/itk/proj_1/Optimizers/itkGradientDescentOptimizerTest.cxx:1744
> **************************************************
> and the list gives :
> ************************************************
> enum { SpaceDimension_one = 1};
> 85 enum { SpaceDimension_two = 4};
> 86 enum { SpaceDimension_three = 4};
> 87 */
> 88 typedef Superclass::ParametersType
> ParametersType;
> 89 typedef Superclass::DerivativeType
> DerivativeType;
> 90 typedef Superclass::MeasureType
> MeasureType ;
> 91
> 92 gradientCostFunction()
> ***************
> the optimizer runs well when run with one
> parameter(stage 1) for 5 occasions (field 1-5 )..on
> the sixth occasion (stage 2) it runs one iteration and
> goes bonkers, although there is an accomodation for
> the stage 2 in all functions that optimization
> handles....
> i do not understand what memory allocations are giving
> the fault .. kindly advise..any suggestion would be
> welcome
> thanks
> digvijay
>