# Multi-Threading Bug on Windows: setting Threads.nthreads() = 6 for using BlackBoxOptim

**URL:** <https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922>\
**Category:** New to Julia\
**Tags:** multithreading, optimization, vscode\
**Created:** [May 6, 2020, 11:44pm UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922 "2020-05-06T23:44:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [May 6, 2020, 11:44pm UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/1 "2020-05-06T23:44:32Z")

</div>

Hallo,

I am trying to take advantage of _Multithreaded and Parallel Function Evaluation_ of **BlackBoxOptim.jl** which requires _Threads.nthreads() \> 2_ by using **Julia 1.4.1**

[BlackBoxOptim.jl](https://github.com/robertfeldt/BlackBoxOptim.jl/blob/master/examples/multithreaded_optimization.jl)

Nevertheless on Windows 10 I am not able to set the number of Threads.nthreads() \> 1

Following  
[Multi-Threading (Experimental)](https://docs.julialang.org/en/v1/manual/parallel-computing/#The-@threads-Macro-1)

I type the following commands:

 ![WindowsShell](https://global.discourse-cdn.com/julialang/original/3X/b/8/b89e66aa24b1cee5431aa20701e5f53735d9f8ab.jpeg)

```julia
set JULIA_NUM_THREADS=6

```

It successfully accepts the code.  
But when I type

```julia
julia> Threads.nthreads()
 1

```

I will be ever so grateful if you could inform me what I am doing wrong?

Also in VScode I have the option:

```julia
Julia: Num Threads
Number of threads to use for Julia processes =6

```

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [May 7, 2020, 8:04am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/2 "2020-05-07T08:04:34Z")

</div>

after `set JULIA_NUM_THREADS=6`, start julia in the same command window (by typing `julia`)

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [May 7, 2020, 8:27am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/3 "2020-05-07T08:27:14Z")

</div>

That was really simple thanks

My question is why the option in VScode of **Num Threads** does not work?

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [May 7, 2020, 8:28am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/4 "2020-05-07T08:28:14Z")

</div>

How can I automatically at the start of Julia force `JULIA_NUM_THREADS=6`?

Thanks

---

<div class="post-metadata">

**Author:** ![wolfgang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wolfgang/32/13053_2.png) [@wolfgang](https://discourse.julialang.org/u/wolfgang)\
**Post date:** [May 7, 2020, 9:11am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/5 "2020-05-07T09:11:00Z")

</div>

I am using this in startup.jl

```julia
ENV["JULIA_NUM_THREADS"] = 6

```

but I am not working on windows, so I am not sure whether it will work for you that way.

---

<div class="post-metadata">

**Author:** ![hsm207](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hsm207/32/12066_2.png) [@hsm207](https://discourse.julialang.org/u/hsm207)\
**Post date:** [May 7, 2020, 9:18am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/6 "2020-05-07T09:18:44Z")

</div>

Are you using Julia VS Code extension version 0.15.29?

I’m on Windows and in this version setting the extension’s `julia.NumThreads` setting works.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 7, 2020, 9:45am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/7 "2020-05-07T09:45:38Z")

</div>

> [@wolfgang](#):
>
> I am using this in startup.jl

I don’t think that works because that file is loaded (by virtue of it being a julia file) after julia has started.

---

<div class="post-metadata">

**Author:** ![wolfgang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wolfgang/32/13053_2.png) [@wolfgang](https://discourse.julialang.org/u/wolfgang)\
**Post date:** [May 7, 2020, 10:16am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/8 "2020-05-07T10:16:06Z")

</div>

You are right, thanks for the correction. I copied that from some other thread on discourse and never verified whether it works or not. And yes, it does not work.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 7, 2020, 10:46am UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/9 "2020-05-07T10:46:57Z")

</div>

In the upcoming 1.5 release it is possible to use `julia --threads=6` for example.

---

<div class="post-metadata">

**Author:** ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Post date:** [May 7, 2020, 8:48pm UTC](https://discourse.julialang.org/t/multi-threading-bug-on-windows-setting-threads-nthreads-6-for-using-blackboxoptim/38922/10 "2020-05-07T20:48:34Z")

</div>

Thanks hsm mine `julia.NumThreads` setting does not work. May be it works for Distributed package with addprocs(). Kristoffer solved my problem:

_In the upcoming 1.5 release it is possible to use `julia --threads=6` for example._
