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

ccpp-physics scm pgi support #70

Merged
merged 3 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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
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()
8 changes: 7 additions & 1 deletion physics/mfpbl.f
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
!> \ingroup GFS_edmf_main
!! \brief This subroutine is used for calculating the mass flux and updraft properties.
!!
!! The mfpbl routines works as follows: if the PBL is convective, first, the ascending parcel entrainment rate is calculated as a function of height. Next, a surface parcel is initiated according to surface layer properties and the updraft buoyancy is calculated as a function of height. Next, using the buoyancy and entrainment values, the parcel vertical velocity is calculated using a well known steady-state budget equation. With the profile of updraft vertical velocity, the PBL height is recalculated as the height where the updraft vertical velocity returns to 0, and the entrainment profile is updated with the new PBL height. Finally, the mass flux profile is calculated using the updraft vertical velocity and assumed updraft fraction and the updraft properties are calculated using the updated entrainment profile, surface values, and environmental profiles.
!! The mfpbl routines works as follows: if the PBL is convective, first, the ascending parcel entrainment rate is calculated as a
!! function of height. Next, a surface parcel is initiated according to surface layer properties and the updraft buoyancy is calculated
!! as a function of height. Next, using the buoyancy and entrainment values, the parcel vertical velocity is calculated using a well
!! known steady-state budget equation. With the profile of updraft vertical velocity, the PBL height is recalculated as the height
!! where the updraft vertical velocity returns to 0, and the entrainment profile is updated with the new PBL height. Finally, the mass
!! flux profile is calculated using the updraft vertical velocity and assumed updraft fraction and the updraft properties are calculated
!! using the updated entrainment profile, surface values, and environmental profiles.
!! \param[in] im integer, number of used points
!! \param[in] ix integer, horizontal dimension
!! \param[in] km integer, vertical layer dimension
Expand Down