@@ -82,8 +82,8 @@ ProcessScope() = ProcessScope(myid())
82
82
struct ProcessorTypeTaint{T} <: AbstractScopeTaint end
83
83
84
84
" Scoped to any processor with a given supertype."
85
- ProcessorTypeScope (T) =
86
- TaintScope (AnyScope () ,
85
+ ProcessorTypeScope (T, inner_scope = AnyScope () ) =
86
+ TaintScope (inner_scope ,
87
87
Set {AbstractScopeTaint} ([ProcessorTypeTaint {T} ()]))
88
88
89
89
" Scoped to a specific processor."
@@ -318,47 +318,86 @@ function to_scope(sc::NamedTuple)
318
318
return to_scope (Val (max_prec_key), sc)
319
319
end
320
320
321
+ all_workers = false
321
322
workers = if haskey (sc, :worker )
322
323
Int[sc. worker]
323
324
elseif haskey (sc, :workers )
324
- Int[sc. workers... ]
325
+ if sc. workers == Colon ()
326
+ all_workers = true
327
+ nothing
328
+ else
329
+ Int[sc. workers... ]
330
+ end
325
331
else
332
+ all_workers = true
326
333
nothing
327
334
end
335
+
336
+ all_threads = false
337
+ want_threads = false
328
338
threads = if haskey (sc, :thread )
339
+ want_threads = true
329
340
Int[sc. thread]
330
341
elseif haskey (sc, :threads )
331
- Int[sc. threads... ]
342
+ want_threads = true
343
+ if sc. threads == Colon ()
344
+ all_threads = true
345
+ nothing
346
+ else
347
+ Int[sc. threads... ]
348
+ end
332
349
else
350
+ all_threads = true
333
351
nothing
334
352
end
335
353
336
354
# Simple cases
355
+ if workers != = nothing && isempty (workers)
356
+ throw (ArgumentError (" Cannot construct scope with workers=[]" ))
357
+ end
358
+ if threads != = nothing && isempty (threads)
359
+ throw (ArgumentError (" Cannot construct scope with threads=[]" ))
360
+ end
337
361
if workers != = nothing && threads != = nothing
338
362
subscopes = AbstractScope[]
339
363
for w in workers, t in threads
340
364
push! (subscopes, ExactScope (ThreadProc (w, t)))
341
365
end
342
366
return simplified_union_scope (subscopes)
343
- elseif workers != = nothing && threads === nothing
344
- subscopes = AbstractScope[ProcessScope (w) for w in workers]
345
- return simplified_union_scope (subscopes)
367
+ end
368
+ if workers != = nothing && threads === nothing
369
+ subscopes = simplified_union_scope (AbstractScope[ProcessScope (w) for w in workers])
370
+ if all_threads
371
+ return constrain (subscopes, ProcessorTypeScope (ThreadProc))
372
+ else
373
+ return subscopes
374
+ end
375
+ end
376
+ if all_threads && want_threads
377
+ if all_workers
378
+ return ProcessorTypeScope (ThreadProc)
379
+ end
380
+ return UnionScope ([ProcessorTypeScope (ThreadProc, ProcessScope (w)) for w in workers])
346
381
end
347
382
348
383
# More complex cases that require querying the cluster
349
384
# FIXME : Use per-field scope taint
350
385
if workers === nothing
351
- workers = procs ()
386
+ workers = map (p -> p . pid, filter (p -> p isa OSProc, procs (Dagger . Sch . eager_context ())) )
352
387
end
353
388
subscopes = AbstractScope[]
354
389
for w in workers
355
- if threads === nothing
356
- threads = map (c-> c. tid,
357
- filter (c-> c isa ThreadProc,
358
- collect (children (OSProc (w)))))
359
- end
360
- for t in threads
361
- push! (subscopes, ExactScope (ThreadProc (w, t)))
390
+ if want_threads
391
+ if threads === nothing
392
+ threads = map (c-> c. tid,
393
+ filter (c-> c isa ThreadProc,
394
+ collect (children (OSProc (w)))))
395
+ end
396
+ for t in threads
397
+ push! (subscopes, ExactScope (ThreadProc (w, t)))
398
+ end
399
+ else
400
+ push! (subscopes, ProcessScope (w))
362
401
end
363
402
end
364
403
return simplified_union_scope (subscopes)
0 commit comments