Skip to content

Commit

Permalink
Merge pull request #498 from climbfuji/feature/remove_ccpp_hardcoded_…
Browse files Browse the repository at this point in the history
…name_and_update_stub

(main) ccpp_prebuild: fix hardcoded name of ccpp_t host variable, update CCPP stub, fix capgen unit tests
  • Loading branch information
climbfuji authored Sep 7, 2023
2 parents 57d268c + 64ba62b commit 3a8f278
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CCPP_STAGES['run'] = 'run'
CCPP_STAGES['finalize'] = 'final'

CCPP_T_INSTANCE_VARIABLE = 'ccpp_t_instance'
CCPP_CONSTANT_ONE = 'ccpp_constant_one'
CCPP_ERROR_CODE_VARIABLE = 'ccpp_error_code'
CCPP_ERROR_MSG_VARIABLE = 'ccpp_error_message'
Expand Down
21 changes: 13 additions & 8 deletions scripts/mkstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from common import encode_container
from common import CCPP_STAGES
from common import CCPP_ERROR_CODE_VARIABLE, CCPP_ERROR_MSG_VARIABLE, CCPP_LOOP_COUNTER, CCPP_LOOP_EXTENT
from common import CCPP_T_INSTANCE_VARIABLE, CCPP_ERROR_CODE_VARIABLE, CCPP_ERROR_MSG_VARIABLE, CCPP_LOOP_COUNTER, CCPP_LOOP_EXTENT
from common import CCPP_BLOCK_NUMBER, CCPP_BLOCK_COUNT, CCPP_BLOCK_SIZES, CCPP_THREAD_NUMBER, CCPP_INTERNAL_VARIABLES
from common import CCPP_CONSTANT_ONE, CCPP_HORIZONTAL_DIMENSION, CCPP_HORIZONTAL_LOOP_EXTENT, CCPP_NUM_INSTANCES
from common import FORTRAN_CONDITIONAL_REGEX_WORDS, FORTRAN_CONDITIONAL_REGEX
Expand Down Expand Up @@ -930,37 +930,37 @@ class Group(object):

initialized_test_blocks = {
'init' : '''
if (initialized(cdata%ccpp_instance)) return
if (initialized({ccpp_var_name}%ccpp_instance)) return
''',
'timestep_init' : '''
if (.not.initialized(cdata%ccpp_instance)) then
if (.not.initialized({ccpp_var_name}%ccpp_instance)) then
write({target_name_msg},'(*(a))') '{name}_timestep_init called before {name}_init'
{target_name_flag} = 1
return
end if
''',
'run' : '''
if (.not.initialized(cdata%ccpp_instance)) then
if (.not.initialized({ccpp_var_name}%ccpp_instance)) then
write({target_name_msg},'(*(a))') '{name}_run called before {name}_init'
{target_name_flag} = 1
return
end if
''',
'timestep_finalize' : '''
if (.not.initialized(cdata%ccpp_instance)) then
if (.not.initialized({ccpp_var_name}%ccpp_instance)) then
write({target_name_msg},'(*(a))') '{name}_timestep_finalize called before {name}_init'
{target_name_flag} = 1
return
end if
''',
'finalize' : '''
if (.not.initialized(cdata%ccpp_instance)) return
if (.not.initialized({ccpp_var_name}%ccpp_instance)) return
''',
}

