Multithreading on the Mac


#1

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.


#2

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


#3

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 thread somewhat recently regarding thread overhead, maybe that’s of any help to you.


#4

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


#5

Thanks for the pointer, looks relevant!


#6

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…


#7

Note that multithreaded code can also be hit by this unpleasant closure bug. There was also recently a PR to resolve bad performance for one specific multithreading pattern:

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

#8

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


#9

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