Numpy matrix multiplications with multiprocessing suddenly slow down as dimension increase
This is for self-reference.
Here, I found a solution.
My numpy
uses MKL as backend, it may be the problem that MKL multithreading collides multiprocessing
.
If I run the code:
import osos.environ['MKL_NUM_THREADS'] = '1'
before importing numpy
, then it solved.
I just found an explanation here: https://github.com/numpy/numpy/issues/10145.Looks like the CPU caching gets messed up when you have conflicting MKL matrix multiplications going at the same time.