initialized_set_blocks = {
'init' : '''
initialized(cdata%ccpp_instance) = .true.
initialized({ccpp_var_name}%ccpp_instance) = .true.
''',
'timestep_init' : '',
'run' : '',
Expand Down Expand Up @@ -999,7 +999,10 @@ def write(self, metadata_request, metadata_define, arguments, debug):
ccpp_loop_extent_target_name = metadata_request[CCPP_LOOP_EXTENT][0].target
ccpp_error_code_target_name = metadata_request[CCPP_ERROR_CODE_VARIABLE][0].target
ccpp_error_msg_target_name = metadata_request[CCPP_ERROR_MSG_VARIABLE][0].target
#
# Then, identify the variable name of the mandatory ccpp_t variable defined by the host model
ccpp_var = metadata_define[CCPP_T_INSTANCE_VARIABLE][0]

# Init
module_use = ''
self._module = 'ccpp_{suite}_{name}_cap'.format(name=self._name, suite=self._suite)
self._filename = '{module_name}.F90'.format(module_name=self._module)
Expand Down Expand Up @@ -1624,12 +1627,14 @@ def write(self, metadata_request, metadata_define, arguments, debug):
# at least one subroutine that gets called from this group), or skip.
if self.arguments[ccpp_stage]:
initialized_test_block = Group.initialized_test_blocks[ccpp_stage].format(
ccpp_var_name = ccpp_var.local_name,
target_name_flag=ccpp_error_code_target_name,
target_name_msg=ccpp_error_msg_target_name,
name=self._name)
else:
initialized_test_block = ''
initialized_set_block = Group.initialized_set_blocks[ccpp_stage].format(
ccpp_var_name = ccpp_var.local_name,
target_name_flag=ccpp_error_code_target_name,
target_name_msg=ccpp_error_msg_target_name,
name=self._name)
Expand Down
8 changes: 4 additions & 4 deletions stub/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(TYPEDEFS $ENV{CCPP_TYPEDEFS})
if(TYPEDEFS)
message(STATUS "Got CCPP TYPEDEFS from environment variable: ${TYPEDEFS}")
else(TYPEDEFS)
include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_TYPEDEFS.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_TYPEDEFS.cmake)
message(STATUS "Got CCPP TYPEDEFS from cmakefile include file: ${TYPEDEFS}")
endif(TYPEDEFS)

Expand All @@ -31,7 +31,7 @@ set(SCHEMES $ENV{CCPP_SCHEMES})
if(SCHEMES)
message(STATUS "Got CCPP SCHEMES from environment variable: ${SCHEMES}")
else(SCHEMES)
include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_SCHEMES.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_SCHEMES.cmake)
message(STATUS "Got CCPP SCHEMES from cmakefile include file: ${SCHEMES}")
endif(SCHEMES)

Expand All @@ -40,7 +40,7 @@ set(CAPS $ENV{CCPP_CAPS})
if(CAPS)
message(STATUS "Got CCPP CAPS from environment variable: ${CAPS}")
else(CAPS)
include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_CAPS.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_CAPS.cmake)
message(STATUS "Got CCPP CAPS from cmakefile include file: ${CAPS}")
endif(CAPS)

Expand All @@ -49,7 +49,7 @@ set(API $ENV{CCPP_API})
if(API)
message(STATUS "Got CCPP API from environment variable: ${API}")
else(API)
include(${CMAKE_CURRENT_SOURCE_DIR}/CCPP_API.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/CCPP_API.cmake)
message(STATUS "Got CCPP API from cmakefile include file: ${API}")
endif(API)

Expand Down
9 changes: 5 additions & 4 deletions stub/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# How to build the stub

Note: build is in-source for now

1. Set compiler environment as appropriate for your system
2. Run the following commands:
```
cd stub
../scripts/ccpp_prebuild.py --config=ccpp_prebuild_config.py
cmake . 2>&1 | tee log.cmake
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
```
4 changes: 2 additions & 2 deletions stub/ccpp_prebuild_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Default build dir, relative to current working directory,
# if not specified as command-line argument
DEFAULT_BUILD_DIR = '.'
DEFAULT_BUILD_DIR = 'build'

# Auto-generated makefile/cmakefile snippets that contain all type definitions
TYPEDEFS_MAKEFILE = '{build_dir}/CCPP_TYPEDEFS.mk'
Expand All @@ -54,7 +54,7 @@
CAPS_DIR = '{build_dir}'

# Directory where the suite definition files are stored
SUITES_DIR = '{build_dir}'
SUITES_DIR = '.'

# Optional arguments - only required for schemes that use
# optional arguments. ccpp_prebuild.py will throw an exception
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_FILE = os.path.basename(os.path.abspath(__file__))
TEST_FILE = os.path.abspath(os.path.abspath(__file__))
SCRIPTS_DIR = os.path.abspath(os.path.join(TEST_DIR, os.pardir, os.pardir, "scripts"))
SAMPLE_FILES_DIR = os.path.join(TEST_DIR, "sample_files")

Expand Down

0 comments on commit 3a8f278

Please sign in to comment.