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

Add check for nans config option #386

Merged
merged 15 commits into from
May 24, 2023
39 changes: 34 additions & 5 deletions .github/workflows/extbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ jobs:
FC: mpifort
CXX: mpicxx
CPPFLAGS: "-I/usr/include -I/usr/local/include"

# Versions of all dependencies can be updated here
ESMF_VERSION: v8.4.0
ESMF_VERSION: v8.4.2
PNETCDF_VERSION: checkpoint.1.12.3
NETCDF_FORTRAN_VERSION: v4.6.0
PIO_VERSION: pio2_5_10
PIO_VERSION: pio2_6_0
CDEPS_VERSION: cdeps1.0.15
steps:
- uses: actions/checkout@v3
# Build the ESMF library, if the cache contains a previous build
Expand Down Expand Up @@ -50,14 +52,14 @@ jobs:
key: ${{ runner.os }}-${{ env.PIO_VERSION }}.pio
- name: Build ParallelIO
if: steps.cache-ParallelIO.outputs.cache-hit != 'true'
uses: NCAR/ParallelIO/.github/actions/parallelio_cmake@9390e30e29d4ebbfbef0fc72162cacd9e8f25e4e
uses: NCAR/ParallelIO/.github/actions/parallelio_cmake@pio2_6_0
with:
parallelio_version: ${{ env.ParallelIO_VERSION }}
enable_fortran: True
install_prefix: $HOME/pio
- name: Build ESMF
if: steps.cache-esmf.outputs.cache-hit != 'true'
uses: ESCOMP/CDEPS/.github/actions/buildesmf@e06246b560d3132170bb1a5443fa3d65dfbd2040
uses: ESCOMP/CDEPS/.github/actions/buildesmf@cdeps1.0.15
with:
esmf_version: ${{ env.ESMF_VERSION }}
esmf_bopt: g
Expand All @@ -67,12 +69,39 @@ jobs:
netcdf_fortran_path: /usr
pnetcdf_path: /usr
parallelio_path: $HOME/pio
- name: Cache CDEPS
id: cache-cdeps
uses: actions/cache@v3
with:
path: $HOME/cdeps
key: ${{ runner.os }}-${{ env.CDEPS_VERSION }}.cdeps

- name: checkout CDEPS
uses: actions/checkout@v3
with:
repository: ESCOMP/CDEPS
path: cdeps-src
ref: ${{ env.CDEPS_VERSION }}
- name: Build CDEPS
if: steps.cache-cdeps.outputs.cache-hit != 'true'
uses: ESCOMP/CDEPS/.github/actions/buildcdeps@cdeps1.0.15
with:
esmfmkfile: $HOME/ESMF/lib/libg/Linux.gfortran.64.openmpi.default/esmf.mk
pio_path: $HOME/pio
src_root: ${GITHUB_WORKSPACE}/cdeps-src
cmake_flags: " -Wno-dev -DCMAKE_BUILD_TYPE=DEBUG -DWERROR=ON -DCMAKE_Fortran_FLAGS=\"-DCPRGNU -g -Wall \
-ffree-form -ffree-line-length-none -fallow-argument-mismatch \""

- name: Build CMEPS
run: |
export ESMFMKFILE=$HOME/ESMF/lib/libg/Linux.gfortran.64.openmpi.default/esmf.mk
export PIO=$HOME/pio
mkdir build-cmeps
pushd build-cmeps
cmake -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_Fortran_FLAGS="-g -Wall -Werror -ffree-form -ffree-line-length-none -Wno-unused-dummy-argument" ../
cmake -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_Fortran_FLAGS="-g -Wall -Werror -ffree-form -ffree-line-length-none -Wno-unused-dummy-argument -I /home/runner/work/CMEPS/CMEPS/build-cdeps/share" ../
make VERBOSE=1
popd

- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
11 changes: 11 additions & 0 deletions cime_config/namelist_definition_drv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,17 @@
<value>$ESMF_VERBOSITY_LEVEL</value>
</values>
</entry>
<entry id="check_for_nans">
<type>logical</type>
<category>performance</category>
<group>MED_attributes</group>
<desc>
Check for NaN values in fields returned from mediator to components. This has a small performance impact.
</desc>
<values>
<value>.true.</value>
</values>
</entry>
<entry id="atm_nx" modify_via_xml="ATM_NX">
<type>integer</type>
<category>control</category>
Expand Down
19 changes: 19 additions & 0 deletions mediator/med.F90
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ subroutine AdvertiseFields(gcomp, importState, exportState, clock, rc)
use NUOPC , only : NUOPC_CompAttributeGet, NUOPC_CompAttributeSet, NUOPC_CompAttributeAdd
use esmFlds, only : med_fldlist_init1, med_fld_GetFldInfo, med_fldList_entry_type
use med_phases_history_mod, only : med_phases_history_init
use med_methods_mod , only : mediator_checkfornans

! input/output variables
type(ESMF_GridComp) :: gcomp
Expand Down Expand Up @@ -916,6 +917,24 @@ subroutine AdvertiseFields(gcomp, importState, exportState, clock, rc)
end if
end do ! end of ncomps loop

