# Only 50% of Cores/Threads available through VS Code

**URL:** https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990
**Category:** VS Code
**Tags:** question
**Created:** [September 29, 2022, 1:33pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990 "2022-09-29T13:33:58Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![TimKnab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timknab/32/22256_2.png) [@TimKnab](https://discourse.julialang.org/u/TimKnab)
#### Post date: [September 29, 2022, 1:33pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/1 "2022-09-29T13:33:58Z")

</div>

I have a 6 Core MacBook Pro running Ventura (OS X 13) and when I launch Julia directly from the command line I have access to all 12 CPU threads for multithreading. When I launch Julia in VS Code, I can only get up to 6 threads… I have attached some screen shots to show the differences. Am I missing something obvious?

 ![SS1](https://global.discourse-cdn.com/julialang/original/3X/5/3/53d69b7a9635d4e2bc756ee85c0a7673e62cd298.png)

 ![Screenshot 2022-09-29 at 9.32.09 AM](https://global.discourse-cdn.com/julialang/original/3X/1/3/132f34124d9b8b8f38441931bcf1beca4b70d3b1.png)

---

<div class="post-metadata">

### Author: ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)
#### Post date: [September 29, 2022, 1:39pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/2 "2022-09-29T13:39:20Z")

</div>

What is your threads value in the VSCode settings?  
Or how do you start each Julia instance?

---

<div class="post-metadata">

### Author: ![TimKnab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timknab/32/22256_2.png) [@TimKnab](https://discourse.julialang.org/u/TimKnab)
#### Post date: [September 29, 2022, 1:42pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/3 "2022-09-29T13:42:38Z")

</div>

I’ve set the number of threads in the Julia extension to 12 and auto as well as used `Julia -t 12` and `julia -t auto`, doesn’t seem to make a difference. I installed the Julia cask using homebrew and from the command line start by just typing `julia`. In VS Code I have tried starting it using the Julia extension as well as opening a standard terminal and again typing `julia`. In the screenshots I posted, I did not specify the number of threads when launching julia.

---

<div class="post-metadata">

### Author: ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)
#### Post date: [September 29, 2022, 1:47pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/4 "2022-09-29T13:47:09Z")

</div>

And have you checked if it is not a VSCode thing? Like checking in plain terminal what the number of cores/threads is available?  
If I’m not mistaken, VSCode has it’s own terminal emulation, maybe that is causing problems and limits what Julia sees?

---

<div class="post-metadata">

### Author: ![TimKnab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timknab/32/22256_2.png) [@TimKnab](https://discourse.julialang.org/u/TimKnab)
#### Post date: [September 29, 2022, 1:47pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/5 "2022-09-29T13:47:55Z")

</div>

Yeah, I just checked that using `sysctl -n hw.ncpu` and `python -c 'import multiprocessing as mp; print(mp.cpu_count())'` in the VS Code terminal, both returned 12. Happy to check using other methods as well, if you have any suggestions

---

<div class="post-metadata">

### Author: ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)
#### Post date: [September 29, 2022, 2:03pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/6 "2022-09-29T14:03:56Z")

</div>

So I grabbed my old Macbook (with 2-core Intel i5, iOS 12.6) and can confirm that in VSCode Julia reports 2 threads, while outside it is 4 (`Sys.CPU_THREADS`).  
However, the threading module (`Threads.nthreads()`)shows 4 threads when I start Julia with the proper parameter.

Maybe there is something off with the Sys module?  
Do you have some code to test how many threads Julia is actually using?

---

<div class="post-metadata">

### Author: ![TimKnab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timknab/32/22256_2.png) [@TimKnab](https://discourse.julialang.org/u/TimKnab)
#### Post date: [September 29, 2022, 2:06pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/7 "2022-09-29T14:06:25Z")

</div>

So I first started investigating because `Threads.nthreads()` was showing the correct number of threads (i.e if I set it to 12 `Threads.nthreads()` returned 12). But when I was actually running the code and inspecting the CPU usage via `htop` I noticed that it never used more than 6… Granted my check was kind of crude, but the `julia` process topped out at ~580% CPU usage and only 6 “cores” ever showed elevated usage in the charts

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [September 29, 2022, 2:07pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/8 "2022-09-29T14:07:07Z")

</div>

Is this happening for all Julia sessions opened within VS Code, or only those in the integrated REPL?

---

<div class="post-metadata">

### Author: ![TimKnab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timknab/32/22256_2.png) [@TimKnab](https://discourse.julialang.org/u/TimKnab)
#### Post date: [September 29, 2022, 2:08pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/9 "2022-09-29T14:08:50Z")

</div>

It seems to be all of them. It doesn’t matter if I launch julia using the julia extension or the terminal within VS Code. I might be misunderstanding your question though…?

---

<div class="post-metadata">

### Author: ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)
#### Post date: [September 29, 2022, 3:04pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/10 "2022-09-29T15:04:53Z")

</div>

I share this exact issue, but with Julia v. 1.7.2 on a much older quadcore MacBook running Monterrey.

---

<div class="post-metadata">

### Author: ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)
#### Post date: [October 14, 2022, 3:38pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/11 "2022-10-14T15:38:08Z")

</div>

Anybody with this problem find a solution? I have tried “ignored settings” from  
[here](https://discourse.julialang.org/t/julia-num-threads-in-vs-code-windows-10-wsl/28794/13) and it can confirm this did not work. I have no idea what to do. Threads.nthreads() is 8, but I use Sys.CPU\_THREADS is 4 and the CPU usage rarely breaks 400%. when I Threads.@threads 😭

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [October 14, 2022, 7:33pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/12 "2022-10-14T19:33:59Z")

</div>

How many cores does your machine have? If it’s 4, then the other 4 reported threads come from hyperthreading/SMT and aren’t going to be adding much. That may explain why you can’t go beyond 400% (not just in Julia, but any program).

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [October 14, 2022, 8:01pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/13 "2022-10-14T20:01:43Z")

</div>

Yeah, this seems like this would generally be the better default.

---

<div class="post-metadata">

### Author: ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)
#### Post date: [October 15, 2022, 9:04am UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/14 "2022-10-15T09:04:13Z")

</div>

When for instance Julia is ||-compiling things in the terminal, it maxes things out and the fans blare and I hit 800%, and Threads.threads in VS code is much easier on the chip and I often don’t break 300%.

Maybe it’s heavy allocs in computations limiting the hyper-threading? I’ll see if I can get a clearer MWE. Sorry for the lazy post.

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [October 16, 2022, 4:32pm UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/15 "2022-10-16T16:32:15Z")

</div>

By “the terminal” I presume you mean a separate REPL and not the one integrated with VS Code? One thing to try is running your code in a non-VS Code REPL and checking the usage there. I’d also recommend posting the output of `versioninfo()` here because it shows your processor model + the number of virtual cores.

---

<div class="post-metadata">

### Author: ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)
#### Post date: [October 17, 2022, 10:56am UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/16 "2022-10-17T10:56:48Z")

</div>

Thanks for the hint. Here’s a little function for testing ||-ism and the central limit theorem

```julia
function test_parallel(n)
  out = zeros(n)
  Threads.@threads for ii in 1:n
    for jj in 1:10^8
      out[ii] += rand()
    end
  end
  return sum(out)
end

```

you can see what happens when I run in my terminal with 8 threads. CPU running hot.

 ![Screenshot 2022-10-17 at 12.44.19](https://global.discourse-cdn.com/julialang/original/3X/2/2/22b592b66d81bc2980d192759e98b1aa18457102.png)

now from vs code

 ![Screenshot 2022-10-17 at 12.53.33](https://global.discourse-cdn.com/julialang/original/3X/4/c/4cf0355f2ddd3b6708bab04d37bae49f909b22bc.png)

Sure its only 5% slower for this case, I guess the hyperthreading really is overrated Intel marketing, but you are right the `versioninfo` is different: 4 virtual cores from VScode. That’s quite mysterious to me. I hope this helps.

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [October 17, 2022, 11:18am UTC](https://discourse.julialang.org/t/only-50-of-cores-threads-available-through-vs-code/87990/17 "2022-10-17T11:18:39Z")

</div>

> [@ToucheSir](#):
>
> If it’s 4, then the other 4 reported threads come from hyperthreading/SMT and aren’t going to be adding much.

If it’s actually better to use half the threads (likely), then shouldn’t that be the case outside of VS Code with `julia -t auto` too (at least you could override with, for you, `-t 8`)?

I don’t really mind too much what the default is, if it’s the better default (for most cases). Still could it in some cases be better to have access to all threads? Might it be best for `-t auto` to allocate as many threads as virtual cores, then still limit you to half of them by default (and you could optionally in code ask for the dormat hyperthreads to be used too?).

I’m just thinking if you’re limited to half by default, then currently there’s no easy way to add more at runtime. On master there’s a new option to add “foreign threads” (from C), so seemingly a workaround…

> [@cdawg](#):
>
> When for instance Julia is ||-compiling things in the terminal, it maxes things out and the fans blare and I hit 800%

If you mean (full) 8 threads, then compiling forks n single-threaded processes, in effect that (or in general Distributed) is an exception, but unclear to me it should use as many, or also be limited to the non-hyperthreads.
