Skip to content

Commit

Permalink
Fix debug_setup_loop_ranges_split_one_combination()
Browse files Browse the repository at this point in the history
This debug function is meant to emulate `get_best_ranges()`, but only
actually splitting one region type. Previously, it treated all the other
region types as serial regions, but this means that only the rank-0
process in each shared-memory block actually enters any `@loop_*` macro.
However, in `get_best_ranges()` it is only the parallelised dimensions
that get an empty range (of `1:0`) on processes that have no work to do
- for the other (non-parallelised) dimensions every process should loop
over all the points. Treating other region types as serial regions meant
that some code that was correct in non-debug mode failed in debug mode.
This commit fixes this problem, by making every process loop over all
points in the non-parallelised dimensions.
  • Loading branch information
johnomotani committed Nov 26, 2023
1 parent 4bb811e commit cc3e880
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 43 deletions.
12 changes: 10 additions & 2 deletions src/looping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,17 @@ eval(quote
loop_ranges_store[dims] = LoopRanges(;
parallel_dims=dims, rank0 = rank0, ranges...)
else
# Use the same ranges as serial loops
# Loop over all indices for non-parallelised dimensions (dimensions not in
# `dims`), but only loop over parallel dimensions (dimensions in `dims`) on
# rank0.
this_ranges = Dict(d=>1:n for (d,n) in dim_sizes)
if !rank0
for d dims
this_ranges[d] = 1:0
end
end
loop_ranges_store[dims] = LoopRanges(;
parallel_dims=dims, rank0 = rank0, serial_ranges...)
parallel_dims=dims, rank0 = rank0, this_ranges...)
end
end

Expand Down
82 changes: 41 additions & 41 deletions test/loop_setup_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,26 @@ function runtests()
@test loop_ranges_store[()].z == 1:0

@test loop_ranges_store[(:s,)].s == 1:0
@test loop_ranges_store[(:s,)].r == 1:0
@test loop_ranges_store[(:s,)].z == 1:0
@test loop_ranges_store[(:s,)].r == 1:3
@test loop_ranges_store[(:s,)].z == 1:4

@test loop_ranges_store[(:r,)].s == 1:0
@test loop_ranges_store[(:r,)].s == 1:2
@test loop_ranges_store[(:r,)].r == 1:0
@test loop_ranges_store[(:r,)].z == 1:0
@test loop_ranges_store[(:r,)].z == 1:4

@test loop_ranges_store[(:z,)].s == 1:0
@test loop_ranges_store[(:z,)].r == 1:0
@test loop_ranges_store[(:z,)].s == 1:2
@test loop_ranges_store[(:z,)].r == 1:3
@test loop_ranges_store[(:z,)].z == 1:0

@test loop_ranges_store[(:s,:r)].s == 1:0
@test loop_ranges_store[(:s,:r)].r == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:4

@test loop_ranges_store[(:s,:z)].s == 2:2
@test loop_ranges_store[(:s,:z)].r == 1:3
@test loop_ranges_store[(:s,:z)].z == 1:4

@test loop_ranges_store[(:r,:z)].s == 1:0
@test loop_ranges_store[(:r,:z)].s == 1:2
@test loop_ranges_store[(:r,:z)].r == 1:0
@test loop_ranges_store[(:r,:z)].z == 1:0

Expand Down Expand Up @@ -269,23 +269,23 @@ function runtests()
@test loop_ranges_store[()].z == 1:0

@test loop_ranges_store[(:s,)].s == 1:0
@test loop_ranges_store[(:s,)].r == 1:0
@test loop_ranges_store[(:s,)].z == 1:0
@test loop_ranges_store[(:s,)].r == 1:3
@test loop_ranges_store[(:s,)].z == 1:4

@test loop_ranges_store[(:r,)].s == 1:0
@test loop_ranges_store[(:r,)].s == 1:2
@test loop_ranges_store[(:r,)].r == 1:0
@test loop_ranges_store[(:r,)].z == 1:0
@test loop_ranges_store[(:r,)].z == 1:4

@test loop_ranges_store[(:z,)].s == 1:0
@test loop_ranges_store[(:z,)].r == 1:0
@test loop_ranges_store[(:z,)].s == 1:2
@test loop_ranges_store[(:z,)].r == 1:3
@test loop_ranges_store[(:z,)].z == 1:0

@test loop_ranges_store[(:s,:r)].s == 1:0
@test loop_ranges_store[(:s,:r)].r == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:4

@test loop_ranges_store[(:s,:z)].s == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:3
@test loop_ranges_store[(:s,:z)].z == 1:0

