How to limit the CPU-cores used by scipy.integrate.quad

Viewed 33

I've got a program that uses scipy.integrate.quad(). When I use it I noticed that it uses all the cores on my PC, which I don't want as I want to run this script in parallel on multiple cores. Is there any way to restrict the function?

I have already tried limiting it with this command before import scipy and numpy:

import os
import sys

os.environ.update(
    OMP_NUM_THREADS='1',
    OPENBLAS_NUM_THREADS='1',
    NUMEXPR_NUM_THREADS='1',
    MKL_NUM_THREADS='1',
)

Unfortunately that didn't help either. Are there other things I could try? My scipy uses openblas in case that is relevant too.

2 Answers

What cores are used when by your computer is handled by the lower layers of your os. There is no way to modify the ammount of cores used for one process. If you want to run the programm multiple times in parallel, you should use multithreading and let the computer handle the workload by himself

Quad by itself should not use parallelism. What is your function you're integrating? (If it has linear algebra, it might be openblas that uses all cores by default etc)

Related