Skip to content

Commit 2ec75fc

Browse files
authored
Merge pull request #640 from JuliaParallel/jps/constrain-perf
scopes/Sch: Add optimized check for proc in scope
2 parents 31eafd7 + 6c89712 commit 2ec75fc

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/sch/Sch.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,7 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
11011101
end
11021102
task, occupancy = peek(queue)
11031103
scope = task.scope
1104-
if !isa(constrain(scope, Dagger.ExactScope(to_proc)),
1105-
InvalidScope) &&
1104+
if Dagger.proc_in_scope(to_proc, scope)
11061105
typemax(UInt32) - proc_occupancy_cached >= occupancy
11071106
# Compatible, steal this task
11081107
return dequeue_pair!(queue)

src/sch/util.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ function can_use_proc(state, task, gproc, proc, opts, scope)
447447
end
448448

449449
# Check against scope
450-
proc_scope = Dagger.ExactScope(proc)
451-
if constrain(scope, proc_scope) isa Dagger.InvalidScope
450+
if !Dagger.proc_in_scope(proc, scope)
452451
@dagdebug task :scope "Rejected $proc: Not contained in task scope ($scope)"
453452
return false, scope
454453
end

src/scopes.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ abstract type AbstractScope end
44

55
"Widest scope that contains all processors."
66
struct AnyScope <: AbstractScope end
7+
proc_in_scope(::Processor, ::AnyScope) = true
78

89
abstract type AbstractScopeTaint end
10+
proc_in_scope(proc::Processor, scope::AbstractScope) =
11+
!isa(constrain(scope, ExactScope(proc)), InvalidScope)
912

1013
"Taints a scope for later evaluation."
1114
struct TaintScope <: AbstractScope
@@ -44,6 +47,8 @@ UnionScope(scopes...) = UnionScope((scopes...,))
4447
UnionScope(scopes::Vector{<:AbstractScope}) = UnionScope((scopes...,))
4548
UnionScope(s::AbstractScope) = UnionScope((s,))
4649
UnionScope() = UnionScope(())
50+
proc_in_scope(proc::Processor, scope::UnionScope) =
51+
any(subscope->proc_in_scope(proc, subscope), scope.scopes)
4752

4853
function Base.:(==)(us1::UnionScope, us2::UnionScope)
4954
if length(us1.scopes) != length(us2.scopes)
@@ -78,6 +83,8 @@ function ProcessScope(wid::Integer)
7883
end
7984
ProcessScope(p::OSProc) = ProcessScope(p.pid)
8085
ProcessScope() = ProcessScope(myid())
86+
proc_in_scope(proc::Processor, scope::ProcessScope) =
87+
root_worker_id(proc) == scope.wid
8188

8289
struct ProcessorTypeTaint{T} <: AbstractScopeTaint end
8390

@@ -92,12 +99,14 @@ struct ExactScope <: AbstractScope
9299
processor::Processor
93100
end
94101
ExactScope(proc) = ExactScope(ProcessScope(get_parent(proc).pid), proc)
102+
proc_in_scope(proc::Processor, scope::ExactScope) = proc == scope.processor
95103

96104
"Indicates that the applied scopes `x` and `y` are incompatible."
97105
struct InvalidScope <: AbstractScope
98106
x::AbstractScope
99107
y::AbstractScope
100108
end
109+
proc_in_scope(::Processor, ::InvalidScope) = false
101110

102111
# Show methods
103112

0 commit comments

Comments
 (0)