using Distributed
addprocs(2, exeflags="--project")
@everywhere begin
function update_remote_counter(remote_counter::RemoteChannel, update_count::Int)
old_value=take!(remote_counter)
put!(remote_counter, old_value + update_count)
return nothing
end
function uses_ts(training_step)
training_step_ = 0
while training_step_ < 10000
training_step_ = fetch(training_step)
println("From user", training_step_)
end
return true
end
function changes_ts(training_step)
training_step_ = 0
while training_step_ < 10000
training_step_ += 1
update_remote_counter(training_step, 1)
println("From changer", training_step_)
end
return true
end
end
training_step = RemoteChannel(()->Channel{Int}(1))
put!(training_step, 0)
u = @spawnat :any uses_ts(training_step)
c = @spawnat :any changes_ts(training_step)
Here is a MWE of my code for the MuZero algorithm at the link.
In the example the line update_remote_counter(training_step, 1)
executes successfully until the last iteration. However in the original code, it is a bottleneck after some iterations. I have checked this using println
just before and the after this line. The code prints before the line but is waiting for RemoteChannel training_step
to receive a value.
Does anyone know why this is happening?