# How to engage all the cores of a CPU?

**URL:** <https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827>\
**Category:** General Usage\
**Created:** [February 6, 2024, 6:04pm UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827 "2024-02-06T18:04:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![soldin](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@soldin](https://discourse.julialang.org/u/soldin)\
**Post date:** [February 6, 2024, 6:04pm UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/1 "2024-02-06T18:04:42Z")

</div>

My cpu has 16 cores, but htops shows I’m using only one. Plz lemme know how can I put all of them to use.

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [February 6, 2024, 6:14pm UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/2 "2024-02-06T18:14:23Z")

</div>

Other than some linear algebra methods, you don’t get parallelism by default. Check these out for how to use threading in Julia:

[https://docs.julialang.org/en/v1/manual/multi-threading/](https://docs.julialang.org/en/v1/manual/multi-threading/)

[https://docs.julialang.org/en/v1/base/multi-threading/](https://docs.julialang.org/en/v1/base/multi-threading/)

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [February 6, 2024, 6:24pm UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/3 "2024-02-06T18:24:28Z")

</div>

What type of operations are you performing? Depending on the workload, you might want to try the recently-released [OhMyThreads.jl](https://github.com/JuliaFolds2/OhMyThreads.jl), which is intended to provide a simple multithreading interface while avoiding some common performance/correctness pitfalls.

---

<div class="post-metadata">

**Author:** ![soldin](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@soldin](https://discourse.julialang.org/u/soldin)\
**Post date:** [February 7, 2024, 5:20am UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/4 "2024-02-07T05:20:10Z")

</div>

Thank you. I thought getting all the cores to use is called multiprocessing. I didn’t know it was actually multi-threading.

---

<div class="post-metadata">

**Author:** ![soldin](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@soldin](https://discourse.julialang.org/u/soldin)\
**Post date:** [February 7, 2024, 5:21am UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/5 "2024-02-07T05:21:29Z")

</div>

Thank you.I didn’t know it was actually multi-threading. I thought putting all the cores to use is called multiprocessing.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 7, 2024, 6:38am UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/6 "2024-02-07T06:38:35Z")

</div>

Multithreading and multiprocessing are two forms of computational parallelism that could be used to occupy your cores.

Multithreading involves mutiple parallel execution units called “threads” which share a common memory space and resources within a single process. In Julia, this is mainly handled through the `Base.Threads` module though packages with alternatives exist.

Multiprocessing involves parallel execution units called “processes” which each have their own memory space and resources. In Julia, this mainly handled through the `Distributed` standard library package though other packages with alternatives exist.

Multithreading can be more efficient than the multiprocessing model by taking advantage of shared resources. However, multiprocessing can be simpler due to a clear separation of resources. That said these distinctions are not so simple since there are ways to separate resources between threads and share resources between processes.

Julia uses a multithreading model based on virtual threads called `Task`s. These virtual threads can be dynamically scheduled on actual threads to achieve parallelism. The potential advantage of virtual threads is that they can be created inexpensively compard to real threads.

To achieve parallelism to occupy all of your cores, you the programmer must ideally find opportunities when computational tasks can run independently of each other. In Julia, a basic parallel form looks like the following.

```julia
Threads.@threads for i in 1:16
    independent_task(i)
end

```

In practice, purely independent tasks are rare and some coordination mechanisms are required.

To simplify parallelism, some packages provide parallel versions of common tasks such as summation. For example, [`Folds.sum`](https://github.com/JuliaFolds2/Folds.jl) provides mechanisms to parallelize summation using either threads or processes.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 2, 2026, 1:26am UTC](https://discourse.julialang.org/t/how-to-engage-all-the-cores-of-a-cpu/109827/7 "2026-09-02T01:26:14Z")

</div>

2 posts were split to a new topic: [How are CPU/core resources utilized with multiple multithreaded processes?](https://discourse.julialang.org/t/how-are-cpu-core-resources-utilized-with-multiple-multithreaded-processes/139151)
