[Insight-developers] multithreading update w/example code

Damion Shelton dmshelto@andrew.cmu.edu
Mon, 22 Apr 2002 13:46:39 -0400


Hi,

In our continuing efforts to track down the multithreading weirdness with a 
dual Athlon XP machine, we've narrowed our test code down to the following 
example, which does not include any of our own code.

Based on the debug output, it looks like it hangs in the gradient filter. 
By "hangs", we mean that the processor usage drops to 0% and the program 
never returns.

Any ideas, please let us know. We can check this in as 
"itkMultithreadingTest" or something similar if that would be a help in 
diagnosing the problem.

Thanks,
Damion and Wilson

------

#include <stdio.h>

// Basic ITK stuff
#include "itkSize.h"
#include "itkIndex.h"
#include "itkImage.h"
#include "itkImageRegionIterator.h"
#include "itkPoint.h"
#include "itkShrinkImageFilter.h"
#include "itkGradientImageFilter.h"

// Image file reading
#include "itkImageFileReader.h"
#include "itkMetaImageIOFactory.h"

// Main for testing BloxImage/BloxPixel storage
void main()
{
  const unsigned int dim = 3;

  // Image typedef
  typedef itk::Image< unsigned char, dim > TImageType;
  typedef itk::ImageFileReader<TImageType> ImageFileReaderType;

  // The input file reader
  ImageFileReaderType::Pointer reader;

  //set up the reader and register the possible types
  reader = ImageFileReaderType::New();
  reader->DebugOn();
  itk::MetaImageIOFactory::RegisterOneFactory();
  reader->SetFileName("d:/brainweb/brainweb1.mha");
  reader->GetOutput()->SetRequestedRegionToLargestPossibleRegion();
  reader->Update();

  // Shrink by a factor of 2
  typedef itk::ShrinkImageFilter<TImageType, TImageType> ShrinkType;
  ShrinkType::Pointer pShrink = ShrinkType::New();
  pShrink->SetShrinkFactors(2);
  pShrink->SetInput( reader->GetOutput() );

  // Create a gradient filter
  typedef itk::GradientImageFilter<TImageType> TGradientFilter;
  TGradientFilter::Pointer gradFilter = TGradientFilter::New();
  gradFilter->DebugOn();
  gradFilter->SetInput( pShrink->GetOutput() );

  // Run the whole pipeline
  gradFilter->Update();

  // Get the output of the pipeline
  TGradientFilter::OutputImageType::Pointer gradOutput = 
gradFilter->GetOutput();
}