Skip to content

Commit

Permalink
Merge pull request #71 from climbfuji/features/ipd-setup-step-fast-fo…
Browse files Browse the repository at this point in the history
…r-scm

features/ipd-setup-step-fast with SCM
  • Loading branch information
climbfuji authored Apr 17, 2018
2 parents 21ba2a5 + 68abcca commit 3bd48d5
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 28 deletions.
38 changes: 29 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ set(SOURCES
./physics/radlw_datatb.f
./physics/set_soilveg.f
./physics/namelist_soilveg.f
./physics/GFS_phys_time_vary.f90
./physics/GFS_phys_time_vary.scm.f90
./physics/ozinterp.f90
./physics/h2ointerp.f90
./physics/gcycle.f90
./physics/GFS_rad_time_vary.f90
./physics/GFS_rad_time_vary.scm.f90
./physics/GFS_radupdate.f90
./physics/GFS_suite_interstitial.ccpp.f90
./physics/get_prs_fv3.f90
Expand Down Expand Up @@ -166,6 +166,9 @@ set(SOURCES
./physics/precpd.f
./physics/GFS_calpreciptype.f90
./physics/GFS_MP_generic_post.f90
)

set(CAPS
./physics/cnvc90_cap.F90
./physics/lsm_noah_pre_cap.F90
./physics/GFS_DCNV_generic_post_cap.F90
Expand Down Expand Up @@ -235,31 +238,34 @@ set(SOURCES
)

if (${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
set(f_flags -ffree-line-length-none)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none")

SET_SOURCE_FILES_PROPERTIES(./physics/module_bfmicrophysics.f ./physics/rascnvv2.f ./physics/sflx.f ./physics/sfc_diff.f ./physics/sfc_diag.f PROPERTIES COMPILE_FLAGS -fdefault-real-8)
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_model.f90 ./physics/GFS_calpreciptype.f90 PROPERTIES COMPILE_FLAGS "-fdefault-real-8 -ffree-form")
SET_SOURCE_FILES_PROPERTIES(./physics/mersenne_twister.f PROPERTIES COMPILE_FLAGS "-fdefault-real-8 -fno-range-check")
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_water_prop.f90 PROPERTIES COMPILE_FLAGS "-ffree-line-length-none -fdefault-real-8 -ffree-form")
SET_SOURCE_FILES_PROPERTIES(./physics/aer_cloud.F ./physics/wv_saturation.F ./physics/cldwat2m_micro.F PROPERTIES COMPILE_FLAGS "-DNEMS_GSM -fdefault-real-8 -fdefault-double-8")
elseif (${CMAKE_Fortran_COMPILER_ID} MATCHES "Intel")

SET_SOURCE_FILES_PROPERTIES(./physics/module_bfmicrophysics.f ./physics/rascnvv2.f ./physics/sflx.f ./physics/sfc_diff.f ./physics/sfc_diag.f PROPERTIES COMPILE_FLAGS -r8)
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_model.f90 ./physics/GFS_calpreciptype.f90 PROPERTIES COMPILE_FLAGS "-r8 -free")
SET_SOURCE_FILES_PROPERTIES(./physics/mersenne_twister.f PROPERTIES COMPILE_FLAGS "-r8 -ftz")
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_water_prop.f90 PROPERTIES COMPILE_FLAGS "-extend-source 132 -r8 -free")
SET_SOURCE_FILES_PROPERTIES(./physics/aer_cloud.F ./physics/wv_saturation.F ./physics/cldwat2m_micro.F PROPERTIES COMPILE_FLAGS "-DNEMS_GSM -r8")
elseif (${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI")
SET_SOURCE_FILES_PROPERTIES(./physics/module_bfmicrophysics.f ./physics/rascnvv2.f ./physics/sflx.f ./physics/sfc_diff.f ./physics/sfc_diag.f PROPERTIES COMPILE_FLAGS -r8)
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_model.f90 ./physics/GFS_calpreciptype.f90 PROPERTIES COMPILE_FLAGS "-r8 -Mfree")
SET_SOURCE_FILES_PROPERTIES(./physics/mersenne_twister.f PROPERTIES COMPILE_FLAGS "-r8 -Mnofptrap")
SET_SOURCE_FILES_PROPERTIES(./physics/module_nst_water_prop.f90 PROPERTIES COMPILE_FLAGS "-r8 -Mfree")
SET_SOURCE_FILES_PROPERTIES(./physics/aer_cloud.F ./physics/wv_saturation.F ./physics/cldwat2m_micro.F PROPERTIES COMPILE_FLAGS "-DNEMS_GSM -r8")
else (${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message ("Fortran compiler: " ${CMAKE_Fortran_COMPILER_ID})
message (FATAL_ERROR "This program has only been compiled with gfortran and ifort. If another compiler is needed, the appropriate flags must be added in ${GFS_PHYS_SRC}/CMakeLists.txt")
message (FATAL_ERROR "This program has only been compiled with gfortran, pgf90 and ifort. If another compiler is needed, the appropriate flags must be added in ${GFS_PHYS_SRC}/CMakeLists.txt")
endif (${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")

#apply general fortran tags to all fortran source files
if(${CMAKE_VERSION} LESS 3.3)
string (REPLACE ";" " " f_flags_str "${f_flags}")
SET_PROPERTY(SOURCE ${GFS_phys_source_code} APPEND_STRING PROPERTY COMPILE_FLAGS " ${f_flags_str}")
SET_PROPERTY(SOURCE ${SOURCES} ${CAPS} APPEND_STRING PROPERTY COMPILE_FLAGS " ${f_flags_str}")
else(${CMAKE_VERSION} LESS 3.3)
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:${f_flags}>")
endif (${CMAKE_VERSION} LESS 3.3)
Expand Down Expand Up @@ -287,10 +293,24 @@ INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/bacio)
#)
#list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/scm_test1_cap.f90)


add_library(ccppphys ${SOURCES})
add_library(ccppphys ${SOURCES} ${CAPS})
target_link_libraries(ccppphys LINK_PUBLIC ${LIBS} w3 sp bacio)
set_target_properties(ccppphys PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
COMPILE_FLAGS "${CMAKE_Fortran_FLAGS}"
LINK_FLAGS "${CMAKE_Fortran_FLAGS}")
# DH* hack for PGI compiler: rename objects in scheme cap object files for ISO_C compliancy
if (${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI")
set(CAPOBJS)
foreach(cap ${CAPS})
string(REPLACE "_cap.F90" "_cap.F90.o" capobj "./${CMAKE_FILES_DIRECTORY}/ccppphys.dir/${cap}")
list(APPEND CAPOBJS ${capobj})
endforeach(cap)

add_custom_command(TARGET ccppphys
PRE_LINK
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/pgifix.py --cmake ${CAPOBJS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running pgifix_wrapper.py over all scheme caps")
endif (${CMAKE_Fortran_COMPILER_ID} MATCHES "PGI")
# *DH end hack for PGI compiler
9 changes: 3 additions & 6 deletions GFS_layer/GFS_initialize_scm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ end subroutine GFS_initialize_scm_finalize
!! | Cldprop | FV3-GFS_Cldprop_type | derived type GFS_cldprop_type in FV3 | DDT | 0 | GFS_cldprop_type | | inout | F |
!! | Radtend | FV3-GFS_Radtend_type | derived type GFS_radtend_type in FV3 | DDT | 0 | GFS_radtend_type | | inout | F |
!! | Diag | FV3-GFS_Diag_type | Fortran DDT containing FV3-GFS fields targeted for diagnostic output | DDT | 0 | GFS_diag_type | | inout | F |
!! | Sfccycle | FV3-GFS_Sfccycle_type | derived type GFS_sfccycle_type in FV3 | DDT | 0 | GFS_sfccycle_type | | inout | F |
!! | Interstitial | FV3-GFS_Interstitial_type | derived type GFS_interstitial_type in FV3 | DDT | 0 | GFS_interstitial_type | | inout | F |
!! | Init_parm | FV3-GFS_Init_type | dervied type GFS_init_type in FV3 | DDT | 0 | GFS_init_type | | in | F |
!! | n_ozone_layers | vertical_dimension_of_ozone_forcing_data_from_host | number of vertical layers in ozone forcing data coming from host | count | 0 | integer | | in | F |
Expand All @@ -51,7 +50,7 @@ end subroutine GFS_initialize_scm_finalize
!!
subroutine GFS_initialize_scm_run (Model, Statein, Stateout, Sfcprop, &
Coupling, Grid, Tbd, Cldprop, Radtend, Diag, &
Sfccycle, Interstitial, Init_parm, n_ozone_lats, &
Interstitial, Init_parm, n_ozone_lats, &
n_ozone_layers, n_ozone_times, n_ozone_coefficients, &
ozone_lat, ozone_pres, ozone_time, ozone_forcing_in, &
errmsg, errflg)
Expand All @@ -63,7 +62,7 @@ subroutine GFS_initialize_scm_run (Model, Statein, Stateout, Sfcprop,
GFS_control_type, GFS_grid_type, &
GFS_tbd_type, GFS_cldprop_type, &
GFS_radtend_type, GFS_diag_type, &
GFS_sfccycle_type, GFS_interstitial_type
GFS_interstitial_type
use funcphys, only: gfuncphys
use module_microphysics, only: gsmconst
use cldwat2m_micro, only: ini_micro
Expand All @@ -82,7 +81,6 @@ subroutine GFS_initialize_scm_run (Model, Statein, Stateout, Sfcprop,
type(GFS_cldprop_type), intent(inout) :: Cldprop
type(GFS_radtend_type), intent(inout) :: Radtend
type(GFS_diag_type), intent(inout) :: Diag
type(GFS_sfccycle_type), intent(inout) :: Sfccycle
type(GFS_interstitial_type), intent(inout) :: Interstitial
type(GFS_init_type), intent(in) :: Init_parm

Expand Down Expand Up @@ -133,8 +131,7 @@ subroutine GFS_initialize_scm_run (Model, Statein, Stateout, Sfcprop,
call Radtend%create(1, Model)
!--- internal representation of diagnostics
call Diag%create(1, Model)
!--- internal representation of sfccycle
call Sfccycle%create(1, Model)
!--- internal representation of interstitials for CCPP physics
call Interstitial%create(1, Model)

! !--- populate the grid components
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ SRCS_f90 = \
./physics/GFS_MP_generic_post.f90 \
./physics/GFS_MP_generic_pre.f90 \
./physics/GFS_zhao_carr_pre.f90 \
./physics/GFS_rad_time_vary.f90 \
./physics/GFS_rad_time_vary.fv3.f90 \
./physics/GFS_radupdate.f90 \
./physics/cs_conv.f90 \
./physics/funcphys.f90 \
Expand All @@ -153,7 +153,7 @@ SRCS_f90 = \
./physics/GFS_SCNV_generic.f90 \
./physics/GFS_PBL_generic.f90 \
$(GFS_SUITE_INTERSTITIAL) \
./physics/GFS_phys_time_vary.f90 \
./physics/GFS_phys_time_vary.fv3.f90 \
./physics/GFS_stochastics.f90 \
./physics/GFS_surface_generic.f90 \
./physics/h2ointerp.f90 \
Expand Down
29 changes: 19 additions & 10 deletions pgifix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import sys

parser = argparse.ArgumentParser(description='Fix cap objects produced by PGI compiler')
parser.add_argument("cap")
parser.add_argument("--cmake", default=False, action='store_true')
parser.add_argument("caps", nargs='+')

FIXCMD_TEMPLATE = 'objcopy '

def parse_args():
args = parser.parse_args()
cap = args.cap
return cap
cmake = args.cmake
caps = args.caps
return (cmake, caps)

def execute(cmd, debug = True, abort = True):
"""Runs a local command in a shell. Waits for completion and
Expand Down Expand Up @@ -39,9 +43,14 @@ def execute(cmd, debug = True, abort = True):
print message
return (status, stdout.rstrip('\n'), stderr.rstrip('\n'))

def correct_cap_object_names(fixcmd, cap):
def correct_cap_object_names(fixcmd, cmake, cap):
(cappath, capname) = os.path.split(cap)
pgiprefix = capname.rstrip('.o').lower() + '_'
# Determine pgi-prepended prefix to remove, different
# for cmake builds and make builds (object filename)
if cmake:
pgiprefix = capname.rstrip('.F90.o').lower() + '_'
else:
pgiprefix = capname.rstrip('.o').lower() + '_'
# Get list of all symbols in cap object
nmcmd = 'nm {0}'.format(cap)
(status, stdout, stderr) = execute(nmcmd)
Expand Down Expand Up @@ -74,11 +83,11 @@ def correct_object_names(fixcmd, cap):
execute(mvcmd)

def main():
cap = parse_args()
fixcmd = 'objcopy '
fixcmd = correct_cap_object_names(fixcmd, cap)
if not fixcmd == 'objcopy ':
(cmake, caps) = parse_args()
for cap in caps:
fixcmd = FIXCMD_TEMPLATE
fixcmd = correct_cap_object_names(fixcmd, cmake, cap)
correct_object_names(fixcmd, cap)

if __name__ == '__main__':
main()
main()
File renamed without changes.
Loading

0 comments on commit 3bd48d5

Please sign in to comment.