From 37363ad6efc536da25e415cbc7686f282aeb5582 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 16 Jul 2020 14:44:26 -0500 Subject: [PATCH 1/8] remove perf_mod dependancy --- datm/atm_comp_nuopc.F90 | 30 +++++++++++------------- dice/ice_comp_nuopc.F90 | 29 +++++++++++------------ dlnd/lnd_comp_nuopc.F90 | 27 ++++++++++------------ docn/ocn_comp_nuopc.F90 | 18 +++++++-------- drof/rof_comp_nuopc.F90 | 23 ++++++++---------- dshr/dshr_mod.F90 | 1 - dwav/wav_comp_nuopc.F90 | 29 +++++++++++------------ streams/dshr_methods_mod.F90 | 5 ++-- streams/dshr_strdata_mod.F90 | 45 ++++++++++++++++++------------------ 9 files changed, 96 insertions(+), 111 deletions(-) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index f2ad7af196..a52fe96586 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -26,8 +26,6 @@ module atm_comp_nuopc use dshr_mod , only : dshr_orbital_init, dshr_orbital_update use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize - use perf_mod , only : t_startf, t_stopf, t_barrierf - use datm_datamode_core2_mod , only : datm_datamode_core2_advertise use datm_datamode_core2_mod , only : datm_datamode_core2_init_pointers use datm_datamode_core2_mod , only : datm_datamode_core2_advance @@ -344,7 +342,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO) ! Initialize mesh, restart flag, compid, and logunit - call t_startf('datm_strdata_init') + call ESMF_TraceRegionEnter('datm_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'ATM', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -354,7 +352,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) xmlfilename = 'datm.streams'//trim(inst_suffix)//'.xml' call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'ATM', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('datm_strdata_init') + call ESMF_TraceRegionExit('datm_strdata_init') ! NUOPC_Realize "realizes" a previously advertised field in the importState and exportState ! by replacing the advertised fields with the newly created fields of the same name. @@ -440,7 +438,7 @@ subroutine ModelAdvance(gcomp, rc) rc = ESMF_SUCCESS - call t_startf(subname) + call ESMF_TraceRegionEnter(subname) call memcheck(subname, 5, my_task==master_task) ! Query the Component for its clock, importState and exportState @@ -475,11 +473,11 @@ subroutine ModelAdvance(gcomp, rc) endif ! Run datm - call t_startf('datm_run') + call ESMF_TraceRegionEnter('datm_run') call datm_comp_run(importstate, exportstate, next_ymd, next_tod, mon, & orbEccen, orbMvelpp, orbLambm0, orbObliqr, restart_write, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('datm_run') + call ESMF_TraceRegionExit('datm_run') ! Update nextsw_cday for scalar data ! Use nextYMD and nextTOD here since since the component - clock is advance at the END of the time interval @@ -487,7 +485,7 @@ subroutine ModelAdvance(gcomp, rc) call dshr_state_SetScalar(nextsw_cday, flds_scalar_index_nextsw_cday, exportState, flds_scalar_name, flds_scalar_num, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf(subname) + call ESMF_TraceRegionExit(subname) end subroutine ModelAdvance @@ -519,7 +517,7 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe rc = ESMF_SUCCESS - call t_startf('DATM_RUN') + call ESMF_TraceRegionEnter('DATM_RUN') !-------------------- ! First time initialization @@ -574,21 +572,21 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe ! time and spatially interpolate to model time and grid call t_barrierf('datm_BARRIER',mpicom) - call t_startf('datm_strdata_advance') + call ESMF_TraceRegionEnter('datm_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'datm', rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('datm_strdata_advance') + call ESMF_TraceRegionExit('datm_strdata_advance') ! copy all fields from streams to export state as default ! This automatically will update the fields in the export state call t_barrierf('datm_comp_dfield_copy_BARRIER', mpicom) - call t_startf('datm_dfield_copy') + call ESMF_TraceRegionEnter('datm_dfield_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('datm_dfield_copy') + call ESMF_TraceRegionExit('datm_dfield_copy') ! Determine data model behavior based on the mode - call t_startf('datm_datamode') + call ESMF_TraceRegionEnter('datm_datamode') select case (trim(datamode)) case('CORE2_NYF','CORE2_IAF') call datm_datamode_core2_advance(exportstate, datamode, target_ymd, target_tod, target_mon, & @@ -637,8 +635,8 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call t_stopf('datm_datamode') - call t_stopf('DATM_RUN') + call ESMF_TraceRegionExit('datm_datamode') + call ESMF_TraceRegionExit('DATM_RUN') !-------- contains diff --git a/dice/ice_comp_nuopc.F90 b/dice/ice_comp_nuopc.F90 index ce11df8505..55df6a81c9 100644 --- a/dice/ice_comp_nuopc.F90 +++ b/dice/ice_comp_nuopc.F90 @@ -23,7 +23,6 @@ module ice_comp_nuopc use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_init_from_xml, shr_strdata_advance use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf use dice_datamode_ssmi_mod , only : dice_datamode_ssmi_advertise use dice_datamode_ssmi_mod , only : dice_datamode_ssmi_init_pointers @@ -296,7 +295,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) rc = ESMF_SUCCESS ! Initialize mesh, restart flag, logunit - call t_startf('dice_strdata_init') + call ESMF_TraceRegionEnter('dice_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'ICE', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -306,7 +305,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) xmlfilename = 'dice.streams'//trim(inst_suffix)//'.xml' call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'ICE', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dice_strdata_init') + call ESMF_TraceRegionExit('dice_strdata_init') ! NUOPC_Realize "realizes" a previously advertised field in the importState and exportState ! by replacing the advertised fields with the newly created fields of the same name. @@ -375,7 +374,7 @@ subroutine ModelAdvance(gcomp, rc) rc = ESMF_SUCCESS - call t_startf(subname) + call ESMF_TraceRegionEnter(subname) call memcheck(subname, 5, my_task == master_task) ! Query the Component for its clock, importState and exportState @@ -413,7 +412,7 @@ subroutine ModelAdvance(gcomp, rc) call dice_comp_run(importState, exportState, next_ymd, next_tod, cosarg, restart_write, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf(subname) + call ESMF_TraceRegionExit(subname) end subroutine ModelAdvance @@ -440,7 +439,7 @@ subroutine dice_comp_run(importstate, exportstate, target_ymd, target_tod, cosar rc = ESMF_SUCCESS - call t_startf('DICE_RUN') + call ESMF_TraceRegionEnter('DICE_RUN') !-------------------- ! first time initialization @@ -477,27 +476,27 @@ subroutine dice_comp_run(importstate, exportstate, target_ymd, target_tod, cosar !-------------------- ! time and spatially interpolate to model time and grid - call t_barrierf('dice_BARRIER',mpicom) - call t_startf('dice_strdata_advance') + + call ESMF_TraceRegionEnter('dice_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'dice', rc=rc) - call t_stopf('dice_strdata_advance') + call ESMF_TraceRegionExit('dice_strdata_advance') !-------------------- ! copy all fields from streams to export state as default !-------------------- ! This automatically will update the fields in the export state - call t_barrierf('dice_comp_dfield_copy_BARRIER', mpicom) - call t_startf('dice_dfield_copy') + + call ESMF_TraceRegionEnter('dice_dfield_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dice_dfield_copy') + call ESMF_TraceRegionExit('dice_dfield_copy') !------------------------------------------------- ! Determine data model behavior based on the mode !------------------------------------------------- - call t_startf('dice_datamode') + call ESMF_TraceRegionEnter('dice_datamode') ! Perform data mode specific calculations select case (trim(datamode)) @@ -523,8 +522,8 @@ subroutine dice_comp_run(importstate, exportstate, target_ymd, target_tod, cosar if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call t_stopf('dice_datamode') - call t_stopf('DICE_RUN') + call ESMF_TraceRegionExit('dice_datamode') + call ESMF_TraceRegionExit('DICE_RUN') end subroutine dice_comp_run diff --git a/dlnd/lnd_comp_nuopc.F90 b/dlnd/lnd_comp_nuopc.F90 index 6d86145dfc..1354b3d11d 100644 --- a/dlnd/lnd_comp_nuopc.F90 +++ b/dlnd/lnd_comp_nuopc.F90 @@ -25,7 +25,6 @@ module lnd_comp_nuopc use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize use glc_elevclass_mod , only : glc_elevclass_as_string, glc_elevclass_init - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf implicit none private ! except @@ -279,7 +278,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) rc = ESMF_SUCCESS ! Initialize sdat - call t_startf('dlnd_strdata_init') + call ESMF_TraceRegionEnter('dlnd_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'LND', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -288,7 +287,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) xmlfilename = 'dlnd.streams'//trim(inst_suffix)//'.xml' call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'LND', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dlnd_strdata_init') + call ESMF_TraceRegionExit('dlnd_strdata_init') ! Realize the actively coupled fields, now that a mesh is established and ! initialize dfields data type (to map streams to export state fields) @@ -376,10 +375,10 @@ subroutine ModelAdvance(gcomp, rc) call ESMF_AlarmRingerOff( alarm, rc=rc ) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_startf('dlnd_restart') + call ESMF_TraceRegionEnter('dlnd_restart') call dshr_restart_write(rpfile, case_name, 'dlnd', inst_suffix, next_ymd, next_tod, & logunit, mpicom, my_task, sdat) - call t_stopf('dlnd_restart') + call ESMF_TraceRegionExit('dlnd_restart') endif ! write diagnostics @@ -512,7 +511,7 @@ subroutine dlnd_comp_run(importState, exportState, target_ymd, target_tod, rc) rc = ESMF_SUCCESS - call t_startf('DLND_RUN') + call ESMF_TraceRegionEnter('DLND_RUN') !-------------------- ! set module pointers @@ -561,29 +560,27 @@ subroutine dlnd_comp_run(importState, exportState, target_ymd, target_tod, rc) !-------------------- ! time and spatially interpolate to model time and grid - call t_barrierf('dlnd_BARRIER',mpicom) - call t_startf('dlnd_strdata_advance') + call ESMF_TraceRegionEnter('dlnd_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'dlnd', rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dlnd_strdata_advance') + call ESMF_TraceRegionExit('dlnd_strdata_advance') ! copy all fields from streams to export state as default ! This automatically will update the fields in the export state - call t_barrierf('dlnd_comp_strdata_copy_BARRIER', mpicom) - call t_startf('dlnd_strdata_copy') + call ESMF_TraceRegionEnter('dlnd_strdata_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dlnd_strdata_copy') + call ESMF_TraceRegionExit('dlnd_strdata_copy') ! determine data model behavior based on the mode - call t_startf('dlnd_datamode') + call ESMF_TraceRegionEnter('dlnd_datamode') select case (trim(datamode)) case('copyall') ! do nothing extra end select - call t_stopf('dlnd_datamode') - call t_stopf('DLND_RUN') + call ESMF_TraceRegionExit('dlnd_datamode') + call ESMF_TraceRegionExit('DLND_RUN') end subroutine dlnd_comp_run diff --git a/docn/ocn_comp_nuopc.F90 b/docn/ocn_comp_nuopc.F90 index 1236b056d4..81c531c888 100644 --- a/docn/ocn_comp_nuopc.F90 +++ b/docn/ocn_comp_nuopc.F90 @@ -22,8 +22,6 @@ module ocn_comp_nuopc use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_realize - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf - use pio ! Datamode specialized modules use docn_datamode_copyall_mod , only : docn_datamode_copyall_advertise @@ -324,7 +322,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) rc = ESMF_SUCCESS ! Initialize model mesh, restart flag, logunit, model_mask and model_frac - call t_startf('docn_strdata_init') + call ESMF_TraceRegionEnter('docn_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'OCN', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -336,7 +334,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'OCN', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call t_stopf('docn_strdata_init') + call ESMF_TraceRegionExit('docn_strdata_init') ! Realize the actively coupled fields, now that a mesh is established and ! NUOPC_Realize "realizes" a previously advertised field in the importState and exportState @@ -447,7 +445,7 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod rc = ESMF_SUCCESS - call t_startf('DOCN_RUN') + call ESMF_TraceRegionEnter('DOCN_RUN') !-------------------- ! First time initialization @@ -497,20 +495,20 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod ! Advance data model streams - time and spatially interpolate to model time and grid call t_barrierf('docn_BARRIER',mpicom) - call t_startf('docn_strdata_advance') + call ESMF_TraceRegionEnter('docn_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'docn', rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('docn_strdata_advance') + call ESMF_TraceRegionExit('docn_strdata_advance') ! Copy all fields from streams to export state as default ! This automatically will update the fields in the export state call t_barrierf('docn_dfield_copy_BARRIER', mpicom) - call t_startf('docn_dfield_copy') + call ESMF_TraceRegionEnter('docn_dfield_copy') if(.not. aquaplanet) then call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return endif - call t_stopf('docn_dfield_copy') + call ESMF_TraceRegionExit('docn_dfield_copy') ! Perform data mode specific calculations select case (trim(datamode)) @@ -546,7 +544,7 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod end select end if - call t_stopf('DOCN_RUN') + call ESMF_TraceRegionExit('DOCN_RUN') ! write diagnostics if (diagnose_data) then diff --git a/drof/rof_comp_nuopc.F90 b/drof/rof_comp_nuopc.F90 index e4963cd7ff..0765c10a9f 100644 --- a/drof/rof_comp_nuopc.F90 +++ b/drof/rof_comp_nuopc.F90 @@ -25,7 +25,6 @@ module rof_comp_nuopc use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf implicit none private ! except @@ -277,7 +276,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) rc = ESMF_SUCCESS ! Initialize mesh, restart flag, logunit - call t_startf('drof_strdata_init') + call ESMF_TraceRegionEnter('drof_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'ROF', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -287,7 +286,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) xmlfilename = 'drof.streams'//trim(inst_suffix)//'.xml' call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'ROF', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('drof_strdata_init') + call ESMF_TraceRegionExit('drof_strdata_init') ! NUOPC_Realize "realizes" a previously advertised field in the importState and exportState ! by replacing the advertised fields with the newly created fields of the same name. @@ -392,7 +391,7 @@ subroutine drof_comp_run(exportState, target_ymd, target_tod, restart_write, rc) character(*), parameter :: subName = "(drof_comp_run) " !------------------------------------------------------------------------------- - call t_startf('DROF_RUN') + call ESMF_TraceRegionEnter('DROF_RUN') !-------------------- ! First time initialization @@ -424,21 +423,19 @@ subroutine drof_comp_run(exportState, target_ymd, target_tod, restart_write, rc) !-------------------- ! time and spatially interpolate to model time and grid - call t_barrierf('drof_BARRIER',mpicom) - call t_startf('drof_strdata_advance') + call ESMF_TraceRegionEnter('drof_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'drof', rc=rc) - call t_stopf('drof_strdata_advance') + call ESMF_TraceRegionExit('drof_strdata_advance') ! copy all fields from streams to export state as default ! This automatically will update the fields in the export state - call t_barrierf('drof_comp_dfield_copy_BARRIER', mpicom) - call t_startf('drof_dfield_copy') + call ESMF_TraceRegionEnter('drof_dfield_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('drof_dfield_copy') + call ESMF_TraceRegionExit('drof_dfield_copy') ! determine data model behavior based on the mode - call t_startf('drof_datamode') + call ESMF_TraceRegionEnter('drof_datamode') select case (trim(datamode)) case('copyall') ! zero out "special values" of export fields @@ -463,8 +460,8 @@ subroutine drof_comp_run(exportState, target_ymd, target_tod, restart_write, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call t_stopf('drof_datamode') - call t_stopf('DROF_RUN') + call ESMF_TraceRegionExit('drof_datamode') + call ESMF_TraceRegionExit('DROF_RUN') end subroutine drof_comp_run diff --git a/dshr/dshr_mod.F90 b/dshr/dshr_mod.F90 index 814c467d93..58e32d04f3 100644 --- a/dshr/dshr_mod.F90 +++ b/dshr/dshr_mod.F90 @@ -40,7 +40,6 @@ module dshr_mod use shr_pio_mod , only : shr_pio_getiosys, shr_pio_getiotype, shr_pio_getioformat use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_init_from_xml, SHR_STRDATA_GET_STREAM_COUNT use dshr_methods_mod , only : chkerr - use perf_mod , only : t_startf, t_stopf use pio implicit none diff --git a/dwav/wav_comp_nuopc.F90 b/dwav/wav_comp_nuopc.F90 index b9999b94bb..2a39fdd630 100644 --- a/dwav/wav_comp_nuopc.F90 +++ b/dwav/wav_comp_nuopc.F90 @@ -24,7 +24,6 @@ module wav_comp_nuopc use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf implicit none private ! except @@ -264,7 +263,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) rc = ESMF_SUCCESS ! Initialize sdat - create the model domain mesh and intialize the sdat clock - call t_startf('dwav_strdata_init') + call ESMF_TraceRegionEnter('dwav_strdata_init') call dshr_mesh_init(gcomp, nullstr, logunit, 'WAV', nx_global, ny_global, & model_meshfile, model_maskfile, model_createmesh_fromfile, model_mesh, & model_mask, model_frac, restart_read, rc=rc) @@ -274,7 +273,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) xmlfilename = 'dwav.streams'//trim(inst_suffix)//'.xml' call shr_strdata_init_from_xml(sdat, xmlfilename, model_mesh, clock, 'WAV', logunit, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dwav_strdata_init') + call ESMF_TraceRegionExit('dwav_strdata_init') ! Realize the actively coupled fields, now that a mesh is established and ! initialize dfields data type (to map streams to export state fields) @@ -328,7 +327,7 @@ subroutine ModelAdvance(gcomp, rc) rc = ESMF_SUCCESS - call t_startf(subname) + call ESMF_TraceRegionEnter(subname) call memcheck(subname, 5, my_task == master_task) ! query the Component for its clock, importState and exportState @@ -357,13 +356,13 @@ subroutine ModelAdvance(gcomp, rc) call ESMF_AlarmRingerOff( alarm, rc=rc ) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_startf('dwav_restart') + call ESMF_TraceRegionEnter('dwav_restart') call NUOPC_CompAttributeGet(gcomp, name='case_name', value=case_name, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return call dshr_restart_write(rpfile, case_name, 'dwav', inst_suffix, next_ymd, next_tod, & logunit, mpicom, my_task, sdat) - call t_stopf('dwav_restart') + call ESMF_TraceRegionExit('dwav_restart') endif ! Write Diagnostics @@ -372,7 +371,7 @@ subroutine ModelAdvance(gcomp, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return end if - call t_stopf(subname) + call ESMF_TraceRegionExit(subname) end subroutine ModelAdvance @@ -484,7 +483,7 @@ subroutine dwav_comp_run(mpicom, my_task, logunit, target_ymd, target_tod, sdat, integer , intent(out) :: rc !------------------------------------------------------------------------------- - call t_startf('DWAV_RUN') + call ESMF_TraceRegionEnter('DWAV_RUN') !-------------------- ! advance dwav streams @@ -492,9 +491,9 @@ subroutine dwav_comp_run(mpicom, my_task, logunit, target_ymd, target_tod, sdat, ! time and spatially interpolate to model time and grid call t_barrierf('dwav_BARRIER',mpicom) - call t_startf('dwav_strdata_advance') + call ESMF_TraceRegionEnter('dwav_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'dwav', rc=rc) - call t_stopf('dwav_strdata_advance') + call ESMF_TraceRegionExit('dwav_strdata_advance') !-------------------- ! copy all fields from streams to export state as default @@ -502,23 +501,23 @@ subroutine dwav_comp_run(mpicom, my_task, logunit, target_ymd, target_tod, sdat, ! This automatically will update the fields in the export state call t_barrierf('dwav_comp_strdata_copy_BARRIER', mpicom) - call t_startf('dwav_strdata_copy') + call ESMF_TraceRegionEnter('dwav_strdata_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return - call t_stopf('dwav_strdata_copy') + call ESMF_TraceRegionExit('dwav_strdata_copy') !------------------------------------------------- ! determine data model behavior based on the mode !------------------------------------------------- - call t_startf('dwav_datamode') + call ESMF_TraceRegionEnter('dwav_datamode') select case (trim(datamode)) case('copyall') ! do nothing end select - call t_stopf('dwav_datamode') + call ESMF_TraceRegionExit('dwav_datamode') - call t_stopf('DWAV_RUN') + call ESMF_TraceRegionExit('DWAV_RUN') end subroutine dwav_comp_run diff --git a/streams/dshr_methods_mod.F90 b/streams/dshr_methods_mod.F90 index 861fc10937..08ab93a0b4 100644 --- a/streams/dshr_methods_mod.F90 +++ b/streams/dshr_methods_mod.F90 @@ -4,7 +4,6 @@ module dshr_methods_mod use ESMF use shr_kind_mod , only : r8=>shr_kind_r8, cs=>shr_kind_cs, cl=>shr_kind_cl - use perf_mod , only : t_startf, t_stopf, t_adj_detailf, t_barrierf implicit none public @@ -192,7 +191,7 @@ subroutine dshr_fldbun_regrid(FBsrc, FBdst, RH, zeroregion, rc) rc = ESMF_SUCCESS - call t_startf(subname) + call ESMF_TraceRegionEnter(subname) localzr = ESMF_REGION_TOTAL if (present(zeroregion)) then @@ -235,7 +234,7 @@ subroutine dshr_fldbun_regrid(FBsrc, FBdst, RH, zeroregion, rc) deallocate(lfieldnamelist_src) deallocate(lfieldnamelist_dst) - call t_stopf(subname) + call ESMF_TraceRegionExit(subname) end subroutine dshr_fldbun_regrid diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 7821351f03..9b069c8a7d 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -33,7 +33,6 @@ module dshr_strdata_mod use pio , only : pio_double, pio_real, pio_int, pio_offset_kind, pio_get_var use pio , only : pio_read_darray, pio_setframe, pio_fill_double, pio_get_att use pio , only : PIO_BCAST_ERROR, PIO_RETURN_ERROR, PIO_NOERR, PIO_INTERNAL_ERROR, PIO_SHORT - use perf_mod , only : t_startf, t_stopf, t_adj_detailf implicit none private @@ -735,7 +734,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (.not.ltimers) call t_adj_detailf(tadj) - call t_startf(trim(lstr)//trim(timname)//'_total') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_total') sdat%ymd = ymd sdat%tod = tod @@ -776,7 +775,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! fldbun_stream_ub to fldbun_stream_lb and read in new fldbun_stream_ub data ! --------------------------------------------------------- - call t_startf(trim(lstr)//trim(timname)//'_readLBUB') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_readLBUB') select case(sdat%stream(ns)%readmode) case ('single') @@ -827,7 +826,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) endif endif - call t_stopf(trim(lstr)//trim(timname)//'_readLBUB') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_readLBUB') enddo ! end of loop over streams @@ -843,19 +842,19 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! time interpolation method is coszen ! ------------------------------------------ - call t_startf(trim(lstr)//trim(timname)//'_coszen') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_coszen') allocate(coszen(sdat%model_lsize)) ! get coszen - call t_startf(trim(lstr)//trim(timname)//'_coszenC') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_coszenC') call shr_tInterp_getCosz(coszen, sdat%model_lon, sdat%model_lat, ymdmod(ns), todmod, & sdat%eccen, sdat%mvelpp, sdat%lambm0, sdat%obliqr, sdat%stream(ns)%calendar) - call t_stopf(trim(lstr)//trim(timname)//'_coszenC') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_coszenC') ! get avg cosz factor if (newdata(ns)) then ! compute a new avg cosz - call t_startf(trim(lstr)//trim(timname)//'_coszenN') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_coszenN') if (.not. allocated(sdat%tavCoszen)) then allocate(sdat%tavCoszen(sdat%model_lsize)) end if @@ -863,7 +862,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB, & sdat%eccen, sdat%mvelpp, sdat%lambm0, sdat%obliqr, sdat%modeldt, & sdat%stream(ns)%calendar, rc=rc) - call t_stopf(trim(lstr)//trim(timname)//'_coszenN') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_coszenN') endif ! compute time interperpolate value - LB data normalized with this factor: cosz/tavCosz @@ -884,7 +883,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) end do deallocate(coszen) - call t_stopf(trim(lstr)//trim(timname)//'_coszen') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_coszen') elseif (trim(sdat%stream(ns)%tinterpalgo) /= trim(shr_strdata_nullstr)) then @@ -892,7 +891,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! time interpolation method is not coszen ! ------------------------------------------ - call t_startf(trim(lstr)//trim(timname)//'_tint') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_tint') call shr_tInterp_getFactors(sdat%pstrm(ns)%ymdlb, sdat%pstrm(ns)%todlb, & sdat%pstrm(ns)%ymdub, sdat%pstrm(ns)%todub, & ymdmod(ns), todmod, flb, fub, calendar=sdat%stream(ns)%calendar, logunit=sdat%logunit, & @@ -914,7 +913,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return dataptr(:) = dataptr_lb(:) * flb + dataptr_ub(:) * fub end do - call t_stopf(trim(lstr)//trim(timname)//'_tint') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_tint') else @@ -922,13 +921,13 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ! zero out stream data for this field ! ------------------------------------------ - call t_startf(trim(lstr)//trim(timname)//'_zero') + call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_zero') do nf = 1,size(sdat%pstrm(ns)%fldlist_model) call dshr_fldbun_getfldptr(sdat%pstrm(ns)%fldbun_model, sdat%pstrm(ns)%fldlist_model(nf), dataptr, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return dataptr(:) = 0._r8 end do - call t_stopf(trim(lstr)//trim(timname)//'_zero') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_zero') endif @@ -939,7 +938,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) endif ! nstreams > 0 - call t_stopf(trim(lstr)//trim(timname)//'_total') + call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_total') if (.not.ltimers) call t_adj_detailf(-tadj) end subroutine shr_strdata_advance @@ -1059,7 +1058,7 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) stream => sdat%stream(ns) stream_mesh => sdat%pstrm(ns)%stream_mesh - call t_startf(trim(istr)//'_setup') + call ESMF_TraceRegionEnter(trim(istr)//'_setup') ! allocate streamdat instance on all tasks call ESMF_VMGetCurrent(vm, rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -1081,15 +1080,15 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) rDateLB = real(sdat%pstrm(ns)%ymdLB,r8) + real(sdat%pstrm(ns)%todLB,r8)/shr_const_cday rDateUB = real(sdat%pstrm(ns)%ymdUB,r8) + real(sdat%pstrm(ns)%todUB,r8)/shr_const_cday - call t_stopf(trim(istr)//'_setup') + call ESMF_TraceRegionExit(trim(istr)//'_setup') ! if model current date is outside of model lower or upper bound - find the stream bounds if (rDateM < rDateLB .or. rDateM > rDateUB) then - call t_startf(trim(istr)//'_fbound') + call ESMF_TraceRegionEnter(trim(istr)//'_fbound') call shr_stream_findBounds(stream, mDate, mSec, & sdat%pstrm(ns)%ymdLB, dDateLB, sdat%pstrm(ns)%todLB, n_lb, filename_lb, & sdat%pstrm(ns)%ymdUB, dDateUB, sdat%pstrm(ns)%todUB, n_ub, filename_ub) - call t_stopf(trim(istr)//'_fbound') + call ESMF_TraceRegionExit(trim(istr)//'_fbound') endif ! determine if need to read in new stream data @@ -1122,7 +1121,7 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) endif ! determine previous & next data files in list of files - call t_startf(trim(istr)//'_filemgt') + call ESMF_TraceRegionEnter(trim(istr)//'_filemgt') if (sdat%masterproc .and. newdata) then call shr_stream_getPrevFileName(stream, filename_lb, filename_prev) call shr_stream_getNextFileName(stream, filename_ub, filename_next) @@ -1131,7 +1130,7 @@ subroutine shr_strdata_readLBUB(sdat, ns, mDate, mSec, newData, istr, rc) ! do nothing end if endif - call t_stopf(trim(istr)//'_filemgt') + call ESMF_TraceRegionExit(trim(istr)//'_filemgt') end subroutine shr_strdata_readLBUB @@ -1246,7 +1245,7 @@ subroutine shr_strdata_readstrm(sdat, ns, stream, stream_mesh, & ! the data for fldbun_stream with the field names fldname_stream_model ! ****************************************************************************** - call t_startf(trim(istr)//'_readpio') + call ESMF_TraceRegionEnter(trim(istr)//'_readpio') if (sdat%masterproc) then write(sdat%logunit,F02) 'file ' // trim(boundstr) //': ',trim(filename), nt endif @@ -1433,7 +1432,7 @@ subroutine shr_strdata_readstrm(sdat, ns, stream, stream_mesh, & if(.not. pio_iodesc_set) then deallocate(dataptr) endif - call t_stopf(trim(istr)//'_readpio') + call ESMF_TraceRegionExit(trim(istr)//'_readpio') end subroutine shr_strdata_readstrm From 06a00b9fc04c4f99afa9db6cb795aaccf4064a25 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 16 Jul 2020 17:11:15 -0500 Subject: [PATCH 2/8] not yet working --- CMakeLists.txt | 2 + cmake/FindFoX.cmake | 40 ++++++ cmake/FindPIO.cmake | 103 +++++++++++++ cmake/LibCheck.cmake | 104 ++++++++++++++ cmake/LibFind.cmake | 333 +++++++++++++++++++++++++++++++++++++++++++ share/CMakeLists.txt | 3 +- 6 files changed, 584 insertions(+), 1 deletion(-) create mode 100644 cmake/FindFoX.cmake create mode 100644 cmake/FindPIO.cmake create mode 100644 cmake/LibCheck.cmake create mode 100644 cmake/LibFind.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d3b12130fb..5a308e0ef7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(NUOPC_DATA_MODELS LANGUAGES Fortran VERSION 0.1) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(ExternalProject) find_package(ESMF REQUIRED) +find_package(PIO REQUIRED) +find_package(FoX REQUIRED) if (DEFINED CIMEROOT) message("Using CIME in ${CIMEROOT} with compiler ${COMPILER}") diff --git a/cmake/FindFoX.cmake b/cmake/FindFoX.cmake new file mode 100644 index 0000000000..f26b7b3e40 --- /dev/null +++ b/cmake/FindFoX.cmake @@ -0,0 +1,40 @@ +# - Try to find FoX +# +# This can be controled by setting FoX_PATH or FoX__PATH Cmake variables, +# where is the COMPONENT language one needs. +# +# Once done, this will define: +# +# FoX__FOUND (BOOL) - system has FoX +# FoX__IS_SHARED (BOOL) - whether the library is shared/dynamic +# FoX__INCLUDE_DIR (PATH) - Location of the header files and modules +# FoX__LIBRARY (File) - Path to the library files +# FoX__LIBRARIES (List) - link these to use FoX +# +# Available COMPONENTS are: Fortran +# +include (LibFind) +include (LibCheck) + +# Define FoX Fortran Component +define_package_component(FoX DEFAULT + COMPONENT Fortran + INCLUDE_NAMES fox_common.mod + LIBRARY_NAMES FoX_common) + +# Search for list of valid components requested +find_valid_components(FoX) + +#============================================================================== +# SEARCH FOR VALIDATED COMPONENTS +foreach (pcomp IN LISTS FoX_FIND_VALID_COMPONENTS) + set(FoX_Fortran_INCLUDE_DIR $ENV{FoX}/finclude) + set(FoX_Fortran_LIBRARY $ENV{FoX}/lib) + initialize_paths(FoX_${pcomp}_PATHS + INCLUDE_DIRECTORIES $ENV{FoX}/finclude + LIBRARIES $ENV{FoX}/lib) + find_package_component(FoX COMPONENT ${pcomp}) +endforeach () +if(FoX_Fortran_FOUND) +message(" Found FoX:") +endif() \ No newline at end of file diff --git a/cmake/FindPIO.cmake b/cmake/FindPIO.cmake new file mode 100644 index 0000000000..d2761d20c7 --- /dev/null +++ b/cmake/FindPIO.cmake @@ -0,0 +1,103 @@ +# - Try to find PIO +# +# This can be controled by setting PIO_PATH or PIO__PATH Cmake variables, +# where is the COMPONENT language one needs. +# +# Once done, this will define: +# +# PIO__FOUND (BOOL) - system has PIO +# PIO__IS_SHARED (BOOL) - whether the library is shared/dynamic +# PIO__INCLUDE_DIR (PATH) - Location of the header files and modules +# PIO__LIBRARY (File) - Path to the library files +# PIO__LIBRARIES (List) - link these to use PIO +# +# Available COMPONENTS are: C Fortran +# If no components are specified only C is assumed +include (LibFind) +include (LibCheck) + +# Define PIO C Component +define_package_component(PIO DEFAULT + COMPONENT C + INCLUDE_NAMES pio.h + LIBRARY_NAMES pioc) + +# Define PIO Fortran Component +define_package_component(PIO + Component Fortran + INCLUDE_NAMES pio.mod pio.inc + LIBRARY_NAMES piof) + +# Search for list of valid components requested +find_valid_components(PIO) + +#============================================================================== +# SEARCH FOR VALIDATED COMPONENTS +foreach (pcomp IN LISTS PIO_FIND_VALID_COMPONENTS) + + # If not found already, search... + if (NOT PIO_${pcomp}_FOUND) + + # Manually add the MPI include and library dirs to search paths + # and search for the package component + if (MPI_${pcomp}_FOUND) + initialize_paths (PIO_${pcomp}_PATHS + INCLUDE_DIRECTORIES ${MPI_${pcomp}_INCLUDE_PATH} + LIBRARIES ${MPI_${pcomp}_LIBRARIES}) + find_package_component(PIO COMPONENT ${pcomp} + PATHS ${PIO_${pcomp}_PATHS}) + else () + find_package_component(PIO COMPONENT ${pcomp}) + endif () + + # Continue only if component found + if (PIO_${pcomp}_FOUND) + + # Checks + if (pcomp STREQUAL C) + + # Check version + check_version (PIO + NAME "pio_meta.h" + HINTS ${PIO_C_INCLUDE_DIRS} + MACRO_REGEX "PIO_VERSION_") + + endif () + + # Dependencies + if (pcomp STREQUAL C AND NOT PIO_C_IS_SHARED) + + # DEPENDENCY: PnetCDF (if PnetCDF enabled) + check_macro (PIO_HAS_PNETCDF + NAME TryPIO_PNETCDF.c + HINTS ${CMAKE_MODULE_PATH} + DEFINITIONS -I${PIO_C_INCLUDE_DIR} + COMMENT "whether PIO has PnetCDF support") + if (PIO_HAS_PNETCDF) + find_package (PnetCDF COMPONENTS C) + endif () + + + elseif (pcomp STREQUAL Fortran AND NOT PIO_Fortran_IS_SHARED) + + # DEPENDENCY: PIO + set (orig_comp ${pcomp}) + set (orig_comps ${PIO_FIND_VALID_COMPONENTS}) + find_package (PIO COMPONENTS C) + set (PIO_FIND_VALID_COMPONENTS ${orig_comps}) + set (pcomp ${orig_comp}) + if (PIO_C_FOUND) + list (APPEND PIO_Fortran_INCLUDE_DIRS ${PIO_C_INCLUDE_DIRS}) + list (APPEND PIO_Fortran_LIBRARIES ${PIO_C_LIBRARIES}) + endif () + + endif () + + endif () + + endif () + +endforeach () +message("PIO_C_FOUND ${PIO_C_FOUND}") +message("PIO_Fortran_FOUND ${PIO_Fortran_FOUND}") +message("PIO_INCLUDE_DIR ${PIO_INCLUDE_DIR}") diff --git a/cmake/LibCheck.cmake b/cmake/LibCheck.cmake new file mode 100644 index 0000000000..3f12bdf796 --- /dev/null +++ b/cmake/LibCheck.cmake @@ -0,0 +1,104 @@ +include (CMakeParseArguments) +include (CheckFunctionExists) +#============================================================================== +# +# FUNCTIONS TO HELP WITH Check* MODULES +# +#============================================================================== + +#______________________________________________________________________________ +# - Basic function to check a property of a package using a try_compile step +# +# SYNTAX: check_macro ( +# NAME +# HINTS ... +# DEFINITIONS ... +# COMMENT ) +# +function (check_macro VARIABLE) + + # Parse the input arguments + set (oneValueArgs COMMENT NAME) + set (multiValueArgs HINTS DEFINITIONS) + cmake_parse_arguments (${VARIABLE} "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # If the return variable is defined, already, don't continue + if (NOT DEFINED ${VARIABLE}) + + message (STATUS "Checking ${${VARIABLE}_COMMENT}") + find_file (${VARIABLE}_TRY_FILE + NAMES ${${VARIABLE}_NAME} + HINTS ${${VARIABLE}_HINTS}) + if (${VARIABLE}_TRY_FILE) + try_compile (COMPILE_RESULT + ${CMAKE_CURRENT_BINARY_DIR}/try${VARIABLE} + SOURCES ${${VARIABLE}_TRY_FILE} + COMPILE_DEFINITIONS ${${VARIABLE}_DEFINITIONS} + OUTPUT_VARIABLE TryOUT) + if (COMPILE_RESULT) + message (STATUS "Checking ${${VARIABLE}_COMMENT} - yes") + else () + message (STATUS "Checking ${${VARIABLE}_COMMENT} - no") + endif () + + set (${VARIABLE} ${COMPILE_RESULT} + CACHE BOOL "${${VARIABLE}_COMMENT}") + + else () + message (STATUS "Checking ${${VARIABLE}_COMMENT} - failed") + endif () + + unset (${VARIABLE}_TRY_FILE CACHE) + endif () + +endfunction () + +#______________________________________________________________________________ +# - Basic function to check the version of a package using a try_run step +# +# SYNTAX: check_version ( +# NAME +# HINTS ... +# DEFINITIONS ...) +# +function (check_version PKG) + + # Parse the input arguments + set (oneValueArgs NAME MACRO_REGEX) + set (multiValueArgs HINTS) + cmake_parse_arguments (${PKG} "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # If the return variable is defined, already, don't continue + if (NOT DEFINED ${PKG}_VERSION) + + message (STATUS "Checking ${PKG} version") + find_file (${PKG}_VERSION_HEADER + NAMES ${${PKG}_NAME} + HINTS ${${PKG}_HINTS}) + if (${PKG}_VERSION_HEADER) + set (def) + file (STRINGS ${${PKG}_VERSION_HEADER} deflines + REGEX "^#define[ \\t]+${${PKG}_MACRO_REGEX}") + foreach (defline IN LISTS deflines) + string (REPLACE "\"" "" defline "${defline}") + string (REPLACE "." "" defline "${defline}") + string (REGEX REPLACE "[ \\t]+" ";" deflist "${defline}") + list (GET deflist 2 arg) + list (APPEND def ${arg}) + endforeach () + string (REPLACE ";" "." vers "${def}") + message (STATUS "Checking ${PKG} version - ${vers}") + set (${PKG}_VERSION ${vers} + CACHE STRING "${PKG} version string") + if (${PKG}_VERSION VERSION_LESS ${PKG}_FIND_VERSION}) + message (FATAL_ERROR "${PKG} version insufficient") + endif () + else () + message (STATUS "Checking ${PKG} version - failed") + endif () + + unset (${PKG}_VERSION_HEADER CACHE) + + endif () + +endfunction () \ No newline at end of file diff --git a/cmake/LibFind.cmake b/cmake/LibFind.cmake new file mode 100644 index 0000000000..61cd93aa37 --- /dev/null +++ b/cmake/LibFind.cmake @@ -0,0 +1,333 @@ +include (CMakeParseArguments) +include(FindPackageHandleStandardArgs) + +#============================================================================== +# +# FUNCTIONS TO HELP WITH Find* MODULES +# +#============================================================================== + +#______________________________________________________________________________ +# - Wrapper for finding static libraries ONLY +# +macro (find_static_library) + set (_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) + find_library(${ARGN}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${_CMAKE_FIND_LIBRARY_SUFFIXES}) + unset (_CMAKE_FIND_LIBRARY_SUFFIXES) +endmacro () + + +#______________________________________________________________________________ +# - Wrapper for finding shared/dynamic libraries ONLY +# +macro (find_shared_library) + set (_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX}) + find_library(${ARGN}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${_CMAKE_FIND_LIBRARY_SUFFIXES}) + unset (_CMAKE_FIND_LIBRARY_SUFFIXES) +endmacro () + + +#______________________________________________________________________________ +# - Function to determine type (SHARED or STATIC) of library +# +# Input: +# LIB (FILE) +# +# Returns: +# RETURN_VAR (BOOL) +# +function (is_shared_library RETURN_VAR LIB) + get_filename_component(libext ${LIB} EXT) + if (libext MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX}) + set (${RETURN_VAR} TRUE PARENT_SCOPE) + else () + set (${RETURN_VAR} FALSE PARENT_SCOPE) + endif () +endfunction () + + +#______________________________________________________________________________ +# - Function to define a valid package component +# +# Input: +# ${PKG}_DEFAULT (BOOL) +# ${PKG}_COMPONENT (STRING) +# ${PKG}_INCLUDE_NAMES (LIST) +# ${PKG}_LIBRARY_NAMES (LIST) +# +# Returns: +# ${PKG}_DEFAULT_COMPONENT (STRING) +# ${PKG}_VALID_COMPONENTS (LIST) +# ${PKG}_${COMPONENT}_INCLUDE_NAMES (LIST) +# ${PKG}_${COMPONENT}_LIBRARY_NAMES (LIST) +# +function (define_package_component PKG) + + # Parse the input arguments + set (options DEFAULT) + set (oneValueArgs COMPONENT) + set (multiValueArgs INCLUDE_NAMES LIBRARY_NAMES) + cmake_parse_arguments (${PKG} "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if (${PKG}_COMPONENT) + set (PKGCOMP ${PKG}_${${PKG}_COMPONENT}) + else () + set (PKGCOMP ${PKG}) + endif () + + # Set return values + if (${PKG}_COMPONENT) + if (${PKG}_DEFAULT) + set (${PKG}_DEFAULT_COMPONENT ${${PKG}_COMPONENT} PARENT_SCOPE) + endif () + set (VALID_COMPONENTS ${${PKG}_VALID_COMPONENTS}) + list (APPEND VALID_COMPONENTS ${${PKG}_COMPONENT}) + set (${PKG}_VALID_COMPONENTS ${VALID_COMPONENTS} PARENT_SCOPE) + endif () + set (${PKGCOMP}_INCLUDE_NAMES ${${PKG}_INCLUDE_NAMES} PARENT_SCOPE) + set (${PKGCOMP}_LIBRARY_NAMES ${${PKG}_LIBRARY_NAMES} PARENT_SCOPE) + +endfunction () + + +#______________________________________________________________________________ +# - Function to find valid package components +# +# Assumes pre-defined variables: +# ${PKG}_FIND_COMPONENTS (LIST) +# ${PKG}_DEFAULT_COMPONENT (STRING) +# ${PKG}_VALID_COMPONENTS (LIST) +# +# Returns: +# ${PKG}_FIND_VALID_COMPONENTS (LIST) +# +function (find_valid_components PKG) + + if (NOT ${PKG}_FIND_COMPONENTS) + set (${PKG}_FIND_COMPONENTS ${${PKG}_DEFAULT_COMPONENT}) + endif () + + set (FIND_VALID_COMPONENTS) + foreach (comp IN LISTS ${PKG}_FIND_COMPONENTS) + if (";${${PKG}_VALID_COMPONENTS};" MATCHES ";${comp};") + list (APPEND FIND_VALID_COMPONENTS ${comp}) + endif () + endforeach () + + set (${PKG}_FIND_VALID_COMPONENTS ${FIND_VALID_COMPONENTS} PARENT_SCOPE) + +endfunction () + + +#______________________________________________________________________________ +# - Initialize a list of paths from a list of includes and libraries +# +# Input: +# INCLUDE_DIRECTORIES +# LIBRARIES +# +# Ouput: +# ${PATHLIST} +# +function (initialize_paths PATHLIST) + + # Parse the input arguments + set (multiValueArgs INCLUDE_DIRECTORIES LIBRARIES) + cmake_parse_arguments (INIT "" "" "${multiValueArgs}" ${ARGN}) + + set (paths) + foreach (inc IN LISTS INIT_INCLUDE_DIRECTORIES) + list (APPEND paths ${inc}) + get_filename_component (dname ${inc} NAME) + if (dname MATCHES "include") + get_filename_component (prefx ${inc} PATH) + list (APPEND paths ${prefx}) + endif () + endforeach () + foreach (lib IN LISTS INIT_LIBRARIES) + get_filename_component (libdir ${lib} PATH) + list (APPEND paths ${libdir}) + get_filename_component (dname ${libdir} PATH) + if (dname MATCHES "lib") + get_filename_component (prefx ${libdir} PATH) + list (APPEND paths ${prefx}) + endif () + endforeach () + + set (${PATHLIST} ${paths} PARENT_SCOPE) + +endfunction () + + +#______________________________________________________________________________ +# - Basic find package macro for a specific component +# +# Assumes pre-defined variables: +# ${PKG}_${COMP}_INCLUDE_NAMES or ${PKG}_INCLUDE_NAMES +# ${PKG}_${COMP}_LIBRARY_NAMES or ${PKG}_LIBRARY_NAMES +# +# Input: +# ${PKG}_COMPONENT +# ${PKG}_HINTS +# ${PKG}_PATHS +# +function (find_package_component PKG) + + # Parse the input arguments + set (options) + set (oneValueArgs COMPONENT) + set (multiValueArgs HINTS PATHS) + cmake_parse_arguments (${PKG} "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set (COMP ${${PKG}_COMPONENT}) + if (COMP) + set (PKGCOMP ${PKG}_${COMP}) + else () + set (PKGCOMP ${PKG}) + endif () + string (TOUPPER ${PKG} PKGUP) + string (TOUPPER ${PKGCOMP} PKGCOMPUP) + + # Only continue if package not found already + if (NOT ${PKGCOMP}_FOUND) + + # Handle QUIET and REQUIRED arguments + if (${${PKG}_FIND_QUIETLY}) + set (${PKGCOMP}_FIND_QUIETLY TRUE) + endif () + if (${${PKG}_FIND_REQUIRED}) + set (${PKGCOMP}_FIND_REQUIRED TRUE) + endif () + + # Determine search order + set (SEARCH_DIRS) + if (${PKG}_HINTS) + list (APPEND SEARCH_DIRS ${${PKG}_HINTS}) + endif () + if (${PKGCOMP}_PATH) + list (APPEND SEARCH_DIRS ${${PKGCOMP}_PATH}) + endif () + if (${PKG}_PATH) + list (APPEND SEARCH_DIRS ${${PKG}_PATH}) + endif () + if (DEFINED ENV{${PKGCOMPUP}}) + list (APPEND SEARCH_DIRS $ENV{${PKGCOMPUP}}) + endif () + if (DEFINED ENV{${PKGUP}}) + list (APPEND SEARCH_DIRS $ENV{${PKGUP}}) + endif () + if (CMAKE_SYSTEM_PREFIX_PATH) + list (APPEND SEARCH_DIRS ${CMAKE_SYSTEM_PREFIX_PATH}) + endif () + if (${PKG}_PATHS) + list (APPEND SEARCH_DIRS ${${PKG}_PATHS}) + endif () + + # Start the search for the include file and library file. Only overload + # if the variable is not defined. + foreach (suffix PREFIX LIBRARY INCLUDE_DIR) + if (NOT DEFINED ${PKGCOMP}_${suffix}) + set (${PKGCOMP}_${suffix} ${PKGCOMP}_${suffix}-NOTFOUND) + endif () + endforeach () + + foreach (dir IN LISTS SEARCH_DIRS) + + # Search for include file names in current dirrectory + foreach (iname IN LISTS ${PKGCOMP}_INCLUDE_NAMES) + if (EXISTS ${dir}/${iname}) + set (${PKGCOMP}_PREFIX ${dir}) + set (${PKGCOMP}_INCLUDE_DIR ${dir}) + break () + endif () + if (EXISTS ${dir}/include/${iname}) + set (${PKGCOMP}_PREFIX ${dir}) + set (${PKGCOMP}_INCLUDE_DIR ${dir}/include) + break () + endif () + endforeach () + + # Search for library file names in the found prefix only! + if (${PKGCOMP}_PREFIX) + find_library (${PKGCOMP}_LIBRARY + NAMES ${${PKGCOMP}_LIBRARY_NAMES} + PATHS ${${PKGCOMP}_PREFIX} + PATH_SUFFIXES lib + NO_DEFAULT_PATH) + + # If found, check if library is static or dynamic + if (${PKGCOMP}_LIBRARY) + is_shared_library (${PKGCOMP}_IS_SHARED ${${PKGCOMP}_LIBRARY}) + + # If we want only shared libraries, and it isn't shared... + if (PREFER_SHARED AND NOT ${PKGCOMP}_IS_SHARED) + find_shared_library (${PKGCOMP}_SHARED_LIBRARY + NAMES ${${PKGCOMP}_LIBRARY_NAMES} + PATHS ${${PKGCOMP}_PREFIX} + PATH_SUFFIXES lib + NO_DEFAULT_PATH) + if (${PKGCOMP}_SHARED_LIBRARY) + set (${PKGCOMP}_LIBRARY ${${PKGCOMP}_SHARED_LIBRARY}) + set (${PKGCOMP}_IS_SHARED TRUE) + endif () + + # If we want only static libraries, and it is shared... + elseif (PREFER_STATIC AND ${PKGCOMP}_IS_SHARED) + find_static_library (${PKGCOMP}_STATIC_LIBRARY + NAMES ${${PKGCOMP}_LIBRARY_NAMES} + PATHS ${${PKGCOMP}_PREFIX} + PATH_SUFFIXES lib + NO_DEFAULT_PATH) + if (${PKGCOMP}_STATIC_LIBRARY) + set (${PKGCOMP}_LIBRARY ${${PKGCOMP}_STATIC_LIBRARY}) + set (${PKGCOMP}_IS_SHARED FALSE) + endif () + endif () + endif () + + # If include dir and library both found, then we're done + if (${PKGCOMP}_INCLUDE_DIR AND ${PKGCOMP}_LIBRARY) + break () + + # Otherwise, reset the search variables and continue + else () + set (${PKGCOMP}_PREFIX ${PKGCOMP}_PREFIX-NOTFOUND) + set (${PKGCOMP}_INCLUDE_DIR ${PKGCOMP}_INCLUDE_DIR-NOTFOUND) + set (${PKGCOMP}_LIBRARY ${PKGCOMP}_LIBRARY-NOTFOUND) + endif () + endif () + + endforeach () + + # handle the QUIETLY and REQUIRED arguments and + # set NetCDF_C_FOUND to TRUE if all listed variables are TRUE + find_package_handle_standard_args (${PKGCOMP} DEFAULT_MSG + ${PKGCOMP}_LIBRARY + ${PKGCOMP}_INCLUDE_DIR) + mark_as_advanced (${PKGCOMP}_INCLUDE_DIR ${PKGCOMP}_LIBRARY) + + # HACK For bug in CMake v3.0: + set (${PKGCOMP}_FOUND ${${PKGCOMPUP}_FOUND}) + + # Set return variables + if (${PKGCOMP}_FOUND) + set (${PKGCOMP}_INCLUDE_DIRS ${${PKGCOMP}_INCLUDE_DIR}) + set (${PKGCOMP}_LIBRARIES ${${PKGCOMP}_LIBRARY}) + endif () + + # Set variables in parent scope + set (${PKGCOMP}_FOUND ${${PKGCOMP}_FOUND} PARENT_SCOPE) + set (${PKGCOMP}_INCLUDE_DIR ${${PKGCOMP}_INCLUDE_DIR} PARENT_SCOPE) + set (${PKGCOMP}_INCLUDE_DIRS ${${PKGCOMP}_INCLUDE_DIRS} PARENT_SCOPE) + set (${PKGCOMP}_LIBRARY ${${PKGCOMP}_LIBRARY} PARENT_SCOPE) + set (${PKGCOMP}_LIBRARIES ${${PKGCOMP}_LIBRARIES} PARENT_SCOPE) + set (${PKGCOMP}_IS_SHARED ${${PKGCOMP}_IS_SHARED} PARENT_SCOPE) + + endif () + +endfunction () + + + diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 8c8e5a701a..d088e58c93 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -19,8 +19,9 @@ add_library(cdeps_share ${GenF90_SRCS} shr_strconvert_mod.F90 shr_precip_mod.F90 shr_string_mod.F90) +message("HERE ${PIO_Fortran_INCLUDE_DIR}") +target_include_directories (cdeps_share PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${ESMF_F90COMPILEPATHS} ${PIO_Fortran_INCLUDE_DIRS}) -target_include_directories (cdeps_share PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${ESMF_F90COMPILEPATHS} ${PIO_INCDIR}) #===== genf90 ===== if (DEFINED GENF90_PATH) From db398b4ef85665d63c28176ac02c327fad90f93c Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 21 Jul 2020 16:25:55 -0600 Subject: [PATCH 3/8] fix standalone build --- CMakeLists.txt | 2 +- cmake/FindFoX.cmake | 10 +++++----- cmake/FindPIO.cmake | 15 ++++++++------- share/CMakeLists.txt | 2 +- streams/CMakeLists.txt | 4 ++-- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a308e0ef7..9cdb8965a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(NUOPC_DATA_MODELS LANGUAGES Fortran VERSION 0.1) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(ExternalProject) find_package(ESMF REQUIRED) -find_package(PIO REQUIRED) +find_package(PIO REQUIRED COMPONENT C Fortran) find_package(FoX REQUIRED) if (DEFINED CIMEROOT) diff --git a/cmake/FindFoX.cmake b/cmake/FindFoX.cmake index f26b7b3e40..7ddb02b1ad 100644 --- a/cmake/FindFoX.cmake +++ b/cmake/FindFoX.cmake @@ -1,8 +1,8 @@ -# - Try to find FoX +# - Try to find FoX +# +# This can be controled by setting FoX_PATH or FoX__PATH Cmake variables, +# where is the COMPONENT language one needs. # -# This can be controled by setting FoX_PATH or FoX__PATH Cmake variables, -# where is the COMPONENT language one needs. -# # Once done, this will define: # # FoX__FOUND (BOOL) - system has FoX @@ -36,5 +36,5 @@ foreach (pcomp IN LISTS FoX_FIND_VALID_COMPONENTS) find_package_component(FoX COMPONENT ${pcomp}) endforeach () if(FoX_Fortran_FOUND) -message(" Found FoX:") +message(" Found FoX: ${FoX_Fortran_INCLUDE_DIR}") endif() \ No newline at end of file diff --git a/cmake/FindPIO.cmake b/cmake/FindPIO.cmake index d2761d20c7..6de7030ec8 100644 --- a/cmake/FindPIO.cmake +++ b/cmake/FindPIO.cmake @@ -1,8 +1,8 @@ -# - Try to find PIO +# - Try to find PIO +# +# This can be controled by setting PIO_PATH or PIO__PATH Cmake variables, +# where is the COMPONENT language one needs. # -# This can be controled by setting PIO_PATH or PIO__PATH Cmake variables, -# where is the COMPONENT language one needs. -# # Once done, this will define: # # PIO__FOUND (BOOL) - system has PIO @@ -23,14 +23,15 @@ define_package_component(PIO DEFAULT LIBRARY_NAMES pioc) # Define PIO Fortran Component -define_package_component(PIO - Component Fortran +define_package_component(PIO + COMPONENT Fortran INCLUDE_NAMES pio.mod pio.inc LIBRARY_NAMES piof) # Search for list of valid components requested find_valid_components(PIO) +message("This is ${PIO_FIND_COMPONENTS}") #============================================================================== # SEARCH FOR VALIDATED COMPONENTS foreach (pcomp IN LISTS PIO_FIND_VALID_COMPONENTS) @@ -100,4 +101,4 @@ foreach (pcomp IN LISTS PIO_FIND_VALID_COMPONENTS) endforeach () message("PIO_C_FOUND ${PIO_C_FOUND}") message("PIO_Fortran_FOUND ${PIO_Fortran_FOUND}") -message("PIO_INCLUDE_DIR ${PIO_INCLUDE_DIR}") +message("PIO_Fortran_INCLUDE_DIR ${PIO_Fortran_INCLUDE_DIR}") diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index d088e58c93..06bb2c7d3f 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -19,7 +19,7 @@ add_library(cdeps_share ${GenF90_SRCS} shr_strconvert_mod.F90 shr_precip_mod.F90 shr_string_mod.F90) -message("HERE ${PIO_Fortran_INCLUDE_DIR}") + target_include_directories (cdeps_share PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${ESMF_F90COMPILEPATHS} ${PIO_Fortran_INCLUDE_DIRS}) diff --git a/streams/CMakeLists.txt b/streams/CMakeLists.txt index 750a88b224..902b53adde 100644 --- a/streams/CMakeLists.txt +++ b/streams/CMakeLists.txt @@ -17,8 +17,8 @@ if(BLD_STANDALONE) add_dependencies(streams cdeps_share) endif() target_include_directories (streams PUBLIC ${ESMF_F90COMPILEPATHS}) -target_include_directories (streams PUBLIC ${PIO_INCDIR}) -target_include_directories (streams PUBLIC ${FOX}/finclude) +target_include_directories (streams PUBLIC ${PIO_Fortran_INCLUDE_DIR}) +target_include_directories (streams PUBLIC ${FoX_Fortran_INCLUDE_DIR}) target_include_directories (streams PUBLIC ${CMAKE_BINARY_DIR}/share) install(TARGETS streams LIBRARY DESTINATION lib) From b0820dc2e6bd16f847a5c019abef2e95dc333d1d Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Tue, 21 Jul 2020 16:46:17 -0600 Subject: [PATCH 4/8] update pio path --- CMakeLists.txt | 2 +- datm/CMakeLists.txt | 2 +- dice/CMakeLists.txt | 2 +- dlnd/CMakeLists.txt | 2 +- docn/CMakeLists.txt | 2 +- drof/CMakeLists.txt | 2 +- dshr/CMakeLists.txt | 2 +- dwav/CMakeLists.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cdb8965a1..6d273b518a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ endif() if(BLD_STANDALONE) add_subdirectory(share) list(APPEND EXTRA_LIBS cdeps_share) - list(APPEND EXTRA_INCLUDES "${PIO_INCDIR}" "${CMAKE_BINARY_DIR}/share" ) + list(APPEND EXTRA_INCLUDES "${CMAKE_BINARY_DIR}/share" ) endif() diff --git a/datm/CMakeLists.txt b/datm/CMakeLists.txt index 61785d7d1c..a39d02e234 100644 --- a/datm/CMakeLists.txt +++ b/datm/CMakeLists.txt @@ -12,4 +12,4 @@ target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (datm PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (datm PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (datm PUBLIC "${PIO_INCDIR}") +target_include_directories (datm PUBLIC "${PIO_Fortran_INCLUDE_DIR}") diff --git a/dice/CMakeLists.txt b/dice/CMakeLists.txt index 841ddd71ed..f45a446b35 100644 --- a/dice/CMakeLists.txt +++ b/dice/CMakeLists.txt @@ -17,4 +17,4 @@ target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (dice PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (dice PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (dice PUBLIC "${PIO_INCDIR}") +target_include_directories (dice PUBLIC "${PIO_Fortran_INCLUDE_DIR}") diff --git a/dlnd/CMakeLists.txt b/dlnd/CMakeLists.txt index 03a81ac0e5..ae080d3072 100644 --- a/dlnd/CMakeLists.txt +++ b/dlnd/CMakeLists.txt @@ -16,4 +16,4 @@ target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (dlnd PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (dlnd PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (dlnd PUBLIC "${PIO_INCDIR}") +target_include_directories (dlnd PUBLIC "${PIO_Fortran_INCLUDE_DIR}") diff --git a/docn/CMakeLists.txt b/docn/CMakeLists.txt index 1253fd1d4e..33e3ba01ce 100644 --- a/docn/CMakeLists.txt +++ b/docn/CMakeLists.txt @@ -21,4 +21,4 @@ target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (docn PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (docn PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (docn PUBLIC "${PIO_INCDIR}") +target_include_directories (docn PUBLIC "${PIO_Fortran_INCLUDE_DIR}") diff --git a/drof/CMakeLists.txt b/drof/CMakeLists.txt index 41ded49c89..62a92cb83b 100644 --- a/drof/CMakeLists.txt +++ b/drof/CMakeLists.txt @@ -16,4 +16,4 @@ target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (drof PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (drof PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (drof PUBLIC "${PIO_INCDIR}") +target_include_directories (drof PUBLIC "${PIO_Fortran_INCLUDE_DIR}") diff --git a/dshr/CMakeLists.txt b/dshr/CMakeLists.txt index f45a646bb8..1a98d00ab3 100644 --- a/dshr/CMakeLists.txt +++ b/dshr/CMakeLists.txt @@ -19,6 +19,6 @@ add_dependencies(dshr streams) target_include_directories (dshr PUBLIC ${ESMF_F90COMPILEPATHS}) target_include_directories (dshr PUBLIC "${CMAKE_BINARY_DIR}/streams") target_include_directories (dshr PUBLIC "${CMAKE_BINARY_DIR}/share") -target_include_directories (dshr PUBLIC "${PIO_INCDIR}") +target_include_directories (dshr PUBLIC "${PIO_Fortran_INCLUDE_DIR}") install(TARGETS dshr LIBRARY DESTINATION lib) diff --git a/dwav/CMakeLists.txt b/dwav/CMakeLists.txt index 27dced49ea..c848741c61 100644 --- a/dwav/CMakeLists.txt +++ b/dwav/CMakeLists.txt @@ -16,4 +16,4 @@ target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/dshr") target_include_directories (dwav PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/share") target_include_directories (dwav PUBLIC "${CMAKE_BINARY_DIR}/streams") -target_include_directories (dwav PUBLIC "${PIO_INCDIR}") +target_include_directories (dwav PUBLIC "${PIO_Fortran_INCLUDE_DIR}") From eb8e465e293b12d9b2ea823b0662adca6d9546c2 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 27 Jul 2020 13:47:19 -0600 Subject: [PATCH 5/8] more bld changes --- CMakeLists.txt | 15 +++++++++++++-- cime_config/buildlib | 2 ++ cmake/FindPIO.cmake | 1 - datm/atm_comp_nuopc.F90 | 6 ++---- streams/dshr_strdata_mod.F90 | 7 ++----- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d273b518a..c6f2499910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,19 @@ project(NUOPC_DATA_MODELS LANGUAGES Fortran VERSION 0.1) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(ExternalProject) find_package(ESMF REQUIRED) -find_package(PIO REQUIRED COMPONENT C Fortran) -find_package(FoX REQUIRED) +if (DEFINED PIO) + set(PIO_PATH ${PIO}) +else() + set(PIO_PATH $ENV{PIO}) +endif() +find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH}) + +if (DEFINED FOX) + set(FOX_PATH ${FOX}) +else() + set(FOX_PATH $ENV{FOX}) +endif() +find_package(FoX REQUIRED HINT ${FOX}) if (DEFINED CIMEROOT) message("Using CIME in ${CIMEROOT} with compiler ${COMPILER}") diff --git a/cime_config/buildlib b/cime_config/buildlib index 24a498e032..2d7f6f8580 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -58,6 +58,8 @@ def buildlib(bldroot, libroot, case, compname=None): cmake_flags += " -DCMAKE_INSTALL_PREFIX={} ".format(libroot) cmake_flags += " -DLIBROOT={} ".format(libroot) + srcpath cmake_flags += " -DMPILIB={} ".format(mpilib) + cmake_flags += " -DPIO={} ".format(os.path.join(case.get_value("EXEROOT"),sharedpath)) + cmake_flags += " -DFOX={} ".format(os.path.join(case.get_value("EXEROOT"),sharedpath)) logger.info("cmake_flags {}".format(cmake_flags)) s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True) diff --git a/cmake/FindPIO.cmake b/cmake/FindPIO.cmake index 6de7030ec8..141834128d 100644 --- a/cmake/FindPIO.cmake +++ b/cmake/FindPIO.cmake @@ -31,7 +31,6 @@ define_package_component(PIO # Search for list of valid components requested find_valid_components(PIO) -message("This is ${PIO_FIND_COMPONENTS}") #============================================================================== # SEARCH FOR VALIDATED COMPONENTS foreach (pcomp IN LISTS PIO_FIND_VALID_COMPONENTS) diff --git a/datm/atm_comp_nuopc.F90 b/datm/atm_comp_nuopc.F90 index a52fe96586..cbe3a4fcfb 100644 --- a/datm/atm_comp_nuopc.F90 +++ b/datm/atm_comp_nuopc.F90 @@ -330,8 +330,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) integer(i8) :: stepno ! step number real(r8) :: nextsw_cday ! calendar of next atm sw character(CL) :: cvalue ! character string for input config - real(R8) :: orbEccen ! orb eccentricity (unit-less) - real(R8) :: orbMvelpp ! orb moving vernal eq (radians) + real(R8) :: orbEccen ! orb eccentricity (unist-less) + real(R8) :: orbMvelpp ! orb moving vernal eqa (radians) real(R8) :: orbLambm0 ! orb mean long of perhelion (radians) real(R8) :: orbObliqr ! orb obliquity (radians) logical :: isPresent, isSet @@ -571,7 +571,6 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe call shr_strdata_setOrbs(sdat, orbEccen, orbMvelpp, orbLambm0, orbObliqr, idt) ! time and spatially interpolate to model time and grid - call t_barrierf('datm_BARRIER',mpicom) call ESMF_TraceRegionEnter('datm_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'datm', rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -579,7 +578,6 @@ subroutine datm_comp_run(importState, exportState, target_ymd, target_tod, targe ! copy all fields from streams to export state as default ! This automatically will update the fields in the export state - call t_barrierf('datm_comp_dfield_copy_BARRIER', mpicom) call ESMF_TraceRegionEnter('datm_dfield_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 9b069c8a7d..150633769b 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -6,7 +6,7 @@ module dshr_strdata_mod use ESMF use shr_kind_mod , only : r8=>shr_kind_r8, r4=>shr_kind_r4, i2=>shr_kind_I2 - use shr_kind_mod , only : cs=>shr_kind_cs, cl=>shr_kind_cl, cxx=>shr_kind_cxx + use shr_kind_mod , only : cs=>shr_kind_cs, cl=>shr_kind_cl, cxx=>shr_kind_cxx use shr_sys_mod , only : shr_sys_abort use shr_const_mod , only : shr_const_pi, shr_const_cDay, shr_const_spval use shr_cal_mod , only : shr_cal_calendarname, shr_cal_timeSet @@ -212,7 +212,7 @@ subroutine shr_strdata_init_from_inline(sdat, my_task, logunit, compname, model_ type(shr_strdata_type) , intent(inout) :: sdat ! stream data type integer , intent(in) :: my_task ! my mpi task integer , intent(in) :: logunit ! stdout logunit - character(len=*) , intent(in) :: compname ! component name (e.g. ATM, OCN, ...) + character(len=*) , intent(in) :: compname ! component name (e.g. ATM, OCN, ...) type(ESMF_Clock) , intent(in) :: model_clock ! model clock type(ESMF_Mesh) , intent(in) :: model_mesh ! model mesh character(*) , intent(in) :: stream_meshFile ! full pathname to stream mesh file @@ -732,8 +732,6 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) ltimers = timers endif - if (.not.ltimers) call t_adj_detailf(tadj) - call ESMF_TraceRegionEnter(trim(lstr)//trim(timname)//'_total') sdat%ymd = ymd @@ -939,7 +937,6 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) endif ! nstreams > 0 call ESMF_TraceRegionExit(trim(lstr)//trim(timname)//'_total') - if (.not.ltimers) call t_adj_detailf(-tadj) end subroutine shr_strdata_advance From 6ed43c2198821aa850597b5b56e84a7f1e15ecfc Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 6 Aug 2020 13:00:04 -0600 Subject: [PATCH 6/8] add fox as a submodule of cdeps --- .gitmodules | 3 +++ fox | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 fox diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..eff7950f69 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "fox"] + path = fox + url = https://github.com/ESMCI/fox.git diff --git a/fox b/fox new file mode 160000 index 0000000000..0ed59c1552 --- /dev/null +++ b/fox @@ -0,0 +1 @@ +Subproject commit 0ed59c15525258579efcf40369d383193f170902 From 1c6624d0c9c48b3e5170b2611e4b5a98426d6ecb Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 6 Aug 2020 14:36:21 -0600 Subject: [PATCH 7/8] add fox submodule --- CMakeLists.txt | 10 +--------- cime_config/buildlib | 4 ++-- cmake/FindFoX.cmake | 40 ---------------------------------------- cmake/FindPIO.cmake | 2 +- docn/ocn_comp_nuopc.F90 | 2 -- streams/CMakeLists.txt | 3 ++- 6 files changed, 6 insertions(+), 55 deletions(-) delete mode 100644 cmake/FindFoX.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f2499910..1dc0570676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,20 +11,12 @@ else() endif() find_package(PIO REQUIRED COMPONENT C Fortran PATH ${PIO_PATH}) -if (DEFINED FOX) - set(FOX_PATH ${FOX}) -else() - set(FOX_PATH $ENV{FOX}) -endif() -find_package(FoX REQUIRED HINT ${FOX}) - if (DEFINED CIMEROOT) message("Using CIME in ${CIMEROOT} with compiler ${COMPILER}") include(${CASEROOT}/Macros.cmake) if (${PIO_VERSION} LESS 2) message( FATAL_ERROR "Version 2 of the PIO library required") endif() - set(FOX ${LIBROOT}) set(CMAKE_Fortran_FLAGS "${FFLAGS} -I${LIBROOT}/include -I${LIBROOT}/finclude -I${LIBROOT}/nuopc/esmf/${NINST_VALUE}/include") else () set(BLD_STANDALONE TRUE) @@ -39,7 +31,7 @@ if(BLD_STANDALONE) list(APPEND EXTRA_INCLUDES "${CMAKE_BINARY_DIR}/share" ) endif() - +add_subdirectory(fox) add_subdirectory(streams) add_subdirectory(dshr) diff --git a/cime_config/buildlib b/cime_config/buildlib index 2d7f6f8580..d6f460072a 100755 --- a/cime_config/buildlib +++ b/cime_config/buildlib @@ -58,8 +58,8 @@ def buildlib(bldroot, libroot, case, compname=None): cmake_flags += " -DCMAKE_INSTALL_PREFIX={} ".format(libroot) cmake_flags += " -DLIBROOT={} ".format(libroot) + srcpath cmake_flags += " -DMPILIB={} ".format(mpilib) - cmake_flags += " -DPIO={} ".format(os.path.join(case.get_value("EXEROOT"),sharedpath)) - cmake_flags += " -DFOX={} ".format(os.path.join(case.get_value("EXEROOT"),sharedpath)) + cmake_flags += " -DPIO_C_LIBRARY={path}/lib -DPIO_C_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath)) + cmake_flags += " -DPIO_Fortran_LIBRARY={path}/lib -DPIO_Fortran_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath)) logger.info("cmake_flags {}".format(cmake_flags)) s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True) diff --git a/cmake/FindFoX.cmake b/cmake/FindFoX.cmake deleted file mode 100644 index 7ddb02b1ad..0000000000 --- a/cmake/FindFoX.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# - Try to find FoX -# -# This can be controled by setting FoX_PATH or FoX__PATH Cmake variables, -# where is the COMPONENT language one needs. -# -# Once done, this will define: -# -# FoX__FOUND (BOOL) - system has FoX -# FoX__IS_SHARED (BOOL) - whether the library is shared/dynamic -# FoX__INCLUDE_DIR (PATH) - Location of the header files and modules -# FoX__LIBRARY (File) - Path to the library files -# FoX__LIBRARIES (List) - link these to use FoX -# -# Available COMPONENTS are: Fortran -# -include (LibFind) -include (LibCheck) - -# Define FoX Fortran Component -define_package_component(FoX DEFAULT - COMPONENT Fortran - INCLUDE_NAMES fox_common.mod - LIBRARY_NAMES FoX_common) - -# Search for list of valid components requested -find_valid_components(FoX) - -#============================================================================== -# SEARCH FOR VALIDATED COMPONENTS -foreach (pcomp IN LISTS FoX_FIND_VALID_COMPONENTS) - set(FoX_Fortran_INCLUDE_DIR $ENV{FoX}/finclude) - set(FoX_Fortran_LIBRARY $ENV{FoX}/lib) - initialize_paths(FoX_${pcomp}_PATHS - INCLUDE_DIRECTORIES $ENV{FoX}/finclude - LIBRARIES $ENV{FoX}/lib) - find_package_component(FoX COMPONENT ${pcomp}) -endforeach () -if(FoX_Fortran_FOUND) -message(" Found FoX: ${FoX_Fortran_INCLUDE_DIR}") -endif() \ No newline at end of file diff --git a/cmake/FindPIO.cmake b/cmake/FindPIO.cmake index 141834128d..2a7af648aa 100644 --- a/cmake/FindPIO.cmake +++ b/cmake/FindPIO.cmake @@ -47,7 +47,7 @@ foreach (pcomp IN LISTS PIO_FIND_VALID_COMPONENTS) find_package_component(PIO COMPONENT ${pcomp} PATHS ${PIO_${pcomp}_PATHS}) else () - find_package_component(PIO COMPONENT ${pcomp}) + find_package_component(PIO COMPONENT ${pcomp} HINT PIO_${pcomp}_PATH=${PIO_PATH}) endif () # Continue only if component found diff --git a/docn/ocn_comp_nuopc.F90 b/docn/ocn_comp_nuopc.F90 index 81c531c888..8b7300ad19 100644 --- a/docn/ocn_comp_nuopc.F90 +++ b/docn/ocn_comp_nuopc.F90 @@ -494,7 +494,6 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod !-------------------- ! Advance data model streams - time and spatially interpolate to model time and grid - call t_barrierf('docn_BARRIER',mpicom) call ESMF_TraceRegionEnter('docn_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'docn', rc=rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return @@ -502,7 +501,6 @@ subroutine docn_comp_run(importState, exportState, clock, target_ymd, target_tod ! Copy all fields from streams to export state as default ! This automatically will update the fields in the export state - call t_barrierf('docn_dfield_copy_BARRIER', mpicom) call ESMF_TraceRegionEnter('docn_dfield_copy') if(.not. aquaplanet) then call dshr_dfield_copy(dfields, sdat, rc) diff --git a/streams/CMakeLists.txt b/streams/CMakeLists.txt index 902b53adde..e57a520bc0 100644 --- a/streams/CMakeLists.txt +++ b/streams/CMakeLists.txt @@ -13,12 +13,13 @@ foreach(FILE ${SRCFILES}) endforeach() message("Stream srcfiles are ${SRCFILES}") add_library(streams ${SRCFILES}) +add_dependencies(streams FoX_dom) if(BLD_STANDALONE) add_dependencies(streams cdeps_share) endif() +target_include_directories (streams PUBLIC ${CMAKE_BINARY_DIR}/fox/include) target_include_directories (streams PUBLIC ${ESMF_F90COMPILEPATHS}) target_include_directories (streams PUBLIC ${PIO_Fortran_INCLUDE_DIR}) -target_include_directories (streams PUBLIC ${FoX_Fortran_INCLUDE_DIR}) target_include_directories (streams PUBLIC ${CMAKE_BINARY_DIR}/share) install(TARGETS streams LIBRARY DESTINATION lib) From fac382cc0dae2cb398fee54a05109630724fef7a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 6 Aug 2020 15:32:49 -0600 Subject: [PATCH 8/8] remove more t_barriers --- dwav/wav_comp_nuopc.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/dwav/wav_comp_nuopc.F90 b/dwav/wav_comp_nuopc.F90 index 2a39fdd630..d48abb636f 100644 --- a/dwav/wav_comp_nuopc.F90 +++ b/dwav/wav_comp_nuopc.F90 @@ -490,7 +490,6 @@ subroutine dwav_comp_run(mpicom, my_task, logunit, target_ymd, target_tod, sdat, !-------------------- ! time and spatially interpolate to model time and grid - call t_barrierf('dwav_BARRIER',mpicom) call ESMF_TraceRegionEnter('dwav_strdata_advance') call shr_strdata_advance(sdat, target_ymd, target_tod, logunit, 'dwav', rc=rc) call ESMF_TraceRegionExit('dwav_strdata_advance') @@ -500,7 +499,6 @@ subroutine dwav_comp_run(mpicom, my_task, logunit, target_ymd, target_tod, sdat, !-------------------- ! This automatically will update the fields in the export state - call t_barrierf('dwav_comp_strdata_copy_BARRIER', mpicom) call ESMF_TraceRegionEnter('dwav_strdata_copy') call dshr_dfield_copy(dfields, sdat, rc) if (ChkErr(rc,__LINE__,u_FILE_u)) return