Skip to content

Instantly share code, notes, and snippets.

@dmitryhd
Created September 7, 2017 08:48
Show Gist options
  • Select an option

  • Save dmitryhd/82d4fee3c8d3cf5f859cdae7ff26bd57 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryhd/82d4fee3c8d3cf5f859cdae7ff26bd57 to your computer and use it in GitHub Desktop.
import os
os.environ['MKL_DYNAMIC'] = '0'
os.environ['OPENBLAS_NUM_THREADS'] = '1'
os.environ['OMP_NUM_THREADS'] = '1'
import numpy
import ctypes
# linux only
mkl_rt = ctypes.CDLL('libmkl_rt.so')
mkl_get_max_threads = mkl_rt.mkl_get_max_threads
print(mkl_get_max_threads()) # says 1
def mkl_set_num_threads(cores):
mkl_rt.mkl_set_num_threads(ctypes.byref(ctypes.c_int(cores)))
# https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/559554
def mkl_set_dynamic(v):
mkl_rt.mkl_set_dynamic(ctypes.byref(ctypes.c_int(v)))
mkl_set_num_threads(4)
mkl_set_dynamic(0)
print(mkl_get_max_threads()) # says 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment