[vtkusers] thread safety

Lodron, Gerald Gerald.Lodron at joanneum.at
Tue Sep 4 10:56:51 EDT 2012


I only tested it in a pipeline but the crash is not always in the New() method, I also tried to create all vtk Objects in the main thread and give the treads a pointer to the vtk objects, so the threads are only using vtk objects without creating or deleting them but they also crash anywhere. The pipeline was:

MyImage of our internal software lib (with a data pointer) which is internally splitted into image blocks
For each thread
{
                Take one block of MyImage
                Create a vtkImageData of the block
                Make vtkMarchingCubes
                Make Mutex.lock
                AddInput of vtkAppendPolyData
                Make Mutex.unlock
} until each block was calculated

Output of filter is output of vtkAppendPolyData

I tried also to comment the mutex and vtkAppendPolyData stuff so there was no vtk object shared between threads, also crashed.

Currently I solved the problem over copying the raw VTK code of every filter of my pipeline (only vtkMarchingCubes with its internal vtkMergePoints) and use this code in my multithreaded function. Since my filter only uses the vtkMarchingCubes and has a non vtk object as input (image from our internal lib), this works well. The return value is a std::vector of points and indices which are then concatenated in the main thread into a vtkPolyData, so the threads are now completely vtk object free.

I got a speed improvement of marching cubes over a blockwise sampled image of factor 5 (8 cores) in comparison to calculating marching cubes over one single big vtkImageData so in my opinion the vtkMarchingCubes should be implemented in a multithreaded manner too, but it is not possible because of the stupid behavior....

I also have a  code pipeline with the vtkHardwareSelector which detects a visible surface of a renderer in offscreen mode which could be also made multithreaded (for different camera positions) but the rendering code pipeline is a little bit too complex for me to reimplement it in vtk Object free code....

If anyone is interested in exact code I could send it (both) but as I told there is an object of our internal software lib as input but it should be easily understandable...





Von: Berk Geveci [mailto:berk.geveci at kitware.com]
Gesendet: Dienstag, 04. September 2012 16:37
An: David E DeMarle
Cc: Lodron, Gerald; (vtkusers at vtk.org)
Betreff: Re: [vtkusers] thread safety

Currently there are a lot of pitfalls in using VTK objects in a multi-threaded application. I am working on addressing some of them and I will also create a document describing what is and what is not possible.

What Gerald is describing should be possible. In fact, I have done it many times in the past. I can't answer why the crash is happening without doing some experimentation. Gerald: does the crash within a minimal code that simply create vtkImageData in multiple threads? Or does it need the full-blown filter to happen?

-berk
On Wed, Aug 29, 2012 at 12:14 PM, David E DeMarle <dave.demarle at kitware.com<mailto:dave.demarle at kitware.com>> wrote:
Unfortunately, VTK isn't thread safe, with the exception being
operations (mostly limited to array access methods that are declared
to be thread safe in doxygen) that take place in the Threaded* methods
in subclasses of vtkThreadedImageAlgorithm.

Berk is working on more wide scale thread/SMP parallel support, but
that won't be in until after 6.0.

If anyone on the list has had success in writing multithreaded VTK
programs, I'ld like to see examples along with descriptions of what
your approach was and what you had to mutex protect.

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909<tel:518-881-4909>


On Wed, Aug 29, 2012 at 2:47 AM, Lodron, Gerald
<Gerald.Lodron at joanneum.at<mailto:Gerald.Lodron at joanneum.at>> wrote:
> Hi
>
> I programmed an own vtk Filter which internally has multiple threads. In
> each thread I create a vtkImageData object using
>
> vtkSmartPointer<vtkImageData>       oImage = vtkImageData::New();
>
> the problem is that sometimes the New() operator crashes, I debugged it the
> the line 61 of vtkImageData.cxx:
>
> this->Information->Set(vtkDataObject::DATA_EXTENT(), this->Extent, 6);
>
> whereby the exact crash is in vtkInformationIntegerPointerKey.cxx on line
> 58:
>
> if(this->RequiredLength >= 0 && length != this->RequiredLength)
>
> wherehy the "this" pointer is zero. I am not so deep familiar with that, any
> suggestions?
>
> DI Gerald Lodron
>
> Machine Vision Applications
>
> DIGITAL - Institute for Information and Communication Technologies
>
> JOANNEUM RESEARCH Forschungsgesellschaft mbH
> Steyrergasse 17, 8010 Graz, AUSTRIA
>
> phone:   +43-316-876-1751<tel:%2B43-316-876-1751>       personal fax: +43-316-876-91751<tel:%2B43-316-876-91751>
> mobile:   +43-699-1876-1751<tel:%2B43-699-1876-1751>      general fax: +43-316-876-1720<tel:%2B43-316-876-1720>
> web: http://www.joanneum.at/digital
> e-mail: gerald.lodron at joanneum.at<mailto:gerald.lodron at joanneum.at>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com<http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120904/0166c2bb/attachment.htm>


More information about the vtkusers mailing list