# \#multithreading

**URL:** https://discourse.julialang.org/tag/multithreading/100.md?match_all_tags=true&page=2&tags%5B%5D=multithreading

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 3

---

## [Thread.jl yields wrong results in parallelisation compared to serial for-loop](https://discourse.julialang.org/t/thread-jl-yields-wrong-results-in-parallelisation-compared-to-serial-for-loop/127239)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 7\
**Last updated:** [March 21, 2025, 8:09pm UTC](https://discourse.julialang.org/t/thread-jl-yields-wrong-results-in-parallelisation-compared-to-serial-for-loop/127239 "2025-03-21T20:09:52Z")

</div>

Hi Guys, I am using @thread for my model parallelisation. However, it yields different results compared to serial for-loop. Here is my script function batch\_cost\_function(p) num\_params = size(p, 2) # Number of para…

---

## [How to select elements of a three-dimensional array fast](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 4\
**Last updated:** [March 20, 2025, 10:28pm UTC](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185 "2025-03-20T22:28:50Z")

</div>

I have large three-dimensional arrays A that have different values, but from which I always wish to select the same set of entries. So A is a different matrix each time, but it has the same size and I need to collect th…

---

## [Floops multithreading HasBoxedVariableError](https://discourse.julialang.org/t/floops-multithreading-hasboxedvariableerror/127139)

<div class="topic-metadata">

**Author:** [@s\_amap](https://discourse.julialang.org/u/s_amap)\
**Replies:** 7\
**Last updated:** [March 19, 2025, 3:54pm UTC](https://discourse.julialang.org/t/floops-multithreading-hasboxedvariableerror/127139 "2025-03-19T15:54:34Z")

</div>

I’ve been trying to adjust a parallel loop after some changes, and I need some clarification to make sure I’m not at risk of false sharing. The loop conceptually works like this: object # holds a state, which is a tupl…

---

## [Conditional Multithreading](https://discourse.julialang.org/t/conditional-multithreading/32421)

<div class="topic-metadata">

**Author:** [@bjack205](https://discourse.julialang.org/u/bjack205)\
**Replies:** 12\
**Last updated:** [March 12, 2025, 11:50am UTC](https://discourse.julialang.org/t/conditional-multithreading/32421 "2025-03-12T11:50:04Z")

</div>

Is there a way to enable/disable calls to Threads.@threads? I’m developing an optimization solver, and when the problem is sufficiently small, using multi-threading hurts performance, and incurs allocations (my code doe…

---

## [Speeding up array multiplication](https://discourse.julialang.org/t/speeding-up-array-multiplication/126607)

<div class="topic-metadata">

**Author:** [@ttx002000](https://discourse.julialang.org/u/ttx002000)\
**Replies:** 7\
**Last updated:** [March 9, 2025, 10:20am UTC](https://discourse.julialang.org/t/speeding-up-array-multiplication/126607 "2025-03-09T10:20:29Z")

</div>

Dear Community members: I need advice for speeding up the following operations. I have three arrays, Fockmatrix, fcmatrix, densitymatrix densitymatrix and fcmatrix are already given, and they are passed as arguments …

---

## [ExaModels CPU backend acceleration](https://discourse.julialang.org/t/examodels-cpu-backend-acceleration/126153)

<div class="topic-metadata">

**Author:** [@KSepetanc](https://discourse.julialang.org/u/KSepetanc)\
**Replies:** 4\
**Last updated:** [March 2, 2025, 11:26pm UTC](https://discourse.julialang.org/t/examodels-cpu-backend-acceleration/126153 "2025-03-02T23:26:07Z")

</div>

I am trying to setup CPU() backend acceleration as described in ExaModels documentation but it is not working. The optimization runs but on single thread (System monitor detects no multiple threads usage) and with the sa…

---

## [Multithreading doesn't improve the performance](https://discourse.julialang.org/t/multithreading-doesnt-improve-the-performance/126020)

<div class="topic-metadata">

**Author:** [@wq-123](https://discourse.julialang.org/u/wq-123)\
**Replies:** 6\
**Last updated:** [February 18, 2025, 10:27am UTC](https://discourse.julialang.org/t/multithreading-doesnt-improve-the-performance/126020 "2025-02-18T10:27:48Z")

</div>

Hello, I’m trying to calculate my for-loop with multithreading. But there’s no increase in computing speed. Here’s the struct of my code. B = \[\[\[zeros(ComplexF64,1,6) for a in 1:3\] for \_ in 1:Nw\] for z in 1:Threads.nthr…

---

## [How to spawn persistent threads and reuse them?](https://discourse.julialang.org/t/how-to-spawn-persistent-threads-and-reuse-them/126002)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 16\
**Last updated:** [February 17, 2025, 9:50pm UTC](https://discourse.julialang.org/t/how-to-spawn-persistent-threads-and-reuse-them/126002 "2025-02-17T21:50:25Z")

</div>

Let nt=nthreads(). I have a loop for k=1:n compute!(k, ...) end that I wish to parallelize. I did so as for k0=1:nt:n k1 = min(k0+nt-1,n); @threads for k=k0:k1 compute!(k, ...) end compress\_results!(k0…

---

## [Sharp edge with \`Threads.threadid()\` and task migration](https://discourse.julialang.org/t/sharp-edge-with-threads-threadid-and-task-migration/124550)

<div class="topic-metadata">

**Author:** [@GeorgeGkountouras](https://discourse.julialang.org/u/GeorgeGkountouras)\
**Replies:** 64\
**Last updated:** [February 12, 2025, 6:55am UTC](https://discourse.julialang.org/t/sharp-edge-with-threads-threadid-and-task-migration/124550 "2025-02-12T06:55:37Z")

</div>

Your code might get rescheduled on a different thread between the check and the access.

---

## [\`task\_local\_storage\`, why and where?](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670)

<div class="topic-metadata">

**Author:** [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Replies:** 3\
**Last updated:** [February 8, 2025, 9:58am UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670 "2025-02-08T09:58:51Z")

</div>

I recently discovered that there exists such function as task\_local\_storage for task. It’s exported. Can anyone give me an example of practical application of such functionality?

---

## [How to quantitatively analyze the impact of memory bandwidth on multithreading](https://discourse.julialang.org/t/how-to-quantitatively-analyze-the-impact-of-memory-bandwidth-on-multithreading/125059)

<div class="topic-metadata">

**Author:** [@quantumdreamer](https://discourse.julialang.org/u/quantumdreamer)\
**Replies:** 10\
**Last updated:** [February 6, 2025, 3:20am UTC](https://discourse.julialang.org/t/how-to-quantitatively-analyze-the-impact-of-memory-bandwidth-on-multithreading/125059 "2025-02-06T03:20:15Z")

</div>

When I increased the number of threads in my Julia project, I noticed that the performance of the project did not scale linearly with the number of threads. Currently, the multi-threaded performance is twice that of the …

---

## [FFTW scales pretty well (some @btime benchmarks)](https://discourse.julialang.org/t/fftw-scales-pretty-well-some-btime-benchmarks/28341)

<div class="topic-metadata">

**Author:** [@xzackli](https://discourse.julialang.org/u/xzackli)\
**Replies:** 1\
**Last updated:** [February 4, 2025, 2:30pm UTC](https://discourse.julialang.org/t/fftw-scales-pretty-well-some-btime-benchmarks/28341 "2025-02-04T14:30:43Z")

</div>

I was misled into thinking that FFTW scales poorly in parallel after reading this discourse thread, so I wanted to post some numbers for someone trying to do fast FFTs in the future. My use case requires repeatedly perfo…

---

## [Multi-thread speed in very large vectors](https://discourse.julialang.org/t/multi-thread-speed-in-very-large-vectors/125342)

<div class="topic-metadata">

**Author:** [@pjssilva](https://discourse.julialang.org/u/pjssilva)\
**Replies:** 11\
**Last updated:** [February 3, 2025, 3:02pm UTC](https://discourse.julialang.org/t/multi-thread-speed-in-very-large-vectors/125342 "2025-02-03T15:02:26Z")

</div>

Hi, I am trying to get my toes wet on some multi-threading code using the great OhMyThreads package. But there is a behavior that I don’t understand. I can exemplify it using the sum function. The most natural implementa…

---

## [Weird behaviour of GC with multithreaded array-access](https://discourse.julialang.org/t/weird-behaviour-of-gc-with-multithreaded-array-access/125433)

<div class="topic-metadata">

**Author:** [@wilhelm](https://discourse.julialang.org/u/wilhelm)\
**Replies:** 2\
**Last updated:** [January 31, 2025, 6:57pm UTC](https://discourse.julialang.org/t/weird-behaviour-of-gc-with-multithreaded-array-access/125433 "2025-01-31T18:57:31Z")

</div>

Hi! I recently worked with some big arrays and used multithreading to access and fill these arrays, but after the calculation it seemed like the GC did not manage to clear the ram used by the “non-main” thread. MWE: f…

---

## [Bug in sleep() function - main thread work affecting sleep duration on running tasks](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 47\
**Last updated:** [January 23, 2025, 8:36pm UTC](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911 "2025-01-23T20:36:44Z")

</div>

What triggered the present experiment was my failure to find a reasonable solution for the issue raised by this topic. It turned out that the issue was unrelated to the HTTP.jl package and went deeper. Now, the experim…

---

## [Solver and AD advice for nonlinear LS problem](https://discourse.julialang.org/t/solver-and-ad-advice-for-nonlinear-ls-problem/125014)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 5\
**Last updated:** [January 21, 2025, 5:26pm UTC](https://discourse.julialang.org/t/solver-and-ad-advice-for-nonlinear-ls-problem/125014 "2025-01-21T17:26:51Z")

</div>

(This is a vague open-ended question for which I cannot provide an MWE.) I have a nonlinear least squares problem \\min\_x \\| f(x) \\|\_2^2 where x \\in \\mathbb{R}^N, N \\approx 20...40, and f(x) has about 100–200 elements…

---

## [Poor parallel speedup](https://discourse.julialang.org/t/poor-parallel-speedup/124782)

<div class="topic-metadata">

**Author:** [@billmclean](https://discourse.julialang.org/u/billmclean)\
**Replies:** 2\
**Last updated:** [January 17, 2025, 3:14am UTC](https://discourse.julialang.org/t/poor-parallel-speedup/124782 "2025-01-17T03:14:49Z")

</div>

I want to understand why some code exhibits fairly poor parallel speedup. In simplified form, I am just computing a discrete Laplacian over a 3D grid: function discrete\_laplacian!(AU::Array{T,3}, U::OffsetArray{T,3}) w…

---

## [Broadcasting performance](https://discourse.julialang.org/t/broadcasting-performance/123392)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 13\
**Last updated:** [January 6, 2025, 9:39am UTC](https://discourse.julialang.org/t/broadcasting-performance/123392 "2025-01-06T09:39:27Z")

</div>

f(x) = sin(x)cos(x)tan(x)exp(x)sin(x)cos(x)tan(x)exp(x) X = randn(100\_000\_000) @time f.(X) # 4 seconds @time @threads for x in X; f(x) end # .8 seconds 16 threads @time @turbo f.(X) …

---

## [Improving Efficiency of Embarassingly Parallel Problem Using \`Threads\`](https://discourse.julialang.org/t/improving-efficiency-of-embarassingly-parallel-problem-using-threads/123897)

<div class="topic-metadata">

**Author:** [@freestatelabs](https://discourse.julialang.org/u/freestatelabs)\
**Replies:** 7\
**Last updated:** [December 17, 2024, 1:32pm UTC](https://discourse.julialang.org/t/improving-efficiency-of-embarassingly-parallel-problem-using-threads/123897 "2024-12-17T13:32:31Z")

</div>

I recently upgraded my workstation and have been benchmarking a code I had written that I consider to be “embarrassingly parallel”, implemented via the Threads module. However, I found that I was getting far greater loss…

---

## [Embedding Julia and multiple foreign threads](https://discourse.julialang.org/t/embedding-julia-and-multiple-foreign-threads/123394)

<div class="topic-metadata">

**Author:** [@peremato](https://discourse.julialang.org/u/peremato)\
**Replies:** 3\
**Last updated:** [December 4, 2024, 1:51pm UTC](https://discourse.julialang.org/t/embedding-julia-and-multiple-foreign-threads/123394 "2024-12-04T13:51:14Z")

</div>

The embedding documentation says clearly that you can only use the functions jl\_...() from a single foreign thread in which you have called jl\_init(). The question is, has anything changed with respect this restriction i…

---

## [Does stdlib network sockets use only first thread?](https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027)

<div class="topic-metadata">

**Author:** [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Replies:** 6\
**Last updated:** [December 4, 2024, 10:16am UTC](https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027 "2024-12-04T10:16:17Z")

</div>

I am writing a multi-threaded applications with a GUI (CImGui.jl) and a network sockets (Base.Sockets) to handle low-latency data stream over local network via UDP. I have a few independent threads to handle data proces…

---

## [Why can Julia spawn new processes but not new threads?](https://discourse.julialang.org/t/why-can-julia-spawn-new-processes-but-not-new-threads/123267)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 1\
**Last updated:** [November 30, 2024, 5:10am UTC](https://discourse.julialang.org/t/why-can-julia-spawn-new-processes-but-not-new-threads/123267 "2024-11-30T05:10:57Z")

</div>

With Distributed.jl, you can create new worker processes easily with addprocs (each of which can have multiple threads), but once a Julia process starts you can’t add more threads to that process; why?

---

## [IntervalOptimisation.jl and threads gives lock conflicts](https://discourse.julialang.org/t/intervaloptimisation-jl-and-threads-gives-lock-conflicts/122588)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 10\
**Last updated:** [November 29, 2024, 12:56am UTC](https://discourse.julialang.org/t/intervaloptimisation-jl-and-threads-gives-lock-conflicts/122588 "2024-11-29T00:56:02Z")

</div>

Hi, in a project I’m working on, I need to run many, many small optimizations. I like to do this by using Threads.@threads, which typically cuts down my runtime by a factor 2-4 for the problems I’m looking at. However, w…

---

## [Please help me to understand the \`OhMyThreads.jl\` parallel mutation example](https://discourse.julialang.org/t/please-help-me-to-understand-the-ohmythreads-jl-parallel-mutation-example/123114)

<div class="topic-metadata">

**Author:** [@scheidan1](https://discourse.julialang.org/u/scheidan1)\
**Replies:** 8\
**Last updated:** [November 27, 2024, 11:17am UTC](https://discourse.julialang.org/t/please-help-me-to-understand-the-ohmythreads-jl-parallel-mutation-example/123114 "2024-11-27T11:17:55Z")

</div>

Hi all, The documentation of OhMyThreads.jl contains an example of an apparently very simple parallelization: # Base.Threads using Base.Threads: @threads data = rand(10) @threads for i in eachindex(data) data\[i\] =…

---

## [Is it possible to enforce scheduler to instantly yield to specific task?](https://discourse.julialang.org/t/is-it-possible-to-enforce-scheduler-to-instantly-yield-to-specific-task/123133)

<div class="topic-metadata">

**Author:** [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Replies:** 0\
**Last updated:** [November 27, 2024, 12:13am UTC](https://discourse.julialang.org/t/is-it-possible-to-enforce-scheduler-to-instantly-yield-to-specific-task/123133 "2024-11-27T00:13:27Z")

</div>

I writing a program with the aim of real-time and low-latency data processing that have multiple tasks running on a single thread. For two of those tasks, let’s call them A and B, I need a very tight synchronization on s…

---

## [Crash when tuning SVC with multithreading in MLJ.jl](https://discourse.julialang.org/t/crash-when-tuning-svc-with-multithreading-in-mlj-jl/122908)

<div class="topic-metadata">

**Author:** [@Yuan-Ru-Lin](https://discourse.julialang.org/u/Yuan-Ru-Lin)\
**Replies:** 4\
**Last updated:** [November 21, 2024, 10:11pm UTC](https://discourse.julialang.org/t/crash-when-tuning-svc-with-multithreading-in-mlj-jl/122908 "2024-11-21T22:11:41Z")

</div>

I have been trying to tune a set of hyper-parameters of a SVC. The SVC is from LIBSVM.jl. It works when I use only one thread, but crashes indeterministically with multiple threads. Not only did it may or may not crash,…

---

## [Reducing Channel Lock Contention with Batches](https://discourse.julialang.org/t/reducing-channel-lock-contention-with-batches/122215)

<div class="topic-metadata">

**Author:** [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Replies:** 4\
**Last updated:** [November 6, 2024, 11:59pm UTC](https://discourse.julialang.org/t/reducing-channel-lock-contention-with-batches/122215 "2024-11-06T23:59:44Z")

</div>

This has been asked before, but it looks like it didn’t go anywhere. Channels are very powerful, but the lock overhead makes it slow for iterating. Bundling items into batches before take!/put! would help with this overh…

---

## [Are there any plans to improve the composability of @batch and/or reduce overhead of @threads?](https://discourse.julialang.org/t/are-there-any-plans-to-improve-the-composability-of-batch-and-or-reduce-overhead-of-threads/122213)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 2\
**Last updated:** [November 5, 2024, 6:09pm UTC](https://discourse.julialang.org/t/are-there-any-plans-to-improve-the-composability-of-batch-and-or-reduce-overhead-of-threads/122213 "2024-11-05T18:09:06Z")

</div>

Does it only require a lot of work? Would it require julia 2.0? Etc. This would definitely be useful info when planning projects. Related to what I learned here:

---

## [How to process a dictionary with multi tasking?](https://discourse.julialang.org/t/how-to-process-a-dictionary-with-multi-tasking/122186)

<div class="topic-metadata">

**Author:** [@dgagnon](https://discourse.julialang.org/u/dgagnon)\
**Replies:** 9\
**Last updated:** [November 3, 2024, 1:45pm UTC](https://discourse.julialang.org/t/how-to-process-a-dictionary-with-multi-tasking/122186 "2024-11-03T13:45:47Z")

</div>

Hello I have a dictionary that I currently process this way: a = pairs(tiledict) foreach(a) do paire # some stuff goes here using paire\[1\] and paire\[2\] end I have to go through the whole dictionary. It does the wo…

---

## [How to write multithreading matrix multiplication](https://discourse.julialang.org/t/how-to-write-multithreading-matrix-multiplication/121865)

<div class="topic-metadata">

**Author:** [@Enc](https://discourse.julialang.org/u/Enc)\
**Replies:** 4\
**Last updated:** [October 29, 2024, 1:31pm UTC](https://discourse.julialang.org/t/how-to-write-multithreading-matrix-multiplication/121865 "2024-10-29T13:31:46Z")

</div>

Hello! I’m studying parallel programming in Julia, so i decided to write some basics matrix multiplication without using Linear Algebra package, because it’s already multi-threaded. using Base.Threads using BenchmarkToo…

[Previous page](https://discourse.julialang.org/tag/multithreading/100.md?match_all_tags=true&page=1&tags%5B%5D=multithreading)

[Next page](https://discourse.julialang.org/tag/multithreading/100.md?match_all_tags=true&page=3&tags%5B%5D=multithreading)
