[Insight-developers] interrupting filter execution

Miller, James V (GE, Research) millerjv at crd.ge.com
Wed Jul 19 16:19:07 EDT 2006


On a multiprocessor system, the DiscreteGaussian will 
create multiple threads.  Any exceptions thrown in these threads
should be caught by the Multithreader and passed to the main 
thread (of the DiscreteGaussian).  

I have to think about this.  I don't recall whether all threads
of a filter check the abort execute and stop cleanly.  I have to 
dig into the ProcessAccumulator to see.

Jim

-----Original Message-----
From: insight-developers-bounces+millerjv=crd.ge.com at itk.org
[mailto:insight-developers-bounces+millerjv=crd.ge.com at itk.org]On Behalf
Of Paul Koshevoy
Sent: Wednesday, July 19, 2006 2:13 PM
To: insight-developers at itk.org
Subject: Re: [Insight-developers] interrupting filter execution


Miller, James V (GE, Research) wrote:
> You have to catch the exception in the thread from which it was thrown.
> I do not know of a way to have to have exception pass to the main thread.
>   
I do not need to pass the exception to the main thread -- that's where
the UI lives. I want to catch the exception in the worker thread and
stop the thread.

I am concerned about the changes I was told to make to
ProgressAccumulator. I don't know how that class interacts with
multi-threaded filters. Throwing an exception from
ProgressAccumulator::ReportProgress so far has been suicidal -- the
catch block never caught it.

Here is my code with the try/catch block moved closer to the
filter->update() call.


template <typename T>
typename T::Pointer
smooth(const T * in,
       const double sigma,
       const double maximum_error = 0.1)
{
  typedef typename itk::DiscreteGaussianImageFilter<T, T> smoother_t;
  typename smoother_t::Pointer smoother = smoother_t::New();
 
  // FIXME:
  itk::SimpleFilterWatcher w(smoother.GetPointer(), "smoother");
 
  smoother->SetInput(in);
  smoother->SetUseImageSpacing(false);
  smoother->SetVariance(sigma * sigma);
  smoother->SetMaximumError(maximum_error);
 
  // FIXME: remove this:
  try
  {
    terminator_t<smoother_t> terminator(smoother);
    smoother->Update();
  }
  catch (...)
  {
    cerr << "caught an exception thrown by the smoother" << endl;
    assert(false);
  }
 
  return smoother->GetOutput();
}

Below is the execution log generated by GDB and SimpleFilterWatcher. LWP
23470 is the worker thread. I suspect LWP 23471 is a thread started by
the ImageFileReader. I think LWP 23472 is the thread started by
DiscreteGaussianImageFilter. The try/catch block lives in the 23470
thread, therefore if 23472 throws an exception I will not be able to
catch it.

[New Thread 1077832032 (LWP 23470)]
loading a mosaic
[New Thread 1079933280 (LWP 23471)]
[Thread 1079933280 (LWP 23471) exited]
-------- Start DiscreteGaussianImageFilter "smoother"
DiscreteGaussianImageFilter (0x2aaab10130c0)
  RTTI typeinfo:   itk::DiscreteGaussianImageFilter<itk::Image<float,
2u>, itk::Image<float, 2u> >
  Reference Count: 4
  Modified Time: 290
  Debug: Off
  Observers:
    StartEvent(SimpleMemberCommand)
    EndEvent(SimpleMemberCommand)
    ProgressEvent(SimpleMemberCommand)
    IterationEvent(SimpleMemberCommand)
    AbortEvent(SimpleMemberCommand)
  Number Of Required Inputs: 1
  Number Of Required Outputs: 1
  Number Of Threads: 2
  ReleaseDataFlag: Off
  ReleaseDataBeforeUpdateFlag: Off
  Input 0: (0x2aaab1012e70)
  Output 0: (0x2aaab10131e0)
  AbortGenerateData: Off
  Progress: 0.00000000e+00
  Multithreader:
    RTTI typeinfo:   itk::MultiThreader
    Reference Count: 1
    Modified Time: 274
    Debug: Off
    Observers:
      none
    Thread Count: 2
    Global Maximum Number Of Threads: 0
  Variance: [4.00000000e+00, 4.00000000e+00]
  MaximumError: [1.00000000e-01, 1.00000000e-01]
  MaximumKernelWidth: 32
  FilterDimensionality: 2
  UseImageSpacing: 0
Progress [New Thread 1079933280 (LWP 23472)]
 | 0.00000000e+00 | 1.11108751e-03 | 2.22217501e-03 | 3.33326240e-03 |
4.44435002e-03 | 5.55543741e-03 | 6.66652480e-03 | 7.77761219e-03 |
8.88870005e-03 | 9.99978743e-03
 | 1.11108748e-02 | 1.22219622e-02 | 1.33330496e-02 | 1.44441379e-02 |
1.55552244e-02 | 1.66663136e-02 | 1.77774001e-02 | 1.88884865e-02 |
1.99995749e-02 | 2.11106632e-02
 | 2.22217496e-02 | 2.33328380e-02 | 2.44439244e-02 | 2.55550127e-02 |
2.66660992e-02 | 2.77771875e-02 | 2.88882758e-02 | 2.99993623e-02 |
3.11104488e-02 | 3.22215371e-02
 | 3.33326273e-02 | 3.44437137e-02FIXME: ABORT: DiscreteGaussianImageFilter
terminate called after throwing an instance of 'itk::ProcessAborted'
  what():  Unknown:0:
Filter execution was aborted by an external request

Program received signal SIGABRT, Aborted.
[Switching to Thread 1077832032 (LWP 23470)]
0x00002aaaaf72843a in raise () from /lib64/tls/libc.so.6
(gdb)
 


_______________________________________________
Insight-developers mailing list
Insight-developers at itk.org
http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list