# Running for loop in parallel and appending result to vector

**URL:** <https://discourse.julialang.org/t/running-for-loop-in-parallel-and-appending-result-to-vector/20487>\
**Category:** General Usage\
**Tags:** parallel\
**Created:** [February 5, 2019, 9:14pm UTC](https://discourse.julialang.org/t/running-for-loop-in-parallel-and-appending-result-to-vector/20487 "2019-02-05T21:14:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 5, 2019, 11:03pm UTC](https://discourse.julialang.org/t/running-for-loop-in-parallel-and-appending-result-to-vector/20487/2 "2019-02-05T23:03:52Z")

</div>

First, take a look at [this topic](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) on how to format and phrase your question to get better help.

Mostly, it’s very helpful if you can post a minimal, working, self-contained example. It’s not clear from this code what `main` does, how `n` is supposed to be used in the loop, how often you’ll push to the vectors, if you actually intend to print for each iteration, etc.

Is `@distributed` what you want (parallel computing), and not just `@threads` (multiple threads in a single computer)? More details [here](https://docs.julialang.org/en/v1/manual/parallel-computing/index.html).

Multi-threading is usually the last optimization step I do, since it tends to complicate the code, and for unoptimized code you can typically achieve much better speedups using other techniques. Is the rest of your code already optimized? Proper choice of data structures and algorithms, type stability, caching, vectorization where applicable?

---

_[View the full topic](https://discourse.julialang.org/t/running-for-loop-in-parallel-and-appending-result-to-vector/20487)._
