in my code I have 32 parameter, so I used 32 for loop which have 2 steps in each loop. 2^32 computation should be done and it takes long long time. how can I run them parallel to run fast?
my code is this form
c=[0,1];
d=[0.1,0.5];
for x1=c
for x2=c
…
for x16=c
for y1=d
for y2=d
for y3=d
…
for y16=d
H= function of 32 parameter ;
tout, ρₜ = steadystate.master(H, J);
e2= expect(e2e2, ρₜ[end]);
if e2>0.3
println(e2);
end #(in this part I have some calculations to find the best values of 32 parameter )
end
…
end
Do you have 32 nested loops or just 32 separate loops? Could you give a bit more details about what you want to do so that we can try and help you? Sharing a MWE (Minimal Working Example) or just the code you are trying to run can help us a lot.
If it is something like independent samplings, then Threads.@threads
is a good choice in front of the for loop.
Yes. It is nested loop. I used @distributed and @thread but there is not any useful result.
I’ve used it. But did not help me to do fast
You could try using FLoops.jl, or depending if your code supports it @avxt from LoopVectorization.jl
Maybe you can try using Iterators.product
to convert the 32 loops into one loop over the combinations of parameters. Them, make this single loop parallel. But really with only that information is not easy to help.
FYI, FLoops.jl supports nested loops (as in @floop ThreadedEx() for i in 1:32, j in 1:32
) and also Iterators.product
.
thanks.
I edited my question to show form of my code.
I edited my question to give more details. sorry, I am a beginner. thank you if you give me more explanation.