Skip to content

Commit

Permalink
Use serial update by default on one thread
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Jun 27, 2024
1 parent 2020e2b commit 23b646c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/nhs_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ struct GridNeighborhoodSearch{NDIMS, update_strategy,
update_strategy = nothing) where {NDIMS}
ELTYPE = typeof(search_radius)

if isnothing(update_strategy)
if isnothing(update_strategy) && Threads.nthreads == 1
# Use serial update on one thread to avoid a second loop over all particles
# when `:parallel` is picked.
update_strategy = :serial
elseif isnothing(update_strategy)
# Automatically choose best available update option for this cell list
update_strategy = first(supported_update_strategies(cell_list))
elseif !(update_strategy in supported_update_strategies(cell_list))
throw(ArgumentError("$update_strategy is not a valid update strategy for " *
Expand Down
14 changes: 10 additions & 4 deletions test/neighborhood_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@
max_corner = maximum(coords, dims = 2) .+ search_radius

neighborhood_searches = [
GridNeighborhoodSearch{NDIMS}(; search_radius, n_points),
GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
# Note that `:semi_parallel` is only the
# default on multiple threads.
update_strategy = :semi_parallel),
GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
update_strategy = :serial),
GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
cell_list = FullGridCellList(; min_corner,
max_corner,
search_radius)),
search_radius),
# Note that `:parallel` is only the
# default on multiple threads.
update_strategy = :parallel),
GridNeighborhoodSearch{NDIMS}(; search_radius, n_points,
cell_list = FullGridCellList(; min_corner,
max_corner,
Expand All @@ -179,9 +185,9 @@
]

names = [
"`GridNeighborhoodSearch`",
"`GridNeighborhoodSearch` with `:semi_parallel` update",
"`GridNeighborhoodSearch` with `:serial` update",
"`GridNeighborhoodSearch` with `FullGridCellList` with `DynamicVectorOfVectors`",
"`GridNeighborhoodSearch` with `FullGridCellList` with `DynamicVectorOfVectors` and `:parallel` update",
"`GridNeighborhoodSearch` with `FullGridCellList` with `DynamicVectorOfVectors` and `:semi_parallel` update",
"`GridNeighborhoodSearch` with `FullGridCellList` with `Vector{Vector}`",
"`PrecomputedNeighborhoodSearch`",
Expand Down

0 comments on commit 23b646c

Please sign in to comment.