# Add possibility to control TBB region splitter

**URL:** https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666
**Category:** Beginner Questions
**Created:** [January 31, 2020, 2:44pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666 "2020-01-31T14:44:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![illia.kramarenko](https://discourse.itk.org/user_avatar/discourse.itk.org/illia.kramarenko/32/1165_2.png) [@illia.kramarenko](https://discourse.itk.org/u/illia.kramarenko)
#### Post date: [January 31, 2020, 2:44pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/1 "2020-01-31T14:44:29Z")

</div>

Hi,  
In the ITK 5.0 you’ve added new multithreading approach using the TBB library. Now it’s possible to parallelize work on a pixel level. My question is in following - how can I force TBB splitter to stop on slice level? I’m using my own data structures and I want to run default ITK filters on these data structures. Earlier ITK provides a virtual method SplitRequestedRegion(…) and this was enough for me.

But now almost the same functionality (TBBImageRegionSplitter) is in file Modules/Core/Common/src/itkTBBMultiThreader.cxx under the anonymous namespace and now I cannot control splitting without changing ITK.

Maybe it is possible to pass region splitter as lambda or provide a method to override it in ITK?  
I do realize that I can use old parallelization but it will be great to use a new TBB approach.

Thanks for your help!  
Illia.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 31, 2020, 2:54pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/2 "2020-01-31T14:54:22Z")

</div>

Welcome to the community Illia!

Currently there is no way for ITK user to modify TBB’s splitting behavior. You are welcome to propose a PR which introduces an API for controlling the region splitting process. If you decide to try that, beware that the default multi-threader can be selected by environment variable, and that it might not be `TBBMultiThreader` despite that being the default if it is built.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 31, 2020, 3:21pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/3 "2020-01-31T15:21:55Z")

</div>

Perhaps `ParallelizeImageRegionRestrictDimension` meets your needs:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/ca670a797bac1109cc5cc63b3d26d5a1c8c1fd9e/Modules/Core/Common/include/itkMultiThreaderBase.h#L316-L325>

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [January 31, 2020, 3:28pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/4 "2020-01-31T15:28:56Z")

</div>

If you can consider splitting your data into N things, then the `ParallelizeArray` method may be a good fit. N things could be N ImageRegions computed on the fly.

> <https://github.com/InsightSoftwareConsortium/ITK/blob/ca670a797bac1109cc5cc63b3d26d5a1c8c1fd9e/Modules/Core/Common/include/itkMultiThreaderBase.h#L280-L289>

---

<div class="post-metadata">

### Author: ![illia.kramarenko](https://discourse.itk.org/user_avatar/discourse.itk.org/illia.kramarenko/32/1165_2.png) [@illia.kramarenko](https://discourse.itk.org/u/illia.kramarenko)
#### Post date: [January 31, 2020, 4:52pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/5 "2020-01-31T16:52:14Z")

</div>

Hi,

Thanks for the reply! I’ve looked at this function but it didn’t help me because I want to run default ITK filters on my data structures. I can write a new filter using ParallelizeImageRegionRestrictDimension but my goal is to run out of box ITK filters without changing source code.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [January 31, 2020, 5:05pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/6 "2020-01-31T17:05:12Z")

</div>

I don’t think any of the multi-threaders use the Filter’s Splitter any more. It looks like it might be possible to restore it for the PlatformMultiThread and the PoolMultiThreader. Currently the multthreaders just use the global default as opposed to the filters:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/src/itkMultiThreaderBase.cxx#L600>

Could you use one of the other threaders?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [February 1, 2020, 4:08pm UTC](https://discourse.itk.org/t/add-possibility-to-control-tbb-region-splitter/2666/7 "2020-02-01T16:08:40Z")

</div>

`DynamicThreadedGenerateData` does not use the filter’s splitter. When that is needed, `ThreadedGenerateData` should be used, as per classic multi-threading model.
