Hi, I am performing Montecarlo type method and I would like to perform the Multi-Treding.

Unfortunately, I am a beginner in Multi-threading for operations of the form n_{i}/n_{i-1}.

Usually, I perform multiple cores to perform diferent iterations of the same code and I do not

care for the order of the output. But, now I need to put the ordered outputs in an array to perform Prod(n_{i}/n_{i-1}). Here is a simplified version of my code:

```
using Random
using LinearAlgebra
using Distributions
rad = 1.0
rmax = 4
ra = range(0, rad, length=rmax)
sets_prod=Any[]
for s=1:2
suc_iter, pos_iter, neg_iter, rat_set = Any[], Any[], Any[], Any[]
ratious = Any[]
@sync begin
for ri=1:rmax-1
Threads.@spawn begin
suc, pos, neg = 0, 0, 0
for i=1:10^(5)
d = 0
d=rand(Uniform(-ra[ri],ra[ri]), 3)
println("ri, i = $ri, $i on thread $(Threads.threadid())")
if sum(d) >= 0
suc += 1
d[2]=-d[2]
if sum(d) >= 0
pos += 1
else
neg +=1
end
end
end ################### end iterations
push!(suc_iter,suc)
push!(pos_iter,pos)
push!(neg_iter,neg)
if (pos/suc) > 0
push!(rat_set,(pos/suc))
else
push!(rat_set,(0.0))
end
end #### end spawn
end ####Synd
end ##### end radii
println("rat_set: ", rat_set)
for k=2:rmax-1
push!(ratious, rat_set[k]/rat_set[k-1])
end
push!(sets_prod,prod(ratious))
end ############# end sets
println("sets", sets_prod)
The problem is that I want parallelize the loop for ri=1:rmax-1 and after that obtain
the ordered ratios for ri=1,2,3 ..., this because I need the product at the end. I tried
with `spawn` and `@sync` and I am able to send every part of the loop to different
threads but I am not able to collect the results in
push!(suc_iter,suc)
push!(pos_iter,pos)
push!(neg_iter,neg)
in the correct order. I tried Atomic operations but I did not make it work.
Does anyone has a suggestion. Thanks in advance
```