# ParallelizeImageRegion with multiple images?

**URL:** https://discourse.itk.org/t/parallelizeimageregion-with-multiple-images/1138
**Category:** Engineering
**Created:** [July 20, 2018, 3:23pm UTC](https://discourse.itk.org/t/parallelizeimageregion-with-multiple-images/1138 "2018-07-20T15:23:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spinicist](https://discourse.itk.org/user_avatar/discourse.itk.org/spinicist/32/183_2.png) [@spinicist](https://discourse.itk.org/u/spinicist)
#### Post date: [July 20, 2018, 3:23pm UTC](https://discourse.itk.org/t/parallelizeimageregion-with-multiple-images/1138/1 "2018-07-20T15:23:26Z")

</div>

Hello,

I am updating my code to ITK 5.0. In particular I’d like to take advantage of the parallelization improvements. However, the examples I’ve seen so far, e.g. [https://itk.org/ITKExamples/src/Core/Common/UseParallelizeImageRegion/Documentation.html](https://itk.org/ITKExamples/src/Core/Common/UseParallelizeImageRegion/Documentation.html) only deal with parallelizing over one image. I need to parallelize over multiple images, of different types. What’s the recommended approach to do so? I don’t `ParallelizeImageRegion()` is really suitable for this?

(If you are interested, I would like to update this beast of a filter: [https://github.com/spinicist/QUIT/blob/master/Source/Filters/ApplyAlgorithmFilter.hxx](https://github.com/spinicist/QUIT/blob/master/Source/Filters/ApplyAlgorithmFilter.hxx) to be a bit more sensible)

Thanks.

---

<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: [July 20, 2018, 4:30pm UTC](https://discourse.itk.org/t/parallelizeimageregion-with-multiple-images/1138/2 "2018-07-20T16:30:48Z")

</div>

Replace [this](https://github.com/spinicist/QUIT/blob/faefb8aa887ce3771592d51622ebb21065ee3eb7/Source/Filters/ApplyAlgorithmFilter.hxx#L232-L250) by something like this

```
this->GetMultiThreader()->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
this->GetMultiThreader()->template ParallelizeImageRegion<OutputImageDimension>(
    this->GetOutput()->GetRequestedRegion(),
    [this](const OutputImageRegionType & fullRegion)
      { this->DynamicThreadedGenerateData(outputRegionForThread); }, this);

```

And rename `ThreadedGenerateData` into `DynamicThreadedGenerateData` as per [migration guide](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/ITK5MigrationGuide.md#multithreading-refactored).

---

<div class="post-metadata">

### Author: ![spinicist](https://discourse.itk.org/user_avatar/discourse.itk.org/spinicist/32/183_2.png) [@spinicist](https://discourse.itk.org/u/spinicist)
#### Post date: [July 20, 2018, 8:27pm UTC](https://discourse.itk.org/t/parallelizeimageregion-with-multiple-images/1138/3 "2018-07-20T20:27:12Z")

</div>

Thanks @dzenanz, I think I have something working now. I missed the migration guide when googling earlier.
