# New Multithreaded LagrangianParticleTracker.

**URL:** https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838
**Category:** Tips and Tricks
**Created:** [May 13, 2019, 12:01pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838 "2019-05-13T12:01:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 13, 2019, 12:01pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/1 "2019-05-13T12:01:36Z")

</div>

**Multithreaded LagrangianParticleTracker**

The LagragianParticleTracker filter, provided in a Plugin in ParaView,  
has been reimplemented with an multithreaded algorithm using VTK SMP backed that one can benefit from when using TBB or OpenMP as SMP backend when compiling ParaView.  
Note that those changes imply some update on user-developed Lagrangian Integration models  
as some method signatures have been modified.

**Important code changes**

1. A few methods signatures of vtkLagrangianParticleTracker, vtkLagrangianBasicIntegrationModel and vtkLagrangianParticle have changed:

- vtkLagrangianParticleTracker::Integrate/ComputeNextStep(vtkInitialValueProblemSolver\* integrator, …): Integrator are now passed to this method for further usage;
- vtkLagrangianBasicIntegrationModel::FonctionValues/FindInLocator(vtkLagrangianParticle\* particle, … ): There is no concept of CurrentParticle anymore and the particle are passed through these methods;
- vtkLagrangianParticle::SetLastCell(vtkAbstractCellLocator\* locator, …): The particle is now fully responsible of tracking last locator, data, cell and weights;

1. Accessing flow or surface data within your FonctionValues is also now a little bit different:

```auto
      // Fetch flowVelocity at index 3  
      double flowVelocity[3]; 
      if (this->GetFlowOrSurfaceDataNumberOfComponents(3, dataSet) != 3 || 
        !this->GetFlowOrSurfaceData(3, dataSet, cellId, weights, flowVelocity)) 
      { 
        vtkErrorMacro(<< "Flow velocity is not set in source flow dataset or " 
                         "have incorrect number of components, cannot use Matida”
     “equations"); 
        return 0; 
      } 

```

1. Some methods now need to be thread-safe, so that may impact your own implementation. Here is the exhaustive list:

```auto
    In vtkLagrangianParticleTracker: 
    GetNewParticleId 
    Integrate 
    ComputeNextStep 
     
    In vtkLagrangianBasicIntegrationModel: 
    FonctionValues 
    FindInLocators 
    CheckFreeFlightTermination  
    ManualIntegration 
    FindInLocator  
    TerminateParticle 
    BounceParticle 
    BreakParticle (use ParticleQueueMutex before adding new particle)  
    InteractWithSurface (use ParticleQueueMutex before adding new particle)  
    IntersectWithLine  
    InterpolateNextParticleVariables  
    CheckSurfacePerforation  
    GetSeedArray  
    GetFlowOrSurfaceData  
    GetFlowOrSurfaceDataNumberOfComponents  
    GetFlowOrSurfaceDataFieldAssociation 

```

1. A few mutexes are present in the code, the only one you may need to use would be vtkLagrangianBasicIntegrationModel::ParticleQueueMutex before adding particles in the particleQueue, e.g. when interacting with a surface.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 20, 2019, 5:09pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/2 "2019-12-20T17:09:38Z")

</div>

Almost all mutexes have been removed providing an even better speedup. See here :  
[https://gitlab.kitware.com/vtk/vtk/merge\_requests/6240](https://gitlab.kitware.com/vtk/vtk/merge_requests/6240)

---

<div class="post-metadata">

### Author: ![sharon](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://discourse.paraview.org/u/sharon)
#### Post date: [January 12, 2020, 1:38pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/3 "2020-01-12T13:38:25Z")

</div>

Hi Mathieu,

To make TBB enable, should i use “VTK\_SMP\_IMPLEMENTATION=TBB” or “VTK\_SMP\_IMPLEMENTATION\_TYPE=TBB”?  
I can found “VTK\_SMP\_IMPLEMENTATION\_TYPE” in one of cmake files but cannot find VTK\_SMP\_IMPLEMENTATION" which is suggested in paraview build [https://github.com/Kitware/ParaView/blob/master/Documentation/dev/build.md](https://github.com/Kitware/ParaView/blob/master/Documentation/dev/build.md)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 12, 2020, 7:19pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/4 "2020-01-12T19:19:32Z")

</div>

VTK\_SMP\_IMPLEMENTATION\_TYPE=TBB

There is a typo in build.md.

---

<div class="post-metadata">

### Author: ![sharon](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://discourse.paraview.org/u/sharon)
#### Post date: [January 13, 2020, 12:09pm UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/5 "2020-01-13T12:09:38Z")

</div>

Thank you Mathieu for your answers!

Best Regards,  
Sharon

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 17, 2020, 9:56am UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/6 "2020-01-17T09:56:46Z")

</div>

@sharon : Do you think you could take care of correcting the typographic issue ? That would be nice of you.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [February 13, 2020, 7:44am UTC](https://discourse.paraview.org/t/new-multithreaded-lagrangianparticletracker/1838/7 "2020-02-13T07:44:39Z")

</div>

[https://gitlab.kitware.com/paraview/paraview/merge\_requests/3918](https://gitlab.kitware.com/paraview/paraview/merge_requests/3918)
