# Looking for advice on threading

**URL:** https://discourse.julialang.org/t/looking-for-advice-on-threading/33301
**Category:** General Usage
**Created:** [January 13, 2020, 1:51pm UTC](https://discourse.julialang.org/t/looking-for-advice-on-threading/33301 "2020-01-13T13:51:56Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [January 14, 2020, 10:26pm UTC](https://discourse.julialang.org/t/looking-for-advice-on-threading/33301/4 "2020-01-14T22:26:28Z")

</div>

FYI, with Transducers.jl (see [Thread- and process-based parallelisms in Transducers.jl (+ some news)](https://discourse.julialang.org/t/thread-and-process-based-parallelisms-in-transducers-jl-some-news/32285)), it’s `reduce(+, Map(identity), x; basesize=length(x) ÷ nChunks)`.

> [@Paul\_Soderlind](#):
>
> `xSum = zeros(nChunks)`

> [@ffevotte](#):
>
> `partialSum = zeros(eltype(x), Threads.nthreads())`

I find this kind of approaches limiting as it’s impossible to write a parallel version of `sum(f, xs)` this way without relying on compiler internal (aka `Core.Compiler.return_type`).

> [@ffevotte](#):
>
> `@inbounds partialSum[Threads.threadid()] += e`

I think this pattern would invoke [false sharing](https://en.wikipedia.org/wiki/False_sharing) and could be bad for performance.

---

_[View the full topic](https://discourse.julialang.org/t/looking-for-advice-on-threading/33301)._
