Hello, I’m beginner of Julia.
When I draw samples from Multivariate Normal, it uses multicores of my computers.
Especially, when N > 63, they uses 8 cores.
If this things are normal things, and If I don’t wan’t to use multicore, How can I solve this problem?
Example code is as follow.
using Distributions
using BenchmarkTools
n = 64
X=rand(n,n)
A=X’*X
@btime for i = 1 : 100
MvNormal(ones(n), A)
end
My computer is MacBook Pro 14 (M1 Pro)
I found a solution.
“BLAS.set_num_threads(1)”
type this sentence before sampling MvNormal.
Thank you.
1 Like
nilshg
September 3, 2024, 3:32pm
3
How do you know? I don’t observe any multi-core utilisation when running your code.
Also note that you are not drawing any samples from the distributions here, you are just instantiating the distribution objects.
d = MvNormal(ones(n), A)
creates a distribution, rand(d)
samples from it.
Oh that’s right, That code is not a sampling, but creates a distributions.
If I could upload a figure, I could explain my situation much more clearly, But I couldn’t find upload button.
But anyway, “BLAS.set_num_threads(1)” this code force my laptop only use single core.
Thank you !
nilshg
September 3, 2024, 3:46pm
6
Ah, looking at @less MvNormal(ones(n), A)
I see it is doing MvNormal(ones(n), PDMat(A))
and looking at @less Distributions.PDMats.PDMat(A)
I see that that is doing cholesky(A)
so that’s probably where the BLAS call in the constructor comes from.
1 Like