-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix for unit conversion error in ccpp_prebuild.py (variables that…
… are slices of a n+1 dimensional array have wrong allocation) (#600) ## Description 1. Bug fix in `scripts/mkstatic.py`: define `dim_string_allocate` so that temporary (group cap) variables of rank `n` that correspond to a slice of an `n+1` dimensional array have the right dimensions in the assignment calls and subroutine call lists. See the inline documentation added in `mkstatic.py` around line 1476 for more information. 2. Addition of test `test_prebuild/test_unit_conv` to test for the above and to test for the `capgen` issue reported in #594 (Unit conversion bug when variable is used by two different schemes with different units). Note that `ccpp_prebuild.py` did not suffer from this bug, but I wanted to make sure that we test for it. 3. In the development of the new test `test_unit_conv`, I discovered that we should declare all incoming host variables in the group caps as `target`. This is because it is tricky in prebuild to determine that a parent variable `bar` needs to have the `target` attribute in case a slice of it has the active attribute. This is a bit of an edge case, but I believe this additional attribute is safe. I will run full UFS RTs with this PR to check if the results are b4b or if the addition of `target` causes the compiler to optimize differently. 4. Minor updates to `test_prebuid/{test_blocked_data,test_chunked_data}`: fix wrong name of subroutines in diagnostic error messages, set thread number and thread counter to safe values when running over the entire domain.
- Loading branch information
Showing
19 changed files
with
658 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#------------------------------------------------------------------------------ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(ccpp_unit_conv | ||
VERSION 1.0.0 | ||
LANGUAGES Fortran) | ||
|
||
#------------------------------------------------------------------------------ | ||
# Request a static build | ||
option(BUILD_SHARED_LIBS "Build a shared library" OFF) | ||
|
||
#------------------------------------------------------------------------------ | ||
# Set MPI flags for C/C++/Fortran with MPI F08 interface | ||
find_package(MPI REQUIRED Fortran) | ||
if(NOT MPI_Fortran_HAVE_F08_MODULE) | ||
message(FATAL_ERROR "MPI implementation does not support the Fortran 2008 mpi_f08 interface") | ||
endif() | ||
|
||
#------------------------------------------------------------------------------ | ||
# Set the sources: physics type definitions | ||
set(TYPEDEFS $ENV{CCPP_TYPEDEFS}) | ||
if(TYPEDEFS) | ||
message(STATUS "Got CCPP TYPEDEFS from environment variable: ${TYPEDEFS}") | ||
else(TYPEDEFS) | ||
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_TYPEDEFS.cmake) | ||
message(STATUS "Got CCPP TYPEDEFS from cmakefile include file: ${TYPEDEFS}") | ||
endif(TYPEDEFS) | ||
|
||
# Generate list of Fortran modules from the CCPP type | ||
# definitions that need need to be installed | ||
foreach(typedef_module ${TYPEDEFS}) | ||
list(APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR}/${typedef_module}) | ||
endforeach() | ||
|
||
#------------------------------------------------------------------------------ | ||
# Set the sources: physics schemes | ||
set(SCHEMES $ENV{CCPP_SCHEMES}) | ||
if(SCHEMES) | ||
message(STATUS "Got CCPP SCHEMES from environment variable: ${SCHEMES}") | ||
else(SCHEMES) | ||
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_SCHEMES.cmake) | ||
message(STATUS "Got CCPP SCHEMES from cmakefile include file: ${SCHEMES}") | ||
endif(SCHEMES) | ||
|
||
# Set the sources: physics scheme caps | ||
set(CAPS $ENV{CCPP_CAPS}) | ||
if(CAPS) | ||
message(STATUS "Got CCPP CAPS from environment variable: ${CAPS}") | ||
else(CAPS) | ||
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_CAPS.cmake) | ||
message(STATUS "Got CCPP CAPS from cmakefile include file: ${CAPS}") | ||
endif(CAPS) | ||
|
||
# Set the sources: physics scheme caps | ||
set(API $ENV{CCPP_API}) | ||
if(API) | ||
message(STATUS "Got CCPP API from environment variable: ${API}") | ||
else(API) | ||
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_API.cmake) | ||
message(STATUS "Got CCPP API from cmakefile include file: ${API}") | ||
endif(API) | ||
|
||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -O0 -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -ffpe-trap=invalid,zero,overflow -fbounds-check -ggdb -fbacktrace -ffree-line-length-none") | ||
|
||
#------------------------------------------------------------------------------ | ||
add_library(ccpp_unit_conv STATIC ${SCHEMES} ${CAPS} ${API}) | ||
target_link_libraries(ccpp_unit_conv PRIVATE MPI::MPI_Fortran) | ||
# Generate list of Fortran modules from defined sources | ||
foreach(source_f90 ${CAPS} ${API}) | ||
get_filename_component(tmp_source_f90 ${source_f90} NAME) | ||
string(REGEX REPLACE ".F90" ".mod" tmp_module_f90 ${tmp_source_f90}) | ||
string(TOLOWER ${tmp_module_f90} module_f90) | ||
list(APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR}/${module_f90}) | ||
endforeach() | ||
|
||
set_target_properties(ccpp_unit_conv PROPERTIES VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR}) | ||
|
||
add_executable(test_unit_conv.x main.F90) | ||
add_dependencies(test_unit_conv.x ccpp_unit_conv) | ||
target_link_libraries(test_unit_conv.x ccpp_unit_conv) | ||
set_target_properties(test_unit_conv.x PROPERTIES LINKER_LANGUAGE Fortran) | ||
|
||
# Define where to install the library | ||
install(TARGETS ccpp_unit_conv | ||
EXPORT ccpp_unit_conv-targets | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION lib | ||
) | ||
# Export our configuration | ||
install(EXPORT ccpp_unit_conv-targets | ||
FILE ccpp_unit_conv-config.cmake | ||
DESTINATION lib/cmake | ||
) | ||
# Define where to install the C headers and Fortran modules | ||
#install(FILES ${HEADERS_C} DESTINATION include) | ||
install(FILES ${MODULES_F90} DESTINATION include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# How to build the unit conv test | ||
|
||
1. Set compiler environment as appropriate for your system | ||
2. Run the following commands: | ||
``` | ||
cd test_prebuild/test_unit_conv/ | ||
rm -fr build | ||
mkdir build | ||
../../scripts/ccpp_prebuild.py --config=ccpp_prebuild_config.py --builddir=build | ||
cd build | ||
cmake .. 2>&1 | tee log.cmake | ||
make 2>&1 | tee log.make | ||
./test_unit_conv.x | ||
# On systems where linking against the MPI library requires a parallel launcher, | ||
# use 'mpirun -np 1 ./test_unit_conv.x' or 'srun -n 1 ./test_unit_conv.x' etc. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ccpp_kinds | ||
|
||
!! \section arg_table_ccpp_kinds | ||
!! \htmlinclude ccpp_kinds.html | ||
!! | ||
|
||
use iso_fortran_env, only: real64 | ||
|
||
implicit none | ||
|
||
integer, parameter :: kind_phys = real64 | ||
|
||
end module ccpp_kinds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ccpp-table-properties] | ||
name = ccpp_kinds | ||
type = module | ||
dependencies = | ||
|
||
######################################################################## | ||
[ccpp-arg-table] | ||
name = ccpp_kinds | ||
type = module | ||
[kind_phys] | ||
standard_name = kind_phys | ||
long_name = definition of kind_phys | ||
units = none | ||
dimensions = () | ||
type = integer |
Oops, something went wrong.