How to limit a Julia notebook to a single core?

I'm running a Julia 1.4 notebook, via Jupyter lab. I need to limit the notebook to a single logical CPU core, on average.

In Python I use the following incantation to restrict Numpy's CPU usage:

from threadpoolctl import threadpool_info,threadpool_limits
with threadpool_limits(limits=1, user_api='blas'):
     code here 

Would anyone happen to know whether its possible to similarly limit Julia's CPU usage from within a notebook?

Topic julia

Category Data Science


If the high CPU usage is due to parallelized linear algebra routines, limiting the CPU usage of the linear algebra backend helps. For Julia 1.4 compiled to use BLAS, the following limits it to a single core:

using LinearAlgebra; 
BLAS.set_num_threads(1);

(Many forum posts recommend blas_set_num_threads(1) for older versions of Julia. This seems to have been depricated)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.