# Freeing up the threads for multi-threading

**URL:** <https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 11, 2022, 5:39am UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097 "2022-11-11T05:39:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phuntsho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phuntsho/32/46546_2.png) [@Phuntsho](https://discourse.julialang.org/u/Phuntsho)\
**Post date:** [November 11, 2022, 5:39am UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/1 "2022-11-11T05:39:32Z")

</div>

I use IJulia for interactive programming. I usually start with

```julia
julia> ENV["JULIA_NUM_THREADS"]=60
julia> using IJulia
julia> notebook()

```

From there I get a Jupyter environment where I can run programs like those given here [Parallel loops · FLoops](https://juliafolds.github.io/FLoops.jl/dev/tutorials/parallel/#tutorials-parallel). The program runs well as I can confirm from the system monitor /task manager. However, the threads remain engaged even when the programs are done executing. Is there any way to free up the threads when execution is done? something like `delete (gcp('nocreate'))` as in Matlab? Thank you for your help

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 11, 2022, 11:34am UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/2 "2022-11-11T11:34:21Z")

</div>

What you mean by the threads remaining engaged? Having the threads available to the Julia process impairs you from doing anything else?

---

<div class="post-metadata">

**Author:** ![Phuntsho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phuntsho/32/46546_2.png) [@Phuntsho](https://discourse.julialang.org/u/Phuntsho)\
**Post date:** [November 11, 2022, 1:40pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/3 "2022-11-11T13:40:24Z")

</div>

I appreciate your interest in solving my issue. Even if the program is executed, I see the system running as shown in the picture below. I have to restart the machine to relax the cores I need to use for other computations.

 ![eg_CPU](https://global.discourse-cdn.com/julialang/original/3X/f/9/f9522613ecbe4bf8a3d3115be840d56d2cc3d4d9.jpeg)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 11, 2022, 1:50pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/4 "2022-11-11T13:50:22Z")

</div>

Even if you kill the julia process?

---

<div class="post-metadata">

**Author:** ![Phuntsho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phuntsho/32/46546_2.png) [@Phuntsho](https://discourse.julialang.org/u/Phuntsho)\
**Post date:** [November 11, 2022, 1:57pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/5 "2022-11-11T13:57:29Z")

</div>

Even if I killed all of the app processes including Julia.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 11, 2022, 2:45pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/6 "2022-11-11T14:45:52Z")

</div>

That is very strange. Are you sure the problem is related to Julia? Is it possible for you to provide some information about the actual code you are running?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 11, 2022, 3:01pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/8 "2022-11-11T15:01:08Z")

</div>

run `top` to see if it’s Julia using the CPUs?

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [November 11, 2022, 4:20pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/9 "2022-11-11T16:20:44Z")

</div>

This is definitely not normal behavior. What does `top` say as Jling suggested?

---

<div class="post-metadata">

**Author:** ![Phuntsho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phuntsho/32/46546_2.png) [@Phuntsho](https://discourse.julialang.org/u/Phuntsho)\
**Post date:** [November 11, 2022, 9:49pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/10 "2022-11-11T21:49:57Z")

</div>

I am very certain that it is Julia. Before running the Julia CPU usage profiles are very low and some of them are never used since I have 64 of them. After I multi-thread and execute the program, most(all) of CPUs get engaged but won’t get relaxed when done. I am running different metaheuristics algorithms (such as GA, DE, PSO etc) for some combinatorial optimization problems. The actual code is a bit long and hasn’t been uploaded to any internet platforms yet, my sincere apologies. Thanking you.

---

<div class="post-metadata">

**Author:** ![Phuntsho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phuntsho/32/46546_2.png) [@Phuntsho](https://discourse.julialang.org/u/Phuntsho)\
**Post date:** [November 11, 2022, 9:53pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/11 "2022-11-11T21:53:06Z")

</div>

Thank you for your interest in solving this issue. Please help me more with this `top`. How and where do I accomplish this? Do I run this on `terminal`?

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [November 11, 2022, 10:26pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/12 "2022-11-11T22:26:36Z")

</div>

> [@Phuntsho](#):
>
> Even if I killed all of the app processes including Julia.

> [@Phuntsho](#):
>
> I am very certain that it is Julia.

These are incompatible. If julia is killed, it can not be what is taking up your threads. So either you aren’t killing it, or something else is taking up your CPU.

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [November 11, 2022, 11:11pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/13 "2022-11-11T23:11:44Z")

</div>

`top` is a tool which is on most linux systems which lets you see which processes are using the most resources like CPU, RAM etc. There’s also `htop` which is the same information, presented a bit nicer but you usually have to install it.

Yes, you run it from the terminal and `Ctrl+C` to stop.

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [November 11, 2022, 11:14pm UTC](https://discourse.julialang.org/t/freeing-up-the-threads-for-multi-threading/90097/14 "2022-11-11T23:14:51Z")

</div>

Are you only using multithreading in your code? This should be lightweight and you shouldn’t have to kill anything to clean it up.

Are you using multiprocessing at all? Like with `addprocs` (`Distributed.jl`), or do any packages use multiple processes?