@test loop_ranges_store[(:r,:z)].s == 1:2
Expand All @@ -305,23 +305,23 @@ function runtests()
@test loop_ranges_store[()].z == 1:0

@test loop_ranges_store[(:s,)].s == 1:0
@test loop_ranges_store[(:s,)].r == 1:0
@test loop_ranges_store[(:s,)].z == 1:0
@test loop_ranges_store[(:s,)].r == 1:3
@test loop_ranges_store[(:s,)].z == 1:4

@test loop_ranges_store[(:r,)].s == 1:0
@test loop_ranges_store[(:r,)].s == 1:2
@test loop_ranges_store[(:r,)].r == 1:0
@test loop_ranges_store[(:r,)].z == 1:0
@test loop_ranges_store[(:r,)].z == 1:4

@test loop_ranges_store[(:z,)].s == 1:0
@test loop_ranges_store[(:z,)].r == 1:0
@test loop_ranges_store[(:z,)].s == 1:2
@test loop_ranges_store[(:z,)].r == 1:3
@test loop_ranges_store[(:z,)].z == 1:0

@test loop_ranges_store[(:s,:r)].s == 1:0
@test loop_ranges_store[(:s,:r)].r == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:4

@test loop_ranges_store[(:s,:z)].s == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:3
@test loop_ranges_store[(:s,:z)].z == 1:0

@test loop_ranges_store[(:r,:z)].s == 1:2
Expand All @@ -341,23 +341,23 @@ function runtests()
@test loop_ranges_store[()].z == 1:0

@test loop_ranges_store[(:s,)].s == 1:0
@test loop_ranges_store[(:s,)].r == 1:0
@test loop_ranges_store[(:s,)].z == 1:0
@test loop_ranges_store[(:s,)].r == 1:3
@test loop_ranges_store[(:s,)].z == 1:4

@test loop_ranges_store[(:r,)].s == 1:0
@test loop_ranges_store[(:r,)].s == 1:2
@test loop_ranges_store[(:r,)].r == 1:0
@test loop_ranges_store[(:r,)].z == 1:0
@test loop_ranges_store[(:r,)].z == 1:4

@test loop_ranges_store[(:z,)].s == 1:0
@test loop_ranges_store[(:z,)].r == 1:0
@test loop_ranges_store[(:z,)].s == 1:2
@test loop_ranges_store[(:z,)].r == 1:3
@test loop_ranges_store[(:z,)].z == 1:0

@test loop_ranges_store[(:s,:r)].s == 1:0
@test loop_ranges_store[(:s,:r)].r == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:4

@test loop_ranges_store[(:s,:z)].s == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:3
@test loop_ranges_store[(:s,:z)].z == 1:0

@test loop_ranges_store[(:r,:z)].s == 1:2
Expand All @@ -377,26 +377,26 @@ function runtests()
@test loop_ranges_store[()].z == 1:0

@test loop_ranges_store[(:s,)].s == 1:0
@test loop_ranges_store[(:s,)].r == 1:0
@test loop_ranges_store[(:s,)].z == 1:0
@test loop_ranges_store[(:s,)].r == 1:3
@test loop_ranges_store[(:s,)].z == 1:4

@test loop_ranges_store[(:r,)].s == 1:0
@test loop_ranges_store[(:r,)].s == 1:2
@test loop_ranges_store[(:r,)].r == 1:0
@test loop_ranges_store[(:r,)].z == 1:0
@test loop_ranges_store[(:r,)].z == 1:4

@test loop_ranges_store[(:z,)].s == 1:0
@test loop_ranges_store[(:z,)].r == 1:0
@test loop_ranges_store[(:z,)].s == 1:2
@test loop_ranges_store[(:z,)].r == 1:3
@test loop_ranges_store[(:z,)].z == 1:0

@test loop_ranges_store[(:s,:r)].s == 1:0
@test loop_ranges_store[(:s,:r)].r == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:0
@test loop_ranges_store[(:s,:r)].z == 1:4

@test loop_ranges_store[(:s,:z)].s == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:0
@test loop_ranges_store[(:s,:z)].r == 1:3
@test loop_ranges_store[(:s,:z)].z == 1:0

@test loop_ranges_store[(:r,:z)].s == 1:0
@test loop_ranges_store[(:r,:z)].s == 1:2
@test loop_ranges_store[(:r,:z)].r == 1:0
@test loop_ranges_store[(:r,:z)].z == 1:0

Expand Down

0 comments on commit cc3e880

Please sign in to comment.