# RegistrationV4 and BsplineTransform Parallellization

**URL:** <https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683>\
**Category:** Algorithms\
**Tags:** registration\
**Created:** [December 7, 2020, 6:31pm UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683 "2020-12-07T18:31:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 7, 2020, 6:31pm UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683/1 "2020-12-07T18:31:55Z")

</div>

Hello everyone.

As I’ve been mentioning in my previous posts, I am working in a deformable registration pipeline.  
It happens that I am running my tests in a supercomputer and noticed that the code I wrote **using ITK classes ItkRegistrationV4 and ItkBsplineTransform** is not parallel.

How can I make it parallel? Is there any previously defined way to do that in ITK?

---

<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:** [December 7, 2020, 10:09pm UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683/2 "2020-12-07T22:09:49Z")

</div>

Registration code in ITK is parallel. What might be a problem is weirdness of the supercomputer. You can change the number of threads to see how that affects speed. Take a look at the code which initializes max number of threads:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/v5.1.2/Modules/Core/Common/src/itkMultiThreaderBase.cxx#L279-L350>

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [December 8, 2020, 1:09am UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683/3 "2020-12-08T01:09:06Z")

</div>

Some speed improvement is expected if you distribute a registration task to run on more cores, but as you slice the problem into smaller pieces, the relative overhead increases. At some point adding more cores will not improve the performance anymore but will start to slow things down.

If you want to use hundreds of cores work efficiently in parallel on a single registration task then you may need to implement new registration algorithms, or at least redesign the implementation for your special computing architecture.

If you do batch processing then you can achieve high efficiency by running multiple independent registration tasks in parallel (each independent registration running on one or few threads).

---

<div class="post-metadata">

**Author:** ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)\
**Post date:** [December 8, 2020, 5:47pm UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683/4 "2020-12-08T17:47:35Z")

</div>

All right. I partially got it.  
What I still did not get is HOW can I change the NUMBER OF THREADS?  
Or how can I distribute my registration task over more cores?  
Do I have to include a specific class? Fold my code with some other loop?

I have two computers: one with 7 cores, other with 64 cores.

My code right now is basically the **[DeformableRegistration8.cxx](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/RegistrationITKv4/DeformableRegistration8.cxx)** example.

Thank you very much!

---

<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:** [December 8, 2020, 9:34pm UTC](https://discourse.itk.org/t/registrationv4-and-bsplinetransform-parallellization/3683/5 "2020-12-08T21:34:28Z")

</div>

Try invoking in bash like this:

```bash
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 ./DeformableRegistration8 /path/to/input1 /path/...

```

This temporarily sets environment variable `ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS` during execution of the command which follows.
