flatironinstitute / sparse_dot

Python wrapper for Intel Math Kernel Library (MKL) matrix multiplication
MIT License
73 stars 10 forks source link

how to set multithreads #12

Closed leebo-2020 closed 2 years ago

leebo-2020 commented 3 years ago

Dear developers,

i used conda install sparse_dot_mkl, when i do sparse matrix multiplication by dot_product_mkl, i found that this task is not multithreads but one-threads. So, how to achieve multithreads? thanks.

the environment of python3 Python 3.8.3 (default, Jul 2 2020, 16:21:59) [GCC 7.3.0] :: Anaconda, Inc. on linux

!/usr/bin/python3

import time import numpy as np import sparse_dot_mkl

m = 30000 a = np.random.random((m, m)) b = np.random.random((m, m))

t3 = time.time() tmp2 = sparse_dot_mkl.dot_product_mkl(a, b) t4 = time.time()

i runing this test by python3 test.py

asistradition commented 3 years ago

I would suggest trying to explicitly set the thread usage via env variable (e.g. export MKL_NUM_THREADS=10). You need to set this env prior to importing sparse_dot_mkl in python - it's read when imported, not at runtime.

You should note that by default, MKL will scale down to the number of physical cores you have, which may be fewer than your OS reports due to hyperthreading.

leebo-2020 commented 3 years ago

I would suggest trying to explicitly set the thread usage via env variable (e.g. export MKL_NUM_THREADS=10). You need to set this env prior to importing sparse_dot_mkl in python - it's read when imported, not at runtime.

You should note that by default, MKL will scale down to the number of physical cores you have, which may be fewer than your OS reports due to hyperthreading.

my env variable as follows: export OMP_NUM_THREADS=24 export MKL_NUM_THREADS=24

when i re-test, i still found that task executed by one-threads, so, i don't know what happen.

asistradition commented 3 years ago

I would also try using the Intel channel mkl instead of the main channel mkl (e.g. conda install -c intel mkl).

I can't replicate the problem you're having so it's a bit hard to troubleshoot.