! Should mediator check for NaNs?
call NUOPC_CompAttributeGet(gcomp, name="check_for_nans", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if(isPresent .and. isSet) then
read(cvalue, *) mediator_checkfornans
else
mediator_checkfornans = .false.
endif
if(maintask) then
write(logunit,*) ' check_for_nans is ',mediator_checkfornans
if(mediator_checkfornans) then
write(logunit,*) ' Fields will be checked for NaN values when passed from mediator to component'
else
write(logunit,*) ' Fields will NOT be checked for NaN values when passed from mediator to component'
endif
endif


if (profile_memory) call ESMF_VMLogMemInfo("Leaving "//trim(subname))
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)

Expand Down
41 changes: 7 additions & 34 deletions mediator/med_methods_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module med_methods_mod
end interface med_methods_check_for_nans

! used/reused in module

logical, public :: mediator_checkfornans ! set in med.F90 AdvertiseFields
logical :: isPresent
character(len=1024) :: msgString
type(ESMF_FieldStatus_Flag) :: status
Expand Down Expand Up @@ -2506,12 +2506,12 @@ subroutine med_methods_FB_getmesh(FB, mesh, rc)
end subroutine med_methods_FB_getmesh

!-----------------------------------------------------------------------------
subroutine med_methods_FB_check_for_nans(FB, rc)

use ESMF, only : ESMF_FieldBundle, ESMF_Field, ESMF_FieldBundleGet, ESMF_FieldGet

subroutine med_methods_FB_check_for_nans(FB, maintask, logunit, rc)
use ESMF, only : ESMF_FieldBundle, ESMF_Field, ESMF_FieldBundleGet, ESMF_FieldGet
! input/output variables
type(ESMF_FieldBundle) , intent(in) :: FB
logical , intent(in) :: maintask
integer , intent(in) :: logunit
integer , intent(inout) :: rc

! local variables
Expand All @@ -2530,11 +2530,8 @@ subroutine med_methods_FB_check_for_nans(FB, rc)
! ----------------------------------------------
rc = ESMF_SUCCESS

#ifndef CESMCOUPLED
! For now only CESM uses shr_infnan_isnan - so until other models provide this
RETURN
#endif

if(.not. mediator_checkfornans) return

call ESMF_FieldBundleGet(FB, fieldCount=fieldCount, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

Expand Down Expand Up @@ -2571,8 +2568,6 @@ subroutine med_methods_FB_check_for_nans(FB, rc)
end subroutine med_methods_FB_check_for_nans

!-----------------------------------------------------------------------------
#ifdef CESMCOUPLED

subroutine med_methods_check_for_nans_1d(dataptr, nancount)
use shr_infnan_mod, only: shr_infnan_isnan
! input/output variables
Expand Down Expand Up @@ -2607,26 +2602,4 @@ subroutine med_methods_check_for_nans_2d(dataptr, nancount)
end do
end subroutine med_methods_check_for_nans_2d

#else

! For now only CESM uses shr_infnan_isnan - so until other models provide this
! nancount will just be set to zero

subroutine med_methods_check_for_nans_1d(dataptr, nancount)
! input/output variables
real(r8) , intent(in) :: dataptr(:)
integer , intent(out) :: nancount

nancount = 0
end subroutine med_methods_check_for_nans_1d

subroutine med_methods_check_for_nans_2d(dataptr, nancount)
! input/output variables
real(r8) , intent(in) :: dataptr(:,:)
integer , intent(out) :: nancount

nancount = 0
end subroutine med_methods_check_for_nans_2d
#endif

end module med_methods_mod
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_atm_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module med_phases_prep_atm_mod
use med_methods_mod , only : FB_check_for_nans => med_methods_FB_check_for_nans
use med_merge_mod , only : med_merge_auto
use med_map_mod , only : med_map_field_packed
use med_internalstate_mod , only : InternalState, maintask
use med_internalstate_mod , only : InternalState, maintask, logunit
use med_internalstate_mod , only : compatm, compocn, compice, compname, coupling_mode
use esmFlds , only : med_fldlist_GetfldListTo, med_fldlist_type
use perf_mod , only : t_startf, t_stopf
Expand Down Expand Up @@ -245,7 +245,7 @@ subroutine med_phases_prep_atm(gcomp, rc)
end if

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(compatm), rc=rc)
call FB_check_for_nans(is_local%wrap%FBExp(compatm), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (dbug_flag > 5) then
Expand Down
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_glc_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ subroutine med_phases_prep_glc_avg(gcomp, rc)
endif
end if

! Check for nans in fields export to atm
! Check for nans in fields export to glc
do ns = 1,is_local%wrap%num_icesheets
call FB_check_for_nans(is_local%wrap%FBExp(compglc(ns)), rc=rc)
call FB_check_for_nans(is_local%wrap%FBExp(compglc(ns)), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end do

Expand Down
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_ice_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ subroutine med_phases_prep_ice(gcomp, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(compice), rc=rc)
! Check for nans in fields export to ice
call FB_check_for_nans(is_local%wrap%FBExp(compice), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (dbug_flag > 5) then
Expand Down
6 changes: 3 additions & 3 deletions mediator/med_phases_prep_lnd_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ subroutine med_phases_prep_lnd(gcomp, rc)
use med_utils_mod , only : chkerr => med_utils_ChkErr
use med_constants_mod , only : dbug_flag => med_constants_dbug_flag
use med_internalstate_mod , only : complnd, compatm
use med_internalstate_mod , only : InternalState, maintask
use med_internalstate_mod , only : InternalState, maintask, logunit
use med_merge_mod , only : med_merge_auto
use perf_mod , only : t_startf, t_stopf

Expand Down Expand Up @@ -128,8 +128,8 @@ subroutine med_phases_prep_lnd(gcomp, rc)
! Set first call logical to false
first_call = .false.

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(complnd), rc=rc)
! Check for nans in fields export to lnd
call FB_check_for_nans(is_local%wrap%FBExp(complnd), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (dbug_flag > 5) then
Expand Down
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_ocn_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ subroutine med_phases_prep_ocn_avg(gcomp, rc)
call FB_copy(is_local%wrap%FBExp(compocn), is_local%wrap%FBExpAccumOcn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(compocn), rc=rc)
! Check for nans in fields export to ocn
call FB_check_for_nans(is_local%wrap%FBExp(compocn), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! zero accumulator
Expand Down
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_rof_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ subroutine med_phases_prep_rof(gcomp, rc)
FBfrac=is_local%wrap%FBFrac(comprof), FBin=FBlndAccum2rof_r, fldListTo=fldList, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(comprof), rc=rc)
! Check for nans in fields export to rof
call FB_check_for_nans(is_local%wrap%FBExp(comprof), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (dbug_flag > 1) then
Expand Down
4 changes: 2 additions & 2 deletions mediator/med_phases_prep_wav_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ subroutine med_phases_prep_wav_avg(gcomp, rc)
call FB_copy(is_local%wrap%FBExp(compwav), is_local%wrap%FBExpAccumWav, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! Check for nans in fields export to atm
call FB_check_for_nans(is_local%wrap%FBExp(compwav), rc=rc)
! Check for nans in fields export to wav
call FB_check_for_nans(is_local%wrap%FBExp(compwav), maintask, logunit, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! zero accumulator
Expand Down