forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refinements per @amitmurthy comments: JuliaLang#15073 Update _default_worker_pool via JoinPGRPMsg and JoinCompleteMsg per JuliaLang#15073 (comment) Remove sleep() from test/parallel_exec.jl Use Nullable for _default_worker_pool. Init only when myid() == 1. rewrite default_worker_pool() test for n workers
- Loading branch information
1 parent
3c1f2d3
commit 0ab0cad
Showing
5 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1223,6 +1223,7 @@ export | |
pmap, | ||
procs, | ||
put!, | ||
remote, | ||
remotecall, | ||
remotecall_fetch, | ||
remotecall_wait, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# This file is a part of Julia. License is MIT: http://julialang.org/license | ||
|
||
|
||
type WorkerPool | ||
channel::RemoteChannel{Channel{Int}} | ||
end | ||
|
||
|
||
""" | ||
WorkerPool([workers]) | ||
Create a WorkerPool from a vector of worker ids. | ||
""" | ||
function WorkerPool(workers=Int[]) | ||
|
||
# Create a shared queue of available workers... | ||
pool = WorkerPool(RemoteChannel(()->Channel{Int}(128))) | ||
|
||
# Add workers to the pool... | ||
for w in workers | ||
put!(pool, w) | ||
end | ||
|
||
return pool | ||
end | ||
|
||
|
||
put!(pool::WorkerPool, w::Int) = put!(pool.channel, w) | ||
put!(pool::WorkerPool, w::Worker) = put!(pool.channel, w.id) | ||
|
||
isready(pool::WorkerPool) = isready(pool.channel) | ||
|
||
take!(pool::WorkerPool) = take!(pool.channel) | ||
|
||
|
||
""" | ||
remotecall_fetch(f, pool::WorkerPool, args...) | ||
Call `f(args...)` on one of the workers in `pool`. | ||
""" | ||
function remotecall_fetch(f, pool::WorkerPool, args...) | ||
worker = take!(pool) | ||
try | ||
remotecall_fetch(f, worker, args...) | ||
finally | ||
put!(pool, worker) | ||
end | ||
end | ||
|
||
|
||
""" | ||
default_worker_pool | ||
Built-in WorkerPool (used by `remote(f)`). | ||
""" | ||
_default_worker_pool = Nullable{WorkerPool}() | ||
function default_worker_pool() | ||
if isnull(_default_worker_pool) && myid() == 1 | ||
set_default_worker_pool(WorkerPool()) | ||
end | ||
return get(_default_worker_pool) | ||
end | ||
|
||
function set_default_worker_pool(p::WorkerPool) | ||
global _default_worker_pool = Nullable(p) | ||
end | ||
|
||
|
||
""" | ||
remote(f) | ||
Returns a lambda that executes function `f` using the `default_worker_pool()`. | ||
""" | ||
remote(f) = (args...)->remotecall_fetch(f, default_worker_pool(), args...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters