@@ -148,26 +148,25 @@ function thunkize(ctx, c::Cat)
148
148
end
149
149
thunkize (ctx, x:: AbstractChunk ) = x
150
150
thunkize (ctx, x:: Thunk ) = x
151
+
151
152
function finish_task! (state, node, node_order; free= true )
152
- deps = sort ([i for i in state[:dependents ][node]], by= node_order)
153
- immediate_next = false
154
153
if istask (node) && node. cache
155
154
node. cache_ref = Nullable {Any} (state[:cache ][node])
156
155
end
157
- for dep in deps
156
+ immediate_next = false
157
+ for dep in sort! (collect (state[:dependents ][node]), by= node_order)
158
158
set = state[:waiting ][dep]
159
159
pop! (set, node)
160
160
if isempty (set)
161
161
pop! (state[:waiting ], dep)
162
- immediate_next = true
163
162
push! (state[:ready ], dep)
163
+ immediate_next = true
164
164
end
165
165
# todo: free data
166
166
end
167
167
for inp in inputs (node)
168
168
if inp in keys (state[:waiting_data ])
169
169
s = state[:waiting_data ][inp]
170
- # @show s
171
170
if node in s
172
171
pop! (s, node)
173
172
end
@@ -197,12 +196,7 @@ function compute(ctx, d::Thunk)
197
196
ps = procs (ctx)
198
197
chan = Channel {Any} (32 )
199
198
deps = dependents (d)
200
- ndeps = noffspring (deps)
201
- ord = order (d, ndeps)
202
-
203
- sort_ord = collect (ord)
204
- sortord = x -> istask (x[1 ]) ? x[1 ]. id : 0
205
- sort_ord = sort (sort_ord, by= sortord)
199
+ ord = order (d, noffspring (deps))
206
200
207
201
node_order = x -> - get (ord, x, 0 )
208
202
state = start_state (deps, node_order)
@@ -218,21 +212,16 @@ function compute(ctx, d::Thunk)
218
212
219
213
while ! isempty (state[:waiting ]) || ! isempty (state[:ready ]) || ! isempty (state[:running ])
220
214
proc, thunk_id, res = take! (chan)
221
-
222
215
if isa (res, CapturedException) || isa (res, RemoteException)
223
216
rethrow (res)
224
217
end
225
218
node = _thunk_dict[thunk_id]
226
219
@logmsg (" W$(proc. pid) - $node ($(node. f) ) input:$(node. inputs) " )
227
220
state[:cache ][node] = res
228
- # @show state[:cache]
229
- # @show ord
230
- # if any of this guy's dependents are waiting,
231
- # update them
232
- @dbg timespan_start (ctx, :scheduler , thunk_id, master)
233
221
222
+ # if any of this guy's dependents are waiting, update them
223
+ @dbg timespan_start (ctx, :scheduler , thunk_id, master)
234
224
immediate_next = finish_task! (state, node, node_order)
235
-
236
225
if ! isempty (state[:ready ])
237
226
if immediate_next
238
227
# fast path
@@ -248,7 +237,6 @@ function compute(ctx, d::Thunk)
248
237
end
249
238
@dbg timespan_end (ctx, :scheduler , thunk_id, master)
250
239
end
251
-
252
240
state[:cache ][d]
253
241
end
254
242
@@ -342,7 +330,6 @@ function fire_task!(ctx, thunk, proc, state, chan, node_order)
342
330
data = map (thunk. inputs) do x
343
331
istask (x) ? state[:cache ][x] : x
344
332
end
345
-
346
333
async_apply (ctx, proc, thunk. id, thunk. f, data, chan, thunk. get_result, thunk. persist)
347
334
end
348
335
@@ -364,8 +351,6 @@ function dependents(node::Thunk, deps=Dict())
364
351
deps
365
352
end
366
353
367
-
368
-
369
354
"""
370
355
recursively find the number of taks dependent on each task in the DAG.
371
356
Input: dependents dict
@@ -383,7 +368,6 @@ function noffspring(n, dpents)
383
368
end
384
369
end
385
370
386
-
387
371
"""
388
372
Given a root node of the DAG, calculates a total order for tie-braking
389
373
@@ -397,18 +381,16 @@ Args:
397
381
- ndeps: result of `noffspring`
398
382
"""
399
383
function order (node:: Thunk , ndeps)
400
- order ([node], ndeps, 0 )[2 ]
401
- end
402
-
403
- function order (nodes:: AbstractArray , ndeps, c, output= Dict ())
404
-
405
- for node in nodes
406
- c+= 1
407
- output[node] = c
408
- nxt = sort (Any[n for n in inputs (node)], by= k-> get (ndeps,k,0 ))
409
- c, output = order (nxt, ndeps, c, output)
384
+ function recur (nodes, s)
385
+ for n in nodes
386
+ output[n] = s += 1
387
+ s = recur (sort! (collect (Any, inputs (n)), by= k-> get (ndeps,k,0 )), s)
388
+ end
389
+ return s
410
390
end
411
- c, output
391
+ output = Dict {Any,Int} ()
392
+ recur ([node], 0 )
393
+ return output
412
394
end
413
395
414
396
function start_state (deps:: Dict , node_order)
0 commit comments