Skip to content

Commit 71d6de2

Browse files
Distributed.jl -> Multicluster.jl
1 parent ffd5c98 commit 71d6de2

File tree

2 files changed

+425
-0
lines changed

2 files changed

+425
-0
lines changed

src/Multicluster.jl

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
"""
4+
Tools for distributed parallel processing.
5+
"""
6+
module Multicluster
7+
8+
# imports for extension
9+
import Base: getindex, wait, put!, take!, fetch, isready, push!, length,
10+
hash, ==, kill, close, isopen, showerror, iterate, IteratorSize
11+
12+
# imports for use
13+
using Base: Process, Semaphore, JLOptions, buffer_writes, @async_unwrap,
14+
VERSION_STRING, binding_module, atexit, julia_exename,
15+
julia_cmd, AsyncGenerator, acquire, release, invokelatest,
16+
shell_escape_posixly, shell_escape_csh,
17+
shell_escape_wincmd, escape_microsoft_c_args,
18+
uv_error, something, notnothing, isbuffered, mapany, SizeUnknown
19+
using Base.Threads: Event
20+
21+
using Serialization, Sockets
22+
import Serialization: serialize, deserialize
23+
import Sockets: connect, wait_connected
24+
25+
using MPIClusterManagers
26+
27+
# NOTE: clusterserialize.jl imports additional symbols from Serialization for use
28+
29+
export
30+
@spawn,
31+
@spawnat,
32+
@fetch,
33+
@fetchfrom,
34+
@everywhere,
35+
@distributed,
36+
37+
AbstractWorkerPool,
38+
addprocs,
39+
CachingPool,
40+
clear!,
41+
ClusterManager,
42+
default_worker_pool,
43+
init_worker,
44+
interrupt,
45+
launch,
46+
manage,
47+
myid,
48+
nprocs,
49+
nworkers,
50+
pmap,
51+
procs,
52+
remote,
53+
remotecall,
54+
remotecall_eval,
55+
remotecall_fetch,
56+
remotecall_wait,
57+
remote_do,
58+
rmprocs,
59+
workers,
60+
WorkerPool,
61+
RemoteChannel,
62+
Future,
63+
WorkerConfig,
64+
RemoteException,
65+
ProcessExitedException,
66+
67+
process_messages,
68+
remoteref_id,
69+
channel_from_id,
70+
worker_id_from_socket,
71+
cluster_cookie,
72+
start_worker,
73+
74+
75+
76+
# Used only by shared arrays.
77+
check_same_host
78+
79+
function _require_callback(mod::Base.PkgId)
80+
if Base.toplevel_load[] && nprocs(role=:master) > 1
81+
# broadcast top-level (e.g. from Main) import/using from node 1 (only)
82+
@sync for p in procs(role = :master)
83+
#@info "require callback", p
84+
p == 1 && continue
85+
# Extensions are already loaded on workers by their triggers being loaded
86+
# so no need to fire the callback upon extension being loaded on master.
87+
Base.loading_extension && continue
88+
@async_unwrap remotecall_wait(p; role = :master) do
89+
Base.require(mod)
90+
nothing
91+
end
92+
end
93+
end
94+
end
95+
96+
const REF_ID = Threads.Atomic{Int}(1)
97+
next_ref_id() = Threads.atomic_add!(REF_ID, 1)
98+
99+
struct RRID
100+
whence::Int
101+
id::Int
102+
103+
RRID(;role= :default) = RRID(myid(role=role), next_ref_id())
104+
RRID(whence, id) = new(whence, id)
105+
end
106+
107+
hash(r::RRID, h::UInt) = hash(r.whence, hash(r.id, h))
108+
==(r::RRID, s::RRID) = (r.whence==s.whence && r.id==s.id)
109+
110+
include("clusterserialize.jl")
111+
include("cluster.jl") # cluster setup and management, addprocs
112+
include("messages.jl")
113+
include("process_messages.jl") # process incoming messages
114+
include("remotecall.jl") # the remotecall* api
115+
include("macros.jl") # @spawn and friends
116+
include("workerpool.jl")
117+
include("pmap.jl")
118+
include("managers.jl") # LocalManager and SSHManager
119+
include("precompile.jl")
120+
include("multicluster_exts.jl")
121+
122+
function __init__()
123+
init_parallel()
124+
end
125+
126+
end

0 commit comments

Comments
 (0)