# Is this normal things about MvNormal?

**URL:** <https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999>\
**Category:** General Usage\
**Tags:** question, distributions\
**Created:** [September 3, 2024, 3:23pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999 "2024-09-03T15:23:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JULIAAAAA](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@JULIAAAAA](https://discourse.julialang.org/u/JULIAAAAA)\
**Post date:** [September 3, 2024, 3:23pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/1 "2024-09-03T15:23:36Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![JULIAAAAA](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@JULIAAAAA](https://discourse.julialang.org/u/JULIAAAAA)\
**Post date:** [September 3, 2024, 3:31pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/2 "2024-09-03T15:31:51Z")

</div>

I found a solution.

“BLAS.set\_num\_threads(1)”

type this sentence before sampling MvNormal.

Thank you.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 3, 2024, 3:32pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/3 "2024-09-03T15:32:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JULIAAAAA](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@JULIAAAAA](https://discourse.julialang.org/u/JULIAAAAA)\
**Post date:** [September 3, 2024, 3:41pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/5 "2024-09-03T15:41:36Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 3, 2024, 3:46pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/6 "2024-09-03T15:46:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JULIAAAAA](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@JULIAAAAA](https://discourse.julialang.org/u/JULIAAAAA)\
**Post date:** [September 3, 2024, 4:01pm UTC](https://discourse.julialang.org/t/is-this-normal-things-about-mvnormal/118999/7 "2024-09-03T16:01:00Z")

</div>

Thank you!
