Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/shared_utilities/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,22 +593,23 @@ function count_nans_state(
mask = nothing,
verbose = false,
)
# Note: this code uses `parent`; this pattern should not be replicated
num_nans = 0
ClimaComms.allowscalar(ClimaComms.device()) do
num_nans =
isnothing(mask) ? Int(sum(isnan.(parent(state)))) :
Int(sum(isnan.(parent(state)) .* parent(mask)))
end
if isapprox(num_nans, 0)
if isnothing(mask)
num_nans = count(isnan, parent(state))
else
num_nans = mapreduce(
(s, m) -> m != 0 && isnan(s),
Base.add_sum,
parent(state),
parent(mask)
)
end
if num_nans == 0
verbose && @info "No NaNs found"
else
@warn "$num_nans NaNs found"
end
return nothing
end


"""
NaNCheckCallback(nancheck_frequency::Union{AbstractFloat, Dates.Period},
start_date, dt)
Expand Down
Loading