# Parallelize simulations and print out results immediately when they are available

**URL:** <https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025>\
**Category:** New to Julia\
**Created:** [May 9, 2019, 12:09pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025 "2019-05-09T12:09:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [May 9, 2019, 12:09pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025/1 "2019-05-09T12:09:25Z")

</div>

I have currently some code like this

```julia
function printsim(simulator, nsample)
    for i = 1:nsample 
        println(simulation(simulator))
    end
end

```

As soon as each simulation is over, I print it to standard output, which I usually redirect to a file. In this way if the simulation is interrupted, I still have some results.

When I want to parallelize it, now I just start multiple Julia processes with a Python. But this sometimes create issues-- [https://github.com/JuliaLang/julia/issues/31953](https://github.com/JuliaLang/julia/issues/31953)

If I want to parallelize this inside Julia, how can I do it?

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [May 9, 2019, 1:46pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025/2 "2019-05-09T13:46:53Z")

</div>

Have you read the guide on parallel computing? The 3rd section “Multi-Core or Distributed Processing” should do what you want.

[https://docs.julialang.org/en/v1/manual/parallel-computing/index.html](https://docs.julialang.org/en/v1/manual/parallel-computing/index.html)

AFAIK, there are still issues with IO and multithreaiding, but it should be no problem with parallel worker processes.

---

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [May 9, 2019, 6:27pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025/3 "2019-05-09T18:27:20Z")

</div>

So there wouldn’t any issue if I print to stdout in every worker process? The output will not be scrambled?

---

<div class="post-metadata">

**Author:** ![Xing\_Shi\_Cai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xing_shi_cai/32/14128_2.png) [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Post date:** [May 9, 2019, 8:18pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025/4 "2019-05-09T20:18:15Z")

</div>

I did a bit experiments, it seems to be fine to print from multiple process, but the output is like this

```julia
      From worker 2:	154407.10809850367 617409.1958756159 3.4875938817358254e6 
      From worker 2:	153981.47053866184 601490.2774611807 3.262175496086296e6

```

Is there any way to get rid of this “From worker”?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 9, 2019, 8:59pm UTC](https://discourse.julialang.org/t/parallelize-simulations-and-print-out-results-immediately-when-they-are-available/24025/5 "2019-05-09T20:59:10Z")

</div>

> [@Any way to remove "From worker"?](https://discourse.julialang.org/t/any-way-to-remove-from-worker/23604):
>
> I want to print some data in a distributed for-loop but I don’t really want to see these lines with the “from worker” prefix. Is there any way to get rid of it? From worker 3: hello From worker 4: world From worker 2: foo
