From 3429f826157629dc94fdb4117deecf4e22052570 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 18 Nov 2024 16:14:13 +0100 Subject: [PATCH 1/5] Remove STELLA --- .gitignore | 1 + CMakeLists.txt | 50 - cmake/modules/FindSTELLA.cmake | 57 - cmake/modules/FindSphinx.cmake | 3 +- docs/latex/ppser_doc.tex | 2 +- docs/sphinx/Building.rst | 21 - src/serialbox-c/Serializer.h | 2 +- src/serialbox-python/pp_ser/pp_ser.py | 1056 ++++++++++------- src/serialbox-python/serialbox/serializer.py | 410 +++++-- src/serialbox/core/CMakeLists.txt | 9 - src/serialbox/core/SerializerImpl.cpp | 2 +- .../core/frontend/stella/DataFieldInfo.cpp | 211 ---- .../core/frontend/stella/DataFieldInfo.h | 232 ---- .../core/frontend/stella/ForwardDecl.h | 39 - .../core/frontend/stella/IJKBoundary.h | 116 -- src/serialbox/core/frontend/stella/IJKSize.h | 82 -- .../core/frontend/stella/KBoundary.h | 78 -- .../core/frontend/stella/MetainfoSet.cpp | 150 --- .../core/frontend/stella/MetainfoSet.h | 198 ---- .../core/frontend/stella/Savepoint.cpp | 110 -- .../core/frontend/stella/Savepoint.h | 112 -- .../frontend/stella/SerializationException.h | 54 - .../core/frontend/stella/Serializer.cpp | 294 ----- .../core/frontend/stella/Serializer.h | 437 ------- src/serialbox/core/frontend/stella/TypeName.h | 41 - src/serialbox/core/frontend/stella/Utility.h | 93 -- src/serialbox/stella/Serialbox.h | 35 - test/CMakeLists.txt | 4 - test/benchmark/CMakeLists.txt | 4 +- test/serialbox/core/CMakeLists.txt | 10 - .../frontend/stella/UnittestDataFieldInfo.cpp | 92 -- .../frontend/stella/UnittestException.cpp | 39 - .../frontend/stella/UnittestMetainfoSet.cpp | 160 --- .../frontend/stella/UnittestSavepoint.cpp | 70 -- .../frontend/stella/UnittestSerializer.cpp | 555 --------- .../frontend/stella/UnittestStorageView.cpp | 381 ------ .../core/frontend/stella/UnittestUtility.cpp | 61 - test/utility/CMakeLists.txt | 1 - test/utility/Config.h.cmake | 3 - test/utility/STELLA.h | 93 -- test/utility/Storage.h | 2 +- tools/cscs-scripts/build.sh | 15 +- 42 files changed, 930 insertions(+), 4455 deletions(-) delete mode 100644 cmake/modules/FindSTELLA.cmake delete mode 100644 src/serialbox/core/frontend/stella/DataFieldInfo.cpp delete mode 100644 src/serialbox/core/frontend/stella/DataFieldInfo.h delete mode 100644 src/serialbox/core/frontend/stella/ForwardDecl.h delete mode 100644 src/serialbox/core/frontend/stella/IJKBoundary.h delete mode 100644 src/serialbox/core/frontend/stella/IJKSize.h delete mode 100644 src/serialbox/core/frontend/stella/KBoundary.h delete mode 100644 src/serialbox/core/frontend/stella/MetainfoSet.cpp delete mode 100644 src/serialbox/core/frontend/stella/MetainfoSet.h delete mode 100644 src/serialbox/core/frontend/stella/Savepoint.cpp delete mode 100644 src/serialbox/core/frontend/stella/Savepoint.h delete mode 100644 src/serialbox/core/frontend/stella/SerializationException.h delete mode 100644 src/serialbox/core/frontend/stella/Serializer.cpp delete mode 100644 src/serialbox/core/frontend/stella/Serializer.h delete mode 100644 src/serialbox/core/frontend/stella/TypeName.h delete mode 100644 src/serialbox/core/frontend/stella/Utility.h delete mode 100644 src/serialbox/stella/Serialbox.h delete mode 100644 test/serialbox/core/frontend/stella/UnittestDataFieldInfo.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestException.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestMetainfoSet.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestSavepoint.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestSerializer.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestStorageView.cpp delete mode 100644 test/serialbox/core/frontend/stella/UnittestUtility.cpp delete mode 100644 test/utility/STELLA.h diff --git a/.gitignore b/.gitignore index 9792c3ff..e1abe858 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ gh-pages* #theia/vscode/gitpod settings /compile_commands.json /.clangd +/.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index 80666bee..d652fd39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ option(SERIALBOX_USE_NETCDF "Use NetCDF library" OFF) option(SERIALBOX_TESTING "Build unittest executables" OFF) option(SERIALBOX_TESTING_GRIDTOOLS "Build gridtools unitests and examples" OFF) -option(SERIALBOX_TESTING_STELLA "Build STELLA unitests" OFF) option(SERIALBOX_TESTING_DEATH_TESTS "Run death-tests" OFF) option(SERIALBOX_TESTING_LARGE_FILE_TESTS "Run large file (>4GB) tests" OFF) option(SERIALBOX_TESTING_FORTRAN "Build tests for the Fortran interface") @@ -162,7 +161,6 @@ set(SERIALBOX_EXTERNAL_LIBRARIES) ## Enable testing if one ore more of the tests is requested if(SERIALBOX_TESTING_GRIDTOOLS OR - SERIALBOX_TESTING_STELLA OR SERIALBOX_TESTING_DEATH_TESTS OR SERIALBOX_TESTING_FORTRAN) set(SERIALBOX_TESTING ON) @@ -250,54 +248,6 @@ endif(SERIALBOX_TESTING_GRIDTOOLS) find_package(Boost 1.54 REQUIRED) set(SERIALBOX_BOOST_VERSION ${Boost_VERSION}) -#---------------------------------------- STELLA --------------------------------------------------- -if(SERIALBOX_TESTING_STELLA) - - # If STELLA_ROOT is not provided, we try to find it in external/ - set(STELLA_ROOT_ENV "$ENV{STELLA_ROOT}") - if(NOT(STELLA_ROOT) AND NOT(STELLA_ROOT_ENV) AND - EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/stella/CMakeLists.txt") - - set(STELLA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/external/stella") - - set(BUILD_STELLA "ON" BOOL) - set(STELLA_INSTALL_DIR "${CMAKE_BINARY_DIR}/external/stella/install") - - # Forward toolchain - set(CMAKE_EXTERNAL_ARGS -Wno-dev - -DSTELLA_ENABLE_BENCHMARK=OFF - -DSTELLA_ENABLE_COMMUNICATION=OFF - -DSTELLA_ENABLE_SERIALIZATION=OFF - -DSTELLA_ENABLE_TESTING=OFF - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_GENERATOR=${CMAKE_GENERATOR} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_INSTALL_PREFIX=${STELLA_INSTALL_DIR} - ) - - # Build STELLA - ExternalProject_Add( - stella - URL "${CMAKE_CURRENT_SOURCE_DIR}/external/stella" - PREFIX "external/stella" - CMAKE_ARGS ${CMAKE_EXTERNAL_ARGS} - ) - message(STATUS "Building STELLA from: ${CMAKE_CURRENT_SOURCE_DIR}/external/stella") - - set(STELLA_INCLUDE_DIRS "${STELLA_INSTALL_DIR}/include/STELLA") - set(STELLA_LIBRARIES "${STELLA_INSTALL_DIR}/lib/libSharedInfrastructure.a" - "${STELLA_INSTALL_DIR}/lib/libStella.a" - "${STELLA_INSTALL_DIR}/lib/libStellaUtils.a") - else() - find_package(STELLA QUIET REQUIRED) - endif() - - include_directories(SYSTEM ${STELLA_INCLUDE_DIRS}) - set(SERIALBOX_HAS_STELLA 1) - -endif(SERIALBOX_TESTING_STELLA) - #---------------------------------------- ClangTools ----------------------------------------------- find_package(ClangTools) diff --git a/cmake/modules/FindSTELLA.cmake b/cmake/modules/FindSTELLA.cmake deleted file mode 100644 index 71b48a1f..00000000 --- a/cmake/modules/FindSTELLA.cmake +++ /dev/null @@ -1,57 +0,0 @@ -# Try to find STELLA libraries and headers. -# -# Usage of this module as follows: -# -# find_package(STELLA) -# -# Variables used by this module, they can change the default behaviour and need -# to be set before calling find_package: -# -# STELLA_ROOT Set this variable to the root installation of -# STELLA if the module has problems finding the -# proper installation path. -# -# Variables defined by this module: -# -# STELLA_FOUND System has STELLA libraries and headers -# STELLA_INCLUDE_DIRS The location of STELLA headers -# STELLA_LIBRARIES The location of STELLA libraries - -find_path(STELLA_ROOT NAMES include/STELLA) - -# Look for Serialbox libraries -function(stella_find_library name) - find_library(${name} NAMES ${ARGN} HINTS $ENV{STELLA_ROOT}/lib ${STELLA_ROOT}/lib) - mark_as_advanced(${name}) -endfunction() - -stella_find_library(STELLA_LIBRARY_SHARED_INFRASTRUCTURE SharedInfrastructure) -stella_find_library(STELLA_LIBRARY_STELLA Stella) -stella_find_library(STELLA_LIBRARY_STELLA_UTILS StellaUtils) - -set(STELLA_LIBRARIES - ${STELLA_LIBRARY_SHARED_INFRASTRUCTURE} - ${STELLA_LIBRARY_STELLA} - ${STELLA_LIBRARY_STELLA_UTILS} -) - -# Look for STELLA headers -find_path(STELLA_INCLUDE_DIRS - NAMES Stencil.h - HINTS ${STELLA_ROOT}/include/STELLA - $ENV{STELLA_ROOT}/include/STELLA -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(STELLA DEFAULT_MSG STELLA_INCLUDE_DIRS STELLA_LIBRARIES) - -if(STELLA_FOUND) - mark_as_advanced(STELLA_INCLUDE_DIRS STELLA_LIBRARIES) - message(STATUS "STELLA found at ${STELLA_ROOT}") -else() - # If the package was required we abort the process - if(${STELLA_FIND_REQUIRED}) - message(FATAL_ERROR "Could NOT find STELLA. (Try setting STELLA_ROOT in the env)") - endif(${STELLA_FIND_REQUIRED}) -endif() - diff --git a/cmake/modules/FindSphinx.cmake b/cmake/modules/FindSphinx.cmake index 9c0cb5d7..93d7159b 100644 --- a/cmake/modules/FindSphinx.cmake +++ b/cmake/modules/FindSphinx.cmake @@ -7,7 +7,7 @@ # Variables defined by this module: # # SPHINX_FOUND System has Sphinx -# STELLA_EXECUTABLE The location sphinx-build +# SPHINX_EXECUTABLE The location sphinx-build # include(FindPackageHandleStandardArgs) @@ -20,4 +20,3 @@ find_program(SPHINX_EXECUTABLE find_package_handle_standard_args(Sphinx "Failed to locate sphinx-build executable" SPHINX_EXECUTABLE) - diff --git a/docs/latex/ppser_doc.tex b/docs/latex/ppser_doc.tex index 62940f9e..71fc5702 100644 --- a/docs/latex/ppser_doc.tex +++ b/docs/latex/ppser_doc.tex @@ -23,7 +23,7 @@ \begin{document} \maketitle -\ppser{} is a parser to expand \texttt{!\$SER} serialization directives in Fortran code in order to generate serialization code using the \texttt{m\_serialize.f90} interface for the STELLA serialization framework. +\ppser{} is a parser to expand \texttt{!\$SER} serialization directives in Fortran code in order to generate serialization code using the \texttt{m\_serialize.f90} interface. The grammar is defined by a set of \texttt{!\$SER} directives. All directives are case-insensitive. The main keywords are \texttt{INIT} for initialization, \texttt{VERBATIM} for echoing some Fortran statements, \texttt{OPTION} for setting specific options for the serialization module, \texttt{REGISTER} for registering a data field meta-information, \texttt{ZERO} for setting some field to zero, \texttt{SAVEPOINT} for registering a savepoint with some optional information, \texttt{DATA} for serializing a data field, and \texttt{CLEANUP} for finishing serialization. diff --git a/docs/sphinx/Building.rst b/docs/sphinx/Building.rst index e8bb3629..1b18b0ae 100644 --- a/docs/sphinx/Building.rst +++ b/docs/sphinx/Building.rst @@ -70,17 +70,6 @@ Serialbox has several unittest which use the external library they are built for $ cmake -DSERIALBOX_TESTING=ON -DSERIALBOX_TESTING_GRIDTOOLS=ON -DSERIALBOX_GRIDTOOLS_ROOT= ../ -Similarly, you can build the unittest for `STELLA `_ and the compatible tests with the old `Serialbox `_. If you clone those projects in ``external/``, CMake will automatically find and **build** them. The following will enable all possible unittests: - -.. code-block:: console - - $ cd $(git rev-parse --show-toplevel) # Change to top-level directory - $ git clone git@github.com:eth-cscs/gridtools.git external/gridtools - $ git clone git@github.com:MeteoSwiss-APN/stella.git external/stella - $ git clone https://github.com/MeteoSwiss-APN/serialbox external/serialbox - $ cd build - $ cmake -DSERIALBOX_TESTING=ON -DSERIALBOX_TESTING_GRIDTOOLS=ON -DSERIALBOX_TESTING_OLD_SERIALBOX=ON -DSERIALBOX_TESTING_STELLA=ON ../ - To run the unittests via CTest: .. code-block:: console @@ -227,12 +216,6 @@ Serialbox specific variables **SERIALBOX_TESTING_GRIDTOOLS**:BOOL Build `gridtools `_ unittests and examples. -**SERIALBOX_TESTING_STELLA**:BOOL - Build `STELLA `_ unittests. - -**SERIALBOX_TESTING_OLD_SERIALBOX**:BOOL - Build the compatiblity unitests against the old `Serialbox `_. - **SERIALBOX_TESTING_DEATH_TESTS**:BOOL Compile the death-tests. @@ -260,9 +243,5 @@ External project specific variables **SERIALBOX_OLD_ROOT**:PATH Install directory of old `Serialbox `_. -**STELLA_ROOT**:PATH - Install directory of `STELLA `_. - **NETCDF_ROOT**:PATH Install directory of `NetCDF-4 `_. - diff --git a/src/serialbox-c/Serializer.h b/src/serialbox-c/Serializer.h index 4360486e..fe64a63f 100644 --- a/src/serialbox-c/Serializer.h +++ b/src/serialbox-c/Serializer.h @@ -98,7 +98,7 @@ SERIALBOX_API void serialboxSerializerUpdateMetaData(serialboxSerializer_t* seri * The return value can be: * * 0: the variable is not yet initialized -> the serialization is enabled if the environment - * variable `STELLA_SERIALIZATION_DISABLE` or `SERIALBOX_SERIALIZATION_DISABLE` is not set to a + * variable `SERIALBOX_SERIALIZATION_DISABLE` is not set to a * positive value. The first Serializer which is initialized has to set this value either to +1 * or to -1 according to the environment. * +1: the serialization is enabled, independently of the environment diff --git a/src/serialbox-python/pp_ser/pp_ser.py b/src/serialbox-python/pp_ser/pp_ser.py index fb80ccef..2aba04ed 100755 --- a/src/serialbox-python/pp_ser/pp_ser.py +++ b/src/serialbox-python/pp_ser/pp_ser.py @@ -23,8 +23,7 @@ pp_ser.py Parser to expand $!SER serialization directives in Fortran code in order to generate -serialization code using the m_serialize.f90 interface for the STELLA serialization -framework. +serialization code using the m_serialize.f90 interface. The grammar is defined by a set of !$SER directives. All directives are case- insensitive. The main keywords are INIT for initialization, VERBATIM for echoeing @@ -40,23 +39,23 @@ """ # information -__author__ = 'Oliver Fuhrer' -__copyright__ = 'Copyright 2014, MeteoSwiss' -__license__ = 'GPL' -__version__ = '0.1' -__date__ = 'Sun Mar 23 22:06:44 2014' -__email__ = 'oliver.fuhrer@meteoswiss.ch' +__author__ = "Oliver Fuhrer" +__copyright__ = "Copyright 2014, MeteoSwiss" +__license__ = "GPL" +__version__ = "0.1" +__date__ = "Sun Mar 23 22:06:44 2014" +__email__ = "oliver.fuhrer@meteoswiss.ch" def to_ascii(text): if sys.version_info[0] == 3: - return bytes(text, 'ascii') + return bytes(text, "ascii") else: return str(text) def filter_fortran(f): - return (f.split('.')[-1].lower() in ['f90', 'inc', 'incf', 'f', 'f03']) + return f.split(".")[-1].lower() in ["f90", "inc", "incf", "f", "f03"] def build_tree(src, dest, filtered_list, file_filter): @@ -64,237 +63,265 @@ def build_tree(src, dest, filtered_list, file_filter): if not os.path.isdir(dest): os.makedirs(dest) files = os.listdir(src) - filtered_list.extend([os.path.join(src, f) for f in files if os.path.isfile(os.path.join(src, f)) and file_filter(f)]) + filtered_list.extend( + [ + os.path.join(src, f) + for f in files + if os.path.isfile(os.path.join(src, f)) and file_filter(f) + ] + ) dirs = [f for f in files if os.path.isdir(os.path.join(src, f))] for d in dirs: - build_tree(os.path.join(src, d), os.path.join(dest, d), filtered_list, file_filter) + build_tree( + os.path.join(src, d), os.path.join(dest, d), filtered_list, file_filter + ) else: if os.path.isfile(src) and file_filter(src): filtered_list.append(src) class PpSer: - - def __init__(self, infile, outfile='', ifdef='SERIALIZE', real='ireals', - module='m_serialize', identical=True, verbose=False, - acc_prefix=True, acc_if='', modules='', sp_as_var=False): - + def __init__( + self, + infile, + outfile="", + ifdef="SERIALIZE", + real="ireals", + module="m_serialize", + identical=True, + verbose=False, + acc_prefix=True, + acc_if="", + modules="", + sp_as_var=False, + ): # public variables self.verbose = verbose - self.infile = infile # input file - self.outfile = outfile # output file - self.ifdef = ifdef # write #ifdef/#endif blocks - self.real = real # name of real type (Fortran) - self.module = module # name of Fortran module which contains serialization methods - self.identical = identical # write identical files (no preprocessing done)? + self.infile = infile # input file + self.outfile = outfile # output file + self.ifdef = ifdef # write #ifdef/#endif blocks + self.real = real # name of real type (Fortran) + self.module = ( + module # name of Fortran module which contains serialization methods + ) + self.identical = identical # write identical files (no preprocessing done)? self.acc_prefix = acc_prefix # generate preprocessing marco for ACC_PREFIX - self.acc_if = acc_if # generate IF clause after OpenACC update - self.sp_as_var = sp_as_var # Syntax for savepoints using variable instead of string + self.acc_if = acc_if # generate IF clause after OpenACC update + self.sp_as_var = ( + sp_as_var # Syntax for savepoints using variable instead of string + ) # setup (also public) self.methods = { - 'mode': 'ppser_set_mode', - 'getmode': 'ppser_get_mode', - 'init': 'ppser_initialize', - 'cleanup': 'ppser_finalize', - 'data': 'fs_write_field', - 'datawrite': 'fs_write_field', - 'dataread': 'fs_read_field', - 'datareadperturb': 'fs_read_field', - 'datakbuff': 'fs_write_kbuff', - 'option': 'fs_Option', - 'serinfo': 'fs_add_serializer_metainfo', - 'register': 'fs_register_field', - 'registertracers': 'fs_RegisterAllTracers', - 'fieldmetainfo': 'fs_AddFieldMetaInfo', - 'savepoint': 'fs_create_savepoint', - 'spinfo': 'fs_add_savepoint_metainfo', - 'fieldinfo': 'fs_add_field_metainfo', - 'on': 'fs_enable_serialization', - 'off': 'fs_disable_serialization' + "mode": "ppser_set_mode", + "getmode": "ppser_get_mode", + "init": "ppser_initialize", + "cleanup": "ppser_finalize", + "data": "fs_write_field", + "datawrite": "fs_write_field", + "dataread": "fs_read_field", + "datareadperturb": "fs_read_field", + "datakbuff": "fs_write_kbuff", + "option": "fs_Option", + "serinfo": "fs_add_serializer_metainfo", + "register": "fs_register_field", + "registertracers": "fs_RegisterAllTracers", + "fieldmetainfo": "fs_AddFieldMetaInfo", + "savepoint": "fs_create_savepoint", + "spinfo": "fs_add_savepoint_metainfo", + "fieldinfo": "fs_add_field_metainfo", + "on": "fs_enable_serialization", + "off": "fs_disable_serialization", } # language definition (also public) self.language = { - 'cleanup': ['CLEANUP', 'CLE'], - 'data': ['DATA', 'DAT'], - 'data_kbuff': ['DATA_KBUFF', 'KBU'], - 'accdata': ['ACCDATA', 'ACC'], - 'mode': ['MODE', 'MOD'], - 'init': ['INIT', 'INI'], - 'option': ['OPTION', 'OPT'], - 'metainfo': ['METAINFO'], - 'verbatim': ['VERBATIM', 'VER'], - 'register': ['REGISTER', 'REG'], - 'registertracers': ['REGISTERTRACERS'], - 'zero': ['ZERO', 'ZER'], - 'savepoint': ['SAVEPOINT', 'SAV'], - 'tracer': ['TRACER', 'TRA'], - 'on': ['ON'], - 'off': ['OFF'] + "cleanup": ["CLEANUP", "CLE"], + "data": ["DATA", "DAT"], + "data_kbuff": ["DATA_KBUFF", "KBU"], + "accdata": ["ACCDATA", "ACC"], + "mode": ["MODE", "MOD"], + "init": ["INIT", "INI"], + "option": ["OPTION", "OPT"], + "metainfo": ["METAINFO"], + "verbatim": ["VERBATIM", "VER"], + "register": ["REGISTER", "REG"], + "registertracers": ["REGISTERTRACERS"], + "zero": ["ZERO", "ZER"], + "savepoint": ["SAVEPOINT", "SAV"], + "tracer": ["TRACER", "TRA"], + "on": ["ON"], + "off": ["OFF"], } # If you change any of these, please check equivalent parameters in # serialbox-fortran/utils_ppser.f90 - self.modes = { - 'write': 0, - 'read': 1, - 'read-perturb': 2, - 'CPU': 0, - 'GPU': 1 - } + self.modes = {"write": 0, "read": 1, "read-perturb": 2, "CPU": 0, "GPU": 1} self.intentin_to_remove = [] self.intentin_removed = [] # private variables - self.__ser = False # currently processing !$SER directives - self.__line = '' # current line - self.__linenum = 0 # current line number - self.__module = '' # current module - self.__calls = set() # calls to serialization module - self.__outputBuffer = '' # preprocessed file + self.__ser = False # currently processing !$SER directives + self.__line = "" # current line + self.__linenum = 0 # current line number + self.__module = "" # current module + self.__calls = set() # calls to serialization module + self.__outputBuffer = "" # preprocessed file self.__use_stmt_in_module = False # USE statement was inserted in module - self.__extra_module = [] # extra module to add to use statement + self.__extra_module = [] # extra module to add to use statement self.__skip_next_n_lines = 0 # Number of line to skip (use for lookahead) if modules: - self.__extra_module = modules.split(',') + self.__extra_module = modules.split(",") # define compute sign used in field definition. If one is matched, # the read call is not added - self.__computed_fields_sign = ['*', '+', '-', '/', 'merge'] + self.__computed_fields_sign = ["*", "+", "-", "/", "merge"] # shortcuts for field registering def __reg_shortcuts(self, shortcut): shortcut = shortcut.upper() l = [] - if re.match('(^$|[IJK][IJK1-9]*)', shortcut): - if shortcut == '': - l = '1 0 0 0 0 0 0 0 0 0 0 0'.split() - elif shortcut == 'I': - l = 'ie 0 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() - elif shortcut == 'J': - l = 'je 0 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() - elif shortcut == 'J2': - l = 'je 2 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() - elif shortcut == 'K': - l = 'ke 0 0 0 0 0 0 0 0 0 0 0'.split() - elif shortcut == 'K1': - l = 'ke1 0 0 0 0 1 0 0 0 0 0 0'.split() - elif shortcut == 'IJ': - l = 'ie je 0 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() - elif shortcut == 'IJ3': - l = 'ie je 3 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() - elif shortcut == 'IK': - l = 'ie ke 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() - elif shortcut == 'IK1': - l = 'ie ke1 0 0 nboundlines nboundlines 0 0 0 1 0 0'.split() - elif shortcut == 'JK': - l = 'je ke 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() - elif shortcut == 'JK1': - l = 'je ke1 0 0 nboundlines nboundlines 0 1 0 0 0 0'.split() - elif shortcut == 'IJK': - l = 'ie je ke 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() - elif shortcut == 'IJK1': - l = 'ie je ke1 0 nboundlines nboundlines nboundlines nboundlines 0 1 0 0'.split() + if re.match("(^$|[IJK][IJK1-9]*)", shortcut): + if shortcut == "": + l = "1 0 0 0 0 0 0 0 0 0 0 0".split() + elif shortcut == "I": + l = "ie 0 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() + elif shortcut == "J": + l = "je 0 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() + elif shortcut == "J2": + l = "je 2 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() + elif shortcut == "K": + l = "ke 0 0 0 0 0 0 0 0 0 0 0".split() + elif shortcut == "K1": + l = "ke1 0 0 0 0 1 0 0 0 0 0 0".split() + elif shortcut == "IJ": + l = "ie je 0 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() + elif shortcut == "IJ3": + l = "ie je 3 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() + elif shortcut == "IK": + l = "ie ke 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() + elif shortcut == "IK1": + l = "ie ke1 0 0 nboundlines nboundlines 0 0 0 1 0 0".split() + elif shortcut == "JK": + l = "je ke 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() + elif shortcut == "JK1": + l = "je ke1 0 0 nboundlines nboundlines 0 1 0 0 0 0".split() + elif shortcut == "IJK": + l = "ie je ke 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() + elif shortcut == "IJK1": + l = "ie je ke1 0 nboundlines nboundlines nboundlines nboundlines 0 1 0 0".split() return l # error handling - def __exit_error(self, directive='', msg=''): + def __exit_error(self, directive="", msg=""): print('File: "' + self.infile + '", line ' + str(self.__linenum)) if directive: - print('SyntaxError: Invalid !$SER ' + directive + ' directive') + print("SyntaxError: Invalid !$SER " + directive + " directive") if msg: - print('Message: '+msg) + print("Message: " + msg) if self.__line: - print('Line '+str(self.__linenum)+': '+self.__line) + print("Line " + str(self.__linenum) + ": " + self.__line) sys.exit(1) # general SER directive arguments parser def __ser_arg_parse(self, args): # returns list of directives, lists of key=value pairs and (optional) IF statmenet - dirs = [] # directives - keys = [] # keys + dirs = [] # directives + keys = [] # keys values = [] # values if_encountered = False - if_statement = '' + if_statement = "" for arg in args[1:]: - if arg.upper() == 'IF': + if arg.upper() == "IF": if_encountered = True continue if if_encountered: if if_statement: - self.__exit_error(directive=args[0], - msg='IF statement must be last argument') + self.__exit_error( + directive=args[0], msg="IF statement must be last argument" + ) if_statement = arg else: - val = arg.split('=') + val = arg.split("=") if len(val) == 1: dirs.append(val[0]) elif len(val) == 2: keys.append(val[0]) values.append(val[1]) else: - self.__exit_error(directive=args[0], - msg='Problem extracting arguments and key=value pairs') + self.__exit_error( + directive=args[0], + msg="Problem extracting arguments and key=value pairs", + ) return dirs, keys, values, if_statement # parser for tracer directive def __ser_tracer_parse(self, args): tracersspec = [] if_encountered = False - if_statement = '' + if_statement = "" - pattern = '^([a-zA-Z_0-9]+|\$[a-zA-Z_0-9\(\)]+(?:-[a-zA-Z_0-9\(\)]+)?|%all)' # Tracer name, id(s) or %all - pattern += '(?:#(tens|bd|surf|sedimvel))?' # Type (stype) - pattern += '(?:@([a-zA-Z_0-9]+))?' # Time level (timelevel) + pattern = "^([a-zA-Z_0-9]+|\$[a-zA-Z_0-9\(\)]+(?:-[a-zA-Z_0-9\(\)]+)?|%all)" # Tracer name, id(s) or %all + pattern += "(?:#(tens|bd|surf|sedimvel))?" # Type (stype) + pattern += "(?:@([a-zA-Z_0-9]+))?" # Time level (timelevel) r = re.compile(pattern) for arg in args[1:]: - if arg.upper() == 'IF': + if arg.upper() == "IF": if_encountered = True continue if if_encountered: if if_statement: - self.__exit_error(directive=args[0], - msg='IF statement must be last argument') + self.__exit_error( + directive=args[0], msg="IF statement must be last argument" + ) if_statement = arg else: m = r.search(arg) if m is None: - self.__exit_error(directive=args[0], - msg='Tracer specification ' + arg + ' is invalid') + self.__exit_error( + directive=args[0], + msg="Tracer specification " + arg + " is invalid", + ) tracersspec.append(m.groups()) return tracersspec, if_statement # INIT directive def __ser_init(self, args): - (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " - l += tab + 'PRINT *, \'>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<\'\n' - l += tab + 'PRINT *, \'>>> WARNING: SERIALIZATION IS ON <<<\'\n' - l += tab + 'PRINT *, \'>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<\'\n' - l += tab + '\n' - l += tab + '! setup serialization environment\n' + l += tab + "PRINT *, '>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<'\n" + l += tab + "PRINT *, '>>> WARNING: SERIALIZATION IS ON <<<'\n" + l += tab + "PRINT *, '>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<'\n" + l += tab + "\n" + l += tab + "! setup serialization environment\n" args_lower = [item.lower() for item in args] - if 'if' in args_lower: - if_pos = args_lower.index('if'.lower()) + if "if" in args_lower: + if_pos = args_lower.index("if".lower()) else: if_pos = len(args) - self.__calls.add(self.methods['init']) - l += tab + 'call ' + self.methods['init'] + '( &\n' + ' '*11 + (', &\n' + ' '*11).join(args[1:if_pos]) + ')\n' + self.__calls.add(self.methods["init"]) + l += ( + tab + + "call " + + self.methods["init"] + + "( &\n" + + " " * 11 + + (", &\n" + " " * 11).join(args[1:if_pos]) + + ")\n" + ) if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l @@ -302,29 +329,31 @@ def __ser_init(self, args): def __ser_option(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(dirs) != 0: - self.__exit_error(directive=args[0], - msg='Must specify a name and a list of key=value pairs') + self.__exit_error( + directive=args[0], + msg="Must specify a name and a list of key=value pairs", + ) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' + l += "IF (" + if_statement + ") THEN\n" - self.__calls.add(self.methods['option']) - l += 'call ' + self.methods['option'] + '(' + self.__calls.add(self.methods["option"]) + l += "call " + self.methods["option"] + "(" for i in range(len(keys)): - if keys[i].lower() == 'verbosity': - if values[i].lower() == 'off': - values[i] = '0' - if values[i].lower() == 'on': - values[i] = '1' + if keys[i].lower() == "verbosity": + if values[i].lower() == "off": + values[i] = "0" + if values[i].lower() == "on": + values[i] = "1" if i == 0: - l += keys[i] + '=' + values[i] + l += keys[i] + "=" + values[i] else: - l += ', ' + keys[i] + '=' + values[i] - l += ')\n' + l += ", " + keys[i] + "=" + values[i] + l += ")\n" if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l @@ -332,50 +361,75 @@ def __ser_option(self, args): def __ser_metainfo(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " - self.__calls.add(self.methods['serinfo']) + self.__calls.add(self.methods["serinfo"]) for k, v in zip(keys, values): - l += tab + 'call ' + self.methods['serinfo'] + '(ppser_serializer, "' + k + '", ' + v + ')\n' + l += ( + tab + + "call " + + self.methods["serinfo"] + + '(ppser_serializer, "' + + k + + '", ' + + v + + ")\n" + ) for d in dirs: - l += tab + 'call ' + self.methods['serinfo'] + '(ppser_serializer, "' + d + '", ' + d + ')\n' + l += ( + tab + + "call " + + self.methods["serinfo"] + + '(ppser_serializer, "' + + d + + '", ' + + d + + ")\n" + ) if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # VERBATIM directive def __ser_verbatim(self, args): # simply remove $!SER directive for verbatim statements - self.__line = ' '.join(args[1:]) + '\n' + self.__line = " ".join(args[1:]) + "\n" # REGISTER directive def __ser_register(self, args): - # parse arguments (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(dirs) < 2: - self.__exit_error(directive=args[0], - msg='Must specify a name, a type and the field sizes') + self.__exit_error( + directive=args[0], msg="Must specify a name, a type and the field sizes" + ) if len(dirs) == 2: - dirs.append('') + dirs.append("") # quote name dirs[0] = "'" + dirs[0] + "'" # data type - datatypes = dict(integer=["'int'", 'ppser_intlength'], real=['ppser_realtype', 'ppser_reallength']) + datatypes = dict( + integer=["'int'", "ppser_intlength"], + real=["ppser_realtype", "ppser_reallength"], + ) if dirs[1] not in datatypes: - self.__exit_error(directive=args[0], msg='Data type "{0}" not understood. Valid types are: {1}'. - format(dirs[1], ', '.join('"' + d + '"' for d in datatypes.keys()))) + self.__exit_error( + directive=args[0], + msg='Data type "{0}" not understood. Valid types are: {1}'.format( + dirs[1], ", ".join('"' + d + '"' for d in datatypes.keys()) + ), + ) dirs[1:2] = datatypes[dirs[1]] @@ -386,58 +440,66 @@ def __ser_register(self, args): dirs[3:4] = l # REGISTER [arg ...] - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " # registration - self.__calls.add(self.methods['register']) - l += tab + 'call ' + self.methods['register'] + '(ppser_serializer, ' + ', '.join(dirs) + ')\n' + self.__calls.add(self.methods["register"]) + l += ( + tab + + "call " + + self.methods["register"] + + "(ppser_serializer, " + + ", ".join(dirs) + + ")\n" + ) # metainfo if len(keys) > 0: - self.__exit_error(directive=args[0], - msg='Metainformation for fields are not yet implemented') + self.__exit_error( + directive=args[0], + msg="Metainformation for fields are not yet implemented", + ) # for k,v in zip(keys, values): # l += tab + 'call ' + self.methods['fieldmetainfo'] + ' # (ppser_serializer, ' + dirs[0] + ', "' + k + '", ' + v + ')\n' if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # REGISTERTRACERS directive def __ser_registertracers(self, args): - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + + self.__calls.add(self.methods["registertracers"]) + l += "call fs_RegisterAllTracers()\n" - self.__calls.add(self.methods['registertracers']) - l += 'call fs_RegisterAllTracers()\n' - self.__line = l # ZERO directive def __ser_zero(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(keys) > 0: - self.__exit_error(directive=args[0], - msg='Must specify a list of fields') + self.__exit_error(directive=args[0], msg="Must specify a list of fields") - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " for arg in dirs: - l += tab + arg + ' = 0.0_' + self.real + '\n' + l += tab + arg + " = 0.0_" + self.real + "\n" if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l @@ -447,29 +509,54 @@ def __ser_savepoint(self, args): # extract save point name if len(dirs) != 1: - self.__exit_error(directive=args[0], - msg='Must specify a name and a list of key=value pairs') + self.__exit_error( + directive=args[0], + msg="Must specify a name and a list of key=value pairs", + ) name = dirs[0] # generate serialization code - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " - self.__calls.add(self.methods['savepoint']) - self.__calls.add(self.methods['spinfo']) + self.__calls.add(self.methods["savepoint"]) + self.__calls.add(self.methods["spinfo"]) if not self.sp_as_var: - l += tab + 'call ' + self.methods['savepoint'] + '(\'' + name + '\', ppser_savepoint)\n' + l += ( + tab + + "call " + + self.methods["savepoint"] + + "('" + + name + + "', ppser_savepoint)\n" + ) else: - l += tab + 'call ' + self.methods['savepoint'] + '(' + name + ', ppser_savepoint)\n' + l += ( + tab + + "call " + + self.methods["savepoint"] + + "(" + + name + + ", ppser_savepoint)\n" + ) for k, v in zip(keys, values): - l += tab + 'call ' + self.methods['spinfo'] + '(ppser_savepoint, \'' + k + '\', ' + v + ')\n' + l += ( + tab + + "call " + + self.methods["spinfo"] + + "(ppser_savepoint, '" + + k + + "', " + + v + + ")\n" + ) if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l @@ -477,220 +564,268 @@ def __ser_savepoint(self, args): def __ser_mode(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " - self.__calls.add(self.methods['mode']) + self.__calls.add(self.methods["mode"]) if args[1] in self.modes: - l += tab + 'call ' + self.methods['mode'] + '(' + str(self.modes[args[1]]) + ')\n' + l += ( + tab + + "call " + + self.methods["mode"] + + "(" + + str(self.modes[args[1]]) + + ")\n" + ) else: - l += tab + 'call ' + self.methods['mode'] + '(' + args[1] + ')\n' + l += tab + "call " + self.methods["mode"] + "(" + args[1] + ")\n" if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # KBUFF directive def __ser_kbuff(self, args, isacc=False): - (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - # generate serialization code - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + # generate serialization code + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " for v in values: - v = re.sub(r'\(.+\)', '', v) + v = re.sub(r"\(.+\)", "", v) if v not in self.intentin_to_remove: self.intentin_to_remove.append(v) - + d = dict(zip(keys, values)) - k_value = d.pop('k') - k_size = d.pop('k_size') + k_value = d.pop("k") + k_size = d.pop("k_size") - self.__calls.add(self.methods['getmode']) + self.__calls.add(self.methods["getmode"]) for k, v in zip(keys, values): - if (k != 'k') and (k != 'k_size'): - l += tab + ' ' + 'call ' + self.methods['datakbuff'] + \ - '(ppser_serializer, ppser_savepoint, \'' + k + '\', ' + v + ', k=' + \ - k_value + ', k_size=' + k_size + ', mode=' + self.methods['getmode'] +'())\n' + if (k != "k") and (k != "k_size"): + l += ( + tab + + " " + + "call " + + self.methods["datakbuff"] + + "(ppser_serializer, ppser_savepoint, '" + + k + + "', " + + v + + ", k=" + + k_value + + ", k_size=" + + k_size + + ", mode=" + + self.methods["getmode"] + + "())\n" + ) if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # DATA directive def __ser_data(self, args, isacc=False): - (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) # generate serialization code - self.__calls.add(self.methods['datawrite']) - self.__calls.add(self.methods['dataread']) - self.__calls.add(self.methods['datareadperturb']) - self.__calls.add(self.methods['getmode']) + self.__calls.add(self.methods["datawrite"]) + self.__calls.add(self.methods["dataread"]) + self.__calls.add(self.methods["datareadperturb"]) + self.__calls.add(self.methods["getmode"]) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " for v in values: - v = re.sub(r'\(.+\)', '', v) + v = re.sub(r"\(.+\)", "", v) if v not in self.intentin_to_remove: self.intentin_to_remove.append(v) - l += tab + 'SELECT CASE ( ' + self.methods['getmode'] + '() )\n' - l += tab + ' ' + 'CASE(' + str(self.modes['write']) + ')\n' + l += tab + "SELECT CASE ( " + self.methods["getmode"] + "() )\n" + l += tab + " " + "CASE(" + str(self.modes["write"]) + ")\n" for k, v in zip(keys, values): if isacc: # Generate acc update directives only for accdata clause - l += tab + ' ' + 'ACC_PREFIX UPDATE HOST ( ' + v + ' )' + l += tab + " " + "ACC_PREFIX UPDATE HOST ( " + v + " )" # Generate IF clause if needed if len(self.acc_if) > 0: - l += ', IF (' + self.acc_if + ') \n' + l += ", IF (" + self.acc_if + ") \n" else: - l += '\n' - l += tab + ' ' + 'call ' + self.methods['datawrite'] + \ - '(ppser_serializer, ppser_savepoint, \'' + k + '\', ' + v + ')\n' - l += tab + ' ' + 'CASE(' + str(self.modes['read']) + ')\n' + l += "\n" + l += ( + tab + + " " + + "call " + + self.methods["datawrite"] + + "(ppser_serializer, ppser_savepoint, '" + + k + + "', " + + v + + ")\n" + ) + l += tab + " " + "CASE(" + str(self.modes["read"]) + ")\n" for k, v in zip(keys, values): # If the field does not contains any compute sign, the read call is # generated if not any(ext in v for ext in self.__computed_fields_sign): - l += tab + ' ' + 'call ' + self.methods['dataread'] + '(ppser_serializer_ref, ppser_savepoint, \'' \ - + k + '\', ' + v + ')\n' + l += ( + tab + + " " + + "call " + + self.methods["dataread"] + + "(ppser_serializer_ref, ppser_savepoint, '" + + k + + "', " + + v + + ")\n" + ) if isacc: # Generate acc upadte directives only for accdata clause - l += tab + ' ' + 'ACC_PREFIX UPDATE DEVICE ( ' + v + ' )' + l += tab + " " + "ACC_PREFIX UPDATE DEVICE ( " + v + " )" # Generate IF clause if needed if len(self.acc_if) > 0: - l += ', IF (' + self.acc_if + ') \n' + l += ", IF (" + self.acc_if + ") \n" else: - l += '\n' - l += tab + ' ' + 'CASE(' + str(self.modes['read-perturb']) + ')\n' + l += "\n" + l += tab + " " + "CASE(" + str(self.modes["read-perturb"]) + ")\n" for k, v in zip(keys, values): # If the field does not contains any compute sign, the read call is # generated if not any(ext in v for ext in self.__computed_fields_sign): - l += tab + ' ' + 'call ' + self.methods['datareadperturb'] + \ - '(ppser_serializer_ref, ppser_savepoint, \'' + k + '\', ' + v + ', ppser_zrperturb)\n' + l += ( + tab + + " " + + "call " + + self.methods["datareadperturb"] + + "(ppser_serializer_ref, ppser_savepoint, '" + + k + + "', " + + v + + ", ppser_zrperturb)\n" + ) if isacc: # Generate acc upadte directives only for accdata clause - l += tab + ' ' + 'ACC_PREFIX UPDATE DEVICE ( ' + v + ' )' + l += tab + " " + "ACC_PREFIX UPDATE DEVICE ( " + v + " )" # Generate IF clause if needed if len(self.acc_if) > 0: - l += ', IF (' + self.acc_if + ') \n' + l += ", IF (" + self.acc_if + ") \n" else: - l += '\n' + l += "\n" - l += tab + 'END SELECT\n' + l += tab + "END SELECT\n" if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # TRACER directive def __ser_tracer(self, args): - (tracerspec, if_statement) = self.__ser_tracer_parse(args) - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - tab = '' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + tab = "" if if_statement: - l += 'IF (' + if_statement + ') THEN\n' - tab = ' ' + l += "IF (" + if_statement + ") THEN\n" + tab = " " for t in tracerspec: - function = 'ppser_write_tracer_' + function = "ppser_write_tracer_" fargs = [] # Function name and first arguments - if t[0] == '%all': + if t[0] == "%all": # %all specifier - function += 'all' - elif t[0][0] == '$': + function += "all" + elif t[0][0] == "$": # Index-based access - function += 'bx_idx' + function += "bx_idx" idxs = t[0][1:] - if '-' in idxs: - fargs += idxs.split('-') + if "-" in idxs: + fargs += idxs.split("-") else: fargs += [idxs] else: # Name-based access - function += 'by_name' + function += "by_name" fargs.append("'" + t[0] + "'") # Required stype argument - fargs.append("stype='" + (t[1] or '') + "'") + fargs.append("stype='" + (t[1] or "") + "'") # Other arguments - for i, argname in enumerate(('timelevel',), 2): + for i, argname in enumerate(("timelevel",), 2): if t[i]: - fargs.append(argname + '=' + t[i]) + fargs.append(argname + "=" + t[i]) # Put together function call - l += tab + 'call ' + function + '(' + ', '.join(fargs) + ')\n' + l += tab + "call " + function + "(" + ", ".join(fargs) + ")\n" if if_statement: - l += 'ENDIF\n' + l += "ENDIF\n" self.__line = l # CLEANUP directive def __ser_cleanup(self, args): - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - l += '! cleanup serialization environment\n' - - self.__calls.add(self.methods['cleanup']) - l += 'call ' + self.methods['cleanup'] + '(' + ','.join(args[1:]) + ')\n' + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + l += "! cleanup serialization environment\n" + + self.__calls.add(self.methods["cleanup"]) + l += "call " + self.methods["cleanup"] + "(" + ",".join(args[1:]) + ")\n" self.__line = l # ON directive def __ser_on(self, args): - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - - l += 'call ' + self.methods['on'] + '()\n' - self.__calls.add(self.methods['on']) - + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + + l += "call " + self.methods["on"] + "()\n" + self.__calls.add(self.methods["on"]) + self.__line = l # OFF directive def __ser_off(self, args): - l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' - - l += 'call ' + self.methods['off'] + '()\n' - self.__calls.add(self.methods['off']) - + l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + + l += "call " + self.methods["off"] + "()\n" + self.__calls.add(self.methods["off"]) + self.__line = l # LINE: module/program def __re_module(self): - r = re.compile('^ *(?Pmodule|program) +(?P[a-z][a-z0-9_]*)', re.IGNORECASE) + r = re.compile( + "^ *(?Pmodule|program) +(?P[a-z][a-z0-9_]*)", + re.IGNORECASE, + ) m = r.search(self.__line) if m: - if m.group('identifier').upper() == 'PROCEDURE': + if m.group("identifier").upper() == "PROCEDURE": return False if self.__module: - self.__exit_error(msg='Unexpected ' + m.group(1) + ' statement') + self.__exit_error(msg="Unexpected " + m.group(1) + " statement") self.__produce_use_stmt() - if m.group('statement').upper() == 'MODULE': + if m.group("statement").upper() == "MODULE": self.__use_stmt_in_module = True - self.__module = m.group('identifier') + self.__module = m.group("identifier") return m @@ -698,8 +833,8 @@ def __re_module(self): def __re_subroutine_function(self): if self.__use_stmt_in_module: # Statement produced at module level return - r = re.compile('^ *(subroutine|function).*', re.IGNORECASE) - r_cont = re.compile('^ *(subroutine|function)([^!]*)&', re.IGNORECASE) + r = re.compile("^ *(subroutine|function).*", re.IGNORECASE) + r_cont = re.compile("^ *(subroutine|function)([^!]*)&", re.IGNORECASE) m = r.search(self.__line) m_cont = r_cont.search(self.__line) if m and not m_cont: @@ -710,7 +845,7 @@ def __re_subroutine_function(self): # look ahead nextline = linecache.getline(os.path.join(self.infile), lookahead_index) - r_continued_line = re.compile('^([^!]*)&', re.IGNORECASE) + r_continued_line = re.compile("^([^!]*)&", re.IGNORECASE) while r_continued_line.search(nextline): self.__line += nextline lookahead_index += 1 @@ -722,87 +857,96 @@ def __re_subroutine_function(self): # LINE: !$SER directive def __re_ser(self): - r1 = re.compile('^ *!\$ser *(.*)$', re.IGNORECASE) - r2 = re.compile(r'''((?:[^ "']|"[^"]*"|'[^']*')+)''', re.IGNORECASE) + r1 = re.compile("^ *!\$ser *(.*)$", re.IGNORECASE) + r2 = re.compile(r"""((?:[^ "']|"[^"]*"|'[^']*')+)""", re.IGNORECASE) m = r1.search(self.__line) if m: if m.group(1): args = r2.split(m.group(1))[1::2] - if args[0].upper() in self.language['init']: + if args[0].upper() in self.language["init"]: self.__ser_init(args) - elif args[0].upper() in self.language['option']: + elif args[0].upper() in self.language["option"]: self.__ser_option(args) - elif args[0].upper() in self.language['metainfo']: + elif args[0].upper() in self.language["metainfo"]: self.__ser_metainfo(args) - elif args[0].upper() in self.language['verbatim']: + elif args[0].upper() in self.language["verbatim"]: self.__ser_verbatim(args) - elif args[0].upper() in self.language['register']: + elif args[0].upper() in self.language["register"]: self.__ser_register(args) - elif args[0].upper() in self.language['savepoint']: + elif args[0].upper() in self.language["savepoint"]: self.__ser_savepoint(args) - elif args[0].upper() in self.language['zero']: + elif args[0].upper() in self.language["zero"]: self.__ser_zero(args) - elif args[0].upper() in self.language['accdata']: + elif args[0].upper() in self.language["accdata"]: self.__ser_data(args, True) - elif args[0].upper() in self.language['data']: + elif args[0].upper() in self.language["data"]: self.__ser_data(args) - elif args[0].upper() in self.language['data_kbuff']: + elif args[0].upper() in self.language["data_kbuff"]: self.__ser_kbuff(args) - elif args[0].upper() in self.language['tracer']: + elif args[0].upper() in self.language["tracer"]: self.__ser_tracer(args) - elif args[0].upper() in self.language['registertracers']: + elif args[0].upper() in self.language["registertracers"]: self.__ser_registertracers(args) - elif args[0].upper() in self.language['cleanup']: + elif args[0].upper() in self.language["cleanup"]: self.__ser_cleanup(args) - elif args[0].upper() in self.language['on']: + elif args[0].upper() in self.language["on"]: self.__ser_on(args) - elif args[0].upper() in self.language['off']: + elif args[0].upper() in self.language["off"]: self.__ser_off(args) - elif args[0].upper() in self.language['mode']: + elif args[0].upper() in self.language["mode"]: self.__ser_mode(args) else: - self.__exit_error(directive=args[0], - msg='Unknown directive encountered') + self.__exit_error( + directive=args[0], msg="Unknown directive encountered" + ) return m # LINE: end module/end program def __re_endmodule(self): - r = re.compile('^ *end *(module|program) *([a-z][a-z0-9_]*|)', re.IGNORECASE) + r = re.compile("^ *end *(module|program) *([a-z][a-z0-9_]*|)", re.IGNORECASE) m = r.search(self.__line) if m: if not self.__module: - self.__exit_error(msg='Unexpected "end '+m.group(1)+'" statement') + self.__exit_error(msg='Unexpected "end ' + m.group(1) + '" statement') if m.group(2) and self.__module.lower() != m.group(2).lower(): - self.__exit_error(msg='Was expecting "end '+m.group(1)+' '+self.__module+'"') - self.__module = '' + self.__exit_error( + msg='Was expecting "end ' + m.group(1) + " " + self.__module + '"' + ) + self.__module = "" self.__use_stmt_in_module = False return m def __check_intent_in(self, line): - lhs = re.sub(r'!.*', '', line) # Remove comments at end of the line - var_with_dim = [x.strip().replace(' ', '') for x in re.split(r',(?![^(]*\))', lhs)] - var = [re.sub(r'\(.*?\)', '', x) for x in var_with_dim] + lhs = re.sub(r"!.*", "", line) # Remove comments at end of the line + var_with_dim = [ + x.strip().replace(" ", "") for x in re.split(r",(?![^(]*\))", lhs) + ] + var = [re.sub(r"\(.*?\)", "", x) for x in var_with_dim] fields_in_this_line = [x for x in self.intentin_to_remove if x in var] - self.intentin_removed.extend([x for x in fields_in_this_line if x not in self.intentin_removed]) + self.intentin_removed.extend( + [x for x in fields_in_this_line if x not in self.intentin_removed] + ) if fields_in_this_line: - l = '#ifdef ' + self.ifdef + '\n' - r = re.compile(r', *intent *\(in\)', re.IGNORECASE) - l += r.sub('', self.__line) - l += '#else\n' + self.__line + '#endif\n' + l = "#ifdef " + self.ifdef + "\n" + r = re.compile(r", *intent *\(in\)", re.IGNORECASE) + l += r.sub("", self.__line) + l += "#else\n" + self.__line + "#endif\n" self.__line = l return fields_in_this_line def __re_def(self): - r = re.compile(r'.*intent *\(in\)[^:]*::\s*([^!]*)\s*.*', re.IGNORECASE) - r_cont = re.compile(r'.*intent *\(in\)[^:]*::\s*([^!]*)\s*.*&', re.IGNORECASE) + r = re.compile(r".*intent *\(in\)[^:]*::\s*([^!]*)\s*.*", re.IGNORECASE) + r_cont = re.compile(r".*intent *\(in\)[^:]*::\s*([^!]*)\s*.*&", re.IGNORECASE) # Line contains intent with continuation m_cont = r_cont.search(self.__line) m = r.search(self.__line) if m_cont: - splitted = self.__line.split('::') - splitted[1] = re.sub(r'!.*', '', splitted[1]) # Remove comments at end of the line + splitted = self.__line.split("::") + splitted[1] = re.sub( + r"!.*", "", splitted[1] + ) # Remove comments at end of the line if not self.__check_intent_in(splitted[1]): # look ahead to find the variable lookahead_index = self.__linenum @@ -812,16 +956,20 @@ def __re_def(self): nextline = linecache.getline(os.path.join(self.infile), lookahead_index) while nextline: self.__check_intent_in(nextline) - if nextline.find('&') != -1: + if nextline.find("&") != -1: lookahead_index += 1 - nextline = linecache.getline(os.path.join(self.infile), lookahead_index) + nextline = linecache.getline( + os.path.join(self.infile), lookahead_index + ) else: nextline = None # Match a standard declaration with variable and intent on the same line elif m: - splitted = self.__line.split('::') - splitted[1] = re.sub(r'!.*', '', splitted[1]) # Remove comments at end of the line + splitted = self.__line.split("::") + splitted[1] = re.sub( + r"!.*", "", splitted[1] + ) # Remove comments at end of the line self.__check_intent_in(splitted[1]) return m @@ -829,38 +977,44 @@ def __re_def(self): def __produce_use_stmt(self): if self.__use_stmt_in_module is True: return - calls_pp = [c for c in self.__calls if c.startswith('ppser')] - calls_fs = [c for c in self.__calls if not c.startswith('ppser')] + calls_pp = [c for c in self.__calls if c.startswith("ppser")] + calls_fs = [c for c in self.__calls if not c.startswith("ppser")] ncalls = len(calls_pp) + len(calls_fs) if ncalls > 0: - calls_pp += ['ppser_savepoint', 'ppser_serializer', 'ppser_serializer_ref', - 'ppser_intlength', 'ppser_reallength', 'ppser_realtype', 'ppser_zrperturb', - 'ppser_get_mode'] - self.__line += '\n' + calls_pp += [ + "ppser_savepoint", + "ppser_serializer", + "ppser_serializer_ref", + "ppser_intlength", + "ppser_reallength", + "ppser_realtype", + "ppser_zrperturb", + "ppser_get_mode", + ] + self.__line += "\n" if self.ifdef: - self.__line += '#ifdef ' + self.ifdef + '\n' + self.__line += "#ifdef " + self.ifdef + "\n" if len(calls_fs) > 0: - self.__line += 'USE ' + self.module + ', ONLY: &\n' + self.__line += "USE " + self.module + ", ONLY: &\n" for s in calls_fs[:-1]: - self.__line += ' ' + s + ', &\n' - self.__line += ' ' + calls_fs[-1] + '\n' + self.__line += " " + s + ", &\n" + self.__line += " " + calls_fs[-1] + "\n" if len(calls_pp) > 0: - self.__line += 'USE utils_ppser, ONLY: &\n' + self.__line += "USE utils_ppser, ONLY: &\n" for s in calls_pp[:-1]: - self.__line += ' ' + s + ', &\n' - self.__line += ' ' + calls_pp[-1] + '\n' + self.__line += " " + s + ", &\n" + self.__line += " " + calls_pp[-1] + "\n" if len(self.__extra_module) > 0: for mod in self.__extra_module: - self.__line += 'USE ' + mod + '\n' + self.__line += "USE " + mod + "\n" if self.ifdef: - self.__line += '#endif\n' - self.__line += '\n' + self.__line += "#endif\n" + self.__line += "\n" # evaluate one line def lexer(self, final=False): - # parse lines related to scope self.__re_module() self.__re_subroutine_function() @@ -871,43 +1025,45 @@ def lexer(self, final=False): if self.__re_ser(): # if this is the first line with !$SER statements, add #ifdef if self.ifdef and not self.__ser: - self.__line = '#ifdef ' + self.ifdef + '\n' + self.__line + self.__line = "#ifdef " + self.ifdef + "\n" + self.__line self.__ser = True else: # if this is the first line without !$SER statements, add #endif if self.ifdef and self.__ser: - self.__line = '#endif\n' + self.__line + self.__line = "#endif\n" + self.__line self.__ser = False if final: # final call, check consistency if self.__ser: - self.__exit_error(msg='Unterminated #ifdef ' + self.ifdef + ' encountered') + self.__exit_error( + msg="Unterminated #ifdef " + self.ifdef + " encountered" + ) if self.__module: - self.__exit_error(msg='Unterminated module or program unit encountered') + self.__exit_error(msg="Unterminated module or program unit encountered") # execute one parsing pass over file def parse(self, generate=False): # if generate == False we only analyse the file # reset flags (which define state of parser) - self.__ser = False # currently processing !$SER directives - self.__line = '' # current line - self.__linenum = 0 # current line number - self.__module = '' # current module - self.__outputBuffer = '' # preprocessed file + self.__ser = False # currently processing !$SER directives + self.__line = "" # current line + self.__linenum = 0 # current line number + self.__module = "" # current module + self.__outputBuffer = "" # preprocessed file # generate preprocessing macro for ACC_PREFIX if self.acc_prefix: - self.__outputBuffer += '#define ACC_PREFIX !$acc\n' + self.__outputBuffer += "#define ACC_PREFIX !$acc\n" # open and parse file - input_file = open(os.path.join(self.infile), 'r') + input_file = open(os.path.join(self.infile), "r") try: - self.line = '' + self.line = "" for line in input_file: # Skip line already handled - if(self.__skip_next_n_lines > 0): + if self.__skip_next_n_lines > 0: self.__skip_next_n_lines -= 1 self.__linenum += 1 continue @@ -915,15 +1071,15 @@ def parse(self, generate=False): # handle line continuation (next line coming in) if self.__line: - if re.match('^ *!\$ser& ', line, re.IGNORECASE): - line = re.sub('^ *!\$ser& *', ' ', line, re.IGNORECASE) + if re.match("^ *!\$ser& ", line, re.IGNORECASE): + line = re.sub("^ *!\$ser& *", " ", line, re.IGNORECASE) else: - self.__exit_error(msg='Incorrect line continuation encountered') + self.__exit_error(msg="Incorrect line continuation encountered") self.__line += line # handle line continuation (continued line going out) - if re.match('^ *!\$ser *(.*) & *$', self.__line, re.IGNORECASE): + if re.match("^ *!\$ser *(.*) & *$", self.__line, re.IGNORECASE): # chop trailing & - self.__line = re.sub(' +& *$', '', self.__line, re.IGNORECASE) + self.__line = re.sub(" +& *$", "", self.__line, re.IGNORECASE) self.__line = self.__line.rstrip() continue # parse line @@ -931,7 +1087,7 @@ def parse(self, generate=False): if generate: self.__outputBuffer += self.__line # cleanup current line (used for line continuation and final lexer call) - self.__line = '' + self.__line = "" self.lexer(final=True) finally: @@ -940,10 +1096,10 @@ def parse(self, generate=False): # main processing method def preprocess(self): # parse file - self.parse() # first pass, analyse only - self.parse(generate=True) # second pass, preprocess + self.parse() # first pass, analyse only + self.parse(generate=True) # second pass, preprocess # write output - if self.outfile != '': + if self.outfile != "": output_file = tempfile.NamedTemporaryFile(delete=False) # same permissions as infile os.chmod(output_file.name, os.stat(self.infile).st_mode) @@ -1036,7 +1192,7 @@ def simple_test(): f.write(test) f.close() ser = PpSer(f.name) - PpSer.real = 'wp' + PpSer.real = "wp" ser.preprocess() finally: os.remove(f.name) @@ -1044,38 +1200,94 @@ def simple_test(): def parse_args(): from optparse import OptionParser + parser = OptionParser() - parser.add_option('-i', '--ignore-identical', help='Ignore files which are not modified by pre-processor', - default=False, action='store_true', dest='ignore_identical') - parser.add_option('-d', '--output-dir', help='The target directory for writing pre-processed files', - default='', type=str, dest='output_dir') - parser.add_option('-o', '--output', help='Output file name to preprocess single file', - default='', type=str, dest='output_file') - parser.add_option('-r', '--recursive', help='Recursively process target directory and mirror tree', - default=False, action='store_true', dest='recursive') - parser.add_option('-v', '--verbose', help='Enable verbose execution', - default=False, action='store_true', dest='verbose') - parser.add_option('-p', '--no-prefix', help='Don\'t generate preprocessing macro definition for ACC_PREFIX', - default=True, action='store_false', dest='acc_prefix') - parser.add_option('-a', '--acc-if', help='Add IF clause to OpenACC update statement', - default='', type=str, dest='acc_if') - parser.add_option('-m', '--module', help='Extra MODULE to be add to the use statement', - default='', type=str, dest='modules') - parser.add_option('-s', '--sp-as-var', help='Savepoint specified as variable instead of string', - default=False, action='store_true', dest='sp_as_var') + parser.add_option( + "-i", + "--ignore-identical", + help="Ignore files which are not modified by pre-processor", + default=False, + action="store_true", + dest="ignore_identical", + ) + parser.add_option( + "-d", + "--output-dir", + help="The target directory for writing pre-processed files", + default="", + type=str, + dest="output_dir", + ) + parser.add_option( + "-o", + "--output", + help="Output file name to preprocess single file", + default="", + type=str, + dest="output_file", + ) + parser.add_option( + "-r", + "--recursive", + help="Recursively process target directory and mirror tree", + default=False, + action="store_true", + dest="recursive", + ) + parser.add_option( + "-v", + "--verbose", + help="Enable verbose execution", + default=False, + action="store_true", + dest="verbose", + ) + parser.add_option( + "-p", + "--no-prefix", + help="Don't generate preprocessing macro definition for ACC_PREFIX", + default=True, + action="store_false", + dest="acc_prefix", + ) + parser.add_option( + "-a", + "--acc-if", + help="Add IF clause to OpenACC update statement", + default="", + type=str, + dest="acc_if", + ) + parser.add_option( + "-m", + "--module", + help="Extra MODULE to be add to the use statement", + default="", + type=str, + dest="modules", + ) + parser.add_option( + "-s", + "--sp-as-var", + help="Savepoint specified as variable instead of string", + default=False, + action="store_true", + dest="sp_as_var", + ) (options, args) = parser.parse_args() if len(args) < 1: - parser.error('Need at least one source file to process') + parser.error("Need at least one source file to process") if options.output_file and len(args) > 1: - parser.error('Single source file required if output file is given') + parser.error("Single source file required if output file is given") if options.recursive: if not options.output_dir: - parser.error('Output directory is required with recursive option') + parser.error("Output directory is required with recursive option") for indir in args: if not os.path.isdir(indir): - parser.error('Arguments need to be directories with recursive option') + parser.error("Arguments need to be directories with recursive option") return options, args + if __name__ == "__main__": (options, args) = parse_args() if options.recursive: @@ -1087,22 +1299,38 @@ def parse_args(): for infile in args: if options.output_dir: if options.recursive: - outfile = os.path.join(options.output_dir, - os.path.sep.join([p for p in os.path.dirname(infile).rsplit(os.path.sep) if p][1:]), - os.path.basename(infile)) + outfile = os.path.join( + options.output_dir, + os.path.sep.join( + [p for p in os.path.dirname(infile).rsplit(os.path.sep) if p][ + 1: + ] + ), + os.path.basename(infile), + ) else: outfile = os.path.join(options.output_dir, os.path.basename(infile)) elif options.output_file: outfile = options.output_file else: - outfile = '' + outfile = "" # If output is to a file and the file is more updated than the input, skip - if os.path.exists(outfile) and os.path.getctime(outfile) > os.path.getctime(infile): - print('Skipping', infile) + if os.path.exists(outfile) and os.path.getctime(outfile) > os.path.getctime( + infile + ): + print("Skipping", infile) else: - print('Processing file', infile) - ser = PpSer(infile, real='wp', outfile=outfile, identical=(not options.ignore_identical), - verbose=options.verbose, acc_prefix=options.acc_prefix, acc_if=options.acc_if, - modules=options.modules, sp_as_var=options.sp_as_var) + print("Processing file", infile) + ser = PpSer( + infile, + real="wp", + outfile=outfile, + identical=(not options.ignore_identical), + verbose=options.verbose, + acc_prefix=options.acc_prefix, + acc_if=options.acc_if, + modules=options.modules, + sp_as_var=options.sp_as_var, + ) ser.preprocess() diff --git a/src/serialbox-python/serialbox/serializer.py b/src/serialbox-python/serialbox/serializer.py index 1b007fcb..52c236c0 100644 --- a/src/serialbox-python/serialbox/serializer.py +++ b/src/serialbox-python/serialbox/serializer.py @@ -4,7 +4,7 @@ ## ## S E R I A L B O X ## -## This file is distributed under terms of BSD license. +## This file is distributed under terms of BSD license. ## See LICENSE.txt for more information. ## ##===------------------------------------------------------------------------------------------===## @@ -22,14 +22,20 @@ from .error import invoke, SerialboxError from .fieldmetainfo import FieldMetainfo, FieldMetainfoImpl from .metainfomap import MetainfoMap, MetainfoImpl, ArrayOfStringImpl -from .savepoint import Savepoint, SavepointImpl, SavepointTopCollection, SavepointCollection +from .savepoint import ( + Savepoint, + SavepointImpl, + SavepointTopCollection, + SavepointCollection, +) from .type import * lib = get_library() class SerializerImpl(Structure): - """ Mapping of serialboxSerializer_t """ + """Mapping of serialboxSerializer_t""" + _fields_ = [("impl", c_void_p), ("ownsData", c_int)] @@ -79,27 +85,39 @@ def register_library(library): # # Register and Query Savepoints # - library.serialboxSerializerAddSavepoint.argtypes = [POINTER(SerializerImpl), - POINTER(SavepointImpl)] + library.serialboxSerializerAddSavepoint.argtypes = [ + POINTER(SerializerImpl), + POINTER(SavepointImpl), + ] library.serialboxSerializerAddSavepoint.restype = c_int - library.serialboxSerializerHasSavepoint.argtypes = [POINTER(SerializerImpl), - POINTER(SavepointImpl)] + library.serialboxSerializerHasSavepoint.argtypes = [ + POINTER(SerializerImpl), + POINTER(SavepointImpl), + ] library.serialboxSerializerHasSavepoint.restype = c_int library.serialboxSerializerGetNumSavepoints.argtypes = [POINTER(SerializerImpl)] library.serialboxSerializerGetNumSavepoints.restype = c_int library.serialboxSerializerGetSavepointVector.argtypes = [POINTER(SerializerImpl)] - library.serialboxSerializerGetSavepointVector.restype = POINTER(POINTER(SavepointImpl)) - - library.serialboxSerializerDestroySavepointVector.argtypes = [POINTER(POINTER(SavepointImpl)), - c_int] + library.serialboxSerializerGetSavepointVector.restype = POINTER( + POINTER(SavepointImpl) + ) + + library.serialboxSerializerDestroySavepointVector.argtypes = [ + POINTER(POINTER(SavepointImpl)), + c_int, + ] library.serialboxSerializerDestroySavepointVector.restype = None - library.serialboxSerializerGetFieldnamesAtSavepoint.argtypes = [POINTER(SerializerImpl), - POINTER(SavepointImpl)] - library.serialboxSerializerGetFieldnamesAtSavepoint.restype = POINTER(ArrayOfStringImpl) + library.serialboxSerializerGetFieldnamesAtSavepoint.argtypes = [ + POINTER(SerializerImpl), + POINTER(SavepointImpl), + ] + library.serialboxSerializerGetFieldnamesAtSavepoint.restype = POINTER( + ArrayOfStringImpl + ) library.serialboxSavepointCreateFromSavepoint.argtypes = [POINTER(SavepointImpl)] library.serialboxSavepointCreateFromSavepoint.restype = POINTER(SavepointImpl) @@ -107,14 +125,20 @@ def register_library(library): # # Register and Query Fields # - library.serialboxSerializerAddField.argtypes = [POINTER(SerializerImpl), c_char_p, - POINTER(FieldMetainfoImpl)] + library.serialboxSerializerAddField.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + POINTER(FieldMetainfoImpl), + ] library.serialboxSerializerAddField.restype = c_int library.serialboxSerializerHasField.argtypes = [POINTER(SerializerImpl), c_char_p] library.serialboxSerializerHasField.restype = c_int - library.serialboxSerializerGetFieldMetainfo.argtypes = [POINTER(SerializerImpl), c_char_p] + library.serialboxSerializerGetFieldMetainfo.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + ] library.serialboxSerializerGetFieldMetainfo.restype = POINTER(FieldMetainfoImpl) library.serialboxSerializerGetFieldnames.argtypes = [POINTER(SerializerImpl)] @@ -123,37 +147,45 @@ def register_library(library): # # Writing & Reading # - library.serialboxSerializerWrite.argtypes = [POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int] + library.serialboxSerializerWrite.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int, + ] library.serialboxSerializerWrite.restype = None - library.serialboxSerializerRead.argtypes = [POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int] + library.serialboxSerializerRead.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int, + ] library.serialboxSerializerRead.restype = None - library.serialboxSerializerReadSliced.argtypes = [POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int, - POINTER(c_int)] + library.serialboxSerializerReadSliced.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int, + POINTER(c_int), + ] library.serialboxSerializerReadSliced.restype = None - library.serialboxSerializerReadAsync.argtypes = [POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int] + library.serialboxSerializerReadAsync.argtypes = [ + POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int, + ] library.serialboxSerializerReadAsync.restype = None library.serialboxSerializerWaitForAll.argtypes = [POINTER(SerializerImpl)] @@ -162,24 +194,28 @@ def register_library(library): # # Stateless Serialization # - library.serialboxWriteToFile.argtypes = [c_char_p, - c_void_p, - c_int, - POINTER(c_int), - c_int, - POINTER(c_int), - c_char_p, - c_char_p] + library.serialboxWriteToFile.argtypes = [ + c_char_p, + c_void_p, + c_int, + POINTER(c_int), + c_int, + POINTER(c_int), + c_char_p, + c_char_p, + ] library.serialboxWriteToFile.restype = None - library.serialboxReadFromFile.argtypes = [c_char_p, - c_void_p, - c_int, - POINTER(c_int), - c_int, - POINTER(c_int), - c_char_p, - c_char_p] + library.serialboxReadFromFile.argtypes = [ + c_char_p, + c_void_p, + c_int, + POINTER(c_int), + c_int, + POINTER(c_int), + c_char_p, + c_char_p, + ] library.serialboxReadFromFile.restype = None # @@ -210,6 +246,7 @@ class Serializer(object): >>> [f for f in os.listdir(".") if os.path.isfile(os.path.join(".", f))] # List files in current directory ['field_field.dat', 'ArchiveMetaData-field.json', 'MetaData-field.json'] """ + Enabled = 1 Disabled = -1 @@ -244,7 +281,9 @@ def __init__(self, mode, directory, prefix, archive="Binary"): archives = Archive.registered_archives() if archive not in archives: raise SerialboxError( - "'%s' is not a valid archive. Registered archives: %s" % (archive, archives)) + "'%s' is not a valid archive. Registered archives: %s" + % (archive, archives) + ) # # Create serializer @@ -253,8 +292,9 @@ def __init__(self, mode, directory, prefix, archive="Binary"): prefixstr = to_c_string(prefix)[0] archivestr = to_c_string(archive)[0] - self.__serializer = invoke(lib.serialboxSerializerCreate, modeint, dirstr, prefixstr, - archivestr) + self.__serializer = invoke( + lib.serialboxSerializerCreate, modeint, dirstr, prefixstr, archivestr + ) # # Savepoint list @@ -305,8 +345,7 @@ def directory(self): return invoke(lib.serialboxSerializerGetDirectory, self.__serializer).decode() def update_meta_data(self): - """ Write meta-data to disk. - """ + """Write meta-data to disk.""" invoke(lib.serialboxSerializerUpdateMetaData, self.__serializer) @staticmethod @@ -314,7 +353,7 @@ def enable(): """Enable serialization. Serialization is enabled by default, but it can be disabled either by setting the - environment variable ``STELLA_SERIALIZATION_DISABLE`` to a positive value or by calling the + environment variable ``SERIALBOX_SERIALIZATION_DISABLE`` to a positive value or by calling the function :func:`Serializer.disable `. With this function you enable the serialization independently of the current environment. @@ -328,7 +367,7 @@ def disable(): """Disable serialization. Serialization is enabled by default, but it can be disabled either by setting the - environment variable ``STELLA_SERIALIZATION_DISABLE`` to a positive value or by calling the + environment variable ``SERIALBOX_SERIALIZATION_DISABLE`` to a positive value or by calling the function :func:`Serializer.disable `. With this function you disable the serialization independently of the current environment. @@ -344,7 +383,7 @@ def status(): The status is represented as an integer which can take the following values: - 0: the variable is not yet initialized i.e the serialization is enabled if the environment - variable ``STELLA_SERIALIZATION_DISABLE`` or ``SERIALBOX_SERIALIZATION_DISABLE`` is not + variable ``SERIALBOX_SERIALIZATION_DISABLE`` is not set to a positive value. The first Serializer which is initialized has to set this value either to +1 or to -1 according to the environment. - +1: the serialization is enabled, independently of the environment @@ -376,7 +415,9 @@ def global_metainfo(self): :return: Refrence to the meta-information map :rtype: :class:`MetainfoMap ` """ - return MetainfoMap(impl=invoke(lib.serialboxSerializerGetGlobalMetainfo, self.__serializer)) + return MetainfoMap( + impl=invoke(lib.serialboxSerializerGetGlobalMetainfo, self.__serializer) + ) # ===----------------------------------------------------------------------------------------=== # Register and Query Savepoints @@ -393,11 +434,17 @@ def register_savepoint(self, savepoint): :raises serialbox.SerialboxError: if `savepoint` already exists within the Serializer """ if self.mode == OpenModeKind.Read: - raise SerialboxError("registering savepoints is not permitted in OpenModeKind.Read") + raise SerialboxError( + "registering savepoints is not permitted in OpenModeKind.Read" + ) - if not invoke(lib.serialboxSerializerAddSavepoint, self.__serializer, savepoint.impl()): + if not invoke( + lib.serialboxSerializerAddSavepoint, self.__serializer, savepoint.impl() + ): raise SerialboxError( - "savepoint '%s' already exists withing the Serializer" % (savepoint.__str__())) + "savepoint '%s' already exists withing the Serializer" + % (savepoint.__str__()) + ) def has_savepoint(self, savepoint): """Check if `savepoint` exists within the Serializer. @@ -408,7 +455,10 @@ def has_savepoint(self, savepoint): :rtype: bool """ return bool( - invoke(lib.serialboxSerializerHasSavepoint, self.__serializer, savepoint.impl())) + invoke( + lib.serialboxSerializerHasSavepoint, self.__serializer, savepoint.impl() + ) + ) def get_savepoint(self, name): """Get a list of Savepoint(s) identified by `name` in the order they were registered @@ -439,8 +489,11 @@ def fields_at_savepoint(self, savepoint): :raises serialbox.SerialboxError: if `savepoint` does not exists """ savepoint_ = self.__extract_savepoint(savepoint) - array = invoke(lib.serialboxSerializerGetFieldnamesAtSavepoint, self.__serializer, - savepoint_.impl()) + array = invoke( + lib.serialboxSerializerGetFieldnamesAtSavepoint, + self.__serializer, + savepoint_.impl(), + ) list_array = [] for i in range(array.contents.len): list_array += [array.contents.data[i].decode()] @@ -470,14 +523,23 @@ def savepoint_list(self): # list_of_savepoints = [] for i in range(num_savepoints): - list_of_savepoints += [Savepoint('', - impl=invoke( - lib.serialboxSavepointCreateFromSavepoint, - vec_savepoint[i].contents))] + list_of_savepoints += [ + Savepoint( + "", + impl=invoke( + lib.serialboxSavepointCreateFromSavepoint, + vec_savepoint[i].contents, + ), + ) + ] # # Destroy the savepoint vector # - invoke(lib.serialboxSerializerDestroySavepointVector, vec_savepoint, num_savepoints) + invoke( + lib.serialboxSerializerDestroySavepointVector, + vec_savepoint, + num_savepoints, + ) # # If we are in Read mode, we can safely cache the savepoint list @@ -566,12 +628,20 @@ def register_field(self, name, fieldmetainfo): Serializer """ if self.mode == OpenModeKind.Read: - raise SerialboxError("registering fields is not permitted in OpenModeKind.Read") + raise SerialboxError( + "registering fields is not permitted in OpenModeKind.Read" + ) namestr = to_c_string(name)[0] - if not invoke(lib.serialboxSerializerAddField, self.__serializer, namestr, - fieldmetainfo.impl()): - raise SerialboxError("field '%s' already exists within the Serializer" % name) + if not invoke( + lib.serialboxSerializerAddField, + self.__serializer, + namestr, + fieldmetainfo.impl(), + ): + raise SerialboxError( + "field '%s' already exists within the Serializer" % name + ) def has_field(self, field): """Check if `field` is registered within the Serializer. @@ -582,7 +652,9 @@ def has_field(self, field): :rtype: bool """ fieldstr = to_c_string(field)[0] - return bool(invoke(lib.serialboxSerializerHasField, self.__serializer, fieldstr)) + return bool( + invoke(lib.serialboxSerializerHasField, self.__serializer, fieldstr) + ) def get_field_metainfo(self, field): """Get the :class:`FieldMetainfo ` of `field`. @@ -594,9 +666,13 @@ def get_field_metainfo(self, field): :raises serialbox.SerialboxError: if `field` does not exist within the Serializer """ fieldstr = to_c_string(field)[0] - return FieldMetainfo(None, [], - impl=invoke(lib.serialboxSerializerGetFieldMetainfo, self.__serializer, - fieldstr)) + return FieldMetainfo( + None, + [], + impl=invoke( + lib.serialboxSerializerGetFieldMetainfo, self.__serializer, fieldstr + ), + ) def fieldnames(self): """Get a list of registered fieldnames within the Serializer. @@ -618,38 +694,43 @@ def fieldnames(self): @staticmethod def __extract_strides(field): """Extract strides from a numpy.array and convert to unit-strides, returns a C-Array and its - size + size """ strides = (c_int * len(field.strides))() for i in range(len(field.strides)): strides[i] = int(field.strides[i] / field.dtype.itemsize) num_strides = c_int(len(field.strides)) - return strides, num_strides, + return ( + strides, + num_strides, + ) @staticmethod def __extract_dims(field): - """Extract dimensions from a numpy.array, returns a C-Array and its size - """ + """Extract dimensions from a numpy.array, returns a C-Array and its size""" dims = (c_int * len(field.shape))() for i in range(len(field.shape)): dims[i] = int(field.shape[i]) num_dims = c_int(len(field.shape)) - return dims, num_dims, + return ( + dims, + num_dims, + ) @staticmethod def __extract_savepoint(savepoint): - """Extract the savepoint of a savepoint collection - """ + """Extract the savepoint of a savepoint collection""" if isinstance(savepoint, SavepointCollection): return savepoint.as_savepoint() else: return savepoint def __allocate_or_check_field(self, name, field): - """Allocate or check the numpy field for consistency - """ + """Allocate or check the numpy field for consistency""" if not self.has_field(name): - raise SerialboxError("field '%s' is not registered within the Serializer" % name) + raise SerialboxError( + "field '%s' is not registered within the Serializer" % name + ) info = self.get_field_metainfo(name) if field is None: @@ -657,18 +738,23 @@ def __allocate_or_check_field(self, name, field): else: if list(field.shape) != list(info.dims): raise SerialboxError( - "registered dimensions %s do not match dimensions of field (%s) %s" % ( - field.shape, name, info.dims)) + "registered dimensions %s do not match dimensions of field (%s) %s" + % (field.shape, name, info.dims) + ) if numpy2TypeID(field.dtype) != info.type: raise SerialboxError( - "registered type %s does not match type of field (%s) %s" % ( - numpy2TypeID(field.dtype), name, info.type)) + "registered type %s does not match type of field (%s) %s" + % (numpy2TypeID(field.dtype), name, info.type) + ) - return (field, info,) + return ( + field, + info, + ) def write(self, name, savepoint, field, register_field=True): - """ Serialize `field` identified by `name` at `savepoint` to disk + """Serialize `field` identified by `name` at `savepoint` to disk The `savepoint` will be registered at field `name` if not yet present. If `register_field` is `True`, the field will be registered if necessary. @@ -693,7 +779,9 @@ def write(self, name, savepoint, field, register_field=True): :raises serialbox.SerialboxError: if serialization failed """ if self.mode == OpenModeKind.Read: - raise SerialboxError("write operations are not permitted in OpenModeKind.Read") + raise SerialboxError( + "write operations are not permitted in OpenModeKind.Read" + ) savepoint = self.__extract_savepoint(savepoint) @@ -702,7 +790,9 @@ def write(self, name, savepoint, field, register_field=True): info = FieldMetainfo(numpy2TypeID(field.dtype), list(field.shape)) self.register_field(name, info) else: - raise SerialboxError("field '%s' is not registered within the Serializer" % name) + raise SerialboxError( + "field '%s' is not registered within the Serializer" % name + ) # # Extract strides and convert to unit-strides @@ -714,11 +804,18 @@ def write(self, name, savepoint, field, register_field=True): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke(lib.serialboxSerializerWrite, self.__serializer, namestr, savepoint.impl(), - origin_ptr, strides, num_strides) + invoke( + lib.serialboxSerializerWrite, + self.__serializer, + namestr, + savepoint.impl(), + origin_ptr, + strides, + num_strides, + ) def read(self, name, savepoint, field=None): - """ Deserialize `field` identified by `name` at `savepoint` from disk + """Deserialize `field` identified by `name` at `savepoint` from disk If `field` is a :class:`numpy.array ` it will be filled with data from disk. If `field` is ``None``, a new :class:`numpy.array ` will be allocated with @@ -746,7 +843,9 @@ def read(self, name, savepoint, field=None): :raises serialbox.SerialboxError: if deserialization failed """ if self.mode != OpenModeKind.Read: - raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) + raise SerialboxError( + "read operations are not permitted in OpenModeKind.%s" % self.mode + ) savepoint = self.__extract_savepoint(savepoint) @@ -765,13 +864,20 @@ def read(self, name, savepoint, field=None): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke(lib.serialboxSerializerRead, self.__serializer, namestr, savepoint.impl(), - origin_ptr, strides, num_strides) + invoke( + lib.serialboxSerializerRead, + self.__serializer, + namestr, + savepoint.impl(), + origin_ptr, + strides, + num_strides, + ) return field def read_async(self, name, savepoint, field=None): - """ Asynchronously deserialize field `name` at `savepoint` from disk. + """Asynchronously deserialize field `name` at `savepoint` from disk. If `field` is a :class:`numpy.array ` it will be filled with data from disk. If `field` is ``None``, a new :class:`numpy.array ` will be allocated with @@ -804,7 +910,9 @@ def read_async(self, name, savepoint, field=None): :raises SerialboxError: Deserialization failed """ if self.mode != OpenModeKind.Read: - raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) + raise SerialboxError( + "read operations are not permitted in OpenModeKind.%s" % self.mode + ) savepoint = self.__extract_savepoint(savepoint) @@ -823,18 +931,24 @@ def read_async(self, name, savepoint, field=None): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke(lib.serialboxSerializerReadAsync, self.__serializer, namestr, savepoint.impl(), - origin_ptr, strides, num_strides) + invoke( + lib.serialboxSerializerReadAsync, + self.__serializer, + namestr, + savepoint.impl(), + origin_ptr, + strides, + num_strides, + ) return field def wait_for_all(self): - """ Wait for all pending asynchronous read operations and reset the internal queue. - """ + """Wait for all pending asynchronous read operations and reset the internal queue.""" invoke(lib.serialboxSerializerWaitForAll, self.__serializer) def read_slice(self, name, savepoint, slice_obj, field=None): - """ Deserialize sliced `field` identified by `name` and `slice` at `savepoint` from disk + """Deserialize sliced `field` identified by `name` and `slice` at `savepoint` from disk The method will allocate a `numpy.array` with the registered dimensions and type and fill it at specified positions (given by `slice_obj`) with data from disk. @@ -874,7 +988,9 @@ def read_slice(self, name, savepoint, slice_obj, field=None): savepoint = self.__extract_savepoint(savepoint) if self.mode != OpenModeKind.Read: - raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) + raise SerialboxError( + "read operations are not permitted in OpenModeKind.%s" % self.mode + ) # # Allocate or check the field @@ -902,8 +1018,10 @@ def read_slice(self, name, savepoint, slice_obj, field=None): slice_array = list(slice_obj) if len(slice_array) > num_dims: - raise SerialboxError("number of slices (%i) exceeds number of dimensions (%i)" % ( - len(slice_array), num_dims)) + raise SerialboxError( + "number of slices (%i) exceeds number of dimensions (%i)" + % (len(slice_array), num_dims) + ) while len(slice_array) != num_dims: slice_array += [slice(None, None, None)] @@ -922,7 +1040,9 @@ def read_slice(self, name, savepoint, slice_obj, field=None): c_slice_array[3 * i + 2] = 1 else: # start - c_slice_array[3 * i] = 0 if slice_triple.start is None else slice_triple.start + c_slice_array[3 * i] = ( + 0 if slice_triple.start is None else slice_triple.start + ) # stop (expand negative values) if slice_triple.stop is None: @@ -933,15 +1053,25 @@ def read_slice(self, name, savepoint, slice_obj, field=None): c_slice_array[3 * i + 1] = dims[i] + slice_triple.stop # end - c_slice_array[3 * i + 2] = 1 if slice_triple.step is None else slice_triple.step + c_slice_array[3 * i + 2] = ( + 1 if slice_triple.step is None else slice_triple.step + ) # # Read from disk # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke(lib.serialboxSerializerReadSliced, self.__serializer, namestr, savepoint.impl(), - origin_ptr, strides, num_strides, c_slice_array) + invoke( + lib.serialboxSerializerReadSliced, + self.__serializer, + namestr, + savepoint.impl(), + origin_ptr, + strides, + num_strides, + c_slice_array, + ) return field @@ -951,7 +1081,7 @@ def read_slice(self, name, savepoint, slice_obj, field=None): @staticmethod def to_file(name, field, filename, archive=None): - """ Serialize `field` identified by `name` directly to file. + """Serialize `field` identified by `name` directly to file. This method allows stateless serializations i.e serialize fields without the need to register fields or savpoints. @@ -983,11 +1113,20 @@ def to_file(name, field, filename, archive=None): filestr = to_c_string(filename)[0] archivestr = to_c_string(archive)[0] - invoke(lib.serialboxWriteToFile, filestr, origin_ptr, typeint, dims, num_dims, strides, - namestr, archivestr) + invoke( + lib.serialboxWriteToFile, + filestr, + origin_ptr, + typeint, + dims, + num_dims, + strides, + namestr, + archivestr, + ) def from_file(name, field, filename, archive=None): - """ Deserialize `field` identified by `name` directly from file. + """Deserialize `field` identified by `name` directly from file. This method allows stateless deserializations i.e serialize fields without specifying the savepoints or fields. @@ -1028,8 +1167,17 @@ def from_file(name, field, filename, archive=None): filestr = to_c_string(filename)[0] archivestr = to_c_string(archive)[0] - invoke(lib.serialboxReadFromFile, filestr, origin_ptr, typeint, dims, num_dims, strides, - namestr, archivestr) + invoke( + lib.serialboxReadFromFile, + filestr, + origin_ptr, + typeint, + dims, + num_dims, + strides, + namestr, + archivestr, + ) def __del__(self): if self.__serializer: @@ -1054,7 +1202,7 @@ def __str__(self): return invoke(lib.serialboxSerializerToString, self.__serializer).decode() def __repr__(self): - return ''.format(self.__str__()) + return "".format(self.__str__()) register_library(lib) diff --git a/src/serialbox/core/CMakeLists.txt b/src/serialbox/core/CMakeLists.txt index f8599b07..d06eb733 100644 --- a/src/serialbox/core/CMakeLists.txt +++ b/src/serialbox/core/CMakeLists.txt @@ -60,15 +60,6 @@ set(SOURCES archive/NetCDFArchive.h archive/MockArchive.cpp archive/MockArchive.h - - frontend/stella/MetainfoSet.cpp - frontend/stella/MetainfoSet.h - frontend/stella/Savepoint.cpp - frontend/stella/Savepoint.h - frontend/stella/Serializer.cpp - frontend/stella/Serializer.h - frontend/stella/DataFieldInfo.cpp - frontend/stella/DataFieldInfo.h ) add_library(SerialboxObjects OBJECT ${SOURCES}) diff --git a/src/serialbox/core/SerializerImpl.cpp b/src/serialbox/core/SerializerImpl.cpp index 744e3d29..ff7a2b22 100644 --- a/src/serialbox/core/SerializerImpl.cpp +++ b/src/serialbox/core/SerializerImpl.cpp @@ -116,7 +116,7 @@ static inline bool dimsEqual(const std::vector& dims1, const std::vector& fieldMetainfoImpl) - : fieldMetainfoImpl_(fieldMetainfoImpl), - metainfo_(internal::make_shared_ptr(fieldMetainfoImpl_->metaInfoPtr())) {} - -DataFieldInfo::DataFieldInfo(const DataFieldInfo& other) - : fieldMetainfoImpl_(other.fieldMetainfoImpl_), - metainfo_(internal::make_shared_ptr(fieldMetainfoImpl_->metaInfoPtr())) {} - -DataFieldInfo& DataFieldInfo::operator=(const DataFieldInfo& other) { - *fieldMetainfoImpl_ = *other.fieldMetainfoImpl_; - return (*this); -} - -void DataFieldInfo::Init(std::string name, std::string type, int bytesPerElement, int rank, - int iSize, int jSize, int kSize, int lSize, int iMinusHalo, int iPlusHalo, - int jMinusHalo, int jPlusHalo, int kMinusHalo, int kPlusHalo, - int lMinusHalo, int lPlusHalo) { - - fieldMetainfoImpl_ = boost::make_shared(); - metainfo_.setImpl(internal::make_shared_ptr(fieldMetainfoImpl_->metaInfoPtr())); - - try { - TypeID typeID = internal::TypeNameToTypeID(type); - fieldMetainfoImpl_->type() = typeID; - - if(bytesPerElement != TypeUtil::sizeOf(typeID)) - throw Exception("inconsistent bytes-per-element: got '%i' but according to passed type " - "'%s' expected '%i'", - bytesPerElement, type, TypeUtil::sizeOf(typeID)); - - fieldMetainfoImpl_->dims() = std::vector{iSize, jSize, kSize, lSize}; - - MetainfoMapImpl& metaInfo = fieldMetainfoImpl_->metaInfo(); - metaInfo.clear(); - metaInfo.insert("__name", name); - metaInfo.insert("__elementtype", type); - metaInfo.insert("__bytesperelement", bytesPerElement); - metaInfo.insert("__rank", rank); - metaInfo.insert("__isize", iSize); - metaInfo.insert("__jsize", jSize); - metaInfo.insert("__ksize", kSize); - metaInfo.insert("__lsize", lSize); - metaInfo.insert("__iminushalosize", iMinusHalo); - metaInfo.insert("__iplushalosize", iPlusHalo); - metaInfo.insert("__jminushalosize", jMinusHalo); - metaInfo.insert("__jplushalosize", jPlusHalo); - metaInfo.insert("__kminushalosize", kMinusHalo); - metaInfo.insert("__kplushalosize", kPlusHalo); - metaInfo.insert("__lminushalosize", lMinusHalo); - metaInfo.insert("__lplushalosize", lPlusHalo); - - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -std::string DataFieldInfo::name() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__name") - ? fieldMetainfoImpl_->metaInfo().as("__name") - : ""; -} - -std::string DataFieldInfo::type() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__elementtype") - ? fieldMetainfoImpl_->metaInfo().as("__elementtype") - : ""; -} - -int DataFieldInfo::bytesPerElement() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__bytesperelement") - ? fieldMetainfoImpl_->metaInfo().as("__bytesperelement") - : 0; -} - -int DataFieldInfo::rank() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__rank") - ? fieldMetainfoImpl_->metaInfo().as("__rank") - : 0; -} - -int DataFieldInfo::iSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__isize") - ? fieldMetainfoImpl_->metaInfo().as("__isize") - : 1; -} - -int DataFieldInfo::jSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__jsize") - ? fieldMetainfoImpl_->metaInfo().as("__jsize") - : 1; -} - -int DataFieldInfo::kSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__ksize") - ? fieldMetainfoImpl_->metaInfo().as("__ksize") - : 1; -} - -int DataFieldInfo::lSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__lsize") - ? fieldMetainfoImpl_->metaInfo().as("__lsize") - : 1; -} - -int DataFieldInfo::iMinusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__iminushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__iminushalosize") - : 0; -} - -int DataFieldInfo::iPlusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__iplushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__iplushalosize") - : 0; -} - -int DataFieldInfo::jMinusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__jminushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__jminushalosize") - : 0; -} - -int DataFieldInfo::jPlusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__jplushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__jplushalosize") - : 0; -} - -int DataFieldInfo::kMinusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__kminushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__kminushalosize") - : 0; -} - -int DataFieldInfo::kPlusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__kplushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__kplushalosize") - : 0; -} - -int DataFieldInfo::lMinusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__lminushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__lminushalosize") - : 0; -} - -int DataFieldInfo::lPlusHaloSize() const { - return fieldMetainfoImpl_->metaInfo().hasKey("__lplushalosize") - ? fieldMetainfoImpl_->metaInfo().as("__lplushalosize") - : 0; -} - -bool DataFieldInfo::operator==(const DataFieldInfo& other) const { - return (*fieldMetainfoImpl_ == *other.fieldMetainfoImpl_); -} - -std::string DataFieldInfo::ToString() const { - std::ostringstream ss; - const auto& metaInfo = fieldMetainfoImpl_->metaInfo(); - - std::string name = metaInfo.hasKey("__name") ? metaInfo.as("__name") : ""; - - const auto& dims = fieldMetainfoImpl_->dims(); - int iSize = dims.size() < 1 ? 1 : dims[0]; - int jSize = dims.size() < 2 ? 1 : dims[1]; - int kSize = dims.size() < 3 ? 1 : dims[2]; - int lSize = dims.size() < 4 ? 1 : dims[3]; - - ss << name << " (" << iSize << "x" << jSize << "x" << kSize << "x" << lSize << ") " - << metainfo_.ToString(); - return ss.str(); -} - -void DataFieldInfo::setImpl(const boost::shared_ptr& fieldMetainfoImpl) { - metainfo_.setImpl(internal::make_shared_ptr(fieldMetainfoImpl_->metaInfoPtr())); -} - -boost::shared_ptr& DataFieldInfo::getImpl() { return fieldMetainfoImpl_; } - -const boost::shared_ptr& DataFieldInfo::getImpl() const { - return fieldMetainfoImpl_; -} - -} // namespace stella - -} // namespace serialbox diff --git a/src/serialbox/core/frontend/stella/DataFieldInfo.h b/src/serialbox/core/frontend/stella/DataFieldInfo.h deleted file mode 100644 index b1854ec9..00000000 --- a/src/serialbox/core/frontend/stella/DataFieldInfo.h +++ /dev/null @@ -1,232 +0,0 @@ -//===-- serialbox/core/frontend/stella/DataFieldInfo.h ------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the DataFieldInfo implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_DATAFIELDINFO_H -#define SERIALBOX_CORE_FRONTEND_STELLA_DATAFIELDINFO_H - -#include "serialbox/core/frontend/stella/ForwardDecl.h" -#include "serialbox/core/frontend/stella/IJKBoundary.h" -#include "serialbox/core/frontend/stella/IJKSize.h" -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include "serialbox/core/frontend/stella/TypeName.h" - -namespace serialbox { - -namespace stella { - -/// \brief Information of a data-field -/// -/// \ingroup STELLA -class DataFieldInfo { -public: - /// \brief Default constructor - DataFieldInfo(); - - /// \brief Construct with FieldMetainfoImpl - DataFieldInfo(const boost::shared_ptr& fieldMetainfoImpl); - - /// \brief Copy constructor - DataFieldInfo(const DataFieldInfo& other); - - /// \brief Assignment operator - DataFieldInfo& operator=(const DataFieldInfo& other); - - /// \brief Initialize with field. - /// - /// This general-purpose initializer reads the information from a given data field. - /// - /// \param dataField The field of which the information must be read - template - void Init(const TDataField& dataField) { - Init(dataField, dataField.name()); - } - - /// \brief Initializer with field and new name. - /// - /// This general-purpose initializer recovers the information from a given data field. - /// - /// \param dataField The field of which the information must be read - /// \param name The name of the field when serialized - template - void Init(const TDataField& dataField, std::string name) { - // Get the calculation domain - IJKSize domain; - domain.Init(dataField.calculationDomain().iSize(), dataField.calculationDomain().jSize(), - dataField.calculationDomain().kSize()); - - IJKSize size; - size.Init(dataField.storage().allocatedSize().iSize(), - dataField.storage().allocatedSize().jSize(), - dataField.storage().allocatedSize().kSize()); - - // Get the size of the halo - IJKBoundary boundary; - boundary.Init(dataField.boundary().iMinusOffset(), dataField.boundary().iPlusOffset(), - dataField.boundary().jMinusOffset(), dataField.boundary().jPlusOffset(), - dataField.boundary().kMinusOffset(), dataField.boundary().kPlusOffset()); - - // Workaround for boundary() not returning what it should - const bool haloInI = !(size.iSize() <= domain.iSize()); - const bool haloInJ = !(size.jSize() <= domain.jSize()); - const bool haloInK = !(size.kSize() <= domain.kSize()); - const int iMinus = haloInI ? -boundary.iMinusOffset() : 0; - const int iPlus = haloInI ? boundary.iPlusOffset() : 0; - const int jMinus = haloInJ ? -boundary.jMinusOffset() : 0; - const int jPlus = haloInJ ? boundary.jPlusOffset() : 0; - const int kMinus = haloInK ? -boundary.kMinusOffset() : 0; - const int kPlus = haloInK ? boundary.kPlusOffset() : 0; - - // Delegate the initialization - Init(name, type_name(), sizeof(typename TDataField::ValueType), - dataField.storage().rank(), size.iSize(), size.jSize(), size.kSize(), 1, iMinus, iPlus, - jMinus, jPlus, kMinus, kPlus, 0, 0); - } - - /// \brief Initializer with sparse information. - /// - /// This initializer collects the information given in the multiple parameters. - /// - /// \param name The name of the field - /// \param type The data type of the field (e.g. "double") - /// \param bytesPerElement The size in bytes of a single entry - /// \param rank The number of dimensions of the field - /// \param iSize The size in i-direction (including of halo) - /// \param jSize The size in j-direction (including of halo) - /// \param kSize The size in k-direction (including of halo) - /// \param lSize The size in l-direction (including of halo) - /// \param iMinusHalo The dimension of the halo in negative i-direction - /// \param iPlusHalo The dimension of the halo in positive i-direction - /// \param jMinusHalo The dimension of the halo in negative j-direction - /// \param jPlusHalo The dimension of the halo in positive j-direction - /// \param kMinusHalo The dimension of the halo in negative k-direction - /// \param kPlusHalo The dimension of the halo in positive k-direction - /// \param lMinusHalo The dimension of the halo in negative l-direction - /// \param lPlusHalo The dimension of the halo in positive l-direction - void Init(std::string name, std::string type, int bytesPerElement, int rank, int iSize, int jSize, - int kSize, int lSize, int iMinusHalo, int iPlusHalo, int jMinusHalo, int jPlusHalo, - int kMinusHalo, int kPlusHalo, int lMinusHalo, int lPlusHalo); - - /// \brief Gives read-only access to the metainformation associated with the field - const MetainfoSet& metainfo() const { return metainfo_; } - - /// \brief The field name - std::string name() const; - - /// \brief The field scalar type - std::string type() const; - - /// \brief The size of the field data in bytes is returned - int dataSize() const { return bytesPerElement() * iSize() * jSize() * kSize() * lSize(); } - - /// \brief The dimension in bytes of a single element - int bytesPerElement() const; - - /// \brief The number of dimensions of the field - int rank() const; - - /// \brief The size of the field in i-direction, including the halo - int iSize() const; - - /// \brief The size of the field in j-direction, including the halo - int jSize() const; - - /// \brief The size of the field in k-direction, including the halo - int kSize() const; - - /// \brief The size of the field in l-direction, including the halo - int lSize() const; - - /// \brief The size of the halo in negative i-direction - int iMinusHaloSize() const; - - /// \brief The size of the halo in positive i-direction - int iPlusHaloSize() const; - - /// \brief The size of the halo in negative j-direction - int jMinusHaloSize() const; - - /// \brief The size of the halo in positive j-direction - int jPlusHaloSize() const; - - /// \brief The size of the halo in negative k-direction - int kMinusHaloSize() const; - - /// \brief The size of the halo in positive k-direction - int kPlusHaloSize() const; - - /// \brief The size of the halo in negative l-direction - int lMinusHaloSize() const; - - /// \brief The size of the halo in positive l-direction - int lPlusHaloSize() const; - - /// \brief The number of bytes occupied by the field - int fieldLength() const { return bytesPerElement() * iSize() * jSize() * kSize() * lSize(); } - - /// \brief The calculation domain of the field - IJKSize calculationDomain() const { - IJKSize size; - size.Init(iSize() - iMinusHaloSize() - iPlusHaloSize(), - jSize() - jMinusHaloSize() - jPlusHaloSize(), - kSize() - kMinusHaloSize() - kPlusHaloSize()); - return size; - } - - /// \brief The total storage of the field (calculation domain and boundary) - IJKSize size() const { - IJKSize size; - size.Init(iSize(), jSize(), kSize()); - return size; - } - - /// \brief The size of the halo of the field - IJKBoundary boundary() const { - IJKBoundary boundary; - boundary.Init(-iMinusHaloSize(), iPlusHaloSize(), -jMinusHaloSize(), jPlusHaloSize(), - -kMinusHaloSize(), kPlusHaloSize()); - return boundary; - } - - /// \brief Add new metainformation - template - void AddMetainfo(const std::string& key, const ValueType& value) { - metainfo_.AddMetainfo(key, value); - } - - /// \brief Comparator operator - bool operator==(const DataFieldInfo& other) const; - - /// \brief Comparator operator - inline bool operator!=(const DataFieldInfo& other) const { return !(*this == other); } - - /// \brief Gives a string representation of the object, useful for debugging - std::string ToString() const; - - /// \brief Set implementation pointer - void setImpl(const boost::shared_ptr& fieldMetainfoImpl); - - /// \brief Get implementation pointer - boost::shared_ptr& getImpl(); - const boost::shared_ptr& getImpl() const; - -private: - boost::shared_ptr fieldMetainfoImpl_; - MetainfoSet metainfo_; // Allow refrence access -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/ForwardDecl.h b/src/serialbox/core/frontend/stella/ForwardDecl.h deleted file mode 100644 index 15557306..00000000 --- a/src/serialbox/core/frontend/stella/ForwardDecl.h +++ /dev/null @@ -1,39 +0,0 @@ -//===-- serialbox/core/frontend/stella/ForwardDecl.h --------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains forward declaration of the Core infrastructure. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_FORWARDDECL_H -#define SERIALBOX_CORE_FRONTEND_STELLA_FORWARDDECL_H - -#include "serialbox/core/Compiler.h" - -namespace serialbox { - -class FieldMap; -class FieldMetainfoImpl; -class MetainfoMapImpl; -class MetainfoValueImpl; -class SerializerImpl; -class SavepointImpl; - -/// \namespace stella -/// \brief Namespace of the STELLA frontend -namespace stella {} - -} // namespace serialbox - -/// \namespace ser -/// \brief Namespace of the old serialbox library -namespace ser = serialbox::stella; - -#endif diff --git a/src/serialbox/core/frontend/stella/IJKBoundary.h b/src/serialbox/core/frontend/stella/IJKBoundary.h deleted file mode 100644 index 96265e7c..00000000 --- a/src/serialbox/core/frontend/stella/IJKBoundary.h +++ /dev/null @@ -1,116 +0,0 @@ -//===-- serialbox/core/frontend/stella/IJKBoundary.h --------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the defintion of the boundary container. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_IJKBOUNDARY_H -#define SERIALBOX_CORE_FRONTEND_STELLA_IJKBOUNDARY_H - -namespace serialbox { - -namespace stella { - -/// \brief Container for the boundary size -/// -/// Container for boundary offsets in all directions of 3D domain. Positive numbers indicate count -/// arrow direction, negative numbers the opposite. Therefore i-/j-/k-minus are typically negative. -/// -/// \verbatim -/// ^ j-plus -/// | -/// i-minus <-----> i-plus -/// | -/// v j-minus -/// \endverbatim -/// -/// \ingroup STELLA -class IJKBoundary { -public: - IJKBoundary() { - iMinusOffset_ = 0; - iPlusOffset_ = 0; - jMinusOffset_ = 0; - jPlusOffset_ = 0; - kMinusOffset_ = 0; - kPlusOffset_ = 0; - } - - ~IJKBoundary() {} - - IJKBoundary(const IJKBoundary& other) { *this = other; } - - IJKBoundary& operator=(const IJKBoundary& other) { - iMinusOffset_ = other.iMinusOffset_; - iPlusOffset_ = other.iPlusOffset_; - jMinusOffset_ = other.jMinusOffset_; - jPlusOffset_ = other.jPlusOffset_; - kMinusOffset_ = other.kMinusOffset_; - kPlusOffset_ = other.kPlusOffset_; - return *this; - } - - bool operator==(const IJKBoundary& other) const { - return ((iMinusOffset() == other.iMinusOffset()) && (iPlusOffset() == other.iPlusOffset()) && - (jMinusOffset() == other.jMinusOffset()) && (jPlusOffset() == other.jPlusOffset()) && - (kMinusOffset() == other.kMinusOffset()) && (kPlusOffset() == other.kPlusOffset())); - } - - /// \brief Init the container - /// - /// \param iMinusOffset Offset of boundary in i-minus direction of domain - /// \param iPlusOffset Offset of boundary in i-plus direction of domain - /// \param jMinusOffset Offset of boundary in j-minus direction of domain - /// \param jPlusOffset Offset of boundary in j-plus direction of domain - /// \param kMinusOffset Offset of boundary in k-minus direction of domain - /// \param kPlusOffset Offset of boundary in k-plus direction of domain - void Init(const int iMinusOffset, const int iPlusOffset, const int jMinusOffset, - const int jPlusOffset, const int kMinusOffset, const int kPlusOffset) { - iMinusOffset_ = iMinusOffset; - iPlusOffset_ = iPlusOffset; - jMinusOffset_ = jMinusOffset; - jPlusOffset_ = jPlusOffset; - kMinusOffset_ = kMinusOffset; - kPlusOffset_ = kPlusOffset; - } - - /// \brief Offset in i-minus direction - int iMinusOffset() const { return iMinusOffset_; } - - /// \brief Offset in i-plus direction - int iPlusOffset() const { return iPlusOffset_; } - - /// \brief Offset in j-minus direction - int jMinusOffset() const { return jMinusOffset_; } - - /// \brief Offset in j-plus direction - int jPlusOffset() const { return jPlusOffset_; } - - /// \brief Offset in k-minus direction - int kMinusOffset() const { return kMinusOffset_; } - - /// \brief Offset in k-plus direction - int kPlusOffset() const { return kPlusOffset_; } - -private: - int iMinusOffset_; - int iPlusOffset_; - int jMinusOffset_; - int jPlusOffset_; - int kMinusOffset_; - int kPlusOffset_; -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/IJKSize.h b/src/serialbox/core/frontend/stella/IJKSize.h deleted file mode 100644 index fb3d044d..00000000 --- a/src/serialbox/core/frontend/stella/IJKSize.h +++ /dev/null @@ -1,82 +0,0 @@ -//===-- serialbox/core/frontend/stella/IJKSize.h ------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the defintion of the size container. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_IJKSIZE_H -#define SERIALBOX_CORE_FRONTEND_STELLA_IJKSIZE_H - -#include - -namespace serialbox { - -namespace stella { - -/// \brief Container for i, j, k Size -/// -/// \ingroup STELLA -class IJKSize { -public: - IJKSize() { - iSize_ = 0; - jSize_ = 0; - kSize_ = 0; - } - - ~IJKSize() {} - - IJKSize(const IJKSize& other) { *this = other; } - - IJKSize& operator=(const IJKSize& other) { - iSize_ = other.iSize_; - jSize_ = other.jSize_; - kSize_ = other.kSize_; - return *this; - } - - bool operator==(const IJKSize& other) const { - return ((iSize() == other.iSize()) && (jSize() == other.jSize()) && (kSize() == other.kSize())); - } - - /// \brief Init the container - /// - /// \param iSize size in i dimension - /// \param jSize size in j dimension - /// \param kSize size in k dimension - void Init(const int iSize, const int jSize, const int kSize) { - assert(iSize >= 0 && jSize >= 0 && kSize >= 0); - iSize_ = iSize; - jSize_ = jSize; - kSize_ = kSize; - } - - /// \brief Size in i dimension - int iSize() const { return iSize_; } - - /// \brief Size in j dimension - int jSize() const { return jSize_; } - - /// \brief Size in k dimension - int kSize() const { return kSize_; } - - //// \brief Check if container is empty - bool empty() const { return iSize_ <= 0 || jSize_ <= 0 || kSize_ <= 0; } - -private: - int iSize_, jSize_, kSize_; -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/KBoundary.h b/src/serialbox/core/frontend/stella/KBoundary.h deleted file mode 100644 index d4b4d323..00000000 --- a/src/serialbox/core/frontend/stella/KBoundary.h +++ /dev/null @@ -1,78 +0,0 @@ -//===-- serialbox/core/frontend/stella/KBoundary.h ----------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the defintion of the k-boundary offset container. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_KBOUNDARY_H -#define SERIALBOX_CORE_FRONTEND_STELLA_KBOUNDARY_H - -namespace serialbox { - -namespace stella { - -/// \brief Container for boundary offsets in k direction -/// -/// Positive numbers indicate count arrow direction, negative numbers the opposite. -/// Therefore k-minus is typically negative. -/// -/// \verbatim -/// ^ k-plus -/// | -/// v k-minus -/// \endverbatim -/// -/// \ingroup STELLA -class KBoundary { -public: - KBoundary() { - kMinusOffset_ = 0; - kPlusOffset_ = 0; - } - ~KBoundary() {} - - KBoundary(const KBoundary& other) { *this = other; } - - KBoundary& operator=(const KBoundary& other) { - kMinusOffset_ = other.kMinusOffset_; - kPlusOffset_ = other.kPlusOffset_; - return *this; - } - - bool operator==(const KBoundary& other) const { - return ((kMinusOffset() == other.kMinusOffset()) && (kPlusOffset() == other.kPlusOffset())); - } - - /// \brief Init the container - /// - /// \param kMinusOffset Offset of boundary in k-minus direction of domain - /// \param kPlusOffset Offset of boundary in k-plus direction of domain - void Init(const int kMinusOffset, const int kPlusOffset) { - kMinusOffset_ = kMinusOffset; - kPlusOffset_ = kPlusOffset; - } - - /// \brief Offset in k-minus direction - int kMinusOffset() const { return kMinusOffset_; } - - /// \brie Offset in k-plus direction - int kPlusOffset() const { return kPlusOffset_; } - -private: - int kMinusOffset_; - int kPlusOffset_; -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/MetainfoSet.cpp b/src/serialbox/core/frontend/stella/MetainfoSet.cpp deleted file mode 100644 index b2dcbd31..00000000 --- a/src/serialbox/core/frontend/stella/MetainfoSet.cpp +++ /dev/null @@ -1,150 +0,0 @@ -//===-- serialbox/core/frontend/stella/MetainfoSet.cpp ------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the meta-information set implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include "serialbox/core/Exception.h" -#include "serialbox/core/MetainfoMapImpl.h" -#include "serialbox/core/Unreachable.h" -#include "serialbox/core/frontend/stella/Utility.h" -#include - -namespace serialbox { - -namespace stella { - -namespace internal { - -template -static MetainfoMapImpl::const_iterator -checkKeyExists(const boost::shared_ptr& mapImpl, KeyType&& key) { - auto it = mapImpl->find(key); - if(it == mapImpl->end()) - internal::throwSerializationException("Error: requested key %s is not in set", key); - return it; -} -} // namespace internal - -MetainfoSet::MetainfoSet() : mapImpl_(boost::make_shared()) {} - -MetainfoSet::MetainfoSet(const boost::shared_ptr& map) : mapImpl_(map){}; - -MetainfoSet::MetainfoSet(const MetainfoSet& other) { mapImpl_ = other.mapImpl_; } - -MetainfoSet& MetainfoSet::operator=(const MetainfoSet& other) { - *mapImpl_ = *other.mapImpl_; - return (*this); -} - -void MetainfoSet::Cleanup() { mapImpl_->clear(); } - -bool MetainfoSet::HasKey(const std::string& key) const { return mapImpl_->hasKey(key); } - -void MetainfoSet::AddMetainfo(const std::string& key, const bool& value) { - if(!mapImpl_->insert(key, value)) - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); -} - -void MetainfoSet::AddMetainfo(const std::string& key, const int& value) { - if(!mapImpl_->insert(key, value)) - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); -} - -void MetainfoSet::AddMetainfo(const std::string& key, const float& value) { - if(!mapImpl_->insert(key, value)) - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); -} - -void MetainfoSet::AddMetainfo(const std::string& key, const double& value) { - if(!mapImpl_->insert(key, value)) - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); -} - -void MetainfoSet::AddMetainfo(const std::string& key, const std::string& value) { - if(!mapImpl_->insert(key, value)) - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); -} - -const boost::any& MetainfoSet::AsAny(const std::string& key) const { - return internal::checkKeyExists(mapImpl_, key)->second.any(); -} - -bool MetainfoSet::AsBool(const std::string& key) const { - MetainfoValueImpl value = internal::checkKeyExists(mapImpl_, key)->second; - return value.as(); -} - -int MetainfoSet::AsInt(const std::string& key) const { - MetainfoValueImpl value = internal::checkKeyExists(mapImpl_, key)->second; - try { - return value.as(); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } - serialbox_unreachable("unreachable"); -} - -float MetainfoSet::AsFloat(const std::string& key) const { - MetainfoValueImpl value = internal::checkKeyExists(mapImpl_, key)->second; - return value.as(); -} - -double MetainfoSet::AsDouble(const std::string& key) const { - MetainfoValueImpl value = internal::checkKeyExists(mapImpl_, key)->second; - return value.as(); -} - -std::string MetainfoSet::AsString(const std::string& key) const { - MetainfoValueImpl value = internal::checkKeyExists(mapImpl_, key)->second; - return value.as(); -} - -std::string MetainfoSet::ToString() const { - std::ostringstream ss; - ss << "[ "; - for(auto it = mapImpl_->begin(), end = mapImpl_->end(); it != end; ++it) - if(!boost::algorithm::starts_with(it->first, "__")) - ss << it->first << "=" << it->second.toString() << " "; - ss << "]"; - return ss.str(); -} - -std::size_t MetainfoSet::size() const { - std::size_t s = 0; - for(auto it = mapImpl_->begin(), end = mapImpl_->end(); it != end; ++it) - if(!boost::algorithm::starts_with(it->first, "__")) - s++; - return s; -} - -bool MetainfoSet::operator==(const MetainfoSet& other) const { - return (*mapImpl_ == *other.mapImpl_); -} - -void MetainfoSet::setImpl(const boost::shared_ptr& metaInfoMap) { - mapImpl_ = metaInfoMap; -} - -std::vector MetainfoSet::keys() const { - std::vector keyStr; - for(auto it = mapImpl_->begin(), end = mapImpl_->end(); it != end; ++it) - keyStr.push_back(it->first); - return keyStr; -} - -boost::shared_ptr& MetainfoSet::getImpl() { return mapImpl_; } -const boost::shared_ptr& MetainfoSet::getImpl() const { return mapImpl_; } - -} // namespace stella - -} // namespace serialbox diff --git a/src/serialbox/core/frontend/stella/MetainfoSet.h b/src/serialbox/core/frontend/stella/MetainfoSet.h deleted file mode 100644 index efbbf891..00000000 --- a/src/serialbox/core/frontend/stella/MetainfoSet.h +++ /dev/null @@ -1,198 +0,0 @@ -//===-- serialbox/core/frontend/stella/MetainfoSet.h --------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the meta-information set implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_METAINFOSET_H -#define SERIALBOX_CORE_FRONTEND_STELLA_METAINFOSET_H - -#include "serialbox/core/frontend/stella/ForwardDecl.h" -#include -#include -#include -#include -#include - -namespace serialbox { - -namespace stella { - -/// \brief Meta-information set -/// -/// Objects of this class contain a set of metainformation in form of key = value pair. The keys -/// are strings, while the values can be integers, booleans, floating point numbers (either single -/// or double precision) or strings. -/// -/// \ingroup STELLA -class MetainfoSet { -public: - /// \brief Construct empty map - MetainfoSet(); - - /// \brief Construct with MetainfoMapImpl - explicit MetainfoSet(const boost::shared_ptr& map); - - /// \brief Copy constructor - MetainfoSet(const MetainfoSet& other); - - /// \brief Assignment operator - /// - /// Discards all previously stored information and copies data from the other object, performing - /// a deep copy. - /// - /// \param other The object to copy from - MetainfoSet& operator=(const MetainfoSet& other); - - /// Removes all metainfo and frees all memory - void Cleanup(); - - /// \brief Gives access to all existing keys - /// - /// The order in which the keys are returned is ensured not to change if no keys are added or - /// removed. - /// - /// \return A vector containing all keys is returned - std::vector keys() const; - - /// \brief Check if key exists already in set - /// - /// \return True is returned iff the key does exist - bool HasKey(const std::string& key) const; - - /// \brief Add a new key-value pair into the set. The key must not exist yet - /// - /// \param key The key of the pair - /// \param value The value - /// - /// \throw SerializationException The key exists already - /// @{ - void AddMetainfo(const std::string& key, const int& value); - void AddMetainfo(const std::string& key, const bool& value); - void AddMetainfo(const std::string& key, const float& value); - void AddMetainfo(const std::string& key, const double& value); - void AddMetainfo(const std::string& key, const std::string& value); - void AddMetainfo(const std::string& key, const char* value) { - AddMetainfo(key, std::string(value)); - } - /// @} - - /// \brief Gives access to the internal representation of the requested metainfo - /// - /// \param key The identification of the metainfo value which is requested - /// \return The metainfo object is returned as constant reference - /// - /// \throw SerializationException The key exists already - const boost::any& AsAny(const std::string& key) const; - - /// \brief Extracts a value in bool representation - /// - /// If the type is different than bool, the function does its best to convert the value to bool - /// in a meaningful way. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist - bool AsBool(const std::string& key) const; - - /// \brief Extracts a value in int representation - /// - /// If the type is different than int, the function does its best to convert the value to int in a - /// meaningful way, and throws a SerializationException if the value is not convertible to int, - /// e.g., in case of a floating point holding a non-integer value. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist or the value is not convertible to - /// integer - int AsInt(const std::string& key) const; - - /// \brief Extracts a value in single precision floating point representation - /// - /// If the type is different than float, the function converts the value to float. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist - float AsFloat(const std::string& key) const; - - /// Extracts a value in double precision floating point representation - /// - /// If the type is different than double, the function converts the value to double. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist - double AsDouble(const std::string& key) const; - - /// \brief Extracts a value in RealType representation, where RealType is either `float` or - /// `double` - /// - /// If the type is different than RealType, the function converts the value to RealType. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist - template - RealType AsReal(const std::string& key) const { - BOOST_STATIC_ASSERT( - (boost::is_same::value || boost::is_same::value)); - - if(boost::is_same::value) - return AsFloat(key); - else if(boost::is_same::value) - return AsDouble(key); - } - - /// \brief Extracts a value assuming its type is string - /// - /// If the type is different than string, the function constructs a string representation of it. - /// - /// \param key The identification of the metainfo value which is requested - /// \return The value of the metainfo is returned as copy - /// - /// \throw SerializationException The key does not exist - std::string AsString(const std::string& key) const; - - /// \brief Creates a string that carries the metainfo in a human-readable form - /// - /// \return The string representing the set is returned - std::string ToString() const; - - /// \brief Number elements in the set - /// - /// \return The size of the set is returned - std::size_t size() const; - - /// \brief Comparison operator - bool operator==(const MetainfoSet& other) const; - - /// \brief Set implementation pointer - void setImpl(const boost::shared_ptr& metaInfoMap); - - /// \brief Get implementation pointer - boost::shared_ptr& getImpl(); - const boost::shared_ptr& getImpl() const; - -private: - boost::shared_ptr mapImpl_; -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/Savepoint.cpp b/src/serialbox/core/frontend/stella/Savepoint.cpp deleted file mode 100644 index 59d944e0..00000000 --- a/src/serialbox/core/frontend/stella/Savepoint.cpp +++ /dev/null @@ -1,110 +0,0 @@ -//===-- serialbox/core/frontend/stella/Savepoint.cpp --------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the Savepoint implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/Savepoint.h" -#include "serialbox/core/SavepointImpl.h" -#include "serialbox/core/frontend/stella/Utility.h" -#include - -namespace serialbox { - -namespace stella { - -namespace internal { - -template -void insertHelper(boost::shared_ptr& savepointImpl, KeyType&& key, - ValueType&& value) { - try { - savepointImpl->addMetainfo(key, value); - } catch(Exception& e) { - internal::throwSerializationException("Error: metainfo with key = %s exists already", key); - } -} - -} // namespace internal - -Savepoint::Savepoint() : savepointImpl_(), metainfo_() {} - -void Savepoint::Init(const std::string& name) { - savepointImpl_ = boost::make_shared(name); - metainfo_.setImpl(internal::make_shared_ptr(savepointImpl_->metaInfoPtr())); -} - -Savepoint::Savepoint(const boost::shared_ptr& savepointImpl) - : savepointImpl_(savepointImpl), - metainfo_(internal::make_shared_ptr(savepointImpl_->metaInfoPtr())){}; - -Savepoint::Savepoint(const Savepoint& other) { - savepointImpl_ = other.savepointImpl_; - metainfo_.setImpl(internal::make_shared_ptr(savepointImpl_->metaInfoPtr())); -} - -Savepoint& Savepoint::operator=(const Savepoint& other) { - // Make sure savepointImpl_ is allocated - if(!savepointImpl_) - Init(""); - - // Use the assignment operator of the implementation class - *savepointImpl_ = *other.savepointImpl_; - metainfo_.setImpl(internal::make_shared_ptr(savepointImpl_->metaInfoPtr())); - return (*this); -} - -void Savepoint::AddMetainfo(const std::string& key, const bool& value) { - internal::insertHelper(savepointImpl_, key, value); -} - -void Savepoint::AddMetainfo(const std::string& key, const int& value) { - internal::insertHelper(savepointImpl_, key, value); -} - -void Savepoint::AddMetainfo(const std::string& key, const float& value) { - internal::insertHelper(savepointImpl_, key, value); -} - -void Savepoint::AddMetainfo(const std::string& key, const double& value) { - internal::insertHelper(savepointImpl_, key, value); -} - -void Savepoint::AddMetainfo(const std::string& key, const std::string& value) { - internal::insertHelper(savepointImpl_, key, value); -} - -bool Savepoint::operator==(const Savepoint& other) const { - return (*savepointImpl_ == *other.savepointImpl_); -} - -bool Savepoint::operator!=(const Savepoint& other) const { - return (*savepointImpl_ != *other.savepointImpl_); -} - -const std::string& Savepoint::name() const { return savepointImpl_->name(); } - -std::string Savepoint::ToString() const { return savepointImpl_->toString(); } - -std::ostream& operator<<(std::ostream& out, const Savepoint& sp) { return (out << sp.ToString()); } - -void Savepoint::setImpl(const boost::shared_ptr& savepointImpl) { - savepointImpl_ = savepointImpl; - metainfo_.setImpl(internal::make_shared_ptr(savepointImpl_->metaInfoPtr())); -} - -boost::shared_ptr& Savepoint::getImpl() { return savepointImpl_; } - -const boost::shared_ptr& Savepoint::getImpl() const { return savepointImpl_; } - -} // namespace stella - -} // namespace serialbox diff --git a/src/serialbox/core/frontend/stella/Savepoint.h b/src/serialbox/core/frontend/stella/Savepoint.h deleted file mode 100644 index 9a4d416c..00000000 --- a/src/serialbox/core/frontend/stella/Savepoint.h +++ /dev/null @@ -1,112 +0,0 @@ -//===-- serialbox/core/frontend/stella/Savepoint.h ----------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the Savepoint implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_SAVEPOINT_H -#define SERIALBOX_CORE_FRONTEND_STELLA_SAVEPOINT_H - -#include "serialbox/core/frontend/stella/ForwardDecl.h" -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include -#include - -namespace serialbox { - -namespace stella { - -/// \brief Implementation of the STELLA Savepoint -/// -/// \ingroup STELLA -class Savepoint { -public: - /// \brief Construct empty savepoint with name `name` - Savepoint(); - - /// \brief Initialize the savepoint - /// - /// This method prepares the savepoint for usage and gives a name, which is the only required - /// information for the savepoint to be usable. Metainformation can be added after the - /// initialization has been performed. - /// - /// A savepoint can be initialized multiple times. In this case, every initialization removes all - /// metainformation and sets a new name. - /// - /// \param name The name of the savepoint - void Init(const std::string& name); - - /// \brief Construct with SavepointImpl - explicit Savepoint(const boost::shared_ptr& savepointImpl); - - /// \brief Copy constructor - Savepoint(const Savepoint& other); - - /// \brief Copy assignment - Savepoint& operator=(const Savepoint& other); - - /// \brief Add metainformation to the savepoint - /// - /// After this call a new key-value pair is registered as metainformation in the savepoint. The - /// order in which the metainformation is added is irrelevant. - /// - /// \param key The key of the new metainformation - /// \param value The value of the new metainformaiton - /// - /// \throw SerializationException The key exists already - /// @{ - void AddMetainfo(const std::string& key, const bool& value); - void AddMetainfo(const std::string& key, const int& value); - void AddMetainfo(const std::string& key, const float& value); - void AddMetainfo(const std::string& key, const double& value); - void AddMetainfo(const std::string& key, const std::string& value); - void AddMetainfo(const std::string& key, const char* value) { - AddMetainfo(key, std::string(value)); - } - /// @} - - /// \brief Access to the name - const std::string& name() const; - - /// \brief Access to the metainfo - /// - /// The meta-information is constructed from the underlying MetainfoMapImpl of the SavepointImpl. - const MetainfoSet& metainfo() const { return metainfo_; } - - /// \brief Compare equal - bool operator==(const Savepoint& other) const; - - /// \brief Compare unequal - bool operator!=(const Savepoint& other) const; - - /// \brief Convert to string - std::string ToString() const; - - /// \brief Convert to stream - friend std::ostream& operator<<(std::ostream& out, const Savepoint& sp); - - /// \brief Set implementation pointer - void setImpl(const boost::shared_ptr& savepointImpl); - - /// \brief Get implementation pointer - boost::shared_ptr& getImpl(); - const boost::shared_ptr& getImpl() const; - -private: - boost::shared_ptr savepointImpl_; - MetainfoSet metainfo_; // Allow refrence access -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/SerializationException.h b/src/serialbox/core/frontend/stella/SerializationException.h deleted file mode 100644 index 04fae7c6..00000000 --- a/src/serialbox/core/frontend/stella/SerializationException.h +++ /dev/null @@ -1,54 +0,0 @@ -//===-- serialbox/core/frontend/stella/SerializationException.h ---------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains helper functions to create StorageViews of STELLA fields. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_SERIALIZATIONEXCEPTION_H -#define SERIALBOX_CORE_FRONTEND_STELLA_SERIALIZATIONEXCEPTION_H - -#include "serialbox/core/frontend/stella/ForwardDecl.h" -#include -#include - -namespace serialbox { - -namespace stella { - -/// \brief Exception of the STELLA frontend -/// -/// \ingroup STELLA -class SerializationException : public std::exception { -public: - /// \brief Default constructor - SerializationException() throw() {} - - /// \brief Virtual destructor - virtual ~SerializationException() throw() {} - - /// \brief Initialize the exception with an explanatory string `errormsg` - void Init(const std::string& errormsg) { message_ = errormsg; } - - /// \brief Returns an explanatory string - const char* what() const throw() { return message_.c_str(); } - - /// \brief Returns an explanatory string - const std::string& message() const { return message_; } - -private: - std::string message_; -}; - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/Serializer.cpp b/src/serialbox/core/frontend/stella/Serializer.cpp deleted file mode 100644 index 785c7f84..00000000 --- a/src/serialbox/core/frontend/stella/Serializer.cpp +++ /dev/null @@ -1,294 +0,0 @@ -//===-- serialbox/core/frontend/stella/Serializer.cpp -------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the Serializer implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/Serializer.h" -#include "serialbox/core/SerializerImpl.h" -#include "serialbox/core/Unreachable.h" -#include "serialbox/core/frontend/stella/Utility.h" -#include -#include - -namespace serialbox { - -namespace stella { - -int Serializer::enabled_ = 0; - -Serializer::Serializer() {} - -SerializerOpenMode Serializer::mode() const { - switch(serializerImpl_->mode()) { - case OpenModeKind::Read: - return SerializerOpenModeRead; - case OpenModeKind::Write: - return SerializerOpenModeWrite; - case OpenModeKind::Append: - return SerializerOpenModeAppend; - default: - serialbox_unreachable("invalid mode"); - } -} - -void Serializer::EnableSerialization() { SerializerImpl::enableSerialization(); } - -void Serializer::DisableSerialization() { SerializerImpl::disableSerialization(); } - -std::string Serializer::directory() const { return serializerImpl_->directory().string(); } - -std::string Serializer::prefix() const { return serializerImpl_->prefix(); } - -void Serializer::Init(const std::string& directory, const std::string& prefix, - SerializerOpenMode mode) { - if(SerializerImpl::serializationStatus() == 0) { - const char* envvar = std::getenv("STELLA_SERIALIZATION_DISABLED"); - if(envvar && std::atoi(envvar) > 0) - SerializerImpl::disableSerialization(); - } - - // Initialize SerializerImpl - try { - switch(mode) { - case SerializerOpenModeRead: - serializerImpl_ = - boost::make_shared(OpenModeKind::Read, directory, prefix, "Binary"); - break; - case SerializerOpenModeWrite: - serializerImpl_ = - boost::make_shared(OpenModeKind::Write, directory, prefix, "Binary"); - break; - case SerializerOpenModeAppend: - serializerImpl_ = - boost::make_shared(OpenModeKind::Append, directory, prefix, "Binary"); - break; - } - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } - - // Initialize MetainfoSet - globalMetainfo_.setImpl( - internal::make_shared_ptr(serializerImpl_->globalMetainfoPtr())); - - // Initialize savepoint vector - for(auto& savepoint : serializerImpl_->savepoints()) - savepoints_.emplace_back(internal::make_shared_ptr(savepoint)); - - // Initialize data field infos - for(auto it = serializerImpl_->fieldMap().begin(), end = serializerImpl_->fieldMap().end(); - it != end; ++it) - datafieldInfos_.insert({it->first, internal::make_shared_ptr(it->second)}); -} - -bool Serializer::RegisterField(const std::string& name, std::string type, int bytesPerElement, - int iSize, int jSize, int kSize, int lSize, int iMinusHalo, - int iPlusHalo, int jMinusHalo, int jPlusHalo, int kMinusHalo, - int kPlusHalo, int lMinusHalo, int lPlusHalo) { - try { - TypeID typeID = internal::TypeNameToTypeID(type); - if(bytesPerElement != TypeUtil::sizeOf(typeID)) - throw Exception("inconsistent bytes-per-element: got '%i' but according to passed type " - "'%s' expected '%i'", - bytesPerElement, type, TypeUtil::sizeOf(typeID)); - - int rank = - (iSize != 1 ? 1 : 0) + (jSize != 1 ? 1 : 0) + (kSize != 1 ? 1 : 0) + (lSize != 1 ? 1 : 0); - - std::vector dims{iSize, jSize, kSize, lSize}; - MetainfoMapImpl metaInfo; - metaInfo.insert("__name", name); - metaInfo.insert("__elementtype", type); - metaInfo.insert("__bytesperelement", bytesPerElement); - metaInfo.insert("__rank", rank); - metaInfo.insert("__isize", iSize); - metaInfo.insert("__jsize", jSize); - metaInfo.insert("__ksize", kSize); - metaInfo.insert("__lsize", lSize); - metaInfo.insert("__iminushalosize", iMinusHalo); - metaInfo.insert("__iplushalosize", iPlusHalo); - metaInfo.insert("__jminushalosize", jMinusHalo); - metaInfo.insert("__jplushalosize", jPlusHalo); - metaInfo.insert("__kminushalosize", kMinusHalo); - metaInfo.insert("__kplushalosize", kPlusHalo); - metaInfo.insert("__lminushalosize", lMinusHalo); - metaInfo.insert("__lplushalosize", lPlusHalo); - - FieldMetainfoImpl fieldMetainfo(typeID, dims, metaInfo); - - // Field was already registered with the same meta-data - if(serializerImpl_->hasField(name) && - (serializerImpl_->getFieldMetainfoImplOf(name) == fieldMetainfo)) { - return false; - } - - serializerImpl_->registerField(name, fieldMetainfo); - - // Keep the frontend data-structure up to date - auto it = serializerImpl_->fieldMap().findField(name); - datafieldInfos_.insert({it->first, internal::make_shared_ptr(it->second)}); - - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } - return true; -} - -const DataFieldInfo& Serializer::FindField(const std::string& fieldname) const { - try { - auto it = datafieldInfos_.find(fieldname); - if(it == datafieldInfos_.end()) - throw Exception("field %s is not registered", fieldname); - return it->second; - - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::AddFieldMetainfo(const std::string& fieldname, const std::string& key, - bool value) { - try { - if(!serializerImpl_->addFieldMetainfoImpl(fieldname, key, value)) - throw Exception("metainfo with key = %s exists already in field %s", key, fieldname); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::AddFieldMetainfo(const std::string& fieldname, const std::string& key, int value) { - try { - if(!serializerImpl_->addFieldMetainfoImpl(fieldname, key, value)) - throw Exception("metainfo with key = %s exists already in field %s", key, fieldname); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::AddFieldMetainfo(const std::string& fieldname, const std::string& key, - float value) { - try { - if(!serializerImpl_->addFieldMetainfoImpl(fieldname, key, value)) - throw Exception("metainfo with key = %s exists already in field %s", key, fieldname); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::AddFieldMetainfo(const std::string& fieldname, const std::string& key, - double value) { - try { - if(!serializerImpl_->addFieldMetainfoImpl(fieldname, key, value)) - throw Exception("metainfo with key = %s exists already in field %s", key, fieldname); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::AddFieldMetainfo(const std::string& fieldname, const std::string& key, - std::string value) { - try { - if(!serializerImpl_->addFieldMetainfoImpl(fieldname, key, value)) - throw Exception("metainfo with key = %s exists already in field %s", key, fieldname); - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -std::vector Serializer::fieldnames() const { return serializerImpl_->fieldnames(); } - -std::vector Serializer::FieldsAtSavepoint(const Savepoint& savepoint) const { - std::vector fields; - - // Check if savepoint exists - int idx = serializerImpl_->savepointVector().find(*savepoint.getImpl()); - if(idx != -1) { - // Iterate fields per savepoint - const auto& fieldsPerSavepointMap = serializerImpl_->savepointVector().fieldsOf(idx); - for(auto it = fieldsPerSavepointMap.begin(), end = fieldsPerSavepointMap.end(); it != end; ++it) - fields.push_back(it->first); - } - return fields; -} - -static StorageView makeStorageView(const void* pData, TypeID type, const std::vector& dims, - std::vector strides) { - - int bytesPerElement = TypeUtil::sizeOf(type); - - // The StorageView operates on strides per type (not per byte) - for(std::size_t i = 0; i < dims.size(); ++i) - strides[i] /= bytesPerElement; - - // Check dimensions (strides.size() == 4 is guaranteed) - if(dims.size() > 4) - throw Exception("the STELLA frontend does not support %i dimensional storages", dims.size()); - - // Adjust strides s.t dims.size() == strides.size() - while(strides.size() != dims.size()) - strides.pop_back(); - - return StorageView(const_cast(pData), type, dims, std::vector(strides)); -} - -void Serializer::WriteField(const std::string& fieldName, const Savepoint& savepoint, - const void* pData, int iStride, int jStride, int kStride, int lStride) { - if(SerializerImpl::serializationStatus() < 0) - return; - - try { - std::size_t numSavepoints = serializerImpl_->savepointVector().size(); - const FieldMetainfoImpl& info = serializerImpl_->getFieldMetainfoImplOf(fieldName); - - StorageView storageView = - makeStorageView(pData, info.type(), info.dims(), {iStride, jStride, kStride, lStride}); - - serializerImpl_->write(fieldName, *savepoint.getImpl(), storageView); - - // Keep the frontend data-structure up to date - if(numSavepoints < serializerImpl_->savepointVector().size()) - savepoints_.emplace_back( - internal::make_shared_ptr(serializerImpl_->savepointVector().back())); - - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -void Serializer::ReadField(const std::string& fieldName, const Savepoint& savepoint, void* pData, - int iStride, int jStride, int kStride, int lStride, - bool alsoPrevious) const { - if(SerializerImpl::serializationStatus() < 0) - return; - - try { - const FieldMetainfoImpl& info = serializerImpl_->getFieldMetainfoImplOf(fieldName); - - StorageView storageView = - makeStorageView(pData, info.type(), info.dims(), {iStride, jStride, kStride, lStride}); - - serializerImpl_->read(fieldName, *savepoint.getImpl(), storageView, alsoPrevious); - - } catch(Exception& e) { - internal::throwSerializationException("Error: %s", e.what()); - } -} - -std::string Serializer::ToString() const { - std::ostringstream ss; - ss << serializerImpl_; - return ss.str(); -} - -} // namespace stella - -} // namespace serialbox diff --git a/src/serialbox/core/frontend/stella/Serializer.h b/src/serialbox/core/frontend/stella/Serializer.h deleted file mode 100644 index d746bb51..00000000 --- a/src/serialbox/core/frontend/stella/Serializer.h +++ /dev/null @@ -1,437 +0,0 @@ -//===-- serialbox/core/frontend/stella/Serializer.h ---------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the Serializer implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_SERIALIZER_H -#define SERIALBOX_CORE_FRONTEND_STELLA_SERIALIZER_H - -#ifdef SERIALBOX_HAS_STELLA -#include "DataFieldStorageFormat.h" -#include "DataFieldStorageStrides.h" -#endif - -#include "serialbox/core/frontend/stella/DataFieldInfo.h" -#include "serialbox/core/frontend/stella/ForwardDecl.h" -#include "serialbox/core/frontend/stella/KBoundary.h" -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include "serialbox/core/frontend/stella/Savepoint.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include -#include -#include -#include -#include - -namespace serialbox { - -namespace stella { - -/// \enum SerializerOpenMode -/// \brief OpenPolicy of the Serializer -/// -/// \ingroup STELLA -enum SerializerOpenMode { - SerializerOpenModeRead, - SerializerOpenModeWrite, - SerializerOpenModeAppend -}; - -/// \brief Implementation of the STELLA Serializer -/// -/// \ingroup STELLA -class Serializer { -public: - Serializer(); - - /// \brief Enable serialization - /// - /// Serialization is enabled by default, but it can be disabled either by setting the environment - /// variable `STELLA_SERIALIZATION_DISABLE` to a positive value or by calling the function - /// DisableSerialization. With this function you enable the serialization independently of the - /// current environment. - /// - /// The serialization can be only globally enabled or disabled. There is no way to enable or - /// disable only a specific serializer. - static void EnableSerialization(); - - /// \brief Disable serialization - /// - /// Serialization is enabled by default, but it can be disabled either by setting the environment - /// variable `STELLA_SERIALIZATION_DISABLE` to a positive value or by calling the funtcion - /// DisableSerialization. With this function you disable the serialization independently of the - /// current environment. - /// - /// The serialization can be only globally enabled or disabled. There is no way to enable or - /// disable only a specific serializer. - static void DisableSerialization(); - - /// \brief Open mode - /// - /// \return The mode is returned as value - SerializerOpenMode mode() const; - - /// \brief Directory where the data are stored - /// - /// \return The directory is returned as copy - std::string directory() const; - - /// \brief Prefix of the files - /// - /// \return The prefix is returned as copy - std::string prefix() const; - - /// \brief Initializes the serializer - /// - /// This method initializes the serializer and prepares it to perform input/output operations. - /// - /// The serializer is attached to a specific directory and to a specific prefix, with which all - /// files read and written will start. There are three modes to open a serializer: read, write and - /// append. Read will give a read-only access to the serialized data; Write will erase all files - /// of a previous run of a serializer with same directory and prefix; Append wil import all - /// existing information and allow the user to add more data. - /// - /// \param directory The directory where the files will be stored (will be created if necessary) - /// \param prefix The prefix of the files - /// \param mode The read/write/append flag that sets the access mode - void Init(const std::string& directory, const std::string& prefix, SerializerOpenMode mode); - - //===----------------------------------------------------------------------------------------===// - // Global meta-information - //===----------------------------------------------------------------------------------------===// - - /// \brief Read-only access to the metainformation - const MetainfoSet& globalMetainfo() const { return globalMetainfo_; } - - /// Adds a key-value metainformation pair to the serializer. - /// - /// @throw SerializationException The type of the value is not supported. - template - void AddMetainfo(const std::string& key, ValueType value) { - globalMetainfo_.AddMetainfo(key, value); - } - - //===----------------------------------------------------------------------------------------===// - // Register fields - //===----------------------------------------------------------------------------------------===// - - /// \brief Register a field into the serializer - /// - /// It is possible to register a field multiple times, as long as all properties of the field - /// always match. - /// - /// \param name The name of the field - /// \param type The name of the data type (e.g. "double", "float") - /// \param bytesPerElement The size in bytes of a scalar value (e.g. 8 for doubles) - /// \param iSize The size of the first dimension - /// \param jSize The size of the second dimension - /// \param kSize The size of the third dimension - /// \param lsize The size of the fourth dimension - /// \param iMinusHalo The dimension of the halo in negative i-direction - /// \param iPlusHalo The dimension of the halo in positive i-direction - /// \param jMinusHalo The dimension of the halo in negative j-direction - /// \param jPlusHalo The dimension of the halo in positive j-direction - /// \param kMinusHalo The dimension of the halo in negative k-direction - /// \param kPlusHalo The dimension of the halo in positive k-direction - /// \param lMinusHalo The dimension of the halo in negative l-direction - /// \param lPlusHalo The dimension of the halo in positive l-direction - /// - /// \return The method returns true if the field is new, false if the field was already - /// registered with matching information. - /// - /// \throw SerializationException A field with the same name but different properties is - /// registered already - bool RegisterField(const std::string& name, std::string type, int bytesPerElement, int iSize, - int jSize, int kSize, int lSize, int iMinusHalo, int iPlusHalo, int jMinusHalo, - int jPlusHalo, int kMinusHalo, int kPlusHalo, int lMinusHalo, int lPlusHalo); - - /// \brief Gives access to field info - /// - /// \throw SerializationException The field is not registered - const DataFieldInfo& FindField(const std::string& fieldname) const; - - /// \brief Adds a key-value metainformation pair to a field - /// - /// \throw SerializationException The field is not found in table or the type is not supported - /// @{ - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, bool value); - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, int value); - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, float value); - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, double value); - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, std::string value); - void AddFieldMetainfo(const std::string& fieldname, const std::string& key, const char* value) { - AddFieldMetainfo(fieldname, key, std::string(value)); - } - /// @} - - /// \brief Gives access to the registered fields - /// - /// This function fills and returns a vector with the names of the registered fields - /// - /// \return The vector with the names of the fields is returned - std::vector fieldnames() const; - - /// \brief Gives access to the list of savepoints - /// - /// \return A constant reference to the underlying savepoints vector is returned - const std::vector& savepoints() const { return savepoints_; } - - /// \brief Gives all fields which are available at the given savepoint and return their names - /// - /// If the savepoint does not exist in the serializer returns - /// an empty vector and does not throw any exceptions. - /// - /// \return A vector with the names of the available fields is returned - std::vector FieldsAtSavepoint(const Savepoint& savepoint) const; - - //===----------------------------------------------------------------------------------------===// - // Writing - //===----------------------------------------------------------------------------------------===// - - /// \brief Serializes data to file - /// - /// This method serializes the content of the given array as the field with the given name at the - /// provided savepoint. - /// - /// \param fieldName The name of the field - /// \param savepoint The savepoint at which the field will be saved - /// \param pData The pointer to the beginning of the data - /// \param iStride The offset in bytes from one point to the next in i direction - /// \param jStride The offset in bytes from one point to the next in j direction - /// \param kStride The offset in bytes from one point to the next in k direction - /// \param lStride The offset in bytes from one point to the next in l direction - /// - /// \throw SerializationException The field is not registered or it is already present at the - /// given savepoint - void WriteField(const std::string& fieldName, const Savepoint& savepoint, const void* pData, - int iStride, int jStride, int kStride, int lStride); - -#ifdef SERIALBOX_HAS_STELLA - /// \brief Serializes a data field - /// - /// This overload of the method works only with STELLA data types. This will automatically - /// register the field with the provided name and serialize the field. If the provided name is - /// empty the name of the data field will be used. - /// - /// CUDA fields will be synchronized to the host before being accessed. They are \b not - /// synchronized back to the device at the end. - /// - /// See the main WriteField method to see other cases of exception raising. - /// - /// \param name The name of the field (if empty the name of the field object is used) - /// \param field The STELLA data type contianing the information - /// \param savepoint The savepoint at which the field will be registed. - /// - /// \throw SerializationException The registration fails because of inconsistent registration of - /// fields with same name and different properties or the field is - /// already saved at the savepoint - template - void WriteField(std::string name, const TDataField& field, const Savepoint& savepoint); -#endif - - //===----------------------------------------------------------------------------------------===// - // Reading - //===----------------------------------------------------------------------------------------===// - - /// \brief Deserializes data from file - /// - /// This method reads the contents of the file corresponging to the given field name to the given - /// savepoint and places the data into the provided array, which must already be allocated. - /// - /// - /// \param fieldName The name of the field - /// \param savepoint The savepoint at which the field will be read - /// \param pData T The pointer to the beginning of the data - /// \param iStride The offset in bytes from one point to the next in i direction - /// \param jStride The offset in bytes from one point to the next in j direction - /// \param kStride The offset in bytes from one point to the next in k direction - /// \param lStride The offset in bytes from one point to the next in l direction - /// \param alsoPrevious Whether to search in previous savepoints with the same name until a - /// valid entry is found [IGNORED] - /// - /// \throw SerializationException The field is not registered in the serializer or it is not saved - /// at the savepoint - void ReadField(const std::string& fieldName, const Savepoint& savepoint, void* pData, int iStride, - int jStride, int kStride, int lStride, bool alsoPrevious = false) const; - -#ifdef SERIALBOX_HAS_STELLA - /// \brief Deserializes a data field - /// - /// This overload of the method works only with STELLA data types. If the provided name is empty - /// the name of the data field will be used. The field must be initialized already with the - /// correct size and boundaries. If these do not match with the serialized field a - /// SerializationException is raised. - /// - /// CUDA fields will be synchronized to the host before being accessed. They are \b not - /// synchronized back to the device at the end. - /// - /// See the main ReadField method to see cases of exception raising. - /// - /// \param name The name of the field (if empty the name of the field object is used) - /// \param field The STELLA data type where the data will be loaded - /// \param savepoint The savepoint at which the field will be registed. - /// \param alsoPrevious Whether to search in previous savepoints with the same name until a - /// valid entry is found [IGNORED] - template - void ReadField(std::string name, TDataField& field, const Savepoint& savepoint, - bool alsoPrevious = false) const; -#endif - - /// \brief Convert to string - std::string ToString() const; - - /// \brief Get implementation pointer - boost::shared_ptr& getImpl() { return serializerImpl_; } - const boost::shared_ptr& getImpl() const { return serializerImpl_; } - -private: - // Implementation pointer - boost::shared_ptr serializerImpl_; - - // These data-strucures allow to return refrences but do not actually own any data but they need - // to be kept in sync with the data from serializerImpl! - MetainfoSet globalMetainfo_; - std::vector savepoints_; - std::map datafieldInfos_; - - // This variable can take three values: - // - // 0: the variable is not yet initialized -> the serialization is enabled if the environment - // variable STELLA_SERIALIZATION_DISABLE is not set to a positive value. The first - // serializer which is initialized has to set this value either to +1 or to -1 according to - // the environment. - // +1: the serialization is enabled, independently of the environment - // -1: the serialization is disabled, independently of the environment - // - // The value is initialized to 0 - static int enabled_; -}; - -//===------------------------------------------------------------------------------------------===// -// Implementation of template methods -//===------------------------------------------------------------------------------------------===// - -#ifdef SERIALBOX_HAS_STELLA -template -void Serializer::WriteField(std::string name, const TDataField& field, const Savepoint& savepoint) { - - if(name.empty()) - name = field.name(); - - // Retrieve size, boundaries and strides - IJKSize size; - size.Init(field.storage().allocatedSize().iSize(), field.storage().allocatedSize().jSize(), - field.storage().allocatedSize().kSize()); - - IJKBoundary boundary; - boundary.Init(field.boundary().iMinusOffset(), field.boundary().iPlusOffset(), - field.boundary().jMinusOffset(), field.boundary().jPlusOffset(), - field.boundary().kMinusOffset(), field.boundary().kPlusOffset()); - - const int bytesPerElement = sizeof(typename TDataField::ValueType); - - DataFieldStorageStrides strides; - strides.Init(field.storage().paddedSize()); - const int iStride = strides.ComputeStride(1, 0, 0) * bytesPerElement; - const int jStride = strides.ComputeStride(0, 1, 0) * bytesPerElement; - const int kStride = strides.ComputeStride(0, 0, 1) * bytesPerElement; - - // Register field - this->RegisterField(name, type_name(), bytesPerElement, - size.iSize(), size.jSize(), size.kSize(), 1, -boundary.iMinusOffset(), - boundary.iPlusOffset(), -boundary.jMinusOffset(), boundary.jPlusOffset(), - -boundary.kMinusOffset(), boundary.kPlusOffset(), 0, 0); - - this->WriteField(name, savepoint, field.storage().pStorageBase(), iStride, jStride, kStride, 0); -} - -template -void Serializer::ReadField(std::string name, TDataField& field, const Savepoint& savepoint, - bool alsoPrevious) const { - typedef typename TDataField::ValueType ValueType; - - if(name.empty()) - name = field.name(); - - // Get info of serialized field - const DataFieldInfo& info = FindField(name); - const int bytesPerElement = sizeof(typename TDataField::ValueType); - - // Get strides according to STELLA - DataFieldStorageStrides stridesSTELLA; - stridesSTELLA.Init(field.storage().paddedSize()); - - // Get rid of degenerated dimensions and fix strides - std::vector allSizes, size, allStrides, strides; - allSizes.push_back(field.storage().allocatedSize().iSize()); - allSizes.push_back(field.storage().allocatedSize().jSize()); - allSizes.push_back(field.storage().allocatedSize().kSize()); - allSizes.push_back(0); - allStrides.push_back(stridesSTELLA.ComputeStride(1, 0, 0) * bytesPerElement); - allStrides.push_back(stridesSTELLA.ComputeStride(0, 1, 0) * bytesPerElement); - allStrides.push_back(stridesSTELLA.ComputeStride(0, 0, 1) * bytesPerElement); - for(int i = 0; i < 4; ++i) { - if(allSizes[i] > 1) { - size.push_back(allSizes[i]); - strides.push_back(allStrides[i]); - } - } - size.resize(4, 0); - - IJKBoundary boundary; - boundary.Init(field.boundary().iMinusOffset(), field.boundary().iPlusOffset(), - field.boundary().jMinusOffset(), field.boundary().jPlusOffset(), - field.boundary().kMinusOffset(), field.boundary().kPlusOffset()); - - if((info.iSize() != size[0]) || (info.jSize() != size[1]) || (info.kSize() != size[2]) || - (info.lSize() != 0)) { - // Throw exception - std::ostringstream errorstr; - errorstr << "Error: the requested field " << name << " has a different size than" - << " the provided data field.\n"; - errorstr << "Registerd as: " << info.iSize() << "x" << info.jSize() << "x" << info.kSize() - << "x" << info.lSize() << "\n"; - errorstr << "Given : " << size[0] << "x" << size[1] << "x" << size[2] << "x" << size[3] - << "x0" - << "\n"; - SerializationException exception; - exception.Init(errorstr.str()); - throw exception; - } - - // Check data type - if(info.type() != type_name()) { - // Throw exception - std::ostringstream errorstr; - errorstr << "Error: the requested field " << name << " has different type than" - << " the provided data field (expected " << info.type() << ", got " - << type_name() << ")"; - SerializationException exception; - exception.Init(errorstr.str()); - throw exception; - } - - // This hack is used to retrieve the storage pointer for the host memory in case of GPU fields - // This will synchronize the host storage - ValueType* data = - &field(boundary.iMinusOffset(), boundary.jMinusOffset(), boundary.kMinusOffset()); - - // Perform the read - this->ReadField(name, savepoint, data, strides[0], strides[1], strides[2], 0, alsoPrevious); -} -#endif - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/TypeName.h b/src/serialbox/core/frontend/stella/TypeName.h deleted file mode 100644 index fac42e42..00000000 --- a/src/serialbox/core/frontend/stella/TypeName.h +++ /dev/null @@ -1,41 +0,0 @@ -//===-- serialbox/core/frontend/stella/TypeName.h -----------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the type_name class which maps types to strings. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_TYPENAME_H -#define SERIALBOX_CORE_FRONTEND_STELLA_TYPENAME_H - -namespace serialbox { - -namespace stella { - -#include - -template -inline std::string type_name(); - -#define SERIALBOX_TYPENAMEFUNCTION(type) \ - template <> \ - inline std::string type_name() { \ - return #type; \ - } - -SERIALBOX_TYPENAMEFUNCTION(int) -SERIALBOX_TYPENAMEFUNCTION(float) -SERIALBOX_TYPENAMEFUNCTION(double) - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/core/frontend/stella/Utility.h b/src/serialbox/core/frontend/stella/Utility.h deleted file mode 100644 index 135e4edd..00000000 --- a/src/serialbox/core/frontend/stella/Utility.h +++ /dev/null @@ -1,93 +0,0 @@ -//===-- serialbox/core/frontend/stella/Utility.h ------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains some utilities internally used by the STELLA frontend. -/// -/// This file contains C++11 and should therefore not be included in exposed headers. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_CORE_FRONTEND_STELLA_UTILITY_H -#define SERIALBOX_CORE_FRONTEND_STELLA_UTILITY_H - -#include "serialbox/core/Compiler.h" -#include "serialbox/core/Exception.h" -#include "serialbox/core/Type.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include -#include -#include -#include -#include - -namespace serialbox { - -namespace stella { - -namespace internal { - -/// \brief Throw SerializationException constructed with printf-style arguments -template -SERIALBOX_ATTRIBUTE_NORETURN void throwSerializationException(const char* fmt, Args&&... args) { - boost::format f(fmt); - - int unroll[]{0, (f % std::forward(args), 0)...}; - static_cast(unroll); - - SerializationException exception; - exception.Init(boost::str(f)); - throw exception; -} - -template -inline TypeID TypeNameToTypeID(StringType&& name) { - if(name == "bool") - return TypeID::Boolean; - else if(name == "int") - return TypeID::Int32; - else if(name == "float") - return TypeID::Float32; - else if(name == "double") - return TypeID::Float64; - throw Exception("unsupported type: %s", name); -} - -inline std::string TypeIDToTypeName(TypeID typeID) { - switch(typeID) { - case TypeID::Boolean: - return "bool"; - case TypeID::Int32: - return "int"; - case TypeID::Float32: - return "float"; - case TypeID::Float64: - return "double"; - default: - throw Exception("unsupported type: %s", TypeUtil::toString(typeID)); - } -} - -template -boost::shared_ptr make_shared_ptr(std::shared_ptr& ptr) { - return boost::shared_ptr(ptr.get(), [ptr](T*) mutable { ptr.reset(); }); -} - -template -std::shared_ptr make_shared_ptr(boost::shared_ptr& ptr) { - return std::shared_ptr(ptr.get(), [ptr](T*) mutable { ptr.reset(); }); -} - -} // namespace internal - -} // namespace stella - -} // namespace serialbox - -#endif diff --git a/src/serialbox/stella/Serialbox.h b/src/serialbox/stella/Serialbox.h deleted file mode 100644 index 811c4414..00000000 --- a/src/serialbox/stella/Serialbox.h +++ /dev/null @@ -1,35 +0,0 @@ -//===-- serialbox/stella/Serialbox.h ------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file includes the STELLA frontend of serialbox. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_STELLA_SERIALBOX_H -#define SERIALBOX_STELLA_SERIALBOX_H - -/// \defgroup STELLA STELLA -/// \brief STELLA frontend of Serialbox -/// -/// \ingroup frontend - -#include "serialbox/core/Config.h" - -#include "serialbox/core/frontend/stella/DataFieldInfo.h" -#include "serialbox/core/frontend/stella/IJKBoundary.h" -#include "serialbox/core/frontend/stella/IJKSize.h" -#include "serialbox/core/frontend/stella/KBoundary.h" -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include "serialbox/core/frontend/stella/Savepoint.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include "serialbox/core/frontend/stella/Serializer.h" -#include "serialbox/core/frontend/stella/TypeName.h" - -#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6112db30..2d28e655 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,10 +54,6 @@ function(serialbox_add_unittest_executable) add_dependencies(${ARG_NAME} serialbox-old) endif() - if(DEFINED BUILD_STELLA) - add_dependencies(${ARG_NAME} stella) - endif() - if(SERIALBOX_HAS_GRIDTOOLS) target_link_libraries(${ARG_NAME} GridTools::gridtools) endif() diff --git a/test/benchmark/CMakeLists.txt b/test/benchmark/CMakeLists.txt index b76175b1..7d850f16 100644 --- a/test/benchmark/CMakeLists.txt +++ b/test/benchmark/CMakeLists.txt @@ -17,12 +17,10 @@ set(SOURCES # Setup external libraries set(EXTERNAL_LIBRARIES ${Boost_LIBRARIES} ${GTEST_LIBRARIES} - ${SERIALBOX_OLD_LIBRARIES} - ${STELLA_LIBRARIES}) + ${SERIALBOX_OLD_LIBRARIES}) serialbox_add_unittest_executable(NAME SerialboxBenchmarkUnittest LIBRARIES ${EXTERNAL_LIBRARIES} SOURCES ${SOURCES} BenchmarkMain.cpp DEPENDS SerialboxCStatic SerialboxStatic ) - diff --git a/test/serialbox/core/CMakeLists.txt b/test/serialbox/core/CMakeLists.txt index 9dd70a3f..f9e61afd 100644 --- a/test/serialbox/core/CMakeLists.txt +++ b/test/serialbox/core/CMakeLists.txt @@ -40,19 +40,9 @@ set(SOURCES frontend/gridtools/UnittestFieldMetaInfo.cpp frontend/gridtools/UnittestSavepoint.cpp frontend/gridtools/UnittestSerializer.cpp - - # frontend/stella/ - frontend/stella/UnittestStorageView.cpp - frontend/stella/UnittestMetainfoSet.cpp - frontend/stella/UnittestException.cpp - frontend/stella/UnittestSavepoint.cpp - frontend/stella/UnittestSerializer.cpp - frontend/stella/UnittestDataFieldInfo.cpp - frontend/stella/UnittestUtility.cpp ) serialbox_add_unittest_executable(NAME SerialboxCppUnittest SOURCES ${SOURCES} UnittestMain.cpp LIBRARIES SerialboxStatic ) - diff --git a/test/serialbox/core/frontend/stella/UnittestDataFieldInfo.cpp b/test/serialbox/core/frontend/stella/UnittestDataFieldInfo.cpp deleted file mode 100644 index 158dbc14..00000000 --- a/test/serialbox/core/frontend/stella/UnittestDataFieldInfo.cpp +++ /dev/null @@ -1,92 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestDataFieldInfo.cpp --------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the DataFieldInfo of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/DataFieldInfo.h" -#include -#include - -TEST(STELLADataFieldInfoTest, InitConstruction) { - // - // Default construct - // - ser::DataFieldInfo info; - - info.Init("field1", "int", 4, 2, 42, 1, 1, 12, 1, 1, 0, 0, 0, 0, 2, 2); - - // - // Check infomration was set correct - // - EXPECT_EQ(std::string("field1"), info.name()); - EXPECT_EQ(std::string("int"), info.type()); - EXPECT_EQ(4, info.bytesPerElement()); - EXPECT_EQ(2, info.rank()); - EXPECT_EQ(42, info.iSize()); - EXPECT_EQ(1, info.jSize()); - EXPECT_EQ(1, info.kSize()); - EXPECT_EQ(12, info.lSize()); - EXPECT_EQ(1, info.iMinusHaloSize()); - EXPECT_EQ(0, info.jMinusHaloSize()); - EXPECT_EQ(0, info.kMinusHaloSize()); - EXPECT_EQ(2, info.lMinusHaloSize()); - EXPECT_EQ(1, info.iPlusHaloSize()); - EXPECT_EQ(0, info.jPlusHaloSize()); - EXPECT_EQ(0, info.kPlusHaloSize()); - EXPECT_EQ(2, info.lPlusHaloSize()); -} - -#include "utility/STELLA.h" -#ifdef SERIALBOX_HAS_STELLA - -TEST(STELLADataFieldInfoTest, STELLAConstruction) { - // - // Default construct - // - ser::DataFieldInfo info1; - - // - // Initialize with STELLA field - // - IJKSize domain; - domain.Init(1, 2, 3); - - KBoundary kboundary; - kboundary.Init(1, 1); - - IJKRealField field; - field.Init("info", domain, kboundary); - - info1.Init(field); - - // - // Add meta-info - // - info1.AddMetainfo("key1", "str"); - info1.AddMetainfo("key2", double(5)); - - // - // Copy constructor - // - ser::DataFieldInfo info2 = info1; - ASSERT_TRUE(info1 == info2); - - EXPECT_EQ(info2.metainfo().AsString("key1"), "str"); - EXPECT_EQ(info2.metainfo().AsDouble("key2"), double(5)); - - // - // ToString - // - EXPECT_TRUE(boost::algorithm::starts_with(info1.ToString(), "info (7x8x3x1)")); -} - -#endif diff --git a/test/serialbox/core/frontend/stella/UnittestException.cpp b/test/serialbox/core/frontend/stella/UnittestException.cpp deleted file mode 100644 index 00b6a49b..00000000 --- a/test/serialbox/core/frontend/stella/UnittestException.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestException.cpp ------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the SerializationException of the STELLA Frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/SerializationException.h" -#include "serialbox/core/frontend/stella/Utility.h" -#include - -using namespace serialbox; - -TEST(STELLAExceptionTest, Throw) { - auto throwAnExcpetion = [](bool doIt) -> void { - if(doIt) { - ser::SerializationException exception; - exception.Init("you asked for it!"); - throw exception; - } - }; - - EXPECT_THROW(throwAnExcpetion(true), stella::SerializationException); - EXPECT_NO_THROW(throwAnExcpetion(false)); - - try { - ser::internal::throwSerializationException("the %s should be %i", "answer", 42); - } catch(ser::SerializationException& e) { - EXPECT_STREQ(e.what(), "the answer should be 42"); - EXPECT_EQ(e.message(), "the answer should be 42"); - } -} diff --git a/test/serialbox/core/frontend/stella/UnittestMetainfoSet.cpp b/test/serialbox/core/frontend/stella/UnittestMetainfoSet.cpp deleted file mode 100644 index 401237c2..00000000 --- a/test/serialbox/core/frontend/stella/UnittestMetainfoSet.cpp +++ /dev/null @@ -1,160 +0,0 @@ -//===--serialbox/core/frontend/stella/UnittestserMetainfoSet.cpp --------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the MetainfoSet of the ser Frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/MetainfoSet.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include "serialbox/core/MetainfoMapImpl.h" -#include -#include -#include - -using namespace serialbox; - -TEST(STELLAMetainfoSetTest, Construction) { - ser::MetainfoSet set; - EXPECT_EQ(set.size(), 0); - - // - // Add some information - // - - // bool - ASSERT_NO_THROW(set.AddMetainfo("bool", bool(true))); - EXPECT_TRUE(set.HasKey("bool")); - ASSERT_THROW(set.AddMetainfo("bool", bool(true)), ser::SerializationException); - - // int - ASSERT_NO_THROW(set.AddMetainfo("int32", int(32))); - EXPECT_TRUE(set.HasKey("int32")); - ASSERT_THROW(set.AddMetainfo("int32", int(32)), ser::SerializationException); - - // float - ASSERT_NO_THROW(set.AddMetainfo("float32", float(32.0f))); - EXPECT_TRUE(set.HasKey("float32")); - ASSERT_THROW(set.AddMetainfo("float32", float(32.0f)), ser::SerializationException); - ASSERT_NO_THROW(set.AddMetainfo("float32_1", float(32.1f))); - - // double - ASSERT_NO_THROW(set.AddMetainfo("float64", double(64.0f))); - EXPECT_TRUE(set.HasKey("float64")); - ASSERT_THROW(set.AddMetainfo("float64", double(64.0f)), ser::SerializationException); - ASSERT_NO_THROW(set.AddMetainfo("float64_1", double(64.1))); - - // string - ASSERT_NO_THROW(set.AddMetainfo("string", std::string("str"))); - EXPECT_TRUE(set.HasKey("string")); - ASSERT_THROW(set.AddMetainfo("string", std::string("str")), ser::SerializationException); - - ASSERT_EQ(set.size(), 7); - - auto keys = set.keys(); - ASSERT_EQ(keys.size(), set.size()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "bool") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "int32") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "float32") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "float32_1") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "float64") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "float64_1") != keys.end()); - EXPECT_TRUE(std::find(keys.begin(), keys.end(), "string") != keys.end()); - - // Query non-existent key - ASSERT_FALSE(set.HasKey("XXX")); - - ASSERT_EQ(boost::any_cast(set.AsAny("float32")), - boost::any_cast(boost::any(float(32.0f)))); - - // - // Query as Boolean - // - EXPECT_EQ(set.AsBool("bool"), true); - EXPECT_EQ(set.AsBool("int32"), true); - EXPECT_EQ(set.AsBool("float32"), true); - EXPECT_EQ(set.AsBool("float64"), true); - EXPECT_EQ(set.AsBool("string"), false); - ASSERT_THROW(set.AsBool("XXX"), ser::SerializationException); - - // - // Query as Integer - // - EXPECT_EQ(set.AsInt("bool"), 1); - EXPECT_EQ(set.AsInt("int32"), 32); - EXPECT_EQ(set.AsInt("float32"), 32); - ASSERT_THROW(set.AsInt("float32_1"), ser::SerializationException); - EXPECT_EQ(set.AsInt("float64"), 64); - ASSERT_THROW(set.AsInt("float64_1"), ser::SerializationException); - EXPECT_EQ(set.AsInt("string"), 0); - ASSERT_THROW(set.AsInt("XXX"), ser::SerializationException); - - // - // Query as Float - // - EXPECT_EQ(set.AsFloat("bool"), 1); - EXPECT_EQ(set.AsFloat("int32"), 32); - EXPECT_EQ(set.AsFloat("float32"), 32.0f); - EXPECT_EQ(set.AsFloat("float64"), 64.0f); - EXPECT_EQ(set.AsFloat("string"), 0); - ASSERT_THROW(set.AsFloat("XXX"), ser::SerializationException); - - // - // Query as Double - // - EXPECT_EQ(set.AsDouble("bool"), 1); - EXPECT_EQ(set.AsDouble("int32"), 32); - EXPECT_EQ(set.AsDouble("float32"), 32.0); - EXPECT_EQ(set.AsDouble("float64"), 64.0); - EXPECT_EQ(set.AsDouble("string"), 0); - ASSERT_THROW(set.AsDouble("XXX"), ser::SerializationException); - - // - // Query as String - // - EXPECT_EQ(set.AsString("bool"), "true"); - EXPECT_EQ(set.AsString("int32"), "32"); - EXPECT_EQ(set.AsString("float32"), "32.000000"); - EXPECT_EQ(set.AsString("float64"), "64.000000"); - EXPECT_EQ(set.AsString("string"), "str"); - ASSERT_THROW(set.AsString("XXX"), ser::SerializationException); - - // - // ToString - // - std::string str = set.ToString(); - EXPECT_NE(str.find("bool"), std::string::npos); - EXPECT_NE(str.find("int32"), std::string::npos); - EXPECT_NE(str.find("float32"), std::string::npos); - EXPECT_NE(str.find("float32_1"), std::string::npos); - EXPECT_NE(str.find("float64"), std::string::npos); - EXPECT_NE(str.find("float64_1"), std::string::npos); - EXPECT_NE(str.find("string"), std::string::npos); - - // - // Assignment - // - boost::shared_ptr map2 = boost::make_shared(); - ser::MetainfoSet set2(map2); - set2 = set; - ASSERT_EQ(set2.size(), 7); - ASSERT_EQ(map2->size(), 7); - - // - // Comparison - // - ASSERT_TRUE(set2 == set); - - // - // Clear - // - set.Cleanup(); - ASSERT_EQ(set.size(), 0); -} diff --git a/test/serialbox/core/frontend/stella/UnittestSavepoint.cpp b/test/serialbox/core/frontend/stella/UnittestSavepoint.cpp deleted file mode 100644 index 6e573cb2..00000000 --- a/test/serialbox/core/frontend/stella/UnittestSavepoint.cpp +++ /dev/null @@ -1,70 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestSavepoint.cpp ------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the Savepoint implementation of the ser frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/Savepoint.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include "serialbox/core/SavepointImpl.h" -#include -#include -#include -#include - -using namespace serialbox; - -TEST(STELLASavepointTest, Construction) { - // Construction - ser::Savepoint savepoint1; - savepoint1.Init("savepoint"); - - // Add meta-information - EXPECT_NO_THROW(savepoint1.AddMetainfo("bool", bool())); - EXPECT_NO_THROW(savepoint1.AddMetainfo("int", int())); - EXPECT_NO_THROW(savepoint1.AddMetainfo("float", float())); - EXPECT_NO_THROW(savepoint1.AddMetainfo("double", double())); - EXPECT_NO_THROW(savepoint1.AddMetainfo("std::string", std::string(""))); - ASSERT_EQ(savepoint1.metainfo().size(), 5); - - EXPECT_NO_THROW(savepoint1.AddMetainfo("key1", "str")); - EXPECT_NO_THROW(savepoint1.AddMetainfo("key2", double(5))); - - EXPECT_THROW(savepoint1.AddMetainfo("key2", double(5)), ser::SerializationException); - - // Query meta-information - EXPECT_EQ(savepoint1.name(), "savepoint"); - EXPECT_EQ(savepoint1.metainfo().AsString("key1"), "str"); - EXPECT_EQ(savepoint1.metainfo().AsDouble("key2"), double(5)); - - // Comparison - boost::shared_ptr savepointImpl2 = boost::make_shared("savepoint2"); - ser::Savepoint savepoint2(savepointImpl2); - EXPECT_EQ(savepoint2.name(), "savepoint2"); - - EXPECT_TRUE(savepoint1 == savepoint1); - EXPECT_TRUE(savepoint1 != savepoint2); - - // Assignment - savepoint2 = savepoint1; - EXPECT_TRUE(savepoint2 == savepoint1); - - // Copy constructor - ser::Savepoint savepoint3(savepoint1); - EXPECT_TRUE(savepoint3 == savepoint1); - - // ToString - EXPECT_TRUE(boost::algorithm::starts_with(savepoint1.ToString(), "savepoint")); - - std::stringstream ss; - ss << savepoint1; - EXPECT_EQ(ss.str(), savepoint1.ToString()); -} diff --git a/test/serialbox/core/frontend/stella/UnittestSerializer.cpp b/test/serialbox/core/frontend/stella/UnittestSerializer.cpp deleted file mode 100644 index 3bef40aa..00000000 --- a/test/serialbox/core/frontend/stella/UnittestSerializer.cpp +++ /dev/null @@ -1,555 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestSerializer.cpp -----------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the Serializer implementation of the STELLA frontend. -/// -//===------------------------------------------------------------------------------------------===// - -#include "utility/STELLA.h" -#include "utility/SerializerTestBase.h" -#include "utility/Storage.h" -#include "serialbox/core/frontend/stella/SerializationException.h" -#include "serialbox/core/frontend/stella/Serializer.h" -#include "serialbox/core/SerializerImpl.h" -#include - -using namespace serialbox; -using namespace unittest; - -//===------------------------------------------------------------------------------------------===// -// Utility tests -//===------------------------------------------------------------------------------------------===// - -namespace { - -class STELLASerializerUtilityTest : public SerializerUnittestBase {}; - -} // anonymous namespace - -TEST_F(STELLASerializerUtilityTest, ConstructionOfEmptySerializer) { - // SerializerOpenModeWrite - { - ser::Serializer s; - ASSERT_NO_THROW(s.Init(directory->path().string(), "Field", ser::SerializerOpenModeWrite)); - EXPECT_EQ(s.directory(), directory->path().string()); - EXPECT_EQ(s.prefix(), "Field"); - EXPECT_EQ(s.mode(), ser::SerializerOpenModeWrite); - } - - // SerializerOpenModeAppend - { - ser::Serializer s; - ASSERT_NO_THROW(s.Init(directory->path().string(), "Field", ser::SerializerOpenModeAppend)); - EXPECT_EQ(s.mode(), ser::SerializerOpenModeAppend); - } - - // SerializerOpenModeRead - - // No meta-data found -> Exception - { - ser::Serializer s; - ASSERT_THROW(s.Init(directory->path().string(), "Field", ser::SerializerOpenModeRead), - ser::SerializationException); - } -} - -TEST_F(STELLASerializerUtilityTest, AddMetainfo) { - ser::Serializer s; - s.Init(directory->path().string(), "Field", ser::SerializerOpenModeWrite); - - // Add some meta-info - s.AddMetainfo("bool", bool(true)); - s.AddMetainfo("int32", int(32)); - s.AddMetainfo("float32", float(32.0f)); - s.AddMetainfo("float64", double(64.0f)); - s.AddMetainfo("string", "str"); // This has to go through the const char* specialization - - // Query meta-info - EXPECT_EQ(s.globalMetainfo().AsBool("bool"), bool(true)); - EXPECT_EQ(s.globalMetainfo().AsInt("int32"), int(32)); - EXPECT_EQ(s.globalMetainfo().AsFloat("float32"), float(32.0f)); - EXPECT_EQ(s.globalMetainfo().AsDouble("float64"), double(64.0f)); - EXPECT_EQ(s.globalMetainfo().AsString("string"), "str"); - - // Check if information has been correctly passed to the SerializerImpl - SerializerImpl& serializer = *s.getImpl(); - EXPECT_EQ(serializer.getGlobalMetainfoAs("int32"), int(32)); - EXPECT_EQ(serializer.getGlobalMetainfoAs("float32"), float(32.0f)); - EXPECT_EQ(serializer.getGlobalMetainfoAs("float64"), double(64.0f)); - EXPECT_EQ(serializer.getGlobalMetainfoAs("string"), "str"); -} - -TEST_F(STELLASerializerUtilityTest, RegisterField) { - ser::Serializer ser; - ser.Init(directory->path().string(), "Field", ser::SerializerOpenModeWrite); - - // Register some fields - ser.RegisterField("field1", "int", 4, 42, 1, 1, 12, 1, 1, 0, 0, 0, 0, 2, 2); - ser.RegisterField("field2", "double", 8, 42, 28, 80, 1, 3, 3, 3, 3, 0, 1, 0, 0); - - // Register already existing field (same meta-data) -> Returns false - ASSERT_FALSE(ser.RegisterField("field1", "int", 4, 42, 1, 1, 12, 1, 1, 0, 0, 0, 0, 2, 2)); - - // Register already existing field (different meta-data) -> Exception - ASSERT_THROW(ser.RegisterField("field1", "int", 4, 42, 1, 1, 12, 100, 1, 0, 0, 0, 0, 2, 2), - ser::SerializationException); - - // Register with inconsistent bytes-per-element -> Exception - ASSERT_THROW(ser.RegisterField("field1", "int", 8, 42, 1, 1, 12, 1, 1, 0, 0, 0, 0, 2, 2), - ser::SerializationException); - - // Query fields - const ser::DataFieldInfo& field1 = ser.FindField("field1"); - EXPECT_EQ(std::string("field1"), field1.name()); - EXPECT_EQ(std::string("int"), field1.type()); - EXPECT_EQ(4, field1.bytesPerElement()); - EXPECT_EQ(2, field1.rank()); - EXPECT_EQ(42, field1.iSize()); - EXPECT_EQ(1, field1.jSize()); - EXPECT_EQ(1, field1.kSize()); - EXPECT_EQ(12, field1.lSize()); - EXPECT_EQ(1, field1.iMinusHaloSize()); - EXPECT_EQ(0, field1.jMinusHaloSize()); - EXPECT_EQ(0, field1.kMinusHaloSize()); - EXPECT_EQ(2, field1.lMinusHaloSize()); - EXPECT_EQ(1, field1.iPlusHaloSize()); - EXPECT_EQ(0, field1.jPlusHaloSize()); - EXPECT_EQ(0, field1.kPlusHaloSize()); - EXPECT_EQ(2, field1.lPlusHaloSize()); - - const ser::DataFieldInfo& field2 = ser.FindField("field2"); - EXPECT_EQ(std::string("field2"), field2.name()); - EXPECT_EQ(std::string("double"), field2.type()); - EXPECT_EQ(8, field2.bytesPerElement()); - EXPECT_EQ(3, field2.rank()); - EXPECT_EQ(42, field2.iSize()); - EXPECT_EQ(28, field2.jSize()); - EXPECT_EQ(80, field2.kSize()); - EXPECT_EQ(1, field2.lSize()); - EXPECT_EQ(3, field2.iMinusHaloSize()); - EXPECT_EQ(3, field2.jMinusHaloSize()); - EXPECT_EQ(0, field2.kMinusHaloSize()); - EXPECT_EQ(0, field2.lMinusHaloSize()); - EXPECT_EQ(3, field2.iPlusHaloSize()); - EXPECT_EQ(3, field2.jPlusHaloSize()); - EXPECT_EQ(1, field2.kPlusHaloSize()); - EXPECT_EQ(0, field2.lPlusHaloSize()); - - // Field does not exists -> Exception - ASSERT_THROW(ser.FindField("field3"), ser::SerializationException); -} - -TEST_F(STELLASerializerUtilityTest, FieldMetainfoImpl) { - ser::Serializer ser; - ser.Init(directory->path().string(), "Field", ser::SerializerOpenModeWrite); - - ser.RegisterField("field1", "int", 4, 42, 1, 1, 12, 1, 1, 0, 0, 0, 0, 2, 2); - ser.RegisterField("field2", "double", 8, 42, 28, 80, 1, 3, 3, 3, 3, 0, 1, 0, 0); - - // Add some metainfo (second invocation should always throw) - ser.AddFieldMetainfo("field1", "FirstField", true); - ASSERT_THROW(ser.AddFieldMetainfo("field1", "FirstField", true), ser::SerializationException); - - ser.AddFieldMetainfo("field1", "InitValue", 10.75); - ASSERT_THROW(ser.AddFieldMetainfo("field1", "InitValue", 10.75), ser::SerializationException); - - ser.AddFieldMetainfo("field1", "InitValue2", 0.75f); - ASSERT_THROW(ser.AddFieldMetainfo("field1", "InitValue2", 0.75f), ser::SerializationException); - - ser.AddFieldMetainfo("field1", "Elements", 42 * 80); - ASSERT_THROW(ser.AddFieldMetainfo("field1", "Elements", 42 * 80), ser::SerializationException); - - ser.AddFieldMetainfo("field2", "FirstField", false); - ASSERT_THROW(ser.AddFieldMetainfo("field2", "FirstField", false), ser::SerializationException); - - ser.AddFieldMetainfo("field2", "AlternateName", "density"); - ASSERT_THROW(ser.AddFieldMetainfo("field2", "AlternateName", "density"), - ser::SerializationException); - - // Read metainfo - ASSERT_EQ(4, ser.FindField("field1").metainfo().size()); - ASSERT_EQ(2, ser.FindField("field2").metainfo().size()); - - ASSERT_EQ(true, ser.FindField("field1").metainfo().AsBool("FirstField")); - ASSERT_EQ(10.75, ser.FindField("field1").metainfo().AsDouble("InitValue")); - ASSERT_EQ(0.75f, ser.FindField("field1").metainfo().AsFloat("InitValue2")); - ASSERT_EQ(42 * 80, ser.FindField("field1").metainfo().AsInt("Elements")); - ASSERT_EQ(false, ser.FindField("field2").metainfo().AsBool("FirstField")); - ASSERT_EQ(std::string("density"), ser.FindField("field2").metainfo().AsString("AlternateName")); -} - -//===------------------------------------------------------------------------------------------===// -// STELLA Read/Write tests -//===------------------------------------------------------------------------------------------===// - -#ifdef SERIALBOX_HAS_STELLA - -namespace { - -template -class STELLASerializerReadWriteTest : public SerializerUnittestBase {}; - -using TestTypes = testing::Types; - -} // anonymous namespace - -TYPED_TEST_CASE(STELLASerializerReadWriteTest, TestTypes); - -/// Call ser::Serializer::WriteField with dataField -template -static void writeField(SerializerType& serializer, StringType&& name, FieldType& dataField, - const ser::Savepoint& savepoint) { - - DataFieldStorageStrides storageStrides; - storageStrides.Init(dataField.storage().paddedSize()); - - const int bytesPerElement = sizeof(typename FieldType::ValueType); - - int iStride = storageStrides.ComputeStride(1, 0, 0) * bytesPerElement; - int jStride = storageStrides.ComputeStride(0, 1, 0) * bytesPerElement; - int kStride = storageStrides.ComputeStride(0, 0, 1) * bytesPerElement; - - serializer.WriteField(name, dataField, savepoint, iStride, jStride, kStride); -} - -/// Call ser::Serializer::ReadField with dataField -template -static void readField(SerializerType& serializer, StringType&& name, FieldType& dataField, - const ser::Savepoint& savepoint) { - - DataFieldStorageStrides storageStrides; - storageStrides.Init(dataField.storage().paddedSize()); - - const int bytesPerElement = sizeof(typename FieldType::ValueType); - - int iStride = storageStrides.ComputeStride(1, 0, 0) * bytesPerElement; - int jStride = storageStrides.ComputeStride(0, 1, 0) * bytesPerElement; - int kStride = storageStrides.ComputeStride(0, 0, 1) * bytesPerElement; - - serializer.ReadField(name, dataField, savepoint, true, true, iStride, jStride, kStride, false); -} - -/// Verify data fields are bit-wise identical -template -static testing::AssertionResult verifyFields(FieldType&& field, RefFieldType&& refField) { - const IJKSize& calculationDomain = field.calculationDomain(); - const IJKBoundary& boundary = field.boundary(); - - const int Ni = calculationDomain.iSize(); - const int Nj = calculationDomain.jSize(); - const int Nk = calculationDomain.kSize(); - - for(int i = boundary.iMinusOffset(); i < (Ni + boundary.iPlusOffset()); ++i) - for(int j = boundary.jMinusOffset(); j < (Nj + boundary.jPlusOffset()); ++j) - for(int k = boundary.kMinusOffset(); k < (Nk + +boundary.kPlusOffset()); ++k) - if(field(i, j, k) != refField(i, j, k)) { - std::stringstream ss; - ss << "\nStorage mismatch:\n"; - ss << " storage at (" << i << ", " << j << ", " << k << ") = " << field(i, j, k) << "\n"; - ss << " refrence at (" << i << ", " << j << ", " << k << ") = " << refField(i, j, k) - << "\n"; - return testing::AssertionFailure() << ss.str().c_str(); - } - return testing::AssertionSuccess(); -} - -TYPED_TEST(STELLASerializerReadWriteTest, WriteAndRead) { - // Sizes (including halos) - int iSize = 12; - int jSize = 18; - int kSize = 10; - - // Savepoints - ser::Savepoint savepoint1_t_1; - ser::Savepoint savepoint1_t_2; - ser::Savepoint savepoint_u_1; - ser::Savepoint savepoint_v_1; - - savepoint1_t_1.Init("savepoint1"); - savepoint1_t_1.AddMetainfo("time", int(1)); - savepoint1_t_1.AddMetainfo("dt", TypeParam(5.1)); - savepoint1_t_1.AddMetainfo("b", bool(true)); - savepoint1_t_1.AddMetainfo("s", std::string("str1")); - - savepoint1_t_2.Init("savepoint1"); - savepoint1_t_2.AddMetainfo("time", int(2)); - savepoint1_t_2.AddMetainfo("dt", TypeParam(9.1)); - savepoint1_t_2.AddMetainfo("b", bool(false)); - savepoint1_t_2.AddMetainfo("s", std::string("str2")); - - savepoint_u_1.Init("savepoint_u_1"); - savepoint_v_1.Init("savepoint_v_1"); - - using IJKField = - DataFieldOpenMP>; - - IJKField u_0_input, u_1_input, v_0_input, v_1_input; - - // ----------------------------------------------------------------------------------------------- - // Write - // ----------------------------------------------------------------------------------------------- - // - // Savepoint | MetaData | Fields - // ----------------------------------------------------------------- - // savepoint1 | time: 1, dt: 5.1, b: true, s: "str1" | u_0, v_0 - // savepoint1 | time: 2, dt: 9.1, b: false, s: "str2" | u_1, v_1 - // savepoint_u_1 | - | u_1 - // savepoint_v_1 | - | v_1 - // - { - ser::Serializer ser_write; - ser_write.Init(this->directory->path().string(), "Field", ser::SerializerOpenModeWrite); - - // Add some global metainfo - ser_write.AddMetainfo("Day", int(29)); - ser_write.AddMetainfo("Month", std::string("March")); - ser_write.AddMetainfo("Year", TypeParam(2016.10)); - ser_write.AddMetainfo("boolean", true); - - // Register fields - ser_write.RegisterField("u", ser::type_name(), sizeof(TypeParam), iSize, jSize, - kSize, 1, 3, 3, 3, 3, 0, 0, 0, 0); - ser_write.RegisterField("v", ser::type_name(), sizeof(TypeParam), iSize, jSize, 1, 1, - 3, 3, 3, 3, 0, 0, 0, 0); - - ser_write.InitializeField("u", u_0_input, true, true); - ser_write.InitializeField("u", u_1_input, true, true); - ser_write.InitializeField("v", v_0_input, true, true); - ser_write.InitializeField("v", v_1_input, true, true); - - // Fill some random values - bool isFp = std::is_floating_point::value; - const IJKBoundary& boundary = u_0_input.boundary(); - for(int i = boundary.iMinusOffset(); i < (iSize + boundary.iMinusOffset()); ++i) - for(int j = boundary.jMinusOffset(); j < (jSize + boundary.jMinusOffset()); ++j) { - v_0_input(i, j, 0) = (isFp ? (TypeParam(std::rand()) / RAND_MAX) : std::rand()); - v_1_input(i, j, 0) = (isFp ? (TypeParam(std::rand()) / RAND_MAX) : std::rand()); - for(int k = boundary.kMinusOffset(); k < (kSize + boundary.kMinusOffset()); ++k) { - u_0_input(i, j, k) = (isFp ? (TypeParam(std::rand()) / RAND_MAX) : std::rand()); - u_1_input(i, j, k) = (isFp ? (TypeParam(std::rand()) / RAND_MAX) : std::rand()); - } - } - - // Writing (implicitly register the savepoints) - writeField(ser_write, "u", u_0_input, savepoint1_t_1); - writeField(ser_write, "v", v_0_input, savepoint1_t_1); - writeField(ser_write, "u", u_1_input, savepoint1_t_2); - writeField(ser_write, "v", v_1_input, savepoint1_t_2); - writeField(ser_write, "u", u_1_input, savepoint_u_1); - writeField(ser_write, "v", v_1_input, savepoint_v_1); - - // Write field with wrong dimensions -> Exception - ASSERT_THROW(writeField(ser_write, "v", u_0_input, savepoint1_t_1), - ser::SerializationException); - - // Write field with wrong type -> Exception - if(std::is_same::value) { - IJKIntField field; - ser_write.InitializeField("u", field, true, true); - ASSERT_THROW(writeField(ser_write, "u", field, savepoint1_t_1), - ser::SerializationException); - } - } - - // ----------------------------------------------------------------------------------------------- - // Read - // ----------------------------------------------------------------------------------------------- - { - ser::Serializer ser_read; - ser_read.Init(this->directory->path().string(), "Field", ser::SerializerOpenModeRead); - - // Verify global metainfo - EXPECT_EQ(ser_read.globalMetainfo().AsInt("Day"), 29); - EXPECT_EQ(ser_read.globalMetainfo().AsString("Month"), "March"); - EXPECT_EQ(ser_read.globalMetainfo().AsBool("boolean"), true); - - EXPECT_EQ(boost::any_cast(ser_read.globalMetainfo().AsAny("Year")), - TypeParam(2016.10)); - - IJKField u_0_output, u_1_output, v_0_output, v_1_output; - ser_read.InitializeField("u", u_0_output, true, true); - ser_read.InitializeField("u", u_1_output, true, true); - ser_read.InitializeField("v", v_0_output, true, true); - ser_read.InitializeField("v", v_1_output, true, true); - - // Check savepoint ordering - ASSERT_EQ(ser_read.savepoints().size(), 4); - ASSERT_EQ(ser_read.savepoints()[0], savepoint1_t_1); - ASSERT_EQ(ser_read.savepoints()[1], savepoint1_t_2); - ASSERT_EQ(ser_read.savepoints()[2], savepoint_u_1); - ASSERT_EQ(ser_read.savepoints()[3], savepoint_v_1); - - // Check fields at savepoint - auto fields = ser_read.FieldsAtSavepoint(savepoint1_t_1); - ASSERT_EQ(fields.size(), 2); - ASSERT_NE(std::find(fields.begin(), fields.end(), "u"), fields.end()); - ASSERT_NE(std::find(fields.begin(), fields.end(), "v"), fields.end()); - - // Read - readField(ser_read, "u", u_0_output, savepoint1_t_1); - ASSERT_TRUE(verifyFields(u_0_output, u_0_input)); - - readField(ser_read, "v", v_0_output, savepoint1_t_1); - ASSERT_TRUE(verifyFields(v_0_output, v_0_input)); - - readField(ser_read, "u", u_1_output, savepoint1_t_2); - ASSERT_TRUE(verifyFields(u_1_output, u_1_input)); - - readField(ser_read, "v", v_1_output, savepoint1_t_2); - ASSERT_TRUE(verifyFields(v_1_output, v_1_input)); - - // Read into u_0_output as u_1_output already has the correct result - readField(ser_read, "u", u_0_output, savepoint_u_1); - ASSERT_TRUE(verifyFields(u_0_output, u_1_input)); - - // Read into v_0_output as v_1 already_output has the correct result - readField(ser_read, "v", v_0_output, savepoint_v_1); - ASSERT_TRUE(verifyFields(v_0_output, v_1_input)); - - // Read field with wrong dimensions -> Exception - ASSERT_THROW(readField(ser_read, "v", u_0_input, savepoint1_t_1), ser::SerializationException); - - // Read field with wrong type -> Exception - if(std::is_same::value) { - IJKIntField field; - ser_read.InitializeField("u", field, true, true); - ASSERT_THROW(readField(ser_read, "u", field, savepoint1_t_1), - ser::SerializationException); - } - } -} - -#endif // SERIALBOX_HAS_STELLA - -//===------------------------------------------------------------------------------------------===// -// Old serialbox Read/Write tests -//===------------------------------------------------------------------------------------------===// - -template -bool CheckVector(const std::vector& ref, const std::vector& val) { - int size = ref.size(); - EXPECT_EQ(size, val.size()); - - for(int i = 0; i < size; ++i) - if(ref[i] != val[i]) - return false; - - return true; -} - -TEST(STELLASerializerLagecyTest, WriteAndRead) { - std::vector fieldInt2, fieldInt3; - std::vector fieldDouble1, fieldDouble3; - std::vector fieldFloat1, fieldFloat3; - std::vector fieldcheckInt2, fieldcheckInt3; - std::vector fieldcheckDouble1, fieldcheckDouble3; - std::vector fieldcheckFloat1, fieldcheckFloat3; - - ser::Savepoint sp; - sp.Init("TestSavepoint"); - - Directory directory(UnittestEnvironment::getInstance().directory() / - UnittestEnvironment::getInstance().testCaseName() / - UnittestEnvironment::getInstance().testName()); - int iSize = 12; - int jSize = 18; - int kSize = 10; - - int intSize = sizeof(int); - int doubleSize = sizeof(double); - int floatSize = sizeof(float); - - // Allocate fields - fieldInt2.resize(iSize * kSize); - fieldInt3.resize(iSize * jSize * kSize); - fieldDouble1.resize(jSize); - fieldDouble3.resize(iSize * jSize * kSize); - fieldFloat1.resize(jSize); - fieldFloat3.resize(iSize * jSize * kSize); - fieldcheckInt2.resize(iSize * kSize); - fieldcheckInt3.resize(iSize * jSize * kSize); - fieldcheckDouble1.resize(jSize); - fieldcheckDouble3.resize(iSize * jSize * kSize); - fieldcheckFloat1.resize(jSize); - fieldcheckFloat3.resize(iSize * jSize * kSize); - - // ----------------------------------------------------------------------------------------------- - // Write - // ----------------------------------------------------------------------------------------------- - { - ser::Serializer ser; - ser.Init(directory.path().string(), "ReadWriteUnittest", ser::SerializerOpenModeWrite); - - // Register fields - ser.RegisterField("int3", "int", intSize, iSize, jSize, kSize, 1, 0, 0, 0, 0, 0, 0, 0, 0); - ser.RegisterField("int2", "int", intSize, iSize, 1, kSize, 1, 0, 0, 0, 0, 0, 0, 0, 0); - ser.RegisterField("double3", "double", doubleSize, iSize, jSize, kSize, 1, 0, 0, 0, 0, 0, 0, 0, - 0); - ser.RegisterField("double1", "double", doubleSize, 1, jSize, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); - ser.RegisterField("float3", "float", floatSize, iSize, jSize, kSize, 1, 0, 0, 0, 0, 0, 0, 0, 0); - ser.RegisterField("float1", "float", floatSize, 1, jSize, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); - - for(int i = 0; i < iSize; ++i) - for(int j = 0; j < jSize; ++j) - for(int k = 0; k < kSize; ++k) { - fieldInt3[i + j * iSize + k * iSize * jSize] = i + 2 * j - 12 * k * i; - fieldDouble3[i + j * iSize + k * iSize * jSize] = 1.125 * i + 2.25 * j - 12.5 * k * i; - fieldFloat3[i + j * iSize + k * iSize * jSize] = 1.5f * i + 4.25f * j - 16.0f * k * i; - } - - for(int i = 0; i < iSize; ++i) - for(int k = 0; k < kSize; ++k) { - fieldInt2[i + k * iSize] = i - 12 * k * i; - } - - for(int j = 0; j < jSize; ++j) { - fieldDouble1[j] = j * j + 2.875; - fieldFloat1[j] = j * j + 3.5f; - } - - ser.WriteField("int3", sp, fieldInt3.data(), intSize, intSize * iSize, intSize * iSize * jSize, - 0); - ser.WriteField("int2", sp, fieldInt2.data(), intSize, 0, intSize * iSize, 0); - ser.WriteField("double3", sp, fieldDouble3.data(), doubleSize, doubleSize * iSize, - doubleSize * iSize * jSize, 0); - ser.WriteField("double1", sp, fieldDouble1.data(), 0, doubleSize, 0, 0); - ser.WriteField("float3", sp, fieldFloat3.data(), floatSize, floatSize * iSize, - floatSize * iSize * jSize, 0); - ser.WriteField("float1", sp, fieldFloat1.data(), 0, floatSize, 0, 0); - } - - // ----------------------------------------------------------------------------------------------- - // Read - // ----------------------------------------------------------------------------------------------- - { - - ser::Serializer ser; - ser.Init(directory.path().string(), "ReadWriteUnittest", ser::SerializerOpenModeRead); - - ser.ReadField("int3", sp, fieldcheckInt3.data(), intSize, intSize * iSize, - intSize * iSize * jSize, 0); - ser.ReadField("int2", sp, fieldcheckInt2.data(), intSize, 0, intSize * iSize, 0); - ser.ReadField("double3", sp, fieldcheckDouble3.data(), doubleSize, doubleSize * iSize, - doubleSize * iSize * jSize, 0); - ser.ReadField("double1", sp, fieldcheckDouble1.data(), 0, doubleSize, 0, 0); - ser.ReadField("float3", sp, fieldcheckFloat3.data(), floatSize, floatSize * iSize, - floatSize * iSize * jSize, 0); - ser.ReadField("float1", sp, fieldcheckFloat1.data(), 0, floatSize, 0, 0); - - // Check - ASSERT_TRUE(CheckVector(fieldInt3, fieldcheckInt3)); - ASSERT_TRUE(CheckVector(fieldInt2, fieldcheckInt2)); - ASSERT_TRUE(CheckVector(fieldDouble3, fieldcheckDouble3)); - ASSERT_TRUE(CheckVector(fieldDouble1, fieldcheckDouble1)); - ASSERT_TRUE(CheckVector(fieldFloat3, fieldcheckFloat3)); - ASSERT_TRUE(CheckVector(fieldFloat1, fieldcheckFloat1)); - } -} diff --git a/test/serialbox/core/frontend/stella/UnittestStorageView.cpp b/test/serialbox/core/frontend/stella/UnittestStorageView.cpp deleted file mode 100644 index f2cafc6b..00000000 --- a/test/serialbox/core/frontend/stella/UnittestStorageView.cpp +++ /dev/null @@ -1,381 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestStorageView.cpp ----------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the StorageView interoperating with STELLA. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/StorageView.h" -#include "utility/STELLA.h" -#include -#include - -#ifdef SERIALBOX_HAS_STELLA - -namespace { - -template -class STELLAStorageViewTest : public testing::Test { -public: - using StorageType = serialbox::unittest::STELLAStorageTypes; - - // ----------------------------------------------------------------------------------------------- - // Dimensions - // ----------------------------------------------------------------------------------------------- - int dim1; - int dim2; - int dim3; - - // ----------------------------------------------------------------------------------------------- - // Boundaries - // ----------------------------------------------------------------------------------------------- - std::unique_ptr k_boundary; - - // ----------------------------------------------------------------------------------------------- - // Calculation Domain - // ----------------------------------------------------------------------------------------------- - std::unique_ptr cpu_jik_size; - std::unique_ptr cpu_ji_size; - std::unique_ptr cpu_ik_size; - std::unique_ptr cpu_jk_size; - std::unique_ptr cpu_i_size; - std::unique_ptr cpu_j_size; - std::unique_ptr cpu_k_size; - - std::unique_ptr gpu_kji_size; - std::unique_ptr gpu_ji_size; - std::unique_ptr gpu_ki_size; - std::unique_ptr gpu_kj_size; - std::unique_ptr gpu_i_size; - std::unique_ptr gpu_j_size; - std::unique_ptr gpu_k_size; - - // ----------------------------------------------------------------------------------------------- - // Fields - // ----------------------------------------------------------------------------------------------- - std::unique_ptr cpu_jik_field_ptr; - std::unique_ptr cpu_ji_field_ptr; - std::unique_ptr cpu_ik_field_ptr; - std::unique_ptr cpu_jk_field_ptr; - std::unique_ptr cpu_i_field_ptr; - std::unique_ptr cpu_j_field_ptr; - std::unique_ptr cpu_k_field_ptr; - - std::unique_ptr gpu_kji_field_ptr; - std::unique_ptr gpu_ji_field_ptr; - std::unique_ptr gpu_ki_field_ptr; - std::unique_ptr gpu_kj_field_ptr; - std::unique_ptr gpu_i_field_ptr; - std::unique_ptr gpu_j_field_ptr; - std::unique_ptr gpu_k_field_ptr; - -protected: - virtual void SetUp() override { - dim1 = 2; - dim2 = 3; - dim3 = 4; - - k_boundary = std::make_unique(); - k_boundary->Init(0, 1); - - // CPU Size - cpu_jik_size = std::make_unique(); - cpu_jik_size->Init(dim1, dim2, dim3); - - cpu_ji_size = std::make_unique(); - cpu_ji_size->Init(dim1, dim2, 1); - - cpu_ik_size = std::make_unique(); - cpu_ik_size->Init(dim1, 1, dim3); - - cpu_jk_size = std::make_unique(); - cpu_jk_size->Init(1, dim2, dim3); - - cpu_i_size = std::make_unique(); - cpu_i_size->Init(dim1, 1, 1); - - cpu_j_size = std::make_unique(); - cpu_j_size->Init(1, dim2, 1); - - cpu_k_size = std::make_unique(); - cpu_k_size->Init(1, 1, dim3); - - // GPU Size - gpu_kji_size = std::make_unique(); - gpu_kji_size->Init(dim1, dim2, dim3); - - gpu_ji_size = std::make_unique(); - gpu_ji_size->Init(dim1, dim2, 1); - - gpu_ki_size = std::make_unique(); - gpu_ki_size->Init(dim1, 1, dim3); - - gpu_kj_size = std::make_unique(); - gpu_kj_size->Init(1, dim2, dim3); - - gpu_i_size = std::make_unique(); - gpu_i_size->Init(dim1, 1, 1); - - gpu_j_size = std::make_unique(); - gpu_j_size->Init(1, dim2, 1); - - gpu_k_size = std::make_unique(); - gpu_k_size->Init(1, 1, dim3); - - // CPU Storages - cpu_jik_field_ptr = std::make_unique(); - cpu_jik_field_ptr->Init("cpu_jik_field", *cpu_jik_size, *k_boundary); - - cpu_ji_field_ptr = std::make_unique(); - cpu_ji_field_ptr->Init("cpu_ji_field", *cpu_ji_size, *k_boundary); - - cpu_ik_field_ptr = std::make_unique(); - cpu_ik_field_ptr->Init("cpu_ik_field", *cpu_ik_size, *k_boundary); - - cpu_jk_field_ptr = std::make_unique(); - cpu_jk_field_ptr->Init("cpu_jk_field", *cpu_jk_size, *k_boundary); - - cpu_i_field_ptr = std::make_unique(); - cpu_i_field_ptr->Init("cpu_i_field", *cpu_i_size, *k_boundary); - - cpu_j_field_ptr = std::make_unique(); - cpu_j_field_ptr->Init("cpu_j_field", *cpu_j_size, *k_boundary); - - cpu_k_field_ptr = std::make_unique(); - cpu_k_field_ptr->Init("cpu_k_field", *cpu_k_size, *k_boundary); - - // GPU Storages - gpu_kji_field_ptr = std::make_unique(); - gpu_kji_field_ptr->Init("gpu_kji_field", *gpu_kji_size, *k_boundary); - - gpu_ji_field_ptr = std::make_unique(); - gpu_ji_field_ptr->Init("gpu_ji_field", *gpu_ji_size, *k_boundary); - - gpu_ki_field_ptr = std::make_unique(); - gpu_ki_field_ptr->Init("gpu_ki_field", *gpu_ki_size, *k_boundary); - - gpu_kj_field_ptr = std::make_unique(); - gpu_kj_field_ptr->Init("gpu_kj_field", *gpu_kj_size, *k_boundary); - - gpu_i_field_ptr = std::make_unique(); - gpu_i_field_ptr->Init("gpu_i_field", *gpu_i_size, *k_boundary); - - gpu_j_field_ptr = std::make_unique(); - gpu_j_field_ptr->Init("gpu_j_field", *gpu_j_size, *k_boundary); - - gpu_k_field_ptr = std::make_unique(); - gpu_k_field_ptr->Init("gpu_k_field", *gpu_k_size, *k_boundary); - - T val = 0.0; - const IJKBoundary& boundary = cpu_jik_field_ptr->boundary(); - for(int i = boundary.iMinusOffset(); i < (dim1 + boundary.iPlusOffset()); ++i) - for(int j = boundary.jMinusOffset(); j < (dim2 + boundary.jPlusOffset()); ++j) - for(int k = boundary.kMinusOffset(); k < (dim3 + +boundary.kPlusOffset()); ++k) { - (*cpu_jik_field_ptr)(i, j, k) = val; - (*cpu_ji_field_ptr)(i, j, 0) = val; - (*cpu_ik_field_ptr)(i, 0, k) = val; - (*cpu_jk_field_ptr)(0, j, k) = val; - (*cpu_i_field_ptr)(i, 0, 0) = val; - (*cpu_j_field_ptr)(0, j, 0) = val; - (*cpu_k_field_ptr)(0, 0, k) = val; - - (*gpu_kji_field_ptr)(i, j, k) = val; - (*gpu_ji_field_ptr)(i, j, 0) = val; - (*gpu_ki_field_ptr)(i, 0, k) = val; - (*gpu_kj_field_ptr)(0, j, k) = val; - (*gpu_i_field_ptr)(i, 0, 0) = val; - (*gpu_j_field_ptr)(0, j, 0) = val; - (*gpu_k_field_ptr)(0, 0, k) = val; - - val += 1.0; - } - } - - virtual void TearDown() override {} -}; - -template -serialbox::StorageView makeStorageView(const TFieldType& dataField) { - // Strides - DataFieldStorageStrides storageStrides; - storageStrides.Init(dataField.storage().paddedSize()); - - std::vector strides(3); - strides[0] = storageStrides.ComputeStride(1, 0, 0); - strides[1] = storageStrides.ComputeStride(0, 1, 0); - strides[2] = storageStrides.ComputeStride(0, 0, 1); - - // Dimension - const IJKSize& size = dataField.storage().allocatedSize(); - - std::vector dims(3); - dims[0] = size.iSize(); - dims[1] = size.jSize(); - dims[2] = size.kSize(); - - // Origin ptr - const IJKIndex& originOffset = dataField.storage().originOffset(); - void* originPtr = const_cast(static_cast( - &dataField(-originOffset.iIndex(), -originOffset.jIndex(), -originOffset.kIndex()))); - - return serialbox::StorageView(originPtr, - serialbox::ToTypeID::value, - std::move(dims), std::move(strides)); -} - -using TestTypes = testing::Types; - -} // anonymous namespace - -TYPED_TEST_CASE(STELLAStorageViewTest, TestTypes); - -TYPED_TEST(STELLAStorageViewTest, Iterator) { - int dim1 = this->dim1, dim2 = this->dim2, dim3 = this->dim3; - - // ------------------------------------------------------------------------------------------------- - // 1D I - // ------------------------------------------------------------------------------------------------- - -#define CHECK_1D_I(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int i = boundary.iMinusOffset(); i < (dim1 + boundary.iPlusOffset()); ++i, ++field_it) \ - ASSERT_EQ(field_it.as(), field(i, 0, 0)) << field.name(); \ - } - - CHECK_1D_I(cpu_i_field_ptr); - CHECK_1D_I(gpu_i_field_ptr); - -#undef CHECK_1D_I - - // ------------------------------------------------------------------------------------------------- - // 1D J - // ------------------------------------------------------------------------------------------------- - -#define CHECK_1D_J(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int j = boundary.jMinusOffset(); j < (dim2 + boundary.jPlusOffset()); ++j, ++field_it) \ - ASSERT_EQ(field_it.as(), field(0, j, 0)) << field.name(); \ - } - - CHECK_1D_J(cpu_j_field_ptr); - CHECK_1D_J(gpu_j_field_ptr); - -#undef CHECK_1D_J - - // ------------------------------------------------------------------------------------------------- - // 1D I - // ------------------------------------------------------------------------------------------------- - -#define CHECK_1D_K(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int k = boundary.kMinusOffset(); k < (dim3 + boundary.kPlusOffset()); ++k, ++field_it) \ - ASSERT_EQ(field_it.as(), field(0, 0, k)) << field.name(); \ - } - - CHECK_1D_K(cpu_k_field_ptr); - CHECK_1D_K(gpu_k_field_ptr); - -#undef CHECK_1D_K - - // ------------------------------------------------------------------------------------------------- - // 2D KJ - // ------------------------------------------------------------------------------------------------- - -#define CHECK_2D_KJ(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int k = boundary.kMinusOffset(); k < (dim3 + +boundary.kPlusOffset()); ++k) \ - for(int j = boundary.jMinusOffset(); j < (dim2 + boundary.jPlusOffset()); ++j, ++field_it) \ - ASSERT_EQ(field_it.as(), field(0, j, k)) << field.name(); \ - } - - CHECK_2D_KJ(cpu_jk_field_ptr); - CHECK_2D_KJ(gpu_kj_field_ptr); - -#undef CHECK_2D_KJ - - // ------------------------------------------------------------------------------------------------- - // 2D IK - // ------------------------------------------------------------------------------------------------- - -#define CHECK_2D_IK(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int k = boundary.kMinusOffset(); k < (dim3 + +boundary.kPlusOffset()); ++k) \ - for(int i = boundary.iMinusOffset(); i < (dim1 + boundary.iPlusOffset()); ++i, ++field_it) \ - ASSERT_EQ(field_it.as(), field(i, 0, k)) << field.name(); \ - } - - CHECK_2D_IK(cpu_ik_field_ptr); - CHECK_2D_IK(gpu_ki_field_ptr); - -#undef CHECK_2D_IK - - // ------------------------------------------------------------------------------------------------- - // 2D IJ - // ------------------------------------------------------------------------------------------------- - -#define CHECK_2D_IJ(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int j = boundary.jMinusOffset(); j < (dim2 + boundary.jPlusOffset()); ++j) \ - for(int i = boundary.iMinusOffset(); i < (dim1 + boundary.iPlusOffset()); ++i, ++field_it) \ - ASSERT_EQ(field_it.as(), field(i, j, 0)) << field.name(); \ - } - - CHECK_2D_IJ(cpu_ji_field_ptr); - CHECK_2D_IJ(gpu_ji_field_ptr); - -#undef CHECK_2D_IJ - - // ------------------------------------------------------------------------------------------------- - // 3D - // ------------------------------------------------------------------------------------------------- - -#define CHECK_3D(field_ptr) \ - { \ - auto field = *this->field_ptr; \ - serialbox::StorageView storage_view = makeStorageView(field); \ - auto field_it = storage_view.begin(); \ - const IJKBoundary& boundary = field.boundary(); \ - for(int k = boundary.kMinusOffset(); k < (dim3 + +boundary.kPlusOffset()); ++k) \ - for(int j = boundary.jMinusOffset(); j < (dim2 + boundary.jPlusOffset()); ++j) \ - for(int i = boundary.iMinusOffset(); i < (dim1 + boundary.iPlusOffset()); ++i, ++field_it) \ - ASSERT_EQ(field_it.as(), field(i, j, k)) << field.name(); \ - } - - CHECK_3D(cpu_jik_field_ptr); - CHECK_3D(gpu_kji_field_ptr); - -#undef CHECK_3D -} - -#endif diff --git a/test/serialbox/core/frontend/stella/UnittestUtility.cpp b/test/serialbox/core/frontend/stella/UnittestUtility.cpp deleted file mode 100644 index 95d64902..00000000 --- a/test/serialbox/core/frontend/stella/UnittestUtility.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===-- serialbox/core/frontend/stella/UnittestUtility.cpp --------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file contains the unittests of the STELLA utitlity functions. -/// -//===------------------------------------------------------------------------------------------===// - -#include "serialbox/core/frontend/stella/Utility.h" -#include -#include -#include -#include - -using namespace serialbox; - -TEST(STELLAUtility, BoostToStdSharedPointerConversion) { - - std::shared_ptr std_ptr = std::make_shared(5); - ASSERT_EQ(std_ptr.use_count(), 1); - - boost::shared_ptr boost_ptr = boost::make_shared(5); - ASSERT_EQ(boost_ptr.use_count(), 1); - - // std -> boost - { - { - // Create new shared user - boost::shared_ptr ptr = stella::internal::make_shared_ptr(std_ptr); - EXPECT_EQ(std_ptr.use_count(), 2); - EXPECT_EQ(*ptr, 5); - - // Release original pointer - std_ptr.reset(); - EXPECT_EQ(ptr.use_count(), 1); - EXPECT_EQ(*ptr, 5); - } - EXPECT_EQ(std_ptr.use_count(), 0); - } - - // boost -> std - { - { - // Create new shared user - std::shared_ptr ptr = stella::internal::make_shared_ptr(boost_ptr); - EXPECT_EQ(boost_ptr.use_count(), 2); - - // Release original pointer - boost_ptr.reset(); - EXPECT_EQ(ptr.use_count(), 1); - EXPECT_EQ(*ptr, 5); - } - EXPECT_EQ(boost_ptr.use_count(), 0); - } -} diff --git a/test/utility/CMakeLists.txt b/test/utility/CMakeLists.txt index b1e40161..916c9411 100644 --- a/test/utility/CMakeLists.txt +++ b/test/utility/CMakeLists.txt @@ -17,7 +17,6 @@ set(SOURCES FileUtility.h GridTools.h Storage.h - STELLA.h Serialbox.h SerializerTestBase.h UnittestEnvironment.h diff --git a/test/utility/Config.h.cmake b/test/utility/Config.h.cmake index 3d96ea21..fadbcef1 100644 --- a/test/utility/Config.h.cmake +++ b/test/utility/Config.h.cmake @@ -17,9 +17,6 @@ /* Define if GridTools Unittests are built */ #cmakedefine SERIALBOX_HAS_GRIDTOOLS ${SERIALBOX_HAS_GRIDTOOLS} -/* Define if STELLA Unittests are built */ -#cmakedefine SERIALBOX_HAS_STELLA ${SERIALBOX_HAS_STELLA} - /* Define if compatibility Unittests with old serialbox are built */ #cmakedefine SERIALBOX_HAS_SERIALBOX_OLD ${SERIALBOX_HAS_SERIALBOX_OLD} diff --git a/test/utility/STELLA.h b/test/utility/STELLA.h deleted file mode 100644 index 45d2ad42..00000000 --- a/test/utility/STELLA.h +++ /dev/null @@ -1,93 +0,0 @@ -//===-- utility/STELLA.h ------------------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file includes all the necessary STELLA headers and defines storage types. -/// -//===------------------------------------------------------------------------------------------===// - -#ifndef SERIALBOX_UTILITY_STELLA_H -#define SERIALBOX_UTILITY_STELLA_H - -#include "utility/Config.h" - -#ifdef SERIALBOX_HAS_STELLA - -#include "SharedInfrastructure.h" - -namespace serialbox { - -namespace unittest { - -/// \brief Define CPU and GPU storage types parametrized on the value type T -template -struct STELLAStorageTypes { - using value_type = T; - - //===----------------------------------------------------------------------------------------===// - // Alignment - //===----------------------------------------------------------------------------------------===// - using cpu_alignment = DataFieldAlignment; - using cpu_ijk_boundary = DataFieldIJBoundary<-cNumBoundaryLines, cNumBoundaryLines, - -cNumBoundaryLines, cNumBoundaryLines>; - - using gpu_alignment = DataFieldAlignment; - using gpu_ijk_boundary = DataFieldIJBoundary<-cNumBoundaryLines, cNumBoundaryLines, - -cNumBoundaryLines, cNumBoundaryLines>; - - //===----------------------------------------------------------------------------------------===// - // CPU Storage - //===----------------------------------------------------------------------------------------===// - using cpu_jik_storage = - DataFieldOpenMP>; - - using cpu_ji_storage = - DataFieldOpenMP>; - using cpu_ik_storage = - DataFieldOpenMP>; - using cpu_jk_storage = - DataFieldOpenMP>; - - using cpu_i_storage = - DataFieldOpenMP>; - using cpu_j_storage = - DataFieldOpenMP>; - using cpu_k_storage = - DataFieldOpenMP>; - - //===----------------------------------------------------------------------------------------===// - // GPU Storage - //===----------------------------------------------------------------------------------------===// - using gpu_kji_storage = - DataFieldOpenMP>; - - using gpu_ji_storage = - DataFieldOpenMP>; - using gpu_ki_storage = - DataFieldOpenMP>; - using gpu_kj_storage = - DataFieldOpenMP>; - - using gpu_i_storage = - DataFieldOpenMP>; - using gpu_j_storage = - DataFieldOpenMP>; - using gpu_k_storage = - DataFieldOpenMP>; -}; - -} // namespace unittest - -} // namespace serialbox - -#endif - -#endif diff --git a/test/utility/Storage.h b/test/utility/Storage.h index 326238e1..c3a72fe7 100644 --- a/test/utility/Storage.h +++ b/test/utility/Storage.h @@ -43,7 +43,7 @@ struct Padding { std::initializer_list> padding; }; -/// \brief Represent a dummy storage to test the StorageView in absence of gridtools or STELLA +/// \brief Represent a dummy storage to test the StorageView in absence of gridtools template struct Storage { using value_type = T; diff --git a/tools/cscs-scripts/build.sh b/tools/cscs-scripts/build.sh index 05c51e76..e10f11ac 100755 --- a/tools/cscs-scripts/build.sh +++ b/tools/cscs-scripts/build.sh @@ -43,9 +43,9 @@ print_help() # --help printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\nThe unittests for gridtools and stella will be built " + printf "\nThe unittests for gridtools will be built " printf "automatically they are checked out in external/ or " - printf "GRIDTOOLS_ROOT and/or STELLA_ROOT are set.\n" + printf "GRIDTOOLS_ROOT is set.\n" exit 0 } @@ -176,16 +176,6 @@ else SERIALBOX_TESTING_GRIDTOOLS=OFF fi -# STELLA -if [ ! -z ${STELLA_ROOT+x} ]; then - SERIALBOX_TESTING_STELLA=ON -elif [ -d "${EXTERNAL_DIR}/stella" ]; then - SERIALBOX_TESTING_STELLA=ON - export GRIDTOOLS_ROOT=${EXTERNAL_DIR}/stella -else - SERIALBOX_TESTING_STELLA=OFF -fi - # pFUnit if [ ! -z ${PFUNIT_INSTALL_DIR+x} ]; then SERIALBOX_TESTING_FORTRAN=ON @@ -233,7 +223,6 @@ cmake \ -DSERIALBOX_ENABLE_C:BOOL=${SERIALBOX_ENABLE_C} \ -DSERIALBOX_ENABLE_FORTRAN:BOOL=${SERIALBOX_ENABLE_FORTRAN} \ -DSERIALBOX_TESTING_GRIDTOOLS:BOOL=${SERIALBOX_TESTING_GRIDTOOLS} \ - -DSERIALBOX_TESTING_STELLA:BOOL=${SERIALBOX_TESTING_STELLA} \ -DSERIALBOX_TESTING_FORTRAN:BOOL=${SERIALBOX_TESTING_FORTRAN} \ -DSERIALBOX_USE_NETCDF:BOOL=${SERIALBOX_USE_NETCDF} \ -DSERIALBOX_ENABLE_FTG:BOOL=ON \ From cd4736e99359a4eb0186d32702c9f3bedadadb3c Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 18 Nov 2024 16:55:35 +0100 Subject: [PATCH 2/5] Remove some dependencies on boost --- examples/CMakeLists.txt | 4 - examples/gridtools/CMakeLists.txt | 13 - examples/gridtools/simple/CMakeLists.txt | 15 - .../gridtools/simple/example-01-laplacian.cpp | 335 ------------------ .../gridtools/simple/example-02-stateless.cpp | 97 ----- .../gridtools/simple/example-03-slice.cpp | 143 -------- examples/gridtools/smagorinsky/.gitignore | 1 - examples/gridtools/smagorinsky/CMakeLists.txt | 64 ---- .../smagorinsky/cmake/FindGridTools.cmake | 39 -- .../gridtools/smagorinsky/smagorinsky.cpp | 59 --- .../smagorinsky/smagorinsky_repository.hpp | 170 --------- .../smagorinsky/smagorinsky_stencil.hpp | 291 --------------- src/serialbox/core/MetainfoValueImpl.cpp | 35 +- src/serialbox/core/MetainfoValueImpl.h | 16 +- src/serialbox/core/SerializerImpl.cpp | 5 +- src/serialbox/core/archive/BinaryArchive.cpp | 4 +- src/serialbox/core/archive/NetCDFArchive.cpp | 4 +- test/serialbox/core/UnittestFieldMap.cpp | 3 +- .../core/UnittestFieldMetainfoImpl.cpp | 1 - .../core/UnittestMetainfoMapImpl.cpp | 3 +- .../core/UnittestMetainfoValueImpl.cpp | 1 + test/serialbox/core/UnittestSavepointImpl.cpp | 1 - .../core/UnittestSavepointVector.cpp | 3 +- test/serialbox/core/UnittestStorageView.cpp | 5 +- .../core/archive/UnittestBinaryArchive.cpp | 3 +- .../core/archive/UnittestNetCDFArchive.cpp | 4 +- .../gridtools/UnittestMetainfoMap.cpp | 2 +- 27 files changed, 40 insertions(+), 1281 deletions(-) delete mode 100644 examples/gridtools/CMakeLists.txt delete mode 100644 examples/gridtools/simple/CMakeLists.txt delete mode 100644 examples/gridtools/simple/example-01-laplacian.cpp delete mode 100644 examples/gridtools/simple/example-02-stateless.cpp delete mode 100644 examples/gridtools/simple/example-03-slice.cpp delete mode 100644 examples/gridtools/smagorinsky/.gitignore delete mode 100644 examples/gridtools/smagorinsky/CMakeLists.txt delete mode 100644 examples/gridtools/smagorinsky/cmake/FindGridTools.cmake delete mode 100644 examples/gridtools/smagorinsky/smagorinsky.cpp delete mode 100644 examples/gridtools/smagorinsky/smagorinsky_repository.hpp delete mode 100644 examples/gridtools/smagorinsky/smagorinsky_stencil.hpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 40578881..f1f65515 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -53,7 +53,3 @@ endif() if(SERIALBOX_ENABLE_PYTHON) add_subdirectory(python) endif() - -if(SERIALBOX_TESTING_GRIDTOOLS) - add_subdirectory(gridtools) -endif() diff --git a/examples/gridtools/CMakeLists.txt b/examples/gridtools/CMakeLists.txt deleted file mode 100644 index 700cbe7e..00000000 --- a/examples/gridtools/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -##===------------------------------------------------------------------------------*- CMake -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===------------------------------------------------------------------------------------------===## - -cmake_minimum_required(VERSION 3.12) - -add_subdirectory(simple) - diff --git a/examples/gridtools/simple/CMakeLists.txt b/examples/gridtools/simple/CMakeLists.txt deleted file mode 100644 index f8fe5cc0..00000000 --- a/examples/gridtools/simple/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -##===------------------------------------------------------------------------------*- CMake -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===------------------------------------------------------------------------------------------===## - -cmake_minimum_required(VERSION 3.12) - -serialbox_add_gridtools_example(example-01-laplacian-cpp example-01-laplacian.cpp) -serialbox_add_gridtools_example(example-02-stateless-cpp example-02-stateless.cpp) -serialbox_add_gridtools_example(example-03-slice-cpp example-03-slice.cpp) - diff --git a/examples/gridtools/simple/example-01-laplacian.cpp b/examples/gridtools/simple/example-01-laplacian.cpp deleted file mode 100644 index 6a98b035..00000000 --- a/examples/gridtools/simple/example-01-laplacian.cpp +++ /dev/null @@ -1,335 +0,0 @@ -//===--------------------------------------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information. -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This example demonstrates how to setup a Serializer, add global meta-information, register -/// fields and savepoints and serialize/deserialize gridtools storages using the gridtools frontend -/// of Serialbox. -/// -/// In this small example we will repeatedly apply a two dimensional laplacian stencil to an input -/// field `phi`. Before and after each invocation of the laplacian stencil, we will serialize the -/// data to disk. -/// -/// This example is also available in all other languages supported by Serialbox. -// -//===------------------------------------------------------------------------------------------===// - -// -// Include gridtools headers -// -#include -#include - -// -// Include Serialbox headers -// -#include "serialbox/gridtools/serialbox.hpp" - -#include -#include -#include - -static constexpr int N = 10; -static constexpr int M = 10; -static constexpr int halo_size = 1; - -// -// Typedefs of the gridtools library -// -using storage_traits_t = gridtools::storage_traits; -using backend_t = gridtools::backend; -using halo_t = gridtools::halo; -using storage_info_t = - storage_traits_t::special_storage_info_t<0, gridtools::selector<1, 1, 0>, halo_t>; -using storage_t = storage_traits_t::data_store_t; - -// -// Laplacian stage -// -struct laplacian_stage { - using lap = gridtools::inout_accessor<0>; - using phi = gridtools::in_accessor<1, gridtools::extent<-1, 1, -1, 1>>; - - using arg_list = boost::mpl::vector; - - template - GT_FUNCTION static void Do(Evaluation& eval) { - eval(lap()) = - eval(phi(1, 0)) + eval(phi(-1, 0)) + eval(phi(0, -1)) + eval(phi(0, 1)) - 4 * eval(phi()); - } -}; - -//===------------------------------------------------------------------------------------------===// -// write() -// -// In this function we first prepare the Serializer for writing, add some global meta-information -// and register the fields `phi` and `lap`. Later, we apply the `laplacianStencil` to `phi` and -// `lap` and serialize every iteration `phi` as an input and `lap` as an output of the stencil. -// -//===------------------------------------------------------------------------------------------===// -void write() { - // - // The gridtools frontend of Serialbox is confined in serialbox::gridtools - // - namespace ser = serialbox::gridtools; - - // - // Create a Serializer for writing. Besides the open-policy, we have to specify the `directory` - // in which the Serializer is created and the `prefix` of all files. In case the directory does - // not exist, it will be created. In addition, if the directory is not empty, all fields with the - // same `prefix` will be erased (this behaviour can be inhibited using the Append mode). - // - ser::serializer serializer(ser::open_mode::Write, "./laplacian/", "field"); - - // - // Allocate the 2D arrays phi and lap and fill it with some random numbers - // - storage_info_t storage_info(N, M, 1); - - std::default_random_engine gen; - std::uniform_real_distribution dist(0.0, 1.0); - - storage_t phi( - storage_info, [&](int i, int j, int k) { return dist(gen); }, "phi"); - storage_t lap(storage_info, -1., "lap"); - - // - // Create the field meta-information of `phi` directly with the gridtools storage and register it - // within the Serializer. For the gridtools interface this can also be done implicitly in the - // write method (see below). - // - ser::field_meta_info fieldmetainfo(phi); - serializer.register_field("phi", fieldmetainfo); - - // - // Add some global meta-information to the serializer. Besides the usual `key = value` pair, - // you can also add `key = {value1, ..., valueN}` pairs. - // - serializer.add_global_meta_info("answer", 42); - serializer.add_global_meta_info("halos", std::vector{1, 1, 1, 1}); - - // - // Up to this point nothing has been written to disk. Using update_meta_data() will force a write - // of all meta-information to the corresponding JSON files. Note that the meta-data is updated - // after each call and thus a manual update of the meta-data is seldom required. If you are - // curious you can inspect the files './laplacian/MetaData-field.json' and - // './laplacian/ArchiveMetaData-field.json' - // - serializer.update_meta_data(); - - // - // We now assemble the gridtools stencil - // - using p_lap = gridtools::arg<0, storage_t>; - using p_phi = gridtools::arg<1, storage_t>; - using arg_list = boost::mpl::vector; - - // Setup grid - gridtools::halo_descriptor di{halo_size, halo_size, halo_size, N - halo_size - 1, N}; - gridtools::halo_descriptor dj{halo_size, halo_size, halo_size, M - halo_size - 1, M}; - - // Make computation - auto laplacian_stencil = gridtools::make_computation( - gridtools::make_grid(di, dj, 1), (p_lap() = lap), (p_phi() = phi), - gridtools::make_multistage(gridtools::enumtype::execute(), - gridtools::make_stage(p_lap(), p_phi()))); - - // - // Now, we apply the `laplacian_stencil` three times to phi. In each iteration we will create - // an input and output savepoint where we save the current `phi` field (input) and `lap` field - // (output). - // - for(int t = 0; t < 3; ++t) { - // - // Create a Savepoint. Savepoints can have the same name as long as they have different - // meta-information. In our case we will always store the current time step `t` as a - // meta-information, thus making it unique. - // - ser::savepoint savepoint_in("laplacian-in"); - savepoint_in.meta_info().insert("time", t); - - // - // Register the Savepoint. - // - serializer.register_savepoint(savepoint_in); - - // - // Write phi to disk at our input savepoint. This will create the file `field_phi.dat` upon - // first invocation and afterwards the data is appended. - // - serializer.write("phi", savepoint_in, phi); - - // - // Apply the laplacian_stencil to phi - // - laplacian_stencil.run(); - - // - // Create the output savepoint. This time we directly initialize the meta-information of the - // savepoint. - // - ser::savepoint savepoint_out("laplacian-out", {{"time", ser::meta_info_value(t)}}); - - // - // Write lap to disk. Note that here we implicitly register the field `lap` upon first - // invocation. Same goes for the output savepoint. - // - serializer.write("lap", savepoint_out, lap); - - // - // Finally, we swap phi with lap (usually you want to use a gridtools::data_field for this - // task!) - // - auto lap_view = make_host_view(lap); - auto phi_view = make_host_view(phi); - for(int i = 0; i < N; ++i) - for(int j = 0; j < M; ++j) - std::swap(phi_view(i, j, 0), lap_view(i, j, 0)); - } -} - -template -std::string vec_to_string(VectorType&& vec) { - std::stringstream ss; - ss << "[ "; - for(auto it = vec.begin(), end = vec.end(); it != end; ++it) - ss << *it << " "; - ss << "]"; - return ss.str(); -} - -//===------------------------------------------------------------------------------------------===// -// read() -// -// In this function we initialize the Serializer for reading with our serialized data from the -// write() method. First, we query some meta-data, like the global meta-information, the -// dimensions of field `phi` or the vector of savepoints. -// Afterwards, we apply the same three time steps of the `laplacianStencil` to `phi` to compute -// `lap`. However, this time we compare the result (i.e the content of `lap`) to the reference -// loaded from disk (`lap_reference`) which we computed in the write() method. Obviously, the -// results will match as we apply the exact same stencil but in a real world scenario you might use -// a different implementations of the stencil and this is where Serialbox has it's use case. -// -//===------------------------------------------------------------------------------------------===// -void read() { - namespace ser = serialbox::gridtools; - - // - // Create a Serializer for reading. This gives access to the previously written data. - // - ser::serializer serializer(ser::open_mode::Read, "./laplacian/", "field"); - - // - // Access the global meta-information - // - std::cout << "The answer is " << serializer.global_meta_info().as("answer") << std::endl; - - std::vector halos = serializer.global_meta_info().as>("halos"); - std::cout << "The halo boundaries are " << vec_to_string(halos) << std::endl; - - // - // Access the field meta-information - // - std::vector fieldnames = serializer.fieldnames(); - std::cout << "The registered fields are: " << vec_to_string(fieldnames) << std::endl; - - const std::vector& dims_of_phi = serializer.get_field_meta_info("phi").dims(); - std::cout << "Dimensions of phi: " << vec_to_string(dims_of_phi) << std::endl; - - // - // Access the savepoints. The savepoints are ordered in the order they were inserted. - // - const std::vector& savepoints = serializer.savepoints(); - std::cout << "Savepoints:\n"; - for(std::size_t i = 0; i < savepoints.size(); ++i) - std::cout << " " << savepoints[i] << "\n"; - - // - // Allocate the 2D arrays phi and lap and assemble the gridtools stencil - // - storage_info_t meta_data(N, M, 1); - storage_t phi(meta_data, -1., "phi"); - storage_t lap(meta_data, -1., "lap"); - storage_t lap_reference(meta_data, -1., "lap_reference"); - - using p_lap = gridtools::arg<0, storage_t>; - using p_phi = gridtools::arg<1, storage_t>; - using arg_list = boost::mpl::vector; - - // Setup grid - gridtools::halo_descriptor di = {halo_size, halo_size, halo_size, N - halo_size - 1, N}; - gridtools::halo_descriptor dj = {halo_size, halo_size, halo_size, M - halo_size - 1, M}; - - // Make computation - auto laplacian_stencil = gridtools::make_computation( - gridtools::make_grid(di, dj, 1), (p_lap() = lap), (p_phi() = phi), - gridtools::make_multistage(gridtools::enumtype::execute(), - gridtools::make_stage(p_lap(), p_phi()))); - // - // We will now perform the same iterations as in the write method but this time we will read - // phi as an input from disk, compute the laplacian and compare the result to the stored output - // of lap on disk (loaded as `lap_refrence`). - // - for(int t = 0; t < 3; ++t) { - // - // Get the current input savepoint at time t (the factor of 2 is due to the fact that we - // stored input and output in alternating order). - // - const ser::savepoint& savepoint_in = savepoints[2 * t]; - - // - // Load phi from disk. - // - serializer.read("phi", savepoint_in, phi); - - // - // Apply the laplacian_stencil to phi - // - laplacian_stencil.run(); - - // - // Load the refrence output of lap ... - // - const ser::savepoint& savepoint_out = savepoints[2 * t + 1]; - serializer.read("lap", savepoint_out, lap_reference); - - // - // ... and compare the results. - // - auto lap_view = make_host_view(lap); - auto lap_reference_view = make_host_view(lap_reference); - for(int i = 1; i < N - 1; ++i) - for(int j = 1; j < M - 1; ++j) - if(lap_view(i, j, 0) != lap_reference_view(i, j, 0)) - throw ser::exception("mismatch at (%i,%i) of lap and lap_reference: %f vs. %f\n", i, j, - lap_view(i, j, 0), lap_reference_view(i, j, 0)); - } -} - -//===------------------------------------------------------------------------------------------===// -// main() -// -// Here we call our write() and read() functions. -// -//===------------------------------------------------------------------------------------------===// -int main() { - try { - // Write some data ... - write(); - - // ... and read it. - read(); - - } catch(std::exception& e) { - std::cerr << "Errror: " << e.what() << std::endl; - return 1; - } - return 0; -} diff --git a/examples/gridtools/simple/example-02-stateless.cpp b/examples/gridtools/simple/example-02-stateless.cpp deleted file mode 100644 index 94790d4d..00000000 --- a/examples/gridtools/simple/example-02-stateless.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//===--------------------------------------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information. -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This example demonstrates how to use stateless serializations i.e serialize fields without the -/// need to register fields or savpoints. In addition, the usage of the logging infrastructure -/// is exemplified. -/// -/// This example is also available in all other languages supported by Serialbox. -// -//===------------------------------------------------------------------------------------------===// - -// -// Include gridtools headers -// -#include - -// -// Include Serialbox headers -// -#include "serialbox/gridtools/serialbox.hpp" - -#include -#include -#include - -// -// Typedefs of the gridtools library -// -using storage_traits_t = gridtools::storage_traits; -using storage_info_t = storage_traits_t::storage_info_t<0, 3>; -using storage_t = storage_traits_t::data_store_t; - -int main() { - int N = 10, M = 15, K = 20; - try { - - // - // The gridtools frontend of Serialbox is confined in serialbox::gridtools - // - namespace ser = serialbox::gridtools; - - // - // Enable logging, by default it is turned off - // - ser::logging::enable(); - - // - // Allocate 3D arrays and fill the input with some random numbers - // - storage_info_t storage_info(N, M, K); - - std::default_random_engine gen; - std::uniform_real_distribution dist(0.0, 1.0); - - storage_t field_in( - storage_info, [&](int i, int j, int k) { return dist(gen); }, "storage"); - storage_t field_out(storage_info, -1., "storage"); - - // - // Write the gridtools storage to disk. The archive will be deduced from the file extension - // (here ".dat" implies the Binary archive). The written data can know also be read in C, Python - // and Fortran. - // - ser::serializer::to_file("field.dat", field_in); - - // - // Read the written field from file (note that this method performs no consistency checks so you - // have to know what you are doing!). - // - ser::serializer::from_file("field.dat", field_out); - - // - // Verify the result - // - { - auto in = make_host_view(field_in); - auto out = make_host_view(field_out); - for(int i = 0; i < N; ++i) - for(int j = 0; j < M; ++j) - for(int k = 0; k < K; ++k) - if(in(i, j, k) != out(i, j, k)) - throw ser::exception("mismatch at (%i,%i) of in and out: %f vs. %f\n", i, j, - in(i, j, k), out(i, j, k)); - } - } catch(std::exception& e) { - std::cerr << "Errror: " << e.what() << std::endl; - return 1; - } - return 0; -} diff --git a/examples/gridtools/simple/example-03-slice.cpp b/examples/gridtools/simple/example-03-slice.cpp deleted file mode 100644 index 8445b232..00000000 --- a/examples/gridtools/simple/example-03-slice.cpp +++ /dev/null @@ -1,143 +0,0 @@ -//===--------------------------------------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information. -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This example demonstrates how to only load parts (slices) of a serialized field. This can -/// significantly improve performance if one is only interested in a small part of the data. -/// -/// This example is also available in all other languages supported by Serialbox. -// -//===------------------------------------------------------------------------------------------===// - -// -// Include gridtools headers -// -#include - -// -// Include Serialbox headers -// -#include "serialbox/gridtools/serialbox.hpp" - -#include -#include -#include -#include - -// -// Typedefs of the gridtools library -// -using storage_traits_t = gridtools::storage_traits; -using storage_info_t = storage_traits_t::storage_info_t<0, 3>; -using storage_t = storage_traits_t::data_store_t; - -int main() { - int N = 512, M = 512, K = 80; - try { - - // - // The gridtools frontend of Serialbox is confined in serialbox::gridtools - // - namespace ser = serialbox::gridtools; - - // - // Initialize the serializer. At the moment sliced loading is only supported by the Binary - // archive - // - ser::serializer serializer_write(ser::open_mode::Write, "./slice", "field", "Binary"); - - // - // Allocate 3D arrays and fill the input with some random numbers - // - storage_info_t storage_info(N, M, K); - - std::default_random_engine gen; - std::uniform_real_distribution dist(0.0, 1.0); - - storage_t field_in( - storage_info, [&](int i, int j, int k) { return dist(gen); }, "storage"); - storage_t field_out(storage_info, -1., "storage"); - - // - // Write the gridtools storage to disk at Savepoint `sp` - // - ser::timer t; - - auto savepoint = ser::savepoint("sp"); - serializer_write.write("field", savepoint, field_in); - - std::printf("serializer.write : %8.2f ms\n", t.stop()); - - // - // Initialize a serializer for reading. - // - ser::serializer serializer_read(ser::open_mode::Read, "./slice", "field", "Binary"); - - // - // Assume we are only interested in a certain layer of the data (k = 50), we can use the slice - // object (ser::slice) to encode this information and instruct the serializer to only load - // the desired data. Note that you still need to allocate memory for the whole field. - // The syntax for slicing follows closely the slicing syntax used in Python, the equivalent of - // `[start1:stop1:step1, ... ,startN:stopN:stepN]` is - // `slice(start1, stop1, step1) ... (startN, stopN, stepN)`. In python we used: - // `serializer_read.read_slice('field', savepoint, ser.Slice[:, :, 50], field_out)` which is - // equivalent to ... - // - t.start(); - - serializer_read.read_slice("field", savepoint, field_out, ser::slice()()(50, 51)); - - std::printf("serializer.read_slice : %8.2f ms\n", t.stop()); - - // - // Verify - // - { - auto in = make_host_view(field_in); - auto out = make_host_view(field_out); - for(int i = 0; i < N; ++i) - for(int j = 0; j < M; ++j) - if(in(i, j, 50) != out(i, j, 50)) - throw ser::exception("mismatch at (%i,%i) of in and out: %f vs. %f\n", i, j, - in(i, j, 50), out(i, j, 50)); - } - - // - // For comparison, let's load the full data. - // - t.start(); - - serializer_read.read("field", savepoint, field_out); - - std::printf("serializer.read : %8.2f ms\n", t.stop()); - - // - // Verify - // - { - auto in = make_host_view(field_in); - auto out = make_host_view(field_out); - for(int i = 0; i < N; ++i) - for(int j = 0; j < M; ++j) - if(in(i, j, 50) != out(i, j, 50)) - throw ser::exception("mismatch at (%i,%i) of in and out: %f vs. %f\n", i, j, - in(i, j, 50), out(i, j, 50)); - } - - // - // Remove directory - // - serialbox::remove_all("./slice"); - - } catch(std::exception& e) { - std::cerr << "Errror: " << e.what() << std::endl; - return 1; - } - return 0; -} diff --git a/examples/gridtools/smagorinsky/.gitignore b/examples/gridtools/smagorinsky/.gitignore deleted file mode 100644 index a007feab..00000000 --- a/examples/gridtools/smagorinsky/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/examples/gridtools/smagorinsky/CMakeLists.txt b/examples/gridtools/smagorinsky/CMakeLists.txt deleted file mode 100644 index 514e1696..00000000 --- a/examples/gridtools/smagorinsky/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -##===------------------------------------------------------------------------------*- CMake -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===------------------------------------------------------------------------------------------===## - -cmake_minimum_required(VERSION 3.12) - -project(SerialboxSmagorinskyExample CXX) - -# -# We use the Serialbox which was installed in install/. If this folder does not exists, or is empty, -# you have to build and install Serialbox first. To tell CMake where Serialbox is located, you have -# to define SERIALBOX_ROOT (either directly in CMake or pass it as -DSERIALBOX_ROOT=<> via -# command-line). -# -if(NOT(DEFINED SERIALBOX_ROOT)) - set(SERIALBOX_ROOT "${PROJECT_SOURCE_DIR}/../../../install") -endif() - -# -# Serialbox has a find_package-module which takes care of looking for the dependency libraries. -# Usually you want to bundle this module with your own project and therefore we copied it into -# "cmake/". We need to tell CMake about this. -# -list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") - -# -# We call the find_package-module of Serialbox and gridtools and set the include directories -# -find_package(Serialbox REQUIRED HINTS - "${CMAKE_CURRENT_LIST_DIR}/../serialbox/install/cmake" - "${SERIALBOX_ROOT}/cmake" - "${SERIALBOX_DIR}/cmake" - "$ENV{SERIALBOX_ROOT}/cmake") - -find_package(GridTools REQUIRED) - -include_directories(SYSTEM ${SERIALBOX_INCLUDE_DIRS}) -include_directories(SYSTEM ${GRIDTOOLS_INCLUDE_DIRS}) - -# -# Serialbox requires C++17 -# -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - -# -# Don't use Debug symbols, gcc takes to long otherwise ;) -# -string(REPLACE "-g" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - -# -# Finally, we add the executables and link against the Serialbox libraries -# -add_executable(smagorinsky smagorinsky.cpp smagorinsky_stencil.hpp smagorinsky_repository.hpp) -target_link_libraries(smagorinsky ${SERIALBOX_CXX_LIBRARIES}) - -add_executable(smagorinsky-error smagorinsky.cpp smagorinsky_stencil.hpp smagorinsky_repository.hpp) -target_compile_definitions(smagorinsky-error PUBLIC -DERROR) -target_link_libraries(smagorinsky-error ${SERIALBOX_CXX_LIBRARIES}) - diff --git a/examples/gridtools/smagorinsky/cmake/FindGridTools.cmake b/examples/gridtools/smagorinsky/cmake/FindGridTools.cmake deleted file mode 100644 index 42c8dac5..00000000 --- a/examples/gridtools/smagorinsky/cmake/FindGridTools.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# Try to find GridTools libraries and headers. -# -# Usage of this module as follows: -# -# find_package(GridTools) -# -# Variables used by this module, they can change the default behaviour and need -# to be set before calling find_package: -# -# GRIDTOOLS_ROOT Set this variable to the root installation of -# GridTools if the module has problems finding the -# proper installation path. -# -# Variables defined by this module: -# -# GRIDTOOLS_FOUND System has GridTools libraries and headers -# GRIDTOOLS_INCLUDE_DIRS The location of GridTools headers - -find_path(GRIDTOOLS_ROOT NAMES include/gridtools.hpp) - -# Look for GridTools headers -find_path(GRIDTOOLS_INCLUDE_DIRS - NAMES gridtools.hpp - HINTS ${GRIDTOOLS_ROOT}/include - $ENV{GRIDTOOLS_ROOT}/include -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GRIDTOOLS DEFAULT_MSG GRIDTOOLS_INCLUDE_DIRS) - -if(GRIDTOOLS_FOUND) - mark_as_advanced(GRIDTOOLS_INCLUDE_DIRS) -else() - # If the package was required we abort the process - if(${GridTools_FIND_REQUIRED}) - message(FATAL_ERROR "Could NOT find GRIDTOOLS. (Try setting GRIDTOOLS_ROOT in the env)") - endif(${GridTools_FIND_REQUIRED}) -endif() - diff --git a/examples/gridtools/smagorinsky/smagorinsky.cpp b/examples/gridtools/smagorinsky/smagorinsky.cpp deleted file mode 100644 index 30f9fa20..00000000 --- a/examples/gridtools/smagorinsky/smagorinsky.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===-- smagorinsky.cpp -------------------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// This file calls the Smagorinsky horizontal-diffusion stencil with serialized data and uses the -/// fine-grained deserialization of gridtools for further preprocessing with sdb. -/// -//===------------------------------------------------------------------------------------------===// - -#include "smagorinsky_repository.hpp" -#include "smagorinsky_stencil.hpp" - -#include -#include - -namespace { -#ifdef ERROR -const char* output_dir = "./smagorinsky-stencil-error"; -#else -const char* output_dir = "./smagorinsky-stencil"; -#endif -} - -int main() { - // - // Allocate & initialize fields - // - - auto repo = smagorinsky::repository(33, 28, 80); - repo.init_fields(); - - try { - - // - // Setup serializer - // - serialbox::gridtools::serializer serializer(serialbox::gridtools::open_mode::Write, output_dir, - "stencil"); - - // - // Run & serialize smagorinsky stencil - // - - smagorinsky::run_stencil(repo, serializer, 3); - - } catch(std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - return 1; - } - - std::cout << "Successfully ran Smagorinsky stencil!" << std::endl; - return 0; -} diff --git a/examples/gridtools/smagorinsky/smagorinsky_repository.hpp b/examples/gridtools/smagorinsky/smagorinsky_repository.hpp deleted file mode 100644 index 2047bef1..00000000 --- a/examples/gridtools/smagorinsky/smagorinsky_repository.hpp +++ /dev/null @@ -1,170 +0,0 @@ -//===-- smagorinsky_repository.hpp --------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// Allocate and initialize the gridtools storages with serialized data. -/// -//===------------------------------------------------------------------------------------------===// - -#pragma once - -#define CXX11_ENABLED -#define STRUCTURED_GRIDS -#include -#include -#include -#include - -#include -#include - -namespace smagorinsky { - -// Fine-grained serialization is only supported by the Naive Host backend at the moment. -using backend = gridtools::backend; - -/// @brief Axis of the Grid including the entire vertical domain -using axis_t = gridtools::interval, gridtools::level<1, 3>>; - -/// \brief All layers, meaning [0, k) -using full_domain_t = gridtools::interval, gridtools::level<1, -1>>; - -/// \brief Repository of the storages of the smagorinsky stencil -class repository { -public: - static constexpr int halo_size = 3; - - /// \brief Floating point type - using float_type = gridtools::float_type; - - /// \brief Horizontal halo - using halo_ijk_t = gridtools::halo<3, 3, 0>; - using halo_j_t = gridtools::halo<0, 3, 0>; - - /// \brief Layout types - /// @{ - using layout_ijk_t = gridtools::layout_map<0, 1, 2>; - using layout_j_t = gridtools::layout_map<-1, 0, -1>; - using layout_scalar_t = gridtools::layout_map<-1, -1, -1>; - /// @} - - /// \brief Meta-data types - /// @{ - using metadata_ijk_t = backend::storage_info<0, layout_ijk_t, halo_ijk_t>; - using metadata_j_t = backend::storage_info<1, layout_j_t, halo_j_t>; - using metadata_scalar_t = backend::storage_info<2, layout_scalar_t>; - /// @} - - /// \brief Storage types - /// @{ - using storage_ijk_t = backend::storage_type::type; - using storage_ijk_tmp_t = backend::temporary_storage_type::type; - using storage_j_t = backend::storage_type::type; - using storage_scalar_t = backend::storage_type::type; - - /// \brief Allocate the storages - repository(int i, int j, int k) - : isize_(i + 2 * halo_size), jsize_(j + 2 * halo_size), ksize_(k), - - metadata_scalar_(1, 1, 1), metadata_j_(1, jsize_, 1), metadata_ijk_(isize_, jsize_, ksize_), - - // Output fields - u_out_(metadata_ijk_, -1.0, "u_out"), v_out_(metadata_ijk_, -1.0, "v_out"), - - // Input fields - u_in_(metadata_ijk_, -1.0, "u_in"), v_in_(metadata_ijk_, -1.0, "v_in"), - hdmaskvel_(metadata_ijk_, -1.0, "hdmaskvel"), - - crlavo_(metadata_j_, -1.0, "crlavo"), crlavu_(metadata_j_, -1.0, "crlavu"), - crlato_(metadata_j_, -1.0, "crlato"), crlatu_(metadata_j_, -1.0, "crlatu"), - acrlat0_(metadata_j_, -1.0, "acrlat0"), - - // Scalar fields - eddlon_(metadata_scalar_, -1.0, "eddlon"), eddlat_(metadata_scalar_, -1.0, "eddlat"), - tau_smag_(metadata_scalar_, -1.0, "tau_smag"), - weight_smag_(metadata_scalar_, -1.0, "weight_smag") {} - - /// \brief Getter - /// @{ - storage_ijk_t& u_out() { return u_out_; } - storage_ijk_t& v_out() { return v_out_; } - - storage_ijk_t& u_in() { return u_in_; } - storage_ijk_t& v_in() { return v_in_; } - storage_ijk_t& hdmaskvel() { return hdmaskvel_; } - - storage_j_t& crlavo() { return crlavo_; } - storage_j_t& crlavu() { return crlavu_; } - storage_j_t& crlato() { return crlato_; } - storage_j_t& crlatu() { return crlatu_; } - storage_j_t& acrlat0() { return acrlat0_; } - - storage_scalar_t& eddlon() { return eddlon_; } - storage_scalar_t& eddlat() { return eddlat_; } - storage_scalar_t& tau_smag() { return tau_smag_; } - storage_scalar_t& weight_smag() { return weight_smag_; } - /// @} - - gridtools::uint_t isize() const { return isize_; } - gridtools::uint_t jsize() const { return jsize_; } - gridtools::uint_t ksize() const { return ksize_; } - - /// \brief Load input data - void init_fields() { - - std::cout << "Initializing storages ..." << std::endl; - - std::default_random_engine generator; - std::uniform_real_distribution distribution(0.0, 1.0); - - for(int i = 0; i < isize_; i++) - for(int j = 0; j < jsize_; j++) - for(int k = 0; k < ksize_; k++) { - u_out_(i, j, k) = distribution(generator); - v_out_(i, j, k) = distribution(generator); - u_in_(i, j, k) = distribution(generator); - v_in_(i, j, k) = distribution(generator); - hdmaskvel_(i, j, k) = distribution(generator); - } - - for(int j = 0; j < jsize_; j++) { - crlavo_(0, j, 0) = distribution(generator); - crlavu_(0, j, 0) = distribution(generator); - crlato_(0, j, 0) = distribution(generator); - crlatu_(0, j, 0) = distribution(generator); - acrlat0_(0, j, 0) = distribution(generator); - } - - eddlon_(0, 0, 0) = distribution(generator); - eddlat_(0, 0, 0) = distribution(generator); - tau_smag_(0, 0, 0) = distribution(generator); - weight_smag_(0, 0, 0) = distribution(generator); - } - -private: - gridtools::uint_t isize_, jsize_, ksize_; - - // Meta-data - metadata_scalar_t metadata_scalar_; - metadata_j_t metadata_j_; - metadata_ijk_t metadata_ijk_; - - // Output fields - storage_ijk_t u_out_, v_out_; - - // Input fields - storage_ijk_t u_in_, v_in_, hdmaskvel_; - storage_j_t crlavo_, crlavu_, crlato_, crlatu_, acrlat0_; - - // Scalar fields - storage_scalar_t eddlon_, eddlat_, tau_smag_, weight_smag_; -}; - -} // smagorinsky diff --git a/examples/gridtools/smagorinsky/smagorinsky_stencil.hpp b/examples/gridtools/smagorinsky/smagorinsky_stencil.hpp deleted file mode 100644 index e551cfcf..00000000 --- a/examples/gridtools/smagorinsky/smagorinsky_stencil.hpp +++ /dev/null @@ -1,291 +0,0 @@ -//===-- smagorinsky_stencil.hpp -----------------------------------------------------*- C++ -*-===// -// -// S E R I A L B O X -// -// This file is distributed under terms of BSD license. -// See LICENSE.txt for more information -// -//===------------------------------------------------------------------------------------------===// -// -/// \file -/// Define Smagorinsky horizontal diffusion stencil. -/// -//===------------------------------------------------------------------------------------------===// - -#pragma once - -#include "smagorinsky_repository.hpp" -#include - -namespace smagorinsky { - -using namespace gridtools; -using namespace gridtools::enumtype; -using namespace gridtools::expressions; - -constexpr static gridtools::dimension<1> i; -constexpr static gridtools::dimension<2> j; -constexpr static gridtools::dimension<3> k; - -namespace math { -using std::min; -using std::max; -using std::sqrt; -} - -//===------------------------------------------------------------------------------------------===// -// Stage 1 - TensionShearStage -//===------------------------------------------------------------------------------------------===// - -/// \brief Compute the tension and shear used for the Smagorinsky diffusion -struct tension_shear_stage { - using T_sqr_s = inout_accessor<0>; - using S_sqr_uv = inout_accessor<1>; - - using acrlat0 = in_accessor<2>; - using eddlon = in_accessor<3>; - using eddlat = in_accessor<4>; - using u_in = in_accessor<5, extent<-1, 0, 0, 1>>; - using v_in = in_accessor<6, extent<0, 1, -1, 0>>; - - using arg_list = boost::mpl::vector; - - template - GT_FUNCTION static void Do(const Evaluation& eval, full_domain_t) { - const float_type frac_1_dx = eval(acrlat0(i, j, k) * eddlon(i, j, k)); - const float_type frac_1_dy = eval(eddlat(i, j, k)) / float_type(6371.229e3); - - // Tension - const float_type T_s = eval(v_in(i, j - 1, k) - v_in(i, j, k)) * frac_1_dy - - eval(u_in(i - 1, j, k) - u_in(i, j, k)) * frac_1_dx; - eval(T_sqr_s()) = T_s * T_s; - - // Shear - const float_type S_uv = eval(u_in(i, j + 1, k) - u_in(i, j, k)) * frac_1_dy + - eval(v_in(i + 1, j, k) - v_in(i, j, k)) * frac_1_dx; - eval(S_sqr_uv()) = S_uv * S_uv; - } -}; - -//===------------------------------------------------------------------------------------------===// -// Stage 2 - SmagCoeffStage -//===------------------------------------------------------------------------------------------===// - -/// \brief Stage computing the coefficients for the Smagorinsky diffusion -struct smag_coeff_stage { - using smag_u = inout_accessor<0>; - using smag_v = inout_accessor<1>; - - using T_sqr_s = in_accessor<2, extent<0, 1, 0, 1>>; - using S_sqr_uv = in_accessor<3, extent<-1, 0, -1, 0>>; - using hdmaskvel = in_accessor<4>; - using tau_smag = in_accessor<5>; - using weight_smag = in_accessor<6>; - - using arg_list = - boost::mpl::vector; - - template - GT_FUNCTION static void Do(const Evaluation& eval, full_domain_t) { - const float_type hdweight = eval(weight_smag(i, j, k) * hdmaskvel(i, j, k)); - - // i-direction - const float_type smag_u_ = - eval(tau_smag(i, j, k)) * - math::sqrt((float_type)0.5 * (eval(T_sqr_s(i, j, k) + T_sqr_s(i + 1, j, k) + - S_sqr_uv(i, j, k) + S_sqr_uv(i, j - 1, k)))) - - hdweight; - - eval(smag_u()) = math::min((float_type)0.5, math::max((float_type)0.0, smag_u_)); - -// j-direction -#ifdef ERROR - const float_type smag_v_ = - eval(tau_smag(i, j, k)) * - math::sqrt((float_type)0.5 * (eval(T_sqr_s(i, j, k) + T_sqr_s(i, j + 1, k) + - S_sqr_uv(i, j, k) + S_sqr_uv(i - 1, j, k)))) + // <-- - hdweight; -#else - const float_type smag_v_ = - eval(tau_smag(i, j, k)) * - math::sqrt((float_type)0.5 * (eval(T_sqr_s(i, j, k) + T_sqr_s(i, j + 1, k) + - S_sqr_uv(i, j, k) + S_sqr_uv(i - 1, j, k)))) - - hdweight; -#endif - - eval(smag_v()) = math::min((float_type)0.5, math::max((float_type)0.0, smag_v_)); - } -}; - -//===------------------------------------------------------------------------------------------===// -// Stage 3 - SmagUpdateStage -//===------------------------------------------------------------------------------------------===// - -/// \brief Function computing the the Laplacian of an input array -struct laplacian { - using lap = inout_accessor<0>; - using in = in_accessor<1, extent<-1, 1, -1, 1>>; - using crlato = in_accessor<2>; - using crlatu = in_accessor<3>; - - using arg_list = boost::mpl::vector; - - template - GT_FUNCTION static void Do(const Evaluation& eval, full_domain_t) { - eval(lap()) = eval(in(i + 1, j, k)) + eval(in(i - 1, j, k)) - - (float_type)2.0 * eval(in(i, j, k)) + - eval(crlato(i, j) * (in(i, j + 1, k) - in(i, j, k))) + - eval(crlatu(i, j) * (in(i, j - 1, k) - in(i, j, k))); - } -}; - -/// \brief Stage updating the horizontal velocities using the Smagorinsy coefficients -struct smag_update_stage { - using u_out = inout_accessor<0>; - using v_out = inout_accessor<1>; - - using u_in = in_accessor<2, extent<-1, 1, -1, 1>>; - using v_in = in_accessor<3, extent<-1, 1, -1, 1>>; - using smag_u = in_accessor<4>; - using smag_v = in_accessor<5>; - using crlato = in_accessor<6>; - using crlatu = in_accessor<7>; - using crlavo = in_accessor<8>; - using crlavu = in_accessor<9>; - - using arg_list = - boost::mpl::vector; - - template - GT_FUNCTION static void Do(const Evaluation& eval, full_domain_t) { - const float_type lapu = - call::at<0, 0, 0>::with(eval, u_in(), crlato(), crlatu()); - - const float_type lapv = - call::at<0, 0, 0>::with(eval, v_in(), crlavo(), crlavu()); - - eval(u_out()) = eval(u_in(i, j, k)) + eval(smag_u(i, j, k)) * lapu; - eval(v_out()) = eval(v_in(i, j, k)) - eval(smag_v(i, j, k)) * lapv; - } -}; - -//===------------------------------------------------------------------------------------------===// -// Stencil -//===------------------------------------------------------------------------------------------===// - -/// \brief Smagorninsky stencil -template -void run_stencil(repository& repo, SerializerType& serializer, int invocation_count = 1) { - - // - // Argument list - // - - // Temporaries - using T_sqr_s = arg<0, repository::storage_ijk_tmp_t>; - using S_sqr_uv = arg<1, repository::storage_ijk_tmp_t>; - using smag_u = arg<2, repository::storage_ijk_tmp_t>; - using smag_v = arg<3, repository::storage_ijk_tmp_t>; - - // Output fields - using u_out = arg<4, repository::storage_ijk_t>; - using v_out = arg<5, repository::storage_ijk_t>; - - // Input fields - using u_in = arg<6, repository::storage_ijk_t>; - using v_in = arg<7, repository::storage_ijk_t>; - using hdmaskvel = arg<8, repository::storage_ijk_t>; - using crlavo = arg<9, repository::storage_j_t>; - using crlavu = arg<10, repository::storage_j_t>; - using crlato = arg<11, repository::storage_j_t>; - using crlatu = arg<12, repository::storage_j_t>; - using acrlat0 = arg<13, repository::storage_j_t>; - - // Scalar fields - using eddlon = arg<14, repository::storage_scalar_t>; - using eddlat = arg<15, repository::storage_scalar_t>; - using tau_smag = arg<16, repository::storage_scalar_t>; - using weight_smag = arg<17, repository::storage_scalar_t>; - - using arg_list = boost::mpl::vector< - // Temporaries - T_sqr_s, S_sqr_uv, smag_u, smag_v, - - // Output fields - u_out, v_out, - - // Input fields - u_in, v_in, hdmaskvel, crlavo, crlavu, crlato, crlatu, acrlat0, - - // Scalar fields - eddlon, eddlat, tau_smag, weight_smag>; - - // - // Domain - // - - auto domain = aggregator_type(boost::fusion::make_vector( - // Output fields - &repo.u_out(), &repo.v_out(), - - // Input fields - &repo.u_in(), &repo.v_in(), &repo.hdmaskvel(), &repo.crlavo(), &repo.crlavu(), &repo.crlato(), - &repo.crlatu(), &repo.acrlat0(), - - // Scalar fields - &repo.eddlon(), &repo.eddlat(), &repo.tau_smag(), &repo.weight_smag())); - - // - // Grid - // - - const int halo_size = 3; - - // minus, plus, begin, end, length - uint_t di[5] = {halo_size, halo_size, halo_size, repo.isize() - halo_size - 2, - repo.isize() - 2 * halo_size}; - uint_t dj[5] = {halo_size, halo_size, halo_size, repo.jsize() - halo_size - 2, - repo.jsize() - 2 * halo_size}; - - gridtools::grid grid(di, dj); - grid.value_list[0] = 0; - grid.value_list[1] = repo.ksize() - 1; - - // - // Computation - // - - auto computation = make_computation( - domain, grid, - make_multistage(execute(), - - // 1. Stage - Tension shear - make_stage(T_sqr_s(), S_sqr_uv(), acrlat0(), eddlon(), - eddlat(), u_in(), v_in()), - - // 2. Stage - Smagorinsky coefficient - make_stage(smag_u(), smag_v(), T_sqr_s(), S_sqr_uv(), - hdmaskvel(), tau_smag(), weight_smag()), - - // 3. Stage - Update output variable - make_stage(u_out(), v_out(), u_in(), v_in(), smag_u(), - smag_v(), crlato(), crlatu(), crlavo(), - crlavu()))); - - // - // Run stencil - // - - computation->ready(); - computation->steady(); - - std::cout << "Running smagorinsky stencil ... " << std::endl; - for(int i = 0; i < invocation_count; ++i) { - std::cout << "Invocation: " << i << std::endl; - computation->run(serializer, "Smagorinsky"); - } - - computation->finalize(); -} - -} // namespace smagorinsky diff --git a/src/serialbox/core/MetainfoValueImpl.cpp b/src/serialbox/core/MetainfoValueImpl.cpp index 89c14590..942098e5 100644 --- a/src/serialbox/core/MetainfoValueImpl.cpp +++ b/src/serialbox/core/MetainfoValueImpl.cpp @@ -13,19 +13,18 @@ //===------------------------------------------------------------------------------------------===// #include "serialbox/core/MetainfoValueImpl.h" +#include "serialbox/core/Exception.h" #include "serialbox/core/Unreachable.h" #include -#include - namespace serialbox { namespace internal { /// Convert any to type T template -const T& convert(const boost::any& any) noexcept { - return *boost::any_cast(&any); +const T& convert(const std::any& any) noexcept { + return *std::any_cast(&any); } /// Construct T from string @@ -40,10 +39,10 @@ T fromString(StringType&& valueStr) { /// Convert any to primtive T template -T makePrimitiveOf(const boost::any& any, TypeID type); +T makePrimitiveOf(const std::any& any, TypeID type); template <> -bool makePrimitiveOf(const boost::any& any, TypeID type) { +bool makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return convert(any); @@ -64,7 +63,7 @@ bool makePrimitiveOf(const boost::any& any, TypeID type) { } template <> -int makePrimitiveOf(const boost::any& any, TypeID type) { +int makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return (int)convert(any); @@ -93,7 +92,7 @@ int makePrimitiveOf(const boost::any& any, TypeID type) { } template <> -std::int64_t makePrimitiveOf(const boost::any& any, TypeID type) { +std::int64_t makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return (std::int64_t)convert(any); @@ -122,7 +121,7 @@ std::int64_t makePrimitiveOf(const boost::any& any, TypeID type) { } template <> -float makePrimitiveOf(const boost::any& any, TypeID type) { +float makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return (float)convert(any); @@ -143,7 +142,7 @@ float makePrimitiveOf(const boost::any& any, TypeID type) { } template <> -double makePrimitiveOf(const boost::any& any, TypeID type) { +double makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return (double)convert(any); @@ -164,7 +163,7 @@ double makePrimitiveOf(const boost::any& any, TypeID type) { } template <> -std::string makePrimitiveOf(const boost::any& any, TypeID type) { +std::string makePrimitiveOf(const std::any& any, TypeID type) { switch(type) { case TypeID::Boolean: return (convert(any) ? "true" : "false"); @@ -186,7 +185,7 @@ std::string makePrimitiveOf(const boost::any& any, TypeID type) { /// Convert any to array of T template > -ArrayType makeArrayOf(const boost::any& any, TypeID type) { +ArrayType makeArrayOf(const std::any& any, TypeID type) { if(!TypeUtil::isArray(type)) throw Exception("cannot convert non-array [type = %s] to array [T = %s]", TypeUtil::toString(type), TypeUtil::toString(ToTypeID::value)); @@ -197,37 +196,37 @@ ArrayType makeArrayOf(const boost::any& any, TypeID type) { case TypeID::Boolean: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(bool(a)), TypeID::Boolean)); + arrayT.push_back(makePrimitiveOf(std::any(bool(a)), TypeID::Boolean)); break; } case TypeID::Int32: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(int(a)), TypeID::Int32)); + arrayT.push_back(makePrimitiveOf(std::any(int(a)), TypeID::Int32)); break; } case TypeID::Int64: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(std::int64_t(a)), TypeID::Int64)); + arrayT.push_back(makePrimitiveOf(std::any(std::int64_t(a)), TypeID::Int64)); break; } case TypeID::Float32: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(float(a)), TypeID::Float32)); + arrayT.push_back(makePrimitiveOf(std::any(float(a)), TypeID::Float32)); break; } case TypeID::Float64: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(double(a)), TypeID::Float64)); + arrayT.push_back(makePrimitiveOf(std::any(double(a)), TypeID::Float64)); break; } case TypeID::String: { const auto& array = convert>(any); for(const auto& a : array) - arrayT.push_back(makePrimitiveOf(boost::any(std::string(a)), TypeID::String)); + arrayT.push_back(makePrimitiveOf(std::any(std::string(a)), TypeID::String)); break; } default: diff --git a/src/serialbox/core/MetainfoValueImpl.h b/src/serialbox/core/MetainfoValueImpl.h index 18dceac8..2fca8d12 100644 --- a/src/serialbox/core/MetainfoValueImpl.h +++ b/src/serialbox/core/MetainfoValueImpl.h @@ -16,10 +16,8 @@ #define SERIALBOX_CORE_METAINFOVALUEIMPL_H #include "serialbox/core/Array.h" -#include "serialbox/core/Exception.h" #include "serialbox/core/Type.h" -#include -#include +#include #include namespace serialbox { @@ -59,7 +57,7 @@ class MetainfoValueImpl { static_assert(IsSupported::value, "ValueType is not supported"); type_ = ToTypeID::value; - any_ = boost::any(DecayedValueType(value)); + any_ = std::any(DecayedValueType(value)); } explicit MetainfoValueImpl(const char* value) : MetainfoValueImpl(std::string(value)) {} @@ -102,9 +100,9 @@ class MetainfoValueImpl { /// \brief Get TypeID TypeID type() const noexcept { return type_; } - /// \brief Get boost::any - boost::any& any() noexcept { return any_; } - const boost::any& any() const noexcept { return any_; } + /// \brief Get std::any + std::any& any() noexcept { return any_; } + const std::any& any() const noexcept { return any_; } /// \brief Convert to string std::string toString() const; @@ -112,12 +110,12 @@ class MetainfoValueImpl { private: template const T& convert() const noexcept { - return *boost::any_cast(&any_); + return *std::any_cast(&any_); } private: TypeID type_; ///< Type of the data - boost::any any_; ///< Type-erased value of the data + std::any any_; ///< Type-erased value of the data }; template <> diff --git a/src/serialbox/core/SerializerImpl.cpp b/src/serialbox/core/SerializerImpl.cpp index ff7a2b22..38fd8309 100644 --- a/src/serialbox/core/SerializerImpl.cpp +++ b/src/serialbox/core/SerializerImpl.cpp @@ -23,7 +23,6 @@ #include "serialbox/core/archive/ArchiveFactory.h" #include "serialbox/core/archive/BinaryArchive.h" #include "serialbox/core/hash/HashFactory.h" -#include #include #include #include @@ -473,7 +472,7 @@ bool SerializerImpl::upgradeMetaData() { LOG(info) << "Inserting global meta-info: key = " << it.key() << ", value = " << it.value(); std::string key = it.key(); - if(!boost::algorithm::starts_with(key, "__")) { + if(!(key.rfind("__", 0) == 0)) { // replace by starts_with in C++20 if(it.value().is_string()) { std::string value = it.value(); addGlobalMetainfo(key, value); @@ -583,7 +582,7 @@ bool SerializerImpl::upgradeMetaData() { // Add meta-info to savepoint for(auto it = offsetTableEntry.begin(), end = offsetTableEntry.end(); it != end; ++it) { std::string key = it.key(); - if(!boost::algorithm::starts_with(key, "__")) { + if(!(key.rfind("__", 0) == 0)) { // replace by starts_with in C++20 if(it.value().is_string()) { std::string value = it.value(); savepoint.addMetainfo(it.key(), value); diff --git a/src/serialbox/core/archive/BinaryArchive.cpp b/src/serialbox/core/archive/BinaryArchive.cpp index 4374bd62..67b53e8a 100644 --- a/src/serialbox/core/archive/BinaryArchive.cpp +++ b/src/serialbox/core/archive/BinaryArchive.cpp @@ -16,7 +16,6 @@ #include "serialbox/core/Logging.h" #include "serialbox/core/Version.h" #include "serialbox/core/hash/HashFactory.h" -#include #include namespace serialbox { @@ -452,7 +451,8 @@ void BinaryArchive::clear() { std::filesystem::directory_iterator end; for(std::filesystem::directory_iterator it(directory_); it != end; ++it) { if(std::filesystem::is_regular_file(it->path()) && - boost::algorithm::starts_with(it->path().filename().string(), prefix_ + "_") && + (it->path().filename().string().rfind(prefix_ + "_", 0) == 0) && // replace with starts_with + // in C++20 std::filesystem::path(it->path()).extension() == ".dat") { if(!std::filesystem::remove(it->path())) diff --git a/src/serialbox/core/archive/NetCDFArchive.cpp b/src/serialbox/core/archive/NetCDFArchive.cpp index 77d62173..85d76fd8 100644 --- a/src/serialbox/core/archive/NetCDFArchive.cpp +++ b/src/serialbox/core/archive/NetCDFArchive.cpp @@ -19,7 +19,6 @@ #include "serialbox/core/Unreachable.h" #include "serialbox/core/Version.h" #include "serialbox/core/archive/NetCDFArchive.h" -#include #include #include #include @@ -489,7 +488,8 @@ void NetCDFArchive::clear() { std::filesystem::directory_iterator end; for(std::filesystem::directory_iterator it(directory_); it != end; ++it) { if(std::filesystem::is_regular_file(it->path()) && - boost::algorithm::starts_with(it->path().filename().string(), prefix_ + "_") && + (it->path().filename().string().rfind(prefix_ + "_", 0) == + 0) && // replace with starts_with in c++20 std::filesystem::path(it->path()).extension() == ".nc") { if(!std::filesystem::remove(it->path())) diff --git a/test/serialbox/core/UnittestFieldMap.cpp b/test/serialbox/core/UnittestFieldMap.cpp index ef2a68f4..3e6913b9 100644 --- a/test/serialbox/core/UnittestFieldMap.cpp +++ b/test/serialbox/core/UnittestFieldMap.cpp @@ -14,7 +14,6 @@ #include "serialbox/core/FieldMap.h" #include "serialbox/core/FieldMapSerializer.h" -#include #include using namespace serialbox; @@ -295,7 +294,7 @@ TEST(FieldMapTest, toString) { std::stringstream ss; ss << map; - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "FieldMap")); + EXPECT_TRUE(ss.str().rfind("FieldMap", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("field1"), std::string::npos); EXPECT_NE(ss.str().find("key1"), std::string::npos); EXPECT_NE(ss.str().find("key2"), std::string::npos); diff --git a/test/serialbox/core/UnittestFieldMetainfoImpl.cpp b/test/serialbox/core/UnittestFieldMetainfoImpl.cpp index 6224ff1d..0d7adac1 100644 --- a/test/serialbox/core/UnittestFieldMetainfoImpl.cpp +++ b/test/serialbox/core/UnittestFieldMetainfoImpl.cpp @@ -15,7 +15,6 @@ #include "serialbox/core/FieldMetainfoImpl.h" #include "serialbox/core/FieldMetainfoImplSerializer.h" -#include #include using nlohmann::basic_json; diff --git a/test/serialbox/core/UnittestMetainfoMapImpl.cpp b/test/serialbox/core/UnittestMetainfoMapImpl.cpp index 55de024d..299e42fe 100644 --- a/test/serialbox/core/UnittestMetainfoMapImpl.cpp +++ b/test/serialbox/core/UnittestMetainfoMapImpl.cpp @@ -15,7 +15,6 @@ #include "serialbox/core/MetainfoMapImpl.h" #include "serialbox/core/MetainfoMapImplSerializer.h" -#include #include using namespace serialbox; @@ -85,7 +84,7 @@ TEST(MetainfoMapImplTest, Construction) { ASSERT_TRUE(map2.empty()); // Iterate values - std::vector anyvec; + std::vector anyvec; for(const auto& map_element : map) anyvec.push_back(map_element.second.any()); EXPECT_EQ(anyvec.size(), map.size()); diff --git a/test/serialbox/core/UnittestMetainfoValueImpl.cpp b/test/serialbox/core/UnittestMetainfoValueImpl.cpp index 589dd376..57e3e511 100644 --- a/test/serialbox/core/UnittestMetainfoValueImpl.cpp +++ b/test/serialbox/core/UnittestMetainfoValueImpl.cpp @@ -12,6 +12,7 @@ /// //===------------------------------------------------------------------------------------------===// +#include "serialbox/core/Exception.h" #include "serialbox/core/MetainfoValueImpl.h" #include #include diff --git a/test/serialbox/core/UnittestSavepointImpl.cpp b/test/serialbox/core/UnittestSavepointImpl.cpp index 51c0d682..3451ff66 100644 --- a/test/serialbox/core/UnittestSavepointImpl.cpp +++ b/test/serialbox/core/UnittestSavepointImpl.cpp @@ -14,7 +14,6 @@ #include "serialbox/core/SavepointImpl.h" #include "serialbox/core/SavepointImplSerializer.h" -#include #include #include diff --git a/test/serialbox/core/UnittestSavepointVector.cpp b/test/serialbox/core/UnittestSavepointVector.cpp index 74047750..3097b83f 100644 --- a/test/serialbox/core/UnittestSavepointVector.cpp +++ b/test/serialbox/core/UnittestSavepointVector.cpp @@ -14,7 +14,6 @@ #include "serialbox/core/SavepointVector.h" #include "serialbox/core/SavepointVectorSerializer.h" -#include #include using namespace serialbox; @@ -386,7 +385,7 @@ TEST(SavepointVectorTest, toString) { ASSERT_TRUE(s.addField(savepoint1, FieldID{"u", 0})); ss << s; - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "SavepointVector")); + EXPECT_TRUE(ss.str().rfind("SavepointVector", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("savepoint"), std::string::npos); EXPECT_NE(ss.str().find("key1"), std::string::npos); } diff --git a/test/serialbox/core/UnittestStorageView.cpp b/test/serialbox/core/UnittestStorageView.cpp index b0af7e0d..d0a3e9ef 100644 --- a/test/serialbox/core/UnittestStorageView.cpp +++ b/test/serialbox/core/UnittestStorageView.cpp @@ -16,7 +16,6 @@ #include "serialbox/core/StorageView.h" #include "serialbox/core/Type.h" #include "utility/Storage.h" -#include #include #include #include @@ -387,7 +386,7 @@ TYPED_TEST(StorageViewTest, toString) { // StorageView ss << sv_1d; - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "StorageView")); + EXPECT_TRUE(ss.str().rfind("StorageView", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("originPtr"), std::string::npos); EXPECT_NE(ss.str().find("type"), std::string::npos); EXPECT_NE(ss.str().find("dims"), std::string::npos); @@ -397,7 +396,7 @@ TYPED_TEST(StorageViewTest, toString) { // StorageViewIterator ss << sv_1d.begin(); - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "StorageViewIterator")); + EXPECT_TRUE(ss.str().rfind("StorageViewIterator", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("originPtr"), std::string::npos); EXPECT_NE(ss.str().find("index"), std::string::npos); EXPECT_NE(ss.str().find("end"), std::string::npos); diff --git a/test/serialbox/core/archive/UnittestBinaryArchive.cpp b/test/serialbox/core/archive/UnittestBinaryArchive.cpp index 78420ecc..322dfce8 100644 --- a/test/serialbox/core/archive/UnittestBinaryArchive.cpp +++ b/test/serialbox/core/archive/UnittestBinaryArchive.cpp @@ -16,7 +16,6 @@ #include "serialbox/core/archive/BinaryArchive.h" #include "utility/SerializerTestBase.h" #include "utility/Storage.h" -#include #include using namespace serialbox; @@ -174,7 +173,7 @@ TEST_F(BinaryArchiveUtilityTest, toString) { archive.write(sv, "storage", nullptr); ss << archive; - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "BinaryArchive")); + EXPECT_TRUE(ss.str().rfind("BinaryArchive", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("directory"), std::string::npos); EXPECT_NE(ss.str().find("mode"), std::string::npos); EXPECT_NE(ss.str().find("prefix"), std::string::npos); diff --git a/test/serialbox/core/archive/UnittestNetCDFArchive.cpp b/test/serialbox/core/archive/UnittestNetCDFArchive.cpp index 327eb270..9ccc070f 100644 --- a/test/serialbox/core/archive/UnittestNetCDFArchive.cpp +++ b/test/serialbox/core/archive/UnittestNetCDFArchive.cpp @@ -45,7 +45,7 @@ TEST_F(NetCDFArchiveUtilityTest, Construction) { NetCDFArchive b(OpenModeKind::Write, this->directory->path().string(), "field"); b.updateMetaData(); - EXPECT_TRUE(boost::algorithm::starts_with(b.name(), "NetCDF")); + EXPECT_TRUE(b.name().rfind("NetCDF", 0) == 0); // replace by starts_with in C++20 EXPECT_EQ(b.mode(), OpenModeKind::Write); EXPECT_EQ(b.prefix(), "field"); } @@ -177,7 +177,7 @@ TEST_F(NetCDFArchiveUtilityTest, toString) { ss << archive; - EXPECT_TRUE(boost::algorithm::starts_with(ss.str(), "NetCDFArchive")); + EXPECT_TRUE(ss.str().rfind("NetCDFArchive", 0) == 0); // replace by starts_with in C++20 EXPECT_NE(ss.str().find("directory"), std::string::npos); EXPECT_NE(ss.str().find("mode"), std::string::npos); EXPECT_NE(ss.str().find("prefix"), std::string::npos); diff --git a/test/serialbox/core/frontend/gridtools/UnittestMetainfoMap.cpp b/test/serialbox/core/frontend/gridtools/UnittestMetainfoMap.cpp index 2cf50bef..3ad5d4cd 100644 --- a/test/serialbox/core/frontend/gridtools/UnittestMetainfoMap.cpp +++ b/test/serialbox/core/frontend/gridtools/UnittestMetainfoMap.cpp @@ -80,7 +80,7 @@ TEST(GridToolsMetainfoMapTest, Construction) { ASSERT_TRUE(map1.empty()); // Iterate values - std::vector anyvec; + std::vector anyvec; for(const auto& map_element : map1) anyvec.push_back(map_element.second.any()); EXPECT_EQ(anyvec.size(), map1.size()); From 9007ac3c53498fbc8eb246e2f8912fea918d1854 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 18 Nov 2024 16:58:17 +0100 Subject: [PATCH 3/5] delete some outdated files --- tools/cscs-scripts/env_kesch-test.sh | 111 -------------------------- tools/cscs-scripts/env_kesch.sh | 105 ------------------------ tools/cscs-scripts/env_tave.sh | 99 ----------------------- tools/cscs-scripts/env_tsa.sh | 93 --------------------- tools/cscs-scripts/submit.kesch.slurm | 92 --------------------- 5 files changed, 500 deletions(-) delete mode 100644 tools/cscs-scripts/env_kesch-test.sh delete mode 100644 tools/cscs-scripts/env_kesch.sh delete mode 100644 tools/cscs-scripts/env_tave.sh delete mode 100755 tools/cscs-scripts/env_tsa.sh delete mode 100644 tools/cscs-scripts/submit.kesch.slurm diff --git a/tools/cscs-scripts/env_kesch-test.sh b/tools/cscs-scripts/env_kesch-test.sh deleted file mode 100644 index 086a513f..00000000 --- a/tools/cscs-scripts/env_kesch-test.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash -##===-----------------------------------------------------------*- bash -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===----------------------------------------------------------------------===## - -## Print help statement and exit. -print_help() -{ - printf "Usage: $0 [options]\n\n" - printf "Options:\n" - - # --fc-compiler - printf " %-35s %s\n" \ - "-f, --fc-compiler FORTRAN_COMPILER" \ - "Fortran compiler to use (set to " - printf " %-35s %s\n" "" "environment variable FC)." - - # --help - printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\n" - exit 0 -} - -## Convert to lower case and remove all whitespaces -to_lower_and_trim() -{ - if [ $# -ne 1 ]; then - echo "$0: internal error." ; exit 1 - fi - - local to_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') - local trim_whitespaces=${to_lower// /} - echo "${trim_whitespaces}" -} - -#------------------------------ Parse options ---------------------------------- -ENV_ARGS=$(getopt -o f:h:: -l fc-compiler,help:: -n 'env_kesch' -- "$@"); - -if [ $? -ne 0 ]; then - exit 1 -fi - -eval set -- "$ENV_ARGS" - -while true; do - case "$1" in - -h|--h*) print_help; exit 0;; - -f|--fc-compiler) ARG_FC_COMPILER=$(to_lower_and_trim $2); shift 2;; - --) shift; break ;; - *) echo "$0: internal error." ; exit 1 ;; - esac -done - -# Fortran Compiler -if [ -z ${ARG_FC_COMPILER+x} ]; then - echo "$0: error: fortran compiler is not set" - exit 1 -else - FC_COMPILER=${ARG_FC_COMPILER} -fi - -#------------------------------ Set environment -------------------------------- - -module purge -module load cmake/3.9.1 - -if [ "$FC_COMPILER" = "pgfortran" ]; then - -module unuse /apps/escha/UES/generic/modulefiles:/apps/escha/UES/PrgEnv-gnu-17.02/modulefiles:/apps/escha/UES/PrgEnv-cray-17.06/modulefiles:/apps/escha/UES/experimental/modulefiles -module use /apps/escha/UES/jenkins/RH7.4/gnu_PE17.02/easybuild/modules/all -module use /apps/escha/UES/jenkins/RH7.4/generic/easybuild/modules/all -module use /apps/escha/UES/jenkins/RH7.4/cray_PE17.06/easybuild/modules/all - - module load craype-haswell - module load craype-accel-nvidia35 - module switch mvapich2_cce/2.2rc1.0.3_cuda80 mvapich2gdr_gnu/2.2_cuda_8.0 - module load PrgEnv-pgi/17.10 - module load gcc/5.4.0-2.26 - -elif [ "$FC_COMPILER" = "ftn" ]; then -module unuse /apps/escha/UES/generic/modulefiles:/apps/escha/UES/PrgEnv-gnu-17.02/modulefiles:/apps/escha/UES/PrgEnv-cray-17.06/modulefiles:/apps/escha/UES/experimental/modulefiles -module use /apps/escha/UES/jenkins/RH7.4/gnu_PE17.02/easybuild/modules/all -module use /apps/escha/UES/jenkins/RH7.4/generic/easybuild/modules/all -module use /apps/escha/UES/jenkins/RH7.4/cray_PE17.06/easybuild/modules/all - - module load craype-haswell - module load PrgEnv-cray - module load craype-accel-nvidia35 - module load craype-network-infiniband - module switch mvapich2_cce/2.2rc1.0.3_cuda80 mvapich2gdr_gnu/2.2_cuda_8.0 - module load gcc/5.4.0-2.26 - export GCC_X86_64=$EBROOTGCCCORE -else - module load PrgEnv-gnu -fi - -export CXX=$(which g++) -export CC=$(which gcc) -export FC=$(which $FC_COMPILER) - -export Boost_NO_SYSTEM_PATHS=true -export Boost_NO_BOOST_CMAKE=true - -export BOOST_ROOT=/project/c14/install/kesch/boost/boost_1_67_0/ -export BOOST_INCLUDE={BOOST_ROOT}/include/ - diff --git a/tools/cscs-scripts/env_kesch.sh b/tools/cscs-scripts/env_kesch.sh deleted file mode 100644 index d309d229..00000000 --- a/tools/cscs-scripts/env_kesch.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash -##===-----------------------------------------------------------*- bash -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===----------------------------------------------------------------------===## - -## Print help statement and exit. -print_help() -{ - printf "Usage: $0 [options]\n\n" - printf "Options:\n" - - # --fc-compiler - printf " %-35s %s\n" \ - "-f, --fc-compiler FORTRAN_COMPILER" \ - "Fortran compiler to use (set to " - printf " %-35s %s\n" "" "environment variable FC)." - - # --help - printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\n" - exit 0 -} - -## Convert to lower case and remove all whitespaces -to_lower_and_trim() -{ - if [ $# -ne 1 ]; then - echo "$0: internal error." ; exit 1 - fi - - local to_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') - local trim_whitespaces=${to_lower// /} - echo "${trim_whitespaces}" -} - -#------------------------------ Parse options ---------------------------------- -ENV_ARGS=$(getopt -o f:h:: -l fc-compiler,help:: -n 'env_kesch' -- "$@"); - -if [ $? -ne 0 ]; then - exit 1 -fi - -eval set -- "$ENV_ARGS" - -while true; do - case "$1" in - -h|--h*) print_help; exit 0;; - -f|--fc-compiler) ARG_FC_COMPILER=$(to_lower_and_trim $2); shift 2;; - --) shift; break ;; - *) echo "$0: internal error." ; exit 1 ;; - esac -done - -# Fortran Compiler -if [ -z ${ARG_FC_COMPILER+x} ]; then - echo "$0: error: fortran compiler is not set" - exit 1 -else - FC_COMPILER=${ARG_FC_COMPILER} -fi - -#------------------------------ Set environment -------------------------------- - -module purge - -module load PE/17.06 -module load craype-network-infiniband -module load craype-haswell -module load cmake/3.13.4 -module load python/3.6.2-gmvolf-17.02 - -if [ "$FC_COMPILER" = "pgfortran" ]; then - module load PrgEnv-pgi/18.5 - module load netcdf-fortran/4.4.4-pgi-18.5-gcc-5.4.0-2.26 - export NETCDF_ROOT=$EBROOTNETCDF - module load gcc/5.4.0-2.26 - -elif [ "$FC_COMPILER" = "ftn" ]; then - module unload mvapich2/2.2-gcc-5.4.0-2.26 - module load PrgEnv-CrayCCE/17.06 - module load gcc/5.4.0-2.26 - module load netCDF-Fortran/4.4.4-CrayCCE-17.06 - export NETCDF_ROOT=$EBROOTNETCDF - export GCC_X86_64=$EBROOTGCCCORE -else - module load PrgEnv-gnu/17.02 - module load netcdf-fortran/4.4.4-gmvolf-17.02 - export NETCDF_ROOT=$EBROOTNETCDF -fi - -export CXX=$(which g++) -export CC=$(which gcc) -export FC=$(which $FC_COMPILER) - -export Boost_NO_SYSTEM_PATHS=true -export Boost_NO_BOOST_CMAKE=true - -export BOOST_ROOT=/project/c14/install/kesch/boost/boost_1_67_0/ -export BOOST_INCLUDE={BOOST_ROOT}/include/ - diff --git a/tools/cscs-scripts/env_tave.sh b/tools/cscs-scripts/env_tave.sh deleted file mode 100644 index 61deb20a..00000000 --- a/tools/cscs-scripts/env_tave.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash -##===-----------------------------------------------------------*- bash -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===----------------------------------------------------------------------===## - -## Print help statement and exit. -print_help() -{ - printf "Usage: $0 [options]\n\n" - printf "Options:\n" - - # --fc-compiler - printf " %-35s %s\n" \ - "-f, --fc-compiler FORTRAN_COMPILER" \ - "Fortran compiler to use (set to " - printf " %-35s %s\n" "" "environment variable FC)." - - # --help - printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\n" - exit 0 -} - -## Convert to lower case and remove all whitespaces -to_lower_and_trim() -{ - if [ $# -ne 1 ]; then - echo "$0: internal error." ; exit 1 - fi - - local to_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') - local trim_whitespaces=${to_lower// /} - echo "${trim_whitespaces}" -} - -#------------------------------ Parse options ---------------------------------- -ENV_ARGS=$(getopt -o f:h:: -l fc-compiler,help:: -n 'env_kesch' -- "$@"); - -if [ $? -ne 0 ]; then - exit 1 -fi - -eval set -- "$ENV_ARGS" - -while true; do - case "$1" in - -h|--h*) print_help; exit 0;; - -f|--fc-compiler) ARG_FC_COMPILER=$(to_lower_and_trim $2); shift 2;; - --) shift; break ;; - *) echo "$0: internal error." ; exit 1 ;; - esac -done - -# Fortran Compiler -if [ -z ${ARG_FC_COMPILER+x} ]; then - echo "$0: error: fortran compiler is not set" - exit 1 -else - FC_COMPILER=${ARG_FC_COMPILER} -fi - -#------------------------------ Set environment -------------------------------- - -module use /users/jenkins/easybuild/tave/modules/all -module load CMake/3.12.0 - -if [ "$FC_COMPILER" = "pgfortran" ]; then - module rm PrgEnv-cray - module load PrgEnv-pgi - module load gcc -elif [ "$FC_COMPILER" = "ftn" ]; then - module load gcc -elif [ "$FC_COMPILER" = "ifort" ]; then - module swap PrgEnv-cray PrgEnv-intel - module load gcc -else - module rm PrgEnv-cray - module load PrgEnv-gnu -fi - -module load cray-netcdf -export NETCDF_ROOT=${NETCDF_DIR} - -export CXX=$(which g++) -export CC=$(which gcc) -export FC=$(which $FC_COMPILER) - -export Boost_NO_SYSTEM_PATHS=true -export Boost_NO_BOOST_CMAKE=true - -export BOOST_ROOT=/project/c14/install/daint/boost/boost_1_67_0 -export BOOST_INCLUDE={BOOST_ROOT}/include/ -export LD_LIBRARY_PATH=${BOOST_ROOT}/lib:$LD_LIBRARY_PATH - diff --git a/tools/cscs-scripts/env_tsa.sh b/tools/cscs-scripts/env_tsa.sh deleted file mode 100755 index 12c97311..00000000 --- a/tools/cscs-scripts/env_tsa.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash -##===-----------------------------------------------------------*- bash -*-===## -## -## S E R I A L B O X -## -## This file is distributed under terms of BSD license. -## See LICENSE.txt for more information. -## -##===----------------------------------------------------------------------===## - -## Print help statement and exit. -print_help() -{ - printf "Usage: $0 [options]\n\n" - printf "Options:\n" - - # --fc-compiler - printf " %-35s %s\n" \ - "-f, --fc-compiler FORTRAN_COMPILER" \ - "Fortran compiler to use (set to " - printf " %-35s %s\n" "" "environment variable FC)." - - # --help - printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\n" - exit 0 -} - -## Convert to lower case and remove all whitespaces -to_lower_and_trim() -{ - if [ $# -ne 1 ]; then - echo "$0: internal error." ; exit 1 - fi - - local to_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') - local trim_whitespaces=${to_lower// /} - echo "${trim_whitespaces}" -} - -#------------------------------ Parse options ---------------------------------- -ENV_ARGS=$(getopt -o f:h:: -l fc-compiler,help:: -n 'env_kesch' -- "$@"); - -if [ $? -ne 0 ]; then - exit 1 -fi - -eval set -- "$ENV_ARGS" - -while true; do - case "$1" in - -h|--h*) print_help; exit 0;; - -f|--fc-compiler) ARG_FC_COMPILER=$(to_lower_and_trim $2); shift 2;; - --) shift; break ;; - *) echo "$0: internal error." ; exit 1 ;; - esac -done - -# Fortran Compiler -if [ -z ${ARG_FC_COMPILER+x} ]; then - echo "$0: error: fortran compiler is not set" - exit 1 -else - FC_COMPILER=${ARG_FC_COMPILER} -fi - -#------------------------------ Set environment -------------------------------- - -module load slurm -module load cmake/3.14.5 - -if [ "$FC_COMPILER" = "pgfortran" ]; then - module load PrgEnv-pgi - module load gcc -elif [ "$FC_COMPILER" = "ftn" ]; then - echo "$FC_COMPILER not available on tsa" - exit 1 -elif [ "$FC_COMPILER" = "ifort" ]; then - echo "$FC_COMPILER not available on tsa" - exit 1 -else - module load PrgEnv-gnu -fi - -export CXX=$(which g++) -export CC=$(which gcc) -export FC=$(which $FC_COMPILER) - -export Boost_NO_SYSTEM_PATHS=true -export Boost_NO_BOOST_CMAKE=true - -export BOOST_ROOT=/apps/tsa/SSL/gridtools/jenkins/boost_1_77_0 - diff --git a/tools/cscs-scripts/submit.kesch.slurm b/tools/cscs-scripts/submit.kesch.slurm deleted file mode 100644 index 65d844d8..00000000 --- a/tools/cscs-scripts/submit.kesch.slurm +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=serialbox-unittest -#SBATCH --nodes=1 -#SBATCH --ntasks=1 -#SBATCH --ntasks-per-node=1 -#SBATCH --ntasks-per-socket=1 -#SBATCH --output=serialbox-unittest.out -#SBATCH --partition=debug -#SBATCH --time=00:2:00 -#SBATCH --cpus-per-task=12 -#SBATCH --distribution block:block - -## Print help statement and exit. -print_help() -{ - printf "Usage: $0 [options]\n\n" - printf "Options:\n" - - # --fc-compiler - printf " %-35s %s\n" \ - "-f, --fc-compiler [gnu|cray|pgi]" \ - "Select Fortran compiler [default: gnu]." - - # --help - printf " %-35s %s\n" "-h, --help" "Print this help statement." - printf "\n" - exit 0 -} - -## Convert to lower case and remove all whitespaces -to_lower_and_trim() -{ - if [ $# -ne 1 ]; then - echo "$0: internal error." ; exit 1 - fi - - local to_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') - local trim_whitespaces=${to_lower// /} - echo "${trim_whitespaces}" -} - -#------------------------------ Parse options ---------------------------------- -ENV_ARGS=$(getopt -o f:h:: -l fc-compiler,help:: -n \ - 'submit.kesch.slurm' -- "$@"); - -if [ $? -ne 0 ]; then - exit 1 -fi - -eval set -- "$ENV_ARGS" - -while true; do - case "$1" in - -h|--h*) print_help; exit 0;; - -f|--fc-compiler) ARG_FC_COMPILER=$(to_lower_and_trim $2); shift 2;; - --) shift; break ;; - *) echo "$0: internal error." ; exit 1 ;; - esac -done - -# Fortran Compiler -if [ "${ARG_FC_COMPILER}" = "cray" ]; then - printf "%-20s: %s\n" "Fortran compiler" "cray" - FC_COMPILER="ftn" -elif [ "${ARG_FC_COMPILER}" = "pgi" ]; then - printf "%-20s: %s\n" "Fortran compiler" "pgi" - FC_COMPILER="pgfortran" -else - printf "%-20s: %s\n" "Fortran compiler" "gnu" - FC_COMPILER="gfortran" -fi - -#------------------------------ Load environment ------------------------------- - -CURRENT_PATH=$(pwd) - -# Load environment -source ${CURRENT_PATH}/env_kesch.sh -f ${FC_COMPILER} - -#------------------------------ Run -------------------------------------------- - -RUN_SCRIPT=${CURRENT_PATH}/../../build_gcc_${ARG_FC_COMPILER}/run_tests.sh - -printf "%-10s: %s\n" "Host" "$HOSTNAME" -printf "%-10s: %s\n" "Device" "CPU" -echo "---------------------------------------------" - -srun -n 1 bash ${RUN_SCRIPT} - -echo "---------------------------------------------" -echo "Parallel execution finished." - From 7879af150cd00db57f447696a5af19d8202f4bde Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 18 Nov 2024 17:11:37 +0100 Subject: [PATCH 4/5] undo re-formatting of python files --- src/serialbox-python/pp_ser/pp_ser.py | 1053 +++++++----------- src/serialbox-python/serialbox/serializer.py | 404 +++---- 2 files changed, 540 insertions(+), 917 deletions(-) diff --git a/src/serialbox-python/pp_ser/pp_ser.py b/src/serialbox-python/pp_ser/pp_ser.py index 2aba04ed..5dd297bc 100755 --- a/src/serialbox-python/pp_ser/pp_ser.py +++ b/src/serialbox-python/pp_ser/pp_ser.py @@ -39,23 +39,23 @@ """ # information -__author__ = "Oliver Fuhrer" -__copyright__ = "Copyright 2014, MeteoSwiss" -__license__ = "GPL" -__version__ = "0.1" -__date__ = "Sun Mar 23 22:06:44 2014" -__email__ = "oliver.fuhrer@meteoswiss.ch" +__author__ = 'Oliver Fuhrer' +__copyright__ = 'Copyright 2014, MeteoSwiss' +__license__ = 'GPL' +__version__ = '0.1' +__date__ = 'Sun Mar 23 22:06:44 2014' +__email__ = 'oliver.fuhrer@meteoswiss.ch' def to_ascii(text): if sys.version_info[0] == 3: - return bytes(text, "ascii") + return bytes(text, 'ascii') else: return str(text) def filter_fortran(f): - return f.split(".")[-1].lower() in ["f90", "inc", "incf", "f", "f03"] + return (f.split('.')[-1].lower() in ['f90', 'inc', 'incf', 'f', 'f03']) def build_tree(src, dest, filtered_list, file_filter): @@ -63,265 +63,237 @@ def build_tree(src, dest, filtered_list, file_filter): if not os.path.isdir(dest): os.makedirs(dest) files = os.listdir(src) - filtered_list.extend( - [ - os.path.join(src, f) - for f in files - if os.path.isfile(os.path.join(src, f)) and file_filter(f) - ] - ) + filtered_list.extend([os.path.join(src, f) for f in files if os.path.isfile(os.path.join(src, f)) and file_filter(f)]) dirs = [f for f in files if os.path.isdir(os.path.join(src, f))] for d in dirs: - build_tree( - os.path.join(src, d), os.path.join(dest, d), filtered_list, file_filter - ) + build_tree(os.path.join(src, d), os.path.join(dest, d), filtered_list, file_filter) else: if os.path.isfile(src) and file_filter(src): filtered_list.append(src) class PpSer: - def __init__( - self, - infile, - outfile="", - ifdef="SERIALIZE", - real="ireals", - module="m_serialize", - identical=True, - verbose=False, - acc_prefix=True, - acc_if="", - modules="", - sp_as_var=False, - ): + + def __init__(self, infile, outfile='', ifdef='SERIALIZE', real='ireals', + module='m_serialize', identical=True, verbose=False, + acc_prefix=True, acc_if='', modules='', sp_as_var=False): + # public variables self.verbose = verbose - self.infile = infile # input file - self.outfile = outfile # output file - self.ifdef = ifdef # write #ifdef/#endif blocks - self.real = real # name of real type (Fortran) - self.module = ( - module # name of Fortran module which contains serialization methods - ) - self.identical = identical # write identical files (no preprocessing done)? + self.infile = infile # input file + self.outfile = outfile # output file + self.ifdef = ifdef # write #ifdef/#endif blocks + self.real = real # name of real type (Fortran) + self.module = module # name of Fortran module which contains serialization methods + self.identical = identical # write identical files (no preprocessing done)? self.acc_prefix = acc_prefix # generate preprocessing marco for ACC_PREFIX - self.acc_if = acc_if # generate IF clause after OpenACC update - self.sp_as_var = ( - sp_as_var # Syntax for savepoints using variable instead of string - ) + self.acc_if = acc_if # generate IF clause after OpenACC update + self.sp_as_var = sp_as_var # Syntax for savepoints using variable instead of string # setup (also public) self.methods = { - "mode": "ppser_set_mode", - "getmode": "ppser_get_mode", - "init": "ppser_initialize", - "cleanup": "ppser_finalize", - "data": "fs_write_field", - "datawrite": "fs_write_field", - "dataread": "fs_read_field", - "datareadperturb": "fs_read_field", - "datakbuff": "fs_write_kbuff", - "option": "fs_Option", - "serinfo": "fs_add_serializer_metainfo", - "register": "fs_register_field", - "registertracers": "fs_RegisterAllTracers", - "fieldmetainfo": "fs_AddFieldMetaInfo", - "savepoint": "fs_create_savepoint", - "spinfo": "fs_add_savepoint_metainfo", - "fieldinfo": "fs_add_field_metainfo", - "on": "fs_enable_serialization", - "off": "fs_disable_serialization", + 'mode': 'ppser_set_mode', + 'getmode': 'ppser_get_mode', + 'init': 'ppser_initialize', + 'cleanup': 'ppser_finalize', + 'data': 'fs_write_field', + 'datawrite': 'fs_write_field', + 'dataread': 'fs_read_field', + 'datareadperturb': 'fs_read_field', + 'datakbuff': 'fs_write_kbuff', + 'option': 'fs_Option', + 'serinfo': 'fs_add_serializer_metainfo', + 'register': 'fs_register_field', + 'registertracers': 'fs_RegisterAllTracers', + 'fieldmetainfo': 'fs_AddFieldMetaInfo', + 'savepoint': 'fs_create_savepoint', + 'spinfo': 'fs_add_savepoint_metainfo', + 'fieldinfo': 'fs_add_field_metainfo', + 'on': 'fs_enable_serialization', + 'off': 'fs_disable_serialization' } # language definition (also public) self.language = { - "cleanup": ["CLEANUP", "CLE"], - "data": ["DATA", "DAT"], - "data_kbuff": ["DATA_KBUFF", "KBU"], - "accdata": ["ACCDATA", "ACC"], - "mode": ["MODE", "MOD"], - "init": ["INIT", "INI"], - "option": ["OPTION", "OPT"], - "metainfo": ["METAINFO"], - "verbatim": ["VERBATIM", "VER"], - "register": ["REGISTER", "REG"], - "registertracers": ["REGISTERTRACERS"], - "zero": ["ZERO", "ZER"], - "savepoint": ["SAVEPOINT", "SAV"], - "tracer": ["TRACER", "TRA"], - "on": ["ON"], - "off": ["OFF"], + 'cleanup': ['CLEANUP', 'CLE'], + 'data': ['DATA', 'DAT'], + 'data_kbuff': ['DATA_KBUFF', 'KBU'], + 'accdata': ['ACCDATA', 'ACC'], + 'mode': ['MODE', 'MOD'], + 'init': ['INIT', 'INI'], + 'option': ['OPTION', 'OPT'], + 'metainfo': ['METAINFO'], + 'verbatim': ['VERBATIM', 'VER'], + 'register': ['REGISTER', 'REG'], + 'registertracers': ['REGISTERTRACERS'], + 'zero': ['ZERO', 'ZER'], + 'savepoint': ['SAVEPOINT', 'SAV'], + 'tracer': ['TRACER', 'TRA'], + 'on': ['ON'], + 'off': ['OFF'] } # If you change any of these, please check equivalent parameters in # serialbox-fortran/utils_ppser.f90 - self.modes = {"write": 0, "read": 1, "read-perturb": 2, "CPU": 0, "GPU": 1} + self.modes = { + 'write': 0, + 'read': 1, + 'read-perturb': 2, + 'CPU': 0, + 'GPU': 1 + } self.intentin_to_remove = [] self.intentin_removed = [] # private variables - self.__ser = False # currently processing !$SER directives - self.__line = "" # current line - self.__linenum = 0 # current line number - self.__module = "" # current module - self.__calls = set() # calls to serialization module - self.__outputBuffer = "" # preprocessed file + self.__ser = False # currently processing !$SER directives + self.__line = '' # current line + self.__linenum = 0 # current line number + self.__module = '' # current module + self.__calls = set() # calls to serialization module + self.__outputBuffer = '' # preprocessed file self.__use_stmt_in_module = False # USE statement was inserted in module - self.__extra_module = [] # extra module to add to use statement + self.__extra_module = [] # extra module to add to use statement self.__skip_next_n_lines = 0 # Number of line to skip (use for lookahead) if modules: - self.__extra_module = modules.split(",") + self.__extra_module = modules.split(',') # define compute sign used in field definition. If one is matched, # the read call is not added - self.__computed_fields_sign = ["*", "+", "-", "/", "merge"] + self.__computed_fields_sign = ['*', '+', '-', '/', 'merge'] # shortcuts for field registering def __reg_shortcuts(self, shortcut): shortcut = shortcut.upper() l = [] - if re.match("(^$|[IJK][IJK1-9]*)", shortcut): - if shortcut == "": - l = "1 0 0 0 0 0 0 0 0 0 0 0".split() - elif shortcut == "I": - l = "ie 0 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() - elif shortcut == "J": - l = "je 0 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() - elif shortcut == "J2": - l = "je 2 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() - elif shortcut == "K": - l = "ke 0 0 0 0 0 0 0 0 0 0 0".split() - elif shortcut == "K1": - l = "ke1 0 0 0 0 1 0 0 0 0 0 0".split() - elif shortcut == "IJ": - l = "ie je 0 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() - elif shortcut == "IJ3": - l = "ie je 3 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() - elif shortcut == "IK": - l = "ie ke 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() - elif shortcut == "IK1": - l = "ie ke1 0 0 nboundlines nboundlines 0 0 0 1 0 0".split() - elif shortcut == "JK": - l = "je ke 0 0 nboundlines nboundlines 0 0 0 0 0 0".split() - elif shortcut == "JK1": - l = "je ke1 0 0 nboundlines nboundlines 0 1 0 0 0 0".split() - elif shortcut == "IJK": - l = "ie je ke 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0".split() - elif shortcut == "IJK1": - l = "ie je ke1 0 nboundlines nboundlines nboundlines nboundlines 0 1 0 0".split() + if re.match('(^$|[IJK][IJK1-9]*)', shortcut): + if shortcut == '': + l = '1 0 0 0 0 0 0 0 0 0 0 0'.split() + elif shortcut == 'I': + l = 'ie 0 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() + elif shortcut == 'J': + l = 'je 0 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() + elif shortcut == 'J2': + l = 'je 2 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() + elif shortcut == 'K': + l = 'ke 0 0 0 0 0 0 0 0 0 0 0'.split() + elif shortcut == 'K1': + l = 'ke1 0 0 0 0 1 0 0 0 0 0 0'.split() + elif shortcut == 'IJ': + l = 'ie je 0 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() + elif shortcut == 'IJ3': + l = 'ie je 3 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() + elif shortcut == 'IK': + l = 'ie ke 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() + elif shortcut == 'IK1': + l = 'ie ke1 0 0 nboundlines nboundlines 0 0 0 1 0 0'.split() + elif shortcut == 'JK': + l = 'je ke 0 0 nboundlines nboundlines 0 0 0 0 0 0'.split() + elif shortcut == 'JK1': + l = 'je ke1 0 0 nboundlines nboundlines 0 1 0 0 0 0'.split() + elif shortcut == 'IJK': + l = 'ie je ke 0 nboundlines nboundlines nboundlines nboundlines 0 0 0 0'.split() + elif shortcut == 'IJK1': + l = 'ie je ke1 0 nboundlines nboundlines nboundlines nboundlines 0 1 0 0'.split() return l # error handling - def __exit_error(self, directive="", msg=""): + def __exit_error(self, directive='', msg=''): print('File: "' + self.infile + '", line ' + str(self.__linenum)) if directive: - print("SyntaxError: Invalid !$SER " + directive + " directive") + print('SyntaxError: Invalid !$SER ' + directive + ' directive') if msg: - print("Message: " + msg) + print('Message: '+msg) if self.__line: - print("Line " + str(self.__linenum) + ": " + self.__line) + print('Line '+str(self.__linenum)+': '+self.__line) sys.exit(1) # general SER directive arguments parser def __ser_arg_parse(self, args): # returns list of directives, lists of key=value pairs and (optional) IF statmenet - dirs = [] # directives - keys = [] # keys + dirs = [] # directives + keys = [] # keys values = [] # values if_encountered = False - if_statement = "" + if_statement = '' for arg in args[1:]: - if arg.upper() == "IF": + if arg.upper() == 'IF': if_encountered = True continue if if_encountered: if if_statement: - self.__exit_error( - directive=args[0], msg="IF statement must be last argument" - ) + self.__exit_error(directive=args[0], + msg='IF statement must be last argument') if_statement = arg else: - val = arg.split("=") + val = arg.split('=') if len(val) == 1: dirs.append(val[0]) elif len(val) == 2: keys.append(val[0]) values.append(val[1]) else: - self.__exit_error( - directive=args[0], - msg="Problem extracting arguments and key=value pairs", - ) + self.__exit_error(directive=args[0], + msg='Problem extracting arguments and key=value pairs') return dirs, keys, values, if_statement # parser for tracer directive def __ser_tracer_parse(self, args): tracersspec = [] if_encountered = False - if_statement = "" + if_statement = '' - pattern = "^([a-zA-Z_0-9]+|\$[a-zA-Z_0-9\(\)]+(?:-[a-zA-Z_0-9\(\)]+)?|%all)" # Tracer name, id(s) or %all - pattern += "(?:#(tens|bd|surf|sedimvel))?" # Type (stype) - pattern += "(?:@([a-zA-Z_0-9]+))?" # Time level (timelevel) + pattern = '^([a-zA-Z_0-9]+|\$[a-zA-Z_0-9\(\)]+(?:-[a-zA-Z_0-9\(\)]+)?|%all)' # Tracer name, id(s) or %all + pattern += '(?:#(tens|bd|surf|sedimvel))?' # Type (stype) + pattern += '(?:@([a-zA-Z_0-9]+))?' # Time level (timelevel) r = re.compile(pattern) for arg in args[1:]: - if arg.upper() == "IF": + if arg.upper() == 'IF': if_encountered = True continue if if_encountered: if if_statement: - self.__exit_error( - directive=args[0], msg="IF statement must be last argument" - ) + self.__exit_error(directive=args[0], + msg='IF statement must be last argument') if_statement = arg else: m = r.search(arg) if m is None: - self.__exit_error( - directive=args[0], - msg="Tracer specification " + arg + " is invalid", - ) + self.__exit_error(directive=args[0], + msg='Tracer specification ' + arg + ' is invalid') tracersspec.append(m.groups()) return tracersspec, if_statement # INIT directive def __ser_init(self, args): + (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' - l += tab + "PRINT *, '>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<'\n" - l += tab + "PRINT *, '>>> WARNING: SERIALIZATION IS ON <<<'\n" - l += tab + "PRINT *, '>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<'\n" - l += tab + "\n" - l += tab + "! setup serialization environment\n" + l += tab + 'PRINT *, \'>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<\'\n' + l += tab + 'PRINT *, \'>>> WARNING: SERIALIZATION IS ON <<<\'\n' + l += tab + 'PRINT *, \'>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<\'\n' + l += tab + '\n' + l += tab + '! setup serialization environment\n' args_lower = [item.lower() for item in args] - if "if" in args_lower: - if_pos = args_lower.index("if".lower()) + if 'if' in args_lower: + if_pos = args_lower.index('if'.lower()) else: if_pos = len(args) - self.__calls.add(self.methods["init"]) - l += ( - tab - + "call " - + self.methods["init"] - + "( &\n" - + " " * 11 - + (", &\n" + " " * 11).join(args[1:if_pos]) - + ")\n" - ) + self.__calls.add(self.methods['init']) + l += tab + 'call ' + self.methods['init'] + '( &\n' + ' '*11 + (', &\n' + ' '*11).join(args[1:if_pos]) + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l @@ -329,31 +301,29 @@ def __ser_init(self, args): def __ser_option(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(dirs) != 0: - self.__exit_error( - directive=args[0], - msg="Must specify a name and a list of key=value pairs", - ) + self.__exit_error(directive=args[0], + msg='Must specify a name and a list of key=value pairs') - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' if if_statement: - l += "IF (" + if_statement + ") THEN\n" + l += 'IF (' + if_statement + ') THEN\n' - self.__calls.add(self.methods["option"]) - l += "call " + self.methods["option"] + "(" + self.__calls.add(self.methods['option']) + l += 'call ' + self.methods['option'] + '(' for i in range(len(keys)): - if keys[i].lower() == "verbosity": - if values[i].lower() == "off": - values[i] = "0" - if values[i].lower() == "on": - values[i] = "1" + if keys[i].lower() == 'verbosity': + if values[i].lower() == 'off': + values[i] = '0' + if values[i].lower() == 'on': + values[i] = '1' if i == 0: - l += keys[i] + "=" + values[i] + l += keys[i] + '=' + values[i] else: - l += ", " + keys[i] + "=" + values[i] - l += ")\n" + l += ', ' + keys[i] + '=' + values[i] + l += ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l @@ -361,75 +331,50 @@ def __ser_option(self, args): def __ser_metainfo(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' - self.__calls.add(self.methods["serinfo"]) + self.__calls.add(self.methods['serinfo']) for k, v in zip(keys, values): - l += ( - tab - + "call " - + self.methods["serinfo"] - + '(ppser_serializer, "' - + k - + '", ' - + v - + ")\n" - ) + l += tab + 'call ' + self.methods['serinfo'] + '(ppser_serializer, "' + k + '", ' + v + ')\n' for d in dirs: - l += ( - tab - + "call " - + self.methods["serinfo"] - + '(ppser_serializer, "' - + d - + '", ' - + d - + ")\n" - ) + l += tab + 'call ' + self.methods['serinfo'] + '(ppser_serializer, "' + d + '", ' + d + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # VERBATIM directive def __ser_verbatim(self, args): # simply remove $!SER directive for verbatim statements - self.__line = " ".join(args[1:]) + "\n" + self.__line = ' '.join(args[1:]) + '\n' # REGISTER directive def __ser_register(self, args): + # parse arguments (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(dirs) < 2: - self.__exit_error( - directive=args[0], msg="Must specify a name, a type and the field sizes" - ) + self.__exit_error(directive=args[0], + msg='Must specify a name, a type and the field sizes') if len(dirs) == 2: - dirs.append("") + dirs.append('') # quote name dirs[0] = "'" + dirs[0] + "'" # data type - datatypes = dict( - integer=["'int'", "ppser_intlength"], - real=["ppser_realtype", "ppser_reallength"], - ) + datatypes = dict(integer=["'int'", 'ppser_intlength'], real=['ppser_realtype', 'ppser_reallength']) if dirs[1] not in datatypes: - self.__exit_error( - directive=args[0], - msg='Data type "{0}" not understood. Valid types are: {1}'.format( - dirs[1], ", ".join('"' + d + '"' for d in datatypes.keys()) - ), - ) + self.__exit_error(directive=args[0], msg='Data type "{0}" not understood. Valid types are: {1}'. + format(dirs[1], ', '.join('"' + d + '"' for d in datatypes.keys()))) dirs[1:2] = datatypes[dirs[1]] @@ -440,66 +385,58 @@ def __ser_register(self, args): dirs[3:4] = l # REGISTER [arg ...] - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' # registration - self.__calls.add(self.methods["register"]) - l += ( - tab - + "call " - + self.methods["register"] - + "(ppser_serializer, " - + ", ".join(dirs) - + ")\n" - ) + self.__calls.add(self.methods['register']) + l += tab + 'call ' + self.methods['register'] + '(ppser_serializer, ' + ', '.join(dirs) + ')\n' # metainfo if len(keys) > 0: - self.__exit_error( - directive=args[0], - msg="Metainformation for fields are not yet implemented", - ) + self.__exit_error(directive=args[0], + msg='Metainformation for fields are not yet implemented') # for k,v in zip(keys, values): # l += tab + 'call ' + self.methods['fieldmetainfo'] + ' # (ppser_serializer, ' + dirs[0] + ', "' + k + '", ' + v + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # REGISTERTRACERS directive def __ser_registertracers(self, args): - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - - self.__calls.add(self.methods["registertracers"]) - l += "call fs_RegisterAllTracers()\n" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + self.__calls.add(self.methods['registertracers']) + l += 'call fs_RegisterAllTracers()\n' + self.__line = l # ZERO directive def __ser_zero(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) if len(keys) > 0: - self.__exit_error(directive=args[0], msg="Must specify a list of fields") + self.__exit_error(directive=args[0], + msg='Must specify a list of fields') - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' for arg in dirs: - l += tab + arg + " = 0.0_" + self.real + "\n" + l += tab + arg + ' = 0.0_' + self.real + '\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l @@ -509,54 +446,29 @@ def __ser_savepoint(self, args): # extract save point name if len(dirs) != 1: - self.__exit_error( - directive=args[0], - msg="Must specify a name and a list of key=value pairs", - ) + self.__exit_error(directive=args[0], + msg='Must specify a name and a list of key=value pairs') name = dirs[0] # generate serialization code - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' - self.__calls.add(self.methods["savepoint"]) - self.__calls.add(self.methods["spinfo"]) + self.__calls.add(self.methods['savepoint']) + self.__calls.add(self.methods['spinfo']) if not self.sp_as_var: - l += ( - tab - + "call " - + self.methods["savepoint"] - + "('" - + name - + "', ppser_savepoint)\n" - ) + l += tab + 'call ' + self.methods['savepoint'] + '(\'' + name + '\', ppser_savepoint)\n' else: - l += ( - tab - + "call " - + self.methods["savepoint"] - + "(" - + name - + ", ppser_savepoint)\n" - ) + l += tab + 'call ' + self.methods['savepoint'] + '(' + name + ', ppser_savepoint)\n' for k, v in zip(keys, values): - l += ( - tab - + "call " - + self.methods["spinfo"] - + "(ppser_savepoint, '" - + k - + "', " - + v - + ")\n" - ) + l += tab + 'call ' + self.methods['spinfo'] + '(ppser_savepoint, \'' + k + '\', ' + v + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l @@ -564,268 +476,220 @@ def __ser_savepoint(self, args): def __ser_mode(self, args): (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' - self.__calls.add(self.methods["mode"]) + self.__calls.add(self.methods['mode']) if args[1] in self.modes: - l += ( - tab - + "call " - + self.methods["mode"] - + "(" - + str(self.modes[args[1]]) - + ")\n" - ) + l += tab + 'call ' + self.methods['mode'] + '(' + str(self.modes[args[1]]) + ')\n' else: - l += tab + "call " + self.methods["mode"] + "(" + args[1] + ")\n" + l += tab + 'call ' + self.methods['mode'] + '(' + args[1] + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # KBUFF directive def __ser_kbuff(self, args, isacc=False): + (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) - # generate serialization code - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + # generate serialization code + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' for v in values: - v = re.sub(r"\(.+\)", "", v) + v = re.sub(r'\(.+\)', '', v) if v not in self.intentin_to_remove: self.intentin_to_remove.append(v) - + d = dict(zip(keys, values)) - k_value = d.pop("k") - k_size = d.pop("k_size") + k_value = d.pop('k') + k_size = d.pop('k_size') - self.__calls.add(self.methods["getmode"]) + self.__calls.add(self.methods['getmode']) for k, v in zip(keys, values): - if (k != "k") and (k != "k_size"): - l += ( - tab - + " " - + "call " - + self.methods["datakbuff"] - + "(ppser_serializer, ppser_savepoint, '" - + k - + "', " - + v - + ", k=" - + k_value - + ", k_size=" - + k_size - + ", mode=" - + self.methods["getmode"] - + "())\n" - ) + if (k != 'k') and (k != 'k_size'): + l += tab + ' ' + 'call ' + self.methods['datakbuff'] + \ + '(ppser_serializer, ppser_savepoint, \'' + k + '\', ' + v + ', k=' + \ + k_value + ', k_size=' + k_size + ', mode=' + self.methods['getmode'] +'())\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # DATA directive def __ser_data(self, args, isacc=False): + (dirs, keys, values, if_statement) = self.__ser_arg_parse(args) # generate serialization code - self.__calls.add(self.methods["datawrite"]) - self.__calls.add(self.methods["dataread"]) - self.__calls.add(self.methods["datareadperturb"]) - self.__calls.add(self.methods["getmode"]) + self.__calls.add(self.methods['datawrite']) + self.__calls.add(self.methods['dataread']) + self.__calls.add(self.methods['datareadperturb']) + self.__calls.add(self.methods['getmode']) - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' for v in values: - v = re.sub(r"\(.+\)", "", v) + v = re.sub(r'\(.+\)', '', v) if v not in self.intentin_to_remove: self.intentin_to_remove.append(v) - l += tab + "SELECT CASE ( " + self.methods["getmode"] + "() )\n" - l += tab + " " + "CASE(" + str(self.modes["write"]) + ")\n" + l += tab + 'SELECT CASE ( ' + self.methods['getmode'] + '() )\n' + l += tab + ' ' + 'CASE(' + str(self.modes['write']) + ')\n' for k, v in zip(keys, values): if isacc: # Generate acc update directives only for accdata clause - l += tab + " " + "ACC_PREFIX UPDATE HOST ( " + v + " )" + l += tab + ' ' + 'ACC_PREFIX UPDATE HOST ( ' + v + ' )' # Generate IF clause if needed if len(self.acc_if) > 0: - l += ", IF (" + self.acc_if + ") \n" + l += ', IF (' + self.acc_if + ') \n' else: - l += "\n" - l += ( - tab - + " " - + "call " - + self.methods["datawrite"] - + "(ppser_serializer, ppser_savepoint, '" - + k - + "', " - + v - + ")\n" - ) - l += tab + " " + "CASE(" + str(self.modes["read"]) + ")\n" + l += '\n' + l += tab + ' ' + 'call ' + self.methods['datawrite'] + \ + '(ppser_serializer, ppser_savepoint, \'' + k + '\', ' + v + ')\n' + l += tab + ' ' + 'CASE(' + str(self.modes['read']) + ')\n' for k, v in zip(keys, values): # If the field does not contains any compute sign, the read call is # generated if not any(ext in v for ext in self.__computed_fields_sign): - l += ( - tab - + " " - + "call " - + self.methods["dataread"] - + "(ppser_serializer_ref, ppser_savepoint, '" - + k - + "', " - + v - + ")\n" - ) + l += tab + ' ' + 'call ' + self.methods['dataread'] + '(ppser_serializer_ref, ppser_savepoint, \'' \ + + k + '\', ' + v + ')\n' if isacc: # Generate acc upadte directives only for accdata clause - l += tab + " " + "ACC_PREFIX UPDATE DEVICE ( " + v + " )" + l += tab + ' ' + 'ACC_PREFIX UPDATE DEVICE ( ' + v + ' )' # Generate IF clause if needed if len(self.acc_if) > 0: - l += ", IF (" + self.acc_if + ") \n" + l += ', IF (' + self.acc_if + ') \n' else: - l += "\n" - l += tab + " " + "CASE(" + str(self.modes["read-perturb"]) + ")\n" + l += '\n' + l += tab + ' ' + 'CASE(' + str(self.modes['read-perturb']) + ')\n' for k, v in zip(keys, values): # If the field does not contains any compute sign, the read call is # generated if not any(ext in v for ext in self.__computed_fields_sign): - l += ( - tab - + " " - + "call " - + self.methods["datareadperturb"] - + "(ppser_serializer_ref, ppser_savepoint, '" - + k - + "', " - + v - + ", ppser_zrperturb)\n" - ) + l += tab + ' ' + 'call ' + self.methods['datareadperturb'] + \ + '(ppser_serializer_ref, ppser_savepoint, \'' + k + '\', ' + v + ', ppser_zrperturb)\n' if isacc: # Generate acc upadte directives only for accdata clause - l += tab + " " + "ACC_PREFIX UPDATE DEVICE ( " + v + " )" + l += tab + ' ' + 'ACC_PREFIX UPDATE DEVICE ( ' + v + ' )' # Generate IF clause if needed if len(self.acc_if) > 0: - l += ", IF (" + self.acc_if + ") \n" + l += ', IF (' + self.acc_if + ') \n' else: - l += "\n" + l += '\n' - l += tab + "END SELECT\n" + l += tab + 'END SELECT\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # TRACER directive def __ser_tracer(self, args): + (tracerspec, if_statement) = self.__ser_tracer_parse(args) - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - tab = "" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + tab = '' if if_statement: - l += "IF (" + if_statement + ") THEN\n" - tab = " " + l += 'IF (' + if_statement + ') THEN\n' + tab = ' ' for t in tracerspec: - function = "ppser_write_tracer_" + function = 'ppser_write_tracer_' fargs = [] # Function name and first arguments - if t[0] == "%all": + if t[0] == '%all': # %all specifier - function += "all" - elif t[0][0] == "$": + function += 'all' + elif t[0][0] == '$': # Index-based access - function += "bx_idx" + function += 'bx_idx' idxs = t[0][1:] - if "-" in idxs: - fargs += idxs.split("-") + if '-' in idxs: + fargs += idxs.split('-') else: fargs += [idxs] else: # Name-based access - function += "by_name" + function += 'by_name' fargs.append("'" + t[0] + "'") # Required stype argument - fargs.append("stype='" + (t[1] or "") + "'") + fargs.append("stype='" + (t[1] or '') + "'") # Other arguments - for i, argname in enumerate(("timelevel",), 2): + for i, argname in enumerate(('timelevel',), 2): if t[i]: - fargs.append(argname + "=" + t[i]) + fargs.append(argname + '=' + t[i]) # Put together function call - l += tab + "call " + function + "(" + ", ".join(fargs) + ")\n" + l += tab + 'call ' + function + '(' + ', '.join(fargs) + ')\n' if if_statement: - l += "ENDIF\n" + l += 'ENDIF\n' self.__line = l # CLEANUP directive def __ser_cleanup(self, args): - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - l += "! cleanup serialization environment\n" - - self.__calls.add(self.methods["cleanup"]) - l += "call " + self.methods["cleanup"] + "(" + ",".join(args[1:]) + ")\n" + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + l += '! cleanup serialization environment\n' + + self.__calls.add(self.methods['cleanup']) + l += 'call ' + self.methods['cleanup'] + '(' + ','.join(args[1:]) + ')\n' self.__line = l # ON directive def __ser_on(self, args): - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - - l += "call " + self.methods["on"] + "()\n" - self.__calls.add(self.methods["on"]) - + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + + l += 'call ' + self.methods['on'] + '()\n' + self.__calls.add(self.methods['on']) + self.__line = l # OFF directive def __ser_off(self, args): - l = "! file: " + self.infile + " lineno: #" + str(self.__linenum) + "\n" - - l += "call " + self.methods["off"] + "()\n" - self.__calls.add(self.methods["off"]) - + l = '! file: ' + self.infile + ' lineno: #' + str(self.__linenum) + '\n' + + l += 'call ' + self.methods['off'] + '()\n' + self.__calls.add(self.methods['off']) + self.__line = l # LINE: module/program def __re_module(self): - r = re.compile( - "^ *(?Pmodule|program) +(?P[a-z][a-z0-9_]*)", - re.IGNORECASE, - ) + r = re.compile('^ *(?Pmodule|program) +(?P[a-z][a-z0-9_]*)', re.IGNORECASE) m = r.search(self.__line) if m: - if m.group("identifier").upper() == "PROCEDURE": + if m.group('identifier').upper() == 'PROCEDURE': return False if self.__module: - self.__exit_error(msg="Unexpected " + m.group(1) + " statement") + self.__exit_error(msg='Unexpected ' + m.group(1) + ' statement') self.__produce_use_stmt() - if m.group("statement").upper() == "MODULE": + if m.group('statement').upper() == 'MODULE': self.__use_stmt_in_module = True - self.__module = m.group("identifier") + self.__module = m.group('identifier') return m @@ -833,8 +697,8 @@ def __re_module(self): def __re_subroutine_function(self): if self.__use_stmt_in_module: # Statement produced at module level return - r = re.compile("^ *(subroutine|function).*", re.IGNORECASE) - r_cont = re.compile("^ *(subroutine|function)([^!]*)&", re.IGNORECASE) + r = re.compile('^ *(subroutine|function).*', re.IGNORECASE) + r_cont = re.compile('^ *(subroutine|function)([^!]*)&', re.IGNORECASE) m = r.search(self.__line) m_cont = r_cont.search(self.__line) if m and not m_cont: @@ -845,7 +709,7 @@ def __re_subroutine_function(self): # look ahead nextline = linecache.getline(os.path.join(self.infile), lookahead_index) - r_continued_line = re.compile("^([^!]*)&", re.IGNORECASE) + r_continued_line = re.compile('^([^!]*)&', re.IGNORECASE) while r_continued_line.search(nextline): self.__line += nextline lookahead_index += 1 @@ -857,96 +721,87 @@ def __re_subroutine_function(self): # LINE: !$SER directive def __re_ser(self): - r1 = re.compile("^ *!\$ser *(.*)$", re.IGNORECASE) - r2 = re.compile(r"""((?:[^ "']|"[^"]*"|'[^']*')+)""", re.IGNORECASE) + r1 = re.compile('^ *!\$ser *(.*)$', re.IGNORECASE) + r2 = re.compile(r'''((?:[^ "']|"[^"]*"|'[^']*')+)''', re.IGNORECASE) m = r1.search(self.__line) if m: if m.group(1): args = r2.split(m.group(1))[1::2] - if args[0].upper() in self.language["init"]: + if args[0].upper() in self.language['init']: self.__ser_init(args) - elif args[0].upper() in self.language["option"]: + elif args[0].upper() in self.language['option']: self.__ser_option(args) - elif args[0].upper() in self.language["metainfo"]: + elif args[0].upper() in self.language['metainfo']: self.__ser_metainfo(args) - elif args[0].upper() in self.language["verbatim"]: + elif args[0].upper() in self.language['verbatim']: self.__ser_verbatim(args) - elif args[0].upper() in self.language["register"]: + elif args[0].upper() in self.language['register']: self.__ser_register(args) - elif args[0].upper() in self.language["savepoint"]: + elif args[0].upper() in self.language['savepoint']: self.__ser_savepoint(args) - elif args[0].upper() in self.language["zero"]: + elif args[0].upper() in self.language['zero']: self.__ser_zero(args) - elif args[0].upper() in self.language["accdata"]: + elif args[0].upper() in self.language['accdata']: self.__ser_data(args, True) - elif args[0].upper() in self.language["data"]: + elif args[0].upper() in self.language['data']: self.__ser_data(args) - elif args[0].upper() in self.language["data_kbuff"]: + elif args[0].upper() in self.language['data_kbuff']: self.__ser_kbuff(args) - elif args[0].upper() in self.language["tracer"]: + elif args[0].upper() in self.language['tracer']: self.__ser_tracer(args) - elif args[0].upper() in self.language["registertracers"]: + elif args[0].upper() in self.language['registertracers']: self.__ser_registertracers(args) - elif args[0].upper() in self.language["cleanup"]: + elif args[0].upper() in self.language['cleanup']: self.__ser_cleanup(args) - elif args[0].upper() in self.language["on"]: + elif args[0].upper() in self.language['on']: self.__ser_on(args) - elif args[0].upper() in self.language["off"]: + elif args[0].upper() in self.language['off']: self.__ser_off(args) - elif args[0].upper() in self.language["mode"]: + elif args[0].upper() in self.language['mode']: self.__ser_mode(args) else: - self.__exit_error( - directive=args[0], msg="Unknown directive encountered" - ) + self.__exit_error(directive=args[0], + msg='Unknown directive encountered') return m # LINE: end module/end program def __re_endmodule(self): - r = re.compile("^ *end *(module|program) *([a-z][a-z0-9_]*|)", re.IGNORECASE) + r = re.compile('^ *end *(module|program) *([a-z][a-z0-9_]*|)', re.IGNORECASE) m = r.search(self.__line) if m: if not self.__module: - self.__exit_error(msg='Unexpected "end ' + m.group(1) + '" statement') + self.__exit_error(msg='Unexpected "end '+m.group(1)+'" statement') if m.group(2) and self.__module.lower() != m.group(2).lower(): - self.__exit_error( - msg='Was expecting "end ' + m.group(1) + " " + self.__module + '"' - ) - self.__module = "" + self.__exit_error(msg='Was expecting "end '+m.group(1)+' '+self.__module+'"') + self.__module = '' self.__use_stmt_in_module = False return m def __check_intent_in(self, line): - lhs = re.sub(r"!.*", "", line) # Remove comments at end of the line - var_with_dim = [ - x.strip().replace(" ", "") for x in re.split(r",(?![^(]*\))", lhs) - ] - var = [re.sub(r"\(.*?\)", "", x) for x in var_with_dim] + lhs = re.sub(r'!.*', '', line) # Remove comments at end of the line + var_with_dim = [x.strip().replace(' ', '') for x in re.split(r',(?![^(]*\))', lhs)] + var = [re.sub(r'\(.*?\)', '', x) for x in var_with_dim] fields_in_this_line = [x for x in self.intentin_to_remove if x in var] - self.intentin_removed.extend( - [x for x in fields_in_this_line if x not in self.intentin_removed] - ) + self.intentin_removed.extend([x for x in fields_in_this_line if x not in self.intentin_removed]) if fields_in_this_line: - l = "#ifdef " + self.ifdef + "\n" - r = re.compile(r", *intent *\(in\)", re.IGNORECASE) - l += r.sub("", self.__line) - l += "#else\n" + self.__line + "#endif\n" + l = '#ifdef ' + self.ifdef + '\n' + r = re.compile(r', *intent *\(in\)', re.IGNORECASE) + l += r.sub('', self.__line) + l += '#else\n' + self.__line + '#endif\n' self.__line = l return fields_in_this_line def __re_def(self): - r = re.compile(r".*intent *\(in\)[^:]*::\s*([^!]*)\s*.*", re.IGNORECASE) - r_cont = re.compile(r".*intent *\(in\)[^:]*::\s*([^!]*)\s*.*&", re.IGNORECASE) + r = re.compile(r'.*intent *\(in\)[^:]*::\s*([^!]*)\s*.*', re.IGNORECASE) + r_cont = re.compile(r'.*intent *\(in\)[^:]*::\s*([^!]*)\s*.*&', re.IGNORECASE) # Line contains intent with continuation m_cont = r_cont.search(self.__line) m = r.search(self.__line) if m_cont: - splitted = self.__line.split("::") - splitted[1] = re.sub( - r"!.*", "", splitted[1] - ) # Remove comments at end of the line + splitted = self.__line.split('::') + splitted[1] = re.sub(r'!.*', '', splitted[1]) # Remove comments at end of the line if not self.__check_intent_in(splitted[1]): # look ahead to find the variable lookahead_index = self.__linenum @@ -956,20 +811,16 @@ def __re_def(self): nextline = linecache.getline(os.path.join(self.infile), lookahead_index) while nextline: self.__check_intent_in(nextline) - if nextline.find("&") != -1: + if nextline.find('&') != -1: lookahead_index += 1 - nextline = linecache.getline( - os.path.join(self.infile), lookahead_index - ) + nextline = linecache.getline(os.path.join(self.infile), lookahead_index) else: nextline = None # Match a standard declaration with variable and intent on the same line elif m: - splitted = self.__line.split("::") - splitted[1] = re.sub( - r"!.*", "", splitted[1] - ) # Remove comments at end of the line + splitted = self.__line.split('::') + splitted[1] = re.sub(r'!.*', '', splitted[1]) # Remove comments at end of the line self.__check_intent_in(splitted[1]) return m @@ -977,44 +828,38 @@ def __re_def(self): def __produce_use_stmt(self): if self.__use_stmt_in_module is True: return - calls_pp = [c for c in self.__calls if c.startswith("ppser")] - calls_fs = [c for c in self.__calls if not c.startswith("ppser")] + calls_pp = [c for c in self.__calls if c.startswith('ppser')] + calls_fs = [c for c in self.__calls if not c.startswith('ppser')] ncalls = len(calls_pp) + len(calls_fs) if ncalls > 0: - calls_pp += [ - "ppser_savepoint", - "ppser_serializer", - "ppser_serializer_ref", - "ppser_intlength", - "ppser_reallength", - "ppser_realtype", - "ppser_zrperturb", - "ppser_get_mode", - ] - self.__line += "\n" + calls_pp += ['ppser_savepoint', 'ppser_serializer', 'ppser_serializer_ref', + 'ppser_intlength', 'ppser_reallength', 'ppser_realtype', 'ppser_zrperturb', + 'ppser_get_mode'] + self.__line += '\n' if self.ifdef: - self.__line += "#ifdef " + self.ifdef + "\n" + self.__line += '#ifdef ' + self.ifdef + '\n' if len(calls_fs) > 0: - self.__line += "USE " + self.module + ", ONLY: &\n" + self.__line += 'USE ' + self.module + ', ONLY: &\n' for s in calls_fs[:-1]: - self.__line += " " + s + ", &\n" - self.__line += " " + calls_fs[-1] + "\n" + self.__line += ' ' + s + ', &\n' + self.__line += ' ' + calls_fs[-1] + '\n' if len(calls_pp) > 0: - self.__line += "USE utils_ppser, ONLY: &\n" + self.__line += 'USE utils_ppser, ONLY: &\n' for s in calls_pp[:-1]: - self.__line += " " + s + ", &\n" - self.__line += " " + calls_pp[-1] + "\n" + self.__line += ' ' + s + ', &\n' + self.__line += ' ' + calls_pp[-1] + '\n' if len(self.__extra_module) > 0: for mod in self.__extra_module: - self.__line += "USE " + mod + "\n" + self.__line += 'USE ' + mod + '\n' if self.ifdef: - self.__line += "#endif\n" - self.__line += "\n" + self.__line += '#endif\n' + self.__line += '\n' # evaluate one line def lexer(self, final=False): + # parse lines related to scope self.__re_module() self.__re_subroutine_function() @@ -1025,45 +870,43 @@ def lexer(self, final=False): if self.__re_ser(): # if this is the first line with !$SER statements, add #ifdef if self.ifdef and not self.__ser: - self.__line = "#ifdef " + self.ifdef + "\n" + self.__line + self.__line = '#ifdef ' + self.ifdef + '\n' + self.__line self.__ser = True else: # if this is the first line without !$SER statements, add #endif if self.ifdef and self.__ser: - self.__line = "#endif\n" + self.__line + self.__line = '#endif\n' + self.__line self.__ser = False if final: # final call, check consistency if self.__ser: - self.__exit_error( - msg="Unterminated #ifdef " + self.ifdef + " encountered" - ) + self.__exit_error(msg='Unterminated #ifdef ' + self.ifdef + ' encountered') if self.__module: - self.__exit_error(msg="Unterminated module or program unit encountered") + self.__exit_error(msg='Unterminated module or program unit encountered') # execute one parsing pass over file def parse(self, generate=False): # if generate == False we only analyse the file # reset flags (which define state of parser) - self.__ser = False # currently processing !$SER directives - self.__line = "" # current line - self.__linenum = 0 # current line number - self.__module = "" # current module - self.__outputBuffer = "" # preprocessed file + self.__ser = False # currently processing !$SER directives + self.__line = '' # current line + self.__linenum = 0 # current line number + self.__module = '' # current module + self.__outputBuffer = '' # preprocessed file # generate preprocessing macro for ACC_PREFIX if self.acc_prefix: - self.__outputBuffer += "#define ACC_PREFIX !$acc\n" + self.__outputBuffer += '#define ACC_PREFIX !$acc\n' # open and parse file - input_file = open(os.path.join(self.infile), "r") + input_file = open(os.path.join(self.infile), 'r') try: - self.line = "" + self.line = '' for line in input_file: # Skip line already handled - if self.__skip_next_n_lines > 0: + if(self.__skip_next_n_lines > 0): self.__skip_next_n_lines -= 1 self.__linenum += 1 continue @@ -1071,15 +914,15 @@ def parse(self, generate=False): # handle line continuation (next line coming in) if self.__line: - if re.match("^ *!\$ser& ", line, re.IGNORECASE): - line = re.sub("^ *!\$ser& *", " ", line, re.IGNORECASE) + if re.match('^ *!\$ser& ', line, re.IGNORECASE): + line = re.sub('^ *!\$ser& *', ' ', line, re.IGNORECASE) else: - self.__exit_error(msg="Incorrect line continuation encountered") + self.__exit_error(msg='Incorrect line continuation encountered') self.__line += line # handle line continuation (continued line going out) - if re.match("^ *!\$ser *(.*) & *$", self.__line, re.IGNORECASE): + if re.match('^ *!\$ser *(.*) & *$', self.__line, re.IGNORECASE): # chop trailing & - self.__line = re.sub(" +& *$", "", self.__line, re.IGNORECASE) + self.__line = re.sub(' +& *$', '', self.__line, re.IGNORECASE) self.__line = self.__line.rstrip() continue # parse line @@ -1087,7 +930,7 @@ def parse(self, generate=False): if generate: self.__outputBuffer += self.__line # cleanup current line (used for line continuation and final lexer call) - self.__line = "" + self.__line = '' self.lexer(final=True) finally: @@ -1096,10 +939,10 @@ def parse(self, generate=False): # main processing method def preprocess(self): # parse file - self.parse() # first pass, analyse only - self.parse(generate=True) # second pass, preprocess + self.parse() # first pass, analyse only + self.parse(generate=True) # second pass, preprocess # write output - if self.outfile != "": + if self.outfile != '': output_file = tempfile.NamedTemporaryFile(delete=False) # same permissions as infile os.chmod(output_file.name, os.stat(self.infile).st_mode) @@ -1192,7 +1035,7 @@ def simple_test(): f.write(test) f.close() ser = PpSer(f.name) - PpSer.real = "wp" + PpSer.real = 'wp' ser.preprocess() finally: os.remove(f.name) @@ -1200,94 +1043,38 @@ def simple_test(): def parse_args(): from optparse import OptionParser - parser = OptionParser() - parser.add_option( - "-i", - "--ignore-identical", - help="Ignore files which are not modified by pre-processor", - default=False, - action="store_true", - dest="ignore_identical", - ) - parser.add_option( - "-d", - "--output-dir", - help="The target directory for writing pre-processed files", - default="", - type=str, - dest="output_dir", - ) - parser.add_option( - "-o", - "--output", - help="Output file name to preprocess single file", - default="", - type=str, - dest="output_file", - ) - parser.add_option( - "-r", - "--recursive", - help="Recursively process target directory and mirror tree", - default=False, - action="store_true", - dest="recursive", - ) - parser.add_option( - "-v", - "--verbose", - help="Enable verbose execution", - default=False, - action="store_true", - dest="verbose", - ) - parser.add_option( - "-p", - "--no-prefix", - help="Don't generate preprocessing macro definition for ACC_PREFIX", - default=True, - action="store_false", - dest="acc_prefix", - ) - parser.add_option( - "-a", - "--acc-if", - help="Add IF clause to OpenACC update statement", - default="", - type=str, - dest="acc_if", - ) - parser.add_option( - "-m", - "--module", - help="Extra MODULE to be add to the use statement", - default="", - type=str, - dest="modules", - ) - parser.add_option( - "-s", - "--sp-as-var", - help="Savepoint specified as variable instead of string", - default=False, - action="store_true", - dest="sp_as_var", - ) + parser.add_option('-i', '--ignore-identical', help='Ignore files which are not modified by pre-processor', + default=False, action='store_true', dest='ignore_identical') + parser.add_option('-d', '--output-dir', help='The target directory for writing pre-processed files', + default='', type=str, dest='output_dir') + parser.add_option('-o', '--output', help='Output file name to preprocess single file', + default='', type=str, dest='output_file') + parser.add_option('-r', '--recursive', help='Recursively process target directory and mirror tree', + default=False, action='store_true', dest='recursive') + parser.add_option('-v', '--verbose', help='Enable verbose execution', + default=False, action='store_true', dest='verbose') + parser.add_option('-p', '--no-prefix', help='Don\'t generate preprocessing macro definition for ACC_PREFIX', + default=True, action='store_false', dest='acc_prefix') + parser.add_option('-a', '--acc-if', help='Add IF clause to OpenACC update statement', + default='', type=str, dest='acc_if') + parser.add_option('-m', '--module', help='Extra MODULE to be add to the use statement', + default='', type=str, dest='modules') + parser.add_option('-s', '--sp-as-var', help='Savepoint specified as variable instead of string', + default=False, action='store_true', dest='sp_as_var') (options, args) = parser.parse_args() if len(args) < 1: - parser.error("Need at least one source file to process") + parser.error('Need at least one source file to process') if options.output_file and len(args) > 1: - parser.error("Single source file required if output file is given") + parser.error('Single source file required if output file is given') if options.recursive: if not options.output_dir: - parser.error("Output directory is required with recursive option") + parser.error('Output directory is required with recursive option') for indir in args: if not os.path.isdir(indir): - parser.error("Arguments need to be directories with recursive option") + parser.error('Arguments need to be directories with recursive option') return options, args - if __name__ == "__main__": (options, args) = parse_args() if options.recursive: @@ -1299,38 +1086,22 @@ def parse_args(): for infile in args: if options.output_dir: if options.recursive: - outfile = os.path.join( - options.output_dir, - os.path.sep.join( - [p for p in os.path.dirname(infile).rsplit(os.path.sep) if p][ - 1: - ] - ), - os.path.basename(infile), - ) + outfile = os.path.join(options.output_dir, + os.path.sep.join([p for p in os.path.dirname(infile).rsplit(os.path.sep) if p][1:]), + os.path.basename(infile)) else: outfile = os.path.join(options.output_dir, os.path.basename(infile)) elif options.output_file: outfile = options.output_file else: - outfile = "" + outfile = '' # If output is to a file and the file is more updated than the input, skip - if os.path.exists(outfile) and os.path.getctime(outfile) > os.path.getctime( - infile - ): - print("Skipping", infile) + if os.path.exists(outfile) and os.path.getctime(outfile) > os.path.getctime(infile): + print('Skipping', infile) else: - print("Processing file", infile) - ser = PpSer( - infile, - real="wp", - outfile=outfile, - identical=(not options.ignore_identical), - verbose=options.verbose, - acc_prefix=options.acc_prefix, - acc_if=options.acc_if, - modules=options.modules, - sp_as_var=options.sp_as_var, - ) + print('Processing file', infile) + ser = PpSer(infile, real='wp', outfile=outfile, identical=(not options.ignore_identical), + verbose=options.verbose, acc_prefix=options.acc_prefix, acc_if=options.acc_if, + modules=options.modules, sp_as_var=options.sp_as_var) ser.preprocess() diff --git a/src/serialbox-python/serialbox/serializer.py b/src/serialbox-python/serialbox/serializer.py index 52c236c0..db0dde9c 100644 --- a/src/serialbox-python/serialbox/serializer.py +++ b/src/serialbox-python/serialbox/serializer.py @@ -4,7 +4,7 @@ ## ## S E R I A L B O X ## -## This file is distributed under terms of BSD license. +## This file is distributed under terms of BSD license. ## See LICENSE.txt for more information. ## ##===------------------------------------------------------------------------------------------===## @@ -22,20 +22,14 @@ from .error import invoke, SerialboxError from .fieldmetainfo import FieldMetainfo, FieldMetainfoImpl from .metainfomap import MetainfoMap, MetainfoImpl, ArrayOfStringImpl -from .savepoint import ( - Savepoint, - SavepointImpl, - SavepointTopCollection, - SavepointCollection, -) +from .savepoint import Savepoint, SavepointImpl, SavepointTopCollection, SavepointCollection from .type import * lib = get_library() class SerializerImpl(Structure): - """Mapping of serialboxSerializer_t""" - + """ Mapping of serialboxSerializer_t """ _fields_ = [("impl", c_void_p), ("ownsData", c_int)] @@ -85,39 +79,27 @@ def register_library(library): # # Register and Query Savepoints # - library.serialboxSerializerAddSavepoint.argtypes = [ - POINTER(SerializerImpl), - POINTER(SavepointImpl), - ] + library.serialboxSerializerAddSavepoint.argtypes = [POINTER(SerializerImpl), + POINTER(SavepointImpl)] library.serialboxSerializerAddSavepoint.restype = c_int - library.serialboxSerializerHasSavepoint.argtypes = [ - POINTER(SerializerImpl), - POINTER(SavepointImpl), - ] + library.serialboxSerializerHasSavepoint.argtypes = [POINTER(SerializerImpl), + POINTER(SavepointImpl)] library.serialboxSerializerHasSavepoint.restype = c_int library.serialboxSerializerGetNumSavepoints.argtypes = [POINTER(SerializerImpl)] library.serialboxSerializerGetNumSavepoints.restype = c_int library.serialboxSerializerGetSavepointVector.argtypes = [POINTER(SerializerImpl)] - library.serialboxSerializerGetSavepointVector.restype = POINTER( - POINTER(SavepointImpl) - ) - - library.serialboxSerializerDestroySavepointVector.argtypes = [ - POINTER(POINTER(SavepointImpl)), - c_int, - ] + library.serialboxSerializerGetSavepointVector.restype = POINTER(POINTER(SavepointImpl)) + + library.serialboxSerializerDestroySavepointVector.argtypes = [POINTER(POINTER(SavepointImpl)), + c_int] library.serialboxSerializerDestroySavepointVector.restype = None - library.serialboxSerializerGetFieldnamesAtSavepoint.argtypes = [ - POINTER(SerializerImpl), - POINTER(SavepointImpl), - ] - library.serialboxSerializerGetFieldnamesAtSavepoint.restype = POINTER( - ArrayOfStringImpl - ) + library.serialboxSerializerGetFieldnamesAtSavepoint.argtypes = [POINTER(SerializerImpl), + POINTER(SavepointImpl)] + library.serialboxSerializerGetFieldnamesAtSavepoint.restype = POINTER(ArrayOfStringImpl) library.serialboxSavepointCreateFromSavepoint.argtypes = [POINTER(SavepointImpl)] library.serialboxSavepointCreateFromSavepoint.restype = POINTER(SavepointImpl) @@ -125,20 +107,14 @@ def register_library(library): # # Register and Query Fields # - library.serialboxSerializerAddField.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - POINTER(FieldMetainfoImpl), - ] + library.serialboxSerializerAddField.argtypes = [POINTER(SerializerImpl), c_char_p, + POINTER(FieldMetainfoImpl)] library.serialboxSerializerAddField.restype = c_int library.serialboxSerializerHasField.argtypes = [POINTER(SerializerImpl), c_char_p] library.serialboxSerializerHasField.restype = c_int - library.serialboxSerializerGetFieldMetainfo.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - ] + library.serialboxSerializerGetFieldMetainfo.argtypes = [POINTER(SerializerImpl), c_char_p] library.serialboxSerializerGetFieldMetainfo.restype = POINTER(FieldMetainfoImpl) library.serialboxSerializerGetFieldnames.argtypes = [POINTER(SerializerImpl)] @@ -147,45 +123,37 @@ def register_library(library): # # Writing & Reading # - library.serialboxSerializerWrite.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int, - ] + library.serialboxSerializerWrite.argtypes = [POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int] library.serialboxSerializerWrite.restype = None - library.serialboxSerializerRead.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int, - ] + library.serialboxSerializerRead.argtypes = [POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int] library.serialboxSerializerRead.restype = None - library.serialboxSerializerReadSliced.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int, - POINTER(c_int), - ] + library.serialboxSerializerReadSliced.argtypes = [POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int, + POINTER(c_int)] library.serialboxSerializerReadSliced.restype = None - library.serialboxSerializerReadAsync.argtypes = [ - POINTER(SerializerImpl), - c_char_p, - POINTER(SavepointImpl), - c_void_p, - POINTER(c_int), - c_int, - ] + library.serialboxSerializerReadAsync.argtypes = [POINTER(SerializerImpl), + c_char_p, + POINTER(SavepointImpl), + c_void_p, + POINTER(c_int), + c_int] library.serialboxSerializerReadAsync.restype = None library.serialboxSerializerWaitForAll.argtypes = [POINTER(SerializerImpl)] @@ -194,28 +162,24 @@ def register_library(library): # # Stateless Serialization # - library.serialboxWriteToFile.argtypes = [ - c_char_p, - c_void_p, - c_int, - POINTER(c_int), - c_int, - POINTER(c_int), - c_char_p, - c_char_p, - ] + library.serialboxWriteToFile.argtypes = [c_char_p, + c_void_p, + c_int, + POINTER(c_int), + c_int, + POINTER(c_int), + c_char_p, + c_char_p] library.serialboxWriteToFile.restype = None - library.serialboxReadFromFile.argtypes = [ - c_char_p, - c_void_p, - c_int, - POINTER(c_int), - c_int, - POINTER(c_int), - c_char_p, - c_char_p, - ] + library.serialboxReadFromFile.argtypes = [c_char_p, + c_void_p, + c_int, + POINTER(c_int), + c_int, + POINTER(c_int), + c_char_p, + c_char_p] library.serialboxReadFromFile.restype = None # @@ -246,7 +210,6 @@ class Serializer(object): >>> [f for f in os.listdir(".") if os.path.isfile(os.path.join(".", f))] # List files in current directory ['field_field.dat', 'ArchiveMetaData-field.json', 'MetaData-field.json'] """ - Enabled = 1 Disabled = -1 @@ -281,9 +244,7 @@ def __init__(self, mode, directory, prefix, archive="Binary"): archives = Archive.registered_archives() if archive not in archives: raise SerialboxError( - "'%s' is not a valid archive. Registered archives: %s" - % (archive, archives) - ) + "'%s' is not a valid archive. Registered archives: %s" % (archive, archives)) # # Create serializer @@ -292,9 +253,8 @@ def __init__(self, mode, directory, prefix, archive="Binary"): prefixstr = to_c_string(prefix)[0] archivestr = to_c_string(archive)[0] - self.__serializer = invoke( - lib.serialboxSerializerCreate, modeint, dirstr, prefixstr, archivestr - ) + self.__serializer = invoke(lib.serialboxSerializerCreate, modeint, dirstr, prefixstr, + archivestr) # # Savepoint list @@ -345,7 +305,8 @@ def directory(self): return invoke(lib.serialboxSerializerGetDirectory, self.__serializer).decode() def update_meta_data(self): - """Write meta-data to disk.""" + """ Write meta-data to disk. + """ invoke(lib.serialboxSerializerUpdateMetaData, self.__serializer) @staticmethod @@ -415,9 +376,7 @@ def global_metainfo(self): :return: Refrence to the meta-information map :rtype: :class:`MetainfoMap ` """ - return MetainfoMap( - impl=invoke(lib.serialboxSerializerGetGlobalMetainfo, self.__serializer) - ) + return MetainfoMap(impl=invoke(lib.serialboxSerializerGetGlobalMetainfo, self.__serializer)) # ===----------------------------------------------------------------------------------------=== # Register and Query Savepoints @@ -434,17 +393,11 @@ def register_savepoint(self, savepoint): :raises serialbox.SerialboxError: if `savepoint` already exists within the Serializer """ if self.mode == OpenModeKind.Read: - raise SerialboxError( - "registering savepoints is not permitted in OpenModeKind.Read" - ) + raise SerialboxError("registering savepoints is not permitted in OpenModeKind.Read") - if not invoke( - lib.serialboxSerializerAddSavepoint, self.__serializer, savepoint.impl() - ): + if not invoke(lib.serialboxSerializerAddSavepoint, self.__serializer, savepoint.impl()): raise SerialboxError( - "savepoint '%s' already exists withing the Serializer" - % (savepoint.__str__()) - ) + "savepoint '%s' already exists withing the Serializer" % (savepoint.__str__())) def has_savepoint(self, savepoint): """Check if `savepoint` exists within the Serializer. @@ -455,10 +408,7 @@ def has_savepoint(self, savepoint): :rtype: bool """ return bool( - invoke( - lib.serialboxSerializerHasSavepoint, self.__serializer, savepoint.impl() - ) - ) + invoke(lib.serialboxSerializerHasSavepoint, self.__serializer, savepoint.impl())) def get_savepoint(self, name): """Get a list of Savepoint(s) identified by `name` in the order they were registered @@ -489,11 +439,8 @@ def fields_at_savepoint(self, savepoint): :raises serialbox.SerialboxError: if `savepoint` does not exists """ savepoint_ = self.__extract_savepoint(savepoint) - array = invoke( - lib.serialboxSerializerGetFieldnamesAtSavepoint, - self.__serializer, - savepoint_.impl(), - ) + array = invoke(lib.serialboxSerializerGetFieldnamesAtSavepoint, self.__serializer, + savepoint_.impl()) list_array = [] for i in range(array.contents.len): list_array += [array.contents.data[i].decode()] @@ -523,23 +470,14 @@ def savepoint_list(self): # list_of_savepoints = [] for i in range(num_savepoints): - list_of_savepoints += [ - Savepoint( - "", - impl=invoke( - lib.serialboxSavepointCreateFromSavepoint, - vec_savepoint[i].contents, - ), - ) - ] + list_of_savepoints += [Savepoint('', + impl=invoke( + lib.serialboxSavepointCreateFromSavepoint, + vec_savepoint[i].contents))] # # Destroy the savepoint vector # - invoke( - lib.serialboxSerializerDestroySavepointVector, - vec_savepoint, - num_savepoints, - ) + invoke(lib.serialboxSerializerDestroySavepointVector, vec_savepoint, num_savepoints) # # If we are in Read mode, we can safely cache the savepoint list @@ -628,20 +566,12 @@ def register_field(self, name, fieldmetainfo): Serializer """ if self.mode == OpenModeKind.Read: - raise SerialboxError( - "registering fields is not permitted in OpenModeKind.Read" - ) + raise SerialboxError("registering fields is not permitted in OpenModeKind.Read") namestr = to_c_string(name)[0] - if not invoke( - lib.serialboxSerializerAddField, - self.__serializer, - namestr, - fieldmetainfo.impl(), - ): - raise SerialboxError( - "field '%s' already exists within the Serializer" % name - ) + if not invoke(lib.serialboxSerializerAddField, self.__serializer, namestr, + fieldmetainfo.impl()): + raise SerialboxError("field '%s' already exists within the Serializer" % name) def has_field(self, field): """Check if `field` is registered within the Serializer. @@ -652,9 +582,7 @@ def has_field(self, field): :rtype: bool """ fieldstr = to_c_string(field)[0] - return bool( - invoke(lib.serialboxSerializerHasField, self.__serializer, fieldstr) - ) + return bool(invoke(lib.serialboxSerializerHasField, self.__serializer, fieldstr)) def get_field_metainfo(self, field): """Get the :class:`FieldMetainfo ` of `field`. @@ -666,13 +594,9 @@ def get_field_metainfo(self, field): :raises serialbox.SerialboxError: if `field` does not exist within the Serializer """ fieldstr = to_c_string(field)[0] - return FieldMetainfo( - None, - [], - impl=invoke( - lib.serialboxSerializerGetFieldMetainfo, self.__serializer, fieldstr - ), - ) + return FieldMetainfo(None, [], + impl=invoke(lib.serialboxSerializerGetFieldMetainfo, self.__serializer, + fieldstr)) def fieldnames(self): """Get a list of registered fieldnames within the Serializer. @@ -694,43 +618,38 @@ def fieldnames(self): @staticmethod def __extract_strides(field): """Extract strides from a numpy.array and convert to unit-strides, returns a C-Array and its - size + size """ strides = (c_int * len(field.strides))() for i in range(len(field.strides)): strides[i] = int(field.strides[i] / field.dtype.itemsize) num_strides = c_int(len(field.strides)) - return ( - strides, - num_strides, - ) + return strides, num_strides, @staticmethod def __extract_dims(field): - """Extract dimensions from a numpy.array, returns a C-Array and its size""" + """Extract dimensions from a numpy.array, returns a C-Array and its size + """ dims = (c_int * len(field.shape))() for i in range(len(field.shape)): dims[i] = int(field.shape[i]) num_dims = c_int(len(field.shape)) - return ( - dims, - num_dims, - ) + return dims, num_dims, @staticmethod def __extract_savepoint(savepoint): - """Extract the savepoint of a savepoint collection""" + """Extract the savepoint of a savepoint collection + """ if isinstance(savepoint, SavepointCollection): return savepoint.as_savepoint() else: return savepoint def __allocate_or_check_field(self, name, field): - """Allocate or check the numpy field for consistency""" + """Allocate or check the numpy field for consistency + """ if not self.has_field(name): - raise SerialboxError( - "field '%s' is not registered within the Serializer" % name - ) + raise SerialboxError("field '%s' is not registered within the Serializer" % name) info = self.get_field_metainfo(name) if field is None: @@ -738,23 +657,18 @@ def __allocate_or_check_field(self, name, field): else: if list(field.shape) != list(info.dims): raise SerialboxError( - "registered dimensions %s do not match dimensions of field (%s) %s" - % (field.shape, name, info.dims) - ) + "registered dimensions %s do not match dimensions of field (%s) %s" % ( + field.shape, name, info.dims)) if numpy2TypeID(field.dtype) != info.type: raise SerialboxError( - "registered type %s does not match type of field (%s) %s" - % (numpy2TypeID(field.dtype), name, info.type) - ) + "registered type %s does not match type of field (%s) %s" % ( + numpy2TypeID(field.dtype), name, info.type)) - return ( - field, - info, - ) + return (field, info,) def write(self, name, savepoint, field, register_field=True): - """Serialize `field` identified by `name` at `savepoint` to disk + """ Serialize `field` identified by `name` at `savepoint` to disk The `savepoint` will be registered at field `name` if not yet present. If `register_field` is `True`, the field will be registered if necessary. @@ -779,9 +693,7 @@ def write(self, name, savepoint, field, register_field=True): :raises serialbox.SerialboxError: if serialization failed """ if self.mode == OpenModeKind.Read: - raise SerialboxError( - "write operations are not permitted in OpenModeKind.Read" - ) + raise SerialboxError("write operations are not permitted in OpenModeKind.Read") savepoint = self.__extract_savepoint(savepoint) @@ -790,9 +702,7 @@ def write(self, name, savepoint, field, register_field=True): info = FieldMetainfo(numpy2TypeID(field.dtype), list(field.shape)) self.register_field(name, info) else: - raise SerialboxError( - "field '%s' is not registered within the Serializer" % name - ) + raise SerialboxError("field '%s' is not registered within the Serializer" % name) # # Extract strides and convert to unit-strides @@ -804,18 +714,11 @@ def write(self, name, savepoint, field, register_field=True): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke( - lib.serialboxSerializerWrite, - self.__serializer, - namestr, - savepoint.impl(), - origin_ptr, - strides, - num_strides, - ) + invoke(lib.serialboxSerializerWrite, self.__serializer, namestr, savepoint.impl(), + origin_ptr, strides, num_strides) def read(self, name, savepoint, field=None): - """Deserialize `field` identified by `name` at `savepoint` from disk + """ Deserialize `field` identified by `name` at `savepoint` from disk If `field` is a :class:`numpy.array ` it will be filled with data from disk. If `field` is ``None``, a new :class:`numpy.array ` will be allocated with @@ -843,9 +746,7 @@ def read(self, name, savepoint, field=None): :raises serialbox.SerialboxError: if deserialization failed """ if self.mode != OpenModeKind.Read: - raise SerialboxError( - "read operations are not permitted in OpenModeKind.%s" % self.mode - ) + raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) savepoint = self.__extract_savepoint(savepoint) @@ -864,20 +765,13 @@ def read(self, name, savepoint, field=None): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke( - lib.serialboxSerializerRead, - self.__serializer, - namestr, - savepoint.impl(), - origin_ptr, - strides, - num_strides, - ) + invoke(lib.serialboxSerializerRead, self.__serializer, namestr, savepoint.impl(), + origin_ptr, strides, num_strides) return field def read_async(self, name, savepoint, field=None): - """Asynchronously deserialize field `name` at `savepoint` from disk. + """ Asynchronously deserialize field `name` at `savepoint` from disk. If `field` is a :class:`numpy.array ` it will be filled with data from disk. If `field` is ``None``, a new :class:`numpy.array ` will be allocated with @@ -910,9 +804,7 @@ def read_async(self, name, savepoint, field=None): :raises SerialboxError: Deserialization failed """ if self.mode != OpenModeKind.Read: - raise SerialboxError( - "read operations are not permitted in OpenModeKind.%s" % self.mode - ) + raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) savepoint = self.__extract_savepoint(savepoint) @@ -931,24 +823,18 @@ def read_async(self, name, savepoint, field=None): # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke( - lib.serialboxSerializerReadAsync, - self.__serializer, - namestr, - savepoint.impl(), - origin_ptr, - strides, - num_strides, - ) + invoke(lib.serialboxSerializerReadAsync, self.__serializer, namestr, savepoint.impl(), + origin_ptr, strides, num_strides) return field def wait_for_all(self): - """Wait for all pending asynchronous read operations and reset the internal queue.""" + """ Wait for all pending asynchronous read operations and reset the internal queue. + """ invoke(lib.serialboxSerializerWaitForAll, self.__serializer) def read_slice(self, name, savepoint, slice_obj, field=None): - """Deserialize sliced `field` identified by `name` and `slice` at `savepoint` from disk + """ Deserialize sliced `field` identified by `name` and `slice` at `savepoint` from disk The method will allocate a `numpy.array` with the registered dimensions and type and fill it at specified positions (given by `slice_obj`) with data from disk. @@ -988,9 +874,7 @@ def read_slice(self, name, savepoint, slice_obj, field=None): savepoint = self.__extract_savepoint(savepoint) if self.mode != OpenModeKind.Read: - raise SerialboxError( - "read operations are not permitted in OpenModeKind.%s" % self.mode - ) + raise SerialboxError("read operations are not permitted in OpenModeKind.%s" % self.mode) # # Allocate or check the field @@ -1018,10 +902,8 @@ def read_slice(self, name, savepoint, slice_obj, field=None): slice_array = list(slice_obj) if len(slice_array) > num_dims: - raise SerialboxError( - "number of slices (%i) exceeds number of dimensions (%i)" - % (len(slice_array), num_dims) - ) + raise SerialboxError("number of slices (%i) exceeds number of dimensions (%i)" % ( + len(slice_array), num_dims)) while len(slice_array) != num_dims: slice_array += [slice(None, None, None)] @@ -1040,9 +922,7 @@ def read_slice(self, name, savepoint, slice_obj, field=None): c_slice_array[3 * i + 2] = 1 else: # start - c_slice_array[3 * i] = ( - 0 if slice_triple.start is None else slice_triple.start - ) + c_slice_array[3 * i] = 0 if slice_triple.start is None else slice_triple.start # stop (expand negative values) if slice_triple.stop is None: @@ -1053,25 +933,15 @@ def read_slice(self, name, savepoint, slice_obj, field=None): c_slice_array[3 * i + 1] = dims[i] + slice_triple.stop # end - c_slice_array[3 * i + 2] = ( - 1 if slice_triple.step is None else slice_triple.step - ) + c_slice_array[3 * i + 2] = 1 if slice_triple.step is None else slice_triple.step # # Read from disk # origin_ptr = c_void_p(field.ctypes.data) namestr = to_c_string(name)[0] - invoke( - lib.serialboxSerializerReadSliced, - self.__serializer, - namestr, - savepoint.impl(), - origin_ptr, - strides, - num_strides, - c_slice_array, - ) + invoke(lib.serialboxSerializerReadSliced, self.__serializer, namestr, savepoint.impl(), + origin_ptr, strides, num_strides, c_slice_array) return field @@ -1081,7 +951,7 @@ def read_slice(self, name, savepoint, slice_obj, field=None): @staticmethod def to_file(name, field, filename, archive=None): - """Serialize `field` identified by `name` directly to file. + """ Serialize `field` identified by `name` directly to file. This method allows stateless serializations i.e serialize fields without the need to register fields or savpoints. @@ -1113,20 +983,11 @@ def to_file(name, field, filename, archive=None): filestr = to_c_string(filename)[0] archivestr = to_c_string(archive)[0] - invoke( - lib.serialboxWriteToFile, - filestr, - origin_ptr, - typeint, - dims, - num_dims, - strides, - namestr, - archivestr, - ) + invoke(lib.serialboxWriteToFile, filestr, origin_ptr, typeint, dims, num_dims, strides, + namestr, archivestr) def from_file(name, field, filename, archive=None): - """Deserialize `field` identified by `name` directly from file. + """ Deserialize `field` identified by `name` directly from file. This method allows stateless deserializations i.e serialize fields without specifying the savepoints or fields. @@ -1167,17 +1028,8 @@ def from_file(name, field, filename, archive=None): filestr = to_c_string(filename)[0] archivestr = to_c_string(archive)[0] - invoke( - lib.serialboxReadFromFile, - filestr, - origin_ptr, - typeint, - dims, - num_dims, - strides, - namestr, - archivestr, - ) + invoke(lib.serialboxReadFromFile, filestr, origin_ptr, typeint, dims, num_dims, strides, + namestr, archivestr) def __del__(self): if self.__serializer: @@ -1202,7 +1054,7 @@ def __str__(self): return invoke(lib.serialboxSerializerToString, self.__serializer).decode() def __repr__(self): - return "".format(self.__str__()) + return ''.format(self.__str__()) register_library(lib) From fed71212df66d06e46066e3b3d73b93c4d1cbf11 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Mon, 18 Nov 2024 17:38:19 +0100 Subject: [PATCH 5/5] more cleanup --- CMakeLists.txt | 3 +-- cmake/SerialboxConfig.cmake.in | 28 ++------------------------- docs/sphinx/Building.rst | 2 +- docs/sphinx/C.rst | 3 +-- docs/sphinx/Fortran.rst | 3 +-- docs/sphinx/Usage.rst | 7 ++----- examples/CMakeLists.txt | 1 - src/serialbox-c/CMakeLists.txt | 2 +- src/serialbox/core/Config.h.cmake | 4 ---- test/benchmark/CMakeLists.txt | 3 +-- test/serialbox-fortran/CMakeLists.txt | 1 - 11 files changed, 10 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d652fd39..8665ffbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,8 +244,7 @@ if(SERIALBOX_TESTING_GRIDTOOLS) set(SERIALBOX_HAS_GRIDTOOLS 1) endif(SERIALBOX_TESTING_GRIDTOOLS) -# If ${REQUIRED_BOOST_COMPONENTS} is empty we still need the headers -find_package(Boost 1.54 REQUIRED) +find_package(Boost 1.54 REQUIRED) # only Boost headers set(SERIALBOX_BOOST_VERSION ${Boost_VERSION}) #---------------------------------------- ClangTools ----------------------------------------------- diff --git a/cmake/SerialboxConfig.cmake.in b/cmake/SerialboxConfig.cmake.in index 55844db9..e35740ac 100644 --- a/cmake/SerialboxConfig.cmake.in +++ b/cmake/SerialboxConfig.cmake.in @@ -33,13 +33,6 @@ set(SERIALBOX_HAS_NETCDF "@SERIALBOX_USE_NETCDF@") # SERIALBOX was compiled with logging support (requires Boost.Log) set(SERIALBOX_HAS_LOGGING "@SERIALBOX_LOGGING@") -# Set Boost configuration -set(SERIALBOX_BOOST_LIB_VERSION "@Boost_LIB_VERSION@") -STRING(REGEX REPLACE "_" "." SERIALBOX_BOOST_VERSION ${SERIALBOX_BOOST_LIB_VERSION}) -set(SERIALBOX_BOOST_LIBRARY_DIRS "@Boost_LIBRARY_DIRS@") -set(SERIALBOX_BOOST_INCLUDE_DIRS "@Boost_INCLUDE_DIRS@") -set(SERIALBOX_REQUIRED_BOOST_COMPONENTS "@REQUIRED_BOOST_COMPONENTS@") - #===---------------------------------------------------------------------------------------------=== # Helper functions used in this file #====--------------------------------------------------------------------------------------------=== @@ -154,30 +147,13 @@ if(NOT(DEFINED SERIALBOX_NO_EXTERNAL_LIBS)) message( STATUS "Serialbox: find_dependency(Threads)" ) find_dependency(Threads) - set(BOOST_LIBRARYDIR "${SERIALBOX_BOOST_LIBRARY_DIRS}") - set(BOOST_INCLUDEDIR "${SERIALBOX_BOOST_INCLUDE_DIRS}") - set(Boost_NO_SYSTEM_PATHS "ON") # Force boost to search locations specified above - - message( STATUS "Serialbox: find_dependency(Boost ${SERIALBOX_BOOST_VERSION} COMPONENTS ${SERIALBOX_REQUIRED_BOOST_COMPONENTS})") - find_dependency(Boost - ${SERIALBOX_BOOST_VERSION} COMPONENTS ${SERIALBOX_REQUIRED_BOOST_COMPONENTS}) + message( STATUS "Serialbox: find_dependency(Boost ${SERIALBOX_BOOST_VERSION})") + find_dependency(Boost ${SERIALBOX_BOOST_VERSION}) if(Boost_FOUND) list(APPEND SERIALBOX_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}) else() # Give some diagnostic infos set(WARN_STR "Serialbox: Boost (${SERIALBOX_BOOST_VERSION}) NOT found!") - - if(DEFINED Boost_LIB_VERSION) - string(REPLACE "_" "." FOUND_BOOST_VERSION ${Boost_LIB_VERSION}) - list(APPEND WARN_STR " (Found Boost ${FOUND_BOOST_VERSION})") - endif() - - list(APPEND WARN_STR "\nRequired components:") - - foreach(component ${SERIALBOX_REQUIRED_BOOST_COMPONENTS}) - list(APPEND WARN_STR "\n - ${component}") - endforeach() - message(WARNING ${WARN_STR} "\n") endif() diff --git a/docs/sphinx/Building.rst b/docs/sphinx/Building.rst index 1b18b0ae..d9fc920e 100644 --- a/docs/sphinx/Building.rst +++ b/docs/sphinx/Building.rst @@ -12,7 +12,7 @@ Serialbox relies on `CMake `_ (>= 3.1), a cross-platform Quick start =========== -To build Serialbox you need a C++17 toolchain, `CMake `_ and a fairly recent version of `Boost `_. We use here the command-line, non-interactive CMake interface. +To build Serialbox you need a C++17 toolchain, `CMake `_ and `Boost `_ headers. We use here the command-line, non-interactive CMake interface. #. Make sure you have installed all the tools and dependencies, especially Boost and CMake. See `Dependencies`_. diff --git a/docs/sphinx/C.rst b/docs/sphinx/C.rst index 5b7e62ff..70bbca63 100644 --- a/docs/sphinx/C.rst +++ b/docs/sphinx/C.rst @@ -30,7 +30,7 @@ Consider the following minimalistic example, ``test.c``, which simply creates an serialboxSerializerDestroy(serializer); } -To compile this sample program, you have to link against ``SerialboxC`` and the dependency libraries. The dependency libraries include the Boost libraries (filesystem, system, chrono, log, date_time, log_setup, thread, regex and atomic) as well as the NetCDF and OpenSSL libraries. However, if you choose to link dynamically (i.e against ``libSerialboxC.so``), the dependencies will be resolved automatically: +To compile this sample program, you have to link against ``SerialboxC`` and the dependency libraries. The dependency libraries include the NetCDF and OpenSSL libraries. However, if you choose to link dynamically (i.e against ``libSerialboxC.so``), the dependencies will be resolved automatically: .. code-block:: console @@ -39,4 +39,3 @@ To compile this sample program, you have to link against ``SerialboxC`` and the $ export LD_LIBRARY_PATH=$SERIALBOX_INSTALL_PATH/lib; ./test In general, it is **strongly** advised to use the CMake find_package-module of Serialbox which takes care of linking against the correct libraries (see :doc:`Usage`). - diff --git a/docs/sphinx/Fortran.rst b/docs/sphinx/Fortran.rst index 6bdacb83..64101898 100644 --- a/docs/sphinx/Fortran.rst +++ b/docs/sphinx/Fortran.rst @@ -28,7 +28,6 @@ The CMake build system of Serialbox takes care of setting the correct flags for Using the Fortran Interface =========================== -To use the Fortran interface in your project, you need to link against ``libSerialboxFortran`` and the C++ standard library used to compile the code (e.g ``libstdc++`` for GNU gcc) as well as the dependency libraries (Boost and possibly NetCDF and OpenSSL). As this can be tedious, Serialbox provides a CMake find_package module (:ref:`FindSerialbox`) to handle this task. +To use the Fortran interface in your project, you need to link against ``libSerialboxFortran`` and the C++ standard library used to compile the code (e.g ``libstdc++`` for GNU gcc) as well as the dependency libraries (possibly NetCDF and OpenSSL). As this can be tedious, Serialbox provides a CMake find_package module (:ref:`FindSerialbox`) to handle this task. To use the preprocessing script ``pp_ser.py``, take a look at the CMake module :ref:`SerialboxTooling`. For a self-contained example see ``examples/fortran/perturbation``. - diff --git a/docs/sphinx/Usage.rst b/docs/sphinx/Usage.rst index 962541a1..477ef024 100644 --- a/docs/sphinx/Usage.rst +++ b/docs/sphinx/Usage.rst @@ -32,9 +32,8 @@ Example to find Serialbox headers and `shared` libraries for the C, C++ and Fort set(SERIALBOX_USE_SHARED_LIBS ON) find_package(Serialbox REQUIRED COMPONENTS C++ C Fortran) -The Serialbox module will look for the `exact` boost version used during compilation and append -the necessary libraries to the ``SERIALBOX_[LANGUAGE]_LIBRARIES`` variable. If Serialbox was -compiled with OpenSSL and/or NetCDF support, the necessary libraries will be appended as well. +If Serialbox was compiled with OpenSSL and/or NetCDF support, +the necessary libraries will be appended to the ``SERIALBOX_[LANGUAGE]_LIBRARIES``. Variables used by this module, they can change the default behaviour and need to be set before calling find_package:: @@ -61,7 +60,6 @@ Variables defined by this module:: SERIALBOX_FORTRAN_LIBRARIES - The Fortran libraries of Serialbox (libSerialboxFortran) and possibly the external libraries. SERIALBOX_PPSER - Path to the pp_ser.py script. - SERIALBOX_BOOST_VERSION - Boost version used during compilation. SERIALBOX_HAS_OPENSSL - Serialbox was compiled with OpenSSL support. SERIALBOX_HAS_NETCDF - Serialbox was compiled with NetCDF support. @@ -78,4 +76,3 @@ Function arguments:: SOURCES - Sources to preprocess OUTPUT_DIR - Output directory of the the source files. If nothing is specified ${PROJECT_BINARY_DIR}/pp is used. - diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f1f65515..1848643b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,7 +23,6 @@ function(serialbox_add_gridtools_example NAME) SerialboxStatic GridTools::gridtools ${CMAKE_THREAD_LIBS_INIT}) - target_compile_definitions(${NAME} PUBLIC BOOST_NO_CXX11_DECLTYPE) install(TARGETS ${NAME} DESTINATION bin) if(SERIALBOX_TESTING) serialbox_add_test(TARGET ${NAME} EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}) diff --git a/src/serialbox-c/CMakeLists.txt b/src/serialbox-c/CMakeLists.txt index ba59fa95..dd2cbeb3 100644 --- a/src/serialbox-c/CMakeLists.txt +++ b/src/serialbox-c/CMakeLists.txt @@ -53,7 +53,7 @@ if(SERIALBOX_ENABLE_C) FortranWrapper.h ) - set(EXTERNAL_LIBRARIES ${Boost_LIBRARIES} ${SERIALBOX_EXTERNAL_LIBRARIES}) + set(EXTERNAL_LIBRARIES ${SERIALBOX_EXTERNAL_LIBRARIES}) add_library(SerialboxCObjects OBJECT ${SOURCES}) target_include_directories(SerialboxCObjects diff --git a/src/serialbox/core/Config.h.cmake b/src/serialbox/core/Config.h.cmake index ffa9c2e8..dc880dc7 100644 --- a/src/serialbox/core/Config.h.cmake +++ b/src/serialbox/core/Config.h.cmake @@ -34,9 +34,6 @@ /* SERIALBOX version string */ #define SERIALBOX_VERSION_STRING "${Serialbox_VERSION_MAJOR}.${Serialbox_VERSION_MINOR}.${Serialbox_VERSION_PATCH}" -/* Boost version used during compilation */ -#define SERIALBOX_BOOST_VERSION ${SERIALBOX_BOOST_VERSION} - /* Define if OpenSSL is available */ #cmakedefine SERIALBOX_HAS_OPENSSL ${SERIALBOX_HAS_OPENSSL} @@ -47,4 +44,3 @@ #cmakedefine SERIALBOX_HAS_LOGGING ${SERIALBOX_HAS_LOGGING} #endif - diff --git a/test/benchmark/CMakeLists.txt b/test/benchmark/CMakeLists.txt index 7d850f16..616a5bde 100644 --- a/test/benchmark/CMakeLists.txt +++ b/test/benchmark/CMakeLists.txt @@ -15,8 +15,7 @@ set(SOURCES ) # Setup external libraries -set(EXTERNAL_LIBRARIES ${Boost_LIBRARIES} - ${GTEST_LIBRARIES} +set(EXTERNAL_LIBRARIES ${GTEST_LIBRARIES} ${SERIALBOX_OLD_LIBRARIES}) serialbox_add_unittest_executable(NAME SerialboxBenchmarkUnittest diff --git a/test/serialbox-fortran/CMakeLists.txt b/test/serialbox-fortran/CMakeLists.txt index f441beb3..4a8860b0 100644 --- a/test/serialbox-fortran/CMakeLists.txt +++ b/test/serialbox-fortran/CMakeLists.txt @@ -19,7 +19,6 @@ endif() # Setup external libraries set(EXTERNAL_LIBRARIES SerialboxFortranStatic SerialboxCStatic - ${Boost_LIBRARIES} ${SERIALBOX_EXTERNAL_LIBRARIES} )