[vtkusers] How to use OpenMP with VTK

Sunrise helios.corona at gmail.com
Wed Mar 19 14:09:44 EDT 2014


Thanks a lot for the SMP suggestion and the reference, David and Berk!

SMP framework seems much more organized. I will definitely ask you if I
needed help.

Thanks.
-Sia

On 03/18/2014 05:29 AM, Berk Geveci wrote:
> For reference: http://www.vtk.org/Wiki/images/3/3b/VTK_SMP_Guide.pdf
>
> This is a work in progress so please feel free to ask questions.
>
> To answer your specific question, GetTuple1() is not thread safe. You
> need to use a version of GetTuple() that is thread safe. Like this
> one:
>
>   virtual void GetTuple(vtkIdType i, double * tuple);
>
> For this type of work, you will have to make sure that each function
> that you use in a parallel section is thread safe by checking out the
> implementation. Currently, this is the only way.
>
> Best,
> -berk
>
>
> On Mon, Mar 17, 2014 at 4:59 PM, David E DeMarle
> <dave.demarle at kitware.com> wrote:
>> I recommend you follow the pattern of the filters Filters/SMP (first
>> appearing vtk 6.1).
>> OpenMP is one of the threading back ends that these filters can use
>> efficiently.
>>
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 21 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-881-4909
>>
>>
>> On Mon, Mar 17, 2014 at 4:35 PM, Sunrise <helios.corona at gmail.com> wrote:
>>> Hello,
>>>
>>> I would like to parallelize the vtk filter that I wrote using OpenMP, and
>>> I just started learning OpenMP on a need basis. A part of code is a for loop
>>> over tuples of a vtkDoubleArray. Each tuple is associated with a point on
>>> Data. The computation for each point is totally independent and
>>> embarrassingly parallelize-able. A short version of part of the code is
>>>
>>> vtkDoubleArray *InputArray = ... // Get it from Input Data
>>> vtkDoubleArray *OutputArray = ... // Define new array
>>>
>>> #pragma omp parallel for
>>> for(int PointId = 0; PointId < InputArray->GetNumberOfTuples(); PointId++)
>>> {
>>>     double InputValue = InputArray->GetTuple1(PointId);
>>>     double OutputValue = DoSomething(InputValue,OtherParameters);
>>>     OutputArray->SetTuple1(OutputValue);
>>> }
>>>
>>> However, I am getting the following error for GetTuple1() method:
>>>
>>> ERROR: In
>>> /SomePath/paraview/ParaView-4.1.0-source/VTK/Common/Core/vtkDataArrayTemplate.txx,
>>> line 598
>>> vtkDoubleArray (0x14bf6808): Unable to allocate 1 elements of size 8
>>> bytes.
>>>
>>> Aborted
>>>
>>> Could anyone help me to use OpenMP within my filter?
>>>
>>> Thank you,
>>> -Sia
>>>
>>> _______________________________________________
>>> Powered by 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
>>
>> 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
>>



More information about the vtkusers mailing list