# Efficient parallelization of in place transforms

**URL:** <https://discourse.julialang.org/t/efficient-parallelization-of-in-place-transforms/59062>\
**Category:** Performance\
**Tags:** parallel\
**Created:** [April 12, 2021, 12:03am UTC](https://discourse.julialang.org/t/efficient-parallelization-of-in-place-transforms/59062 "2021-04-12T00:03:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [April 12, 2021, 12:03am UTC](https://discourse.julialang.org/t/efficient-parallelization-of-in-place-transforms/59062/1 "2021-04-12T00:03:56Z")

</div>

I wanted to revisit this discussion from [Pmap with in place functions](https://discourse.julialang.org/t/pmap-with-in-place-functions/10523) that I started 2 years ago. Generalizing a bit, suppose I have an in place transform `f!(x)` and array of data, `xvals`, on which I want to apply the transform:

```julia
f!.(xvals)

```

Being open to multithreading/multiprocessing, is there a straightforward way to modify this to take advantage of a shared memory environment? Ideally, I’d like to have a piece of code that will still execute properly in a purely serial situation.

---

<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:** [April 12, 2021, 4:50am UTC](https://discourse.julialang.org/t/efficient-parallelization-of-in-place-transforms/59062/2 "2021-04-12T04:50:22Z")

</div>

FoldsDagger.jl contains a proof-of-concept implementation for this. However, we are still searching for a good Dagger API, for supporting this type of computation: [Correctly implement in-place mutation · Issue #7 · JuliaFolds/FoldsDagger.jl · GitHub](https://github.com/JuliaFolds/FoldsDagger.jl/issues/7)

Once this is implemented correctly, it should be possible to use [`Folds.map!`](https://juliafolds.github.io/Folds.jl/dev/#Folds.map!) to express this type of computation. Alternatively, you can combine [FLoops.jl](https://github.com/JuliaFolds/FLoops.jl) and [Referenceables.jl](https://github.com/tkf/Referenceables.jl) (for easier multi-output support)

```julia
@floop executor for x in referenceable(xs)
    x[] += 1
end

```

This kind of code is already executable on a single thread, multiple threads, and GPU. We need a good distributed collections library to make it work in distributed environments.
