# Running optimizer in parallel

**URL:** https://discourse.itk.org/t/running-optimizer-in-parallel/1421
**Category:** Algorithms
**Tags:** optimization, registration
**Created:** [November 16, 2018, 2:01pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421 "2018-11-16T14:01:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)
#### Post date: [November 16, 2018, 2:01pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/1 "2018-11-16T14:01:34Z")

</div>

Hello,

i have a question regarding parallel optimization. The actual setup is more cpmplex. Therefore I try to simplify.

I have a reference image and multiple other images. I want to register the other images onto the reference image. The transformations are expected to be different (or weakly coupled).  
Now I want to run each registration in parallel. This means I need to start multiple instances of optimizers (can be different optimizer types).

If I want to run the optimizers in parallel what would be the best approach?  
The ITK offers three Mutlithreading options:  
ThreadedGenerateData() -\> This seems to be for single images to be splitted and processed .  
itk::DomainThreader -\> This seems to be the most feasable option.  
itk::MultiThreader -\> This might also work but with a lot of overhead code.

Have someone done something like this and could provide some insight?

Thanks,  
Gordian

---

<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: [November 16, 2018, 2:27pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/2 "2018-11-16T14:27:35Z")

</div>

Hello Gordian,

The best approach is to [use `itk::MultiThreaderBase::ParallelizeImageRegion`](https://itk.org/ITKExamples/src/Core/Common/UseParallelizeImageRegion/Documentation.html) in ITK 5 Beta for the most flexibility, performance, and programming ease. Use a different optimizer instance in each thread because they will need independent optimization states.

HTH,  
Matt

---

<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: [November 16, 2018, 3:11pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/3 "2018-11-16T15:11:37Z")

</div>

You could also use [ParallelizeArray](https://itk.org/Doxygen/html/classitk_1_1MultiThreaderBase.html#ae66a7a935161cbed46022571ac9b0a12) method, so each index of the array corresponds to one moving image.

You could create a vector of file names of moving images, and parallelize over that. And the procedure you might want to run in parallel takes a pointer to the fixed image and a filename string. And that procedure could be just one of the example registration methods.

---

<div class="post-metadata">

### Author: ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)
#### Post date: [November 16, 2018, 3:24pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/4 "2018-11-16T15:24:12Z")

</div>

The ITK i am using is a modified version of ITK-4.13. As far as I can see the functions you mentioned are not available.  
Is there a possible replacement or an easy way to introduce the MultiThreaderBase class to 4.13?

---

<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: [November 16, 2018, 3:35pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/5 "2018-11-16T15:35:30Z")

</div>

> [@Gordian](#):
>
> I have a reference image and multiple other images.

@dzenanz is right, and `ParallelizeArray` is better for this case.

These functions are only available in ITK 5 as a result of a major amount of internal refactoring.

---

<div class="post-metadata">

### Author: ![gdevenyi](https://discourse.itk.org/user_avatar/discourse.itk.org/gdevenyi/32/355_2.png) [@gdevenyi](https://discourse.itk.org/u/gdevenyi)
#### Post date: [December 3, 2025, 7:25pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/6 "2025-12-03T19:25:17Z")

</div>

Is there an equivalent function in SimpleITK

---

<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: [December 3, 2025, 8:42pm UTC](https://discourse.itk.org/t/running-optimizer-in-parallel/1421/7 "2025-12-03T20:42:34Z")

</div>

There are a variety of task based parallelism tools available in Python. There is the build in `concurrent` and `multiprocessing` modules, along with tools like Disk, or even higher level workflow frameworks like Prefect. Please create a new topic and describe your particular case if you’d like more specific recommendations or to continue a new conversation.
