Skip to content

Commit

Permalink
Made progress reporting behave better with Python wrappings
Browse files Browse the repository at this point in the history
There was deadlock when multiple threads were trying to acquire
the lock to update the progress. I think a problem was caused
when a non-zero thread tried to call UpdateProgress(). Now
only thread zero calls UpdateProgress() periodically and passes
it the total filter progress.
  • Loading branch information
Cory Quammen committed Aug 2, 2012
1 parent 7a18f8b commit c5eb566
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 13 additions & 7 deletions vtkPartialVolumeModeller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "vtkBoxClipDataSet.h"
#include "vtkCell.h"
#include "vtkCellLocator.h"
#include "vtkCriticalSection.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkGenericCell.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiThreader.h"
#include "vtkMutexLock.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkRectilinearGrid.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ vtkPartialVolumeModeller::vtkPartialVolumeModeller()

this->Threader = vtkMultiThreader::New();
this->NumberOfThreads = this->Threader->GetNumberOfThreads();
this->ProgressMutex = vtkSimpleMutexLock::New();
this->ProgressMutex = vtkSimpleCriticalSection::New();
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -329,6 +329,11 @@ VTK_THREAD_RETURN_TYPE vtkPartialVolumeModeller::ThreadedExecute( void *arg )
{
userData->Modeller->UpdateThreadProgress(voxelProgressWeight*count);
count = 0;

if (threadId == 0)
{
userData->Modeller->UpdateProgress( userData->Modeller->TotalProgress );
}
}
++count;
}
Expand All @@ -337,6 +342,10 @@ VTK_THREAD_RETURN_TYPE vtkPartialVolumeModeller::ThreadedExecute( void *arg )

// Report the remnants
userData->Modeller->UpdateThreadProgress(voxelProgressWeight*count);
if (threadId == 0)
{
userData->Modeller->UpdateProgress( userData->Modeller->TotalProgress );
}

clipper->Delete();
surfaceFilter->Delete();
Expand Down Expand Up @@ -426,6 +435,7 @@ int vtkPartialVolumeModeller::RequestData(
}
this->Threader->SetSingleMethod( vtkPartialVolumeModeller::ThreadedExecute,
(void *)&info);
this->TotalProgress = 0.0;
this->Threader->SingleMethodExecute();

// Clean up.
Expand Down Expand Up @@ -555,13 +565,9 @@ void vtkPartialVolumeModeller::UpdateThreadProgress(double threadProgress)
{
this->ProgressMutex->Lock();

double filterProgress = this->GetProgress();

// This doesn't exactly represent the fraction of work contributed
// by the thread to the total problem, but it's good enough.
filterProgress += threadProgress / static_cast<double>(this->Threader->GetNumberOfThreads());

this->UpdateProgress(filterProgress);
this->TotalProgress += threadProgress / static_cast<double>(this->Threader->GetNumberOfThreads());

this->ProgressMutex->Unlock();
}
Expand Down
11 changes: 7 additions & 4 deletions vtkPartialVolumeModeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "vtkImageAlgorithm.h"

class vtkMultiThreader;
class vtkSimpleMutexLock;
class vtkSimpleCriticalSection;

class VTK_ABI_EXPORT vtkPartialVolumeModeller : public vtkImageAlgorithm
{
Expand Down Expand Up @@ -112,15 +112,18 @@ class VTK_ABI_EXPORT vtkPartialVolumeModeller : public vtkImageAlgorithm

static VTK_THREAD_RETURN_TYPE ThreadedExecute( void *arg );

vtkMultiThreader *Threader;
int NumberOfThreads;
vtkSimpleMutexLock *ProgressMutex;
vtkMultiThreader *Threader;
int NumberOfThreads;
vtkSimpleCriticalSection *ProgressMutex;

int SampleDimensions[3];
double MaximumDistance;
double ModelBounds[6];
int OutputScalarType;

// Keeps track of the total progress of the filter
double TotalProgress;

private:
vtkPartialVolumeModeller(const vtkPartialVolumeModeller&); // Not implemented
void operator=(const vtkPartialVolumeModeller&); // Not implemented
Expand Down

0 comments on commit c5eb566

Please sign in to comment.