How to install and import openmp to use it through numba?

Viewed 282

I am building a program using numba in python and I need to use openmp as a numba threading layer. I am struggling to get it up and running.

I have visited the following sites:

  1. http://numba.pydata.org/numba-doc/latest/user/installing.html#installing-from-source
  2. https://numba.readthedocs.io/en/stable/user/threading-layer.html
  3. https://tigress-web.princeton.edu/~jdh4/PyOMPintro.pdf

I have pip installed 'intel-openmp'. However, the following code causes import errors:

import importlib  
openmp = importlib.import_module("intel-openmp")

obtaining:

 ModuleNotFoundError: No module named 'intel-openmp'

'intel-openmp' appears as a package when I run conda list . What am I missing here?

Additionally, if I try anything like:

from numba import threading_layer
from numba import config, njit, threading_layer


config.THREADING_LAYER = 'omp'

causes:

ImportError: cannot import name 'threading_layer'

Could anyone please help? I am relatively new to Python and Numba so there might be key concepts I am missing.

This is my first post ever, so apologies in case some requirements are not met.

Thank you

1 Answers

This seems to be working fine for me:

$ pip install numba
Collecting numba
  Downloading numba-0.54.1-cp39-cp39-macosx_10_14_x86_64.whl (2.3 MB)
     |████████████████████████████████| 2.3 MB 2.6 MB/s
Collecting numpy<1.21,>=1.17
  Downloading numpy-1.20.3-cp39-cp39-macosx_10_9_x86_64.whl (16.1 MB)
     |████████████████████████████████| 16.1 MB 6.7 MB/s
Requirement already satisfied: setuptools in ./sqlapi_test/lib/python3.9/site-packages (from numba) (59.0.1)
Collecting llvmlite<0.38,>=0.37.0rc1
  Downloading llvmlite-0.37.0-cp39-cp39-macosx_10_9_x86_64.whl (19.1 MB)
     |████████████████████████████████| 19.1 MB 11.0 MB/s
Installing collected packages: numpy, llvmlite, numba
Successfully installed llvmlite-0.37.0 numba-0.54.1 numpy-1.20.3

The importing threading_layer:

$ python
Python 3.9.9 (main, Nov 21 2021, 03:23:44)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numba
>>> numba.__version__
'0.54.1'
>>> from numba import threading_layer
>>>

Can you post the steps you used to install numba?

Related