Skip to content

Commit 3689e07

Browse files
reenable tests
1 parent 767d575 commit 3689e07

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

src/DistributedComputations/distributed_fields.jl

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
using Oceananigans.Grids: topology
22
using Oceananigans.Fields: validate_field_data, indices, validate_boundary_conditions
33
using Oceananigans.Fields: validate_indices, set_to_array!, set_to_field!
4+
using CUDA: @allowscalar
5+
6+
using Oceananigans.Fields: ReducedAbstractField,
7+
get_neutral_mask,
8+
condition_operand,
9+
initialize_reduced_field!,
10+
filltype,
11+
reduced_dimensions,
12+
reduced_location
413

514
import Oceananigans.Fields: Field, location, set!
615
import Oceananigans.BoundaryConditions: fill_halo_regions!
@@ -95,63 +104,66 @@ function reconstruct_global_field(field::DistributedField)
95104
return global_field
96105
end
97106

98-
function maybe_all_reduce!(op, f::ReducedDistributedField, dims)
99-
reduced_dims = reduced_dimensions(f)
107+
partition_dimensions(f::DistributedField) = partition_dimensions(architecture(f))
108+
function partition_dimensions(arch::Distributed)
109+
R = ranks(arch)
110+
dims = []
111+
for r in eachindex(R)
112+
if R[r] > 1
113+
push!(dims, r)
114+
end
115+
end
116+
return tuple(dims...)
117+
end
118+
119+
function maybe_all_reduce!(op, f::ReducedAbstractField)
120+
reduced_dims = reduced_dimensions(f)
121+
partition_dims = partition_dimensions(f)
100122

101-
if any(reduced_dims .∈ tuple(dims...))
123+
if any([dim partition_dims for dim in reduced_dims])
102124
all_reduce!(op, interior(f), architecture(f))
103125
end
104126

105127
return f
106128
end
107129

108-
function maybe_all_reduce!(op, f::ReducedDistributedField, ::Colon)
109-
all_reduce!(op, interior(f), architecture(f))
110-
return f
111-
end
112-
113130
# Allocating and in-place reductions
114131
for (reduction, all_reduce_op) in zip((:sum, :maximum, :minimum, :all, :any, :prod),
115-
( +, max, min, &, |, *))
132+
(:+, :max, :min, :&, :|, :*))
116133

117134
reduction! = Symbol(reduction, '!')
118135

119136
@eval begin
120-
121137
# In-place
122138
function Base.$(reduction!)(f::Function,
123139
r::ReducedAbstractField,
124140
a::DistributedField;
125141
condition = nothing,
126142
mask = get_neutral_mask(Base.$(reduction!)),
127-
dims = :,
128143
kwargs...)
129144

130145
operand = condition_operand(f, a, condition, mask)
131146

132147
Base.$(reduction!)(identity,
133148
interior(r),
134149
operand;
135-
dims,
136150
kwargs...)
137151

138-
return maybe_all_reduce!(all_reduce_op, r, dims)
152+
return maybe_all_reduce!($(all_reduce_op), r)
139153
end
140154

141155
function Base.$(reduction!)(r::ReducedAbstractField,
142156
a::DistributedField;
143157
condition = nothing,
144158
mask = get_neutral_mask(Base.$(reduction!)),
145-
dims = :,
146159
kwargs...)
147160

148161
Base.$(reduction!)(identity,
149162
interior(r),
150163
condition_operand(a, condition, mask);
151-
dims,
152164
kwargs...)
153165

154-
return maybe_all_reduce!(all_reduce_op, r, dims)
166+
return maybe_all_reduce!($(all_reduce_op), r)
155167
end
156168

157169
# Allocating
@@ -168,10 +180,10 @@ for (reduction, all_reduce_op) in zip((:sum, :maximum, :minimum, :all, :any, :pr
168180
initialize_reduced_field!(Base.$(reduction!), identity, r, conditioned_c)
169181
Base.$(reduction!)(identity, interior(r), conditioned_c, init=false)
170182

171-
maybe_all_reduce!(all_reduce_op, r, dims)
183+
maybe_all_reduce!($(all_reduce_op), r)
172184

173185
if dims isa Colon
174-
return CUDA.@allowscalar first(r)
186+
return @allowscalar first(r)
175187
else
176188
return r
177189
end

test/test_distributed_models.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ end
408408

409409
@testset "Distributed MPI Oceananigans" begin
410410
@info "Testing distributed MPI Oceananigans..."
411-
#=
412411
@testset "Multi architectures rank connectivity" begin
413412
@info " Testing multi architecture rank connectivity..."
414413
test_triply_periodic_rank_connectivity_with_411_ranks()
@@ -462,7 +461,7 @@ end
462461
@test child_architecture(architecture(cpuosg)) == CPU()
463462
end
464463
end
465-
=#
464+
466465
@testset "Distributed reductions" begin
467466
child_arch = get(ENV, "TEST_ARCHITECTURE", "CPU") == "GPU" ? GPU() : CPU()
468467

@@ -479,11 +478,24 @@ end
479478
@test sum(c) == 1*N + 2*N + 3*N + 4*N
480479

481480
sum!(c_reduced, c)
482-
@test CUDA.@allowscalar c_reduced.data[1, 1, 1] == 1*N + 2*N + 3*N + 4*N
481+
@test CUDA.@allowscalar c_reduced[1, 1, 1] == 1*N + 2*N + 3*N + 4*N
482+
483+
cbool = CenterField(grid, Bool)
484+
cbool_reduced = Field{Nothing, Nothing, Nothing}(grid, Bool)
485+
bool_val = arch.local_rank == 0 ? true : false
486+
set!(cbool, bool_val)
487+
488+
@test any(cbool) == true
489+
@test all(cbool) == false
490+
491+
any!(cbool_reduced, cbool)
492+
@test CUDA.@allowscalar cbool_reduced[1, 1, 1] == true
493+
494+
all!(cbool_reduced, cbool)
495+
@test CUDA.@allowscalar cbool_reduced[1, 1, 1] == false
483496
end
484497
end
485498

486-
#=
487499
# Only test on CPU because we do not have a GPU pressure solver yet
488500
@testset "Time stepping NonhydrostaticModel" begin
489501
child_arch = get(ENV, "TEST_ARCHITECTURE", "CPU") == "GPU" ? GPU() : CPU()
@@ -521,6 +533,5 @@ end
521533
@test model isa ShallowWaterModel
522534
@test model.clock.time 2
523535
end
524-
=#
525536
end
526537

0 commit comments

Comments
 (0)