# Parallel Reductions with Zygote

**URL:** https://discourse.julialang.org/t/parallel-reductions-with-zygote/75969
**Category:** Performance
**Tags:** question, parallel, zygote, threads, sum
**Created:** [February 7, 2022, 7:42pm UTC](https://discourse.julialang.org/t/parallel-reductions-with-zygote/75969 "2022-02-07T19:42:35Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [February 7, 2022, 8:55pm UTC](https://discourse.julialang.org/t/parallel-reductions-with-zygote/75969/5 "2022-02-07T20:55:36Z")

</div>

> [@SEA](#):
>
> I just tried out `Folds` , but realized it relies on `Transducers` , the same backend as `ThreadsX` and for this reason, has the same performance (Intel) and segfault (ARM) issues as `ThreadsX` in conjunction with `Zygote` .

Naive parallel implementations we discussed [here](https://discourse.julialang.org/t/speed-issue-with-kahansummation/75491).

Edit: sorry, corrected link.  
Edit: just for reference, here my latest parallelized version

```julia
function naive_kbn_parallel(xs) # credit to @tkf from another thread
    len = length(xs)
    nt = min(Threads.nthreads(), len)
    ys = Vector{Float64}(undef, 2 * nt)
    chunk = (len + nt - 1) ÷ nt
    Threads.@threads for i in 1:nt
        s, c = _naive_kbn(@view xs[(i - 1) * chunk + 1:min(i * chunk, len)])
        ys[2 * i - 1] = s
        ys[2 * i] = c
    end
    naive_kbn_serial(ys)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/parallel-reductions-with-zygote/75969)._
