# Multithreading on the Mac

**URL:** <https://discourse.julialang.org/t/multithreading-on-the-mac/8436>\
**Category:** General Usage\
**Created:** [January 17, 2018, 4:40pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436 "2018-01-17T16:40:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 17, 2018, 4:40pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/1 "2018-01-17T16:40:35Z")

</div>

Has anyone made some (good) experiences with MT on the Mac? I have a code that runs well MTed on Linux (up to 64 cores w/ corresponding number of threads), but it clearly leaves some performance on the table when run on the Mac…

Thanks for any pointers/info.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [January 17, 2018, 6:49pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/2 "2018-01-17T18:49:54Z")

</div>

I use threads with good success, on a Macbook Air, but running Debian.

---

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [January 17, 2018, 6:55pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/3 "2018-01-17T18:55:27Z")

</div>

I have some multithreaded code (but only 4 cores) which seems to work fine (but I did not time things properly). There was also [this](https://discourse.julialang.org/t/thread-overhead-variability-across-machines/7320/8) thread somewhat recently regarding thread overhead, maybe that’s of any help to you.

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [January 17, 2018, 7:35pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/4 "2018-01-17T19:35:07Z")

</div>

I have had some success, even though my Mac only has 2 logical cores.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 17, 2018, 9:19pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/5 "2018-01-17T21:19:29Z")

</div>

Thanks for the pointer, looks relevant!

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 17, 2018, 9:20pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/6 "2018-01-17T21:20:43Z")

</div>

Thanks to all who responded. It sounds like multithreading SHOULD work on the Mac, and hence I will put some more effort into trying to make it work…

---

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [January 18, 2018, 6:16am UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/7 "2018-01-18T06:16:52Z")

</div>

Note that multithreaded code can also be hit by this unpleasant [closure bug](https://github.com/JuliaLang/julia/issues/15276). There was also recently a [PR](https://github.com/JuliaLang/julia/pull/24688) to resolve bad performance for one specific multithreading pattern:

```julia
function threaded_sum(arr)
    @assert length(arr) % nthreads() == 0
    results::Vector{Float64} = zeros(eltype(arr), nthreads())
    @threads for tid in 1:nthreads()
        # split work
        len = div(length(arr), nthreads())
        domain = ((tid-1)*len +1):tid*len
        acc = zero(eltype(arr))
        @simd for i in domain
            @inbounds acc += arr[i]
        end
        results[tid] = acc
    end
    sum(results)
end

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 18, 2018, 4:21pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/8 "2018-01-18T16:21:53Z")

</div>

But this issue would not be specific to the Mac, or would it?

---

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [January 18, 2018, 4:28pm UTC](https://discourse.julialang.org/t/multithreading-on-the-mac/8436/9 "2018-01-18T16:28:51Z")

</div>

My bad, I forgot that you already have running Linux code.
