@@ -87,88 +87,52 @@ capacity(proc, ::Type{T}) where T =
87
87
"""
88
88
OSProc <: Processor
89
89
90
- Julia CPU (OS) process, identified by Distributed pid. Executes thunks when
91
- threads or other "children" processors are not available, and/or the user has
92
- not opted to use those processors .
90
+ Julia CPU (OS) process, identified by Distributed pid. The logical parent of
91
+ all processors on a given node, but otherwise does not participate in
92
+ computations .
93
93
"""
94
94
struct OSProc <: Processor
95
95
pid:: Int
96
- attrs:: Dict{Symbol,Any}
97
- children:: Vector{Processor}
98
- queue:: Vector{Processor}
99
- end
100
- const OSPROC_CACHE = Dict {Int,OSProc} ()
101
- OSProc (pid:: Int = myid ()) = get! (OSPROC_CACHE, pid) do
102
- remotecall_fetch (get_osproc, pid, pid)
96
+ function OSProc (pid:: Int = myid ())
97
+ get! (OSPROC_CACHE, pid) do
98
+ remotecall_fetch (get_proc_hierarchy, pid)
99
+ end
100
+ new (pid)
101
+ end
103
102
end
104
- function get_osproc (pid:: Int )
105
- proc = OSProc (pid, Dict {Symbol,Any} (), Processor[], Processor[])
103
+ const OSPROC_CACHE = Dict {Int,Vector{Processor}} ()
104
+ children (proc:: OSProc ) = OSPROC_CACHE[proc. pid]
105
+ function get_proc_hierarchy ()
106
+ children = Processor[]
106
107
for cb in PROCESSOR_CALLBACKS
107
108
try
108
- child = Base. invokelatest (cb, proc)
109
- child != = nothing && push! (proc. children, child)
109
+ child = Base. invokelatest (cb)
110
+ if (child isa Tuple) || (child isa Vector)
111
+ append! (children, child)
112
+ elseif child != = nothing
113
+ push! (children, child)
114
+ end
110
115
catch err
111
116
@error " Error in processor callback" exception= (err,catch_backtrace ())
112
117
end
113
118
end
114
- proc
119
+ children
115
120
end
116
121
function add_callback! (func)
117
122
push! (Dagger. PROCESSOR_CALLBACKS, func)
118
123
empty! (OSPROC_CACHE)
119
124
end
120
125
Base.:(== )(proc1:: OSProc , proc2:: OSProc ) = proc1. pid == proc2. pid
121
126
iscompatible (proc:: OSProc , opts, f, args... ) =
122
- any (child-> iscompatible (child, opts, f, args... ), proc . children)
127
+ any (child-> iscompatible (child, opts, f, args... ), children (proc) )
123
128
iscompatible_func (proc:: OSProc , opts, f) =
124
- any (child-> iscompatible_func (child, opts, f), proc . children)
129
+ any (child-> iscompatible_func (child, opts, f), children (proc) )
125
130
iscompatible_arg (proc:: OSProc , opts, args... ) =
126
131
any (child->
127
132
all (arg-> iscompatible_arg (child, opts, arg), args),
128
- proc . children)
133
+ children (proc) )
129
134
get_processors (proc:: OSProc ) =
130
- vcat ((get_processors (child) for child in proc. children). .. ,)
131
- function choose_processor (options, f, Targs)
132
- osproc = OSProc ()
133
- if isempty (osproc. queue)
134
- for child in osproc. children
135
- grandchildren = get_processors (child)
136
- append! (osproc. queue, grandchildren)
137
- end
138
- end
139
- @assert ! isempty (osproc. queue)
140
- for i in 1 : length (osproc. queue)
141
- proc = popfirst! (osproc. queue)
142
- push! (osproc. queue, proc)
143
- if ! iscompatible (proc, options, f, Targs... )
144
- continue
145
- end
146
- if options. proclist === nothing
147
- default_enabled (proc) && return proc
148
- elseif options. proclist isa Function
149
- options. proclist (proc) && return proc
150
- elseif any (p-> proc isa p, options. proclist)
151
- return proc
152
- end
153
- end
154
- throw (ProcessorSelectionException (options. proclist, osproc. queue, f, Targs))
155
- end
156
- struct ProcessorSelectionException <: Exception
157
- proclist
158
- procsavail:: Vector{Processor}
159
- f
160
- args
161
- end
162
- function Base. show (io:: IO , pex:: ProcessorSelectionException )
163
- println (io, " (Worker $(myid ()) ) Exhausted all available processor types!" )
164
- println (io, " Proclist: $(pex. proclist) " )
165
- println (io, " Procs Available: $(pex. procsavail) " )
166
- println (io, " Function: $(pex. f) " )
167
- print (io, " Arguments: $(pex. args) " )
168
- end
169
-
170
- execute! (proc:: OSProc , f, args... ) = f (args... )
171
- default_enabled (proc:: OSProc ) = true
135
+ vcat ((get_processors (child) for child in children (proc)). .. )
172
136
173
137
"""
174
138
ThreadProc <: Processor
0 commit comments