question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How best to parallelize numba.stencil operations

See original GitHub issue

In https://numba.pydata.org/numba-doc/dev/user/stencil.html#numba-stencil it says the following:

Thus, the stencil decorator allows clearer, more concise code and in conjunction with the parallel jit option enables higher performance through parallelization of the stencil execution.

However, my naive attempt to use the parallel=True keyword with numba.stencil has failed:

In [1]: import numba

In [2]: @numba.stencil(parallel=True)
   ...: def f(x):
   ...:     return (x[-1, -1] + x[-1, 0] + x[-1, 1] + x[0, -1] + x[0, 0] + x[0, 1] + x[1, -1] + x[1, 0] + x[1, 1]) 
   ...: / 9
   ...: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-9fe53b83f8a0> in <module>()
----> 1 @numba.stencil(parallel=True)
      2 def f(x):
      3     return (x[-1, -1] + x[-1, 0] + x[-1, 1] + x[0, -1] + x[0, 0] + x[0, 1] + x[1, -1] + x[1, 0] + x[1, 1]) / 9

~/Software/anaconda/lib/python3.6/site-packages/numba/stencil.py in stencil(func_or_mode, **options)
    722     for option in options:
    723         if option not in ["cval", "standard_indexing", "neighborhood"]:
--> 724             raise ValueError("Unknown stencil option " + option)
    725 
    726     wrapper = _stencil(mode, options)

ValueError: Unknown stencil option parallel

What is the right way to parallelize stencil operations? If I’ve missed documentation on this I apologize.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
ehsantncommented, May 21, 2018

numba.stencil decorator is for creating stencil kernels. It doesn’t even jit the kernel; it remains as regular python. The njit functions that use the kernels can have the parallel=True annotation.

Looks like the documentation should be more clear on this.

0reactions
ehsantncommented, May 21, 2018

Makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notes on stencils — Numba 0.50.1 documentation
As mentioned above, Numba supports the calling of stencils from inside or outside a @jit compiled function, with or without the parallel=True option....
Read more >
Automatic parallelization with @jit - Numba documentation
Instead, with auto-parallelization, Numba attempts to identify such operations in a user program, and fuse adjacent ones together, to form one or more...
Read more >
Parallel Python with Numba and ParallelAccelerator - Anaconda
On the other hand, threads can be very lightweight and operate on shared ... there were not very good ways to describe stencil...
Read more >
Composing Dask Array with Numba Stencils
Numba's stencil decorator to craft localized compute kernels · Numba's Just-In-Time (JIT) compiler for array computing in Python · Dask Array for ...
Read more >
Basics [Numba] | Tips & Tricks - Diego Inácio
Jit has a flag which enables the automatic parallelization, and in addition, Numba has implemented the ability to run loops in parallel using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found