# Parallel implementation of Transducers.jl

**URL:** <https://discourse.julialang.org/t/parallel-implementation-of-transducers-jl/55767>\
**Category:** General Usage\
**Tags:** parallel\
**Created:** [February 22, 2021, 9:17am UTC](https://discourse.julialang.org/t/parallel-implementation-of-transducers-jl/55767 "2021-02-22T09:17:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [February 22, 2021, 9:55am UTC](https://discourse.julialang.org/t/parallel-implementation-of-transducers-jl/55767/2 "2021-02-22T09:55:14Z")

</div>

Well, I’ve been thinking about it and I guess I can use tcollect if I make a transducer that maps a container of initial conditions into a container of simulation results.

EDIT: I corrected my code using `tcollect` and `dcollect` as follows and it seems work.

(some part of the corrected code)

```julia
    # simulator
    trajs_evaluate(x0, ts) = Sim(env, x0, ts, ẋ) |> TakeWhile(!terminal_condition) |> Map(postprocess) |> evaluate
    # paralell simulation
    n = rand(num)
    @time data_single = trajs_evaluate(x0s[n], ts) # single scenario
    @time data_multiple = x0s |> Map(x0 -> trajs_evaluate(x0, ts)) |> collect # multiple scenarios
    @time data_parallel_t = x0s |> Map(x0 -> trajs_evaluate(x0, ts)) |> tcollect # multiple scenarios with thread-based parallel computing
    @time data_parallel_d = x0s |> Map(x0 -> trajs_evaluate(x0, ts)) |> dcollect # multiple scenarios with process-based parallel computing
    @test data_single == data_multiple[n]
    @test data_multiple == data_parallel_t == data_parallel_d

```

---

_[View the full topic](https://discourse.julialang.org/t/parallel-implementation-of-transducers-jl/55767)._
