I have the following snippet of code where I am looping over and would like to append/push to curetime or progressiontime based on conditions met. As I want to increase the size of the loop it would be helpful to run this in parallel:
nPatients = 10^6
global curetime = #SharedArray{Float64}(nPatients)
global progressiontime = #SharedArray{Float64}(nPatients)for n = 1 : nPatients
(t, discretePop, continuousPop) = main() if ~isempty(discretePop) && discretePop[4,end] == 0.0 println("cure at t = $(t[end])") # curetime[n] = t[end] push!(curetime,t[end]) elseif continuousPop[4,end] > continuousPop[4,1]*1.2 println("progression at t = $(t[end])") # progressiontime[n] = t[end] push!(progressiontime,t[end]) else println("Stable at t = 200.0") end
end
How can I fix this code to work in parallel? I have tried @distributed but I get complaints when using push!. I am open to preallocating the array size and potentially returning a list (e.g. (timeOfEvent, eventType), where eventType = cure or progression) if this easier to implement.
As an aside, I have also tried @time @distributed and got a time returned of < 1 second when it actually took >10 seconds to return this value to the screen.