This is partially a performance question. I have a parallel process that is working. However, by using @spawn
, all of the tasks are spawned to the available workers before any of the tasks start running. It doesn’t seem like @spawn
cares about whether workers are busy. The tasks are of varying lengths, so some workers finish all of the tasks long before the other workers are done with all of their tasks. This means my CPU utilization goes from 100% to 90% to 80% and so one, slowly dropping CPU utilization.
Is there a way to have @spawn only assign tasks to workers if the worker is not busy with something else already? Then the CPU utilization would stay near 100% the entire time. Here’s a snippit of the code from the relevant section.
#Example Code
@sync for x in packedChunk
@async fs[x.id] = @spawn run_chunks(x.id,x.project,x.scenario,x.sim_group
,x.ord_day,x.dt_file,x.ord_file
,x.driver_file,x.trailer_file
,x.shipwith_file,x.infeasible_file
,x.stopcon_file,x.storetrail_file)
end
@sync for i = eachindex(fs)
a,b = fetch(fs[i])
append!(toOutputFile, a)
append!(toOrphansFile, b)
end