diff --git a/scripts/common.py b/scripts/common.py index 34fb131a..a4b43eb7 100755 --- a/scripts/common.py +++ b/scripts/common.py @@ -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' diff --git a/scripts/mkstatic.py b/scripts/mkstatic.py index cd389b3b..576abdf8 100755 --- a/scripts/mkstatic.py +++ b/scripts/mkstatic.py @@ -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 @@ -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' : '', @@ -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) @@ -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) diff --git a/stub/CMakeLists.txt b/stub/CMakeLists.txt index 9ee7ce9f..4550036f 100644 --- a/stub/CMakeLists.txt +++ b/stub/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/stub/README.md b/stub/README.md index e641aece..19c47c25 100644 --- a/stub/README.md +++ b/stub/README.md @@ -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 ``` diff --git a/stub/ccpp_prebuild_config.py b/stub/ccpp_prebuild_config.py index 31aeccfb..c95a41f6 100755 --- a/stub/ccpp_prebuild_config.py +++ b/stub/ccpp_prebuild_config.py @@ -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' @@ -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 diff --git a/test/unit_tests/test_common.py b/test/unit_tests/test_common.py index fe57caa6..fe5f852d 100755 --- a/test/unit_tests/test_common.py +++ b/test/unit_tests/test_common.py @@ -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")