Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for NaNs and INFs in input to shr_reprosum_calc #1703

Merged
merged 2 commits into from
Aug 9, 2017
Merged
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions cime/src/share/util/shr_reprosum_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module shr_reprosum_mod
use shr_log_mod, only: s_loglev => shr_log_Level
use shr_log_mod, only: s_logunit => shr_log_Unit
use shr_sys_mod, only: shr_sys_abort
use shr_infnan_mod,only: shr_infnan_isnan, shr_infnan_isinf
use perf_mod

!-----------------------------------------------------------------------
Expand Down Expand Up @@ -338,8 +339,14 @@ subroutine shr_reprosum_calc (arr, arr_gsum, nsummands, dsummands, &
logical :: validate ! flag indicating need to
! verify gmax and max_levels
! are accurate/sufficient
integer :: nan_check, inf_check ! flag on whether there are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably meant to be logical :: nan_check, inf_check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - I'll update immediately. My tests still worked though ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just got lucky that assigning logical output to an integer and then testing using the integer gave the same result? At least it was consistent (assignment of logical to integer and evaluating integer as a logical).

! NaNs and INFs in input array

integer :: num_nans, num_infs ! count of NaNs and INFs in
! input array
integer :: omp_nthreads ! number of OpenMP threads
integer :: mpi_comm ! MPI subcommunicator
integer :: mypid ! MPI process ID (COMM_WORLD)
integer :: tasks ! number of MPI processes
integer :: ierr ! MPI error return
integer :: ifld, isum, ithread ! loop variables
Expand Down Expand Up @@ -389,6 +396,38 @@ subroutine shr_reprosum_calc (arr, arr_gsum, nsummands, dsummands, &
!
!-----------------------------------------------------------------------
!
! check whether input contains NaNs or INFs, and abort if so

call t_startf('shr_reprosum_NaN_INF_Chk')
nan_check = .false.
inf_check = .false.
num_nans = 0
num_infs = 0

nan_check = any(shr_infnan_isnan(arr))
inf_check = any(shr_infnan_isinf(arr))
if (nan_check .or. inf_check) then
do ifld=1,nflds
do isum=1,nsummands
if (shr_infnan_isnan(arr(isum,ifld))) then
num_nans = num_nans + 1
endif
if (shr_infnan_isinf(arr(isum,ifld))) then
num_infs = num_infs + 1
endif
end do
end do
endif
call t_stopf('shr_reprosum_NaN_INF_Chk')

if ((num_nans > 0) .or. (num_infs > 0)) then
call mpi_comm_rank(MPI_COMM_WORLD, mypid, ierr)
write(s_logunit,37) real(num_nans,r8), real(num_infs,r8), mypid
37 format("SHR_REPROSUM_CALC: Input contains ",e12.5, &
" NaNs and ", e12.5, " INFs on process ", i7)
call shr_sys_abort("shr_reprosum_calc ERROR: NaNs or INFs in input")
endif

! check whether should use shr_reprosum_ddpdd algorithm
use_ddpdd_sum = repro_sum_use_ddpdd
if ( present(ddpdd_sum) ) then
Expand Down