# Numba with multiprocessing

**URL:** <https://numba.discourse.group/t/numba-with-multiprocessing/1118>\
**Category:** Support: How do I do ...?\
**Created:** [January 9, 2022, 1:45pm UTC](https://numba.discourse.group/t/numba-with-multiprocessing/1118 "2022-01-09T13:45:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![doliolarzz](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@doliolarzz](https://numba.discourse.group/u/doliolarzz)\
**Post date:** [January 9, 2022, 1:45pm UTC](https://numba.discourse.group/t/numba-with-multiprocessing/1118/1 "2022-01-09T13:45:02Z")

</div>

Hello,  
I’ve tried to run some njit functions with python’s multiprocessing as the minimal example code below.  
But, somehow, running with multiprocessing is slower (around 0.01x compared to normal run).

I suspect that it’s because compiling overhead, each process has to compile njit function by itself.  
Is there any workaround to make multiprocessing’s method faster?

Thank you

Update: it’s not about compiling overhead. I’ve pre-compile the function following the guide ([Compiling code ahead of time — Numba 0.52.0.dev0+274.g626b40e-py3.7-linux-x86\_64.egg documentation](https://numba.pydata.org/numba-doc/dev/user/pycc.html)) and called it in multiprocessing, but speed still the same.

```auto
import numba
import multiprocessing

@numba.njit()
def a(arg):
    # a CPU intensive task
    None

@numba.njit()
def b(arg):
    # a CPU intensive task
    None

@numba.njit()
def all(arg):
    a(arg)
    b(arg)

if __name__ == " __main__":

    # running normally
    for a in args:
        all(*a)

    # running with multiprocessing
    with multiprocessing.Pool(8) as p:
        p.starmap(all, args)

```

---

<div class="post-metadata">

**Author:** ![luk-f-a](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/luk-f-a/32/56_2.png) [@luk-f-a](https://numba.discourse.group/u/luk-f-a)\
**Post date:** [January 10, 2022, 2:43pm UTC](https://numba.discourse.group/t/numba-with-multiprocessing/1118/2 "2022-01-10T14:43:47Z")

</div>

hi @doliolarzz  
are you sure numba is a factor in this? Have you tried to run the exact same code without the `njit` decorator?  
The reason I ask is that `multiprocessing` adds some overhead, so any simple function (njit or normal python) will be slower when run in parallel. Only when running something complex enough will you see an advantage.

Luk
