Skip to content

Commit 63a9741

Browse files
add CachingPool method for remotecall
1 parent aa2858e commit 63a9741

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/workerpool.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ function remotecall_pool(rc_f::typeof(remotecall), f, pool::AbstractWorkerPool,
169169
return x
170170
end
171171

172+
function remotecall_pool(rc_f::typeof(remotecall), f, pool::CachingPool, args...; kwargs...)
173+
worker = take!(pool)
174+
f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker)))
175+
isa(f_ref, Tuple) && (pool.map_obj2ref[(worker, f)] = f_ref[2]) # Add to tracker
176+
177+
local x
178+
try
179+
x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...)
180+
catch
181+
put!(pool, worker)
182+
rethrow()
183+
end
184+
185+
t = Threads.@spawn Threads.threadpool() try
186+
wait(x)
187+
finally
188+
put!(pool, worker)
189+
end
190+
errormonitor(t)
191+
192+
return x
193+
end
194+
172195
# Check if pool is local or remote and forward calls if required.
173196
# NOTE: remotecall_fetch does it automatically, but this will be more efficient as
174197
# it avoids the overhead associated with a local remotecall.

0 commit comments

Comments
 (0)