Multithreading on the Mac

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.

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

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.

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

Thanks for the pointer, looks relevant!

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…

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

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

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