# Help with parallelizing indirect inference estimation

**URL:** <https://discourse.julialang.org/t/help-with-parallelizing-indirect-inference-estimation/64487>\
**Category:** Performance\
**Tags:** parallel\
**Created:** [July 12, 2021, 6:33am UTC](https://discourse.julialang.org/t/help-with-parallelizing-indirect-inference-estimation/64487 "2021-07-12T06:33:25Z")\
**Posts on this page:** 1\
**Showing post:** 13

<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:** [July 29, 2021, 9:42am UTC](https://discourse.julialang.org/t/help-with-parallelizing-indirect-inference-estimation/64487/13 "2021-07-29T09:42:31Z")

</div>

> [@mcreel](#):
>
> ```julia
> m = zeros(size(x,2))
> Threads.@threads for i in 1:M
> #for i in 1:M
> m .+= ols(x,ys[i])
> end
> 
> ```

`m .+= ...` causes a data race. Every thread tries to update every element in `m`.

If you need a parallel sum, checkout `Folds.sum` or `FLoops.@reduce`.

> [@amrods](#):
>
> Is there a way to add threads to Julia after it is started?

This is not possible at the moment. It’d require a rather large surgery to the Julia runtime.

> [@amrods](#):
>
> `@floop for i in 1:size(x, 1)`

You’d need `@floop ThreadedEx() for i in 1:size(x, 1)`. Similar Q/A [Problem with `@reduce` of `FLoops`; data race? - #2 by tkf](https://discourse.julialang.org/t/problem-with-reduce-of-floops-data-race/65410/2)

---

_[View the full topic](https://discourse.julialang.org/t/help-with-parallelizing-indirect-inference-estimation/64487)._
