Skip to content

Commit

Permalink
Merge pull request #150 from PALEOtoolkit/thread_barrier_fix
Browse files Browse the repository at this point in the history
Thread barriers can now specify operatorIDs
  • Loading branch information
sjdaines authored Dec 22, 2024
2 parents 92739dc + 411263f commit ade7339
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1090,31 +1090,37 @@ function get_tiled_cellranges(model::PB.Model, ntiles::Int, interior_domain_name
interior_domain = PB.get_domain(model, interior_domain_name)
interior_cellranges = cellrange_cartesiantile(interior_domain, interior_domain.grid, ntiles, operatorID=operatorID)

io = IOBuffer()
println(io, "get_tiled_cellranges:")

cellranges = [] # vector of vectors, 1 per tile
for it in 1:ntiles
println("creating CellRanges for tile $it")
println(io, " creating CellRanges for tile $it")
tcellranges = []
push!(tcellranges, interior_cellranges[it])
for dom in model.domains
if !isnothing(dom.grid) && dom != interior_domain
push!(tcellranges, cellrange_from_columns(dom, dom.grid, interior_cellranges[it]))
println(" add CellRange for domain $(dom.name) length $(length(last(tcellranges).indices))")
println(io, " add CellRange for domain $(dom.name) length $(length(last(tcellranges).indices))")
end
end
push!(cellranges, tcellranges)
end
# create cellranges for scalar Domains
cellrangesscalar = []
@info "creating CellRanges for scalar domains"
println(io, " creating CellRanges for scalar domains")
for dom in model.domains
if isnothing(dom.grid)
push!(cellrangesscalar, create_default_cellrange(dom, dom.grid, operatorID=operatorID))
@info " added CellRange for scalar domain $(dom.name)"
println(io, " added CellRange for scalar domain $(dom.name)")
end
end
@info "adding CellRanges for scalar domains to first tile"
println(io, " adding CellRanges for scalar domains to first tile")

append!(first(cellranges), cellrangesscalar)

@info String(take!(io))

return cellranges
end

Expand Down
4 changes: 3 additions & 1 deletion src/Model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ end

function _dispatch_cellranges(@nospecialize(method::AbstractReactionMethod), cellranges)
if is_do_barrier(method)
return (nothing, )
operatorID = method.operatorID
any_cellranges = any((cr.operatorID == 0 || cr.operatorID in operatorID) for cr in cellranges)
return any_cellranges ? (nothing, ) : ()
else
domain = method.domain
operatorID = method.operatorID
Expand Down
6 changes: 3 additions & 3 deletions src/reactionmethods/SetupInitializeUtilityMethods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ function do_method_barrier(m::ReactionMethod, _, _, _)
end

"""
reaction_method_thread_barrier(barrier)
reaction_method_thread_barrier(barrier, barrierfn; [operatorID=[1]])
Create a ReactionMethod holding a thread barrier `barrier`.
"""
function reaction_method_thread_barrier(barrier, barrierfn)
function reaction_method_thread_barrier(barrier, barrierfn; operatorID=[1])

return ReactionMethod(
do_method_barrier,
NoReaction(),
"thread_barrier",
(VarList_nothing(),),
(barrier, barrierfn), # p
[-1],
operatorID,
Domain(name="thread_barrier", ID=-1, parameters=Dict{String, Any}()),
)
end
Expand Down

0 comments on commit ade7339

Please sign in to comment.