From 74f9694386c253ecb2a4bcee8ce528cad667c422 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Mon, 20 Oct 2025 14:14:03 -0500 Subject: [PATCH 1/2] for testing multi-thread --- src/RegisterWorkerShell.jl | 19 +++++++++++++++++-- test/runtests.jl | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/runtests.jl diff --git a/src/RegisterWorkerShell.jl b/src/RegisterWorkerShell.jl index 6f834a3..d3667ec 100644 --- a/src/RegisterWorkerShell.jl +++ b/src/RegisterWorkerShell.jl @@ -3,7 +3,7 @@ module RegisterWorkerShell using SimpleTraits, ImageAxes, ImageMetadata, Distributed, SharedArrays using AxisArrays: AxisArray, Axis -export AbstractWorker, AnyValue, ArrayDecl, close!, init!, maybe_sharedarray, monitor, monitor!, worker, workerpid, getindex_t +export AbstractWorker, AnyValue, ArrayDecl, close!, init!, maybe_sharedarray, monitor, monitor_thread, monitor!, worker, workerpid, getindex_t export load_mm_package """ @@ -77,7 +77,22 @@ function monitor(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol},Vecto mon end -monitor(algorithm::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = map(alg->monitor(alg, fields, morevars), algorithm) +function monitor_thread(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol},Vector{Symbol}}, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where N + mon = Dict{Symbol,Any}() + for f in fields + isdefined(algorithm, f) || continue + mon[f] = getfield(algorithm, f) + end + for (k,v) in morevars + mon[k] = v + end + mon +end + +monitor(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = + map(alg->monitor(alg, fields, morevars), algorithms) # for multi-process +monitor_thread(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = + map(alg->monitor_thread(alg, fields, morevars), algorithms) # for multi-thread """ `monitor!(mon, algorithm)` updates `mon` with the current values of diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..94c9506 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,3 @@ +using RegisterWorkerShell, Test + +@test 1+1 == 2 From b03be794664d989a6e97c64e540b488107910987 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Wed, 22 Oct 2025 14:25:38 -0500 Subject: [PATCH 2/2] multi-thread base Apertures --- src/RegisterWorkerShell.jl | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/RegisterWorkerShell.jl b/src/RegisterWorkerShell.jl index d3667ec..7ce6f01 100644 --- a/src/RegisterWorkerShell.jl +++ b/src/RegisterWorkerShell.jl @@ -36,7 +36,7 @@ subtypes. The exported operations are: - `init!` and `close!`: functions you may specialize if your algorithm needs to initialize or clean up resources - `worker`: perform registration on an image - - `workerpid`: extract the process-id for a given worker + - `workertid`: extract the thread-id """ RegisterWorkerShell @@ -58,26 +58,8 @@ The worker algorithm should call `monitor!(mon, algorithm)` to copy the values into `mon`, and `monitor!(mon, :var3, var3)` for an internal variable `var3` that is not taken from `algorithm`. See `monitor!` for more detail. - -An important detail is that if `workerpid(algorithm) ≠ myid()`, then any -requested `AbstractArray` fields in `algorithm` will be turned into -`SharedArray`s for `mon`. This reduces the cost of communication -between the worker and driver processes. """ function monitor(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol},Vector{Symbol}}, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where N - pid = workerpid(algorithm) - mon = Dict{Symbol,Any}() - for f in fields - isdefined(algorithm, f) || continue - mon[f] = maybe_sharedarray(getfield(algorithm, f), pid) - end - for (k,v) in morevars - mon[k] = maybe_sharedarray(v, pid) - end - mon -end - -function monitor_thread(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol},Vector{Symbol}}, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where N mon = Dict{Symbol,Any}() for f in fields isdefined(algorithm, f) || continue @@ -88,11 +70,8 @@ function monitor_thread(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol end mon end - monitor(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = - map(alg->monitor(alg, fields, morevars), algorithms) # for multi-process -monitor_thread(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = - map(alg->monitor_thread(alg, fields, morevars), algorithms) # for multi-thread + map(alg->monitor(alg, fields, morevars), algorithms) # for multi-thread """ `monitor!(mon, algorithm)` updates `mon` with the current values of @@ -165,12 +144,12 @@ worker(algorithm::AbstractWorker, img, tindex, mon) = error("Worker modules must worker(rr::RemoteChannel, img, tindex, mon) = worker(fetch(rr), img, tindex, mon) """ -`workerpid(algorithm)` extracts the `pid` associated with the worker +`workertid(algorithm)` extracts the `workertid` associated with the thread that will be assigned tasks for `algorithm`. All `AbstractWorker` -subtypes should include a `workerpid` field, or overload this function +subtypes should include a `workertid` field, or overload this function to return myid(). """ -workerpid(w::AbstractWorker) = w.workerpid +workertid(w::AbstractWorker) = w.workertid """ `load_mm_package(dev)` loads appropriate mismatch module conditioned on