# \[ANN\] ThreadsX.jl: Parallelized Base functions

**URL:** <https://discourse.julialang.org/t/ann-threadsx-jl-parallelized-base-functions/36666>\
**Category:** Package Announcements\
**Tags:** package, announcement, parallel\
**Created:** [March 29, 2020, 5:40am UTC](https://discourse.julialang.org/t/ann-threadsx-jl-parallelized-base-functions/36666 "2020-03-29T05:40:14Z")\
**Posts on this page:** 1\
**Showing post:** 33

<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:** [March 31, 2020, 8:08am UTC](https://discourse.julialang.org/t/ann-threadsx-jl-parallelized-base-functions/36666/33 "2020-03-31T08:08:04Z")

</div>

> [@Elrod](#):
>
> breaks up (what it chooses as) the outer most loop into `Threads.nthreads()` chunks and uses `@spawn`

I guess you are assuming that the outer most axis is much longer than `Threads.nthreads()` and the work load per element is more-or-less constant? I suppose that’s reasonable when the user is asking to vectorize the loop. But, if you want to parallelize all but the inner most axis, it may be useful to use `halve` function from [SplittablesBase.jl](https://github.com/tkf/SplittablesBase.jl) (which can handle `IndexCartesian`-style arrays and `zip` of them). This is how I support something like `ThreadsX.foreach(f, A, A')`. I think this approach is flexible enough to handle “non-rectangular” iterations like upper-triangular part of the matrix.

> [@Elrod](#):
>
> The trickiest part would be having it support reductions.

It’s interesting as I thought reduction would be the easiest part as there is no mutation (e.g., it sounds hard to chunk the iteration space appropriately to avoid simultaneously writing to the shared region). Though maybe there are something subtle when mixing with vectorization? Naively, I’d imagine it’d be implemented as a transformation to `mapreduce`:

1. Separate the loop body to the mapping (`(m, n) -> x[m] * A[m,n] * y[n]`) and reduction (`+`) parts and generate functions for them.
2. Determine unroll factor and SIMD vector width.
3. Feed those functions and parameters to parallelized and vectorized `mapreduce`.

---

_[View the full topic](https://discourse.julialang.org/t/ann-threadsx-jl-parallelized-base-functions/36666)._
