diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 6d7d0122..b57c31f7 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -1,44 +1,99 @@ -name: CI Test +name: CI -on: [push, pull_request] +on: [pull_request] jobs: - bst1-82-0: - runs-on: ubuntu-latest - env: - METALL_LIMIT_MAKE_PARALLELS: 8 + build: + strategy: + fail-fast: false + matrix: + config: + - name: linux-x64-clang-15 + os: ubuntu-22.04 + cxx: clang++-15 + - name: linux-x64-clang-16 + os: ubuntu-20.04 + cxx: clang++-16 + + #- name: linux-x64-clang-16-sanitize-address-undefined + # os: ubuntu-20.04 + # cxx: clang++-16 + # cxx-flags: "-fsanitize=address,undefined" + #- name: linux-x64-clang-16-sanitize-thread + # os: ubuntu-20.04 + # cxx: clang++-16 + # cxx-flags: "-fsanitize=thread" + + - name: linux-x64-gcc-13 + os: ubuntu-22.04 + cxx: g++-13 + cxx-flags: -Werror + + name: ${{matrix.config.name}} + runs-on: ${{matrix.config.os}} steps: - - uses: actions/checkout@v3 - - name: Test + # setup env + - name: Add repos for for gcc-13 and clang-16 run: | - pushd /dev/shm - wget -q https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz - mkdir boost - tar xf boost_1_82_0.tar.gz -C boost --strip-components 1 - export BOOST_ROOT=${PWD}/boost - popd - export METALL_TEST_DIR=${GITHUB_JOB} - export CC=gcc-12 - export CXX=g++-12 - cd $GITHUB_WORKSPACE - bash ./scripts/CI/build_and_test.sh - - bst1-64-0: - runs-on: ubuntu-latest - env: - METALL_LIMIT_MAKE_PARALLELS: 8 - steps: - - uses: actions/checkout@v3 - - name: Test + # gcc-13 + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + + # clang-16 + source /etc/os-release + echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-16 main" | sudo tee /etc/apt/sources.list.d/llvm-16.list + curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-16.gpg > /dev/null + + - name: Ensure stdlib version run: | - pushd /dev/shm - wget -q https://boostorg.jfrog.io/artifactory/main/release/1.64.0/source/boost_1_64_0.tar.gz - mkdir boost - tar xf boost_1_64_0.tar.gz -C boost --strip-components 1 - export BOOST_ROOT=${PWD}/boost - popd - export METALL_TEST_DIR=${GITHUB_JOB} - export CC=gcc-12 - export CXX=g++-12 - cd $GITHUB_WORKSPACE - bash ./scripts/CI/build_and_test.sh + sudo apt-get install -y libstdc++-13-dev + + - name: Install tools + run: | + sudo apt-get install -y python3 python3-pip + + - name: Get minimum cmake version + uses: lukka/get-cmake@v3.24.3 + with: + cmakeVersion: 3.22.6 + + - name: Install compiler + id: install_cc + uses: rlalik/setup-cpp-compiler@v1.2 + with: + compiler: ${{ matrix.config.cxx }} + + - name: Install mold + uses: rui314/setup-mold@v1 + + - name: Configure conan + run: | + pip3 install "conan==1.60.1" + conan profile new --detect default + conan profile update settings.compiler.libcxx=libstdc++11 default + + - name: Cache conan data + id: cache-conan + uses: actions/cache@v3 + with: + path: ~/.conan/data + key: ${{ matrix.config.os }}-${{ matrix.config.cxx }}-conan + + - name: Check out sources + uses: actions/checkout@v3 + + - name: Configure CMake + env: + CC: ${{ steps.install_cc.outputs.cc }} + CXX: ${{ steps.install_cc.outputs.cxx }} + CXXFLAGS: ${{ matrix.config.cxx-flags }} + run: > + cmake -B build_dir -DCMAKE_BUILD_TYPE=Debug -DBUILD_FFI=ON -DBUILD_TESTING=ON + -DBUILD_VERIFICATION=ON -DBUILD_EXAMPLES=ON -DRUN_LARGE_SCALE_TESTS=ON -DBUILD_UTILITY=ON + + - name: Build + working-directory: build_dir + run: cmake --build . --parallel 2 + + - name: Run tests + working-directory: build_dir + run: ctest --parallel 2 --verbose diff --git a/.github/workflows/publish-conan-branch-package.yml b/.github/workflows/publish-conan-branch-package.yml new file mode 100644 index 00000000..6c167ed7 --- /dev/null +++ b/.github/workflows/publish-conan-branch-package.yml @@ -0,0 +1,21 @@ +name: Publish Conan branch package + +on: [ push ] + +concurrency: + group: publish-conan-branch-package-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + publish-conan-branch-package: + uses: dice-group/cpp-conan-release-reusable-workflow/.github/workflows/publish-conan-branch-package.yml@main + with: + public_artifactory: true + os: ubuntu-22.04 + compiler: clang-15 + cmake-version: 3.22.6 + conan-version: 2.0.13 + conan-options: -o boost/*:header_only=True + secrets: + CONAN_USER: ${{ secrets.CONAN_USER }} + CONAN_PW: ${{ secrets.CONAN_PW }} diff --git a/.gitignore b/.gitignore index 1a621962..5f8a5128 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ cmake-build-*/ .idea *~ ~* -.vscode/ \ No newline at end of file +.vscode/ +test_package/build/ +test_package/CMakeUserPresets.json \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 47c65f4f..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,162 +0,0 @@ -# GitLab CI YML file dedicated for LC environment (Quartz) -# -# Spack must be available -# It would be better to install all Boost versions manually, -# as it causes errors often and could exceed the timelimit of the system. -# -# One might want to change the location of builds directory on LC clusters to avoid consuming the home directory space. -# Type the following command on an LC cluster: -# $ ln -s /usr/workspace/lc-username ~/.gitlab-runner - -stages: - - install - - build - - -variables: - GTEST_COLOR: "1" - GIT_DEPTH: 0 - - -install_boost: - stage: install - tags: - - quartz - - shell - script: - - hostname - - srun -N1 -ppdebug spack install boost@1.82.0 boost@1.81.0 boost@1.80.0 boost@1.79.0 boost@1.78.0 boost@1.77.0 boost@1.76.0 boost@1.75.0 boost@1.74.0 boost@1.73.0 boost@1.72.0 boost@1.71.0 boost@1.70.0 boost@1.69.0 boost@1.68.0 boost@1.67.0 boost@1.66.0 boost@1.65.1 boost@1.65.0 boost@1.64.0 - - spack clean - - -.build: - stage: build - tags: - - quartz - - shell - script: - - echo "=== build section ===" - - module load gcc/${GCC_VERSION} - - spack load --first boost@${BOOST_VERSION} arch=$(spack arch) - - export METALL_TEST_DIR="/dev/shm/metall_test-${CI_CONCURRENT_ID}-${CI_PIPELINE_IID}" - - srun -N1 -ppdebug bash ./scripts/CI/build_and_test.sh - -build_gcc12.1.1_bst1.82.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.82.0" - -build_gcc12.1.1_bst1.81.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.81.0" - -build_gcc12.1.1_bst1.80.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.80.0" - -build_gcc12.1.1_bst1.79.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.79.0" - -build_gcc12.1.1_bst1.78.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.78.0" - -build_gcc12.1.1_bst1.77.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.77.0" - -build_gcc12.1.1_bst1.76.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.76.0" - -build_gcc12.1.1_bst1.75.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.75.0" - -build_gcc12.1.1_bst1.74.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.74.0" - -build_gcc12.1.1_bst1.73.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.73.0" - -build_gcc12.1.1_bst1.72.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.72.0" - -build_gcc12.1.1_bst1.71.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.71.0" - -build_gcc12.1.1_bst1.70.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.70.0" - -build_gcc12.1.1_bst1.69.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.69.0" - -build_gcc12.1.1_bst1.68.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.68.0" - -build_gcc12.1.1_bst1.67.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.67.0" - -build_gcc12.1.1_bst1.66.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.66.0" - -build_gcc12.1.1_bst1.65.1: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.65.1" - -build_gcc12.1.1_bst1.65.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.65.0" - -build_gcc12.1.1_bst1.64.0: - extends: .build - variables: - GCC_VERSION: "12.1.1" - BOOST_VERSION: "1.64.0" \ No newline at end of file diff --git a/CITATION.cff b/CITATION.cff index b81eda64..da9f03ca 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -24,7 +24,7 @@ authors: identifiers: - type: url value: 'https://doi.org/10.11578/dc.20190410.1' -repository-code: 'https://github.com/LLNL/metall' +repository-code: 'https://github.com/LLNL/copperr' abstract: >- Metall is a persistent memory allocator built on top of the memory-mapped file mechanism. diff --git a/CMakeLists.txt b/CMakeLists.txt index cc61d4c6..6c87a5d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,211 +1,57 @@ -cmake_minimum_required(VERSION 3.12) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -include(FetchContent) +cmake_minimum_required(VERSION 3.22) +project(copperr VERSION 0.26.1 + DESCRIPTION "A persistent memory allocator for data-centric analytics") -# -------------------------------------------------------------------------------- # -# CMake policy -# -------------------------------------------------------------------------------- # -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") - cmake_policy(SET CMP0077 NEW) -endif() +include(cmake/boilerplate_init.cmake) +boilerplate_init() -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") - cmake_policy(SET CMP0135 NEW) -endif() +option(WITH_DEFAULT_LOGGER "build and use copperrs's default logger" ON) +option(BUILD_FFI "build foreign function interface" OFF) +option(BUILD_TESTING "build tests" OFF) +option(BUILD_UTILITY "build utility executables" OFF) +option(BUILD_EXAMPLES "build example executables" OFF) +option(BUILD_BENCHMARKS "build benchmarks" OFF) +option(BUILD_VERIFICATION "build verification executables" OFF) +option(RUN_LARGE_SCALE_TESTS "build and run large scale tests" OFF) -# -------------------------------------------------------------------------------- # -# Metall general configuration -# -------------------------------------------------------------------------------- # -project(Metall - VERSION 0.26 - DESCRIPTION "A persistent memory allocator for data-centric analytics" - HOMEPAGE_URL "https://github.com/LLNL/metall") - -configure_file(MetallConfig.h.in MetallConfig.h) - -# ----- Setting up a INTERFACE library to install header files ----- # -include(GNUInstallDirs) -add_library(${PROJECT_NAME} INTERFACE) -add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -target_include_directories(${PROJECT_NAME} - INTERFACE $ - $) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) -set(CMAKE_CXX_EXTENSIONS OFF) - -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}_Targets - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - -install(EXPORT ${PROJECT_NAME}_Targets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) - -install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/metall DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - -# -------------------------------------------------------------------------------- # -# Generate and install the package configuration and package version files -# -------------------------------------------------------------------------------- # -include(CMakePackageConfigHelpers) - -# generate the version file for the config file -write_basic_package_version_file( - "${PROJECT_NAME}ConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY ExactVersion) - -# create config file -configure_package_config_file( - "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) - -# install config files -install(FILES - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) -# -------------------------------------------------------------------------------- # - - -# -------------------------------------------------------------------------------- # -# Configuration for building test, benchmark, example, etc. -# ---------- -# User configurable options -# -------------------------------------------------------------------------------- # -option(JUST_INSTALL_METALL_HEADER "Just install Metall header files (do not build anything)" OFF) -option(BUILD_UTILITY "Build utility programs" OFF) -option(BUILD_DOC "Build API documentation" OFF) -option(BUILD_C "Build C examples and libraries" OFF) -option(BUILD_EXAMPLE "Build the examples" OFF) -option(BUILD_TEST "Build the test" OFF) -option(RUN_LARGE_SCALE_TEST "Run large scale tests" OFF) -option(RUN_BUILD_AND_TEST_WITH_CI "Perform build and basic test with CI" OFF) -option(BUILD_BENCH "Build the benchmark" OFF) -option(BUILD_VERIFICATION "Build verification programs" OFF) -set(COMPILER_DEFS "" CACHE STRING "A list of Metall compile definitions to be added to all targets") +set(COMPILER_DEFS "" CACHE STRING + "A list of Metall compile definitions to be added to all targets. For a list of valid values see docs/readthedocs/basics/compile_time_options.md.") # ---------- Experimental options ---------- # set(UMAP_ROOT "" CACHE PATH "UMap installed root directory") -option(ONLY_DOWNLOAD_GTEST "Only downloading Google Test" OFF) -option(SKIP_DOWNLOAD_GTEST "Skip downloading Google Test" OFF) -option(BUILD_NUMA "Build programs that require the NUMA policy library (numa.h)" OFF) - -# -------------------------------------------------------------------------------- # - -# -------------------------------------------------------------------------------- # -# Only downloading Google Test -# -------------------------------------------------------------------------------- # -if (ONLY_DOWNLOAD_GTEST) - add_subdirectory(test) - return() -endif () -# -------------------------------------------------------------------------------- # - -# -------------------------------------------------------------------------------- # -# Exit before building anything -# -------------------------------------------------------------------------------- # -if (INSTALL_HEADER_ONLY) - message(WARNING "INSTALL_HEADER_ONLY option has been replaced with JUST_INSTALL_METALL_HEADER.") -endif() - -if (JUST_INSTALL_METALL_HEADER) - return() -endif() -# -------------------------------------------------------------------------------- # - -# -------------------------------------------------------------------------------- # -# Exit CMake if there is nothing to build -# -------------------------------------------------------------------------------- # -if (NOT (BUILD_UTILITY OR BUILD_C OR BUILD_EXAMPLE OR BUILD_BENCH OR BUILD_TEST OR BUILD_VERIFICATION OR RUN_BUILD_AND_TEST_WITH_CI OR BUILD_DOC)) - return() -endif () -# -------------------------------------------------------------------------------- # - -# -------------------------------------------------------------------------------- # -# Document (Doxygen) -# -------------------------------------------------------------------------------- # -if (BUILD_DOC) - include(build_doc) - build_doc() -endif () -# -------------------------------------------------------------------------------- # -# -------------------------------------------------------------------------------- # -# Executables -# -------------------------------------------------------------------------------- # +OPTION(USE_CONAN "If available, use conan to retrieve dependencies." ON) +if (PROJECT_IS_TOP_LEVEL AND USE_CONAN) + include(cmake/conan_cmake.cmake) + if (BUILD_TESTING) + set(CONAN_METALL_WITH_TEST_DEPS "True") + else() + set(CONAN_METALL_WITH_TEST_DEPS "False") + endif() -# Requirements for GCC -if (NOT RUN_BUILD_AND_TEST_WITH_CI) - if (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1) - message(FATAL_ERROR "GCC version must be at least 8.1") - endif () + if (BUILD_FFI) + set(CONAN_METALL_BUILD_FFI "True") + else () + set(CONAN_METALL_BUILD_FFI "False") endif () -endif () - -# ---------- Metall Macros ---------- # -foreach(X ${COMPILER_DEFS}) - message(STATUS "Metall compile definition: ${X}") -endforeach() + if (WITH_DEFAULT_LOGGER) + set(CONAN_METALL_WITH_DEFAULT_LOGGER "True") + else () + set(CONAN_METALL_WITH_DEFAULT_LOGGER "False") + endif () -# ---------- CMAKE_BUILD_TYPE ---------- # -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) - message(STATUS "CMAKE_BUILD_TYPE is set as Release") + set(CONAN_OPTIONS "with_test_deps=${CONAN_METALL_WITH_TEST_DEPS};build_ffi=${CONAN_METALL_BUILD_FFI};with_default_logger=${CONAN_METALL_WITH_DEFAULT_LOGGER}") + install_packages_via_conan("${CMAKE_SOURCE_DIR}/conanfile.py" "${CONAN_OPTIONS};boost/*:header_only=True") endif () - -# ---------- Threads ---------- # +find_package(Boost REQUIRED COMPONENTS) find_package(Threads REQUIRED) - -# ---------- filesystem ---------- # -include(include_cxx_filesystem_library) -include_cxx_filesystem_library() - -# Xcode 11 Beta Release Notes -# Clang now supports the C++17 library for iOS 13, macOS 10.15, watchOS 6, and tvOS 13. (50988273) -# https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_release_notes?language=objc - - -# ---------- UMap ---------- # -if (UMAP_ROOT) - if (UNIX AND NOT APPLE) - find_library(LIBUMAP NAMES umap PATHS ${UMAP_ROOT}/lib) - endif () -endif () - - -# ---------- Boost ---------- # -# Disable the boost-cmake feature (BoostConfig.cmake or boost-config.cmake) since -# there is a tricky behavior/issue especially in Boost 1.70.0. -set(Boost_NO_BOOST_CMAKE ON) - -find_package(Boost 1.64 QUIET) -if (NOT Boost_FOUND) - FetchContent_Declare(Boost - URL https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.tar.bz2) - FetchContent_GetProperties(Boost) - if (NOT Boost_POPULATED) - FetchContent_Populate(Boost) - endif () - set(BOOST_ROOT ${boost_SOURCE_DIR}) - find_package(Boost 1.64) -endif () - -# -------------------------------------------------------------------------------- # -# Add executable functions -# -------------------------------------------------------------------------------- # function(add_common_compile_options name) # Common + set_target_properties(${name} PROPERTIES CXX_STANDARD 20) target_compile_options(${name} PRIVATE -Wall) # Debug @@ -228,41 +74,18 @@ function(add_common_compile_options name) endif () endfunction() -function(common_setup_for_metall_executable name) - target_include_directories(${name} PRIVATE ${Boost_INCLUDE_DIRS}) - - target_link_libraries(${name} PRIVATE Threads::Threads) - - # ----- Compile Options ----- # +function(common_setup_for_copperr_executable name) + target_link_libraries(${name} + PRIVATE + ${PROJECT_NAME}::${PROJECT_NAME} + -Wl,--whole-archive ${PROJECT_NAME}::default-logger -Wl,--no-whole-archive + ) add_common_compile_options(${name}) - # Memo: - # On macOS and FreeBSD libc++ is the default standard library and the -stdlib=libc++ is not required. - # https://libcxx.llvm.org/docs/UsingLibcxx.html - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND - NOT (CMAKE_CXX_COMPILER_ID MATCHES "Darwin" OR CMAKE_CXX_COMPILER_ID MATCHES "FreeBSD")) - target_compile_options(${name} PRIVATE -stdlib=libc++) - endif () - # -------------------- - - # ----- Compile Definitions ----- # foreach(X ${COMPILER_DEFS}) - target_compile_definitions(${name} PRIVATE ${X}) + target_compile_definitions(${name} PRIVATE ${X}) endforeach() - # -------------------- - - # ----- CXX17 Filesystem Lib----- # - # include_cxx_filesystem_library module must be executed first - if (FOUND_CXX17_FILESYSTEM_LIB) - if (REQUIRE_LIB_STDCXX_FS) - target_link_libraries(${name} PRIVATE stdc++fs) - endif() - elseif() - target_compile_definitions(${name} PRIVATE "METALL_DISABLE_CXX17_FILESYSTEM_LIB") - endif() - # -------------------- - # ----- Umap----- # if (UMAP_ROOT) target_include_directories(${name} PRIVATE ${UMAP_ROOT}/include) if (LIBUMAP) @@ -270,44 +93,41 @@ function(common_setup_for_metall_executable name) target_compile_definitions(${name} PRIVATE "METALL_USE_UMAP") endif () endif () - # -------------------- endfunction() -function(add_metall_executable name source) - set(ADDED_METALL_EXE FALSE PARENT_SCOPE) # Tell the caller if an executable is added w/o issue +function(add_copperr_executable name source) + add_executable(${name} ${source}) + common_setup_for_copperr_executable(${name}) +endfunction () - if (Boost_FOUND) - add_executable(${name} ${source}) - target_include_directories(${name} PRIVATE ${PROJECT_SOURCE_DIR}/include) - common_setup_for_metall_executable(${name}) - set(ADDED_METALL_EXE TRUE PARENT_SCOPE) - endif () -endfunction() +add_subdirectory(libs) -function(add_c_executable name source) - add_executable(${name} ${source}) - add_common_compile_options(${name}) -endfunction() +if (PROJECT_IS_TOP_LEVEL) + if (BUILD_DOC) + include(cmake/build_doc.cmake) + build_doc() + endif () -# -------------------------------------------------------------------------------- # -# Build tree -# -------------------------------------------------------------------------------- # -add_subdirectory(src) + if (BUILD_TESTING) + include(CTest) + enable_testing() + add_subdirectory(tests) + endif () -if (BUILD_EXAMPLE) - add_subdirectory(example) -endif () + if (BUILD_EXAMPLES) + add_subdirectory(examples) + endif () -if (BUILD_BENCH) - add_subdirectory(bench) -endif () + if (BUILD_VERIFICATION) + add_subdirectory(verification) + endif () -if (BUILD_TEST) - enable_testing() - add_subdirectory(test) -endif () + if (BUILD_BENCHMARKS) + add_subdirectory(bench) + endif () -if (BUILD_VERIFICATION) - add_subdirectory(verification) + if (BUILD_UTILITY) + add_subdirectory(execs) + endif () endif () diff --git a/MetallConfig.h.in b/MetallConfig.h.in deleted file mode 100644 index 10a79983..00000000 --- a/MetallConfig.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#define METALL_VERSION_MAJOR @Metall_VERSION_MAJOR@ -#define METALL_VERSION_MINOR @Metall_VERSION_MINOR@ \ No newline at end of file diff --git a/README.md b/README.md index 68d32525..d54b8942 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -[![CI Test](https://github.com/LLNL/metall/actions/workflows/ci-test.yml/badge.svg?branch=master)](https://github.com/LLNL/metall/actions/workflows/ci-test.yml) -[![Documentation Status](https://readthedocs.org/projects/metall/badge/?version=latest)](https://metall.readthedocs.io/en/latest/?badge=latest) -[![Deploy API Doc](https://github.com/LLNL/metall/actions/workflows/deploy-api-doc.yml/badge.svg?branch=master)](https://github.com/LLNL/metall/actions/workflows/deploy-api-doc.yml) +[![Documentation Status](https://readthedocs.org/projects/metall/badge/?version=latest)](https://copperr.readthedocs.io/en/latest/?badge=latest) +[![Deploy API Doc](https://github.com/LLNL/copperr/actions/workflows/deploy-api-doc.yml/badge.svg?branch=master)](https://github.com/LLNL/metall/actions/workflows/deploy-api-doc.yml) -Metall: A Persistent Memory Allocator for Data-Centric Analytics +Copperr: A Persistent Memory Allocator for Data-Centric Analytics based on Metall =============================================== +* Copper is based on [Metall](https://github.com/LLNL/metall) but will be adapted to the needs of dice-group over time * Provides rich memory allocation interfaces for C++ applications that use persistent memory devices to persistently store heap data on such devices. @@ -12,94 +12,74 @@ Metall: A Persistent Memory Allocator for Data-Centric Analytics space so that users can access the mapped region just as normal memory regions allocated in DRAM. * Actual persistent memory hardware could be any non-volatile memory (NVM) with file system support. -* To provide persistent memory allocation, Metall employs concepts and +* To provide persistent memory allocation, Copperr employs concepts and APIs developed by [Boost.Interprocess](https://www.boost.org/doc/libs/1_69_0/doc/html/interprocess.html). * Supports multi-thread * Also provides a space-efficient snapshot/versioning, leveraging reflink - copy mechanism in filesystem. In case reflink is not supported, Metall + copy mechanism in filesystem. In case reflink is not supported, Copperr automatically falls back to regular copy. * See details: [Metall overview slides](docs/publications/metall_101.pdf). # Getting Started -Metall consists of only header files and requires some header files in Boost C++ Libraries. +Copperr consists of only header files and requires some header files in Boost C++ Libraries. All core files exist under -[metall/include/metall/](https://github.com/LLNL/metall/tree/master/include/metall). +[copperr/include/copperr/](https://github.com/dice-group/copperr/tree/master/include/copperr). ## Required -- Boost C++ Libraries 1.64 or more. +- Boost C++ Libraries >=1.64. - Build is not required; needs only their header files. - - To use JSON containers in Metall, Boost C++ Libraries 1.75 or more is required. -- C++17 compiler - - Tested with GCC 8.1 or more; however, 8.3 or more is recommended due to early implementation of the C++ Filesystem library. + - To use JSON containers in Copperr, Boost C++ Libraries >=1.75 is required. +- C++20 compiler + - Tested with GCC>=13 / Clang>=15 -## Build +## Usage with conan -To build your program with Metall, all you have to do is just setting include paths such as '-I' or CPLUS_INCLUDE_PATH. - -For example, - -```bash -# Download Boost (Boost C++ Libraries 1.64 or more is required) -# One can skip this step if Boost is already available. -wget https://boostorg.jfrog.io/artifactory/main/release/1.78.0/source/boost_1_78_0.tar.gz -tar xvf boost_1_78_0.tar.gz -export BOOST_ROOT=$PWD/boost_1_78_0 - -git clone https://github.com/LLNL/metall -export METALL_INCLUDE=$PWD/metall/include - -g++ -std=c++17 your_program.cpp -lstdc++fs -I${BOOST_ROOT} -I${METALL_INCLUDE} +You need the package manager Conan installed and set up. You can add the DICE artifactory with: +```shell +conan remote add dice-group https://conan.dice-research.org/artifactory/api/conan/tentris ``` -### Unofficial Support For Clang -Clang can be used instead of GCC to build Metall. -However, we haven't tested it intensively. -Also, Boost C++ Libraries 1.69 or more may be required -if one wants to build Metall with Clang + CUDA. - -## Metall with Spack - -Metall package is also available on [Spack](https://spack.io/). - -As Metall depends on Boost C++ Libraries, -Spack also installs a proper version of Boost C++ Libraries automatically, if needed. +To use copperr, add it to your conanfile.txt: +```shell +[requires] +copperr/0.0.x +``` -```bash -# Install Metall and Boost C++ Libraries -spack install metall +### Defining a sink for the logger +To Use Copperr your application must define a logger sink for Copperr. +A reasonable default sink is provided via the Copperr::default_logger cmake target you can link against that +if you do not want to provide your own logger implementation. -# Sets environment variables: BOOST_ROOT and METALL_ROOT. -# Boost C++ Libraries and Metall are installed at the locations, respectively. -spack load metall +The interface you need to implement is defined in `include/logger_interface.h`. +For an example how to define such a sink see `src/default_logger.cpp`. -# Build a program that uses Metall -# Please note that one has to put 'include' at the end of BOOST_ROOT and METALL_ROOT -g++ -std=c++17 your_program.cpp -lstdc++fs -I${BOOST_ROOT}/include -I${METALL_ROOT}/include +If you don't you will get the following linker error: +``` +Error: Undefined reference to `copperr_log` ``` +## Use Copperr from Another CMake Project -## Use Metall from Another CMake Project - -To download and/or link Metall package from a CMake project, +To download and/or link Copperr package from a CMake project, see example CMake files placed [here](./example/cmake). # Build Example Programs -Metall repository contains some example programs under [example directory](./example). +Copperr repository contains some example programs under [example directory](./example). One can use CMake to build the examples. For more details, see a page -[here](https://metall.readthedocs.io/en/latest/advanced_build/cmake/). +[here](https://copperr.readthedocs.io/en/latest/advanced_build/cmake/). -# Documentations +# Documentation -- [Full documentation](https://metall.readthedocs.io/) -- [API documentation](https://software.llnl.gov/metall/api/) +- [Full documentation](https://copperr.readthedocs.io/) +- [API documentation](https://software.llnl.gov/copperr/api/) ## Generate API documentation using Doxygen @@ -108,18 +88,18 @@ A Doxygen configuration file is [here](docs/Doxyfile.in). To generate API document: ```bash -cd metall +cd copperr mkdir build_doc cd build_doc doxygen ../docs/Doxyfile.in ``` -# Publication +# Publication related to Metall ``` Keita Iwabuchi, Karim Youssef, Kaushik Velusamy, Maya Gokhale, Roger Pearce, -Metall: A persistent memory allocator for data-centric analytics, +Copperr: A persistent memory allocator for data-centric analytics, Parallel Computing, 2022, 102905, ISSN 0167-8191, https://doi.org/10.1016/j.parco.2022.102905. ``` @@ -130,14 +110,11 @@ Parallel Computing, 2022, 102905, ISSN 0167-8191, https://doi.org/10.1016/j.parc # About ## Contact - -- [GitHub Issues](https://github.com/LLNL/metall/issues) is open. - -- Primary contact: [Keita Iwabuchi (LLNL)](https://github.com/KIwabuchi). +- [GitHub Issues](https://github.com/dice-group/copperr/issues) are open. ## License -Metall is distributed under the terms of both the MIT license and the +Copperr is distributed under the terms of both the MIT license and the Apache License (Version 2.0). Users may choose either license, at their option. diff --git a/bench/adjacency_list/CMakeLists.txt b/bench/adjacency_list/CMakeLists.txt index e1d62bd2..e27c72aa 100644 --- a/bench/adjacency_list/CMakeLists.txt +++ b/bench/adjacency_list/CMakeLists.txt @@ -1,22 +1,22 @@ -include(setup_omp) +include(${CMAKE_SOURCE_DIR}/cmake/setup_omp) -add_metall_executable(run_adj_list_bench_stl run_adj_list_bench_stl.cpp) +add_copperr_executable(run_adj_list_bench_stl run_adj_list_bench_stl.cpp) setup_omp_target(run_adj_list_bench_stl) -add_metall_executable(run_adj_list_bench_bip run_adj_list_bench_bip.cpp) +add_copperr_executable(run_adj_list_bench_bip run_adj_list_bench_bip.cpp) setup_omp_target(run_adj_list_bench_bip) -add_metall_executable(run_adj_list_bench_bip_extend run_adj_list_bench_bip_extend.cpp) +add_copperr_executable(run_adj_list_bench_bip_extend run_adj_list_bench_bip_extend.cpp) setup_omp_target(run_adj_list_bench_bip_extend) -add_metall_executable(run_adj_list_bench_metall run_adj_list_bench_metall.cpp) -setup_omp_target(run_adj_list_bench_metall) +add_copperr_executable(run_adj_list_bench_copperr run_adj_list_bench_copperr.cpp) +setup_omp_target(run_adj_list_bench_copperr) -add_metall_executable(run_adj_list_bench_reflink_snapshot run_adj_list_bench_reflink_snapshot.cpp) +add_copperr_executable(run_adj_list_bench_reflink_snapshot run_adj_list_bench_reflink_snapshot.cpp) setup_omp_target(run_adj_list_bench_reflink_snapshot) if (MEMKIND_ROOT) - add_metall_executable(run_adj_list_bench_pmem run_adj_list_bench_pmem.cpp) + add_copperr_executable(run_adj_list_bench_pmem run_adj_list_bench_pmem.cpp) target_include_directories(run_adj_list_bench_pmem PRIVATE ${MEMKIND_ROOT}/include) if (UNIX AND NOT APPLE) find_library(LIBMEMKIND NAMES memkind PATHS ${MEMKIND_ROOT}/lib) diff --git a/bench/adjacency_list/bench_driver.hpp b/bench/adjacency_list/bench_driver.hpp index 48b5cf19..e2343b59 100644 --- a/bench/adjacency_list/bench_driver.hpp +++ b/bench/adjacency_list/bench_driver.hpp @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include "edge_generator/rmat_edge_generator.hpp" #include "../utility/pair_reader.hpp" #include "kernel.hpp" @@ -277,7 +277,7 @@ inline auto run_bench_rmat_edge(const bench_options::rmat_option &rmat_option, assert((int)input_storage.size() == (int)omp::get_num_threads()); auto &local_list = input_storage.at(omp::get_thread_num()); local_list.clear(); - const auto range = metall::mtlldetail::partial_range( + const auto range = dice::copperr::mtlldetail::partial_range( num_generate, omp::get_thread_num(), omp::get_num_threads()); auto &itr = generator_itr_list.at(omp::get_thread_num()); for (std::size_t i = range.first; i < range.second; ++i) { diff --git a/bench/adjacency_list/edge_generator/CMakeLists.txt b/bench/adjacency_list/edge_generator/CMakeLists.txt index 70d2eb61..9bf54e2e 100644 --- a/bench/adjacency_list/edge_generator/CMakeLists.txt +++ b/bench/adjacency_list/edge_generator/CMakeLists.txt @@ -1,2 +1,2 @@ -add_metall_executable(generate_rmat_edge_list generate_rmat_edge_list.cpp) -setup_omp_target(generate_rmat_edge_list) \ No newline at end of file +#add_copperr_executable(generate_rmat_edge_list generate_rmat_edge_list.cpp) +#setup_omp_target(generate_rmat_edge_list) \ No newline at end of file diff --git a/bench/adjacency_list/edge_generator/generate_rmat_edge_list.cpp b/bench/adjacency_list/edge_generator/generate_rmat_edge_list.cpp index bef45278..97df749f 100644 --- a/bench/adjacency_list/edge_generator/generate_rmat_edge_list.cpp +++ b/bench/adjacency_list/edge_generator/generate_rmat_edge_list.cpp @@ -7,8 +7,8 @@ #include #include -#include -#include +#include +#include #include "rmat_edge_generator.hpp" // ---------------------------------------- // @@ -94,21 +94,21 @@ int main(int argc, char **argv) { int num_threads = 1; parse_options(argc, argv, &rmat_option, &edge_list_file_name, &num_threads); - metall::utility::omp::set_num_threads(num_threads); + dice::copperrutility::omp::set_num_threads(num_threads); OMP_DIRECTIVE(parallel) { - const auto range = metall::mtlldetail::partial_range( - rmat_option.edge_count, metall::utility::omp::get_thread_num(), - metall::utility::omp::get_num_threads()); + const auto range = dice::copperr::mtlldetail::partial_range( + rmat_option.edge_count, dice::copperr::utility::omp::get_thread_num(), + dice::copperr::utility::omp::get_num_threads()); const std::size_t num_edges = range.second - range.first; edge_generator::rmat_edge_generator rmat( - rmat_option.seed + metall::utility::omp::get_thread_num(), + rmat_option.seed + dice::copperr::utility::omp::get_thread_num(), rmat_option.vertex_scale, num_edges, rmat_option.a, rmat_option.b, rmat_option.c, rmat_option.scramble_id, rmat_option.undirected); std::ofstream edge_list_file( edge_list_file_name + "-" + - std::to_string(metall::utility::omp::get_thread_num())); + std::to_string(dice::copperr::utility::omp::get_thread_num())); if (!edge_list_file.is_open()) { std::cerr << "Cannot open " << edge_list_file_name << std::endl; std::abort(); diff --git a/bench/adjacency_list/edge_generator/rmat_edge_generator.hpp b/bench/adjacency_list/edge_generator/rmat_edge_generator.hpp index 056c7185..8c9d2aef 100644 --- a/bench/adjacency_list/edge_generator/rmat_edge_generator.hpp +++ b/bench/adjacency_list/edge_generator/rmat_edge_generator.hpp @@ -12,8 +12,8 @@ #include #include -#include -#include +#include +#include namespace edge_generator { @@ -21,7 +21,7 @@ namespace edge_generator { template class rmat_edge_generator_iterator { private: - using rnd_generator_type = metall::utility::rand_512; + using rnd_generator_type = dice::copperr::utility::rand_512; public: using value_type = std::pair; @@ -94,9 +94,9 @@ class rmat_edge_generator_iterator { const uint64_t mask = (1ULL << m_ptr_parent->m_vertex_scale) - 1; // Assume utility::hash is a good hash function m_current_edge.first = - metall::utility::hash<>()(m_current_edge.first) & mask; + dice::copperr::utility::hash<>()(m_current_edge.first) & mask; m_current_edge.second = - metall::utility::hash<>()(m_current_edge.second) & mask; + dice::copperr::utility::hash<>()(m_current_edge.second) & mask; } ++m_num_generated_edges; } diff --git a/bench/adjacency_list/kernel.hpp b/bench/adjacency_list/kernel.hpp index 625d48c0..554de069 100644 --- a/bench/adjacency_list/kernel.hpp +++ b/bench/adjacency_list/kernel.hpp @@ -8,15 +8,15 @@ #include -#include -#include -#include +#include +#include +#include namespace adjacency_list_bench { namespace { -namespace mdtl = metall::mtlldetail; -namespace omp = metall::utility::omp; +namespace mdtl = dice::copperr::mtlldetail; +namespace omp = dice::copperr::utility::omp; } // namespace inline void print_current_num_page_faults() { diff --git a/bench/adjacency_list/numa_aware_kernel.hpp b/bench/adjacency_list/numa_aware_kernel.hpp index d9589f83..8d29170a 100644 --- a/bench/adjacency_list/numa_aware_kernel.hpp +++ b/bench/adjacency_list/numa_aware_kernel.hpp @@ -6,15 +6,15 @@ #ifndef METALL_BENCH_ADJACENCY_LIST_NUMA_AWARE_KERNEL_HPP #define METALL_BENCH_ADJACENCY_LIST_NUMA_AWARE_KERNEL_HPP -#include -#include +#include +#include #include "../utility/numa.hpp" #include "kernel.hpp" namespace adjacency_list_bench { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } inline void configure_numa() { diff --git a/bench/adjacency_list/run_adj_list_bench_bip.cpp b/bench/adjacency_list/run_adj_list_bench_bip.cpp index 04282497..1c41436a 100644 --- a/bench/adjacency_list/run_adj_list_bench_bip.cpp +++ b/bench/adjacency_list/run_adj_list_bench_bip.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -26,7 +26,7 @@ using adjacency_list_type = data_structure::multithread_adjacency_list; -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; int main(int argc, char *argv[]) { bench_options option; diff --git a/bench/adjacency_list/run_adj_list_bench_bip_extend.cpp b/bench/adjacency_list/run_adj_list_bench_bip_extend.cpp index 8efa2aa5..588956df 100644 --- a/bench/adjacency_list/run_adj_list_bench_bip_extend.cpp +++ b/bench/adjacency_list/run_adj_list_bench_bip_extend.cpp @@ -13,8 +13,8 @@ #include #include -#include -#include +#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -33,17 +33,17 @@ using adjacency_list_type = allocator_type>; void *map_file(const std::string &backing_file_name, const size_t file_size) { - metall::mtlldetail::create_file(backing_file_name); - metall::mtlldetail::extend_file_size(backing_file_name, file_size); + dice::copperr::mtlldetail::create_file(backing_file_name); + dice::copperr::mtlldetail::extend_file_size(backing_file_name, file_size); - auto ret = metall::mtlldetail::map_file_write_mode(backing_file_name, nullptr, + auto ret = dice::copperr::mtlldetail::map_file_write_mode(backing_file_name, nullptr, file_size, 0); if (ret.first == -1) { std::cerr << "Failed to map a file" << std::endl; std::abort(); } - if (!metall::mtlldetail::os_close(ret.first)) { + if (!copperr::mtlldetail::os_close(ret.first)) { std::cerr << "Failed to close the file" << std::endl; std::abort(); } @@ -53,7 +53,7 @@ void *map_file(const std::string &backing_file_name, const size_t file_size) { void *map_anonymous(const size_t file_size) { void *ret = - metall::mtlldetail::os_mmap(nullptr, file_size, PROT_READ | PROT_WRITE, + dice::copperr::mtlldetail::os_mmap(nullptr, file_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (!ret) { std::cerr << "Failed to map an anonymous region" << std::endl; @@ -90,9 +90,9 @@ int main(int argc, char *argv[]) { run_bench(option, adj_list); - const auto start = metall::mtlldetail::elapsed_time_sec(); - metall::mtlldetail::os_msync(addr, option.segment_size, true); - const auto elapsed_time = metall::mtlldetail::elapsed_time_sec(start); + const auto start = dice::copperr::mtlldetail::elapsed_time_sec(); + dice::copperr::mtlldetail::os_msync(addr, option.segment_size, true); + const auto elapsed_time = dice::copperr::mtlldetail::elapsed_time_sec(start); std::cout << "sync_time (s)\t" << elapsed_time << std::endl; std::cout << "Segment usage (GB) " @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) { manager.get_free_memory()) / (1ULL << 30) << std::endl; - metall::mtlldetail::munmap(addr, option.segment_size, + dice::copperr::mtlldetail::munmap(addr, option.segment_size, !option.datastore_path_list.empty()); } diff --git a/bench/adjacency_list/run_adj_list_bench_metall.cpp b/bench/adjacency_list/run_adj_list_bench_metall.cpp index 61cdf3fe..44e1284c 100644 --- a/bench/adjacency_list/run_adj_list_bench_metall.cpp +++ b/bench/adjacency_list/run_adj_list_bench_metall.cpp @@ -7,8 +7,8 @@ #include #include -#include -#include +#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -18,7 +18,7 @@ using key_type = uint64_t; using value_type = uint64_t; using adj_list_t = data_structure::multithread_adjacency_list< - key_type, value_type, typename metall::manager::allocator_type>; + key_type, value_type, typename dice::copperr::manager::allocator_type>; int main(int argc, char *argv[]) { bench_options option; @@ -33,14 +33,14 @@ int main(int argc, char *argv[]) { // Stage in if (option.append && !option.staging_location.empty()) { - const auto start = metall::mtlldetail::elapsed_time_sec(); - metall::manager::copy(option.datastore_path_list[0].c_str(), + const auto start = dice::copperr::mtlldetail::elapsed_time_sec(); + dice::copperr::manager::copy(option.datastore_path_list[0].c_str(), option.staging_location.c_str()); - const auto elapsed_time = metall::mtlldetail::elapsed_time_sec(start); + const auto elapsed_time = dice::copperr::mtlldetail::elapsed_time_sec(start); std::cout << "\nStage in took (s)\t" << elapsed_time << std::endl; } - std::unique_ptr manager; + std::unique_ptr manager; // Bench main { @@ -48,9 +48,9 @@ int main(int argc, char *argv[]) { ? option.datastore_path_list[0] : option.staging_location; manager = (option.append) - ? std::make_unique(metall::open_only, + ? std::make_unique(dice::copperr::open_only, data_store_path.c_str()) - : std::make_unique(metall::create_only, + : std::make_unique(dice::copperr::create_only, data_store_path.c_str()); auto adj_list = @@ -63,26 +63,26 @@ int main(int argc, char *argv[]) { // Flush data { - const auto start = metall::mtlldetail::elapsed_time_sec(); + const auto start = dice::copperr::mtlldetail::elapsed_time_sec(); manager->flush(); - const auto elapsed_time = metall::mtlldetail::elapsed_time_sec(start); + const auto elapsed_time = dice::copperr::mtlldetail::elapsed_time_sec(start); std::cout << "Flushing data took (s)\t" << elapsed_time << std::endl; } // Close Metall { - const auto start = metall::mtlldetail::elapsed_time_sec(); + const auto start = dice::copperr::mtlldetail::elapsed_time_sec(); manager.reset(nullptr); - const auto elapsed_time = metall::mtlldetail::elapsed_time_sec(start); + const auto elapsed_time = dice::copperr::mtlldetail::elapsed_time_sec(start); std::cout << "Closing Metall took (s)\t" << elapsed_time << std::endl; } // Stage out if (!option.staging_location.empty()) { - const auto start = metall::mtlldetail::elapsed_time_sec(); - metall::manager::copy(option.staging_location.c_str(), + const auto start = dice::copperr::mtlldetail::elapsed_time_sec(); + dice::copperr::manager::copy(option.staging_location.c_str(), option.datastore_path_list[0].c_str()); - const auto elapsed_time = metall::mtlldetail::elapsed_time_sec(start); + const auto elapsed_time = dice::copperr::mtlldetail::elapsed_time_sec(start); std::cout << "Stage out took (s)\t" << elapsed_time << std::endl; } diff --git a/bench/adjacency_list/run_adj_list_bench_pmem.cpp b/bench/adjacency_list/run_adj_list_bench_pmem.cpp index 5cc9c9fa..70ebac74 100644 --- a/bench/adjacency_list/run_adj_list_bench_pmem.cpp +++ b/bench/adjacency_list/run_adj_list_bench_pmem.cpp @@ -9,8 +9,8 @@ #include -#include -#include +#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -29,7 +29,8 @@ std::string run_command(const std::string &cmd) { const std::string tmp_file("/tmp/tmp_command_result"); std::string command(cmd + " > " + tmp_file); - std::system(command.c_str()); + int res = std::system(command.c_str()); + assert(WIFEXITED(res)); std::ifstream ifs(tmp_file); if (!ifs.is_open()) { @@ -40,7 +41,7 @@ std::string run_command(const std::string &cmd) { buf.assign((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - metall::mtlldetail::remove_file(tmp_file); + dice::copperr::mtlldetail::remove_file(tmp_file); return buf; } @@ -62,10 +63,10 @@ int main(int argc, char *argv[]) { run_bench(option, &adj_list); std::cout << "File size\t" - << metall::mtlldetail::get_file_size(option.datastore_path_list[0]) + << dice::copperr::mtlldetail::get_file_size(option.datastore_path_list[0]) << std::endl; std::cout << "Actual file size\t" - << metall::mtlldetail::get_actual_file_size( + << dice::copperr::mtlldetail::get_actual_file_size( option.datastore_path_list[0]) << std::endl; std::cout << run_command("df " + option.datastore_path_list[0]) << std::endl; diff --git a/bench/adjacency_list/run_adj_list_bench_reflink_snapshot.cpp b/bench/adjacency_list/run_adj_list_bench_reflink_snapshot.cpp index bc00b920..7803735d 100644 --- a/bench/adjacency_list/run_adj_list_bench_reflink_snapshot.cpp +++ b/bench/adjacency_list/run_adj_list_bench_reflink_snapshot.cpp @@ -10,9 +10,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -22,7 +22,7 @@ using key_type = uint64_t; using value_type = uint64_t; using adjacency_list_type = data_structure::multithread_adjacency_list< - key_type, value_type, typename metall::manager::allocator_type>; + key_type, value_type, typename dice::copperr::manager::allocator_type>; ssize_t g_directory_total = 0; int sum_file_sizes(const char *, const struct stat *statbuf, int typeflag) { @@ -46,7 +46,9 @@ void run_df(const std::string &dir_path, const std::string full_command(df_command + " " + dir_path + " > " + out_file_name); - std::system(full_command.c_str()); + int res = std::system(full_command.c_str()); + assert(WIFEXITED(res)); + std::ifstream ifs(out_file_name); std::string buf; std::getline(ifs, buf); @@ -70,7 +72,7 @@ int main(int argc, char *argv[]) { option.verbose = true; { - metall::manager manager(metall::create_only, + dice::copperr::manager manager(dice::copperr::create_only, option.datastore_path_list[0].c_str()); // This function is called after inserting each chunk @@ -95,7 +97,7 @@ int main(int argc, char *argv[]) { option.datastore_path_list[0] + "-snapshot-" + snapshot_id.str(); const auto start = mdtl::elapsed_time_sec(); // Use copy() so that flush() is not called again - metall::manager::copy(option.datastore_path_list[0].c_str(), + dice::copperr::manager::copy(option.datastore_path_list[0].c_str(), snapshot_dir.c_str()); const auto elapsed_time = mdtl::elapsed_time_sec(start); std::cout << "Snapshot took (s)\t" << elapsed_time << std::endl; diff --git a/bench/adjacency_list/run_bench.sh b/bench/adjacency_list/run_bench.sh index 7e240c97..be0c0dbe 100755 --- a/bench/adjacency_list/run_bench.sh +++ b/bench/adjacency_list/run_bench.sh @@ -3,7 +3,7 @@ # ------------------------- # # Usage # ------------------------- # -# cd metall/build/bench/adjacency_list +# cd copperr/build/bench/adjacency_list # sh run_bench.sh [options] # ------------------------- # @@ -21,7 +21,7 @@ linux*) DATASTORE_DIR_ROOT="/dev/shm" ;; esac NO_CLEANING_FILES_AT_END=false UMAP_PAGESIZE="" -EXEC_NAME="metall" # "run_adj_list_bench_${EXEC_NAME}" is the execution file +EXEC_NAME="copperr" # "run_adj_list_bench_${EXEC_NAME}" is the execution file while getopts "v:f:l:t:s:d:n:cp:E:" OPT; do case $OPT in @@ -47,7 +47,7 @@ A=0.57 B=0.19 C=0.19 RND_SEED=123 -DATASTORE_NAME="metall_adjlist_bench" +DATASTORE_NAME="copperr_adjlist_bench" #case "$OSTYPE" in # darwin*) diff --git a/bench/adjacency_list/test/CMakeLists.txt b/bench/adjacency_list/test/CMakeLists.txt index 2ff8a0b2..6507b007 100644 --- a/bench/adjacency_list/test/CMakeLists.txt +++ b/bench/adjacency_list/test/CMakeLists.txt @@ -1,7 +1,7 @@ -add_metall_executable(open_metall open_metall.cpp) -add_metall_executable(extend_metall extend_metall.cpp) -add_metall_executable(destroy_metall destroy_metall.cpp) -add_metall_executable(compare_key_value_lists compare_key_value_lists.cpp) +add_copperr_executable(open_copperr open_copperr.cpp) +add_copperr_executable(extend_copperr extend_copperr.cpp) +add_copperr_executable(destroy_copperr destroy_copperr.cpp) +add_copperr_executable(compare_key_value_lists compare_key_value_lists.cpp) configure_file(test.sh test.sh COPYONLY) configure_file(test_large.sh test_large.sh COPYONLY) diff --git a/bench/adjacency_list/test/compare_key_value_lists.cpp b/bench/adjacency_list/test/compare_key_value_lists.cpp index dff64556..9fb42702 100644 --- a/bench/adjacency_list/test/compare_key_value_lists.cpp +++ b/bench/adjacency_list/test/compare_key_value_lists.cpp @@ -12,13 +12,13 @@ #include #include #include -#include +#include using key_type = uint64_t; using value_type = uint64_t; using item_type = std::pair; using table_type = - std::unordered_map>; + std::unordered_map>; void ingest_item(const std::string& file_name, table_type* table) { std::ifstream ifs(file_name); diff --git a/bench/adjacency_list/test/destroy_metall.cpp b/bench/adjacency_list/test/destroy_metall.cpp index 1b139140..6ee6ec3a 100644 --- a/bench/adjacency_list/test/destroy_metall.cpp +++ b/bench/adjacency_list/test/destroy_metall.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "../bench_driver.hpp" #include "../../data_structure/multithread_adjacency_list.hpp" @@ -16,7 +16,7 @@ using namespace adjacency_list_bench; using key_type = uint64_t; using value_type = uint64_t; using adjacency_list_type = data_structure::multithread_adjacency_list< - key_type, value_type, typename metall::manager::allocator_type>; + key_type, value_type, typename dice::copperr::manager::allocator_type>; int main(int argc, char *argv[]) { bench_options option; @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { } { - metall::manager manager(metall::open_only, + dice::copperr::manager manager(dice::copperr::open_only, option.datastore_path_list[0].c_str()); manager.destroy(option.adj_list_key_name.c_str()); diff --git a/bench/adjacency_list/test/extend_metall.cpp b/bench/adjacency_list/test/extend_metall.cpp index 0a618494..4592e20e 100644 --- a/bench/adjacency_list/test/extend_metall.cpp +++ b/bench/adjacency_list/test/extend_metall.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "../bench_driver.hpp" #include "../../data_structure/multithread_adjacency_list.hpp" @@ -16,7 +16,7 @@ using namespace adjacency_list_bench; using key_type = uint64_t; using value_type = uint64_t; using adjacency_list_type = data_structure::multithread_adjacency_list< - key_type, value_type, typename metall::manager::allocator_type>; + key_type, value_type, typename dice::copperr::manager::allocator_type>; int main(int argc, char *argv[]) { bench_options option; @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { } { - metall::manager manager(metall::open_only, + dice::copperr::manager manager(dice::copperr::open_only, option.datastore_path_list[0].c_str()); auto ret = manager.find(option.adj_list_key_name.c_str()); diff --git a/bench/adjacency_list/test/open_metall.cpp b/bench/adjacency_list/test/open_metall.cpp index 8747c719..56f857b7 100644 --- a/bench/adjacency_list/test/open_metall.cpp +++ b/bench/adjacency_list/test/open_metall.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "../bench_driver.hpp" #include "../../data_structure/multithread_adjacency_list.hpp" @@ -16,7 +16,7 @@ using namespace adjacency_list_bench; using key_type = uint64_t; using value_type = uint64_t; using adjacency_list_type = data_structure::multithread_adjacency_list< - key_type, value_type, typename metall::manager::allocator_type>; + key_type, value_type, typename dice::copperr::manager::allocator_type>; int main(int argc, char *argv[]) { bench_options option; @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { } { - metall::manager manager(metall::open_read_only, + dice::copperr::manager manager(dice::copperr::open_read_only, option.datastore_path_list[0].c_str()); const auto ret = manager.find(option.adj_list_key_name.c_str()); diff --git a/bench/adjacency_list/test/test.sh b/bench/adjacency_list/test/test.sh index 86590266..97ae43e3 100644 --- a/bench/adjacency_list/test/test.sh +++ b/bench/adjacency_list/test/test.sh @@ -1,11 +1,11 @@ #!/bin/sh # USAGE -# cd metall/build/bench/adjacency_list/ +# cd copperr/build/bench/adjacency_list/ # sh ./test/test.sh DATA=./test/data/edge_list_rmat_s10_ -DATASTORE_DIR_ROOT="/tmp/metall_adj_test" +DATASTORE_DIR_ROOT="/tmp/copperr_adj_test" err() { echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2 @@ -72,7 +72,7 @@ main() { mkdir -p ${DATASTORE_DIR_ROOT} echo "Create Test" - ./run_adj_list_bench_metall -o ${DATASTORE_DIR_ROOT}/metall_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out ${DATA}* + ./run_adj_list_bench_copperr -o ${DATASTORE_DIR_ROOT}/copperr_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out ${DATA}* check_program_exit_status rm -f ${DATASTORE_DIR_ROOT}/adj_ref cat ${DATA}* >> ${DATASTORE_DIR_ROOT}/adj_ref @@ -82,7 +82,7 @@ main() { # Open the adj-list with the open mode and add more edges echo "" echo "Extend Test" - ./test/extend_metall -o ${DATASTORE_DIR_ROOT}/metall_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out_extend ${DATA}* + ./test/extend_copperr -o ${DATASTORE_DIR_ROOT}/copperr_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out_extend ${DATA}* check_program_exit_status cat ${DATA}* >> ${DATASTORE_DIR_ROOT}/adj_ref compare "${DATASTORE_DIR_ROOT}/adj_out_extend" "${DATASTORE_DIR_ROOT}/adj_ref" @@ -90,14 +90,14 @@ main() { # Open the adj-list with the read only open mode echo "" echo "Open Test" - ./test/open_metall -o ${DATASTORE_DIR_ROOT}/metall_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out_open + ./test/open_copperr -o ${DATASTORE_DIR_ROOT}/copperr_test_dir -d ${DATASTORE_DIR_ROOT}/adj_out_open check_program_exit_status compare "${DATASTORE_DIR_ROOT}/adj_out_open" "${DATASTORE_DIR_ROOT}/adj_ref" # Open the adj-list and destroy it to test memory leak echo "" echo "Destroy Test" - ./test/destroy_metall -o ${DATASTORE_DIR_ROOT}/metall_test_dir + ./test/destroy_copperr -o ${DATASTORE_DIR_ROOT}/copperr_test_dir check_program_exit_status echo "<< Passed all tests!! >>" diff --git a/bench/adjacency_list/test/test_large.sh b/bench/adjacency_list/test/test_large.sh index 9002c677..3fada216 100644 --- a/bench/adjacency_list/test/test_large.sh +++ b/bench/adjacency_list/test/test_large.sh @@ -1,7 +1,7 @@ #!/bin/sh # USAGE -# cd metall/build/bench/adjacency_list/ +# cd copperr/build/bench/adjacency_list/ # sh ./test/test_large.sh # ----- Default Configuration ----- # @@ -15,8 +15,8 @@ seed=123 # The default path to store data. # This value is overwritten if '-d' option is specified case "$OSTYPE" in - darwin*) out_dir_path="/tmp/metall_adj_test";; - linux*) out_dir_path="/dev/shm/metall_adj_test";; + darwin*) out_dir_path="/tmp/copperr_adj_test";; + linux*) out_dir_path="/dev/shm/copperr_adj_test";; esac # --------------- # @@ -70,7 +70,7 @@ main() { parse_option "$@" mkdir -p ${out_dir_path} - data_store_path="${out_dir_path}/metall_test_dir" + data_store_path="${out_dir_path}/copperr_test_dir" adj_list_dump_file="${out_dir_path}/dumped_edge_list" # Contains edges generated directly from the edge generator @@ -79,7 +79,7 @@ main() { local e=$((2**$((${v}+4)))) # The number of edges to generate - ./run_adj_list_bench_metall -o ${data_store_path} -d ${adj_list_dump_file} -s ${seed} -v ${v} -e ${e} -a ${a} -b ${b} -c ${c} -r 1 -u 1 -D ${ref_edge_dump_file1} + ./run_adj_list_bench_copperr -o ${data_store_path} -d ${adj_list_dump_file} -s ${seed} -v ${v} -e ${e} -a ${a} -b ${b} -c ${c} -r 1 -u 1 -D ${ref_edge_dump_file1} check_program_exit_status echo "" @@ -90,7 +90,7 @@ main() { # ---------- Reopen the file for persistence test ---------- # # Open and add another edge list - ./test/extend_metall -o ${data_store_path} -d ${adj_list_dump_file} -s $(($seed+1024)) -v ${v} -e ${e} -a ${a} -b ${b} -c ${c} -r 1 -u 1 -D ${ref_edge_dump_file2} + ./test/extend_copperr -o ${data_store_path} -d ${adj_list_dump_file} -s $(($seed+1024)) -v ${v} -e ${e} -a ${a} -b ${b} -c ${c} -r 1 -u 1 -D ${ref_edge_dump_file2} check_program_exit_status echo "" @@ -103,7 +103,7 @@ main() { /bin/rm -rf ${adj_list_dump_file} # Open the datastore as the read only mode - ./test/open_metall -o ${data_store_path} -d ${adj_list_dump_file} + ./test/open_copperr -o ${data_store_path} -d ${adj_list_dump_file} check_program_exit_status echo "" @@ -111,7 +111,7 @@ main() { echo "" # Open the adj-list and destroy it to test memory leak - ./test/destroy_metall -o ${data_store_path} + ./test/destroy_copperr -o ${data_store_path} check_program_exit_status echo "<< Passed all tests!! >>" diff --git a/bench/bfs/CMakeLists.txt b/bench/bfs/CMakeLists.txt index bd2b73d2..4169805d 100644 --- a/bench/bfs/CMakeLists.txt +++ b/bench/bfs/CMakeLists.txt @@ -1,12 +1,12 @@ -include(setup_omp) +include(${CMAKE_SOURCE_DIR}/cmake/setup_omp) -add_metall_executable(run_bfs_bench_metall run_bfs_bench_metall.cpp) -setup_omp_target(run_bfs_bench_metall) +add_copperr_executable(run_bfs_bench_copperr run_bfs_bench_copperr.cpp) +setup_omp_target(run_bfs_bench_copperr) -add_metall_executable(run_bfs_bench_metall_multiple run_bfs_bench_metall_multiple.cpp) -setup_omp_target(run_bfs_bench_metall_multiple) +add_copperr_executable(run_bfs_bench_copperr_multiple run_bfs_bench_copperr_multiple.cpp) +setup_omp_target(run_bfs_bench_copperr_multiple) -add_metall_executable(run_bfs_bench_bip run_bfs_bench_bip.cpp) +add_copperr_executable(run_bfs_bench_bip run_bfs_bench_bip.cpp) setup_omp_target(run_bfs_bench_bip) configure_file(run_bench.sh run_bench.sh COPYONLY) \ No newline at end of file diff --git a/bench/bfs/bench_driver.hpp b/bench/bfs/bench_driver.hpp index 91880f27..0fdde635 100644 --- a/bench/bfs/bench_driver.hpp +++ b/bench/bfs/bench_driver.hpp @@ -11,17 +11,17 @@ #include #include -#include -#include +#include +#include #include "kernel.hpp" -#include +#include namespace bfs_bench { namespace { -namespace mdtl = metall::mtlldetail; -namespace omp = metall::utility::omp; +namespace mdtl = dice::copperr::mtlldetail; +namespace omp = dice::copperr::utility::omp; } // namespace // ---------------------------------------- // diff --git a/bench/bfs/kernel.hpp b/bench/bfs/kernel.hpp index 03b11ca8..24eac7f3 100644 --- a/bench/bfs/kernel.hpp +++ b/bench/bfs/kernel.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include namespace bfs_bench { diff --git a/bench/bfs/run_bench.sh b/bench/bfs/run_bench.sh index 7255c9fc..909ef65c 100755 --- a/bench/bfs/run_bench.sh +++ b/bench/bfs/run_bench.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Usage -# cd metall/build/bench/bfs +# cd copperr/build/bench/bfs # sh run_bench.sh -v 31 -f $((2**40)) -t 24 -s static[dynamic,10000] -g /dev/shm # ----- Options----- # @@ -164,8 +164,8 @@ run() { main() { run bip - run metall - #run metall_numa + run copperr + #run copperr_numa } main "$@" \ No newline at end of file diff --git a/bench/bfs/run_bfs_bench_metall.cpp b/bench/bfs/run_bfs_bench_metall.cpp index ccf3b0b4..a7044a6d 100644 --- a/bench/bfs/run_bfs_bench_metall.cpp +++ b/bench/bfs/run_bfs_bench_metall.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -17,7 +17,7 @@ using vertex_id_type = uint64_t; using adjacency_list_type = data_structure::multithread_adjacency_list< vertex_id_type, vertex_id_type, - typename metall::manager::allocator_type>; + typename dice::copperr::manager::allocator_type>; int main(int argc, char *argv[]) { bench_options option; @@ -26,9 +26,9 @@ int main(int argc, char *argv[]) { } { - // metall::logger::set_log_level(metall::logger::level::verbose); + // dice::copperr::logger::set_log_level(dice::copperr::logger::level::verbose); - metall::manager manager(metall::open_read_only, + dice::copperr::manager manager(dice::copperr::open_read_only, option.graph_file_name_list[0].c_str()); auto adj_list = manager.find(option.graph_key_name.c_str()).first; diff --git a/bench/bfs/run_bfs_bench_metall_multiple.cpp b/bench/bfs/run_bfs_bench_metall_multiple.cpp index 6fa7e2d3..b830eaaf 100644 --- a/bench/bfs/run_bfs_bench_metall_multiple.cpp +++ b/bench/bfs/run_bfs_bench_metall_multiple.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include "../data_structure/multithread_adjacency_list.hpp" #include "../data_structure/partitioned_multithread_adjacency_list.hpp" #include "bench_driver.hpp" @@ -19,7 +19,7 @@ using vertex_id_type = uint64_t; using local_adjacency_list_type = multithread_adjacency_list< vertex_id_type, vertex_id_type, - typename metall::manager::allocator_type>; + typename dice::copperr::manager::allocator_type>; using adjacency_list_type = partitioned_multithread_adjacency_list; @@ -30,10 +30,10 @@ int main(int argc, char *argv[]) { } { - std::vector managers; + std::vector managers; for (const auto &file_name : option.graph_file_name_list) { managers.emplace_back( - new metall::manager(metall::open_read_only, file_name.c_str())); + new dice::copperr::manager(dice::copperr::open_read_only, file_name.c_str())); } auto adj_list = adjacency_list_type(option.graph_key_name, managers.begin(), diff --git a/bench/container/CMakeLists.txt b/bench/container/CMakeLists.txt index a6be13c2..9b69ec47 100644 --- a/bench/container/CMakeLists.txt +++ b/bench/container/CMakeLists.txt @@ -1,3 +1,3 @@ -add_metall_executable(run_vector_bench run_vector_bench.cpp) -add_metall_executable(run_map_bench run_map_bench.cpp) -add_metall_executable(run_unordered_map_bench run_unordered_map_bench.cpp) +add_copperr_executable(run_vector_bench run_vector_bench.cpp) +add_copperr_executable(run_map_bench run_map_bench.cpp) +add_copperr_executable(run_unordered_map_bench run_unordered_map_bench.cpp) diff --git a/bench/container/bench_common.hpp b/bench/container/bench_common.hpp index 62721f77..6a0afa46 100644 --- a/bench/container/bench_common.hpp +++ b/bench/container/bench_common.hpp @@ -10,11 +10,11 @@ #include #include -#include +#include #include "../bench/adjacency_list/edge_generator/rmat_edge_generator.hpp" -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; using rmat_generator_type = edge_generator::rmat_edge_generator; @@ -31,7 +31,7 @@ void gen_edges(const std::size_t vertex_scale, const std::size_t num_edges, void gen_random_values(const std::size_t num_values, std::vector> &buf) { - metall::utility::rand_1024 rnd_generator(std::random_device{}()); + dice::copperr::utility::rand_1024 rnd_generator(std::random_device{}()); buf.reserve(num_values); for (std::size_t i = 0; i < num_values; ++i) { diff --git a/bench/container/run_map_bench.cpp b/bench/container/run_map_bench.cpp index 93f4c1dc..2d1befbf 100644 --- a/bench/container/run_map_bench.cpp +++ b/bench/container/run_map_bench.cpp @@ -11,9 +11,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "bench_common.hpp" @@ -51,8 +51,8 @@ int main() { } { - metall::manager mngr(metall::create_only, "/tmp/metall"); - metall::container::map map(mngr.get_allocator()); + dice::copperr::manager mngr(dice::copperr::create_only, "/tmp/copperr"); + dice::copperr::container::map map(mngr.get_allocator()); const auto start = mdtl::elapsed_time_sec(); for (const auto &kv : inputs) { diff --git a/bench/container/run_unordered_map_bench.cpp b/bench/container/run_unordered_map_bench.cpp index 4a2d746f..7988fbf0 100644 --- a/bench/container/run_unordered_map_bench.cpp +++ b/bench/container/run_unordered_map_bench.cpp @@ -11,9 +11,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "bench_common.hpp" @@ -51,8 +51,8 @@ int main() { } { - metall::manager mngr(metall::create_only, "/tmp/metall"); - metall::container::unordered_map map( + dice::copperr::manager mngr(dice::copperr::create_only, "/tmp/copperr"); + dice::copperr::container::unordered_map map( mngr.get_allocator()); const auto start = mdtl::elapsed_time_sec(); diff --git a/bench/container/run_vector_bench.cpp b/bench/container/run_vector_bench.cpp index a2f70581..bea36080 100644 --- a/bench/container/run_vector_bench.cpp +++ b/bench/container/run_vector_bench.cpp @@ -11,9 +11,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "bench_common.hpp" @@ -39,8 +39,8 @@ int main() { { std::cout << "Boost vector (push_back) with Metall" << std::endl; - metall::manager mngr(metall::create_only, "/tmp/metall"); - metall::container::vector> vec( + dice::copperr::manager mngr(dice::copperr::create_only, "/tmp/copperr"); + dice::copperr::container::vector> vec( mngr.get_allocator()); run_bench(inputs, [&vec](const auto &kv) { vec.push_back(kv); }); } @@ -66,8 +66,8 @@ int main() { { std::cout << "Boost vector ([]) with Metall" << std::endl; - metall::manager mngr(metall::create_only, "/tmp/metall"); - metall::container::vector> vec( + dice::copperr::manager mngr(dice::copperr::create_only, "/tmp/copperr"); + dice::copperr::container::vector> vec( mngr.get_allocator()); std::size_t index = 0; run_bench( diff --git a/bench/data_structure/multithread_adjacency_list.hpp b/bench/data_structure/multithread_adjacency_list.hpp index c14b0243..5171718f 100644 --- a/bench/data_structure/multithread_adjacency_list.hpp +++ b/bench/data_structure/multithread_adjacency_list.hpp @@ -19,14 +19,14 @@ #include namespace container = std; #else -#include -#include -#include -namespace container = metall::container; +#include +#include +#include +namespace container = dice::copperr::container; #endif -#include -#include +#include +#include namespace data_structure { @@ -49,7 +49,7 @@ class multithread_adjacency_list { using key_table_allocator_type = container::scoped_allocator_adaptor< other_allocator_type>>; using key_table_type = - container::unordered_map, + container::unordered_map, std::equal_to, key_table_allocator_type>; @@ -76,7 +76,7 @@ class multithread_adjacency_list { bool add(key_type key, value_type value) { auto guard = - metall::utility::mutex::mutex_lock(bank_index(key)); + dice::copperr::utility::mutex::mutex_lock(bank_index(key)); #ifdef __clang__ #if METALL_USE_STL_CONTAINERS_IN_ADJLIST m_bank_table[bank_index(key)][key].emplace_back(std::move(value)); diff --git a/bench/mapping/CMakeLists.txt b/bench/mapping/CMakeLists.txt index e79eb906..0791a433 100644 --- a/bench/mapping/CMakeLists.txt +++ b/bench/mapping/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(run_mapping_bench run_mapping_bench.cpp) \ No newline at end of file +add_copperr_executable(run_mapping_bench run_mapping_bench.cpp) \ No newline at end of file diff --git a/bench/mapping/run_mapping_bench.cpp b/bench/mapping/run_mapping_bench.cpp index 1f3424cc..2e7582cb 100644 --- a/bench/mapping/run_mapping_bench.cpp +++ b/bench/mapping/run_mapping_bench.cpp @@ -13,16 +13,16 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include -using rand_engine = metall::utility::rand_512; +using rand_engine = dice::copperr::utility::rand_512; static constexpr std::size_t k_page_size = 4096; namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } auto random_write_by_page(const std::size_t size, unsigned char *const map) { @@ -170,12 +170,12 @@ void run_bench_one_time( // Use Metall { - metall::manager manager(metall::create_only, dir_path.data()); + dice::copperr::manager manager(dice::copperr::create_only, dir_path.data()); auto *map = static_cast(manager.allocate(length)); bench_core("Metall", map); manager.deallocate(map); } - metall::manager::remove(dir_path.data()); + dice::copperr::manager::remove(dir_path.data()); } void run_bench(std::string_view dir_path, const std::size_t num_repeats, diff --git a/bench/offset_ptr/CMakeLists.txt b/bench/offset_ptr/CMakeLists.txt index de5caf50..3b146243 100644 --- a/bench/offset_ptr/CMakeLists.txt +++ b/bench/offset_ptr/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(run_offset_ptr_bench run_offset_ptr_bench.cpp) \ No newline at end of file +add_copperr_executable(run_offset_ptr_bench run_offset_ptr_bench.cpp) \ No newline at end of file diff --git a/bench/offset_ptr/run_offset_ptr_bench.cpp b/bench/offset_ptr/run_offset_ptr_bench.cpp index dc2e84cb..9e647363 100644 --- a/bench/offset_ptr/run_offset_ptr_bench.cpp +++ b/bench/offset_ptr/run_offset_ptr_bench.cpp @@ -8,10 +8,10 @@ /// ./run_offset_ptr_bench #include -#include -#include +#include +#include -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; int main() { const std::size_t length = 1ULL << 22; @@ -34,7 +34,7 @@ int main() { } { - auto ofset_ptr = metall::offset_ptr(array); + auto ofset_ptr = dice::copperr::offset_ptr(array); const auto start = mdtl::elapsed_time_sec(); for (std::size_t i = 0; i < length; ++i) { [[maybe_unused]] volatile const uint64_t x = *ofset_ptr; diff --git a/bench/rand_engine/CMakeLists.txt b/bench/rand_engine/CMakeLists.txt index ca149b95..25820b3b 100644 --- a/bench/rand_engine/CMakeLists.txt +++ b/bench/rand_engine/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(run_rand_engine_bench run_rand_engine_bench.cpp) \ No newline at end of file +add_copperr_executable(run_rand_engine_bench run_rand_engine_bench.cpp) \ No newline at end of file diff --git a/bench/rand_engine/run_rand_engine_bench.cpp b/bench/rand_engine/run_rand_engine_bench.cpp index 9c002908..55baa1db 100644 --- a/bench/rand_engine/run_rand_engine_bench.cpp +++ b/bench/rand_engine/run_rand_engine_bench.cpp @@ -6,17 +6,17 @@ #include #include #include -#include -#include +#include +#include template auto run_bench(const uint64_t num_generate) { rand_engine_type rand_engine(123); - const auto s = metall::mtlldetail::elapsed_time_sec(); + const auto s = dice::copperr::mtlldetail::elapsed_time_sec(); for (uint64_t i = 0; i < num_generate; ++i) { [[maybe_unused]] volatile const uint64_t x = rand_engine(); } - const auto t = metall::mtlldetail::elapsed_time_sec(s); + const auto t = dice::copperr::mtlldetail::elapsed_time_sec(s); return t; } @@ -29,9 +29,9 @@ int main() { std::cout << "boost::mt19937_64\t" << run_bench(num_generate) << std::endl; std::cout << "xoshiro512++ \t" - << run_bench(num_generate) << std::endl; + << run_bench(num_generate) << std::endl; std::cout << "xoshiro1024++ \t" - << run_bench(num_generate) << std::endl; + << run_bench(num_generate) << std::endl; return 0; } diff --git a/bench/simple_alloc/CMakeLists.txt b/bench/simple_alloc/CMakeLists.txt index 78fcfcc7..ff70e485 100644 --- a/bench/simple_alloc/CMakeLists.txt +++ b/bench/simple_alloc/CMakeLists.txt @@ -1,4 +1,4 @@ -add_metall_executable(run_simple_allocation_bench_stl run_simple_allocation_bench_stl.cpp) -add_metall_executable(run_simple_allocation_bench_metall run_simple_allocation_bench_metall.cpp) -add_metall_executable(run_simple_allocation_bench_bip run_simple_allocation_bench_bip.cpp) +add_copperr_executable(run_simple_allocation_bench_stl run_simple_allocation_bench_stl.cpp) +add_copperr_executable(run_simple_allocation_bench_copperr run_simple_allocation_bench_copperr.cpp) +add_copperr_executable(run_simple_allocation_bench_bip run_simple_allocation_bench_bip.cpp) configure_file(run_bench.sh run_bench.sh COPYONLY) \ No newline at end of file diff --git a/bench/simple_alloc/kernel.hpp b/bench/simple_alloc/kernel.hpp index 2274d208..c3b7912d 100644 --- a/bench/simple_alloc/kernel.hpp +++ b/bench/simple_alloc/kernel.hpp @@ -17,13 +17,13 @@ #include #include #include -#include -#include +#include +#include namespace simple_alloc_bench { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperrmtlldetail; } struct option_type { @@ -70,7 +70,7 @@ template void allocate_sequential( byte_allocator_type byte_allocator, const std::vector &size_list, - std::vector *allocated_addr_list) { + std::vector::pointer> *allocated_addr_list) { static_assert( std::is_same< typename std::allocator_traits::value_type, @@ -89,7 +89,7 @@ template void deallocate_sequential( byte_allocator_type byte_allocator, const std::vector &size_list, - const std::vector + const std::vector::pointer> &allocated_addr_list) { static_assert( std::is_same< @@ -105,7 +105,7 @@ template void allocate_parallel( byte_allocator_type byte_allocator, const std::vector &size_list, - std::vector *allocated_addr_list) { + std::vector::pointer> *allocated_addr_list) { static_assert( std::is_same< typename std::allocator_traits::value_type, @@ -116,12 +116,12 @@ void allocate_parallel( nullptr); for (std::size_t t = 0; t < threads.size(); ++t) { const auto range = - metall::mtlldetail::partial_range(size_list.size(), t, threads.size()); + dice::copperrmtlldetail::partial_range(size_list.size(), t, threads.size()); threads[t] = new std::thread( [range](byte_allocator_type byte_allocator, const std::vector &size_list, - std::vector + std::vector::pointer> *allocated_addr_list) { for (std::size_t i = range.first; i < range.second; ++i) { (*allocated_addr_list)[i] = byte_allocator.allocate(size_list[i]); @@ -143,7 +143,7 @@ template void deallocate_parallel( byte_allocator_type byte_allocator, const std::vector &size_list, - const std::vector + const std::vector::pointer> &allocated_addr_list) { static_assert( std::is_same< @@ -155,12 +155,12 @@ void deallocate_parallel( nullptr); for (std::size_t t = 0; t < threads.size(); ++t) { const auto range = - metall::mtlldetail::partial_range(size_list.size(), t, threads.size()); + dice::copperrmtlldetail::partial_range(size_list.size(), t, threads.size()); threads[t] = new std::thread( [range](byte_allocator_type byte_allocator, const std::vector &size_list, - const std::vector + const std::vector::pointer> &allocated_addr_list) { for (std::size_t i = range.first; i < range.second; ++i) { byte_allocator.deallocate(allocated_addr_list[i], size_list[i]); @@ -218,7 +218,7 @@ void run_bench(const option_type &option, const allocator_type allocator) { byte_allocator_type byte_allocator(allocator); std::vector allocation_request_list(option.num_allocations); - std::vector allocated_addr_list( + std::vector::pointer> allocated_addr_list( option.num_allocations); std::cout << std::fixed; diff --git a/bench/simple_alloc/run_bench.sh b/bench/simple_alloc/run_bench.sh index 14ab5b85..76e62f0e 100755 --- a/bench/simple_alloc/run_bench.sh +++ b/bench/simple_alloc/run_bench.sh @@ -11,4 +11,4 @@ rm -rf ${FILE}* ./run_simple_allocation_bench_bip -n ${NUM_ALLOCS} -o ${FILE} | tee ${LOG_FILE_PREFIX}"bip.log" rm -rf ${FILE}* -./run_simple_allocation_bench_metall -n ${NUM_ALLOCS} -o ${FILE} | tee ${LOG_FILE_PREFIX}"metall.log" \ No newline at end of file +./run_simple_allocation_bench_copperr -n ${NUM_ALLOCS} -o ${FILE} | tee ${LOG_FILE_PREFIX}"copperr.log" \ No newline at end of file diff --git a/bench/simple_alloc/run_simple_allocation_bench_metall.cpp b/bench/simple_alloc/run_simple_allocation_bench_metall.cpp index 1b9d5249..877fddc5 100644 --- a/bench/simple_alloc/run_simple_allocation_bench_metall.cpp +++ b/bench/simple_alloc/run_simple_allocation_bench_metall.cpp @@ -7,16 +7,16 @@ #include #include -#include +#include #include "kernel.hpp" int main(int argc, char *argv[]) { const auto option = simple_alloc_bench::parse_option(argc, argv); { - metall::manager manager(metall::create_only, option.datastore_path.c_str()); + dice::copperr::manager manager(dice::copperr::create_only, option.datastore_path.c_str()); simple_alloc_bench::run_bench(option, manager.get_allocator()); } - metall::manager::remove(option.datastore_path.c_str()); + dice::copperr::manager::remove(option.datastore_path.c_str()); return 0; } \ No newline at end of file diff --git a/bench/utility/numa.hpp b/bench/utility/numa.hpp index e3d8711c..2c44556c 100644 --- a/bench/utility/numa.hpp +++ b/bench/utility/numa.hpp @@ -12,7 +12,7 @@ #warning "Does not use NUMA" #endif -#include +#include namespace bench_utility::numa { @@ -57,7 +57,7 @@ int set_node([[maybe_unused]] const int thread_id) noexcept { int get_local_num_threads([[maybe_unused]] const int thread_id, const int num_threads) noexcept { #ifdef METALL_USE_NUMA_LIB - const auto range = metall::mtlldetail::partial_range( + const auto range = dice::copperr::mtlldetail::partial_range( num_threads, get_node(thread_id), get_avail_nodes()); return range.second - range.first; #else diff --git a/cmake/MetallConfig.cmake.in b/cmake/MetallConfig.cmake.in deleted file mode 100644 index ff0fa672..00000000 --- a/cmake/MetallConfig.cmake.in +++ /dev/null @@ -1,4 +0,0 @@ -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") -check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/cmake/boilerplate_init.cmake b/cmake/boilerplate_init.cmake new file mode 100644 index 00000000..d306c601 --- /dev/null +++ b/cmake/boilerplate_init.cmake @@ -0,0 +1,27 @@ +macro(boilerplate_init) + ## enforce standard compliance + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) + + ## C++ compiler flags + if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall") + else () + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Wcast-qual") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") + endif () + + ## C++ language visibility configuration + if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND + NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN) + set(CMAKE_CXX_VISIBILITY_PRESET default) + set(CMAKE_VISIBILITY_INLINES_HIDDEN NO) + endif () + + # conan requires cmake build type to be specified and it is generally a good idea + if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt) + if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) + endif () + endif () +endmacro() \ No newline at end of file diff --git a/cmake/conan_cmake.cmake b/cmake/conan_cmake.cmake new file mode 100644 index 00000000..1cd79894 --- /dev/null +++ b/cmake/conan_cmake.cmake @@ -0,0 +1,27 @@ +macro(install_packages_via_conan conanfile conan_options) + + list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) + list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}) + + + if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") + message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") + file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake" + TLS_VERIFY ON) + endif () + + include(${CMAKE_BINARY_DIR}/conan.cmake) + + conan_cmake_autodetect(settings) + conan_check(VERSION 1 DETECT_QUIET) + if (CONAN_CMD) + conan_cmake_install(PATH_OR_REFERENCE ${conanfile} + BUILD missing + SETTINGS ${settings} + OPTIONS "${conan_options}" + ENV_HOST "CC=${CMAKE_C_COMPILER};CXX=${CMAKE_CXX_COMPILER}") + else () + message(WARNING "No conan executable was found. Dependency retrieval via conan is disabled. System dependencies will be used if available.") + endif () +endmacro() \ No newline at end of file diff --git a/cmake/get_macos_version.cmake b/cmake/get_macos_version.cmake deleted file mode 100644 index 38053d7d..00000000 --- a/cmake/get_macos_version.cmake +++ /dev/null @@ -1,21 +0,0 @@ -function(get_macos_version) - if (NOT APPLE) - message(WARNING "The system is not macOS.") - set(MACOS_VERSION 0 PARENT_SCOPE) - return() - endif () - - execute_process(COMMAND sw_vers -productVersion - RESULT_VARIABLE RET - OUTPUT_VARIABLE STDOUT - ERROR_VARIABLE STDERR) - if (RET) # the command failed - message(WARNING "Cannot get macOS version.") - set(MACOS_VERSION 0 PARENT_SCOPE) - return() - endif () - - set(MACOS_VERSION ${STDOUT} PARENT_SCOPE) - message(VERBOSE "macOS version ${MACOS_VERSION}") - -endfunction() \ No newline at end of file diff --git a/cmake/include_cxx_filesystem_library.cmake b/cmake/include_cxx_filesystem_library.cmake deleted file mode 100644 index a54ca061..00000000 --- a/cmake/include_cxx_filesystem_library.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Find the correct option to link the C++17 library. -# If it is not available, uses own implementation. -function(include_cxx_filesystem_library) - - set(FOUND_CXX17_FILESYSTEM_LIB TRUE PARENT_SCOPE) - set(REQUIRE_LIB_STDCXX_FS FALSE PARENT_SCOPE) - - # Check if C++17 header files are available - # If not, uses our own implementation. - include(CheckIncludeFileCXX) - CHECK_INCLUDE_FILE_CXX(filesystem FOUND_FILESYSTEM_HEADER) - if (NOT FOUND_FILESYSTEM_HEADER) - message(STATUS "Cannot find the C++17 library.") - set(FOUND_CXX17_FILESYSTEM_LIB FALSE PARENT_SCOPE) - return() - endif () - - # Find the correct option to link the C++17 library - # GCC - # Any platform: stdc++fs - # LLVM - # Assumes LLVM >= 9.0 and libc++ >= 7.0. - # Clang + macOS >= 10.15: nothing special is required to use - # Clang + macOS < 10.15: uses our own implementation - # Clang + the other OS: nothing special is required to use - if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) # GCC - set(REQUIRE_LIB_STDCXX_FS TRUE PARENT_SCOPE) - elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang - if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") # macOS - include(get_macos_version) - get_macos_version() # Get macOS version - message(VERBOSE "macOS version ${MACOS_VERSION}") - if (MACOS_VERSION VERSION_LESS 10.15) # macOS < 10.15 - message(STATUS "macOS >= 10.15 is required to use the C++17 library.") - set(FOUND_CXX17_FILESYSTEM_LIB FALSE PARENT_SCOPE) - endif () - endif () - endif () - -endfunction() \ No newline at end of file diff --git a/cmake/install_components.cmake b/cmake/install_components.cmake new file mode 100644 index 00000000..541c0697 --- /dev/null +++ b/cmake/install_components.cmake @@ -0,0 +1,65 @@ +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +function(install_component TYPE COMPONENT_NAME INCLUDE_PATH) + set(lib_name "${PROJECT_NAME}-${COMPONENT_NAME}") + + set(possible_types INTERFACE PUBLIC) + if(NOT TYPE IN_LIST possible_types) + message(FATAL_ERROR "Argument TYPE=${component} of function install_component is not allowed. Allowed values are ${possible_types}") + endif() + + if("${TYPE}" STREQUAL "INTERFACE") + target_include_directories( + ${lib_name} INTERFACE $/${PROJECT_NAME}/${COMPONENT_NAME}) + + install(TARGETS ${lib_name} + EXPORT ${lib_name}-config + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${COMPONENT_NAME}/ + ) + else() + set_target_properties(${lib_name} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + CXX_STANDARD 20 + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON) + target_include_directories( + ${lib_name} PUBLIC $/${PROJECT_NAME}/${COMPONENT_NAME}) + + install(TARGETS ${lib_name} + EXPORT ${lib_name}-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/${COMPONENT_NAME}/ + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/${COMPONENT_NAME}/ + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${COMPONENT_NAME}/ + ) + endif() + + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PATH}/ + DESTINATION include/${PROJECT_NAME}/${COMPONENT_NAME}/ + FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h" PATTERN "*.ipp") + + install( + EXPORT ${lib_name}-config + FILE ${lib_name}-config.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/${COMPONENT_NAME}/) + +endfunction() + +function(install_package) + + write_basic_package_version_file("${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + + configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/main-component-config.cmake.in" + "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/) + + + install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}/) +endfunction() \ No newline at end of file diff --git a/cmake/main-component-config.cmake.in b/cmake/main-component-config.cmake.in new file mode 100644 index 00000000..fddf5bfe --- /dev/null +++ b/cmake/main-component-config.cmake.in @@ -0,0 +1,30 @@ +# parent package with with targets in components +# components are expected to contain the actual target +# each component's config should be in a equally named subdirectory, i.e.: ${CMAKE_INSTALL_DATAROOTDIR}/cmake/@PROJECT_NAME@/${component}/${component}-config.cmake + + +file(GLOB query_available_components LIST_DIRECTORIES true ${CMAKE_CURRENT_LIST_DIR}/*) +list(FILTER query_available_components EXCLUDE REGEX ".*\\..*") +message("actual: ${query_available_components}") + +# available components are listed here +set(@PROJECT_NAME@_available_components query sparql node-wrapper) +message("expected: ${@PROJECT_NAME@_available_components}") + +# check if the user provided components are actually available +foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS}) + if(NOT component IN_LIST @PROJECT_NAME@_available_components) + message(FATAL_ERROR "Component ${component} does not exist in package @PROJECT_NAME@. Available components are ${@PROJECT_NAME@_available_components}") + endif() +endforeach() + +# set(@PROJECT_NAME@_default_component @PROJECT_NAME@) +set(@PROJECT_NAME@_default_component query) + +# default component @PROJECT_NAME@::${@PROJECT_NAME@_default_component} is always included +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@/${@PROJECT_NAME@_default_component}-config.cmake) + +# include all listed components +foreach(component ${@PROJECT_NAME@_FIND_COMPONENTS}) + include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@/${component}-config.cmake) +endforeach() \ No newline at end of file diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 00000000..e8b7f247 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,103 @@ +import re +import os + +from conan import ConanFile +from conan.tools.cmake import CMake +from conan.tools.files import load, rmdir, copy + + +class DiceCopperrConan(ConanFile): + license = "MIT/Apache" + author = "DICE Group " + homepage = "https://github.com/dice-group/copperr" + url = homepage + topics = "persistent memory", "allocator" + settings = "build_type", "compiler", "os", "arch" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_test_deps": [True, False], + "build_ffi": [True, False], + "with_default_logger": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "build_ffi": False, + "with_test_deps": False, + "with_default_logger": True, + } + + generators = "CMakeDeps", "CMakeToolchain" + exports_sources = "libs/*", "CMakeLists.txt", "cmake/*", "LICENSE*", "COPYRIGHT", "NOTICE" + + def requirements(self): + self.requires("boost/1.83.0", transitive_headers=True) + + if self.options.with_test_deps: + self.requires("gtest/1.14.0") + + def set_name(self): + if not hasattr(self, 'name') or self.version is None: + cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt")) + self.name = re.search(r"project\(\s*([A-Za-z\-]+)\s+VERSION", cmake_file).group(1) + + def set_version(self): + if not hasattr(self, 'version') or self.version is None: + cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt")) + self.version = re.search(r"project\([^)]*VERSION\s+(\d+\.\d+.\d+)[^)]*\)", cmake_file).group(1) + if not hasattr(self, 'description') or self.description is None: + cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt")) + self.description = re.search(r"project\([^)]*DESCRIPTION\s+\"([^\"]+)\"[^)]*\)", cmake_file).group(1) + + _cmake = None + + def _configure_cmake(self): + if self._cmake is None: + self._cmake = CMake(self) + self._cmake.configure(variables={"USE_CONAN": False, "BUILD_FFI": self.options.build_ffi, + "WITH_DEFAULT_LOGGER": self.options.with_default_logger}) + + return self._cmake + + def build(self): + self._configure_cmake().build() + + def package(self): + self._configure_cmake().install() + + for dir in ("cmake", "share"): + rmdir(self, os.path.join(self.package_folder, dir)) + + copy(self, pattern="LICENSE*", dst="licenses", src=self.folders.source_folder) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", self.name) + + self.cpp_info.components["global"].set_property("cmake_find_mode", "both") + self.cpp_info.components["global"].set_property("cmake_file_name", self.name) + self.cpp_info.components["global"].set_property("cmake_target_name", f"{self.name}::{self.name}") + self.cpp_info.components["global"].includedirs = [f"include/{self.name}/{self.name}"] + self.cpp_info.components["global"].libdirs = [] + self.cpp_info.components["global"].bindirs = [] + self.cpp_info.components["global"].requires = ["boost::headers"] + + if self.options.build_ffi: + self.cpp_info.components["ffi"].set_property("cmake_find_mode", "both") + self.cpp_info.components["ffi"].set_property("cmake_file_name", self.name) + self.cpp_info.components["ffi"].set_property("cmake_target_name", f"{self.name}::ffi") + self.cpp_info.components["ffi"].includedirs = [f"include/{self.name}/ffi"] + self.cpp_info.components["ffi"].libdirs = [f"lib/{self.name}/ffi"] + self.cpp_info.components["ffi"].libs = [f"{self.name}-ffi"] + self.cpp_info.components["ffi"].requires = ["global"] + + if self.options.with_default_logger: + self.cpp_info.components["default-logger"].set_property("cmake_find_mode", "both") + self.cpp_info.components["default-logger"].set_property("cmake_file_name", self.name) + self.cpp_info.components["default-logger"].set_property("cmake_target_name", f"{self.name}::default-logger") + self.cpp_info.components["default-logger"].includedirs = [] + self.cpp_info.components["default-logger"].libdirs = [f"lib/{self.name}/default-logger"] + self.cpp_info.components["default-logger"].libs = [f"{self.name}-default-logger"] + self.cpp_info.components["default-logger"].requires = [] + + self.cpp_info.components["global"].requires += ["default-logger"] diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index b7ae43f3..17dfbcd7 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -179,7 +179,7 @@ STRIP_FROM_PATH = # specify the list of include paths that are normally passed to the compiler # using the -I flag. -STRIP_FROM_INC_PATH = metall +STRIP_FROM_INC_PATH = copperr # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't @@ -829,12 +829,12 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ../include/metall \ - ../include/metall/c_api \ - ../include/metall/container \ - ../include/metall/json \ - ../include/metall/container/experimental/jgraph \ - ../include/metall/utility \ +INPUT = ../include/copperr \ + ../include/copperr/c_api \ + ../include/copperr/container \ + ../include/copperr/json \ + ../include/copperr/container/experimental/jgraph \ + ../include/copperr/utility \ ../example/graph_data_structure \ ../example/json diff --git a/docs/readthedocs/about/license_notice.md b/docs/readthedocs/about/license_notice.md index 66643cd7..ba5e3249 100644 --- a/docs/readthedocs/about/license_notice.md +++ b/docs/readthedocs/about/license_notice.md @@ -5,10 +5,10 @@ Users may choose either license, at their option. All new contributions must be made under both the MIT and Apache-2.0 licenses. -See [LICENSE-MIT](https://github.com/LLNL/metall/blob/develop/LICENSE-MIT), -[LICENSE-APACHE](https://github.com/LLNL/metall/blob/develop/LICENSE-APACHE), -[NOTICE](https://github.com/LLNL/metall/blob/develop/NOTICE), -and [COPYRIGHT](https://github.com/LLNL/metall/blob/develop/COPYRIGHT) for details. +See [LICENSE-MIT](https://github.com/LLNL/copperr/blob/develop/LICENSE-MIT), +[LICENSE-APACHE](https://github.com/LLNL/copperr/blob/develop/LICENSE-APACHE), +[NOTICE](https://github.com/LLNL/copperr/blob/develop/NOTICE), +and [COPYRIGHT](https://github.com/LLNL/copperr/blob/develop/COPYRIGHT) for details. SPDX-License-Identifier: (Apache-2.0 OR MIT) diff --git a/docs/readthedocs/advanced_build/cmake.md b/docs/readthedocs/advanced_build/cmake.md index 40fdfd96..9f170d53 100644 --- a/docs/readthedocs/advanced_build/cmake.md +++ b/docs/readthedocs/advanced_build/cmake.md @@ -4,8 +4,8 @@ Metall's repository contains example, test, benchmark, and utility programs. Here is how to build them using CMake. ```bash -git clone https://github.com/LLNL/metall -cd metall +git clone https://github.com/LLNL/copperr +cd copperr mkdir build cd build cmake .. -DBOOST_ROOT=/path/to/boost/root/ @@ -68,12 +68,12 @@ Step 2) Run CMake with BUILD_TEST=ON and SKIP_DOWNLOAD_GTEST=ON on a machine tha For example, ```bash # On a machine with the internet -cd metall +cd copperr mkdir build cd build cmake ../ -DBUILD_TEST=ON -DONLY_DOWNLOAD_GTEST=on # Use CMake to just download Google Test # On a machine that does not have an internet access -cd metall/build +cd copperr/build rm CMakeCache.txt cmake ../ -DBUILD_TEST=on -DSKIP_DOWNLOAD_GTEST=on # Add other options you want to use ``` diff --git a/docs/readthedocs/advanced_build/test.md b/docs/readthedocs/advanced_build/test.md index fcb3cae4..cfeeb5d5 100644 --- a/docs/readthedocs/advanced_build/test.md +++ b/docs/readthedocs/advanced_build/test.md @@ -29,21 +29,21 @@ env METALL_TEST_DIR="/mnt/ssd/" make test ## Manual Test There is another test program in Metall's repository. -The test program uses [Adjacency List Benchmark](https://github.com/LLNL/metall/tree/master/bench/adjacency_list/). +The test program uses [Adjacency List Benchmark](https://github.com/LLNL/copperr/tree/master/bench/adjacency_list/). One program creates a graph data and another program opens it. This test is useful to make sure that Metall can store data persistently. Here is how to run the test with small data. ```bash -cd metall/build/bench/adjacency_list/ +cd copperr/build/bench/adjacency_list/ sh ../../../bench/adjacency_list/test/test.sh -d/path/to/store/data/store ``` Here is how to run the test with large data. ```bash -cd metall/build/bench/adjacency_list/ +cd copperr/build/bench/adjacency_list/ sh ../../../bench/adjacency_list/test/test_large.sh -d/path/to/store/data/store -v17 ``` diff --git a/docs/readthedocs/advanced_build/umap.md b/docs/readthedocs/advanced_build/umap.md index e6f8bc4c..7ec2cdfe 100644 --- a/docs/readthedocs/advanced_build/umap.md +++ b/docs/readthedocs/advanced_build/umap.md @@ -7,7 +7,7 @@ An actual build command would be something like: ```bash g++ -std=c++17 -lstdc++fs your_program.cpp \ --I/path/to/metall/include -I/path/to/boost/include \ +-I/path/to/copperr/include -I/path/to/boost/include \ -I/path/to/umap/include -L/path/to/umap/lib -lumap -DMETALL_USE_UMAP ``` diff --git a/docs/readthedocs/basics/compile_time_options.md b/docs/readthedocs/basics/compile_time_options.md index 6d85ebce..fee25ca1 100644 --- a/docs/readthedocs/basics/compile_time_options.md +++ b/docs/readthedocs/basics/compile_time_options.md @@ -1,4 +1,4 @@ # Compile-Time Options There are some compile-time options (C/C++ macro) to configure the behavior of Metall. -Those macros are defined in `metall/include/metall/defs.hpp`. +Those macros are defined in `copperr/include/copperr/defs.hpp`. diff --git a/docs/readthedocs/basics/getting_started.md b/docs/readthedocs/basics/getting_started.md index 45965228..410cf2be 100644 --- a/docs/readthedocs/basics/getting_started.md +++ b/docs/readthedocs/basics/getting_started.md @@ -5,7 +5,7 @@ In this page, we describe how to use Metall with your program. Metall consists of only header files and requires some header files in Boost C++ Libraries. All core files exist under -[metall/include/metall/](https://github.com/LLNL/metall/tree/master/include/metall). +[copperr/include/copperr/](https://github.com/LLNL/copperr/tree/master/include/copperr). ## Required @@ -39,8 +39,8 @@ wget https://dl.bintray.com/boostorg/release/1.77.0/source/boost_1_77_0.tar.gz tar xvf boost_1_77_0.tar.gz export BOOST_ROOT=$PWD/boost_1_77_0 -git clone https://github.com/LLNL/metall -export METALL_INCLUDE=$PWD/metall/include +git clone https://github.com/LLNL/copperr +export METALL_INCLUDE=$PWD/copperr/include g++ -std=c++17 your_program.cpp -lstdc++fs -I${BOOST_ROOT} -I${METALL_INCLUDE} ``` @@ -54,11 +54,11 @@ Spack also installs a proper version of Boost C++ Libraries automatically, if ne ```bash # Install Metall and Boost C++ Libraries -spack install metall +spack install copperr # Sets environment variables: BOOST_ROOT and METALL_ROOT. # Boost C++ Libraries and Metall are installed at the locations, respectively. -spack load metall +spack load copperr # Build a program that uses Metall # Please note that one has to put 'include' at the end of BOOST_ROOT and METALL_ROOT @@ -80,11 +80,5 @@ clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} ``` **On macOS < 10.15** - The C++17 library is not available on macOS < 10.15. -One has to stop using C++17 library in Metall. -If METALL_DISABLE_CXX17_FILESYSTEM_LIB macro is defined, Metall uses its own file system operation implementation. - -```bash -clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} -DMETALL_DISABLE_CXX17_FILESYSTEM_LIB -``` +Metall will not compile if is not avaiable. diff --git a/docs/readthedocs/css/custom.css b/docs/readthedocs/css/custom.css index f938ea8c..da25e100 100644 --- a/docs/readthedocs/css/custom.css +++ b/docs/readthedocs/css/custom.css @@ -2,7 +2,7 @@ body { font-family: "Hiragino Sans"; } -img[src$="metall_overview.png"] { +img[src$="copperr_overview.png"] { display: block; margin-left: auto; margin-right: auto; diff --git a/docs/readthedocs/detail/api.md b/docs/readthedocs/detail/api.md index 29dcd1bf..446368d4 100644 --- a/docs/readthedocs/detail/api.md +++ b/docs/readthedocs/detail/api.md @@ -17,10 +17,10 @@ Here, we list Metall's main APIs. ```C++ // The main header file -#include +#include // The main class of Metall -class metall::manager; +class dice::copperr::manager; // ---------- Constructors ---------- // // Opens an existing data store. @@ -94,40 +94,40 @@ bool manager.snapshot(const char *destination_dir_path) // ---------- Utilities (Metall original) ---------- // // Check if a datastore exists and is consistent // (i.e., it was closed properly in the previous run). -static bool metall::manager::consistent(const char *dir_path) +static bool dice::copperr::manager::consistent(const char *dir_path) // Copies datastore -static bool metall::manager::copy(const char *source_dir_path, const char *destination_dir_path) +static bool dice::copperr::manager::copy(const char *source_dir_path, const char *destination_dir_path) // Removes datastore synchronously -static bool metall::manager::remove(const char *dir_path) +static bool dice::copperr::manager::remove(const char *dir_path) // Gets the version number of the Metall that created the current datastore. version_type manager.get_version() // Gets the version of the Metall that created a datastore -static version_type metall::get_version(const char_type *dir_path) +static version_type dice::copperr::get_version(const char_type *dir_path) // ---------- Data store description ---------- // // Sets a description bool set_description(const std::string &description) -static bool metall::set_description(const char *dir_path, const std::string &description) +static bool dice::copperr::set_description(const char *dir_path, const std::string &description) // Gets a description bool get_description(std::string *description) -static bool metall::get_description(const char *dir_path, std::string *description) +static bool dice::copperr::get_description(const char *dir_path, std::string *description) ``` -Example programs are located in [example](https://github.com/LLNL/metall/tree/master/example). +Example programs are located in [example](https://github.com/LLNL/copperr/tree/master/example). ## FUll API document -The full API document is available [here](https://software.llnl.gov/metall/api/). +The full API document is available [here](https://software.llnl.gov/copperr/api/). To generate the full API document locally using Doxygen: ```bash -cd metall +cd copperr mkdir build_doc cd build_doc doxygen ../docs/Doxyfile.in diff --git a/docs/readthedocs/detail/example.md b/docs/readthedocs/detail/example.md index d5d82914..d4f82bf8 100644 --- a/docs/readthedocs/detail/example.md +++ b/docs/readthedocs/detail/example.md @@ -1,5 +1,5 @@ ## Example -Example programs are located in [example](https://github.com/LLNL/metall/tree/master/example) +Example programs are located in [example](https://github.com/LLNL/copperr/tree/master/example) To build the examples see [build source files in Metall](../advanced_build/cmake.md) \ No newline at end of file diff --git a/docs/readthedocs/detail/internal_architecture.md b/docs/readthedocs/detail/internal_architecture.md index da73bc48..aa99ce7f 100644 --- a/docs/readthedocs/detail/internal_architecture.md +++ b/docs/readthedocs/detail/internal_architecture.md @@ -9,7 +9,7 @@ that is, physical memory space both in DRAM and persistent memory is not consume The figure below is the internal architecture of Metall -![metall_architecture](../img/metall_architecture.png "Metall's Internal Architecture") +![copperr_architecture](../img/copperr_architecture.png "Metall's Internal Architecture") ### Backing Data Store diff --git a/docs/readthedocs/detail/ls.md b/docs/readthedocs/detail/ls.md index 4912ac57..dad27cbf 100644 --- a/docs/readthedocs/detail/ls.md +++ b/docs/readthedocs/detail/ls.md @@ -3,7 +3,7 @@ `datastore_ls` is a utility program that lists object attributes in a Metall data store. `mpi_datastore_ls` is available for Metall MPI data store, -which is created by [Metall MPI Adaptor](https://github.com/LLNL/metall/blob/master/include/metall/utility/metall_mpi_adaptor.hpp). +which is created by [Metall MPI Adaptor](https://github.com/LLNL/copperr/blob/master/include/copperr/utility/copperr_mpi_adaptor.hpp). `mpi_datastore_ls` is not a MPI program. ### Synopsis @@ -17,7 +17,7 @@ mpi_datastore_ls [/path/to/datastore] [MPI rank number] $ cmake [option]... $ make datastore_ls $ make install -$/install/path/bin/datastore_ls /path/to/metall/datastore +$/install/path/bin/datastore_ls /path/to/copperr/datastore [Named Object] | Name | Length | Offset | Type-ID | Description | ---------------------------------------------------------------------------- diff --git a/docs/readthedocs/detail/pointer.md b/docs/readthedocs/detail/pointer.md index 05821392..13122dde 100644 --- a/docs/readthedocs/detail/pointer.md +++ b/docs/readthedocs/detail/pointer.md @@ -8,7 +8,7 @@ To fix the problem, the **offset pointer** has to be used instead of the raw poi An offset pointer holds an offset between the address pointing at and itself so that it can always point to the same location regardless of the VM address it is mapped. Additionally, references, virtual functions, and virtual base classes have to be removed since those mechanisms also use raw pointers internally. -The [offset pointer in Metall](https://github.com/KIwabuchi/metall/blob/develop/include/metall/offset_ptr.hpp) is just an alias of [offset pointer in Boost.Interprocess](https://www.boost.org/doc/libs/release/doc/html/interprocess/offset_ptr.html). +The [offset pointer in Metall](https://github.com/KIwabuchi/copperr/blob/develop/include/copperr/offset_ptr.hpp) is just an alias of [offset pointer in Boost.Interprocess](https://www.boost.org/doc/libs/release/doc/html/interprocess/offset_ptr.html). ## STL Container diff --git a/docs/readthedocs/external/list.md b/docs/readthedocs/external/list.md index ec91cf13..e4e6cfcb 100644 --- a/docs/readthedocs/external/list.md +++ b/docs/readthedocs/external/list.md @@ -8,7 +8,7 @@ miniVite is a proxy app that implements a single phase of Louvain method in dist miniVite has a mode that uses Metall to store a graph in persistent memory to reuse the data and reduce the overall analytics workload. For building and running miniVite with Metall, -see the details located [here](https://github.com/ECP-ExaGraph/miniVite/tree/metallds2#minivite--metall-and-umap). +see the details located [here](https://github.com/ECP-ExaGraph/miniVite/tree/copperrds2#minivite--copperr-and-umap). ### Ripples diff --git a/docs/readthedocs/external/ripples-metall.patch b/docs/readthedocs/external/ripples-metall.patch index a11cd016..7c5e82b1 100644 --- a/docs/readthedocs/external/ripples-metall.patch +++ b/docs/readthedocs/external/ripples-metall.patch @@ -57,7 +57,7 @@ index a1c2b2f..3b260e6 100644 //! input graphs. struct GraphInputConfiguration { std::string IFileName{""}; //!< The input file name -+ std::string metall_dir{"/tmp/graph"}; //!< Where is the metall directory? ++ std::string copperr_dir{"/tmp/graph"}; //!< Where is the copperr directory? bool weighted{false}; //!< is Graph weighted? bool undirected{false}; //!< is Graph undirected? bool disable_renumbering{false}; //!< trust the input to be clean. @@ -65,8 +65,8 @@ index a1c2b2f..3b260e6 100644 "The input file with the edge-list.") ->group("Input Options") ->required(); -+ app.add_flag("--metall-store-dir", metall_dir, -+ "Directory to store metall graph data.") ++ app.add_flag("--copperr-store-dir", copperr_dir, ++ "Directory to store copperr graph data.") + ->group("Input Options"); app.add_flag("--reload-binary", reload, "Reload a graph from binary input") ->group("Input Options"); @@ -84,8 +84,8 @@ index df44175..919b063 100644 -#ifdef ENABLE_METALL +#ifdef ENABLE_METALL_RRRSETS - #include "metall/metall.hpp" - #include "metall/container/vector.hpp" + #include "copperr/copperr.hpp" + #include "copperr/container/vector.hpp" #endif @@ -72,13 +73,13 @@ namespace ripples { @@ -96,11 +96,11 @@ index df44175..919b063 100644 +using RRRsetAllocator = libmemkind::pmem::allocator; +#elif defined ENABLE_METALL_RRRSETS template - using RRRsetAllocator = metall::manager::allocator_type; + using RRRsetAllocator = dice::copperr::manager::allocator_type; - metall::manager &metall_manager_instance() { -- static metall::manager manager(metall::create_only, "/tmp/ripples"); -+ static metall::manager manager(metall::create_only, "/dev/shm/metall_tmp"); + dice::copperr::manager &copperr_manager_instance() { +- static dice::copperr::manager manager(dice::copperr::create_only, "/tmp/ripples"); ++ static dice::copperr::manager manager(dice::copperr::create_only, "/dev/shm/copperr_tmp"); return manager; } @@ -110,7 +110,7 @@ index df44175..919b063 100644 using RRRset = -#ifdef ENABLE_METALL +#ifdef ENABLE_METALL_RRRSETS - metall::container::vector>; #else diff --git a/include/ripples/graph.h b/include/ripples/graph.h @@ -124,7 +124,7 @@ index d34ecbe..2a027bb 100644 +#if defined ENABLE_METALL +#include +#include -+#include "metall/metall.hpp" ++#include "copperr/copperr.hpp" +#endif + namespace ripples { @@ -490,7 +490,7 @@ index 8030582..32c5e54 100644 - #elif defined ENABLE_METALL + RRRsetAllocator allocator("/mnt/bb/reeceneff/memkind_tmp", 0); + #elif defined ENABLE_METALL_RRRSETS - RRRsetAllocator allocator = metall_manager_instance().get_allocator(); + RRRsetAllocator allocator = copperr_manager_instance().get_allocator(); #else RRRsetAllocator allocator; @@ -266,10 +266,10 @@ auto Sampling(const GraphTy &G, const ConfTy &CFG, double l, @@ -501,7 +501,7 @@ index 8030582..32c5e54 100644 - #elif defined ENABLE_METALL + RRRsetAllocator allocator("/mnt/bb/reeceneff/memkind_tmp", 0); + #elif defined ENABLE_METALL_RRRSETS - RRRsetAllocator allocator = metall_manager_instance().get_allocator(); + RRRsetAllocator allocator = copperr_manager_instance().get_allocator(); -#else + #else RRRsetAllocator allocator; @@ -595,7 +595,7 @@ index 80bbe3a..b64b438 100644 RRRsetAllocator allocator("/pmem1", 0); - #elif defined ENABLE_METALL + #elif defined ENABLE_METALL_RRRSETS - RRRsetAllocator allocator = metall_manager_instance().get_allocator(); + RRRsetAllocator allocator = copperr_manager_instance().get_allocator(); #else RRRsetAllocator allocator; diff --git a/tools/imm.cc b/tools/imm.cc @@ -616,9 +616,9 @@ index e835c76..870821c 100644 using dest_type = ripples::WeightedDestination; + #if defined ENABLE_METALL + using GraphFwd = -+ ripples::Graph, metall::manager::allocator_type>; ++ ripples::Graph, dice::copperr::manager::allocator_type>; + using GraphBwd = -+ ripples::Graph, metall::manager::allocator_type>; ++ ripples::Graph, dice::copperr::manager::allocator_type>; + #else using GraphFwd = ripples::Graph>; @@ -629,10 +629,10 @@ index e835c76..870821c 100644 +console->info("Loading..."); +auto loading_start = std::chrono::high_resolution_clock::now(); +#if defined ENABLE_METALL -+bool exists = metall::manager::consistent(CFG.metall_dir.c_str()); -+metall::manager manager = (exists ? -+ metall::manager(metall::open_only, CFG.metall_dir.c_str()) -+ : metall::manager(metall::create_only, CFG.metall_dir.c_str())); ++bool exists = dice::copperr::manager::consistent(CFG.copperr_dir.c_str()); ++copperr::manager manager = (exists ? ++ dice::copperr::manager(dice::copperr::open_only, CFG.copperr_dir.c_str()) ++ : dice::copperr::manager(dice::copperr::create_only, CFG.copperr_dir.c_str())); + GraphBwd *Gr; + if(exists){ + console->info("Previously existing graph exists! Loading..."); @@ -640,7 +640,7 @@ index e835c76..870821c 100644 + // Gr->recalculate_addresses(); + } + else{ -+ console->info("Creating new metall directory..."); ++ console->info("Creating new copperr directory..."); + GraphFwd Gf = ripples::loadGraph(CFG, weightGen, manager.get_allocator()); + Gr = manager.construct("graph")(Gf.get_transpose(manager.get_allocator())); + } @@ -689,9 +689,9 @@ index 60091f8..0ddb121 100644 using edge_type = ripples::WeightedDestination; + #if defined ENABLE_METALL + using GraphFwd = -+ ripples::Graph, metall::manager::allocator_type>; ++ ripples::Graph, dice::copperr::manager::allocator_type>; + using GraphBwd = -+ ripples::Graph, metall::manager::allocator_type>; ++ ripples::Graph, dice::copperr::manager::allocator_type>; + #else using GraphFwd = ripples::Graph>; @@ -702,10 +702,10 @@ index 60091f8..0ddb121 100644 + #endif +console->info("Loading..."); +#if defined ENABLE_METALL -+bool exists = metall::manager::consistent(CFG.metall_dir.c_str()); -+metall::manager manager = (exists ? -+ metall::manager(metall::open_only, CFG.metall_dir.c_str()) -+ : metall::manager(metall::create_only, CFG.metall_dir.c_str())); ++bool exists = dice::copperr::manager::consistent(CFG.copperr_dir.c_str()); ++copperr::manager manager = (exists ? ++ dice::copperr::manager(dice::copperr::open_only, CFG.copperr_dir.c_str()) ++ : dice::copperr::manager(dice::copperr::create_only, CFG.copperr_dir.c_str())); + GraphBwd *Gr; + if(exists){ + console->info("Previously existing graph exists! Loading..."); @@ -713,7 +713,7 @@ index 60091f8..0ddb121 100644 + // Gr->recalculate_addresses(); + } + else{ -+ console->info("Creating new metall directory..."); ++ console->info("Creating new copperr directory..."); + GraphFwd Gf = ripples::loadGraph(CFG, weightGen, manager.get_allocator()); + Gr = manager.construct("graph")(Gf.get_transpose(manager.get_allocator())); + } @@ -734,8 +734,8 @@ index 5be422d..862e61b 100644 cuda_acc_cxx_flags += ['-DENABLE_MEMKIND=1'] if bld.env.ENABLE_METALL: -- cuda_acc_tools_deps += ['metall', 'boost'] -+ cuda_acc_tools_deps += ['metall', 'boost', 'libstdc++fs'] +- cuda_acc_tools_deps += ['copperr', 'boost'] ++ cuda_acc_tools_deps += ['copperr', 'boost', 'libstdc++fs'] cuda_acc_cxx_flags += ['-DENABLE_METALL=1'] bld(features='cxx cxxprogram', source='imm.cc', target='imm', diff --git a/docs/readthedocs/external/ripples.md b/docs/readthedocs/external/ripples.md index 22ab7784..65c236a1 100644 --- a/docs/readthedocs/external/ripples.md +++ b/docs/readthedocs/external/ripples.md @@ -44,7 +44,7 @@ cd ripples git checkout da08b3e759642a93556f081169c61607354ecd3e # Apply the patch file (download from the link under this code block) -git apply ripples-metall.patch +git apply ripples-copperr.patch # Hereafter, build instructions are described in the original Ripples: # https://github.com/pnnl/ripples/blob/master @@ -73,21 +73,21 @@ conan profile update env.CXX=$(which g++) default # Install dependencies conan create conan/waf-generator user/stable conan create conan/trng user/stable -conan create conan/metall user/stable +conan create conan/copperr user/stable # Enable the Metall mode conan install --install-folder build . --build fmt -o metal=True # Build -./waf configure --enable-metall build_release +./waf configure --enable-copperr build_release ``` -Download a patch file from here [ripples-metall.patch](./ripples-metall.patch). +Download a patch file from here [ripples-copperr.patch](./ripples-copperr.patch). ## Run Example ```shell -./build/release/tools/imm -i test-data/karate.tsv -e 0.5 -k 100 -d LT --parallel --metall-store-dir=/mnt/ssd/graph +./build/release/tools/imm -i test-data/karate.tsv -e 0.5 -k 100 -d LT --parallel --copperr-store-dir=/mnt/ssd/graph ``` - Reads edge data from test-data/karate.tsv @@ -99,4 +99,4 @@ Ripples + Metall has another mode that allocates intermediate data (called RRRSe To enable the mode, define `ENABLE_METALL_RRRSETS` macro (e.g., insert `#define ENABLE_METALL_RRRSETS` at the beginning of `tools/imm.cc`). -RRRSet (intermediate data) is allocated in `/dev/shm` (tmpfs) by default. To change the location, modify line 82 `include/ripples/generate_rrr_sets.h` and re-build the program (`./waf configure --enable-metall build_release`). \ No newline at end of file +RRRSet (intermediate data) is allocated in `/dev/shm` (tmpfs) by default. To change the location, modify line 82 `include/ripples/generate_rrr_sets.h` and re-build the program (`./waf configure --enable-copperr build_release`). \ No newline at end of file diff --git a/docs/readthedocs/index.md b/docs/readthedocs/index.md index 95b9135e..8739a967 100644 --- a/docs/readthedocs/index.md +++ b/docs/readthedocs/index.md @@ -1,6 +1,6 @@ # Metall: Persistent Memory Allocator for Data-Centric Analytics -This Read the Docs page describes Metall (open-source library available [here]((https://github.com/LLNL/metall))). +This Read the Docs page describes Metall (open-source library available [here]((https://github.com/LLNL/copperr))). ## Overview @@ -20,4 +20,4 @@ and provides persistent memory snapshotting (versioning) capabilities. Example programs that use Metall are listed [here](detail/example.md). -![Metall Overview](./img/metall_overview.png) +![Metall Overview](./img/copperr_overview.png) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt deleted file mode 100644 index fff4edf5..00000000 --- a/example/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -add_metall_executable(simple simple.cpp) - -add_metall_executable(vector_of_vectors vector_of_vectors.cpp) - -add_metall_executable(string string.cpp) - -add_metall_executable(string_map string_map.cpp) - -add_metall_executable(complex_map complex_map.cpp) - -add_metall_executable(offset_pointer offset_pointer.cpp) - -add_metall_executable(snapshot snapshot.cpp) - -add_metall_executable(csr_graph csr_graph.cpp) - -add_metall_executable(fallback_allocator_adaptor fallback_allocator_adaptor.cpp) - -add_metall_executable(datastore_description datastore_description.cpp) - -add_metall_executable(object_attribute object_attribute.cpp) - -add_metall_executable(object_attribute_api_list object_attribute_api_list.cpp) - -add_metall_executable(multilevel_containers multilevel_containers.cpp) - -add_metall_executable(adjacency_list_graph adjacency_list_graph.cpp) - -add_metall_executable(static_mutex static_mutex.cpp) - -add_metall_executable(concurrent_map concurrent_map.cpp) - -add_metall_executable(metall_containers metall_containers.cpp) - -add_metall_executable(allocator_aware_type allocator_aware_type.cpp) - -add_metall_executable(logger logger.cpp) - -if (BUILD_C) - add_c_executable(c_api c_api.c) - target_link_libraries(c_api PRIVATE metall_c) -endif() - -include(setup_mpi) -if (MPI_CXX_FOUND) - add_metall_executable(mpi_create mpi_create.cpp) - setup_mpi_target(mpi_create) - - add_metall_executable(mpi_open mpi_open.cpp) - setup_mpi_target(mpi_open) -else() - message(STATUS "Will skip building the MPI examples") -endif() - -add_subdirectory(json) -add_subdirectory(container) \ No newline at end of file diff --git a/example/c_api.c b/example/c_api.c deleted file mode 100644 index 1db9c3a3..00000000 --- a/example/c_api.c +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include -#include - -int main(void) { - // Basic allocation - { - metall_open(METALL_CREATE_ONLY, "/tmp/metall1"); - - uint64_t *x = metall_malloc(sizeof(uint64_t)); - x[0] = 1; - - metall_free(x); - - metall_close(); - } - - // Allocate named object - { - metall_open(METALL_CREATE_ONLY, "/tmp/metall2"); - - uint64_t *array = metall_named_malloc("array", sizeof(uint64_t) * 10); - - array[0] = 0; - - metall_flush(); - - array[1] = 1; - - metall_close(); - } - - // Retrieve named object - { - metall_open(METALL_OPEN_ONLY, "/tmp/metall2"); - - uint64_t *array = metall_find("array"); - - assert(array[0] == 0); - assert(array[1] == 1); - - metall_named_free("array"); - - metall_close(); - } - - return 0; -} \ No newline at end of file diff --git a/example/container/CMakeLists.txt b/example/container/CMakeLists.txt deleted file mode 100644 index 0ba68c7b..00000000 --- a/example/container/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") - add_metall_executable(string_key_store string_key_store.cpp) -endif() \ No newline at end of file diff --git a/example/json/CMakeLists.txt b/example/json/CMakeLists.txt deleted file mode 100644 index 2a60cfaa..00000000 --- a/example/json/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") - add_metall_executable(json_create json_create.cpp) - add_metall_executable(json_open json_open.cpp) - add_metall_executable(jgraph jgraph.cpp) - add_metall_executable(vector_of_json vector_of_json.cpp) -endif() \ No newline at end of file diff --git a/example/json/json_open.cpp b/example/json/json_open.cpp deleted file mode 100644 index 41a2641b..00000000 --- a/example/json/json_open.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -using metall_value_type = - metall::json::value>; - -int main() { - std::cout << "Open" << std::endl; - { - metall::manager manager(metall::open_read_only, "./test"); - auto *value = - manager.find(metall::unique_instance).first; - metall::json::pretty_print(std::cout, *value); - } - - { - metall::manager manager(metall::open_only, "./test"); - manager.destroy(metall::unique_instance); - } - - return 0; -} diff --git a/example/logger.cpp b/example/logger.cpp deleted file mode 100644 index efc98653..00000000 --- a/example/logger.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include - -int main() { - // Set the log level to , for example, verbose. - // The log level can be changed at any time. - metall::logger::set_log_level(metall::logger::level::verbose); - - // Enable the program to abort when a critical log message is displayed. - metall::logger::abort_on_critical_error(true); - - // Do Metall operations - metall::manager manager(metall::create_only, "/tmp/dir"); - - return 0; -} \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..0dcb5d02 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,58 @@ +add_copperr_executable(simple simple.cpp) + +add_copperr_executable(vector_of_vectors vector_of_vectors.cpp) + +add_copperr_executable(string string.cpp) + +add_copperr_executable(string_map string_map.cpp) + +add_copperr_executable(complex_map complex_map.cpp) + +add_copperr_executable(offset_pointer offset_pointer.cpp) + +add_copperr_executable(snapshot snapshot.cpp) + +add_copperr_executable(csr_graph csr_graph.cpp) + +add_copperr_executable(fallback_allocator_adaptor fallback_allocator_adaptor.cpp) + +add_copperr_executable(datastore_description datastore_description.cpp) + +add_copperr_executable(object_attribute object_attribute.cpp) + +add_copperr_executable(object_attribute_api_list object_attribute_api_list.cpp) + +add_copperr_executable(multilevel_containers multilevel_containers.cpp) + +add_copperr_executable(adjacency_list_graph adjacency_list_graph.cpp) + +add_copperr_executable(static_mutex static_mutex.cpp) + +add_copperr_executable(concurrent_map concurrent_map.cpp) + +add_copperr_executable(copperr_containers copperr_containers.cpp) + +add_copperr_executable(allocator_aware_type allocator_aware_type.cpp) + +add_executable(logger logger.cpp) +target_link_libraries(logger ${PROJECT_NAME}::${PROJECT_NAME}) +set_target_properties(logger PROPERTIES CXX_STANDARD 20) + +if (BUILD_FFI) + add_copperr_executable(c_api c_api.c) + target_link_libraries(c_api PRIVATE ${PROJECT_NAME}::ffi) +endif() + +include(${CMAKE_SOURCE_DIR}/cmake/setup_mpi.cmake) +if (MPI_CXX_FOUND) + add_copperr_executable(mpi_create mpi_create.cpp) + setup_mpi_target(mpi_create) + + add_copperr_executable(mpi_open mpi_open.cpp) + setup_mpi_target(mpi_open) +else() + message(STATUS "Will skip building the MPI examples") +endif() + +add_subdirectory(json) +add_subdirectory(container) diff --git a/example/README.md b/examples/README.md similarity index 85% rename from example/README.md rename to examples/README.md index f5da344b..b66ecce0 100644 --- a/example/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ # List of Examples -To build examples see a [page](https://metall.readthedocs.io/en/latest/advanced_build/cmake/) hosted on Read the Docs. +To build examples see a [page](https://copperr.readthedocs.io/en/latest/advanced_build/cmake/) hosted on Read the Docs. ### Basic examples @@ -19,7 +19,7 @@ To build examples see a [page](https://metall.readthedocs.io/en/latest/advanced_ ### STL Container with Custom Allocator -In the examples below, we occasionally use STL-compatible containers exist in [metall/container/](../include/metall/container/) for better readability. +In the examples below, we occasionally use STL-compatible containers exist in [copperr/container/](../include/copperr/container/) for better readability. Those containers are just alias of the corresponding containers in Boost.Container and do not have Metall-specific features. Therefore, the data structures in the examples below are more like how to use STL containers with custom allocators rather than how to use containers with just Metall. @@ -69,7 +69,7 @@ Therefore, the data structures in the examples below are more like how to use ST ### Metall's Original Container -* [metall_containers.cpp](metall_containers.cpp) +* [copperr_containers.cpp](copperr_containers.cpp) * List of containers that use Metall at the default allocators. ### Graph @@ -87,18 +87,18 @@ Therefore, the data structures in the examples below are more like how to use ST * [static_mutex.cpp](static_mutex.cpp) - * How to use our [mutex_lock function](../include/metall/utility/mutex.hpp) + * How to use our [mutex_lock function](../include/copperr/utility/mutex.hpp) * [concurrent_map.cpp](concurrent_map.cpp) - * How to use our [persistent concurrent_map class](../include/metall/container/concurrent_map.hpp) + * How to use our [persistent concurrent_map class](../include/copperr/container/concurrent_map.hpp) ### Fallback Allocator * [fallback_allocator_adaptor.cpp](fallback_allocator_adaptor.cpp) - * How to use [fallback_allocator_adaptor](../include/metall/utility/fallback_allocator_adaptor.hpp) + * How to use [fallback_allocator_adaptor](../include/copperr/utility/fallback_allocator_adaptor.hpp) ### MPI (experimental implementation) diff --git a/example/adjacency_list_graph.cpp b/examples/adjacency_list_graph.cpp similarity index 81% rename from example/adjacency_list_graph.cpp rename to examples/adjacency_list_graph.cpp index 7fb6ca53..4ac8dc6a 100644 --- a/example/adjacency_list_graph.cpp +++ b/examples/adjacency_list_graph.cpp @@ -5,17 +5,17 @@ #include -#include +#include #include "graph_data_structure/adjacency_list.hpp" using vid_t = uint64_t; using adj_list_graph_t = - adjacency_list>; + adjacency_list>; int main() { { // Create a new Metall datastore in "/tmp/dir" - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); // Allocate and construct an object in the persistent memory with a name // "adj_list_graph" @@ -29,7 +29,7 @@ int main() { { // Open the existing Metall datastore in "/tmp/dir" - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); adj_list_graph_t *adj_list_graph = manager.find("adj_list_graph").first; diff --git a/example/allocator_aware_type.cpp b/examples/allocator_aware_type.cpp similarity index 86% rename from example/allocator_aware_type.cpp rename to examples/allocator_aware_type.cpp index 9a5cfc88..6b8dba38 100644 --- a/example/allocator_aware_type.cpp +++ b/examples/allocator_aware_type.cpp @@ -9,10 +9,10 @@ #include #include -#include -#include +#include +#include -#include +#include // A simple allocator-aware class, which uses an allocator to allocate internal // contents and can be stored in an STL container. @@ -32,7 +32,7 @@ struct key_value_pair { using allocator_type = Alloc; // Use the given allocator type in the key - using key_type = metall::container::basic_string< + using key_type = dice::copperr::container::basic_string< char, std::char_traits, typename std::allocator_traits::template rebind_alloc< char>>; @@ -64,7 +64,7 @@ struct key_value_pair { // We use Metall in this example but any STL compatible allocator can be used. template -using alloc_t = metall::manager::allocator_type; +using alloc_t = dice::copperr::manager::allocator_type; using kv_t = key_value_pair>; @@ -73,12 +73,12 @@ using kv_t = key_value_pair>; // the inner containers (allocator-aware types) use the same allocator. See: // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor using vec_t = - metall::container::vector>>; int main() { { - metall::manager manager(metall::create_only, "/tmp/metall-dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/copperr-dir"); auto *vec = manager.construct("vec")(manager.get_allocator()); vec->resize(2); @@ -91,7 +91,7 @@ int main() { } { - metall::manager manager(metall::open_read_only, "/tmp/metall-dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/copperr-dir"); auto *vec = manager.find("vec").first; for (const auto &e : *vec) { std::cout << e.key << " : " << e.value << std::endl; diff --git a/examples/c_api.c b/examples/c_api.c new file mode 100644 index 00000000..55ccdad3 --- /dev/null +++ b/examples/c_api.c @@ -0,0 +1,49 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#include +#include +#include + +int main(void) { + // Basic allocation + { + copperr_manager *manager = copperr_create("/tmp/copperr1"); + + uint64_t *x = copperr_malloc(manager, sizeof(uint64_t)); + x[0] = 1; + + copperr_free(manager, x); + copperr_close(manager); + } + + // Allocate named object + { + copperr_manager *manager = copperr_create("/tmp/copperr1"); + + uint64_t *array = copperr_named_malloc(manager, "array", sizeof(uint64_t) * 10); + + array[0] = 0; + array[1] = 1; + + copperr_close(manager); + } + + // Retrieve named object + { + copperr_manager *manager = copperr_open("/tmp/copperr1"); + + uint64_t *array = copperr_find(manager, "array"); + + assert(array[0] == 0); + assert(array[1] == 1); + + copperr_named_free(manager, "array"); + copperr_close(manager); + copperr_remove("/tmp/copperrl1"); + } + + return 0; +} \ No newline at end of file diff --git a/example/cmake/FetchContent/CMakeLists.txt b/examples/cmake/FetchContent/CMakeLists.txt similarity index 91% rename from example/cmake/FetchContent/CMakeLists.txt rename to examples/cmake/FetchContent/CMakeLists.txt index 612bcbce..aabaf082 100644 --- a/example/cmake/FetchContent/CMakeLists.txt +++ b/examples/cmake/FetchContent/CMakeLists.txt @@ -29,7 +29,7 @@ if (NOT BUILD_C) endif() FetchContent_Declare( Metall - GIT_REPOSITORY https://github.com/LLNL/metall.git + GIT_REPOSITORY https://github.com/LLNL/copperr.git GIT_TAG master ) FetchContent_MakeAvailable(Metall) @@ -60,6 +60,6 @@ target_link_libraries(cpp_example PRIVATE Metall::Metall) if (BUILD_C) add_executable(c_example ../src/c_example.c) - # Link Metall C library (libmetall_c) - target_link_libraries(c_example PRIVATE Metall::metall_c) + # Link Metall C library (libcopperr_c) + target_link_libraries(c_example PRIVATE Metall::copperr_c) endif () \ No newline at end of file diff --git a/example/cmake/FetchContent/README.md b/examples/cmake/FetchContent/README.md similarity index 100% rename from example/cmake/FetchContent/README.md rename to examples/cmake/FetchContent/README.md diff --git a/example/cmake/README.md b/examples/cmake/README.md similarity index 100% rename from example/cmake/README.md rename to examples/cmake/README.md diff --git a/example/cmake/find_package/CMakeLists.txt b/examples/cmake/find_package/CMakeLists.txt similarity index 87% rename from example/cmake/find_package/CMakeLists.txt rename to examples/cmake/find_package/CMakeLists.txt index 200c804d..818ec657 100644 --- a/example/cmake/find_package/CMakeLists.txt +++ b/examples/cmake/find_package/CMakeLists.txt @@ -40,12 +40,12 @@ endif () # ---------------------------------------- # # Not required to do this. -# Just checking if metall_c exists. -find_library(LIB_METALL_C NAMES metall_c) +# Just checking if copperr_c exists. +find_library(LIB_METALL_C NAMES copperr_c) if (LIB_METALL_C) add_executable(c_example ../src/c_example.c) - # Link Metall C library (libmetall_c) - target_link_libraries(c_example PRIVATE Metall::metall_c) + # Link Metall C library (libcopperr_c) + target_link_libraries(c_example PRIVATE Metall::copperr_c) endif() \ No newline at end of file diff --git a/example/cmake/find_package/README.md b/examples/cmake/find_package/README.md similarity index 92% rename from example/cmake/find_package/README.md rename to examples/cmake/find_package/README.md index 86befd4a..8df7b70e 100644 --- a/example/cmake/find_package/README.md +++ b/examples/cmake/find_package/README.md @@ -14,7 +14,7 @@ Here is how to build example programs. To install Metall at `"/path/to/install"`, for example: ```bash -cd metall +cd copperr mkdir build cd build @@ -35,7 +35,7 @@ Please note that Metall C API is not supported with Spack. ```bash # Install Metall using Spack # Boost is also install -spack install metall +spack install copperr ``` @@ -49,7 +49,7 @@ cd build export CMAKE_PREFIX_PATH="/path/to/install" # Or (if one uses Spack) -spack load metall # Spack exports CMAKE_PREFIX_PATH (and also BOOST_ROOT). +spack load copperr # Spack exports CMAKE_PREFIX_PATH (and also BOOST_ROOT). cmake ../ \ -DBOOST_ROOT=/path/to/boost # Required if one wants to build programs that uses Metall C++ API. diff --git a/example/cmake/src/c_example.c b/examples/cmake/src/c_example.c similarity index 68% rename from example/cmake/src/c_example.c rename to examples/cmake/src/c_example.c index 9798be2a..459a5588 100644 --- a/example/cmake/src/c_example.c +++ b/examples/cmake/src/c_example.c @@ -3,11 +3,11 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include +#include int main(void) { - metall_open(METALL_CREATE_ONLY, "/tmp/dir"); - metall_close(); + copperr_open(METALL_CREATE_ONLY, "/tmp/dir"); + copperr_close(); return 0; } \ No newline at end of file diff --git a/example/cmake/src/cpp_example.cpp b/examples/cmake/src/cpp_example.cpp similarity index 67% rename from example/cmake/src/cpp_example.cpp rename to examples/cmake/src/cpp_example.cpp index f4fd840b..3646ad99 100644 --- a/example/cmake/src/cpp_example.cpp +++ b/examples/cmake/src/cpp_example.cpp @@ -3,9 +3,9 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include +#include int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); return 0; } \ No newline at end of file diff --git a/example/complex_map.cpp b/examples/complex_map.cpp similarity index 83% rename from example/complex_map.cpp rename to examples/complex_map.cpp index 8c9849cf..9b93f92a 100644 --- a/example/complex_map.cpp +++ b/examples/complex_map.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include namespace bc = boost::container; @@ -47,13 +47,13 @@ using map_type = std::less<>, map_allocator_type>; // Map type instantiated to Metall -using metall_map_type = map_type>; +using copperr_map_type = map_type>; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pmap = - manager.construct("map")(manager.get_allocator<>()); + manager.construct("map")(manager.get_allocator<>()); (*pmap)[0]; pmap->at(0).vec.push_back(0); @@ -65,8 +65,8 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); - auto pmap = manager.find("map").first; + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); + auto pmap = manager.find("map").first; std::cout << pmap->at(0).vec[0] << std::endl; // Prints out "0" std::cout << pmap->at(0).str << std::endl; // Prints out "hello, world 0" diff --git a/example/concurrent_map.cpp b/examples/concurrent_map.cpp similarity index 84% rename from example/concurrent_map.cpp rename to examples/concurrent_map.cpp index bbaa527c..4b3ce582 100644 --- a/example/concurrent_map.cpp +++ b/examples/concurrent_map.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include +#include +#include -using map_type = metall::container::concurrent_map< +using map_type = dice::copperr::container::concurrent_map< char, int, std::less, std::hash, - metall::manager::allocator_type>>; + dice::copperr::manager::allocator_type>>; bool insert_func1(const char key, const int value, map_type *pmap) { return pmap->insert(std::make_pair(key, value)); @@ -41,7 +41,7 @@ void edit(const char key, const int value, map_type *pmap) { int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pmap = manager.construct("map")(manager.get_allocator<>()); // Insert elements concurrently, using the 3 styles @@ -69,7 +69,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto pmap = manager.find("map").first; // Of course, one can update values after reattaching diff --git a/examples/container/CMakeLists.txt b/examples/container/CMakeLists.txt new file mode 100644 index 00000000..56f9fd97 --- /dev/null +++ b/examples/container/CMakeLists.txt @@ -0,0 +1,3 @@ +if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") + add_copperr_executable(string_key_store string_key_store.cpp) +endif() \ No newline at end of file diff --git a/example/container/string_key_store.cpp b/examples/container/string_key_store.cpp similarity index 75% rename from example/container/string_key_store.cpp rename to examples/container/string_key_store.cpp index 38f24467..b66af575 100644 --- a/example/container/string_key_store.cpp +++ b/examples/container/string_key_store.cpp @@ -3,12 +3,12 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include -#include -#include +#include +#include +#include -namespace mc = metall::container; -namespace mj = metall::json; +namespace mc = dice::copperr::container; +namespace mj = dice::copperr::json; // Example of a string-key-store with int value. void int_store_example(); @@ -24,7 +24,7 @@ int main() { void int_store_example() { using int_store_type = mc::string_key_store; { - metall::manager manager(metall::create_only, "./string_key_store_obj"); + dice::copperr::manager manager(dice::copperr::create_only, "./string_key_store_obj"); // Allocate an instance of the int-store which accept duplicate keys by // default. @@ -37,7 +37,7 @@ void int_store_example() { } { - metall::manager manager(metall::open_read_only, "./string_key_store_obj"); + dice::copperr::manager manager(dice::copperr::open_read_only, "./string_key_store_obj"); auto *store = manager.find("int-store").first; // Iterate over all elements @@ -48,10 +48,10 @@ void int_store_example() { } void json_store_example() { - using json_type = mj::value>; + using json_type = mj::value>; using json_store_type = mc::string_key_store; { - metall::manager manager(metall::open_only, "./string_key_store_obj"); + dice::copperr::manager manager(dice::copperr::open_only, "./string_key_store_obj"); const bool unique = true; const uint64_t hash_seed = 123; @@ -66,7 +66,7 @@ void json_store_example() { } { - metall::manager manager(metall::open_read_only, "./string_key_store_obj"); + dice::copperr::manager manager(dice::copperr::open_read_only, "./string_key_store_obj"); auto *store = manager.find("json-store").first; // Use find() to locate an element. diff --git a/example/metall_containers.cpp b/examples/copperr_containers.cpp similarity index 72% rename from example/metall_containers.cpp rename to examples/copperr_containers.cpp index 1ab379d6..61716ae7 100644 --- a/example/metall_containers.cpp +++ b/examples/copperr_containers.cpp @@ -3,33 +3,33 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Boost 1.81 or later is required #if BOOST_VERSION >= 108100 -#include -#include +#include +#include #endif // Boost 1.82 or later is required #if BOOST_VERSION >= 108200 -#include -#include +#include +#include #endif -using namespace metall; -namespace mc = metall::container; +using namespace dice::copperr; +namespace mc = dice::copperr::container; int main() { manager mg(create_only, "/tmp/dir"); diff --git a/example/csr_graph.cpp b/examples/csr_graph.cpp similarity index 81% rename from example/csr_graph.cpp rename to examples/csr_graph.cpp index c56579c5..bc27f3e6 100644 --- a/example/csr_graph.cpp +++ b/examples/csr_graph.cpp @@ -5,7 +5,7 @@ #include -#include +#include #include "graph_data_structure/csr.hpp" #include "graph_data_structure/csr_using_vector.hpp" @@ -14,17 +14,17 @@ using vid_t = uint64_t; // We have two CSR graph data structures that have the same interfaces #if 0 -using csr_graph_t = csr>; +using csr_graph_t = csr>; #else using csr_graph_t = - csr_using_vector>; + csr_using_vector>; #endif int main() { { // Create a new Metall datastore in "/tmp/dir" // If 'dir' does not exist, Metall creates automatically - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); std::size_t num_vertices = 16; std::size_t num_edges = 256; @@ -43,7 +43,7 @@ int main() { { // Open the existing Metall datastore in "/tmp/dir" - metall::manager manager(metall::open_read_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); csr_graph_t *csr_graph = manager.find("csr_graph").first; if (!csr_graph) { diff --git a/example/datastore_description.cpp b/examples/datastore_description.cpp similarity index 77% rename from example/datastore_description.cpp rename to examples/datastore_description.cpp index 21df681b..315bd565 100644 --- a/example/datastore_description.cpp +++ b/examples/datastore_description.cpp @@ -7,12 +7,12 @@ #include #include -#include +#include int main() { // ----- Non-static methods ----- // { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); std::string buf; [[maybe_unused]] const auto ret = manager.get_description(&buf); @@ -26,10 +26,10 @@ int main() { // ----- Static methods ----- // { - metall::manager::set_description("/tmp/dir", "description example 2"); + dice::copperr::manager::set_description("/tmp/dir", "description example 2"); std::string buf; - metall::manager::get_description("/tmp/dir", &buf); + dice::copperr::manager::get_description("/tmp/dir", &buf); std::cout << buf << std::endl; // Shows "description example 2" } diff --git a/example/fallback_allocator_adaptor.cpp b/examples/fallback_allocator_adaptor.cpp similarity index 70% rename from example/fallback_allocator_adaptor.cpp rename to examples/fallback_allocator_adaptor.cpp index e4d291fd..8ae69a75 100644 --- a/example/fallback_allocator_adaptor.cpp +++ b/examples/fallback_allocator_adaptor.cpp @@ -7,23 +7,23 @@ #include -#include -#include +#include +#include // The line below is the only change required to use fallback_allocator_adaptor. -// Wraps up 'metall::manager::allocator_type<..>' with +// Wraps up 'copperr::manager::allocator_type<..>' with // fallback_allocator_adaptor. -using allocator_t = metall::utility::fallback_allocator_adaptor< - metall::manager::allocator_type>; +using allocator_t = dice::copperr::utility::fallback_allocator_adaptor< + dice::copperr::manager::allocator_type>; using vector_t = boost::container::vector; int main() { // Allocation with Metall // The code below works with both 'fallback_allocator_adaptor<..>' and - // 'metall::manager::allocator_type<...>'. + // 'copperr::manager::allocator_type<...>'. { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto pvec = manager.construct("vec")(manager.get_allocator()); pvec->push_back(1); std::cout << (*pvec)[0] << std::endl; diff --git a/example/graph_data_structure/adjacency_list.hpp b/examples/graph_data_structure/adjacency_list.hpp similarity index 100% rename from example/graph_data_structure/adjacency_list.hpp rename to examples/graph_data_structure/adjacency_list.hpp diff --git a/example/graph_data_structure/csr.hpp b/examples/graph_data_structure/csr.hpp similarity index 95% rename from example/graph_data_structure/csr.hpp rename to examples/graph_data_structure/csr.hpp index 3ad3e0d9..bfd36f98 100644 --- a/example/graph_data_structure/csr.hpp +++ b/examples/graph_data_structure/csr.hpp @@ -7,7 +7,7 @@ #define METALL_EXAMPLE_GRAPH_DATA_STRUCTURE_CSR_HPP #include -#include +#include /// \brief Simple CSR graph data structure that can take a custom C++ allocator /// and be stored in persistent memory \tparam index_t Index type \tparam vid_t @@ -57,14 +57,14 @@ class csr { /// \brief Returns a raw pointer to the indices array index_t *indices() { - return metall::to_raw_pointer(m_indices); + return dice::copperr::to_raw_pointer(m_indices); // return std::pointer_traits::to_address(m_indices); // // From C++20 } /// \brief Returns a raw pointer to the edges array vid_t *edges() { - return metall::to_raw_pointer(m_edges); + return dice::copperr::to_raw_pointer(m_edges); // return std::pointer_traits::to_address(m_edges); // From // C++20 } diff --git a/example/graph_data_structure/csr_using_vector.hpp b/examples/graph_data_structure/csr_using_vector.hpp similarity index 100% rename from example/graph_data_structure/csr_using_vector.hpp rename to examples/graph_data_structure/csr_using_vector.hpp diff --git a/examples/json/CMakeLists.txt b/examples/json/CMakeLists.txt new file mode 100644 index 00000000..d99ca47b --- /dev/null +++ b/examples/json/CMakeLists.txt @@ -0,0 +1,6 @@ +if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") + add_copperr_executable(json_create json_create.cpp) + add_copperr_executable(json_open json_open.cpp) + add_copperr_executable(jgraph jgraph.cpp) + add_copperr_executable(vector_of_json vector_of_json.cpp) +endif() \ No newline at end of file diff --git a/example/json/jgraph.cpp b/examples/json/jgraph.cpp similarity index 72% rename from example/json/jgraph.cpp rename to examples/json/jgraph.cpp index c809b18d..b8e409ae 100644 --- a/example/json/jgraph.cpp +++ b/examples/json/jgraph.cpp @@ -5,11 +5,11 @@ #include #include -#include -#include +#include +#include -using namespace metall::container::experimental; -using graph_type = jgraph::jgraph>; +using namespace dice::copperr::container::experimental; +using graph_type = jgraph::jgraph>; std::vector input_json_string_list = { R"({"type":"node", "id":"0", "properties":["user0"]})", @@ -24,12 +24,12 @@ std::vector input_json_string_list = { int main() { { std::cout << "-- Create ---" << std::endl; - metall::manager manager(metall::create_only, "./jgraph_obj"); + dice::copperr::manager manager(dice::copperr::create_only, "./jgraph_obj"); - auto *graph = manager.construct(metall::unique_instance)( + auto *graph = manager.construct(dice::copperr::unique_instance)( manager.get_allocator()); for (const auto &json_string : input_json_string_list) { - auto value = metall::json::parse(json_string, manager.get_allocator()); + auto value = dice::copperr::json::parse(json_string, manager.get_allocator()); if (value.as_object()["type"].as_string() == "node") { const auto &vertex_id = value.as_object()["id"].as_string(); @@ -46,16 +46,16 @@ int main() { { std::cout << "\n--- Open ---" << std::endl; - metall::manager manager(metall::open_read_only, "./jgraph_obj"); + dice::copperr::manager manager(dice::copperr::open_read_only, "./jgraph_obj"); const auto *const graph = - manager.find(metall::unique_instance).first; + manager.find(dice::copperr::unique_instance).first; std::cout << "" << std::endl; - metall::json::pretty_print(std::cout, graph->find_vertex("0")->value()); - metall::json::pretty_print(std::cout, graph->find_vertex("1")->value()); - metall::json::pretty_print(std::cout, graph->find_vertex("2")->value()); - metall::json::pretty_print(std::cout, graph->find_vertex("3")->value()); + dice::copperr::json::pretty_print(std::cout, graph->find_vertex("0")->value()); + dice::copperr::json::pretty_print(std::cout, graph->find_vertex("1")->value()); + dice::copperr::json::pretty_print(std::cout, graph->find_vertex("2")->value()); + dice::copperr::json::pretty_print(std::cout, graph->find_vertex("3")->value()); // Access edge values and edge values using the iterators std::cout << "\n" << std::endl; @@ -74,7 +74,7 @@ int main() { std::cout << "Destination vertex ID = " << eitr->source_id() << std::endl; } - metall::json::pretty_print(std::cout, eitr->value()); + dice::copperr::json::pretty_print(std::cout, eitr->value()); } std::cout << std::endl; } diff --git a/example/json/json_create.cpp b/examples/json/json_create.cpp similarity index 66% rename from example/json/json_create.cpp rename to examples/json/json_create.cpp index af558751..9d9d207c 100644 --- a/example/json/json_create.cpp +++ b/examples/json/json_create.cpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include -#include +#include +#include int main() { std::string json_string = R"( @@ -27,13 +27,13 @@ int main() { std::cout << "Create" << std::endl; - using metall_value_type = - metall::json::value>; - metall::manager manager(metall::create_only, "./test"); + using copperr_value_type = + dice::copperr::json::value>; + dice::copperr::manager manager(dice::copperr::create_only, "./test"); - auto *value = manager.construct(metall::unique_instance)( - metall::json::parse(json_string, manager.get_allocator())); - metall::json::pretty_print(std::cout, *value); + auto *value = manager.construct(dice::copperr::unique_instance)( + dice::copperr::json::parse(json_string, manager.get_allocator())); + dice::copperr::json::pretty_print(std::cout, *value); value->as_object()["name"].as_string() = "Alice"; // Change a string value @@ -45,7 +45,7 @@ int main() { auto pos = value->as_object().find("happy"); std::cout << "Happy? : " << pos->value() << std::endl; - metall::json::pretty_print(std::cout, *value); + dice::copperr::json::pretty_print(std::cout, *value); const auto clone(*value); std::cout << (clone == *value) << std::endl; diff --git a/examples/json/json_open.cpp b/examples/json/json_open.cpp new file mode 100644 index 00000000..dba4aaae --- /dev/null +++ b/examples/json/json_open.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +using copperr_value_type = + dice::copperr::json::value>; + +int main() { + std::cout << "Open" << std::endl; + { + dice::copperr::manager manager(dice::copperr::open_read_only, "./test"); + auto *value = + manager.find(dice::copperr::unique_instance).first; + dice::copperr::json::pretty_print(std::cout, *value); + } + + { + dice::copperr::manager manager(dice::copperr::open_only, "./test"); + manager.destroy(dice::copperr::unique_instance); + } + + return 0; +} diff --git a/example/json/vector_of_json.cpp b/examples/json/vector_of_json.cpp similarity index 62% rename from example/json/vector_of_json.cpp rename to examples/json/vector_of_json.cpp index 004f2986..90a242d6 100644 --- a/example/json/vector_of_json.cpp +++ b/examples/json/vector_of_json.cpp @@ -4,22 +4,22 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include -#include -#include +#include +#include +#include -namespace mc = metall::container; -namespace mj = metall::json; +namespace mc = dice::copperr::container; +namespace mj = dice::copperr::json; int main() { // Metall JSON container works like the other containers w.r.t. allocation, // i.e., it takes an allocator type in its template parameter and an allocator // object in its constructors. - using json_value_type = mj::value>; + using json_value_type = mj::value>; // Need to use scoped_allocator as this is a multi-layer container. using vector_json_type = mc::vector>; + dice::copperr::manager::scoped_allocator_type>; // An example input json strings. std::vector json_string_list{ @@ -28,8 +28,8 @@ int main() { // Create a vector-of-json object { - metall::manager manager(metall::create_only, "./test"); - auto *vec = manager.construct(metall::unique_instance)( + dice::copperr::manager manager(dice::copperr::create_only, "./test"); + auto *vec = manager.construct(dice::copperr::unique_instance)( manager.get_allocator()); for (const auto &json_string : json_string_list) { vec->emplace_back(mj::parse(json_string, manager.get_allocator())); @@ -38,8 +38,8 @@ int main() { // Reattach the vector-of-json object created above. { - metall::manager manager(metall::open_read_only, "./test"); - auto *vec = manager.find(metall::unique_instance).first; + dice::copperr::manager manager(dice::copperr::open_read_only, "./test"); + auto *vec = manager.find(dice::copperr::unique_instance).first; for (const auto &json : *vec) { mj::pretty_print(std::cout, json); // Show contents. } diff --git a/examples/logger.cpp b/examples/logger.cpp new file mode 100644 index 00000000..7781ac7c --- /dev/null +++ b/examples/logger.cpp @@ -0,0 +1,21 @@ +// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#include + +// define logger ops +extern "C" void copperr_log([[maybe_unused]] copperr_log_level lvl, + [[maybe_unused]] char const *file, + [[maybe_unused]] size_t line, + char const *function, char const *message) { + std::cerr << "(" << function << "): " << message << std::endl; +} + +int main() { + // Do Copperr operations + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); + + return 0; +} \ No newline at end of file diff --git a/example/mpi_create.cpp b/examples/mpi_create.cpp similarity index 61% rename from example/mpi_create.cpp rename to examples/mpi_create.cpp index fc28c583..5c7185fa 100644 --- a/example/mpi_create.cpp +++ b/examples/mpi_create.cpp @@ -3,8 +3,8 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include -#include +#include +#include int main(int argc, char **argv) { ::MPI_Init(&argc, &argv); @@ -14,15 +14,15 @@ int main(int argc, char **argv) { // MPI ranks. // To forcibly remove the existing datastore, one can use the following // code. - // metall::utility::filesystem::remove("/tmp/metall_mpi"); + // dice::copperr::utility::filesystem::remove("/tmp/copperr_mpi"); // ::MPI_Barrier(MPI_COMM_WORLD); bool overwrite = true; - metall::utility::metall_mpi_adaptor mpi_adaptor( - metall::create_only, "/tmp/metall_mpi", MPI_COMM_WORLD, overwrite); - auto &metall_manager = mpi_adaptor.get_local_manager(); + dice::copperr::utility::copperr_mpi_adaptor mpi_adaptor( + dice::copperr::create_only, "/tmp/copperr_mpi", MPI_COMM_WORLD, overwrite); + auto &copperr_manager = mpi_adaptor.get_local_manager(); - auto rank = metall_manager.construct("my-rank")(); + auto rank = copperr_manager.construct("my-rank")(); ::MPI_Comm_rank(MPI_COMM_WORLD, rank); // Stores my rank } ::MPI_Finalize(); diff --git a/example/mpi_open.cpp b/examples/mpi_open.cpp similarity index 62% rename from example/mpi_open.cpp rename to examples/mpi_open.cpp index 579c0bb9..bb8134a6 100644 --- a/example/mpi_open.cpp +++ b/examples/mpi_open.cpp @@ -3,16 +3,16 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include +#include int main(int argc, char **argv) { ::MPI_Init(&argc, &argv); { - metall::utility::metall_mpi_adaptor mpi_adaptor(metall::open_only, - "/tmp/metall_mpi"); - auto &metall_manager = mpi_adaptor.get_local_manager(); + dice::copperr::utility::copperr_mpi_adaptor mpi_adaptor(dice::copperr::open_only, + "/tmp/copperr_mpi"); + auto &copperr_manager = mpi_adaptor.get_local_manager(); - auto stored_rank = metall_manager.find("my-rank").first; + auto stored_rank = copperr_manager.find("my-rank").first; int rank; ::MPI_Comm_rank(MPI_COMM_WORLD, &rank); diff --git a/example/multilevel_containers.cpp b/examples/multilevel_containers.cpp similarity index 81% rename from example/multilevel_containers.cpp rename to examples/multilevel_containers.cpp index bba0d3b9..93bc43ae 100644 --- a/example/multilevel_containers.cpp +++ b/examples/multilevel_containers.cpp @@ -11,14 +11,14 @@ // vector // > // >; -// As Metall has a STL compatible allocator (metall::manager::allocator_type), +// As Metall has a STL compatible allocator (dice::copperr::manager::allocator_type), // all you have to do is just following the standard way to use custom allocator // in containers // -------------------- // #include #include -#include +#include // We recommend you to use containers implemented in Boost libraries because // they fully support the offset pointer @@ -32,12 +32,12 @@ using boost::container::scoped_allocator_adaptor; using boost::container::vector; // Inner vector type -using vector_type = vector>; +using vector_type = vector>; // Inner multimap type using multimap_type = unordered_multimap< uint64_t, vector_type, std::hash, std::equal_to, - metall::manager::allocator_type>>; + dice::copperr::manager::allocator_type>>; // To use custom allocator in multi-level containers, you have to use // scoped_allocator_adaptor in the most outer container so that the inner @@ -45,15 +45,15 @@ using multimap_type = unordered_multimap< // scoped_allocator_adaptor See: // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor using map_allocator_type = scoped_allocator_adaptor< - metall::manager::allocator_type>>; + dice::copperr::manager::allocator_type>>; using map_type = unordered_map, std::equal_to, map_allocator_type>; int main() { { - // Create a new metall object - metall::manager manager(metall::create_only, "/tmp/datastore"); + // Create a new copperr object + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); // Construct an object of map_type map_type* pmap = @@ -70,7 +70,7 @@ int main() { { // Open the snapshot - metall::manager manager(metall::open_only, "/tmp/datastore_snapshot"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore_snapshot"); // Find already allocated object with name 'map' map_type* pmap = manager.find("map").first; diff --git a/example/object_attribute.cpp b/examples/object_attribute.cpp similarity index 78% rename from example/object_attribute.cpp rename to examples/object_attribute.cpp index 9d8b27bb..dd7fc10d 100644 --- a/example/object_attribute.cpp +++ b/examples/object_attribute.cpp @@ -6,12 +6,12 @@ #include #include -#include +#include int main() { - // Set and get object attributes via metall::manager object + // Set and get object attributes via dice::copperr::manager object { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto *obj = manager.construct("obj")(); std::string description; @@ -25,9 +25,9 @@ int main() { // Set and get object attributes via object attribute accessor object // Using object attribute accessor, one can access object attribute without - // allocating a metall::manager object (i.e., w/o memory mapping files). + // allocating a dice::copperr::manager object (i.e., w/o memory mapping files). { - auto accessor = metall::manager::access_named_object_attribute("/tmp/dir"); + auto accessor = dice::copperr::manager::access_named_object_attribute("/tmp/dir"); for (const auto &object : accessor) { std::cout << "Name: " << object.name() << ", Length: " << object.length() << ", Description: " << object.description() << std::endl; diff --git a/example/object_attribute_api_list.cpp b/examples/object_attribute_api_list.cpp similarity index 74% rename from example/object_attribute_api_list.cpp rename to examples/object_attribute_api_list.cpp index b3316380..b94f5cd8 100644 --- a/example/object_attribute_api_list.cpp +++ b/examples/object_attribute_api_list.cpp @@ -6,16 +6,16 @@ #include #include -#include +#include using T = int; // Just a one way to extract the type of the attributed object directory // iterator -using iterator_t = metall::manager::const_named_iterator; +using iterator_t = dice::copperr::manager::const_named_iterator; int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); T* obj = manager.construct("obj")(); [[maybe_unused]] bool flag; @@ -23,7 +23,7 @@ int main() { [[maybe_unused]] std::string str; [[maybe_unused]] iterator_t itr; - // Accessing object attributes via metall::manager object + // Accessing object attributes via dice::copperr::manager object { manager.get_instance_name(obj); manager.get_instance_kind(obj); @@ -42,7 +42,7 @@ int main() { // Attributed Object Directory Accessor { // Named object - auto asn = metall::manager::access_named_object_attribute("/dir"); + auto asn = dice::copperr::manager::access_named_object_attribute("/dir"); flag = asn.good(); n = asn.num_objects(); n = asn.count("obj"); @@ -53,21 +53,21 @@ int main() { flag = asn.set_description(itr, "foo"); // Unique object - auto asu = metall::manager::access_unique_object_attribute("/dir"); + auto asu = dice::copperr::manager::access_unique_object_attribute("/dir"); flag = asu.good(); n = asu.num_objects(); n = asu.count(typeid(T).name()); - n = asu.count(metall::unique_instance); + n = asu.count(dice::copperr::unique_instance); itr = asu.find(typeid(T).name()); - itr = asu.find(metall::unique_instance); + itr = asu.find(dice::copperr::unique_instance); itr = asu.begin(); itr = asu.end(); asu.set_description(typeid(T).name(), "foo"); - asu.set_description(metall::unique_instance, "foo"); + asu.set_description(dice::copperr::unique_instance, "foo"); asu.set_description(itr, "foo"); // Anonymous object - auto asa = metall::manager::access_anonymous_object_attribute("/dir"); + auto asa = dice::copperr::manager::access_anonymous_object_attribute("/dir"); flag = asa.good(); n = asa.num_objects(); itr = asa.begin(); diff --git a/example/offset_pointer.cpp b/examples/offset_pointer.cpp similarity index 69% rename from example/offset_pointer.cpp rename to examples/offset_pointer.cpp index cd84c624..954f89a2 100644 --- a/example/offset_pointer.cpp +++ b/examples/offset_pointer.cpp @@ -7,15 +7,15 @@ // offset pointer #include -#include +#include -// metall::offset_ptr is just an alias of offset_ptr in Boost.Interprocess +// dice::copperr::offset_ptr is just an alias of offset_ptr in Boost.Interprocess // https://www.boost.org/doc/libs/release/doc/html/interprocess/offset_ptr.html -using int_offset_prt = metall::offset_ptr; +using int_offset_prt = dice::copperr::offset_ptr; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); // Allocate a simple array in persistent memory int *array = static_cast(manager.allocate(10 * sizeof(int))); @@ -29,20 +29,20 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); int_offset_prt *ptr = manager.find("ptr").first; - // metall::to_raw_pointer extracts a raw pointer from metall::offset_ptr + // dice::copperr::to_raw_pointer extracts a raw pointer from dice::copperr::offset_ptr // If a raw pointer is given, it just returns the address the given pointer // points to - int *array = metall::to_raw_pointer(*ptr); + int *array = dice::copperr::to_raw_pointer(*ptr); std::cout << array[0] << std::endl; // Print 1 std::cout << array[1] << std::endl; // Print 2 // Deallocate the array - manager.deallocate(metall::to_raw_pointer(*ptr)); + manager.deallocate(dice::copperr::to_raw_pointer(*ptr)); *ptr = nullptr; // Destroy the offset pointer object diff --git a/example/simple.cpp b/examples/simple.cpp similarity index 80% rename from example/simple.cpp rename to examples/simple.cpp index 19eb7d22..722ab3e1 100644 --- a/example/simple.cpp +++ b/examples/simple.cpp @@ -7,19 +7,19 @@ #include -#include // Only one header file is required to be included +#include // Only one header file is required to be included // Type alias // This is the standard way to give a custom allocator to a container using vector_t = - boost::container::vector>; + boost::container::vector>; int main() { { // Construct a manager instance // A process can allocate multiple manager instances - metall::manager manager( - metall::create_only, // Create a new one + dice::copperr::manager manager( + dice::copperr::create_only, // Create a new one "/tmp/dir"); // The directory to store backing datastore // Allocate and construct a vector instance of vector_t. @@ -31,15 +31,15 @@ int main() { // From now on, the vector instance can be used normally. pvec->push_back(5); } // Implicitly sync with backing files, i.e., sync() is called in - // metall::manager's destructor + // dice::copperr::manager's destructor // ---------- Assume exit and restart the program at this point ---------- // /// consistent() returns true if a Metall data store exits at the path and /// was closed property. - if (metall::manager::consistent("/tmp/dir")) { + if (dice::copperr::manager::consistent("/tmp/dir")) { // Reattach the manager instance - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); // Find the previously constructed instance // Please do not forget to use ".first" at the end diff --git a/example/snapshot.cpp b/examples/snapshot.cpp similarity index 60% rename from example/snapshot.cpp rename to examples/snapshot.cpp index 54705065..886c06fd 100644 --- a/example/snapshot.cpp +++ b/examples/snapshot.cpp @@ -5,7 +5,7 @@ #include -#include +#include int main() { const std::string master_path("/tmp/dir_path"); @@ -15,8 +15,8 @@ int main() { { // Create the master data - metall::manager manager(metall::create_only, master_path.c_str()); - int *a = manager.construct(metall::unique_instance)(0); + dice::copperr::manager manager(dice::copperr::create_only, master_path.c_str()); + int *a = manager.construct(dice::copperr::unique_instance)(0); // Take a snapshot before updating to '1' manager.snapshot(snapshot_name0.c_str()); @@ -28,27 +28,27 @@ int main() { } // Open snapshot 0 if it is consistent, i.e., it was closed properly. - if (metall::manager::consistent(snapshot_name0.c_str())) { - metall::manager manager(metall::open_read_only, snapshot_name0.c_str()); - int *a = manager.find(metall::unique_instance).first; + if (dice::copperr::manager::consistent(snapshot_name0.c_str())) { + dice::copperr::manager manager(dice::copperr::open_read_only, snapshot_name0.c_str()); + int *a = manager.find(dice::copperr::unique_instance).first; std::cout << *a << std::endl; // Print 0 } else { std::cerr << snapshot_name0 << " is inconsistent" << std::endl; } // Open snapshot 1 if it is consistent, i.e., it was closed properly. - if (metall::manager::consistent(snapshot_name1.c_str())) { - metall::manager manager(metall::open_read_only, snapshot_name1.c_str()); - int *a = manager.find(metall::unique_instance).first; + if (dice::copperr::manager::consistent(snapshot_name1.c_str())) { + dice::copperr::manager manager(dice::copperr::open_read_only, snapshot_name1.c_str()); + int *a = manager.find(dice::copperr::unique_instance).first; std::cout << *a << std::endl; // Print 1 } else { std::cerr << snapshot_name1 << " is inconsistent" << std::endl; } // Open the master data if it is consistent, i.e., it was closed properly. - if (metall::manager::consistent(master_path.c_str())) { - metall::manager manager(metall::open_read_only, master_path.c_str()); - int *a = manager.find(metall::unique_instance).first; + if (dice::copperr::manager::consistent(master_path.c_str())) { + dice::copperr::manager manager(dice::copperr::open_read_only, master_path.c_str()); + int *a = manager.find(dice::copperr::unique_instance).first; std::cout << *a << std::endl; // Print 2 } else { std::cerr << master_path << " is inconsistent" << std::endl; diff --git a/example/static_mutex.cpp b/examples/static_mutex.cpp similarity index 89% rename from example/static_mutex.cpp rename to examples/static_mutex.cpp index d56144e5..6c989779 100644 --- a/example/static_mutex.cpp +++ b/examples/static_mutex.cpp @@ -6,14 +6,14 @@ #include #include -#include +#include static constexpr std::size_t k_num_mutexes = 2; void mutex_work(const int key, const int value, int* array) { { // A mutex block const int index = key % k_num_mutexes; - auto guard = metall::utility::mutex::mutex_lock(index); + auto guard = dice::copperr::utility::mutex::mutex_lock(index); array[index] = array[index] + value; // do some mutex work } // The mutex is released here } diff --git a/example/string.cpp b/examples/string.cpp similarity index 71% rename from example/string.cpp rename to examples/string.cpp index 8b16bfb2..faa4e457 100644 --- a/example/string.cpp +++ b/examples/string.cpp @@ -5,24 +5,24 @@ #include #include -#include +#include #include // String with Metall using persistent_string = boost::container::basic_string, - metall::manager::allocator_type>; + dice::copperr::manager::allocator_type>; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pstr = manager.construct("mystring")( "Hello, World!", manager.get_allocator<>()); std::cout << *pstr << std::endl; } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto pstr = manager.find("mystring").first; std::cout << *pstr << std::endl; } diff --git a/example/string_map.cpp b/examples/string_map.cpp similarity index 80% rename from example/string_map.cpp rename to examples/string_map.cpp index 0486857c..cadf6c99 100644 --- a/example/string_map.cpp +++ b/examples/string_map.cpp @@ -6,22 +6,22 @@ #include #include #include -#include +#include // String with Metall using persistent_string = boost::container::basic_string, - metall::manager::allocator_type>; + dice::copperr::manager::allocator_type>; // Example of string-int map void string_int_map() { using value_type = std::pair; // Mapped type using string_int_map = boost::container::map, - metall::manager::scoped_allocator_type>; + dice::copperr::manager::scoped_allocator_type>; { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pmap = manager.construct("string-int-map")( manager.get_allocator<>()); @@ -32,7 +32,7 @@ void string_int_map() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto pmap = manager.find("string-int-map").first; std::cout << pmap->at(persistent_string("zero", manager.get_allocator<>())) @@ -48,12 +48,12 @@ void int_string_map() { using value_type = std::pair; // Mapped type - using map_allocator_type = metall::manager::scoped_allocator_type; + using map_allocator_type = dice::copperr::manager::scoped_allocator_type; using int_string_map = boost::container::map, map_allocator_type>; { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pmap = manager.construct("int-string-map")( manager.get_allocator<>()); @@ -70,7 +70,7 @@ void int_string_map() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto pmap = manager.find("int-string-map").first; std::cout << pmap->at(0) << std::endl; // Will print "zero" diff --git a/example/vector_of_vectors.cpp b/examples/vector_of_vectors.cpp similarity index 85% rename from example/vector_of_vectors.cpp rename to examples/vector_of_vectors.cpp index f35bbabb..e247630f 100644 --- a/example/vector_of_vectors.cpp +++ b/examples/vector_of_vectors.cpp @@ -9,12 +9,12 @@ #include #include #include -#include +#include namespace bc = boost::container; // Vector of int -using inner_vector_allocator_type = metall::manager::allocator_type; +using inner_vector_allocator_type = dice::copperr::manager::allocator_type; using inner_vector_type = bc::vector; // Vector of vectors with scoped allocator adaptor @@ -23,13 +23,13 @@ using inner_vector_type = bc::vector; // arguments from the outer containers's scoped_allocator_adaptor See: // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor using outer_vector_allocator_type = bc::scoped_allocator_adaptor< - metall::manager::allocator_type>; + dice::copperr::manager::allocator_type>; using outer_vector_type = bc::vector; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto pvec = manager.construct("vec-of-vecs")( manager.get_allocator<>()); @@ -51,7 +51,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto pvec = manager.find("vec-of-vecs").first; // Check the result of pattern 1 diff --git a/execs/CMakeLists.txt b/execs/CMakeLists.txt new file mode 100644 index 00000000..4363c077 --- /dev/null +++ b/execs/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.21) + +add_copperr_executable(datastore_ls + src/dice/copperr/datastore_ls.cpp + ) + +add_copperr_executable(mpi_datastore_ls + src/dice/copperr/mpi_datastore_ls.cpp + ) \ No newline at end of file diff --git a/src/datastore_ls.cpp b/execs/src/dice/copperr/datastore_ls.cpp similarity index 68% rename from src/datastore_ls.cpp rename to execs/src/dice/copperr/datastore_ls.cpp index aa5948e4..d7665dd3 100644 --- a/src/datastore_ls.cpp +++ b/execs/src/dice/copperr/datastore_ls.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include +#include int main(int argc, char *argv[]) { if (argc == 1) { @@ -14,13 +14,13 @@ int main(int argc, char *argv[]) { const std::string datastore_path = argv[1]; - metall::utility::ls_named_object(datastore_path); + dice::copperr::utility::ls_named_object(datastore_path); std::cout << std::endl; - metall::utility::ls_unique_object(datastore_path); + dice::copperr::utility::ls_unique_object(datastore_path); std::cout << std::endl; - metall::utility::ls_anonymous_object(datastore_path); + dice::copperr::utility::ls_anonymous_object(datastore_path); std::cout << std::endl; return 0; diff --git a/src/mpi_datastore_ls.cpp b/execs/src/dice/copperr/mpi_datastore_ls.cpp similarity index 63% rename from src/mpi_datastore_ls.cpp rename to execs/src/dice/copperr/mpi_datastore_ls.cpp index 57b9dd98..8ca089ce 100644 --- a/src/mpi_datastore_ls.cpp +++ b/execs/src/dice/copperr/mpi_datastore_ls.cpp @@ -5,8 +5,8 @@ #include #include -#include -#include +#include +#include int main(int argc, char *argv[]) { if (argc <= 1) { @@ -18,22 +18,22 @@ int main(int argc, char *argv[]) { const int mpi_rank = (argc < 3) ? 0 : std::stoi(argv[2]); const auto local_datastore_path = - metall::utility::mpi_datastore::make_local_dir_path(datastore_path, + dice::copperr::utility::mpi_datastore::make_local_dir_path(datastore_path, mpi_rank); - if (!metall::manager::consistent(local_datastore_path.c_str())) { + if (!dice::copperr::manager::consistent(local_datastore_path.c_str())) { std::cerr << "Inconsistent datastore or invalid datastore path" << std::endl; std::abort(); } - metall::utility::ls_named_object(local_datastore_path); + dice::copperr::utility::ls_named_object(local_datastore_path); std::cout << std::endl; - metall::utility::ls_unique_object(local_datastore_path); + dice::copperr::utility::ls_unique_object(local_datastore_path); std::cout << std::endl; - metall::utility::ls_anonymous_object(local_datastore_path); + dice::copperr::utility::ls_anonymous_object(local_datastore_path); std::cout << std::endl; return 0; diff --git a/include/metall/c_api/metall.h b/include/metall/c_api/metall.h deleted file mode 100644 index 27a979c1..00000000 --- a/include/metall/c_api/metall.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_C_API_METALL_H -#define METALL_C_API_METALL_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/// \brief Tag to create the segment always. -/// The existing segment with the same name is over written. -#define METALL_CREATE_ONLY 1 - -/// \brief Tag to open an already created segment. -#define METALL_OPEN_ONLY 2 - -/// \brief Tag to open an already created segment as read only. -#define METALL_OPEN_READ_ONLY 3 - -/// \brief Constructs a Metall manager object -/// \param mode Open mode -/// \param path A path to the backing data store -/// \return On success, returns 0. On error, returns -1. -extern int metall_open(int mode, const char *path); - -/// \brief Destructs Metall manager object -extern void metall_close(); - -/// \brief Flush data to persistent memory -extern void metall_flush(); - -/// \brief Allocates nbytes bytes. -/// \param nbytes The Number of bytes to allocate -/// \return Returns a pointer to the allocated memory -extern void *metall_malloc(uint64_t nbytes); - -/// \brief Frees the allocated memory -/// \param ptr A pointer to the allocated memory to be free -extern void metall_free(void *ptr); - -/// \brief Allocates nbytes bytes and save the address of the allocated memory -/// with name \param name A name of the allocated memory \param nbytes A size to -/// allocate \return Returns a pointer to the allocated memory -extern void *metall_named_malloc(const char *name, uint64_t nbytes); - -/// \brief Finds a saved memory -/// \param name A name of the allocated memory to find -/// \return Returns a pointer to the allocated memory if it exist. Otherwise, -/// returns NULL. -extern void *metall_find(char *name); - -/// \brief Frees memory with the name -/// \param name A name of the allocated memory to free -extern void metall_named_free(const char *name); - -/// \brief Snapshot the entire data. -/// \param destination_path The path to store a snapshot. -/// \return On success, returns 0. On error, returns -1. -extern int snapshot(const char *destination_path); - -/// \brief Copies backing files synchronously. -/// \param source_path Source data store path. -/// \param destination_path Destination data store path. -/// \return On success, returns 0. On error, returns -1. -extern int copy(const char *source_path, const char *destination_path); - -/// \brief Check if the backing data store is consistent, -/// i.e. it was closed properly. -/// \param path A path to the backing data store. -/// \return Returns a oon-zero integer if the data store is consistent; -/// otherwise, returns 0. -extern int consistent(const char *path); - -#ifdef __cplusplus -} -#endif - -/// \example c_api.c -/// This is an example of how to use the C API. - -#endif // METALL_C_API_METALL_H \ No newline at end of file diff --git a/include/metall/detail/file.hpp b/include/metall/detail/file.hpp deleted file mode 100644 index f10a999e..00000000 --- a/include/metall/detail/file.hpp +++ /dev/null @@ -1,596 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_DETAIL_UTILITY_FILE_HPP -#define METALL_DETAIL_UTILITY_FILE_HPP - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __linux__ -#include // For FALLOC_FL_PUNCH_HOLE and FALLOC_FL_KEEP_SIZE -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __has_include - -// Check if the Filesystem library is available or disabled by the user -#if __has_include() && !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) -#include -#else -#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING -#warning "The Filesystem library is not available or disabled by the user." -#endif -#endif - -#else // __has_include is not defined - -#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING -#warning \ - "__has_include is not defined, consequently disable the Filesystem library." -#endif // METALL_VERBOSE_SYSTEM_SUPPORT_WARNING - -#endif // #ifdef __has_include - -#include - -namespace metall::mtlldetail { - -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) -namespace { -namespace fs = std::filesystem; -} -#endif - -inline bool os_close(const int fd) { - if (::close(fd) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "close"); - return false; - } - return true; -} - -inline bool os_fsync(const int fd) { - if (::fsync(fd) != 0) { - logger::perror(logger::level::error, __FILE__, __LINE__, "fsync"); - return false; - } - return true; -} - -inline bool fsync(const std::string &path) { - const int fd = ::open(path.c_str(), O_RDONLY); - if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); - return false; - } - - bool ret = true; - ret &= os_fsync(fd); - ret &= os_close(fd); - - return ret; -} - -inline bool fsync_recursive(const std::string &path) { -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) - fs::path p(path); - p = fs::canonical(p); - while (true) { - if (!fsync(p.string())) { - return false; - } - if (p == p.root_path()) { - break; - } - p = p.parent_path(); - } - return true; -#else - char *abs = ::realpath(path.c_str(), NULL); - if (!abs) return false; - char *ref = abs; - while (true) { - if (!fsync(std::string(abs))) { - ::free(ref); - return false; - } - if (::strcmp(abs, "/") == 0) { - break; - } - abs = ::dirname(abs); - } - ::free(ref); - return true; -#endif -} - -inline bool extend_file_size_manually(const int fd, const off_t offset, - const ssize_t file_size) { - auto buffer = new unsigned char[4096]; - for (off_t i = offset; i < file_size / 4096 + offset; ++i) { - ::pwrite(fd, buffer, 4096, i * 4096); - } - const size_t remained_size = file_size % 4096; - if (remained_size > 0) - ::pwrite(fd, buffer, remained_size, file_size - remained_size); - - delete[] buffer; - - const bool ret = os_fsync(fd); - - return ret; -} - -inline bool extend_file_size(const int fd, const size_t file_size, - const bool fill_with_zero) { - if (fill_with_zero) { -#ifdef __APPLE__ - if (!extend_file_size_manually(fd, 0, file_size)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to extend file size manually, filling zero"); - return false; - } -#else - if (::posix_fallocate(fd, 0, file_size) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "fallocate"); - return false; - } -#endif - } else { - // ----- extend the file if its size is smaller than that of mapped area - // ----- // - struct stat stat_buf; - if (::fstat(fd, &stat_buf) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "fstat"); - return false; - } - if (::llabs(stat_buf.st_size) < static_cast(file_size)) { - if (::ftruncate(fd, file_size) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "ftruncate"); - return false; - } - } - } - - const bool ret = os_fsync(fd); - return ret; -} - -inline bool extend_file_size(const std::string &file_path, - const size_t file_size, - const bool fill_with_zero = false) { - const int fd = ::open(file_path.c_str(), O_RDWR); - if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); - return false; - } - - bool ret = extend_file_size(fd, file_size, fill_with_zero); - ret &= os_close(fd); - - return ret; -} - -/// \brief Check if a file, any kinds of file including directory, exists -/// \warning This implementation could return a wrong result due to metadata -/// cache on NFS. The following code could fail: if (mpi_rank == 1) -/// file_exist(path); // NFS creates metadata cache mpi_barrier(); if (mpi_rank -/// == 0) create_directory(path); mpi_barrier(); if (mpi_rank == 1) -/// assert(file_exist(path)); // Could fail due to the cached metadata. -inline bool file_exist(const std::string &file_name) { - std::string fixed_string(file_name); - while (fixed_string.back() == '/') { - fixed_string.pop_back(); - } - return (::access(fixed_string.c_str(), F_OK) == 0); -} - -/// \brief Check if a directory exists -/// \warning This implementation could return a wrong result due to metadata -/// cache on NFS. -inline bool directory_exist(const std::string &dir_path) { - struct stat stat_buf; - if (::stat(dir_path.c_str(), &stat_buf) == -1) { - return false; - } - return S_ISDIR(stat_buf.st_mode); -} - -inline bool create_file(const std::string &file_path) { - const int fd = - ::open(file_path.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); - return false; - } - - if (!os_close(fd)) return false; - - return fsync_recursive(file_path); -} - -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) -/// \brief Creates directories recursively. -/// \return Returns true if the directory was created or already exists. -/// Otherwise, returns false. -inline bool create_directory(const std::string &dir_path) { - std::string fixed_string = dir_path; - // MEMO: GCC bug 87846 (fixed in v8.3) - // "Calling std::filesystem::create_directories with a path with a trailing - // separator (e.g. "./a/b/") does not create any directory." -#if (defined(__GNUG__) && !defined(__clang__)) && \ - (__GNUC__ < 8 || \ - (__GNUC__ == 8 && __GNUC_MINOR__ < 3)) // Check if < GCC 8.3 - // Remove trailing separator(s) if they exist: - while (fixed_string.back() == '/') { - fixed_string.pop_back(); - } -#endif - - bool success = true; - try { - std::error_code ec; - if (!fs::create_directories(fixed_string, ec)) { - if (!ec) { - // if the directory exist, create_directories returns false. - // However, std::error_code is cleared and !ec returns true. - return true; - } - - logger::out(logger::level::error, __FILE__, __LINE__, - ec.message().c_str()); - success = false; - } - } catch (fs::filesystem_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); - success = false; - } - - return success; -} -#else -/// \brief Creates directories recursively. -/// \return Returns true if the directory was created or already exists, returns -/// true. Otherwise, returns false. -inline bool create_directory(const std::string &dir_path) { - std::string mkdir_command("mkdir -p " + dir_path); - const int status = std::system(mkdir_command.c_str()); - return (status != -1) && !!(WIFEXITED(status)); -} -#endif - -inline ssize_t get_file_size(const std::string &file_path) { - std::ifstream ifs(file_path, std::ifstream::binary | std::ifstream::ate); - ssize_t size = ifs.tellg(); - if (size == -1) { - std::stringstream ss; - ss << "Failed to get file size: " << file_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - } - - return size; -} - -/// \brief -/// Note that, according to GCC, -/// the file system may use some blocks for internal record keeping -inline ssize_t get_actual_file_size(const std::string &file_path) { - struct stat stat_buf; - if (::stat(file_path.c_str(), &stat_buf) != 0) { - std::string s("stat (" + file_path + ")"); - logger::perror(logger::level::error, __FILE__, __LINE__, s.c_str()); - return -1; - } - return stat_buf.st_blocks * 512LL; -} - -/// \brief Remove a file or directory -/// \return Upon successful completion, returns true; otherwise, false is -/// returned. If the file or directory does not exist, true is returned. -inline bool remove_file(const std::string &path) { -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) - std::filesystem::path p(path); - std::error_code ec; - [[maybe_unused]] const auto num_removed = std::filesystem::remove_all(p, ec); - return !ec; -#else - std::string rm_command("rm -rf " + path); - const int status = std::system(rm_command.c_str()); - return (status != -1) && !!(WIFEXITED(status)); -#endif -} - -inline bool free_file_space([[maybe_unused]] const int fd, - [[maybe_unused]] const off_t off, - [[maybe_unused]] const off_t len) { -#if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) - if (::fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off, len) == - -1) { - logger::perror(logger::level::warning, __FILE__, __LINE__, "fallocate"); - return false; - } - return true; - -#else -#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING -#warning "FALLOC_FL_PUNCH_HOLE or FALLOC_FL_KEEP_SIZE is not supported" -#endif - return false; -#endif -} - -namespace file_copy_detail { - -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) -inline bool copy_file_dense(const std::string &source_path, - const std::string &destination_path) { - bool success = true; - try { - if (!fs::copy_file(source_path, destination_path, - fs::copy_options::overwrite_existing)) { - std::stringstream ss; - ss << "Failed copying file: " << source_path << " -> " - << destination_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - success = false; - } - } catch (fs::filesystem_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); - success = false; - } - - if (success) { - success &= metall::mtlldetail::fsync(destination_path); - } - - return success; -} - -#else - -inline bool copy_file_dense(const std::string &source_path, - const std::string &destination_path) { - { - const ssize_t source_file_size = get_file_size(source_path); - const ssize_t actual_source_file_size = get_actual_file_size(source_path); - if (source_file_size == -1 || actual_source_file_size == -1) { - return false; - } - - // If the source file is empty, just create the destination file and done. - if (source_file_size == 0 || actual_source_file_size == 0) { - create_file(destination_path); - return true; - } - } - - { - std::ifstream source(source_path); - if (!source.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << source_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - return false; - } - - std::ofstream destination(destination_path); - if (!destination.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << destination_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - return false; - } - - destination << source.rdbuf(); - if (!destination) { - std::stringstream ss; - ss << "Something happened in the ofstream: " << destination_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - return false; - } - - destination.close(); - - if (!metall::mtlldetail::fsync(destination_path)) { - return false; - } - } - - { - // Sanity check - const ssize_t s1 = get_file_size(source_path); - const ssize_t s2 = get_file_size(destination_path); - if (s1 < 0 || s1 != s2) { - std::stringstream ss; - ss << "Something wrong in file sizes: " << s1 << " " << s2; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - return false; - } - } - return true; -} - -#endif - -#ifdef __linux__ -inline bool copy_file_sparse_linux(const std::string &source_path, - const std::string &destination_path) { - std::string command("cp --sparse=auto " + source_path + " " + - destination_path); - const int status = std::system(command.c_str()); - const bool success = (status != -1) && !!(WIFEXITED(status)); - if (!success) { - std::stringstream ss; - ss << "Failed copying file: " << source_path << " -> " << destination_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); - return false; - } - return success; -} -#endif - -} // namespace file_copy_detail - -/// \brief Copy a file. -/// \param source_path A source file path. -/// \param destination_path A destination path. -/// \param sparse_copy If true is specified, tries to perform sparse file copy. -/// \return On success, returns true. On error, returns false. -inline bool copy_file(const std::string &source_path, - const std::string &destination_path, - const bool sparse_copy = true) { - if (sparse_copy) { -#ifdef __linux__ - return file_copy_detail::copy_file_sparse_linux(source_path, - destination_path); -#else - logger::out(logger::level::info, __FILE__, __LINE__, - "Sparse file copy is not available"); -#endif - } - return file_copy_detail::copy_file_dense(source_path, destination_path); -} - -/// \brief Get the file names in a directory. -/// This function does not list files recursively. -/// Only regular files are returned. -/// \param dir_path A directory path. -/// \param file_list A buffer to put results. -/// \return Returns true if there is no error (empty directory returns true as -/// long as the operation does not fail). Returns false on error. -inline bool get_regular_file_names(const std::string &dir_path, - std::vector *file_list) { -#if defined(__cpp_lib_filesystem) && \ - !defined(METALL_DISABLE_CXX17_FILESYSTEM_LIB) - - if (!directory_exist(dir_path)) { - return false; - } - - try { - file_list->clear(); - for (auto &p : fs::directory_iterator(dir_path)) { - if (p.is_regular_file()) { - file_list->push_back(p.path().filename().string()); - } - } - } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown"); - return false; - } - - return true; - -#else - DIR *d = ::opendir(dir_path.c_str()); - if (!d) { - return false; - } - - for (dirent *dir; (dir = ::readdir(d)) != nullptr;) { - if (dir->d_type == DT_REG) { - file_list->push_back(dir->d_name); - } - } - ::closedir(d); - - return true; -#endif -} - -/// \brief Copy files in a directory. -/// This function does not copy files in subdirectories. -/// This function does not also copy directories. -/// \param source_dir_path A path to source directory. -/// \param destination_dir_path A path to destination directory. -/// \param max_num_threads The maximum number of threads to use. -/// If <= 0 is given, the value is automatically determined. -/// \param copy_func The actual copy function. -/// \return On success, returns true. On error, returns false. -inline bool copy_files_in_directory_in_parallel_helper( - const std::string &source_dir_path, const std::string &destination_dir_path, - const int max_num_threads, - const std::function - ©_func) { - std::vector src_file_names; - if (!get_regular_file_names(source_dir_path, &src_file_names)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to get file list"); - return false; - } - - std::atomic_uint_fast64_t num_successes = 0; - std::atomic_uint_fast64_t file_no_cnt = 0; - auto copy_lambda = [&file_no_cnt, &num_successes, &source_dir_path, - &src_file_names, &destination_dir_path, ©_func]() { - while (true) { - const auto file_no = file_no_cnt.fetch_add(1); - if (file_no >= src_file_names.size()) break; - const std::string &src_file_path = - source_dir_path + "/" + src_file_names[file_no]; - const std::string &dst_file_path = - destination_dir_path + "/" + src_file_names[file_no]; - num_successes.fetch_add(copy_func(src_file_path, dst_file_path) ? 1 : 0); - } - }; - - const auto num_threads = (int)std::min( - src_file_names.size(), - (std::size_t)(max_num_threads > 0 ? max_num_threads - : std::thread::hardware_concurrency())); - std::vector threads(num_threads, nullptr); - for (auto &th : threads) { - th = new std::thread(copy_lambda); - } - - for (auto &th : threads) { - th->join(); - } - - return num_successes == src_file_names.size(); -} - -/// \brief Copy files in a directory. -/// This function does not copy files in subdirectories. -/// \param source_dir_path A path to source directory. -/// \param destination_dir_path A path to destination directory. -/// \param max_num_threads The maximum number of threads to use. -/// If <= 0 is given, it is automatically determined. -/// \param sparse_copy Performs sparse file copy. -/// \return On success, returns true. On error, returns false. -inline bool copy_files_in_directory_in_parallel( - const std::string &source_dir_path, const std::string &destination_dir_path, - const int max_num_threads, const bool sparse_copy = true) { - return copy_files_in_directory_in_parallel_helper( - source_dir_path, destination_dir_path, max_num_threads, - [&sparse_copy](const std::string &src, const std::string &dst) -> bool { - return copy_file(src, dst, sparse_copy); - }); -} -} // namespace metall::mtlldetail - -#endif // METALL_DETAIL_UTILITY_FILE_HPP diff --git a/include/metall/detail/file_clone.hpp b/include/metall/detail/file_clone.hpp deleted file mode 100644 index f4cdf8df..00000000 --- a/include/metall/detail/file_clone.hpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_DETAIL_UTILITY_FILE_CLONE_HPP -#define METALL_DETAIL_UTILITY_FILE_CLONE_HPP - -#include - -#ifdef __linux__ -#include -#endif - -#ifdef __APPLE__ -#include -#include -#endif - -#include -#include -#include - -namespace metall::mtlldetail { - -namespace file_clone_detail { -#ifdef __linux__ -inline bool clone_file_linux(const std::string &source_path, - const std::string &destination_path) { - std::string command("cp --reflink=auto -R " + source_path + " " + - destination_path); - const int status = std::system(command.c_str()); - return (status != -1) && !!(WIFEXITED(status)); -} -#endif - -#ifdef __APPLE__ -inline bool clone_file_macos(const std::string &source_path, - const std::string &destination_path) { - std::string command("cp -cR " + source_path + " " + destination_path); - const int status = std::system(command.c_str()); - return (status != -1) && !!(WIFEXITED(status)); -} -#endif -} // namespace file_clone_detail - -/// \brief Clones a file. If file cloning is not supported, copies the file -/// normally. \param source_path A path to the file to be cloned. \param -/// destination_path A path to copy to. \return On success, returns true. On -/// error, returns false. -inline bool clone_file(const std::string &source_path, - const std::string &destination_path) { - bool ret = false; -#if defined(__linux__) - ret = file_clone_detail::clone_file_linux(source_path, destination_path); - if (!ret) { - std::string s("On Linux, Failed to clone " + source_path + " to " + - destination_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); - } -#elif defined(__APPLE__) - ret = file_clone_detail::clone_file_macos(source_path, destination_path); - if (!ret) { - std::string s("On MacOS, Failed to clone " + source_path + " to " + - destination_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); - } -#else -#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING -#warning "Copy file normally instead of cloning" -#endif - logger::out(logger::level::warning, __FILE__, __LINE__, - "Use normal copy instead of clone"); - ret = copy_file(source_path, destination_path); // Copy normally - if (!ret) { - std::string s("Failed to copy " + source_path + " to " + destination_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); - } -#endif - - if (ret) { - ret &= metall::mtlldetail::fsync(destination_path); - } - - return ret; -} - -/// \brief Clone files in a directory. -/// This function does not clone files in subdirectories. -/// \param source_dir_path A path to source directory. -/// \param destination_dir_path A path to destination directory. -/// \param max_num_threads The maximum number of threads to use. -/// If <= 0 is given, it is automatically determined. -/// \return On success, returns true. On error, returns false. -inline bool clone_files_in_directory_in_parallel( - const std::string &source_dir_path, const std::string &destination_dir_path, - const int max_num_threads) { - return copy_files_in_directory_in_parallel_helper( - source_dir_path, destination_dir_path, max_num_threads, clone_file); -} - -} // namespace metall::mtlldetail - -#endif // METALL_DETAIL_UTILITY_FILE_CLONE_HPP diff --git a/include/metall/json/json.hpp b/include/metall/json/json.hpp deleted file mode 100644 index 716dbec4..00000000 --- a/include/metall/json/json.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_JSON_JSON_HPP -#define METALL_JSON_JSON_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/// \example json_create.cpp -/// This is an example of how to create a JSON object with Metall. - -/// \example json_open.cpp -/// This is an example of how to open an already created JSON object. - -#endif // METALL_JSON_JSON_HPP diff --git a/include/metall/logger.hpp b/include/metall/logger.hpp deleted file mode 100644 index 9934c617..00000000 --- a/include/metall/logger.hpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_LOGGER_HPP -#define METALL_LOGGER_HPP - -#include -#include -#include -#include - -namespace metall { - -class logger { - public: - /// \brief Log message level - enum struct level { - /// \brief Silent logger message — never show logger message - silent = 10, - /// \brief Critical logger message — abort the execution unless disabled - critical = 5, - /// \brief Error logger message - error = 4, - /// \brief Warning logger message - warning = 3, - /// \brief Info logger message - info = 2, - /// \brief Debug logger message - debug = 1, - /// \brief Verbose (lowest priority) logger message - verbose = 0, - }; - - /// \brief Set the minimum logger level to show message - static void set_log_level(const level lvl) noexcept { - log_message_out_level = lvl; - } - - /// \brief If true is specified, enable an abort at a critical logger message - static void abort_on_critical_error(const bool enable) noexcept { - abort_on_critical = enable; - } - - /// \brief Log a message to std::cerr if the specified logger level is equal - /// to or higher than the pre-set logger level. - static void out(const level lvl, const char* const file_name, - const int line_no, const char* const message) noexcept { - if (log_message_out_level == level::silent || lvl == level::silent || - lvl < log_message_out_level) - return; - - try { - std::cerr << file_name << " at line " << line_no << " --- " << message - << std::endl; - } catch (...) { - } - - if (lvl == level::critical && abort_on_critical) { - std::abort(); - } - } - - /// \brief Log a message about errno if the specified logger level is equal to - /// or higher than the pre-set logger level. - static void perror(const level lvl, const char* const file_name, - const int line_no, const char* const message) noexcept { - if (log_message_out_level == level::silent || lvl == level::silent || - lvl < log_message_out_level) - return; - - try { - std::cerr << file_name << " at line " << line_no << " --- "; - std::perror(message); - } catch (...) { - } - - // std::out << "errno is " << errno << std::endl; - - if (lvl == level::critical && abort_on_critical) { - std::abort(); - } - } - - logger() = delete; - ~logger() = delete; - logger(const logger&) = delete; - logger(logger&&) = delete; - logger& operator=(const logger&) = delete; - logger& operator=(logger&&) = delete; - - private: - static level log_message_out_level; - static bool abort_on_critical; -}; - -inline logger::level logger::log_message_out_level = logger::level::error; -inline bool logger::abort_on_critical = true; - -} // namespace metall - -#endif // METALL_LOGGER_HPP diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt new file mode 100644 index 00000000..efc79ca2 --- /dev/null +++ b/libs/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.22) +add_subdirectory(copperr) + +if (BUILD_FFI) + add_subdirectory(ffi) +endif () + +if (WITH_DEFAULT_LOGGER) + add_subdirectory(default-logger) +endif () + +include(${CMAKE_SOURCE_DIR}/cmake/install_components.cmake) +install_package() diff --git a/libs/copperr/CMakeLists.txt b/libs/copperr/CMakeLists.txt new file mode 100644 index 00000000..8f4d58bb --- /dev/null +++ b/libs/copperr/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.22) +set(lib "${PROJECT_NAME}-${PROJECT_NAME}") + +find_package(Boost REQUIRED COMPONENTS) +find_package(Threads REQUIRED) + +add_library(${lib} INTERFACE) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${lib}) + +target_include_directories(${lib} + INTERFACE + $) + +target_link_libraries(${lib} + INTERFACE + Threads::Threads + Boost::headers + ) + +set_target_properties(${lib} + PROPERTIES + CXX_STANDARD 20 + ) + +include(${CMAKE_SOURCE_DIR}/cmake/install_components.cmake) +install_component(INTERFACE ${PROJECT_NAME} src) diff --git a/include/metall/basic_manager.hpp b/libs/copperr/src/dice/copperr/basic_manager.hpp similarity index 84% rename from include/metall/basic_manager.hpp rename to libs/copperr/src/dice/copperr/basic_manager.hpp index fb18ca9f..61316793 100644 --- a/include/metall/basic_manager.hpp +++ b/libs/copperr/src/dice/copperr/basic_manager.hpp @@ -7,15 +7,16 @@ #define METALL_BASIC_MANAGER_HPP #include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -namespace metall { +namespace dice::copperr { #if !defined(DOXYGEN_SKIP) // Forward declaration @@ -63,12 +64,12 @@ class basic_manager { /// \brief Construct proxy template using construct_proxy = - metall::mtlldetail::named_proxy; + dice::copperr::mtlldetail::named_proxy; /// \brief Construct iterator proxy template using construct_iter_proxy = - metall::mtlldetail::named_proxy; + dice::copperr::mtlldetail::named_proxy; /// \brief An value that describes the type of the instance constructed in /// memory @@ -116,56 +117,52 @@ class basic_manager { /// \brief Opens an existing data store. /// \param base_path Path to a data store. - basic_manager(open_only_t, const char *base_path) noexcept { + basic_manager(open_only_t, const std::filesystem::path &base_path) noexcept { try { m_kernel = std::make_unique(); m_kernel->open(base_path); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } /// \brief Opens an existing data store with the read only mode. /// Write accesses will cause segmentation fault. /// \param base_path Path to a data store. - basic_manager(open_read_only_t, const char *base_path) noexcept { + basic_manager(open_read_only_t, const std::filesystem::path &base_path) noexcept { try { m_kernel = std::make_unique(); m_kernel->open_read_only(base_path); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } /// \brief Creates a new data store (an existing data store will be /// overwritten). \param base_path Path to create a data store. - basic_manager(create_only_t, const char *base_path) noexcept { + basic_manager(create_only_t, const std::filesystem::path &base_path) noexcept { try { m_kernel = std::make_unique(); m_kernel->create(base_path); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } /// \brief Creates a new data store (an existing data store will be /// overwritten). \param base_path Path to create a data store. \param /// capacity Maximum total allocation size. - basic_manager(create_only_t, const char *base_path, + basic_manager(create_only_t, const std::filesystem::path &base_path, const size_type capacity) noexcept { try { m_kernel = std::make_unique(); m_kernel->create(base_path, capacity); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } @@ -372,8 +369,7 @@ class basic_manager { try { return m_kernel->template find(name); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return std::make_pair(nullptr, 0); @@ -427,17 +423,17 @@ class basic_manager { /// /// Example: /// \code - /// bool destroyed = basic_manager.destroy(metall::unique_instance); + /// bool destroyed = basic_manager.destroy(dice::copperr::unique_instance); /// \endcode /// /// \tparam T The type of the object. /// \return Returns false if the object was not destroyed. template - bool destroy(const metall::mtlldetail::unique_instance_t *const) { + bool destroy(const dice::copperr::mtlldetail::unique_instance_t *const) { if (!check_sanity()) { return false; } - return m_kernel->template destroy(metall::unique_instance); + return m_kernel->template destroy(dice::copperr::unique_instance); } /// \brief Destroys a object (named, unique, or anonymous) by its address. @@ -500,8 +496,7 @@ class basic_manager { try { return m_kernel->get_instance_name(ptr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return nullptr; } @@ -528,8 +523,7 @@ class basic_manager { try { return m_kernel->get_instance_kind(ptr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return instance_kind(); } @@ -557,8 +551,7 @@ class basic_manager { try { return m_kernel->get_instance_length(ptr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return 0; } @@ -584,8 +577,7 @@ class basic_manager { try { return m_kernel->template is_instance_type(ptr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -614,8 +606,7 @@ class basic_manager { try { return m_kernel->get_instance_description(ptr, description); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -645,8 +636,7 @@ class basic_manager { return m_kernel->set_instance_description(ptr, description); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -667,8 +657,7 @@ class basic_manager { try { return m_kernel->get_num_named_objects(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return 0; } @@ -686,14 +675,13 @@ class basic_manager { try { return m_kernel->get_num_unique_objects(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return 0; } /// \brief Returns Returns the number of anonymous objects (objects - /// constructed with metall::anonymous_instance) stored in the managed + /// constructed with dice::copperr::anonymous_instance) stored in the managed /// segment. /// \copydoc doc_object_attrb_obj_const_thread_safe /// @@ -705,8 +693,7 @@ class basic_manager { try { return m_kernel->get_num_anonymous_objects(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return 0; } @@ -723,8 +710,7 @@ class basic_manager { try { return m_kernel->named_begin(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_named_iterator(); } @@ -742,8 +728,7 @@ class basic_manager { try { return m_kernel->named_end(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_named_iterator(); } @@ -761,8 +746,7 @@ class basic_manager { try { return m_kernel->unique_begin(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_unique_iterator(); } @@ -780,8 +764,7 @@ class basic_manager { try { return m_kernel->unique_end(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_unique_iterator(); } @@ -799,8 +782,7 @@ class basic_manager { try { return m_kernel->anonymous_begin(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_anonymous_iterator(); } @@ -817,8 +799,7 @@ class basic_manager { try { return m_kernel->anonymous_end(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return const_anonymous_iterator(); } @@ -841,8 +822,7 @@ class basic_manager { return m_kernel->allocate(nbytes); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return nullptr; } @@ -863,8 +843,7 @@ class basic_manager { return m_kernel->allocate_aligned(nbytes, alignment); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return nullptr; } @@ -884,8 +863,7 @@ class basic_manager { return m_kernel->deallocate(addr); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } @@ -906,8 +884,7 @@ class basic_manager { try { return m_kernel->all_memory_deallocated(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -926,8 +903,7 @@ class basic_manager { m_kernel->flush(synchronous); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } @@ -936,22 +912,20 @@ class basic_manager { /// \copydoc doc_single_thread /// /// \param destination_dir_path Path to store a snapshot. - /// \param clone Use the file clone mechanism (reflink) instead of normal copy /// if it is available. \param num_max_copy_threads The maximum number of copy /// threads to use. If <= 0 is given, the value is automatically determined. /// \return Returns true on success; other false. - bool snapshot(const char_type *destination_dir_path, const bool clone = true, + bool snapshot(const std::filesystem::path &destination_dir_path, const int num_max_copy_threads = 0) noexcept { if (!check_sanity()) { return false; } try { - return m_kernel->snapshot(destination_dir_path, clone, + return m_kernel->snapshot(destination_dir_path, num_max_copy_threads); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -968,16 +942,14 @@ class basic_manager { /// \param num_max_copy_threads The maximum number of copy threads to use. /// If <= 0 is given, the value is automatically determined. /// \return If succeeded, returns true; other false. - static bool copy(const char_type *source_dir_path, - const char_type *destination_dir_path, - const bool clone = true, + static bool copy(const std::filesystem::path &source_dir_path, + const std::filesystem::path &destination_dir_path, const int num_max_copy_threads = 0) noexcept { try { return manager_kernel_type::copy(source_dir_path, destination_dir_path, - clone, num_max_copy_threads); + num_max_copy_threads); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -995,16 +967,14 @@ class basic_manager { /// If <= 0 is given, the value is automatically determined. /// \return Returns an object of std::future. /// If succeeded, its get() returns true; other false. - static auto copy_async(const char_type *source_dir_path, - const char_type *destination_dir_path, - const bool clone = true, + static auto copy_async(const std::filesystem::path &source_dir_path, + const std::filesystem::path &destination_dir_path, const int num_max_copy_threads = 0) noexcept { try { return manager_kernel_type::copy_async( - source_dir_path, destination_dir_path, clone, num_max_copy_threads); + source_dir_path, destination_dir_path, num_max_copy_threads); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return std::future(); } @@ -1015,12 +985,11 @@ class basic_manager { /// /// \param dir_path Path to a data store to remove. \return If /// succeeded, returns true; other false. - static bool remove(const char_type *dir_path) noexcept { + static bool remove(const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::remove(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1032,12 +1001,11 @@ class basic_manager { /// \param dir_path Path to a data store to remove. /// \return Returns an object of std::future. /// If succeeded, its get() returns true; other false - static std::future remove_async(const char_type *dir_path) noexcept { + static std::future remove_async(const std::filesystem::path &dir_path) noexcept { try { return std::async(std::launch::async, remove, dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return std::future(); } @@ -1054,12 +1022,11 @@ class basic_manager { /// \param dir_path Path to a data store. /// \return Returns true if it exists and is consistent; otherwise, returns /// false. - static bool consistent(const char_type *dir_path) noexcept { + static bool consistent(const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::consistent(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1075,8 +1042,7 @@ class basic_manager { try { return m_kernel->get_uuid(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return std::string(); } @@ -1086,12 +1052,11 @@ class basic_manager { /// /// \param dir_path Path to a data store. /// \return UUID in the std::string format; returns an empty string on error. - static std::string get_uuid(const char_type *dir_path) noexcept { + static std::string get_uuid(const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::get_uuid(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return std::string(); } @@ -1107,8 +1072,7 @@ class basic_manager { try { return m_kernel->get_version(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return version_type(); } @@ -1118,12 +1082,11 @@ class basic_manager { /// /// \param dir_path Path to a data store. /// \return Returns a version number; returns 0 on error. - static version_type get_version(const char_type *dir_path) noexcept { + static version_type get_version(const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::get_version(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); return version_type(); } } @@ -1147,8 +1110,7 @@ class basic_manager { return m_kernel->set_description(description); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1161,13 +1123,12 @@ class basic_manager { /// \param dir_path Path to a data store. \param description An std::string /// object that holds a description. \return Returns true on success; /// otherwise, false. - static bool set_description(const char *dir_path, + static bool set_description(const std::filesystem::path &dir_path, const std::string &description) noexcept { try { return manager_kernel_type::set_description(dir_path, description); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1188,8 +1149,7 @@ class basic_manager { try { return m_kernel->get_description(description); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1203,13 +1163,12 @@ class basic_manager { /// to an std::string object to store a description if it exists. \return /// Returns true on success; returns false on error. Trying to get a /// non-existent description is not considered as an error. - static bool get_description(const char *dir_path, + static bool get_description(const std::filesystem::path &dir_path, std::string *description) noexcept { try { return manager_kernel_type::get_description(dir_path, description); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return false; } @@ -1222,12 +1181,11 @@ class basic_manager { /// \param dir_path Path to a data store. \return Returns an instance /// of named_object_attribute_accessor_type. static named_object_attribute_accessor_type access_named_object_attribute( - const char *dir_path) noexcept { + const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::access_named_object_attribute(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return named_object_attribute_accessor_type(); } @@ -1239,12 +1197,11 @@ class basic_manager { /// \param dir_path Path to a data store. \return Returns an instance /// of unique_object_attribute_accessor_type. static unique_object_attribute_accessor_type access_unique_object_attribute( - const char *dir_path) noexcept { + const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::access_unique_object_attribute(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return unique_object_attribute_accessor_type(); } @@ -1256,12 +1213,11 @@ class basic_manager { /// \param dir_path Path to a data store. \return Returns an /// instance of anonymous_object_attribute_accessor_type. static anonymous_object_attribute_accessor_type - access_anonymous_object_attribute(const char *dir_path) noexcept { + access_anonymous_object_attribute(const std::filesystem::path &dir_path) noexcept { try { return manager_kernel_type::access_anonymous_object_attribute(dir_path); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return anonymous_object_attribute_accessor_type(); } @@ -1281,8 +1237,7 @@ class basic_manager { return allocator_type(reinterpret_cast( &(m_kernel->get_segment_header()->manager_kernel_address))); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return allocator_type(nullptr); } @@ -1304,8 +1259,7 @@ class basic_manager { try { return m_kernel->get_segment(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return nullptr; } @@ -1323,8 +1277,7 @@ class basic_manager { try { return m_kernel->get_segment_size(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } return 0; } @@ -1351,8 +1304,7 @@ class basic_manager { m_kernel->profile(log_out); } catch (...) { m_kernel.reset(nullptr); - logger::out(logger::level::error, __FILE__, __LINE__, - "An exception has been thrown"); + METALL_ERROR("An exception has been thrown"); } } #endif @@ -1363,6 +1315,6 @@ class basic_manager { // -------------------- // std::unique_ptr m_kernel{nullptr}; }; -} // namespace metall +} // namespace dice::copperr #endif // METALL_BASIC_MANAGER_HPP diff --git a/include/metall/container/concurrent_map.hpp b/libs/copperr/src/dice/copperr/container/concurrent_map.hpp similarity index 93% rename from include/metall/container/concurrent_map.hpp rename to libs/copperr/src/dice/copperr/container/concurrent_map.hpp index 4deac8d6..cf542d9b 100644 --- a/include/metall/container/concurrent_map.hpp +++ b/libs/copperr/src/dice/copperr/container/concurrent_map.hpp @@ -11,12 +11,12 @@ #include #include #include -#include -#include +#include +#include -/// \namespace metall::container +/// \namespace dice::copperr::container /// \brief Namespace for Metall container -namespace metall::container { +namespace dice::copperr::container { /// \brief A concurrent map container which can be stored in persistent memory. /// This container does not allocate mutex objects internally, but allocates @@ -62,7 +62,7 @@ class concurrent_map { /// \brief A const iterator type. using const_iterator = - metall::utility::container_of_containers_iterator_adaptor< + dice::copperr::utility::container_of_containers_iterator_adaptor< typename banked_map_type::const_iterator, typename internal_map_type::const_iterator>; @@ -95,7 +95,7 @@ class concurrent_map { /// whether the insertion took place. bool insert(value_type &&value) { const auto bank_no = calc_bank_no(value.first); - auto lock = metall::utility::mutex::mutex_lock(bank_no); + auto lock = dice::copperr::utility::mutex::mutex_lock(bank_no); const bool ret = m_banked_map[bank_no].insert(std::forward(value)).second; m_num_items += (ret) ? 1 : 0; @@ -109,7 +109,7 @@ class concurrent_map { std::pair> scoped_edit( const key_type &key) { const auto bank_no = calc_bank_no(key); - auto lock = metall::utility::mutex::mutex_lock(bank_no); + auto lock = dice::copperr::utility::mutex::mutex_lock(bank_no); if (!count(key)) { [[maybe_unused]] const bool ret = register_key_no_lock(key); assert(ret); @@ -126,7 +126,7 @@ class concurrent_map { void edit(const key_type &key, const std::function &editor) { const auto bank_no = calc_bank_no(key); - auto lock = metall::utility::mutex::mutex_lock(bank_no); + auto lock = dice::copperr::utility::mutex::mutex_lock(bank_no); if (!count(key)) { [[maybe_unused]] const bool ret = register_key_no_lock(key); assert(ret); @@ -186,7 +186,7 @@ class concurrent_map { size_type m_num_items; }; -} // namespace metall::container +} // namespace dice::copperr::container /// \example concurrent_map.cpp /// This is an example of how to use the concurrent_map class with Metall. diff --git a/include/metall/container/deque.hpp b/libs/copperr/src/dice/copperr/container/deque.hpp similarity index 82% rename from include/metall/container/deque.hpp rename to libs/copperr/src/dice/copperr/container/deque.hpp index d91f2729..e6dccecd 100644 --- a/include/metall/container/deque.hpp +++ b/libs/copperr/src/dice/copperr/container/deque.hpp @@ -8,14 +8,14 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A deque container that uses Metall as its default allocator. template > using deque = boost::container::deque; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_DEQUE_HPP \ No newline at end of file diff --git a/include/metall/container/experimental/jgraph/jgraph.hpp b/libs/copperr/src/dice/copperr/container/experimental/jgraph/jgraph.hpp similarity index 92% rename from include/metall/container/experimental/jgraph/jgraph.hpp rename to libs/copperr/src/dice/copperr/container/experimental/jgraph/jgraph.hpp index 14b02b10..a2561d2c 100644 --- a/include/metall/container/experimental/jgraph/jgraph.hpp +++ b/libs/copperr/src/dice/copperr/container/experimental/jgraph/jgraph.hpp @@ -12,24 +12,24 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -/// \namespace metall::container::experimental +/// \namespace dice::copperr::container::experimental /// \brief Namespace for Metall containers in an experimental phase. -namespace metall::container::experimental {} +namespace dice::copperr::container::experimental {} -/// \namespace metall::container::experimental::jgraph +/// \namespace dice::copperr::container::experimental::jgraph /// \brief Namespace for Metall JSON graph container, which is in an /// experimental phase. -namespace metall::container::experimental::jgraph { +namespace dice::copperr::container::experimental::jgraph { namespace { -namespace mc = metall::container; -namespace mj = metall::json; +namespace mc = dice::copperr::container; +namespace mj = dice::copperr::json; } // namespace // --- Forward declarations --- // @@ -118,7 +118,7 @@ class jgraph { using vertex_storage_type = mc::unordered_map, std::equal_to<>, + dice::copperr::utility::hash<>, std::equal_to<>, other_scoped_allocator>>; @@ -184,7 +184,7 @@ class jgraph { using edge_storage_type = mc::unordered_map, std::equal_to<>, + dice::copperr::utility::hash<>, std::equal_to<>, other_scoped_allocator< std::pair>>; @@ -210,7 +210,7 @@ class jgraph { public: /// \brief Vertex iterator over a container of vertex data, - /// which is metall::container::experimental::json::key_value_pair_type. + /// which is dice::copperr::container::experimental::json::key_value_pair_type. using vertex_iterator = jgdtl::vertex_iterator_impl; @@ -219,7 +219,7 @@ class jgraph { jgdtl::vertex_iterator_impl; /// \brief Edge iterator over a container of edge data, - /// which is metall::container::experimental::json::key_value_pair_type. + /// which is dice::copperr::container::experimental::json::key_value_pair_type. using edge_iterator = jgdtl::edge_iterator_impl< typename adj_list_edge_list_type::iterator, typename std::pointer_traits; using pointer = typename std::pointer_traits::pointer>::template rebind; + using const_pointer = typename std::pointer_traits::pointer>::template rebind; using reference = value_type &; + using const_reference = const value_type &; using difference_type = typename std::iterator_traits::difference_type; @@ -498,11 +501,11 @@ class vertex_iterator_impl { pointer operator->() { return const_cast(&(m_current_pos->second)); } - const pointer operator->() const { return &(m_current_pos->second); } + const_pointer operator->() const { return &(m_current_pos->second); } reference operator*() { return m_current_pos->second; } - const reference operator*() const { return m_current_pos->second; } + const_reference operator*() const { return m_current_pos->second; } private: storage_iterator_type m_current_pos; @@ -537,7 +540,11 @@ class edge_iterator_impl { using pointer = typename std::pointer_traits< typename std::pointer_traits::element_type:: iterator::pointer>::template rebind; + using const_pointer = typename std::pointer_traits< + typename std::pointer_traits::element_type:: + iterator::pointer>::template rebind; using reference = value_type &; + using const_reference = const value_type &; using difference_type = typename std::iterator_traits< adj_list_edge_list_iterator_type>::difference_type; @@ -573,7 +580,7 @@ class edge_iterator_impl { return &(m_storage_pointer->at(edge_id)); } - const pointer operator->() const { + const_pointer operator->() const { const auto &edge_id = m_current_pos->second; return &(m_storage_pointer->at(edge_id)); } @@ -583,7 +590,7 @@ class edge_iterator_impl { return (m_storage_pointer->at(edge_id)); } - const reference operator*() const { + const_reference operator*() const { const auto &edge_id = m_current_pos->second; return (m_storage_pointer->at(edge_id)); } @@ -615,7 +622,7 @@ inline bool operator!=( } // namespace jgdtl -} // namespace metall::container::experimental::jgraph +} // namespace dice::copperr::container::experimental::jgraph /// \example jgraph.cpp /// This is an example of how to use the jgraph. diff --git a/include/metall/container/experimental/json/json.hpp b/libs/copperr/src/dice/copperr/container/experimental/json/json.hpp similarity index 51% rename from include/metall/container/experimental/json/json.hpp rename to libs/copperr/src/dice/copperr/container/experimental/json/json.hpp index ba716ab3..231582f9 100644 --- a/include/metall/container/experimental/json/json.hpp +++ b/libs/copperr/src/dice/copperr/container/experimental/json/json.hpp @@ -7,14 +7,14 @@ #define METALL_CONTAINER_EXPERIMENT_JSON_JSON_HPP #warning \ - "metall/container/experimental/json/json.hpp is deprecated. Please use include/metall/json/json.hpp instead." + "copperr/container/experimental/json/json.hpp is deprecated. Please use include/copperr/json/json.hpp instead." -#include +#include #warning \ - "Namespace metall::container::experimental::json is deprecated. Please use metall::json instead." -namespace metall::container::experimental::json { -using namespace metall::json; + "Namespace dice::copperr::container::experimental::json is deprecated. Please use dice::copperr::json instead." +namespace dice::copperr::container::experimental::json { +using namespace dice::copperr::json; } #endif // METALL_CONTAINER_EXPERIMENT_JSON_JSON_HPP diff --git a/include/metall/container/list.hpp b/libs/copperr/src/dice/copperr/container/list.hpp similarity index 82% rename from include/metall/container/list.hpp rename to libs/copperr/src/dice/copperr/container/list.hpp index 95741cc8..ade99400 100644 --- a/include/metall/container/list.hpp +++ b/libs/copperr/src/dice/copperr/container/list.hpp @@ -8,14 +8,14 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A list container that uses Metall as its default allocator. template > using list = boost::container::list; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_LIST_HPP \ No newline at end of file diff --git a/include/metall/container/map.hpp b/libs/copperr/src/dice/copperr/container/map.hpp similarity index 89% rename from include/metall/container/map.hpp rename to libs/copperr/src/dice/copperr/container/map.hpp index 5337262c..29938145 100644 --- a/include/metall/container/map.hpp +++ b/libs/copperr/src/dice/copperr/container/map.hpp @@ -10,9 +10,9 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A map container that uses Metall as its default allocator. template , @@ -24,6 +24,6 @@ template , class Allocator = manager::allocator_type>> using multimap = boost::container::multimap; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_MAP_HPP diff --git a/include/metall/container/priority_queue.hpp b/libs/copperr/src/dice/copperr/container/priority_queue.hpp similarity index 83% rename from include/metall/container/priority_queue.hpp rename to libs/copperr/src/dice/copperr/container/priority_queue.hpp index 8f504202..bbce3ca4 100644 --- a/include/metall/container/priority_queue.hpp +++ b/libs/copperr/src/dice/copperr/container/priority_queue.hpp @@ -9,15 +9,15 @@ #include #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A priority_queue container that uses Metall as its default allocator. template , typename Compare = std::less> using priority_queue = std::priority_queue; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_PRIORITY_QUEUE_HPP diff --git a/include/metall/container/queue.hpp b/libs/copperr/src/dice/copperr/container/queue.hpp similarity index 80% rename from include/metall/container/queue.hpp rename to libs/copperr/src/dice/copperr/container/queue.hpp index 5b975447..975c148a 100644 --- a/include/metall/container/queue.hpp +++ b/libs/copperr/src/dice/copperr/container/queue.hpp @@ -8,14 +8,14 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A queue container that uses Metall as its default allocator. template > using queue = std::queue; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_QUEUE_HPP diff --git a/include/metall/container/scoped_allocator.hpp b/libs/copperr/src/dice/copperr/container/scoped_allocator.hpp similarity index 88% rename from include/metall/container/scoped_allocator.hpp rename to libs/copperr/src/dice/copperr/container/scoped_allocator.hpp index 7ff7fdf3..2aa9cccf 100644 --- a/include/metall/container/scoped_allocator.hpp +++ b/libs/copperr/src/dice/copperr/container/scoped_allocator.hpp @@ -8,13 +8,13 @@ #include -namespace metall::container { +namespace dice::copperr::container { /// \brief An allocator which can be used with multilevel containers. template using scoped_allocator_adaptor = boost::container::scoped_allocator_adaptor; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_SCOPED_ALLOCATOR_HPP diff --git a/include/metall/container/set.hpp b/libs/copperr/src/dice/copperr/container/set.hpp similarity index 88% rename from include/metall/container/set.hpp rename to libs/copperr/src/dice/copperr/container/set.hpp index b09d984d..866db074 100644 --- a/include/metall/container/set.hpp +++ b/libs/copperr/src/dice/copperr/container/set.hpp @@ -10,9 +10,9 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A set container that uses Metall as its default allocator. template , @@ -24,6 +24,6 @@ template , class Allocator = manager::allocator_type> using multiset = boost::container::multiset; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_SET_HPP diff --git a/include/metall/container/stack.hpp b/libs/copperr/src/dice/copperr/container/stack.hpp similarity index 80% rename from include/metall/container/stack.hpp rename to libs/copperr/src/dice/copperr/container/stack.hpp index d0954ac3..e65742c7 100644 --- a/include/metall/container/stack.hpp +++ b/libs/copperr/src/dice/copperr/container/stack.hpp @@ -8,14 +8,14 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A stack container that uses Metall as its default allocator. template > using stack = std::stack; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_STACK_HPP diff --git a/include/metall/container/string.hpp b/libs/copperr/src/dice/copperr/container/string.hpp similarity index 82% rename from include/metall/container/string.hpp rename to libs/copperr/src/dice/copperr/container/string.hpp index 133acb8d..808861b1 100644 --- a/include/metall/container/string.hpp +++ b/libs/copperr/src/dice/copperr/container/string.hpp @@ -9,13 +9,13 @@ #include #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A string container that uses Metall as its default allocator. template , - class Allocator = metall::manager::allocator_type> + class Allocator = dice::copperr::manager::allocator_type> using basic_string = boost::container::basic_string; /// \brief A string container that uses char as its character type and Metall as @@ -26,6 +26,6 @@ using string = basic_string; /// as its default allocator. using wstring = basic_string; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_STRING_HPP diff --git a/include/metall/container/string_key_store.hpp b/libs/copperr/src/dice/copperr/container/string_key_store.hpp similarity index 95% rename from include/metall/container/string_key_store.hpp rename to libs/copperr/src/dice/copperr/container/string_key_store.hpp index c707dbf5..2a2b7c33 100644 --- a/include/metall/container/string_key_store.hpp +++ b/libs/copperr/src/dice/copperr/container/string_key_store.hpp @@ -10,16 +10,16 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -namespace metall::container { +namespace dice::copperr::container { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; } /// \brief A ke-value store that uses string for its key. @@ -28,7 +28,7 @@ namespace mc = metall::container; /// \tparam _value_type A value type. /// \tparam allocator_type An allocator type. template > + typename allocator_type = dice::copperr::manager::allocator_type> class string_key_store { private: template @@ -329,8 +329,8 @@ class string_key_store { #ifdef METALL_CONTAINER_STRING_KEY_STORE_USE_SIMPLE_HASH internal_id_type hash = key.empty() ? 0 : (uint8_t)key[0] % 2; #else - auto hash = (internal_id_type)metall::mtlldetail::murmur_hash_64a( - key.data(), (int)key.length(), seed); + auto hash = static_cast(copperr::mtlldetail::murmur_hash_64a( + key.data(), static_cast(key.length()), seed)); #endif if (hash == k_max_internal_id) { hash = priv_increment_internal_id(hash); @@ -352,6 +352,6 @@ class string_key_store { std::size_t m_max_id_probe_distance{0}; }; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_CONCURRENT_STRING_KEY_STORE_HPP diff --git a/include/metall/container/string_key_store_locator.hpp b/libs/copperr/src/dice/copperr/container/string_key_store_locator.hpp similarity index 93% rename from include/metall/container/string_key_store_locator.hpp rename to libs/copperr/src/dice/copperr/container/string_key_store_locator.hpp index 659a20ef..44051c49 100644 --- a/include/metall/container/string_key_store_locator.hpp +++ b/libs/copperr/src/dice/copperr/container/string_key_store_locator.hpp @@ -6,7 +6,7 @@ #ifndef METALL_CONTAINER_CONCURRENT__STRING_KEY_STORE_LOCATOR_HPP_ #define METALL_CONTAINER_CONCURRENT__STRING_KEY_STORE_LOCATOR_HPP_ -namespace metall::container { +namespace dice::copperr::container { template class string_key_store_locator { @@ -40,6 +40,6 @@ class string_key_store_locator { iterator_type m_iterator; }; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_CONCURRENT__STRING_KEY_STORE_LOCATOR_HPP_ diff --git a/include/metall/container/unordered_flat_map.hpp b/libs/copperr/src/dice/copperr/container/unordered_flat_map.hpp similarity index 88% rename from include/metall/container/unordered_flat_map.hpp rename to libs/copperr/src/dice/copperr/container/unordered_flat_map.hpp index ecca824c..8b1970d8 100644 --- a/include/metall/container/unordered_flat_map.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_flat_map.hpp @@ -11,9 +11,9 @@ static_assert(BOOST_VERSION >= 108100, "Unsupported Boost version"); #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_flat_map container that uses Metall as its default /// allocator. @@ -23,6 +23,6 @@ template , using unordered_flat_map = boost::unordered_flat_map; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_FLAT_MAP_HPP diff --git a/include/metall/container/unordered_flat_set.hpp b/libs/copperr/src/dice/copperr/container/unordered_flat_set.hpp similarity index 87% rename from include/metall/container/unordered_flat_set.hpp rename to libs/copperr/src/dice/copperr/container/unordered_flat_set.hpp index 24c63264..413b214a 100644 --- a/include/metall/container/unordered_flat_set.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_flat_set.hpp @@ -11,9 +11,9 @@ static_assert(BOOST_VERSION >= 108100, "Unsupported Boost version"); #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_flat_set container that uses Metall as its default /// allocator. @@ -23,6 +23,6 @@ template , using unordered_flat_set = boost::unordered_flat_set; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_FLAT_SET_HPP diff --git a/include/metall/container/unordered_map.hpp b/libs/copperr/src/dice/copperr/container/unordered_map.hpp similarity index 90% rename from include/metall/container/unordered_map.hpp rename to libs/copperr/src/dice/copperr/container/unordered_map.hpp index 88fb6c4c..4837434a 100644 --- a/include/metall/container/unordered_map.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_map.hpp @@ -10,9 +10,9 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_map container that uses Metall as its default allocator. template , @@ -28,6 +28,6 @@ template , using unordered_multimap = boost::unordered_multimap; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_MAP_HPP diff --git a/include/metall/container/unordered_node_map.hpp b/libs/copperr/src/dice/copperr/container/unordered_node_map.hpp similarity index 88% rename from include/metall/container/unordered_node_map.hpp rename to libs/copperr/src/dice/copperr/container/unordered_node_map.hpp index 07af8ea8..acf895d0 100644 --- a/include/metall/container/unordered_node_map.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_node_map.hpp @@ -11,9 +11,9 @@ static_assert(BOOST_VERSION >= 108200, "Unsupported Boost version"); #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_node_map container that uses Metall as its default /// allocator. @@ -23,6 +23,6 @@ template , using unordered_node_map = boost::unordered_node_map; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_NODE_MAP_HPP diff --git a/include/metall/container/unordered_node_set.hpp b/libs/copperr/src/dice/copperr/container/unordered_node_set.hpp similarity index 87% rename from include/metall/container/unordered_node_set.hpp rename to libs/copperr/src/dice/copperr/container/unordered_node_set.hpp index 2616a12e..84df6847 100644 --- a/include/metall/container/unordered_node_set.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_node_set.hpp @@ -11,9 +11,9 @@ static_assert(BOOST_VERSION >= 108200, "Unsupported Boost version"); #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_node_set container that uses Metall as its default /// allocator. @@ -23,6 +23,6 @@ template , using unordered_node_set = boost::unordered_node_set; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_NODE_SET_HPP diff --git a/include/metall/container/unordered_set.hpp b/libs/copperr/src/dice/copperr/container/unordered_set.hpp similarity index 90% rename from include/metall/container/unordered_set.hpp rename to libs/copperr/src/dice/copperr/container/unordered_set.hpp index 3a343b8d..3bf83ad4 100644 --- a/include/metall/container/unordered_set.hpp +++ b/libs/copperr/src/dice/copperr/container/unordered_set.hpp @@ -10,9 +10,9 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief An unordered_set container that uses Metall as its default allocator. template , @@ -28,6 +28,6 @@ template , using unordered_multiset = boost::unordered_multiset; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_UNORDERED_SET_HPP diff --git a/include/metall/container/vector.hpp b/libs/copperr/src/dice/copperr/container/vector.hpp similarity index 82% rename from include/metall/container/vector.hpp rename to libs/copperr/src/dice/copperr/container/vector.hpp index f0d24c95..2b5d9e71 100644 --- a/include/metall/container/vector.hpp +++ b/libs/copperr/src/dice/copperr/container/vector.hpp @@ -8,14 +8,14 @@ #include -#include +#include -namespace metall::container { +namespace dice::copperr::container { /// \brief A vector container that uses Metall as its default allocator. template > using vector = boost::container::vector; -} // namespace metall::container +} // namespace dice::copperr::container #endif // METALL_CONTAINER_VECTOR_HPP diff --git a/include/metall/metall.hpp b/libs/copperr/src/dice/copperr/copperr.hpp similarity index 88% rename from include/metall/metall.hpp rename to libs/copperr/src/dice/copperr/copperr.hpp index af47f294..fce14211 100644 --- a/include/metall/metall.hpp +++ b/libs/copperr/src/dice/copperr/copperr.hpp @@ -6,20 +6,20 @@ #ifndef METALL_METALL_HPP #define METALL_METALL_HPP -#include -#include -#include -#include +#include +#include +#include +#include -/// \namespace metall +/// \namespace dice::copperr /// \brief The top level of namespace of Metall -namespace metall { +namespace dice::copperr { /// \brief Default Metall manager class which is an alias of basic_manager with /// the default template parameters. using manager = basic_manager<>; -} // namespace metall +} // namespace dice::copperr /// \example complex_map.cpp /// This is an example of how to use a complex STL map container with Metall. @@ -67,7 +67,7 @@ using manager = basic_manager<>; /// \example object_attribute_api_list.cpp /// This is an example of how to use all API related to object attributes. -/// \example metall_containers.cpp +/// \example copperr_containers.cpp /// This is an example of how to use Metall containers. #endif // METALL_METALL_HPP diff --git a/include/metall/defs.hpp b/libs/copperr/src/dice/copperr/defs.hpp similarity index 100% rename from include/metall/defs.hpp rename to libs/copperr/src/dice/copperr/defs.hpp diff --git a/include/metall/detail/array_construct.hpp b/libs/copperr/src/dice/copperr/detail/array_construct.hpp similarity index 90% rename from include/metall/detail/array_construct.hpp rename to libs/copperr/src/dice/copperr/detail/array_construct.hpp index 9cfb4474..d01b475d 100644 --- a/include/metall/detail/array_construct.hpp +++ b/libs/copperr/src/dice/copperr/detail/array_construct.hpp @@ -8,12 +8,12 @@ #include -namespace metall { +namespace dice::copperr { namespace mtlldetail { using boost::interprocess::ipcdetail::array_construct; } // namespace mtlldetail -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_UTILITY_ARRAY_CONSTRUCT_HPP diff --git a/include/metall/detail/bitset.hpp b/libs/copperr/src/dice/copperr/detail/bitset.hpp similarity index 98% rename from include/metall/detail/bitset.hpp rename to libs/copperr/src/dice/copperr/detail/bitset.hpp index 53746ed2..0f30a036 100644 --- a/include/metall/detail/bitset.hpp +++ b/libs/copperr/src/dice/copperr/detail/bitset.hpp @@ -13,9 +13,9 @@ #include #include -#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { namespace bitset_detail { // example (sizeof(block_type) is 8 byte) @@ -371,5 +371,5 @@ class bitset { internal_table_t m_table; }; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_BITSET_HPP diff --git a/include/metall/detail/builtin_functions.hpp b/libs/copperr/src/dice/copperr/detail/builtin_functions.hpp similarity index 91% rename from include/metall/detail/builtin_functions.hpp rename to libs/copperr/src/dice/copperr/detail/builtin_functions.hpp index cbf741c2..bff58b0d 100644 --- a/include/metall/detail/builtin_functions.hpp +++ b/libs/copperr/src/dice/copperr/detail/builtin_functions.hpp @@ -6,7 +6,7 @@ #ifndef METALL_DETAIL_UTILITY_BUILTIN_FUNCTIONS_HPP #define METALL_DETAIL_UTILITY_BUILTIN_FUNCTIONS_HPP -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { /// \brief Count Leading Zeros. inline int clzll(const unsigned long long x) noexcept { @@ -26,6 +26,6 @@ inline int ctzll(const unsigned long long x) noexcept { #endif } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_BUILTIN_FUNCTIONS_HPP diff --git a/include/metall/detail/char_ptr_holder.hpp b/libs/copperr/src/dice/copperr/detail/char_ptr_holder.hpp similarity index 90% rename from include/metall/detail/char_ptr_holder.hpp rename to libs/copperr/src/dice/copperr/detail/char_ptr_holder.hpp index ad6c7ae1..d73938b9 100644 --- a/include/metall/detail/char_ptr_holder.hpp +++ b/libs/copperr/src/dice/copperr/detail/char_ptr_holder.hpp @@ -8,7 +8,7 @@ #include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { template using char_ptr_holder = @@ -20,5 +20,5 @@ using anonymous_instance_t = boost::interprocess::ipcdetail::anonymous_instance_t; using unique_instance_t = boost::interprocess::ipcdetail::unique_instance_t; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_CHAR_OTR_HOLDER_HPP diff --git a/libs/copperr/src/dice/copperr/detail/file.hpp b/libs/copperr/src/dice/copperr/detail/file.hpp new file mode 100644 index 00000000..5ea499f7 --- /dev/null +++ b/libs/copperr/src/dice/copperr/detail/file.hpp @@ -0,0 +1,629 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#ifndef METALL_DETAIL_UTILITY_FILE_HPP +#define METALL_DETAIL_UTILITY_FILE_HPP + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __linux__ +#include // For FALLOC_FL_PUNCH_HOLE and FALLOC_FL_KEEP_SIZE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace dice::copperr::mtlldetail { + +/** + * Calls ::close, logs a warning on error + * @return true if ::close() succeeded, false otherwise + */ +inline bool os_close(const int fd) { + if (::close(fd) == -1) { + METALL_ERRNO_WARN("close"); + return false; + } + return true; +} + +/** + * Calls ::fsync, logs a warning on error + * @return true if ::fsync() succeeded, false otherwise + */ +inline bool os_fsync(const int fd) { + if (::fsync(fd) != 0) { + METALL_ERRNO_WARN("fsync"); + return false; + } + return true; +} + +inline bool fsync(const std::filesystem::path &path) { + const int fd = ::open(path.c_str(), O_RDONLY); + if (fd == -1) { + METALL_ERRNO_ERROR("open"); + return false; + } + + bool ret = true; + ret &= os_fsync(fd); + ret &= os_close(fd); + + return ret; +} + +inline bool fsync_recursive(const std::filesystem::path &path) { + auto p = std::filesystem::canonical(path); + while (true) { + if (!fsync(p.string())) { + return false; + } + if (p == p.root_path()) { + break; + } + p = p.parent_path(); + } + return true; +} + +inline bool extend_file_size_manually(const int fd, const off_t offset, + const ssize_t file_size) { + auto buffer = new unsigned char[4096]; + for (off_t i = offset; i < file_size / 4096 + offset; ++i) { + ::pwrite(fd, buffer, 4096, i * 4096); + } + const size_t remained_size = file_size % 4096; + if (remained_size > 0) + ::pwrite(fd, buffer, remained_size, file_size - remained_size); + + delete[] buffer; + + const bool ret = os_fsync(fd); + + return ret; +} + +inline bool extend_file_size(const int fd, const size_t file_size, + const bool fill_with_zero) { + if (fill_with_zero) { +#ifdef __APPLE__ + if (!extend_file_size_manually(fd, 0, file_size)) { + METALL_ERROR("Failed to extend file size manually, filling zero"); + return false; + } +#else + if (::posix_fallocate(fd, 0, file_size) == -1) { + METALL_ERRNO_ERROR("fallocate"); + return false; + } +#endif + } else { + // ----- extend the file if its size is smaller than that of mapped area + // ----- // + struct stat stat_buf; + if (::fstat(fd, &stat_buf) == -1) { + METALL_ERRNO_ERROR("fstat"); + return false; + } + if (::llabs(stat_buf.st_size) < static_cast(file_size)) { + if (::ftruncate(fd, file_size) == -1) { + METALL_ERRNO_ERROR("ftruncate"); + return false; + } + } + } + + const bool ret = os_fsync(fd); + return ret; +} + +inline bool extend_file_size(const std::filesystem::path &file_path, + const size_t file_size, + const bool fill_with_zero = false) { + const int fd = ::open(file_path.c_str(), O_RDWR); + if (fd == -1) { + METALL_ERRNO_ERROR("open"); + return false; + } + + bool ret = extend_file_size(fd, file_size, fill_with_zero); + ret &= os_close(fd); + + return ret; +} + +/// \brief Check if a file, any kinds of file including directory, exists +/// \warning This implementation could return a wrong result due to metadata +/// cache on NFS. The following code could fail: if (mpi_rank == 1) +/// file_exist(path); // NFS creates metadata cache mpi_barrier(); if (mpi_rank +/// == 0) create_directory(path); mpi_barrier(); if (mpi_rank == 1) +/// assert(file_exist(path)); // Could fail due to the cached metadata. +inline bool file_exist(const std::filesystem::path &file_name) { + return (::access(file_name.c_str(), F_OK) == 0); +} + +/// \brief Check if a directory exists +/// \warning This implementation could return a wrong result due to metadata +/// cache on NFS. +inline bool directory_exist(const std::filesystem::path &dir_path) { + struct stat stat_buf; + if (::stat(dir_path.c_str(), &stat_buf) == -1) { + return false; + } + return S_ISDIR(stat_buf.st_mode); +} + +inline bool create_file(const std::filesystem::path &file_path) { + const int fd = + ::open(file_path.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd == -1) { + METALL_ERRNO_ERROR("open"); + return false; + } + + if (!os_close(fd)) return false; + + return fsync_recursive(file_path); +} + +inline bool create_directory(const std::filesystem::path &dir_path) { + bool success = true; + try { + std::error_code ec; + if (!std::filesystem::create_directories(dir_path, ec)) { + if (!ec) { + // if the directory exist, create_directories returns false. + // However, std::error_code is cleared and !ec returns true. + return true; + } + + METALL_ERROR("{}", ec.message()); + success = false; + } + } catch (std::filesystem::filesystem_error &e) { + METALL_ERROR("{}", e.what()); + success = false; + } + + return success; +} + +inline ssize_t get_file_size(const std::filesystem::path &file_path) { + std::ifstream ifs(file_path, std::ifstream::binary | std::ifstream::ate); + ssize_t size = ifs.tellg(); + if (size == -1) { + METALL_ERROR("Failed to get file size: {}", file_path.c_str()); + } + + return size; +} + +/// \brief +/// Note that, according to GCC, +/// the file system may use some blocks for internal record keeping +inline ssize_t get_actual_file_size(const std::filesystem::path &file_path) { + struct stat stat_buf; + if (::stat(file_path.c_str(), &stat_buf) != 0) { + METALL_ERRNO_ERROR("stat ({})", file_path.c_str()); + return -1; + } + return stat_buf.st_blocks * 512LL; +} + +/// \brief Remove a file or directory +/// \return Upon successful completion, returns true; otherwise, false is +/// returned. If the file or directory does not exist, true is returned. +inline bool remove_file(const std::filesystem::path &path) { + std::error_code ec; + std::filesystem::remove_all(path, ec); + return !ec; +} + +inline bool free_file_space([[maybe_unused]] const int fd, + [[maybe_unused]] const off_t off, + [[maybe_unused]] const off_t len) { +#if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) + if (::fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off, len) == + -1) { + METALL_ERRNO_WARN("fallocate"); + return false; + } + return true; + +#else +#ifdef METALL_VERBOSE_SYSTEM_SUPPORT_WARNING +#warning "FALLOC_FL_PUNCH_HOLE or FALLOC_FL_KEEP_SIZE is not supported" +#endif + return false; +#endif +} + +namespace file_copy_detail { + +inline bool copy_file_dense(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path) { + bool success = true; + try { + if (!std::filesystem::copy_file(source_path, destination_path, + std::filesystem::copy_options::overwrite_existing)) { + METALL_ERROR("Failed copying file {} to {}", source_path.c_str(), destination_path.c_str()); + success = false; + } + } catch (std::filesystem::filesystem_error &e) { + METALL_ERROR("{}", e.what()); + success = false; + } + + mtlldetail::fsync(destination_path); + return success; +} + +#ifdef __linux__ +/** + * @brief Prepares a file copy from source_path to destination_path + * by opening/creating the relevant files and setting appropriate permissions. + * + * @param source_path path to source file + * @param destination_path desired path of destination file + * @param src out parameter for the file descriptor opened for source_path (will be opened read only) + * @param dst out parameter for the file descriptor opened for destination_path (will be opened write only) + * @return on success: size of source file as obtained by ::fstat. on failure: -1 + * + * @warning if the function fails the user must not use the obtained src and dst file descriptors in any way + * (they don't need to be closed) + */ +inline off_t prepare_file_copy_linux(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path, + int *src, + int *dst) { + *src = ::open(source_path.c_str(), O_RDONLY); + if (*src == -1) { + METALL_ERRNO_ERROR("Unable to open {}", source_path.c_str()); + return -1; + } + + struct stat st; + if (::fstat(*src, &st) == -1) { + METALL_ERRNO_ERROR("Unable to stat {}", source_path.c_str()); + os_close(*src); + return -1; + } + + *dst = ::open(destination_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, st.st_mode); + if (*dst == -1) { + METALL_ERRNO_ERROR("Unable to open {}", destination_path.c_str()); + os_close(*src); + return -1; + } + + return st.st_size; +} + +/** + * Creates a hole of size size at the current cursor of fd. + * Moves cursor of fd behind the created hole. + * + * @param fd file descriptor + * @param size size of to-be-created hole + * @return if creation was successful + * @note the cursor position will still be advanced even if hole punching fails + * + * Relevant man pages: + * https://www.man7.org/linux/man-pages/man2/lseek.2.html + * https://man7.org/linux/man-pages/man2/fallocate.2.html + */ +inline bool create_hole_linux(const int fd, const off_t size) { + if (size == 0) { + return true; + } + + // Seek size bytes past the current position + const off_t hole_end = ::lseek(fd, size, SEEK_CUR); + if (hole_end < 0) { + METALL_ERRNO_ERROR("lseek"); + return false; + } + + // punch a hole from old cursor to new cursor + if (::fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, hole_end - size, size) < 0) { + METALL_ERRNO_ERROR("fallocate(FALLOC_FL_PUNCH_HOLE)"); + return false; + } + + return true; +} + +/** + * Performs a sparse copy from src to dst, by only copying actual data and manually recreating + * all holes from src in dst. + * + * I.e. for each "segment" (data segment or hole) in src do + * if segment is data => copy segment to dst + * if segment is hole => create new hole (of the appropriate size) in dst + * + * @param src source file descriptor + * @param dst destination file descriptor + * @param src_size size of file behind src as obtained by ::fstat + * @return if copying was successful + * + * Relevant man pages: + * https://www.man7.org/linux/man-pages/man2/lseek.2.html + * https://www.man7.org/linux/man-pages/man2/copy_file_range.2.html + * https://www.man7.org/linux/man-pages/man3/ftruncate.3p.html + */ +inline bool copy_file_sparse_linux(const int src, const int dst, const off_t src_size) { + off_t old_off = 0; + off_t off = 0; + + while ((off = ::lseek(src, off, SEEK_DATA)) >= 0) { + if (!create_hole_linux(dst, off - old_off)) { + METALL_ERROR("Unable to punch hole"); + return false; + } + + off_t const hole_start = ::lseek(src, off, SEEK_HOLE); + if (hole_start < 0) { + METALL_ERRNO_ERROR("fseek(SEEK_HOLE)"); + return false; + } + + if (::copy_file_range(src, &off, dst, nullptr, hole_start - off, 0) < 0) { + METALL_ERRNO_ERROR("copy_file_range"); + return false; + } + + old_off = off; + } + + if (errno != ENXIO) { + // error condition: offset is _not_ within a hole at the end of the file. + // previous lseek from while-loop condition must have failed + METALL_ERRNO_ERROR("fseek(SEEK_DATA)"); + return false; + } + + if (old_off < src_size) { + // the final extent is a hole we must call ftruncate + // here in order to record the proper length in the destination. + // See also: https://github.com/coreutils/coreutils/blob/a257b63ce7ebcc4577adb5406b39fc0edd61dcac/src/copy.c#L643-L658 + if (::ftruncate(dst, src_size) < 0) { + METALL_ERRNO_ERROR("ftruncate"); + return false; + } + + if (!create_hole_linux(dst, src_size - old_off)) { + METALL_ERROR("Unable to punch hole"); + return false; + } + } + + return true; +} + +/** + * Attempts to perform a sparse copy from source_path to destination_path, + * falling back to regular copy if the sparse copy fails. + */ +inline bool copy_file_sparse_linux(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path) { + int src; + int dst; + const off_t src_size = prepare_file_copy_linux(source_path, destination_path, &src, &dst); + if (src_size < 0) { + METALL_ERROR("Unable to prepare for file copy"); + return false; + } + + if (copy_file_sparse_linux(src, dst, src_size)) { + os_fsync(dst); + os_close(src); + os_close(dst); + return true; + } + + METALL_WARN("Unable to sparse copy {} to {}, falling back to normal copy", source_path.c_str(), destination_path.c_str()); + os_close(src); + os_close(dst); + + if (copy_file_dense(source_path, destination_path)) { + return true; + } + + METALL_ERROR("Unable to copy {} to {}", source_path.c_str(), destination_path.c_str()); + return false; +} + +/** + * @brief Performs an accelerated, in-kernel copy from src to dst + * @param src source file descriptor + * @param dst destination file descriptor + * @param src_size size of source file as obtained by ::fstat(src) + * @return if the operation was successful + * + * Relevant man pages: + * - https://www.man7.org/linux/man-pages/man2/copy_file_range.2.html + */ +inline bool copy_file_dense_linux(const int src, const int dst, const off_t src_size) { + if (::copy_file_range(src, nullptr, dst, nullptr, src_size, 0) < 0) { + METALL_ERRNO_ERROR("copy_file_range"); + return false; + } + + return true; +} + +/** + * @brief performs a dense copy from source_path to destionation_path + * @param source_path path to source file + * @param destination_path path to destination file + * @return if the operation was successful + */ +inline bool copy_file_dense_linux(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path) { + int src; + int dst; + const off_t src_size = prepare_file_copy_linux(source_path, destination_path, &src, &dst); + if (src_size >= 0) { + if (copy_file_dense_linux(src, dst, src_size)) { + os_fsync(dst); + os_close(src); + os_close(dst); + return true; + } + } + + os_close(src); + os_close(dst); + METALL_WARN("Unable to use accelerated dense copy, falling back to unaccelerated dense copy"); + + return copy_file_dense(source_path, destination_path); +} + +#endif // __linux__ +} // namespace file_copy_detail + +/// \brief Copy a file. +/// \param source_path A source file path. +/// \param destination_path A destination path. +/// \param sparse_copy If true is specified, tries to perform sparse file copy. +/// \return On success, returns true. On error, returns false. +inline bool copy_file(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path, + const bool sparse_copy = true) { + if (sparse_copy) { +#ifdef __linux__ + return file_copy_detail::copy_file_sparse_linux(source_path, destination_path); +#else + METALL_WARN("Sparse file copy is only supported on linux, falling back to normal copy"); +#endif + } + +#ifdef __linux__ + return file_copy_detail::copy_file_dense_linux(source_path, destination_path); +#else + return file_copy_detail::copy_file_dense(source_path, destination_path); +#endif +} + +/// \brief Get the file names in a directory. +/// This function does not list files recursively. +/// Only regular files are returned. +/// \param dir_path A directory path. +/// \param file_list A buffer to put results. +/// \return Returns true if there is no error (empty directory returns true as +/// long as the operation does not fail). Returns false on error. +inline bool get_regular_file_names(const std::filesystem::path &dir_path, + std::vector *file_list) { + if (!directory_exist(dir_path)) { + return false; + } + + try { + file_list->clear(); + for (auto &p : std::filesystem::directory_iterator(dir_path)) { + if (p.is_regular_file()) { + file_list->push_back(p.path().filename().string()); + } + } + } catch (...) { + METALL_ERROR("Exception was thrown"); + return false; + } + + return true; +} + +/// \brief Copy files in a directory. +/// This function does not copy files in subdirectories. +/// This function does not also copy directories. +/// \param source_dir_path A path to source directory. +/// \param destination_dir_path A path to destination directory. +/// \param max_num_threads The maximum number of threads to use. +/// If <= 0 is given, the value is automatically determined. +/// \param copy_func The actual copy function. +/// \return On success, returns true. On error, returns false. +template +inline bool copy_files_in_directory_in_parallel_helper( + const std::filesystem::path &source_dir_path, const std::filesystem::path &destination_dir_path, + const int max_num_threads, + F &©_func) { + std::vector src_file_names; + if (!get_regular_file_names(source_dir_path, &src_file_names)) { + METALL_ERROR("Failed to get file list"); + return false; + } + + std::atomic_uint_fast64_t num_successes = 0; + std::atomic_uint_fast64_t file_no_cnt = 0; + auto copy_lambda = [&file_no_cnt, &num_successes, &source_dir_path, + &src_file_names, &destination_dir_path, ©_func]() { + while (true) { + const auto file_no = file_no_cnt.fetch_add(1); + if (file_no >= src_file_names.size()) break; + std::filesystem::path const src_file_path = source_dir_path / src_file_names[file_no]; + std::filesystem::path const dst_file_path = destination_dir_path / src_file_names[file_no]; + num_successes.fetch_add(copy_func(src_file_path, dst_file_path) ? 1 : 0); + } + }; + + const auto num_threads = std::min( + src_file_names.size(), + (max_num_threads > 0 ? max_num_threads + : std::thread::hardware_concurrency())); + std::vector threads; + threads.reserve(num_threads); + for (size_t ix = 0; ix < num_threads; ++ix) { + threads.emplace_back(copy_lambda); + } + + for (auto &th : threads) { + th.join(); + } + + return num_successes == src_file_names.size(); +} + +/// \brief Copy files in a directory. +/// This function does not copy files in subdirectories. +/// \param source_dir_path A path to source directory. +/// \param destination_dir_path A path to destination directory. +/// \param max_num_threads The maximum number of threads to use. +/// If <= 0 is given, it is automatically determined. +/// \param sparse_copy Performs sparse file copy. +/// \return On success, returns true. On error, returns false. +inline bool copy_files_in_directory_in_parallel( + const std::filesystem::path &source_dir_path, const std::filesystem::path &destination_dir_path, + const int max_num_threads, const bool sparse_copy = true) { + return copy_files_in_directory_in_parallel_helper( + source_dir_path, destination_dir_path, max_num_threads, + [sparse_copy](auto const &src, auto const &dst) { + return copy_file(src, dst, sparse_copy); + }); +} +} // namespace dice::copperr::mtlldetail + +#endif // METALL_DETAIL_UTILITY_FILE_HPP diff --git a/libs/copperr/src/dice/copperr/detail/file_clone.hpp b/libs/copperr/src/dice/copperr/detail/file_clone.hpp new file mode 100644 index 00000000..274db268 --- /dev/null +++ b/libs/copperr/src/dice/copperr/detail/file_clone.hpp @@ -0,0 +1,113 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#ifndef METALL_DETAIL_UTILITY_FILE_CLONE_HPP +#define METALL_DETAIL_UTILITY_FILE_CLONE_HPP + +#include + +#ifdef __linux__ +#include +#endif + +#include +#include +#include + +namespace dice::copperr::mtlldetail { + +namespace file_clone_detail { +#ifdef __linux__ +/** + * Clone file using + * https://man7.org/linux/man-pages/man2/ioctl_ficlone.2.html + */ +inline bool clone_file_linux(const int src, const int dst) { +#ifdef FICLONE + return ::ioctl(dst, FICLONE, src) != -1; +#else + errno = ENOTSUP; + return false; +#endif // defined(FICLONE) +} + +/** + * Attempts to perform an O(1) clone of source_path to destionation_path + * if cloning fails, falls back to sparse copying + * if sparse copying fails, falls back to regular copying + */ +inline bool clone_file_linux(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path) { + int src; + int dst; + const off_t src_size = file_copy_detail::prepare_file_copy_linux(source_path, destination_path, &src, &dst); + if (src_size < 0) { + METALL_ERROR("Unable to prepare for file copy"); + return false; + } + + const auto close_fsync_all = [&]() noexcept { + os_fsync(dst); + os_close(src); + os_close(dst); + }; + + if (clone_file_linux(src, dst)) { + close_fsync_all(); + return true; + } + + METALL_WARN("Unable to clone {} to {}, falling back to sparse copy", source_path.c_str(), destination_path.c_str()); + + if (file_copy_detail::copy_file_sparse_linux(src, dst, src_size)) { + close_fsync_all(); + return true; + } + + METALL_WARN("Unable to sparse copy {} to {}, falling back to normal copy", source_path.c_str(), destination_path.c_str()); + os_close(src); + os_close(dst); + + if (file_copy_detail::copy_file_dense(source_path, destination_path)) { + return true; + } + + METALL_ERROR("Unable to copy {} to {}", source_path.c_str(), destination_path.c_str()); + return false; +} +#endif // __linux__ +} // namespace file_clone_detail + +/// \brief Clones a file. If file cloning is not supported, copies the file +/// normally. \param source_path A path to the file to be cloned. \param +/// destination_path A path to copy to. \return On success, returns true. On +/// error, returns false. +inline bool clone_file(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path) { +#if defined(__linux__) + return file_clone_detail::clone_file_linux(source_path, destination_path); +#else + METALL_WARN("Cloning is only supported on linux, falling back to copying"); + return mtlldetail::copy_file(source_path, destination_path); +#endif +} + +/// \brief Clone files in a directory. +/// This function does not clone files in subdirectories. +/// \param source_dir_path A path to source directory. +/// \param destination_dir_path A path to destination directory. +/// \param max_num_threads The maximum number of threads to use. +/// If <= 0 is given, it is automatically determined. +/// \return On success, returns true. On error, returns false. +inline bool clone_files_in_directory_in_parallel( + const std::filesystem::path &source_dir_path, const std::filesystem::path &destination_dir_path, + const int max_num_threads) { + return copy_files_in_directory_in_parallel_helper( + source_dir_path, destination_dir_path, max_num_threads, clone_file); +} + +} // namespace dice::copperr::mtlldetail + +#endif // METALL_DETAIL_UTILITY_FILE_CLONE_HPP diff --git a/include/metall/detail/hash.hpp b/libs/copperr/src/dice/copperr/detail/hash.hpp similarity index 93% rename from include/metall/detail/hash.hpp rename to libs/copperr/src/dice/copperr/detail/hash.hpp index ee0c0dc4..80f3619e 100644 --- a/include/metall/detail/hash.hpp +++ b/libs/copperr/src/dice/copperr/detail/hash.hpp @@ -8,9 +8,9 @@ #include -#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { // ----------------------------------------------------------------------------- // This file contains public domain code from MurmurHash2. @@ -51,7 +51,7 @@ inline uint64_t murmur_hash_64a(const void *key, int len, uint64_t h = seed ^ (len * m); - const uint64_t *data = (const uint64_t *)key; + const uint64_t *data = reinterpret_cast(key); const uint64_t *end = data + (len / 8); while (data != end) { @@ -65,7 +65,7 @@ inline uint64_t murmur_hash_64a(const void *key, int len, h *= m; } - const unsigned char *data2 = (const unsigned char *)data; + const unsigned char *data2 = reinterpret_cast(data); switch (len & 7) { case 7: @@ -135,6 +135,6 @@ struct str_hash { } }; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_HASH_HPP diff --git a/include/metall/detail/in_place_interface.hpp b/libs/copperr/src/dice/copperr/detail/in_place_interface.hpp similarity index 87% rename from include/metall/detail/in_place_interface.hpp rename to libs/copperr/src/dice/copperr/detail/in_place_interface.hpp index e0736d22..2db4ad88 100644 --- a/include/metall/detail/in_place_interface.hpp +++ b/libs/copperr/src/dice/copperr/detail/in_place_interface.hpp @@ -8,11 +8,11 @@ #include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { /// \brief Abstract interface for placement construction and destruction using in_place_interface = boost::interprocess::ipcdetail::in_place_interface; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_IN_PLACE_INTERFACE_HPP diff --git a/include/metall/detail/memory.hpp b/libs/copperr/src/dice/copperr/detail/memory.hpp similarity index 93% rename from include/metall/detail/memory.hpp rename to libs/copperr/src/dice/copperr/detail/memory.hpp index 8fa1fde8..bf5b7077 100644 --- a/include/metall/detail/memory.hpp +++ b/libs/copperr/src/dice/copperr/detail/memory.hpp @@ -12,15 +12,14 @@ #include #include #include -#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { inline ssize_t get_page_size() noexcept { const ssize_t page_size = ::sysconf(_SC_PAGE_SIZE); if (page_size == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, - "Failed to get the page size"); + METALL_ERRNO_ERROR("Failed to get the page size"); } return page_size; @@ -127,7 +126,7 @@ inline std::pair get_num_page_faults() { &minflt, &majflt)) != 2) { std::stringstream ss; ss << "Failed to reading #of page faults " << ret; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("{}", ss.str()); minflt = majflt = 0; } } @@ -140,6 +139,6 @@ inline std::pair get_num_page_faults() { return std::make_pair(minflt, majflt); } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_MEMORY_HPP diff --git a/include/metall/detail/mmap.hpp b/libs/copperr/src/dice/copperr/detail/mmap.hpp similarity index 81% rename from include/metall/detail/mmap.hpp rename to libs/copperr/src/dice/copperr/detail/mmap.hpp index 8f14e7ed..7f984bcc 100644 --- a/include/metall/detail/mmap.hpp +++ b/libs/copperr/src/dice/copperr/detail/mmap.hpp @@ -20,12 +20,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { /// \brief Maps a file checking errors /// \param addr Same as mmap(2) @@ -44,34 +44,25 @@ inline void *os_mmap(void *const addr, const size_t length, return nullptr; } - if ((ptrdiff_t)addr % page_size != 0) { - std::stringstream ss; - ss << "address (" << addr << ") is not page aligned (" - << ::sysconf(_SC_PAGE_SIZE) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + if (reinterpret_cast(addr) % page_size != 0) { + METALL_ERROR("address ({}) is not page aligned ({})", addr, ::sysconf(_SC_PAGE_SIZE)); return nullptr; } if (offset % page_size != 0) { - std::stringstream ss; - ss << "offset (" << offset << ") is not a multiple of the page size (" - << ::sysconf(_SC_PAGE_SIZE) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("offset ({}) is not a multiple of the page size ({})", offset, ::sysconf(_SC_PAGE_SIZE)); return nullptr; } // ----- Map the file ----- // void *mapped_addr = ::mmap(addr, length, protection, flags, fd, offset); if (mapped_addr == MAP_FAILED) { - logger::perror(logger::level::error, __FILE__, __LINE__, "mmap"); + METALL_ERRNO_ERROR("mmap"); return nullptr; } - if ((ptrdiff_t)mapped_addr % page_size != 0) { - std::stringstream ss; - ss << "mapped address (" << mapped_addr << ") is not page aligned (" - << ::sysconf(_SC_PAGE_SIZE) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + if (reinterpret_cast(mapped_addr) % page_size != 0) { + METALL_ERROR("mapped address ({}) is not page aligned ({})", mapped_addr, ::sysconf(_SC_PAGE_SIZE)); return nullptr; } @@ -98,12 +89,12 @@ inline void *map_anonymous_write_mode(void *const addr, const size_t length, /// \return A pair of the file descriptor of the file and the starting address /// for the map inline std::pair map_file_read_mode( - const std::string &file_name, void *const addr, const size_t length, + const std::filesystem::path &file_name, void *const addr, const size_t length, const off_t offset, const int additional_flags = 0) { // ----- Open the file ----- // const int fd = ::open(file_name.c_str(), O_RDONLY); if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); + METALL_ERRNO_ERROR("open"); return std::make_pair(-1, nullptr); } @@ -147,12 +138,12 @@ inline void *map_file_write_mode(const int fd, void *const addr, /// \return A pair of the file descriptor of the file and the starting address /// for the map inline std::pair map_file_write_mode( - const std::string &file_name, void *const addr, const size_t length, + const std::filesystem::path &file_name, void *const addr, const size_t length, const off_t offset, const int additional_flags = 0) { // ----- Open the file ----- // const int fd = ::open(file_name.c_str(), O_RDWR); if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); + METALL_ERRNO_ERROR("open"); return std::make_pair(-1, nullptr); } @@ -197,12 +188,12 @@ inline void *map_file_write_private_mode(const int fd, void *const addr, /// \return A pair of the file descriptor of the file and the starting address /// for the map inline std::pair map_file_write_private_mode( - const std::string &file_name, void *const addr, const size_t length, + const std::filesystem::path &file_name, void *const addr, const size_t length, const off_t offset, const int additional_flags = 0) { // ----- Open the file ----- // const int fd = ::open(file_name.c_str(), O_RDWR); if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); + METALL_ERRNO_ERROR("open"); return std::make_pair(-1, nullptr); } @@ -221,7 +212,7 @@ inline bool os_msync(void *const addr, const size_t length, const bool sync, const int additional_flags = 0) { if (::msync(addr, length, (sync ? MS_SYNC : MS_ASYNC) | additional_flags) != 0) { - logger::perror(logger::level::error, __FILE__, __LINE__, "msync"); + METALL_ERRNO_ERROR("msync"); return false; } return true; @@ -229,7 +220,7 @@ inline bool os_msync(void *const addr, const size_t length, const bool sync, inline bool os_munmap(void *const addr, const size_t length) { if (::munmap(addr, length) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "munmap"); + METALL_ERRNO_ERROR("munmap"); return false; } return true; @@ -256,7 +247,7 @@ inline bool map_with_prot_none(void *const addr, const size_t length) { inline bool os_mprotect(void *const addr, const size_t length, const int prot) { if (::mprotect(addr, length, prot) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "mprotect"); + METALL_ERRNO_ERROR("mprotect"); return false; } return true; @@ -288,8 +279,7 @@ inline bool uncommit_private_anonymous_pages(void *const addr, const size_t length) { #ifdef MADV_FREE if (!os_madvise(addr, length, MADV_FREE)) { - logger::perror(logger::level::info, __FILE__, __LINE__, - "madvise MADV_FREE"); + METALL_ERRNO_INFO("madvise MADV_FREE"); return false; } #else @@ -297,8 +287,7 @@ inline bool uncommit_private_anonymous_pages(void *const addr, #warning "MADV_FREE is not defined. Metall uses MADV_DONTNEED instead." #endif if (!os_madvise(addr, length, MADV_DONTNEED)) { - logger::perror(logger::level::info, __FILE__, __LINE__, - "madvise MADV_DONTNEED"); + METALL_ERRNO_INFO("madvise MADV_DONTNEED"); return false; } #endif @@ -308,8 +297,7 @@ inline bool uncommit_private_anonymous_pages(void *const addr, inline bool uncommit_private_nonanonymous_pages(void *const addr, const size_t length) { if (!os_madvise(addr, length, MADV_DONTNEED)) { - logger::perror(logger::level::info, __FILE__, __LINE__, - "madvise MADV_DONTNEED"); + METALL_ERRNO_INFO("madvise MADV_DONTNEED"); return false; } @@ -318,8 +306,7 @@ inline bool uncommit_private_nonanonymous_pages(void *const addr, inline bool uncommit_shared_pages(void *const addr, const size_t length) { if (!os_madvise(addr, length, MADV_DONTNEED)) { - logger::perror(logger::level::info, __FILE__, __LINE__, - "madvise MADV_DONTNEED"); + METALL_ERRNO_INFO("madvise MADV_DONTNEED"); return false; } return true; @@ -329,8 +316,7 @@ inline bool uncommit_shared_pages_and_free_file_space( [[maybe_unused]] void *const addr, [[maybe_unused]] const size_t length) { #ifdef MADV_REMOVE if (!os_madvise(addr, length, MADV_REMOVE)) { - logger::perror(logger::level::info, __FILE__, __LINE__, - "madvise MADV_REMOVE"); + METALL_ERRNO_INFO("madvise MADV_REMOVE"); return uncommit_shared_pages(addr, length); } return true; @@ -361,18 +347,12 @@ inline void *reserve_aligned_vm_region(const size_t alignment, } if (alignment % page_size != 0) { - std::stringstream ss; - ss << "alignment (" << alignment << ") is not a multiple of the page size (" - << ::sysconf(_SC_PAGE_SIZE) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("alignment ({}) is not a multiple of the page size ({})", alignment, ::sysconf(_SC_PAGE_SIZE)); return nullptr; } if (length % alignment != 0) { - std::stringstream ss; - ss << "length (" << length << ") is not a multiple of alignment (" - << ::sysconf(_SC_PAGE_SIZE) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("length ({}) is not a multiple of the alignment ({})", length, alignment); return nullptr; } @@ -413,9 +393,8 @@ class pagemap_reader { pagemap_reader() : m_fd(-1) { m_fd = ::open("/proc/self/pagemap", O_RDONLY); if (m_fd < 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot open /proc/self/pagemap\n"); - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); + METALL_ERROR("Cannot open /proc/self/pagemap"); + METALL_ERRNO_ERROR("open"); } } @@ -437,14 +416,13 @@ class pagemap_reader { uint64_t buf; if (::pread(m_fd, &buf, sizeof(buf), page_no * sizeof(uint64_t)) == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "pread"); + METALL_ERRNO_ERROR("pread"); return error_value; } if (buf & 0x1E00000000000000ULL) { // Sanity check; 57-60 bits are must be 0. - logger::out(logger::level::error, __FILE__, __LINE__, - "57-60 bits of the pagemap are not 0\n"); + METALL_ERROR("57-60 bits of the pagemap are not 0\n"); return error_value; } @@ -455,5 +433,5 @@ class pagemap_reader { int m_fd; }; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_MMAP_HPP \ No newline at end of file diff --git a/include/metall/detail/mutex.hpp b/libs/copperr/src/dice/copperr/detail/mutex.hpp similarity index 83% rename from include/metall/detail/mutex.hpp rename to libs/copperr/src/dice/copperr/detail/mutex.hpp index f00b8d09..cb7d96a0 100644 --- a/include/metall/detail/mutex.hpp +++ b/libs/copperr/src/dice/copperr/detail/mutex.hpp @@ -8,10 +8,10 @@ #include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { using mutex = std::mutex; using mutex_lock_guard = std::lock_guard; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_MUTEX_HPP diff --git a/include/metall/detail/named_proxy.hpp b/libs/copperr/src/dice/copperr/detail/named_proxy.hpp similarity index 88% rename from include/metall/detail/named_proxy.hpp rename to libs/copperr/src/dice/copperr/detail/named_proxy.hpp index 1b8acdbb..a6e2946b 100644 --- a/include/metall/detail/named_proxy.hpp +++ b/libs/copperr/src/dice/copperr/detail/named_proxy.hpp @@ -8,9 +8,9 @@ #include -/// \namespace metall::mtlldetail +/// \namespace dice::copperr::mtlldetail /// \brief Namespace for implementation details -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { /// \brief Proxy class that implements named allocation syntax. /// \tparam segment_manager segment manager to construct the object @@ -20,6 +20,6 @@ template using named_proxy = boost::interprocess::ipcdetail::named_proxy; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_UTILITY_DETAIL_NAMED_PROXY_HPP diff --git a/include/metall/detail/parameter_pack.hpp b/libs/copperr/src/dice/copperr/detail/parameter_pack.hpp similarity index 90% rename from include/metall/detail/parameter_pack.hpp rename to libs/copperr/src/dice/copperr/detail/parameter_pack.hpp index 5248f589..5ba3e8bb 100644 --- a/include/metall/detail/parameter_pack.hpp +++ b/libs/copperr/src/dice/copperr/detail/parameter_pack.hpp @@ -6,7 +6,7 @@ #ifndef METALL_DETAIL_UTILITY_PARAMETER_PACK_HPP #define METALL_DETAIL_UTILITY_PARAMETER_PACK_HPP -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { // ---------- get index ---------- // template @@ -24,5 +24,5 @@ struct get_index { static constexpr std::size_t value = get_index::value + 1; }; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_PARAMETER_PACK_HPP diff --git a/include/metall/detail/proc.hpp b/libs/copperr/src/dice/copperr/detail/proc.hpp similarity index 90% rename from include/metall/detail/proc.hpp rename to libs/copperr/src/dice/copperr/detail/proc.hpp index 3d46dd01..da645185 100644 --- a/include/metall/detail/proc.hpp +++ b/libs/copperr/src/dice/copperr/detail/proc.hpp @@ -8,6 +8,7 @@ #include +namespace dice::copperr::mtlldetail { #ifdef _GNU_SOURCE #include #define SUPPORT_GET_CPU_NO true @@ -17,8 +18,6 @@ #include -namespace metall::mtlldetail { - /// \brief Returns the number of the logical CPU core on which the calling /// thread is currently executing. inline unsigned int get_cpu_no() { @@ -43,11 +42,11 @@ inline unsigned int get_cpu_no() { /// \brief Returns the number of the logical CPU cores on the system. inline unsigned int get_num_cpus() { #if SUPPORT_GET_CPU_NO - return ::get_nprocs_conf(); + return get_nprocs_conf(); #else return std::thread::hardware_concurrency(); #endif } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_PROC_HPP diff --git a/include/metall/detail/ptree.hpp b/libs/copperr/src/dice/copperr/detail/ptree.hpp similarity index 68% rename from include/metall/detail/ptree.hpp rename to libs/copperr/src/dice/copperr/detail/ptree.hpp index e547fb7c..52db8b3c 100644 --- a/include/metall/detail/ptree.hpp +++ b/libs/copperr/src/dice/copperr/detail/ptree.hpp @@ -6,12 +6,14 @@ #ifndef METALL_DETAIL_UTILITY_PTREE_HPP #define METALL_DETAIL_UTILITY_PTREE_HPP +#include + #include #include -#include +#include -namespace metall::mtlldetail::ptree { +namespace dice::copperr::mtlldetail::ptree { namespace { namespace bptree = boost::property_tree; @@ -29,8 +31,7 @@ inline bool empty(const node_type &tree) { return tree.empty(); } inline std::size_t count(const node_type &tree, const std::string &key) { if (!validate_key(key)) { - std::string s("Invalid key: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Invalid key: {}", key); return 0; } return tree.count(key); @@ -40,15 +41,14 @@ template inline bool get_value(const node_type &tree, const std::string &key, value_type *const value) { if (!validate_key(key)) { - std::string s("Invalid key: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Invalid key: {}", key); return false; } try { *value = tree.get(key); } catch (const bptree::ptree_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); + METALL_ERROR("{}", e.what()); return false; } return true; @@ -57,8 +57,7 @@ inline bool get_value(const node_type &tree, const std::string &key, inline bool get_child(const node_type &tree, const std::string &key, node_type *out) { if (!validate_key(key)) { - std::string s("Invalid key: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Invalid key: {}", key); return false; } @@ -73,16 +72,14 @@ template inline bool add_value(const std::string &key, const value_type &value, node_type *tree) { if (!validate_key(key)) { - std::string s("Invalid key: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Invalid key: {}", key); return false; } try { tree->add(key, value); } catch (...) { - std::string s("Failed to add: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to add: {}", key); return false; } return true; @@ -91,16 +88,14 @@ inline bool add_value(const std::string &key, const value_type &value, inline bool add_child(const std::string &key, const node_type &child, node_type *tree) { if (!validate_key(key)) { - std::string s("Invalid key: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Invalid key: {}", key); return false; } try { tree->add_child(key, child); } catch (...) { - std::string s("Failed to add: " + key); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to add: {}", key); return false; } return true; @@ -110,8 +105,7 @@ inline bool push_back(const node_type &child, node_type *parent) { try { parent->push_back(std::make_pair("", child)); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to pushback an item"); + METALL_ERROR("Failed to pushback an item"); return false; } return true; @@ -121,17 +115,17 @@ inline bool read_json(const std::string &file_name, node_type *root) { try { bptree::read_json(file_name, *root); } catch (const bptree::json_parser_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); + METALL_ERROR("{}", e.what()); return false; } return true; } -inline bool write_json(const node_type &root, const std::string &file_name) { +inline bool write_json(const node_type &root, const std::filesystem::path &file_name) { try { bptree::write_json(file_name, root); } catch (const bptree::json_parser_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); + METALL_ERROR("{}", e.what()); return false; } return true; @@ -141,7 +135,7 @@ inline bool serialize(const node_type &root, std::string *const out_str) { try { bptree::write_json(*out_str, root); } catch (const bptree::json_parser_error &e) { - logger::out(logger::level::error, __FILE__, __LINE__, e.what()); + METALL_ERROR("{}", e.what()); return false; } return true; @@ -151,6 +145,6 @@ inline std::size_t erase(const std::string &key, node_type *tree) { return tree->erase(key); } -} // namespace metall::mtlldetail::ptree +} // namespace dice::copperr::mtlldetail::ptree #endif // METALL_DETAIL_UTILITY_PTREE_HPP diff --git a/include/metall/detail/soft_dirty_page.hpp b/libs/copperr/src/dice/copperr/detail/soft_dirty_page.hpp similarity index 73% rename from include/metall/detail/soft_dirty_page.hpp rename to libs/copperr/src/dice/copperr/detail/soft_dirty_page.hpp index d8274510..7a3a21da 100644 --- a/include/metall/detail/soft_dirty_page.hpp +++ b/libs/copperr/src/dice/copperr/detail/soft_dirty_page.hpp @@ -6,18 +6,18 @@ #ifndef METALL_DETAIL_UTILITY_SOFT_DIRTY_PAGE_HPP #define METALL_DETAIL_UTILITY_SOFT_DIRTY_PAGE_HPP +#include #include #include -#include -#include +#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { inline bool reset_soft_dirty_bit() { std::ofstream ofs("/proc/self/clear_refs"); if (!ofs.is_open()) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot open file clear_refs"); + METALL_ERROR("Cannot open file clear_refs"); return false; } @@ -25,8 +25,7 @@ inline bool reset_soft_dirty_bit() { ofs.close(); if (!ofs) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot write to /proc/self/clear_refs"); + METALL_ERROR("Cannot write to /proc/self/clear_refs"); return false; } @@ -45,6 +44,6 @@ inline constexpr bool check_present_page(const uint64_t pagemap_value) { return (pagemap_value >> 63ULL) & 1ULL; } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_SOFT_DIRTY_PAGE_HPP diff --git a/include/metall/detail/static_bitset.hpp b/libs/copperr/src/dice/copperr/detail/static_bitset.hpp similarity index 98% rename from include/metall/detail/static_bitset.hpp rename to libs/copperr/src/dice/copperr/detail/static_bitset.hpp index a367bba7..6a5f2825 100644 --- a/include/metall/detail/static_bitset.hpp +++ b/libs/copperr/src/dice/copperr/detail/static_bitset.hpp @@ -11,9 +11,9 @@ #include #include -#include +#include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { namespace bitset_detail { @@ -248,6 +248,6 @@ class static_bitset { internal_table_t m_table; } __attribute__((packed)); -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_STATIC_BITSET_HPP diff --git a/include/metall/detail/time.hpp b/libs/copperr/src/dice/copperr/detail/time.hpp similarity index 91% rename from include/metall/detail/time.hpp rename to libs/copperr/src/dice/copperr/detail/time.hpp index 48897dc7..9018eb8b 100644 --- a/include/metall/detail/time.hpp +++ b/libs/copperr/src/dice/copperr/detail/time.hpp @@ -8,7 +8,7 @@ #include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { inline std::chrono::high_resolution_clock::time_point elapsed_time_sec() { return std::chrono::high_resolution_clock::now(); @@ -24,5 +24,5 @@ inline double elapsed_time_sec( 1e6; } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_TIME_HPP diff --git a/include/metall/detail/utilities.hpp b/libs/copperr/src/dice/copperr/detail/utilities.hpp similarity index 97% rename from include/metall/detail/utilities.hpp rename to libs/copperr/src/dice/copperr/detail/utilities.hpp index ca9b2400..dc4c05a4 100644 --- a/include/metall/detail/utilities.hpp +++ b/libs/copperr/src/dice/copperr/detail/utilities.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #ifndef METALL_PRAGMA_IGNORE_GCC_UNINIT_WARNING_BEGIN #if defined(__GNUC__) and !defined(__clang__) @@ -33,7 +33,7 @@ #endif #endif -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { /// \brief Computes the next power of 2 /// \param n Input value @@ -148,5 +148,5 @@ inline std::pair partial_range( return std::make_pair(begin_index, begin_index + partial_length); } -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_COMMON_HPP diff --git a/include/metall/detail/uuid.hpp b/libs/copperr/src/dice/copperr/detail/uuid.hpp similarity index 86% rename from include/metall/detail/uuid.hpp rename to libs/copperr/src/dice/copperr/detail/uuid.hpp index c8c4ec99..e4bbed7c 100644 --- a/include/metall/detail/uuid.hpp +++ b/libs/copperr/src/dice/copperr/detail/uuid.hpp @@ -10,11 +10,11 @@ #include #include -namespace metall::mtlldetail { +namespace dice::copperr::mtlldetail { using uuid = boost::uuids::uuid; using uuid_random_generator = boost::uuids::random_generator; -} // namespace metall::mtlldetail +} // namespace dice::copperr::mtlldetail #endif // METALL_DETAIL_UTILITY_UUID_HPP \ No newline at end of file diff --git a/include/metall/json/array.hpp b/libs/copperr/src/dice/copperr/json/array.hpp similarity index 96% rename from include/metall/json/array.hpp rename to libs/copperr/src/dice/copperr/json/array.hpp index 6f398ef6..889309eb 100644 --- a/include/metall/json/array.hpp +++ b/libs/copperr/src/dice/copperr/json/array.hpp @@ -10,14 +10,14 @@ #include #include -#include -#include -#include +#include +#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; } namespace jsndtl { @@ -195,6 +195,6 @@ inline void swap(array &lhd, lhd.swap(rhd); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_ARRAY_HPP diff --git a/include/metall/json/details/compact_object.hpp b/libs/copperr/src/dice/copperr/json/details/compact_object.hpp similarity index 96% rename from include/metall/json/details/compact_object.hpp rename to libs/copperr/src/dice/copperr/json/details/compact_object.hpp index 0844051b..6e2db64c 100644 --- a/include/metall/json/details/compact_object.hpp +++ b/libs/copperr/src/dice/copperr/json/details/compact_object.hpp @@ -12,15 +12,15 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace metall::json::jsndtl { +namespace dice::copperr::json::jsndtl { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; } // Forward declarations @@ -275,6 +275,6 @@ inline bool general_compact_object_equal( return true; } -} // namespace metall::json::jsndtl +} // namespace dice::copperr::json::jsndtl #endif // METALL_JSON_DETAILS_COMPACT_OBJECT_HPP diff --git a/include/metall/json/details/indexed_object.hpp b/libs/copperr/src/dice/copperr/json/details/indexed_object.hpp similarity index 95% rename from include/metall/json/details/indexed_object.hpp rename to libs/copperr/src/dice/copperr/json/details/indexed_object.hpp index 77863bbf..34eb27bf 100644 --- a/include/metall/json/details/indexed_object.hpp +++ b/libs/copperr/src/dice/copperr/json/details/indexed_object.hpp @@ -12,16 +12,16 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -namespace metall::container::experimental::json::jsndtl { +namespace dice::copperr::container::experimental::json::jsndtl { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; } // Foward declarations @@ -64,7 +64,7 @@ class indexed_object { using index_table_type = mc::unordered_multimap, + dice::copperr::utility::hash, std::equal_to<>, index_table_allocator_type>; public: @@ -256,7 +256,7 @@ class indexed_object { } static auto hash_key(const key_type &key) { - return metall::mtlldetail::MurmurHash64A(key.data(), key.length(), 123); + return dice::copperr::mtlldetail::MurmurHash64A(key.data(), key.length(), 123); } auto priv_erase(const_iterator value_position) { @@ -317,6 +317,6 @@ inline bool general_indexed_object_equal( return true; } -} // namespace metall::container::experimental::json::jsndtl +} // namespace dice::copperr::container::experimental::json::jsndtl #endif // METALL_CONTAINER_EXPERIMENT_JSON_DETAILS_INDEXED_OBJECT_HPP diff --git a/include/metall/json/equal.hpp b/libs/copperr/src/dice/copperr/json/equal.hpp similarity index 97% rename from include/metall/json/equal.hpp rename to libs/copperr/src/dice/copperr/json/equal.hpp index 4da5a7e1..3321bc4d 100644 --- a/include/metall/json/equal.hpp +++ b/libs/copperr/src/dice/copperr/json/equal.hpp @@ -6,9 +6,9 @@ #ifndef METALL_JSON_EQUAL_HPP #define METALL_JSON_EQUAL_HPP -#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace { namespace bj = boost::json; @@ -137,5 +137,5 @@ inline bool operator!=(const bj::string &bj_string, const basic_string &string) { return string != bj_string; } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_EQUAL_HPP diff --git a/libs/copperr/src/dice/copperr/json/json.hpp b/libs/copperr/src/dice/copperr/json/json.hpp new file mode 100644 index 00000000..e762235b --- /dev/null +++ b/libs/copperr/src/dice/copperr/json/json.hpp @@ -0,0 +1,29 @@ +// Copyright 2021 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#ifndef METALL_JSON_JSON_HPP +#define METALL_JSON_JSON_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/// \example json_create.cpp +/// This is an example of how to create a JSON object with Metall. + +/// \example json_open.cpp +/// This is an example of how to open an already created JSON object. + +#endif // METALL_JSON_JSON_HPP diff --git a/include/metall/json/json_fwd.hpp b/libs/copperr/src/dice/copperr/json/json_fwd.hpp similarity index 96% rename from include/metall/json/json_fwd.hpp rename to libs/copperr/src/dice/copperr/json/json_fwd.hpp index 5e740f90..83325667 100644 --- a/include/metall/json/json_fwd.hpp +++ b/libs/copperr/src/dice/copperr/json/json_fwd.hpp @@ -29,29 +29,29 @@ #endif // METALL_BOOST_JSON_SRC_INCLUDED #endif // METALL_LINK_WITH_BOOST_JSON -#include +#include -/// \namespace metall::json +/// \namespace dice::copperr::json /// \brief Namespace for Metall JSON container, which is in an experimental /// phase. -namespace metall::json { +namespace dice::copperr::json { /// \brief JSON null type. using null_type = std::monostate; /// \brief JSON basic string type. template using basic_string = - metall::container::basic_string; + dice::copperr::container::basic_string; /// \brief JSON string. template > using string = basic_string, allocator_type>; -} // namespace metall::json +} // namespace dice::copperr::json // Forward declaration #if !defined(DOXYGEN_SKIP) -namespace metall::json { +namespace dice::copperr::json { template > class value; @@ -214,6 +214,6 @@ bool general_key_value_pair_equal( #endif // DOXYGEN_SKIP -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_JSON_FWD_HPP diff --git a/include/metall/json/key_value_pair.hpp b/libs/copperr/src/dice/copperr/json/key_value_pair.hpp similarity index 96% rename from include/metall/json/key_value_pair.hpp rename to libs/copperr/src/dice/copperr/json/key_value_pair.hpp index 5fb0ee56..11d427f0 100644 --- a/include/metall/json/key_value_pair.hpp +++ b/libs/copperr/src/dice/copperr/json/key_value_pair.hpp @@ -12,11 +12,11 @@ #include #include -#include -#include -#include +#include +#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace jsndtl { /// \brief Provides 'equal' calculation for other key-value types that have the @@ -56,7 +56,7 @@ class key_value_pair { using char_traits = _char_traits; using allocator_type = Alloc; using key_type = std::basic_string_view; - using value_type = metall::json::value; + using value_type = dice::copperr::json::value; using size_type = std::size_t; public: @@ -242,7 +242,7 @@ class key_value_pair { if (priv_short_key()) { return m_short_key; } - return metall::to_raw_pointer(m_long_key); + return dice::copperr::to_raw_pointer(m_long_key); } bool priv_short_key() const noexcept { @@ -268,7 +268,7 @@ class key_value_pair { return false; } - std::char_traits::copy(metall::to_raw_pointer(m_long_key), key, + std::char_traits::copy(dice::copperr::to_raw_pointer(m_long_key), key, m_key_length); std::char_traits::assign(m_long_key[m_key_length], '\0'); } @@ -308,6 +308,6 @@ inline void swap( lhd.swap(rhd); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_KEY_VALUE_PAIR_HPP \ No newline at end of file diff --git a/include/metall/json/object.hpp b/libs/copperr/src/dice/copperr/json/object.hpp similarity index 88% rename from include/metall/json/object.hpp rename to libs/copperr/src/dice/copperr/json/object.hpp index d3776a32..ce967aee 100644 --- a/include/metall/json/object.hpp +++ b/libs/copperr/src/dice/copperr/json/object.hpp @@ -6,10 +6,10 @@ #ifndef METALL_OBJECT_HPP #define METALL_OBJECT_HPP -#include -#include +#include +#include -namespace metall::json { +namespace dice::copperr::json { /// \brief JSON object. /// An object is a table key and value pairs. @@ -43,6 +43,6 @@ inline bool general_object_equal( } // namespace jsndtl -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_OBJECT_HPP diff --git a/include/metall/json/parse.hpp b/libs/copperr/src/dice/copperr/json/parse.hpp similarity index 87% rename from include/metall/json/parse.hpp rename to libs/copperr/src/dice/copperr/json/parse.hpp index 9bf45ab6..59f51ecc 100644 --- a/include/metall/json/parse.hpp +++ b/libs/copperr/src/dice/copperr/json/parse.hpp @@ -10,9 +10,9 @@ #include #include -#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace { namespace bj = boost::json; @@ -41,9 +41,9 @@ inline value parse(std::string_view input_json_string, return value{allocator}; } - return metall::json::value_from(std::move(bj_value), allocator); + return dice::copperr::json::value_from(std::move(bj_value), allocator); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_PARSE_HPP diff --git a/include/metall/json/pretty_print.hpp b/libs/copperr/src/dice/copperr/json/pretty_print.hpp similarity index 92% rename from include/metall/json/pretty_print.hpp rename to libs/copperr/src/dice/copperr/json/pretty_print.hpp index d57275f2..d6acc929 100644 --- a/include/metall/json/pretty_print.hpp +++ b/libs/copperr/src/dice/copperr/json/pretty_print.hpp @@ -8,9 +8,9 @@ #include -#include +#include -namespace metall::json::jsndtl { +namespace dice::copperr::json::jsndtl { template inline void pretty_print_impl(std::ostream &os, const value &jv, const std::string &indent) { @@ -58,9 +58,9 @@ inline void pretty_print_impl(std::ostream &os, const value &jv, } } -} // namespace metall::json::jsndtl +} // namespace dice::copperr::json::jsndtl -namespace metall::json { +namespace dice::copperr::json { /// \brief Pretty-prints a JSON value. /// \tparam allocator_type An allocator type used in the value. @@ -80,6 +80,6 @@ inline void pretty_print(std::ostream &os, os << std::endl; } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_PRETTY_PRINT_HPP diff --git a/include/metall/json/serialize.hpp b/libs/copperr/src/dice/copperr/json/serialize.hpp similarity index 89% rename from include/metall/json/serialize.hpp rename to libs/copperr/src/dice/copperr/json/serialize.hpp index 5ef4e857..b7bc150d 100644 --- a/include/metall/json/serialize.hpp +++ b/libs/copperr/src/dice/copperr/json/serialize.hpp @@ -8,13 +8,13 @@ #include -#include -#include +#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; namespace bj = boost::json; } // namespace @@ -65,6 +65,6 @@ std::ostream &operator<<(std::ostream &os, const array &arr) { return os; } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_SERIALIZE_HPP diff --git a/include/metall/json/string.hpp b/libs/copperr/src/dice/copperr/json/string.hpp similarity index 83% rename from include/metall/json/string.hpp rename to libs/copperr/src/dice/copperr/json/string.hpp index e1469c3e..7f4a605c 100644 --- a/include/metall/json/string.hpp +++ b/libs/copperr/src/dice/copperr/json/string.hpp @@ -8,9 +8,9 @@ #include -#include +#include -namespace metall::json::jsndtl { +namespace dice::copperr::json::jsndtl { template @@ -20,6 +20,6 @@ inline bool general_string_equal( return std::strcmp(string.c_str(), other_string.c_str()) == 0; } -} // namespace metall::json::jsndtl +} // namespace dice::copperr::json::jsndtl #endif // METALL_JSON_STRING_HPP diff --git a/include/metall/json/value.hpp b/libs/copperr/src/dice/copperr/json/value.hpp similarity index 99% rename from include/metall/json/value.hpp rename to libs/copperr/src/dice/copperr/json/value.hpp index 0aef7388..19e64500 100644 --- a/include/metall/json/value.hpp +++ b/libs/copperr/src/dice/copperr/json/value.hpp @@ -12,12 +12,12 @@ #include #include -#include +#include -namespace metall::json { +namespace dice::copperr::json { namespace { -namespace mc = metall::container; +namespace mc = dice::copperr::container; } namespace jsndtl { @@ -541,6 +541,6 @@ inline void swap(value &lhd, lhd.swap(rhd); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_VALUE_HPP diff --git a/include/metall/json/value_from.hpp b/libs/copperr/src/dice/copperr/json/value_from.hpp similarity index 93% rename from include/metall/json/value_from.hpp rename to libs/copperr/src/dice/copperr/json/value_from.hpp index 6652830f..be1baf3e 100644 --- a/include/metall/json/value_from.hpp +++ b/libs/copperr/src/dice/copperr/json/value_from.hpp @@ -6,9 +6,9 @@ #ifndef METALL_JSON_VALUE_FROM_HPP #define METALL_JSON_VALUE_FROM_HPP -#include +#include -namespace metall::json::jsndtl { +namespace dice::copperr::json::jsndtl { namespace { namespace bj = boost::json; @@ -56,9 +56,9 @@ inline value value_from_impl( return value_from_impl(tmp_input_bj_value, allocator); } -} // namespace metall::json::jsndtl +} // namespace dice::copperr::json::jsndtl -namespace metall::json { +namespace dice::copperr::json { /// \brief Convert an input data and construct a JSON value. /// \tparam T The type of an input data. @@ -79,6 +79,6 @@ inline value value_from(T &&input_data, return jsndtl::value_from_impl(std::forward(input_data), allocator); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALL_JSON_VALUE_FROM_HPP diff --git a/include/metall/json/value_to.hpp b/libs/copperr/src/dice/copperr/json/value_to.hpp similarity index 89% rename from include/metall/json/value_to.hpp rename to libs/copperr/src/dice/copperr/json/value_to.hpp index 110f6441..3b5aef05 100644 --- a/include/metall/json/value_to.hpp +++ b/libs/copperr/src/dice/copperr/json/value_to.hpp @@ -6,12 +6,12 @@ #ifndef METALLAL_JSON_VALUE_TO_HPP #define METALLAL_JSON_VALUE_TO_HPP -#include +#include -namespace metall::json::jsndtl { +namespace dice::copperr::json::jsndtl { namespace { -namespace mj = metall::json; +namespace mj = dice::copperr::json; namespace bj = boost::json; } // namespace @@ -55,12 +55,12 @@ inline bj::value value_to_impl(const mj::value &input_value) { return out_value; } -} // namespace metall::json::jsndtl +} // namespace dice::copperr::json::jsndtl -namespace metall::json { +namespace dice::copperr::json { namespace { -namespace mj = metall::json; +namespace mj = dice::copperr::json; } /// \brief Convert a JSON value to another data type. @@ -73,6 +73,6 @@ T value_to(const mj::value &value) { return jsndtl::value_to_impl(value); } -} // namespace metall::json +} // namespace dice::copperr::json #endif // METALLAL_JSON_VALUE_TO_HPP diff --git a/include/metall/kernel/attributed_object_directory.hpp b/libs/copperr/src/dice/copperr/kernel/attributed_object_directory.hpp similarity index 90% rename from include/metall/kernel/attributed_object_directory.hpp rename to libs/copperr/src/dice/copperr/kernel/attributed_object_directory.hpp index 3d85d5b4..bf34022f 100644 --- a/include/metall/kernel/attributed_object_directory.hpp +++ b/libs/copperr/src/dice/copperr/kernel/attributed_object_directory.hpp @@ -20,16 +20,16 @@ #include #include -#include -#include -#include +#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; -namespace json = metall::mtlldetail::ptree; +namespace mdtl = dice::copperr::mtlldetail; +namespace json = dice::copperr::mtlldetail::ptree; } // namespace template @@ -191,8 +191,7 @@ class attributed_object_directory { assert(ret.second); } } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when inserting entry"); + METALL_ERROR("Exception was thrown when inserting entry"); return false; } @@ -348,8 +347,7 @@ class attributed_object_directory { m_name_index_table->erase(position->name()); m_entry_table->erase(position); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when erasing an entry"); + METALL_ERROR("Exception was thrown when erasing an entry"); return 0; } @@ -374,8 +372,7 @@ class attributed_object_directory { m_entry_table->erase(itr); if (!name.empty()) m_name_index_table->erase(name); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when erasing an entry"); + METALL_ERROR("Exception was thrown when erasing an entry"); return 0; } @@ -400,8 +397,7 @@ class attributed_object_directory { if (!itr->name().empty()) m_name_index_table->erase(itr->name()); m_entry_table->erase(itr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when erasing an entry"); + METALL_ERROR("Exception was thrown when erasing an entry"); return 0; } @@ -420,8 +416,7 @@ class attributed_object_directory { m_name_index_table->clear(); m_entry_table->clear(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when clearing entries"); + METALL_ERROR("Exception was thrown when clearing entries"); return false; } return true; @@ -429,7 +424,7 @@ class attributed_object_directory { /// \brief /// \param path - bool serialize(const char *const path) const noexcept { + bool serialize(const std::filesystem::path &path) const noexcept { try { return priv_serialize_throw(path); } catch (...) { @@ -440,7 +435,7 @@ class attributed_object_directory { /// \brief /// \param path - bool deserialize(const char *const path) noexcept { + bool deserialize(const std::filesystem::path &path) noexcept { try { return priv_deserialize_throw(path); } catch (...) { @@ -481,8 +476,7 @@ class attributed_object_directory { m_offset_index_table = std::make_unique(); m_name_index_table = std::make_unique(); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to allocate core data"); + METALL_ERROR("Failed to allocate core data"); m_entry_table.reset(nullptr); m_offset_index_table.reset(nullptr); m_name_index_table.reset(nullptr); @@ -497,8 +491,7 @@ class attributed_object_directory { *m_offset_index_table = *(other.m_offset_index_table); *m_name_index_table = *(other.m_name_index_table); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to copy members"); + METALL_ERROR("Failed to copy members"); m_entry_table.reset(nullptr); m_offset_index_table.reset(nullptr); m_name_index_table.reset(nullptr); @@ -507,7 +500,7 @@ class attributed_object_directory { return true; } - bool priv_serialize_throw(const char *const path) const { + bool priv_serialize_throw(const std::filesystem::path &path) const { if (!good()) { return false; } @@ -546,7 +539,7 @@ class attributed_object_directory { return true; } - bool priv_deserialize_throw(const char *const path) { + bool priv_deserialize_throw(const std::filesystem::path &path) { if (!good()) { return false; } @@ -579,14 +572,12 @@ class attributed_object_directory { } if (count(name) > 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to reconstruct object table"); + METALL_ERROR("Failed to reconstruct object table"); return false; } if (!insert(name, offset, length, type_id, description)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to reconstruct object table"); + METALL_ERROR("Failed to reconstruct object table"); return false; } } @@ -602,5 +593,5 @@ class attributed_object_directory { std::unique_ptr m_name_index_table; }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_ATTRIBUTED_OBJECT_DIRECTORY_HPP diff --git a/include/metall/kernel/bin_directory.hpp b/libs/copperr/src/dice/copperr/kernel/bin_directory.hpp similarity index 86% rename from include/metall/kernel/bin_directory.hpp rename to libs/copperr/src/dice/copperr/kernel/bin_directory.hpp index e3b8bb29..340175ab 100644 --- a/include/metall/kernel/bin_directory.hpp +++ b/libs/copperr/src/dice/copperr/kernel/bin_directory.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -24,14 +25,14 @@ #include #endif -#include -#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } /// \brief A simple key-value store designed to store values related to memory @@ -195,12 +196,10 @@ class bin_directory { /// \brief /// \param path - bool serialize(const char *path) const { + bool serialize(const std::filesystem::path &path) const { std::ofstream ofs(path); if (!ofs.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot open: {}", path.c_str()); return false; } @@ -209,10 +208,7 @@ class bin_directory { ofs << static_cast(i) << " " << static_cast(value) << "\n"; if (!ofs) { - std::stringstream ss; - ss << "Something happened in the ofstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Something happened in the ofstream: {}", path.c_str()); return false; } } @@ -224,12 +220,10 @@ class bin_directory { /// \brief /// \param path - bool deserialize(const char *path) { + bool deserialize(const std::filesystem::path &path) { std::ifstream ifs(path); if (!ifs.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot open: {}", path.c_str()); return false; } @@ -240,9 +234,7 @@ class bin_directory { const auto value = static_cast(buf2); if (m_table.size() <= bin_no) { - std::stringstream ss; - ss << "Too large bin number is found: " << bin_no; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Too large bin number was found: {}", bin_no); return false; } #ifdef METALL_USE_SORTED_BIN @@ -253,9 +245,7 @@ class bin_directory { } if (!ifs.eof()) { - std::stringstream ss; - ss << "Something happened in the ifstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Something happened in the ifstream: {}", path.c_str()); return false; } @@ -280,6 +270,6 @@ class bin_directory { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_BIN_DIRECTORY_HPP diff --git a/include/metall/kernel/bin_number_manager.hpp b/libs/copperr/src/dice/copperr/kernel/bin_number_manager.hpp similarity index 92% rename from include/metall/kernel/bin_number_manager.hpp rename to libs/copperr/src/dice/copperr/kernel/bin_number_manager.hpp index 5664fd81..69611b6e 100644 --- a/include/metall/kernel/bin_number_manager.hpp +++ b/libs/copperr/src/dice/copperr/kernel/bin_number_manager.hpp @@ -9,10 +9,10 @@ #include #include -#include -#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { /// \brief Bin number manager @@ -59,5 +59,5 @@ class bin_number_manager { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_KERNEL_BIN_NUMBER_MANAGER_HPP diff --git a/include/metall/kernel/chunk_directory.hpp b/libs/copperr/src/dice/copperr/kernel/chunk_directory.hpp similarity index 84% rename from include/metall/kernel/chunk_directory.hpp rename to libs/copperr/src/dice/copperr/kernel/chunk_directory.hpp index d5174232..476846bb 100644 --- a/include/metall/kernel/chunk_directory.hpp +++ b/libs/copperr/src/dice/copperr/kernel/chunk_directory.hpp @@ -8,21 +8,22 @@ #include #include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } /// \brief Chunk directory class. @@ -294,12 +295,10 @@ class chunk_directory { /// \brief /// \param path - bool serialize(const char *path) const { + bool serialize(const std::filesystem::path &path) const { std::ofstream ofs(path); if (!ofs.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot open: {}", path.c_str()); return false; } @@ -312,9 +311,7 @@ class chunk_directory { << static_cast(m_table[chunk_no].bin_no) << " " << static_cast(m_table[chunk_no].type); if (!ofs) { - std::stringstream ss; - ss << "Something happened in the ofstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Something happened in the ofstream: {}", path.c_str()); return false; } @@ -325,10 +322,7 @@ class chunk_directory { << " " << m_table[chunk_no].slot_occupancy.serialize(num_slots) << "\n"; if (!ofs) { - std::stringstream ss; - ss << "Something happened in the ofstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Something happened in the ofstream: {}", path.c_str()); return false; } @@ -336,16 +330,12 @@ class chunk_directory { m_table[chunk_no].type == chunk_type::large_chunk_body) { ofs << "\n"; if (!ofs) { - std::stringstream ss; - ss << "Something happened in the ofstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Something happened in the ofstream: {}", path.c_str()); return false; } } else { - logger::out(logger::level::error, __FILE__, __LINE__, - "Unexpected chunk status"); + METALL_ERROR("Unexpected chunk status"); return false; } } @@ -358,12 +348,10 @@ class chunk_directory { /// \brief /// \param path /// \return - bool deserialize(const char *path) { + bool deserialize(const std::filesystem::path &path) { std::ifstream ifs(path); if (!ifs.is_open()) { - std::stringstream ss; - ss << "Cannot open: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot open: {}", path.c_str()); return false; } @@ -387,8 +375,7 @@ class chunk_directory { chunk_type::large_chunk_body)) { m_table[chunk_no].type = chunk_type::large_chunk_body; } else { - logger::out(logger::level::error, __FILE__, __LINE__, - "Invalid chunk type"); + METALL_ERROR("Invalid chunk type"); return false; } @@ -397,16 +384,11 @@ class chunk_directory { calc_num_slots(bin_no_mngr::to_object_size(bin_no)); if (!(ifs >> buf1)) { std::stringstream ss; - ss << "Cannot read a file: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Cannot read a file: {}", path.c_str()); return false; } if (num_slots < buf1) { - std::stringstream ss; - ss << "Invalid num_occupied_slots: " << std::to_string(buf1); - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Invalid num_occupied_slots: {}", buf1); return false; } m_table[chunk_no].num_occupied_slots = buf1; @@ -414,37 +396,28 @@ class chunk_directory { std::string bitset_buf; std::getline(ifs, bitset_buf); if (bitset_buf.empty() || bitset_buf[0] != ' ') { - std::stringstream ss; - ss << "Invalid input for slot_occupancy: " << bitset_buf; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Invalid input for slot_occupancy: {}", bitset_buf); return false; } bitset_buf.erase(0, 1); if (!m_table[chunk_no].slot_occupancy.allocate(num_slots)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to allocate slot occupancy data"); + METALL_ERROR("Failed to allocate slot occupancy data"); return false; } if (!m_table[chunk_no].slot_occupancy.deserialize(num_slots, bitset_buf)) { - std::stringstream ss; - ss << "Invalid input for slot_occupancy: " << bitset_buf; - logger::out(logger::level::error, __FILE__, __LINE__, - ss.str().c_str()); + METALL_ERROR("Invalid input for slot_occupancy: {}", bitset_buf); return false; } } - m_last_used_chunk_no = std::max((ssize_t)chunk_no, m_last_used_chunk_no); + m_last_used_chunk_no = std::max(static_cast(chunk_no), m_last_used_chunk_no); } if (!ifs.eof()) { - std::stringstream ss; - ss << "Something happened in the ifstream: " << path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Something happened in the ifstream: {}", path.c_str()); return false; } @@ -514,8 +487,7 @@ class chunk_directory { nullptr, m_max_num_chunks * sizeof(entry_type))); if (!m_table) { - logger::perror(logger::level::error, __FILE__, __LINE__, - "Cannot allocate chunk table"); + METALL_ERRNO_ERROR("Cannot allocate chunk table"); return false; } @@ -528,8 +500,7 @@ class chunk_directory { try { erase(chunk_no); } catch (...) { - logger::perror(logger::level::error, __FILE__, __LINE__, - "An exception was thrown"); + METALL_ERRNO_ERROR("An exception was thrown"); } } mdtl::os_munmap(m_table, m_max_num_chunks * sizeof(entry_type)); @@ -546,8 +517,7 @@ class chunk_directory { calc_num_slots(bin_no_mngr::to_object_size(bin_no)); assert(num_slots > 1); if (num_slots > multilayer_bitset_type::max_size()) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Too many slots are requested."); + METALL_ERROR("Too many slots are requested."); return m_max_num_chunks; } @@ -559,19 +529,17 @@ class chunk_directory { m_table[chunk_no].type = chunk_type::small_chunk; m_table[chunk_no].num_occupied_slots = 0; if (!m_table[chunk_no].slot_occupancy.allocate(num_slots)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to allocates slot occupancy data"); + METALL_ERROR("Failed to allocates slot occupancy data"); return m_max_num_chunks; } m_last_used_chunk_no = - std::max((ssize_t)chunk_no, m_last_used_chunk_no); + std::max(static_cast(chunk_no), m_last_used_chunk_no); return chunk_no; } } - logger::out(logger::level::error, __FILE__, __LINE__, - "No empty chunk for small allocation"); + METALL_ERROR("No empty chunk for small allocation"); return m_max_num_chunks; } @@ -608,15 +576,13 @@ class chunk_directory { } m_last_used_chunk_no = - std::max((ssize_t)chunk_no, m_last_used_chunk_no); + std::max(static_cast(chunk_no), m_last_used_chunk_no); return top_chunk_no; } } - logger::out(logger::level::error, __FILE__, __LINE__, - "No available space for large allocation, which requires " - "multiple contiguous chunks"); + METALL_ERROR("No available space for large allocation, which requires multiple contiguous chunks"); return m_max_num_chunks; } @@ -641,6 +607,6 @@ class chunk_directory { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_CHUNK_DIRECTORY_HPP diff --git a/include/metall/kernel/manager_kernel.hpp b/libs/copperr/src/dice/copperr/kernel/manager_kernel.hpp similarity index 83% rename from include/metall/kernel/manager_kernel.hpp rename to libs/copperr/src/dice/copperr/kernel/manager_kernel.hpp index c7eb3614..02b606ec 100644 --- a/include/metall/kernel/manager_kernel.hpp +++ b/libs/copperr/src/dice/copperr/kernel/manager_kernel.hpp @@ -19,41 +19,42 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef METALL_USE_UMAP -#include +#include #else -#include +#include #endif #ifndef METALL_DISABLE_CONCURRENCY #define METALL_ENABLE_MUTEX_IN_MANAGER_KERNEL #endif #ifdef METALL_ENABLE_MUTEX_IN_MANAGER_KERNEL -#include +#include #endif -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } template @@ -79,7 +80,7 @@ class manager_kernel { // Private types and static values // -------------------- // using self_type = manager_kernel<_chunk_no_type, _chunk_size>; - static constexpr const char *k_datastore_top_dir_name = "metall_datastore"; + static constexpr const char *k_datastore_top_dir_name = "copperr_datastore"; static constexpr const char *k_datastore_management_dir_name = "management"; static constexpr const char *k_datastore_segment_dir_name = "segment"; @@ -195,7 +196,7 @@ class manager_kernel { /// \param base_dir_path /// \param vm_reserve_size /// \return Returns true if success; otherwise, returns false - bool create(const char *base_dir_path, + bool create(const std::filesystem::path &base_dir_path, size_type vm_reserve_size = k_default_vm_reserve_size); /// \brief Opens an existing datastore @@ -203,14 +204,14 @@ class manager_kernel { /// \param base_dir_path /// \param vm_reserve_size /// \return Returns true if success; otherwise, returns false - bool open(const char *base_dir_path, + bool open(const std::filesystem::path &base_dir_path, size_type vm_reserve_size = k_default_vm_reserve_size); /// \brief Opens an existing datastore with read only /// Expect to be called by a single thread /// \param base_dir_path /// \return Returns true if success; otherwise, returns false - bool open_read_only(const char *base_dir_path); + bool open_read_only(const std::filesystem::path &base_dir_path); /// \brief Expect to be called by a single thread void close(); @@ -368,53 +369,49 @@ class manager_kernel { /// \brief Takes a snapshot. The snapshot has a different UUID. /// \param destination_dir_path Destination path - /// \param clone Use clone (reflink) to copy data. /// \param num_max_copy_threads The maximum number of copy threads to use. /// If <= 0 is given, the value is automatically determined. /// \return If succeeded, returns True; other false - bool snapshot(const char *destination_dir_path, const bool clone, + bool snapshot(const std::filesystem::path &destination_dir_path, const int num_max_copy_threads); /// \brief Copies a data store synchronously, keeping the same UUID. /// \param source_dir_path Source path. /// \param destination_dir_path Destination path. - /// \param clone Use clone (reflink) to copy data. /// \param num_max_copy_threads The maximum number of copy threads to use. /// If <= 0 is given, the value is automatically determined. /// \return If succeeded, returns True; other false. - static bool copy(const char *source_dir_path, - const char *destination_dir_path, const bool clone, + static bool copy(const std::filesystem::path &source_dir_path, + const std::filesystem::path &destination_dir_path, const int num_max_copy_threads); /// \brief Copies a data store asynchronously, keeping the same UUID. /// \param source_dir_path Source path. /// \param destination_dir_path Destination path. - /// \param clone Use clone (reflink) to copy data. /// \param num_max_copy_threads The maximum number of copy threads to use. /// If <= 0 is given, the value is automatically determined. /// \return Returns an object of std::future. /// If succeeded, its get() returns True; other false. - static std::future copy_async(const char *source_dir_path, - const char *destination_dir_path, - const bool clone, + static std::future copy_async(const std::filesystem::path &source_dir_path, + const std::filesystem::path &destination_dir_path, const int num_max_copy_threads); /// \brief Remove a data store synchronously /// \param base_dir_path /// \return If succeeded, returns True; other false - static bool remove(const char *base_dir_path); + static bool remove(const std::filesystem::path &base_dir_path); /// \brief Remove a data store asynchronously /// \param base_dir_path /// \return Returns an object of std::future /// If succeeded, its get() returns True; other false - static std::future remove_async(const char *base_dir_path); + static std::future remove_async(const std::filesystem::path &base_dir_path); /// \brief Check if the backing data store is consistent, /// i.e. it was closed properly. /// \param dir_path /// \return Return true if it is consistent; otherwise, returns false. - static bool consistent(const char *dir_path); + static bool consistent(const std::filesystem::path &dir_path); /// \brief Returns the UUID of the backing data store. /// \return Returns UUID in std::string; returns an empty string on error. @@ -423,7 +420,7 @@ class manager_kernel { /// \brief Returns the UUID of the backing data store. /// \param dir_path Path to a data store. /// \return Returns UUID in std::string; returns an empty string on error. - static std::string get_uuid(const char *dir_path); + static std::string get_uuid(const std::filesystem::path &dir_path); /// \brief Gets the version number of the backing data store. /// \return Returns a version number; returns 0 on error. @@ -432,7 +429,7 @@ class manager_kernel { /// \brief Gets the version number of the backing data store. /// \param dir_path Path to a data store. /// \return Returns a version number; returns 0 on error. - static version_type get_version(const char *dir_path); + static version_type get_version(const std::filesystem::path &dir_path); /// \brief Gets a description from a file. /// \param description A pointer to a string buffer. @@ -443,7 +440,7 @@ class manager_kernel { /// \param base_dir_path Path to a data store. /// \param description A pointer to a string buffer. /// \return Returns false on error. - static bool get_description(const std::string &base_dir_path, + static bool get_description(const std::filesystem::path &base_dir_path, std::string *description); /// \brief Sets a description to a file. @@ -455,26 +452,26 @@ class manager_kernel { /// \param base_dir_path Path to a data store. /// \param description A description to write. /// \return Returns false on error. - static bool set_description(const std::string &base_dir_path, + static bool set_description(const std::filesystem::path &base_dir_path, const std::string &description); /// \brief Returns an instance that provides access to the attribute of named /// objects. \param base_dir_path Path to a data store. \return Returns an /// instance of named_object_attr_accessor_type. static named_object_attr_accessor_type access_named_object_attribute( - const std::string &base_dir_path); + const std::filesystem::path &base_dir_path); /// \brief Returns an instance that provides access to the attribute of unique /// object. \param base_dir_path Path to a data store. \return Returns an /// instance of unique_object_attr_accessor_type. static unique_object_attr_accessor_type access_unique_object_attribute( - const std::string &base_dir_path); + const std::filesystem::path &base_dir_path); /// \brief Returns an instance that provides access to the attribute of /// anonymous object. \param base_dir_path Path to a data store. \return /// Returns an instance of anonymous_object_attr_accessor_type. static anonymous_object_attr_accessor_type access_anonymous_object_attribute( - const std::string &base_dir_path); + const std::filesystem::path &base_dir_path); /// \brief Checks if this kernel is open. /// \return Returns true if it is open; otherwise, returns false. @@ -510,23 +507,23 @@ class manager_kernel { // directories and files for allocation management // segment_dir/ // directories and files for application data segment - static std::string priv_make_top_dir_path(const std::string &base_dir_path); - static std::string priv_make_top_level_file_name( - const std::string &base_dir_path, const std::string &item_name); - static std::string priv_make_management_dir_path( - const std::string &base_dir_path); - static std::string priv_make_management_file_name( - const std::string &base_dir_path, const std::string &item_name); - static std::string priv_make_segment_dir_path( - const std::string &base_dir_path); - static bool priv_init_datastore_directory(const std::string &base_dir_path); + static std::filesystem::path priv_make_top_dir_path(const std::filesystem::path &base_dir_path); + static std::filesystem::path priv_make_top_level_file_name( + const std::filesystem::path &base_dir_path, const std::string &item_name); + static std::filesystem::path priv_make_management_dir_path( + const std::filesystem::path &base_dir_path); + static std::filesystem::path priv_make_management_file_name( + const std::filesystem::path &base_dir_path, const std::string &item_name); + static std::filesystem::path priv_make_segment_dir_path( + const std::filesystem::path &base_dir_path); + static bool priv_init_datastore_directory(const std::filesystem::path &base_dir_path); // ---------- For consistence support ---------- // - static bool priv_consistent(const std::string &base_dir_path); + static bool priv_consistent(const std::filesystem::path &base_dir_path); static bool priv_check_version(const json_store &metadata_json); - static bool priv_properly_closed(const std::string &base_dir_path); - static bool priv_mark_properly_closed(const std::string &base_dir_path); - static bool priv_unmark_properly_closed(const std::string &base_dir_path); + static bool priv_properly_closed(const std::filesystem::path &base_dir_path); + static bool priv_mark_properly_closed(const std::filesystem::path &base_dir_path); + static bool priv_unmark_properly_closed(const std::filesystem::path &base_dir_path); // ---------- For constructed objects ---------- // template @@ -550,9 +547,9 @@ class manager_kernel { bool priv_allocate_segment_header(void *addr); bool priv_deallocate_segment_header(); - bool priv_open(const char *base_dir_path, bool read_only, + bool priv_open(const std::filesystem::path &base_dir_path, bool read_only, size_type vm_reserve_size_request = 0); - bool priv_create(const char *base_dir_path, size_type vm_reserve_size); + bool priv_create(const std::filesystem::path &base_dir_path, size_type vm_reserve_size); // ---------- For serializing/deserializing ---------- // bool priv_serialize_management_data(); @@ -560,23 +557,22 @@ class manager_kernel { // ---------- snapshot ---------- // /// \brief Takes a snapshot. The snapshot has a different UUID. - bool priv_snapshot(const char *destination_base_dir_path, const bool clone, + bool priv_snapshot(const std::filesystem::path &destination_base_dir_path, const int num_max_copy_threads); // ---------- File operations ---------- // /// \brief Copies all backing files using reflink if possible - static bool priv_copy_data_store(const std::string &src_base_dir_path, - const std::string &dst_base_dir_path, - const bool clone, + static bool priv_copy_data_store(const std::filesystem::path &src_base_dir_path, + const std::filesystem::path &dst_base_dir_path, const int num_max_copy_threads); /// \brief Removes all backing files static bool priv_remove_data_store(const std::string &dir_path); // ---------- Management metadata ---------- // - static bool priv_read_management_metadata(const std::string &base_dir_path, + static bool priv_read_management_metadata(const std::filesystem::path &base_dir_path, json_store *json_root); - static bool priv_write_management_metadata(const std::string &base_dir_path, + static bool priv_write_management_metadata(const std::filesystem::path &base_dir_path, const json_store &json_root); static version_type priv_get_version(const json_store &metadata_json); @@ -586,9 +582,9 @@ class manager_kernel { static std::string priv_get_uuid(const json_store &metadata_json); // ---------- Description ---------- // - static bool priv_read_description(const std::string &base_dir_path, + static bool priv_read_description(const std::filesystem::path &base_dir_path, std::string *description); - static bool priv_write_description(const std::string &base_dir_path, + static bool priv_write_description(const std::filesystem::path &base_dir_path, const std::string &description); // -------------------- // @@ -612,9 +608,9 @@ class manager_kernel { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_KERNEL_MANAGER_KERNEL_HPP -#include -#include +#include +#include diff --git a/include/metall/kernel/manager_kernel_fwd.hpp b/libs/copperr/src/dice/copperr/kernel/manager_kernel_fwd.hpp similarity index 91% rename from include/metall/kernel/manager_kernel_fwd.hpp rename to libs/copperr/src/dice/copperr/kernel/manager_kernel_fwd.hpp index 0a7ccc3e..5c573dca 100644 --- a/include/metall/kernel/manager_kernel_fwd.hpp +++ b/libs/copperr/src/dice/copperr/kernel/manager_kernel_fwd.hpp @@ -6,7 +6,7 @@ #ifndef METALL_KERNEL_MANAGER_KERNEL_FWD_HPP #define METALL_KERNEL_MANAGER_KERNEL_FWD_HPP -namespace metall { +namespace dice::copperr { namespace kernel { /// \brief Manager kernel class version 0 @@ -16,6 +16,6 @@ template class manager_kernel; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_KERNEL_MANAGER_KERNEL_FWD_HPP diff --git a/include/metall/kernel/manager_kernel_impl.ipp b/libs/copperr/src/dice/copperr/kernel/manager_kernel_impl.ipp similarity index 76% rename from include/metall/kernel/manager_kernel_impl.ipp rename to libs/copperr/src/dice/copperr/kernel/manager_kernel_impl.ipp index 2d9f7641..c7dab0ab 100644 --- a/include/metall/kernel/manager_kernel_impl.ipp +++ b/libs/copperr/src/dice/copperr/kernel/manager_kernel_impl.ipp @@ -6,9 +6,9 @@ #ifndef METALL_DETAIL_KERNEL_MANAGER_KERNEL_IMPL_IPP #define METALL_DETAIL_KERNEL_MANAGER_KERNEL_IMPL_IPP -#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { // -------------------- // @@ -39,20 +39,20 @@ manager_kernel::~manager_kernel() noexcept { // Public methods // -------------------- // template -bool manager_kernel::create(const char *base_dir_path, +bool manager_kernel::create(const std::filesystem::path &base_dir_path, const size_type vm_reserve_size) { return m_good = priv_create(base_dir_path, vm_reserve_size); } template bool manager_kernel::open_read_only( - const char *base_dir_path) { + const std::filesystem::path &base_dir_path) { return m_good = priv_open(base_dir_path, true, 0); } template bool manager_kernel::open( - const char *base_dir_path, const size_type vm_reserve_size_request) { + const std::filesystem::path &base_dir_path, const size_type vm_reserve_size_request) { return m_good = priv_open(base_dir_path, false, vm_reserve_size_request); } @@ -116,7 +116,7 @@ void *manager_kernel::allocate_aligned( assert(offset >= 0); auto *addr = priv_to_address(offset); - assert((uint64_t)addr % alignment == 0); + assert(reinterpret_cast(addr) % alignment == 0); return addr; } @@ -257,7 +257,7 @@ manager_kernel::get_instance_kind(const T *ptr) const { return instance_kind::anonymous_kind; } - logger::out(logger::level::error, __FILE__, __LINE__, "Invalid pointer"); + METALL_ERROR("Invalid pointer"); return instance_kind(); } @@ -448,40 +448,40 @@ manager_kernel::get_segment_size() const { template bool manager_kernel::snapshot( - const char *destination_base_dir_path, const bool clone, + const std::filesystem::path &destination_base_dir_path, const int num_max_copy_threads) { - return priv_snapshot(destination_base_dir_path, clone, num_max_copy_threads); + return priv_snapshot(destination_base_dir_path, num_max_copy_threads); } template bool manager_kernel::copy( - const char *source_base_dir_path, const char *destination_base_dir_path, - const bool clone, const int num_max_copy_threads) { + const std::filesystem::path &source_base_dir_path, const std::filesystem::path &destination_base_dir_path, + const int num_max_copy_threads) { return priv_copy_data_store(source_base_dir_path, destination_base_dir_path, - clone, num_max_copy_threads); + num_max_copy_threads); } template std::future manager_kernel::copy_async( - const char *source_dir_path, const char *destination_dir_path, - const bool clone, const int num_max_copy_threads) { + const std::filesystem::path &source_dir_path, const std::filesystem::path &destination_dir_path, + const int num_max_copy_threads) { return std::async(std::launch::async, copy, source_dir_path, - destination_dir_path, clone, num_max_copy_threads); + destination_dir_path, num_max_copy_threads); } template -bool manager_kernel::remove(const char *base_dir_path) { +bool manager_kernel::remove(const std::filesystem::path &base_dir_path) { return priv_remove_data_store(base_dir_path); } template std::future manager_kernel::remove_async( - const char *base_dir_path) { + const std::filesystem::path &base_dir_path) { return std::async(std::launch::async, remove, base_dir_path); } template -bool manager_kernel::consistent(const char *dir_path) { +bool manager_kernel::consistent(const std::filesystem::path &dir_path) { return priv_consistent(dir_path); } @@ -491,12 +491,10 @@ std::string manager_kernel::get_uuid() const { } template -std::string manager_kernel::get_uuid(const char *dir_path) { +std::string manager_kernel::get_uuid(const std::filesystem::path &dir_path) { json_store meta_data; if (!priv_read_management_metadata(dir_path, &meta_data)) { - std::stringstream ss; - ss << "Cannot read management metadata in " << dir_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot read management metadata in {}", dir_path.c_str()); return ""; } return priv_get_uuid(meta_data); @@ -509,12 +507,10 @@ version_type manager_kernel::get_version() const { template version_type manager_kernel::get_version( - const char *dir_path) { + const std::filesystem::path &dir_path) { json_store meta_data; if (!priv_read_management_metadata(dir_path, &meta_data)) { - std::stringstream ss; - ss << "Cannot read management metadata in " << dir_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot read management metadata in {}", dir_path.c_str()); return 0; } const auto version = priv_get_version(meta_data); @@ -523,7 +519,7 @@ version_type manager_kernel::get_version( template bool manager_kernel::get_description( - const std::string &base_dir_path, std::string *description) { + const std::filesystem::path &base_dir_path, std::string *description) { return priv_read_description(base_dir_path, description); } @@ -535,7 +531,7 @@ bool manager_kernel::get_description( template bool manager_kernel::set_description( - const std::string &base_dir_path, const std::string &description) { + const std::filesystem::path &base_dir_path, const std::string &description) { return priv_write_description(base_dir_path, description); } @@ -548,7 +544,7 @@ bool manager_kernel::set_description( template typename manager_kernel::named_object_attr_accessor_type manager_kernel::access_named_object_attribute( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return named_object_attr_accessor_type(priv_make_management_file_name( base_dir_path, k_named_object_directory_prefix)); } @@ -556,7 +552,7 @@ manager_kernel::access_named_object_attribute( template typename manager_kernel::unique_object_attr_accessor_type manager_kernel::access_unique_object_attribute( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return unique_object_attr_accessor_type(priv_make_management_file_name( base_dir_path, k_unique_object_directory_prefix)); } @@ -564,7 +560,7 @@ manager_kernel::access_unique_object_attribute( template typename manager_kernel::anonymous_object_attr_accessor_type manager_kernel::access_anonymous_object_attribute( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return anonymous_object_attr_accessor_type(priv_make_management_file_name( base_dir_path, k_anonymous_object_directory_prefix)); } @@ -591,66 +587,60 @@ void *manager_kernel::priv_to_address( } template -std::string manager_kernel::priv_make_top_dir_path( - const std::string &base_dir_path) { - return base_dir_path + "/" + k_datastore_top_dir_name; +std::filesystem::path manager_kernel::priv_make_top_dir_path( + const std::filesystem::path &base_dir_path) { + return base_dir_path / k_datastore_top_dir_name; } template -std::string manager_kernel::priv_make_top_level_file_name( - const std::string &base_dir_path, const std::string &item_name) { - return priv_make_top_dir_path(base_dir_path) + "/" + item_name; +std::filesystem::path manager_kernel::priv_make_top_level_file_name( + const std::filesystem::path &base_dir_path, const std::string &item_name) { + return priv_make_top_dir_path(base_dir_path) / item_name; } template -std::string manager_kernel::priv_make_management_dir_path( - const std::string &base_dir_path) { - return priv_make_top_dir_path(base_dir_path) + "/" + - k_datastore_management_dir_name + "/"; +std::filesystem::path manager_kernel::priv_make_management_dir_path( + const std::filesystem::path &base_dir_path) { + return priv_make_top_dir_path(base_dir_path) / k_datastore_management_dir_name; } template -std::string manager_kernel::priv_make_management_file_name( - const std::string &base_dir_path, const std::string &item_name) { - return priv_make_management_dir_path(base_dir_path) + "/" + item_name; +std::filesystem::path manager_kernel::priv_make_management_file_name( + const std::filesystem::path &base_dir_path, const std::string &item_name) { + return priv_make_management_dir_path(base_dir_path) / item_name; } template -std::string manager_kernel::priv_make_segment_dir_path( - const std::string &base_dir_path) { - return priv_make_top_dir_path(base_dir_path) + "/" + - k_datastore_segment_dir_name + "/"; +std::filesystem::path manager_kernel::priv_make_segment_dir_path( + const std::filesystem::path &base_dir_path) { + return priv_make_top_dir_path(base_dir_path) / k_datastore_segment_dir_name; } template bool manager_kernel::priv_init_datastore_directory( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { // Create the base directory if needed if (!mdtl::create_directory(base_dir_path)) { - std::string s("Failed to create directory: " + base_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", base_dir_path.c_str()); return false; } // Remove existing directory to certainly create a new data store - if (!remove(base_dir_path.c_str())) { - std::string s("Failed to remove a directory: " + base_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + if (!remove(base_dir_path)) { + METALL_ERROR("Failed to remove a directory: {}", base_dir_path.c_str()); return false; } // Create internal directories if needed if (!mdtl::create_directory(priv_make_management_dir_path(base_dir_path))) { - std::string s("Failed to create directory: " + - priv_make_management_dir_path(base_dir_path)); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", + priv_make_management_dir_path(base_dir_path).c_str()); return false; } if (!mdtl::create_directory(priv_make_segment_dir_path(base_dir_path))) { - std::string s("Failed to create directory: " + - priv_make_segment_dir_path(base_dir_path)); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", + priv_make_segment_dir_path(base_dir_path).c_str()); return false; } @@ -674,28 +664,22 @@ bool manager_kernel::priv_validate_runtime_configuration() const { const auto system_page_size = mdtl::get_page_size(); if (system_page_size <= 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to get the system page size"); + METALL_ERROR("Failed to get the system page size"); return false; } if (k_chunk_size % system_page_size != 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "The chunk size must be a multiple of the system page size"); + METALL_ERROR("The chunk size must be a multiple of the system page size"); return false; } if (m_segment_storage.page_size() > k_chunk_size) { - logger::out(logger::level::error, __FILE__, __LINE__, - "The page size of the segment storage must be equal or smaller " - "than the chunk size"); + METALL_ERROR("The page size of the segment storage must be equal or smaller than the chunk size"); return false; } if (m_segment_storage.page_size() % system_page_size != 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "The page size of the segment storage must be a multiple of " - "the system page size"); + METALL_ERROR("The page size of the segment storage must be a multiple of the system page size"); return false; } @@ -704,7 +688,7 @@ bool manager_kernel::priv_validate_runtime_configuration() template bool manager_kernel::priv_consistent( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { json_store metadata; return priv_properly_closed(base_dir_path) && (priv_read_management_metadata(base_dir_path, &metadata) && @@ -719,21 +703,21 @@ bool manager_kernel::priv_check_version( template bool manager_kernel::priv_properly_closed( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return mdtl::file_exist(priv_make_top_level_file_name( base_dir_path, k_properly_closed_mark_file_name)); } template bool manager_kernel::priv_mark_properly_closed( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return mdtl::create_file(priv_make_top_level_file_name( base_dir_path, k_properly_closed_mark_file_name)); } template bool manager_kernel::priv_unmark_properly_closed( - const std::string &base_dir_path) { + const std::filesystem::path &base_dir_path) { return mdtl::remove_file(priv_make_top_level_file_name( base_dir_path, k_properly_closed_mark_file_name)); } @@ -749,9 +733,7 @@ bool manager_kernel::priv_reserve_vm_region( m_vm_region_size = mdtl::round_up(nbytes, alignment); m_vm_region = mdtl::reserve_aligned_vm_region(alignment, m_vm_region_size); if (!m_vm_region) { - std::stringstream ss; - ss << "Cannot reserve a VM region " << nbytes << " bytes"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Cannot reserve a VM region of {} bytes", nbytes); m_vm_region_size = 0; return false; } @@ -763,10 +745,7 @@ bool manager_kernel::priv_reserve_vm_region( template bool manager_kernel::priv_release_vm_region() { if (!mdtl::munmap(m_vm_region, m_vm_region_size, false)) { - std::stringstream ss; - ss << "Cannot release a VM region " << (uint64_t)m_vm_region << ", " - << m_vm_region_size << " bytes."; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_WARN("Cannot release a VM region at {} of {} bytes", m_vm_region, m_vm_region_size); return false; } m_vm_region = nullptr; @@ -784,8 +763,7 @@ bool manager_kernel::priv_allocate_segment_header( if (mdtl::map_anonymous_write_mode(addr, k_segment_header_size, MAP_FIXED) != addr) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot allocate segment header"); + METALL_ERROR("Cannot allocate segment header"); return false; } m_segment_header = reinterpret_cast(addr); @@ -802,8 +780,7 @@ bool manager_kernel::priv_deallocate_segment_header() { const auto ret = mdtl::munmap(m_segment_header, k_segment_header_size, false); m_segment_header = nullptr; if (!ret) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to deallocate segment header"); + METALL_ERROR("Failed to deallocate segment header"); } return ret; } @@ -814,7 +791,7 @@ T *manager_kernel::priv_generic_construct( char_ptr_holder_type name, size_type length, bool try2find, mdtl::in_place_interface &table) { // Check overflow for security - if (length > ((std::size_t)-1) / table.size) { + if (length > static_cast(-1) / table.size) { return nullptr; } @@ -844,9 +821,7 @@ T *manager_kernel::priv_generic_construct( return nullptr; } } catch (...) { - logger::out( - logger::level::error, __FILE__, __LINE__, - "Exception was thrown when finding or allocating an attribute object"); + METALL_ERROR("Exception was thrown when finding or allocating an attribute object"); return nullptr; } @@ -863,8 +838,7 @@ T *manager_kernel::priv_generic_construct( } deallocate(ptr); } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Exception was thrown when cleaning up an object"); + METALL_ERROR("Exception was thrown when cleaning up an object"); } }); @@ -886,28 +860,24 @@ bool manager_kernel::priv_register_attr_object_no_mutex( if (name.is_anonymous()) { if (!m_anonymous_object_directory.insert("", offset, length, gen_type_id())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to insert an entry into the anonymous object table"); + METALL_ERROR("Failed to insert an entry into the anonymous object table"); return false; } } else if (name.is_unique()) { if (!m_unique_object_directory.insert(gen_type_name(), offset, length, gen_type_id())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to insert an entry into the unique object table"); + METALL_ERROR("Failed to insert an entry into the unique object table"); return false; } } else { if (std::string(name.get()).empty()) { - logger::out(logger::level::warning, __FILE__, __LINE__, - "Empty name is invalid for named object"); + METALL_WARN("Empty name is invalid for named object"); return false; } if (!m_named_object_directory.insert(name.get(), offset, length, gen_type_id())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to insert an entry into the named object table"); + METALL_ERROR("Failed to insert an entry into the named object table"); return false; } } @@ -923,8 +893,7 @@ bool manager_kernel::priv_remove_attr_object_no_mutex( if (!m_named_object_directory.erase(offset) && !m_unique_object_directory.erase(offset) && !m_anonymous_object_directory.erase(offset)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to erase an entry from object directories"); + METALL_ERROR("Failed to erase an entry from object directories"); return false; } @@ -944,31 +913,26 @@ void manager_kernel::priv_destruct_and_free_memory( template bool manager_kernel::priv_open( - const char *base_dir_path, const bool read_only, + const std::filesystem::path &base_dir_path, const bool read_only, const size_type vm_reserve_size_request) { if (!priv_validate_runtime_configuration()) { return false; } if (!priv_read_management_metadata(base_dir_path, m_manager_metadata.get())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to read management metadata"); + METALL_ERROR("Failed to read management metadata"); return false; } if (!priv_check_version(*m_manager_metadata)) { - std::stringstream ss; - ss << "Invalid version — it was created by Metall v" - << to_version_string(priv_get_version(*m_manager_metadata)) - << " (currently using v" << to_version_string(METALL_VERSION) << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Invalid version — it was created by Metall v{} (currently using v{})", + to_version_string(priv_get_version(*m_manager_metadata)), + to_version_string(METALL_VERSION)); return false; } if (!priv_properly_closed(base_dir_path)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Inconsistent data store — it was not closed properly and " - "might have been collapsed."); + METALL_ERROR("Inconsistent data store — it was not closed properly and might have been collapsed"); return false; } @@ -992,8 +956,7 @@ bool manager_kernel::priv_open( // Clear the consistent mark before opening with the write mode if (!read_only && !priv_unmark_properly_closed(m_base_dir_path)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to erase the properly close mark before opening"); + METALL_ERROR("Failed to erase the properly close mark before opening"); priv_deallocate_segment_header(); priv_release_vm_region(); return false; @@ -1021,16 +984,13 @@ bool manager_kernel::priv_open( template bool manager_kernel::priv_create( - const char *base_dir_path, const size_type vm_reserve_size) { + const std::filesystem::path &base_dir_path, const size_type vm_reserve_size) { if (!priv_validate_runtime_configuration()) { return false; } if (vm_reserve_size > k_max_segment_size) { - std::stringstream ss; - ss << "Too large VM region size is requested " << vm_reserve_size - << " byte."; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Too large VM region size was requested ({} bytes)", vm_reserve_size); return false; } @@ -1038,9 +998,7 @@ bool manager_kernel::priv_create( if (!priv_unmark_properly_closed(m_base_dir_path) || !priv_init_datastore_directory(base_dir_path)) { - std::stringstream ss; - ss << "Failed to initialize datastore directory under " << base_dir_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to initialize datastore directory under {}", base_dir_path.c_str()); return false; } @@ -1058,8 +1016,7 @@ bool manager_kernel::priv_create( m_vm_region_size - k_segment_header_size, static_cast(m_vm_region) + k_segment_header_size, k_initial_segment_size)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot create application data segment"); + METALL_ERROR("Cannot create application data segment"); priv_deallocate_segment_header(); priv_release_vm_region(); return false; @@ -1088,8 +1045,7 @@ bool manager_kernel::priv_serialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_named_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to serialize named object directory"); + METALL_ERROR("Failed to serialize named object directory"); return false; } @@ -1097,8 +1053,7 @@ bool manager_kernel::priv_serialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_unique_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to serialize unique object directory"); + METALL_ERROR("Failed to serialize unique object directory"); return false; } @@ -1106,8 +1061,7 @@ bool manager_kernel::priv_serialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_anonymous_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to serialize anonymous object directory"); + METALL_ERROR("Failed to serialize anonymous object directory"); return false; } @@ -1125,8 +1079,7 @@ bool manager_kernel::priv_deserialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_named_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to deserialize named object directory"); + METALL_ERROR("Failed to deserialize named object directory"); return false; } @@ -1134,8 +1087,7 @@ bool manager_kernel::priv_deserialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_unique_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to deserialize unique object directory"); + METALL_ERROR("Failed to deserialize unique object directory"); return false; } @@ -1143,8 +1095,7 @@ bool manager_kernel::priv_deserialize_management_data() { priv_make_management_file_name(m_base_dir_path, k_anonymous_object_directory_prefix) .c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to deserialize anonymous object directory"); + METALL_ERROR("Failed to deserialize anonymous object directory"); return false; } @@ -1159,7 +1110,7 @@ bool manager_kernel::priv_deserialize_management_data() { // ---------- snapshot ---------- // template bool manager_kernel::priv_snapshot( - const char *destination_base_dir_path, const bool clone, + const std::filesystem::path &destination_base_dir_path, const int num_max_copy_threads) { priv_sanity_check(); m_segment_storage.sync(true); @@ -1167,9 +1118,7 @@ bool manager_kernel::priv_snapshot( const auto dst_top_dir = priv_make_top_dir_path(destination_base_dir_path); if (!mdtl::create_directory(dst_top_dir)) { - std::stringstream ss; - ss << "Failed to create a directory: " << dst_top_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to create directory: {}", dst_top_dir.c_str()); return false; } @@ -1178,16 +1127,12 @@ bool manager_kernel::priv_snapshot( const auto dst_seg_dir = priv_make_segment_dir_path(destination_base_dir_path); if (!mdtl::create_directory(dst_seg_dir)) { - std::stringstream ss; - ss << "Failed to create directory: " << dst_seg_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to create directory: {}", dst_seg_dir.c_str()); return false; } - if (!m_segment_storage.copy(src_seg_dir, dst_seg_dir, clone, + if (!m_segment_storage.copy(src_seg_dir, dst_seg_dir, num_max_copy_threads)) { - std::stringstream ss; - ss << "Failed to copy " << src_seg_dir << " to " << dst_seg_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to copy {} to {}", src_seg_dir.c_str(), dst_seg_dir.c_str()); return false; } @@ -1196,18 +1141,14 @@ bool manager_kernel::priv_snapshot( const auto dst_mng_dir = priv_make_management_dir_path(destination_base_dir_path); if (!mdtl::create_directory(dst_mng_dir)) { - std::stringstream ss; - ss << "Failed to create directory: " << dst_mng_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to create directory: {}", dst_mng_dir.c_str()); return false; } // Use a normal copy instead of reflink. // reflink might slow down if there are many reflink copied files. if (!mtlldetail::copy_files_in_directory_in_parallel(src_mng_dir, dst_mng_dir, num_max_copy_threads)) { - std::stringstream ss; - ss << "Failed to copy " << src_mng_dir << " to " << dst_mng_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to copy {} to {}", src_mng_dir.c_str(), dst_mng_dir.c_str()); return false; } @@ -1220,8 +1161,7 @@ bool manager_kernel::priv_snapshot( // Finally, mark it as properly-closed if (!priv_mark_properly_closed(destination_base_dir_path)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to create a properly closed mark"); + METALL_ERROR("Failed to create a properly closed mark"); return false; } @@ -1231,27 +1171,21 @@ bool manager_kernel::priv_snapshot( // ---------- File operations ---------- // template bool manager_kernel::priv_copy_data_store( - const std::string &src_base_dir_path, const std::string &dst_base_dir_path, - const bool use_clone, const int num_max_copy_threads) { - if (!consistent(src_base_dir_path.data())) { - std::string s( - "Source directory is not consistnt (may not have closed properly or " - "may still be open): " + - src_base_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + const std::filesystem::path &src_base_dir_path, const std::filesystem::path &dst_base_dir_path, + const int num_max_copy_threads) { + if (!consistent(src_base_dir_path)) { + METALL_ERROR("Source directory is not consistent (may not have closed properly or may still be open): {}", src_base_dir_path.c_str()); return false; } const std::string src_top_dir = priv_make_top_dir_path(src_base_dir_path); if (!mdtl::directory_exist(src_top_dir)) { - std::string s("Source directory does not exist: " + src_top_dir); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Source directory does not exist: {}", src_top_dir.c_str()); return false; } if (!mdtl::create_directory(priv_make_top_dir_path(dst_base_dir_path))) { - std::string s("Failed to create directory: " + dst_base_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", dst_base_dir_path.c_str()); return false; } @@ -1259,15 +1193,12 @@ bool manager_kernel::priv_copy_data_store( const auto src_seg_dir = priv_make_segment_dir_path(src_base_dir_path); const auto dst_seg_dir = priv_make_segment_dir_path(dst_base_dir_path); if (!mdtl::create_directory(dst_seg_dir)) { - std::string s("Failed to create directory: " + dst_seg_dir); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", dst_seg_dir.c_str()); return false; } - if (!segment_storage_type::copy(src_seg_dir, dst_seg_dir, use_clone, + if (!segment_storage_type::copy(src_seg_dir, dst_seg_dir, num_max_copy_threads)) { - std::stringstream ss; - ss << "Failed to copy " << src_seg_dir << " to " << dst_seg_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to copy {} to {}", src_seg_dir.c_str(), dst_seg_dir.c_str()); return false; } @@ -1275,24 +1206,20 @@ bool manager_kernel::priv_copy_data_store( const auto src_mng_dir = priv_make_management_dir_path(src_base_dir_path); const auto dst_mng_dir = priv_make_management_dir_path(dst_base_dir_path); if (!mdtl::create_directory(dst_mng_dir)) { - std::string s("Failed to create directory: " + dst_mng_dir); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create directory: {}", dst_mng_dir.c_str()); return false; } // Use a normal copy instead of reflink. // reflink might slow down if there are many reflink copied files. if (!mtlldetail::copy_files_in_directory_in_parallel(src_mng_dir, dst_mng_dir, num_max_copy_threads)) { - std::stringstream ss; - ss << "Failed to copy " << src_mng_dir << " to " << dst_mng_dir; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to copy {} to {}", src_mng_dir.c_str(), dst_mng_dir.c_str()); return false; } // Finally, mark it as properly-closed if (!priv_mark_properly_closed(dst_base_dir_path)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to create a properly closed mark"); + METALL_ERROR("Failed to create a properly closed mark"); return false; } @@ -1308,12 +1235,11 @@ bool manager_kernel::priv_remove_data_store( // ---------- Management metadata ---------- // template bool manager_kernel::priv_write_management_metadata( - const std::string &base_dir_path, const json_store &json_root) { + const std::filesystem::path &base_dir_path, const json_store &json_root) { if (!mdtl::ptree::write_json( json_root, priv_make_management_file_name( base_dir_path, k_manager_metadata_file_name))) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to write management metadata"); + METALL_ERROR("Failed to write management metadata"); return false; } @@ -1322,12 +1248,11 @@ bool manager_kernel::priv_write_management_metadata( template bool manager_kernel::priv_read_management_metadata( - const std::string &base_dir_path, json_store *json_root) { + const std::filesystem::path &base_dir_path, json_store *json_root) { if (!mdtl::ptree::read_json(priv_make_management_file_name( base_dir_path, k_manager_metadata_file_name), json_root)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to read management metadata"); + METALL_ERROR("Failed to read management metadata"); return false; } return true; @@ -1349,8 +1274,7 @@ bool manager_kernel::priv_set_version( json_store *metadata_json) { if (mdtl::ptree::count(*metadata_json, k_manager_metadata_key_for_version) > 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Version information already exist"); + METALL_ERROR("Version information already exist"); return false; } @@ -1380,13 +1304,12 @@ bool manager_kernel::priv_set_uuid( std::stringstream uuid_ss; uuid_ss << mdtl::uuid(mdtl::uuid_random_generator{}()); if (!uuid_ss) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to convert UUID to std::string"); + METALL_ERROR("Failed to convert UUID to std::string"); return false; } if (mdtl::ptree::count(*metadata_json, k_manager_metadata_key_for_uuid) > 0) { - logger::out(logger::level::error, __FILE__, __LINE__, "UUID already exist"); + METALL_ERROR("UUID already exist"); return false; } @@ -1402,7 +1325,7 @@ bool manager_kernel::priv_set_uuid( template bool manager_kernel::priv_read_description( - const std::string &base_dir_path, std::string *description) { + const std::filesystem::path &base_dir_path, std::string *description) { const auto &file_name = priv_make_management_file_name(base_dir_path, k_description_file_name); @@ -1412,8 +1335,7 @@ bool manager_kernel::priv_read_description( std::ifstream ifs(file_name); if (!ifs.is_open()) { - std::string s("Failed to open: " + file_name); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to open: {}", file_name.c_str()); return false; } @@ -1427,20 +1349,18 @@ bool manager_kernel::priv_read_description( template bool manager_kernel::priv_write_description( - const std::string &base_dir_path, const std::string &description) { + const std::filesystem::path &base_dir_path, const std::string &description) { const auto &file_name = priv_make_management_file_name(base_dir_path, k_description_file_name); std::ofstream ofs(file_name); if (!ofs.is_open()) { - std::string s("Failed to open: " + file_name); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to open: {}", file_name.c_str()); return false; } if (!(ofs << description)) { - std::string s("Failed to write data:" + file_name); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to write data: {}", file_name.c_str()); return false; } @@ -1450,6 +1370,6 @@ bool manager_kernel::priv_write_description( } } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_KERNEL_MANAGER_KERNEL_IMPL_IPP diff --git a/include/metall/kernel/manager_kernel_profile_impl.ipp b/libs/copperr/src/dice/copperr/kernel/manager_kernel_profile_impl.ipp similarity index 85% rename from include/metall/kernel/manager_kernel_profile_impl.ipp rename to libs/copperr/src/dice/copperr/kernel/manager_kernel_profile_impl.ipp index 7475f9c7..585a19b0 100644 --- a/include/metall/kernel/manager_kernel_profile_impl.ipp +++ b/libs/copperr/src/dice/copperr/kernel/manager_kernel_profile_impl.ipp @@ -6,9 +6,9 @@ #ifndef METALL_DETAIL_KERNEL_MANAGER_KERNEL_PROFILE_IMPL_IPP #define METALL_DETAIL_KERNEL_MANAGER_KERNEL_PROFILE_IMPL_IPP -#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { template @@ -19,6 +19,6 @@ void manager_kernel::profile( } } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_KERNEL_MANAGER_KERNEL_PROFILE_IMPL_IPP diff --git a/include/metall/kernel/multilayer_bitset.hpp b/libs/copperr/src/dice/copperr/kernel/multilayer_bitset.hpp similarity index 97% rename from include/metall/kernel/multilayer_bitset.hpp rename to libs/copperr/src/dice/copperr/kernel/multilayer_bitset.hpp index 68db5b5c..b44d69aa 100644 --- a/include/metall/kernel/multilayer_bitset.hpp +++ b/libs/copperr/src/dice/copperr/kernel/multilayer_bitset.hpp @@ -19,16 +19,16 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } namespace multilayer_bitset_detail { @@ -63,7 +63,7 @@ static constexpr std::array, 25> k_num_blocks_table = } // namespace multilayer_bitset_detail namespace { -namespace bs = metall::mtlldetail::bitset_detail; +namespace bs = dice::copperr::mtlldetail::bitset_detail; namespace mlbs = multilayer_bitset_detail; } // namespace @@ -266,8 +266,7 @@ class multilayer_bitset { m_data.array = static_cast(std::malloc(num_blocks * sizeof(block_type))); if (!m_data.array) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Cannot allocate multi-layer bitset"); + METALL_ERROR("Cannot allocate multi-layer bitset"); return false; } std::fill(&m_data.array[0], &m_data.array[num_blocks], 0); @@ -496,5 +495,5 @@ class multilayer_bitset { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_MULTILAYER_BITSET_HPP diff --git a/include/metall/kernel/object_cache.hpp b/libs/copperr/src/dice/copperr/kernel/object_cache.hpp similarity index 98% rename from include/metall/kernel/object_cache.hpp rename to libs/copperr/src/dice/copperr/kernel/object_cache.hpp index 23ac3aa8..e0ed0628 100644 --- a/include/metall/kernel/object_cache.hpp +++ b/libs/copperr/src/dice/copperr/kernel/object_cache.hpp @@ -15,14 +15,14 @@ #include #include -#include -#include +#include +#include #ifndef METALL_DISABLE_CONCURRENCY #define METALL_ENABLE_MUTEX_IN_OBJECT_CACHE #endif #ifdef METALL_ENABLE_MUTEX_IN_OBJECT_CACHE -#include +#include #endif // #define METALL_OBJECT_CACHE_HEAVY_DEBUG @@ -30,10 +30,10 @@ #warning "METALL_OBJECT_CACHE_HEAVY_DEBUG is defined" #endif -namespace metall::kernel { +namespace dice::copperr::kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } namespace obcdetail { @@ -328,9 +328,9 @@ inline constexpr unsigned int comp_chunk_size( // 4096 is meant for page size so that we do not move memory larger than a // page. // 8 is meant for the minimum number of objects to cache within a block. - return std::max(std::min((unsigned int)(4096 / object_size), + return std::max(std::min(static_cast(4096 / object_size), cache_block_type ::k_capacity), - (unsigned int)(8)); + static_cast(8)); } // Calculate the max bin number that can be cached, @@ -350,8 +350,7 @@ inline constexpr typename bin_no_manager::bin_no_type comp_max_bin_no( if (max_per_cpu_cache_size < min_required_cache_size) { if (b == 0) { - logger::out(logger::level::error, __FILE__, __LINE__, - "The request max per-CPU cache size is too small"); + METALL_ERROR("The request max per-CPU cache size is too small"); return 0; } --b; @@ -584,8 +583,7 @@ class object_cache { auto *const mem = std::malloc(sizeof(cache_storage_type) * m_num_caches); m_cache.reset(reinterpret_cast(mem)); if (!m_cache) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to allocate memory for the cache"); + METALL_ERROR("Failed to allocate memory for the cache"); return false; } @@ -821,5 +819,5 @@ class object_cache<_size_type, _difference_type, _bin_no_manager, const cache_block_type *m_block{nullptr}; unsigned int m_in_block_pos{0}; }; -} // namespace metall::kernel +} // namespace dice::copperr::kernel #endif // METALL_DETAIL_OBJECT_CACHE_HPP diff --git a/libs/copperr/src/dice/copperr/kernel/object_cache_container.hpp b/libs/copperr/src/dice/copperr/kernel/object_cache_container.hpp new file mode 100644 index 00000000..e69de29b diff --git a/include/metall/kernel/object_size_manager.hpp b/libs/copperr/src/dice/copperr/kernel/object_size_manager.hpp similarity index 95% rename from include/metall/kernel/object_size_manager.hpp rename to libs/copperr/src/dice/copperr/kernel/object_size_manager.hpp index 9c4448e9..80bdeaec 100644 --- a/include/metall/kernel/object_size_manager.hpp +++ b/libs/copperr/src/dice/copperr/kernel/object_size_manager.hpp @@ -10,14 +10,14 @@ #include #include -#include -#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } namespace object_size_manager_detail { @@ -29,7 +29,7 @@ constexpr std::size_t k_class1_small_size_table[] = { }; constexpr uint64_t k_num_class1_small_sizes = - (uint64_t)std::extent::value; + static_cast(std::extent::value); constexpr std::size_t k_min_class2_offset = 64; template constexpr std::size_t k_max_small_size = k_chunk_size / 2; @@ -181,5 +181,5 @@ class object_size_manager { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAIL_KERNEL_OBJECT_SIZE_MANAGER_HPP diff --git a/include/metall/kernel/segment_allocator.hpp b/libs/copperr/src/dice/copperr/kernel/segment_allocator.hpp similarity index 94% rename from include/metall/kernel/segment_allocator.hpp rename to libs/copperr/src/dice/copperr/kernel/segment_allocator.hpp index 7e601cea..e474d704 100644 --- a/include/metall/kernel/segment_allocator.hpp +++ b/libs/copperr/src/dice/copperr/kernel/segment_allocator.hpp @@ -16,31 +16,31 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #ifndef METALL_DISABLE_CONCURRENCY #define METALL_ENABLE_MUTEX_IN_SEGMENT_ALLOCATOR #endif #ifdef METALL_ENABLE_MUTEX_IN_SEGMENT_ALLOCATOR -#include +#include #endif #ifndef METALL_DISABLE_OBJECT_CACHE -#include +#include #endif -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } template extend(required_segment_size)) { - std::stringstream ss; - ss << "Failed to extend the segment to " << required_segment_size - << " bytes"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to extend the segment to {} bytes", required_segment_size); return false; } @@ -586,7 +575,7 @@ class segment_allocator { // To simplify the implementation, free slots only when object_size is at // least double of the page size const size_type min_free_size = std::max( - (size_type)m_segment_storage->page_size() * 2, min_free_size_hint); + static_cast(m_segment_storage->page_size()) * 2, min_free_size_hint); if (object_size < min_free_size) return; // This function assumes that small objects are equal to or smaller than the @@ -719,5 +708,5 @@ class segment_allocator { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_KERNEL_SEGMENT_ALLOCATOR_HPP diff --git a/include/metall/kernel/segment_header.hpp b/libs/copperr/src/dice/copperr/kernel/segment_header.hpp similarity index 86% rename from include/metall/kernel/segment_header.hpp rename to libs/copperr/src/dice/copperr/kernel/segment_header.hpp index 77cb6096..cab635da 100644 --- a/include/metall/kernel/segment_header.hpp +++ b/libs/copperr/src/dice/copperr/kernel/segment_header.hpp @@ -6,7 +6,7 @@ #ifndef METALL_KERNEL_SEGMENT_HEADER_HPP #define METALL_KERNEL_SEGMENT_HEADER_HPP -namespace metall::kernel { +namespace dice::copperr::kernel { struct segment_header { void *manager_kernel_address; @@ -14,6 +14,6 @@ struct segment_header { ~segment_header() noexcept { manager_kernel_address = nullptr; } }; -} // namespace metall::kernel +} // namespace dice::copperr::kernel #endif // METALL_KERNEL_SEGMENT_HEADER_HPP diff --git a/include/metall/kernel/segment_storage/mmap_segment_storage.hpp b/libs/copperr/src/dice/copperr/kernel/segment_storage/mmap_segment_storage.hpp similarity index 74% rename from include/metall/kernel/segment_storage/mmap_segment_storage.hpp rename to libs/copperr/src/dice/copperr/kernel/segment_storage/mmap_segment_storage.hpp index 3017476f..e2e8be96 100644 --- a/include/metall/kernel/segment_storage/mmap_segment_storage.hpp +++ b/libs/copperr/src/dice/copperr/kernel/segment_storage/mmap_segment_storage.hpp @@ -13,17 +13,17 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } /// \brief Segment storage that uses multiple backing files @@ -36,8 +36,7 @@ class mmap_segment_storage { // -------------------- // mmap_segment_storage() { #ifdef METALL_USE_ANONYMOUS_NEW_MAP - logger::out(logger::level::info, __FILE__, __LINE__, - "METALL_USE_ANONYMOUS_NEW_MAP is defined"); + METALL_DEBUG("METALL_USE_ANONYMOUS_NEW_MAP is defined"); #endif if (!priv_set_system_page_size()) { @@ -55,8 +54,7 @@ class mmap_segment_storage { } if (!ret) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to destruct"); + METALL_ERROR("Failed to destruct"); } } @@ -107,7 +105,7 @@ class mmap_segment_storage { /// \brief Gets the size of an existing segment. /// This is a static version of size() method. /// \param base_path A path to a segment. - static size_type get_size(const std::string &base_path) { + static size_type get_size(const std::filesystem::path &base_path) { int block_no = 0; size_type total_file_size = 0; while (true) { @@ -124,7 +122,7 @@ class mmap_segment_storage { /// \brief Checks if a segment is openable. /// \param base_path A path to a segment. /// \return Return true if success; otherwise, false. - static bool openable(const std::string &base_path) { + static bool openable(const std::filesystem::path &base_path) { const auto file_name = priv_make_block_file_name(base_path, 0); return mdtl::file_exist(file_name); } @@ -136,10 +134,10 @@ class mmap_segment_storage { /// \param max_num_threads The maximum number of threads to use. /// If <= 0 is given, the value is automatically determined. /// \return Return true if success; otherwise, false. - static bool copy(const std::string &source_path, - const std::string &destination_path, const bool clone, + static bool copy(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path, const int max_num_threads) { - return priv_copy(source_path, destination_path, clone, max_num_threads); + return priv_copy(source_path, destination_path, max_num_threads); } /// \brief Creates a new segment. @@ -148,7 +146,7 @@ class mmap_segment_storage { /// vm_region_size The size of a reserved VM region. \param vm_region The /// address of a reserved VM region. \block_size The block size. \return /// Return true if success; otherwise, false. - bool create(const std::string &base_path, const size_type vm_region_size, + bool create(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, const size_type block_size) { return priv_create(base_path, vm_region_size, vm_region, block_size); } @@ -159,7 +157,7 @@ class mmap_segment_storage { /// vm_region_size The size of a VM region. \param vm_region The address of a /// VM region. \param read_only If true, this segment is read only. \return /// Return true if success; otherwise, false. - bool open(const std::string &base_path, const size_type vm_region_size, + bool open(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, const bool read_only) { return priv_open(base_path, vm_region_size, vm_region, read_only); } @@ -224,9 +222,9 @@ class mmap_segment_storage { // -------------------- // // Private methods // -------------------- // - static std::string priv_make_block_file_name(const std::string &base_path, - const size_type n) { - return base_path + "/block-" + std::to_string(n); + static std::filesystem::path priv_make_block_file_name(const std::filesystem::path &base_path, + const size_type n) { + return base_path / std::format("block-{}", n); } void priv_clear_status() { @@ -250,47 +248,32 @@ class mmap_segment_storage { m_block_size > 0); } - static bool priv_copy(const std::string &source_path, - const std::string &destination_path, const bool clone, + static bool priv_copy(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path, const int max_num_threads) { if (!mdtl::directory_exist(destination_path)) { if (!mdtl::create_directory(destination_path)) { - std::string s("Cannot create a directory: " + destination_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Cannot create a directory: {}", destination_path.c_str()); return false; } } - if (clone) { - std::string s("Clone: " + source_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - return mdtl::clone_files_in_directory_in_parallel( - source_path, destination_path, max_num_threads); - } else { - std::string s("Copy: " + source_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - return mdtl::copy_files_in_directory_in_parallel( - source_path, destination_path, max_num_threads); - } - assert(false); - return false; + METALL_TRACE("Clone: {}", source_path.c_str()); + return mdtl::clone_files_in_directory_in_parallel( + source_path, destination_path, max_num_threads); } - bool priv_create(const std::string &base_path, const size_type vm_region_size, + bool priv_create(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, const size_type block_size) { if (!check_sanity()) return false; if (is_open()) return false; // Cannot open multiple segments simultaneously. - { - std::string s("Create a segment under: " + base_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + METALL_TRACE("Create a segment under: {}", base_path.c_str()); if (!mdtl::directory_exist(base_path)) { if (!mdtl::create_directory(base_path)) { - std::string s("Cannot create a directory: " + base_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Cannot create a directory: {}", base_path.c_str()); // As no internal value has been changed, m_broken is still false. return false; } @@ -314,8 +297,7 @@ class mmap_segment_storage { m_num_blocks = 1; if (!priv_test_file_space_free(base_path)) { - std::string s("Failed to test file space free: " + base_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to test file space free: {}", base_path.c_str()); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -324,19 +306,17 @@ class mmap_segment_storage { return true; } - bool priv_open(const std::string &base_path, const size_type vm_region_size, + bool priv_open(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, const bool read_only) { if (!check_sanity()) return false; if (is_open()) return false; // Cannot open multiple segments simultaneously. - { - std::string s("Open a segment under: " + base_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + METALL_TRACE("Open a segment under: {}", base_path.c_str()); m_base_path = base_path; m_vm_region_size = mdtl::round_down(vm_region_size, page_size()); + ; m_segment = reinterpret_cast( mdtl::round_up(reinterpret_cast(vm_region), page_size())); m_read_only = read_only; @@ -352,9 +332,8 @@ class mmap_segment_storage { const auto file_size = mdtl::get_file_size(file_name); assert(file_size % page_size() == 0); - if (m_block_size > 0 && m_block_size != (size_type)file_size) { - logger::out(logger::level::error, __FILE__, __LINE__, - "File sizes are not the same"); + if (m_block_size > 0 && m_block_size != static_cast(file_size)) { + METALL_ERROR("File sizes are not the same"); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -364,9 +343,7 @@ class mmap_segment_storage { const auto fd = priv_map_file(file_name, m_block_size, m_current_segment_size, read_only); if (fd == -1) { - std::stringstream ss; - ss << "Failed to map a file " << file_name; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("Failed to map a file {}", file_name.c_str()); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -380,8 +357,7 @@ class mmap_segment_storage { } if (!read_only && !priv_test_file_space_free(base_path)) { - std::string s("Failed to test file space free: " + base_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to test file space free: {}", base_path.c_str()); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -403,8 +379,7 @@ class mmap_segment_storage { } if (request_size > m_vm_region_size) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Requested segment size is bigger than the reserved VM size"); + METALL_ERROR("Requested segment size is bigger than the reserved VM size"); return false; } @@ -415,8 +390,7 @@ class mmap_segment_storage { while (m_current_segment_size < request_size) { if (!priv_create_new_map(m_base_path, m_num_blocks, m_block_size, m_current_segment_size)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to extend the segment"); + METALL_ERROR("Failed to extend the segment"); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -428,23 +402,19 @@ class mmap_segment_storage { return true; } - bool priv_create_new_map(const std::string &base_path, + bool priv_create_new_map(const std::filesystem::path &base_path, const size_type block_number, const size_type file_size, const different_type segment_offset) { - const std::string file_name = + const auto file_name = priv_make_block_file_name(base_path, block_number); - { - std::string s("Create and extend a file " + file_name + " with " + - std::to_string(file_size) + " bytes"); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + + METALL_TRACE("Create and extend a file {} with {} bytes", file_name.c_str(), file_size); if (!mdtl::create_file(file_name)) return false; if (!mdtl::extend_file_size(file_name, file_size)) return false; if (static_cast(mdtl::get_file_size(file_name)) < file_size) { - std::string s("Failed to create and extend file: " + file_name); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to create and extend file: {}", file_name.c_str()); return false; } @@ -468,7 +438,7 @@ class mmap_segment_storage { return true; } - int priv_map_file(const std::string &path, const size_type file_size, + int priv_map_file(const std::filesystem::path &path, const size_type file_size, const different_type segment_offset, const bool read_only) const { assert(!path.empty()); @@ -485,13 +455,11 @@ class mmap_segment_storage { const auto map_addr = static_cast(m_segment) + segment_offset; - { - std::stringstream ss; - ss << "Map a file " << path << " at " << segment_offset << " with " - << file_size << " bytes; read-only mode is " - << std::to_string(read_only); - logger::out(logger::level::info, __FILE__, __LINE__, ss.str().c_str()); - } + METALL_TRACE("Map a file {} at {} with {} bytes; read-only mode is {}", + path.c_str(), + segment_offset, + file_size, + read_only); const auto ret = (read_only) @@ -499,8 +467,7 @@ class mmap_segment_storage { : mdtl::map_file_write_mode(path, map_addr, file_size, 0, MAP_FIXED | map_nosync); if (ret.first == -1 || !ret.second) { - std::string s("Failed to map a file: " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to map a file: {}", path.c_str()); if (ret.first != -1) { mdtl::os_close(ret.first); } @@ -510,7 +477,7 @@ class mmap_segment_storage { return ret.first; } - int priv_map_anonymous(const std::string &path, const size_type region_size, + int priv_map_anonymous(const std::filesystem::path &path, const size_type region_size, const different_type segment_offset) const { assert(!path.empty()); assert(region_size > 0); @@ -518,19 +485,12 @@ class mmap_segment_storage { assert(segment_offset + region_size <= m_vm_region_size); const auto map_addr = static_cast(m_segment) + segment_offset; - { - std::string s("Map an anonymous region at " + - std::to_string(segment_offset) + " with " + - std::to_string(region_size)); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + METALL_TRACE("Map an anonymous region at {} with size {}", segment_offset, region_size); const auto *addr = mdtl::map_anonymous_write_mode(map_addr, region_size, MAP_FIXED); if (!addr) { - std::string s("Failed to map an anonymous region at " + - std::to_string(segment_offset)); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to map an anonymous region at {}", segment_offset); return -1; } @@ -538,9 +498,8 @@ class mmap_segment_storage { // in this class works. const auto fd = ::open(path.c_str(), O_RDWR); if (fd == -1) { - logger::perror(logger::level::error, __FILE__, __LINE__, "open"); - std::string s("Failed to open a file " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERRNO_ERROR("open"); + METALL_ERROR("Failed to open a file {}", path.c_str()); // Destroy the map by overwriting PROT_NONE map since the VM region is // managed by another class. mdtl::map_with_prot_none(static_cast(m_segment) + segment_offset, @@ -573,8 +532,7 @@ class mmap_segment_storage { bool priv_sync(const bool sync) { if (!priv_sync_segment( sync)) { // Failing this operation is not a critical error - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to synchronize the segment"); + METALL_ERROR("Failed to synchronize the segment"); return false; } return true; @@ -587,21 +545,17 @@ class mmap_segment_storage { // Protect the region to detect unexpected write by application during msync if (!mdtl::mprotect_read_only(m_segment, m_current_segment_size)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to protect the segment with the read only mode"); + METALL_ERROR("Failed to protect the segment with the read only mode"); return false; } - logger::out(logger::level::info, __FILE__, __LINE__, - "msync() for the application data segment"); + METALL_TRACE("msync() for the application data segment"); if (!priv_parallel_msync(sync)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to msync the segment"); + METALL_ERROR("Failed to msync the segment"); return false; } if (!mdtl::mprotect_read_write(m_segment, m_current_segment_size)) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to set the segment to readable and writable"); + METALL_ERROR("Failed to set the segment to readable and writable"); return false; } @@ -632,14 +586,9 @@ class mmap_segment_storage { } }; - const auto num_threads = - (int)std::min(m_block_fd_list.size(), - (std::size_t)std::thread::hardware_concurrency()); - { - std::stringstream ss; - ss << "Sync files with " << num_threads << " threads"; - logger::out(logger::level::info, __FILE__, __LINE__, ss.str().c_str()); - } + const auto num_threads = std::min(m_block_fd_list.size(), + std::thread::hardware_concurrency()); + METALL_TRACE("Sync files with {} threads", num_threads); std::vector> threads(num_threads); for (auto &th : threads) { th = std::make_unique(diff_sync); @@ -693,27 +642,19 @@ class mmap_segment_storage { #ifdef METALL_USE_ANONYMOUS_NEW_MAP bool priv_sync_anonymous_map(const size_type block_no) { assert(m_anonymous_map_flag_list[block_no]); - { - std::string s("Sync anonymous map at block " + std::to_string(block_no)); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + METALL_TRACE("Sync anonymous map at block {}", block_no); auto *const addr = static_cast(m_segment) + block_no * m_block_size; if (::write(m_block_fd_list[block_no], addr, m_block_size) != (ssize_t)m_block_size) { - std::string s("Failed to write back a block"); - logger::perror(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERRNO_ERROR("Failed to write back a block"); priv_destroy_segment(); priv_set_broken_status(); return false; } m_anonymous_map_flag_list[block_no] = false; - { - std::string s("Map block " + std::to_string(block_no) + - " as a non-anonymous map"); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } + METALL_TRACE("Map block {} as non-anonymous map", block_no); [[maybe_unused]] static constexpr int map_nosync = #ifdef MAP_NOSYNC MAP_NOSYNC; @@ -724,8 +665,7 @@ class mmap_segment_storage { mdtl::map_file_write_mode(m_block_fd_list[block_no], addr, m_block_size, 0, MAP_FIXED | map_nosync); if (!mapped_addr || mapped_addr != addr) { - std::string s("Failed to map a block"); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to map a block"); priv_destroy_segment(); priv_set_broken_status(); return false; @@ -737,21 +677,20 @@ class mmap_segment_storage { bool priv_set_system_page_size() { m_system_page_size = mdtl::get_page_size(); if (m_system_page_size == -1) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to get system pagesize"); + METALL_ERROR("Failed to get system pagesize"); return false; } return true; } - bool priv_test_file_space_free(const std::string &base_path) { + bool priv_test_file_space_free(const std::filesystem::path &base_path) { #ifdef METALL_DISABLE_FREE_FILE_SPACE m_free_file_space = false; return true; #endif assert(m_system_page_size > 0); - const std::string file_path(base_path + "/test"); + const auto file_path = base_path / "test"; const size_type file_size = m_system_page_size * 2; if (!mdtl::create_file(file_path)) return false; @@ -761,8 +700,7 @@ class mmap_segment_storage { const auto ret = mdtl::map_file_write_mode(file_path, nullptr, file_size, 0); if (ret.first == -1 || !ret.second) { - std::string s("Failed to map file: " + file_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("Failed to map file: {}", file_path.c_str()); if (ret.first != -1) mdtl::os_close(ret.first); return false; } @@ -778,25 +716,18 @@ class mmap_segment_storage { } if (!mdtl::os_close(ret.first)) { - std::string s("Failed to close file: " + file_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_WARN("Failed to close file: {}", file_path.c_str()); return false; } // Closing mdtl::munmap(ret.second, file_size, false); if (!mdtl::remove_file(file_path)) { - std::string s("Failed to remove a file: " + file_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_WARN("Failed to remove a file: {}", file_path.c_str()); return false; } - { - std::string s("File free test result: "); - s += m_free_file_space ? "success" : "failed"; - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); - } - + METALL_DEBUG("File free test result: {}", m_free_file_space ? "success" : "failed"); return true; } @@ -820,5 +751,5 @@ class mmap_segment_storage { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_KERNEL_SEGMENT_STORAGE_MMAP_SEGMENT_STORAGE_HPP diff --git a/include/metall/kernel/segment_storage/umap_sparse_segment_storage.hpp b/libs/copperr/src/dice/copperr/kernel/segment_storage/umap_sparse_segment_storage.hpp similarity index 92% rename from include/metall/kernel/segment_storage/umap_sparse_segment_storage.hpp rename to libs/copperr/src/dice/copperr/kernel/segment_storage/umap_sparse_segment_storage.hpp index 3dbc00ec..5147fd66 100644 --- a/include/metall/kernel/segment_storage/umap_sparse_segment_storage.hpp +++ b/libs/copperr/src/dice/copperr/kernel/segment_storage/umap_sparse_segment_storage.hpp @@ -23,17 +23,17 @@ const size_t SPARSE_STORE_FILE_GRANULARITY_DEFAULT = 1073741824; #include #include #include -#include -#include -#include +#include +#include +#include // #include "umap_sparse_store.hpp" -namespace metall { +namespace dice::copperr { namespace kernel { namespace { -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; } template @@ -94,30 +94,28 @@ class umap_sparse_segment_storage { // Public methods // -------------------- // /// \brief Check if there is a file that can be opened - static bool openable(const std::string &base_path) { + static bool openable(const std::filesystem::path &base_path) { return mdtl::file_exist(priv_make_file_name(base_path)); } /// \brief Gets the size of an existing segment. /// This is a static version of size() method. - static size_type get_size(const std::string &base_path) { + static size_type get_size(const std::filesystem::path &base_path) { const auto directory_name = priv_make_file_name(base_path); return Umap::SparseStore::get_capacity(directory_name); } /// \brief Copies segment to another location. - static bool copy(const std::string &source_path, - const std::string &destination_path, const bool clone, + static bool copy(const std::filesystem::path &source_path, + const std::filesystem::path &destination_path, const bool clone, [[maybe_unused]] const int max_num_threads) { // TODO: implement parallel copy version if (clone) { - std::string s("Clone: " + source_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); + METALL_TRACE("Clone: {} to {}", source_path, destination_path); return mdtl::clone_file(source_path, destination_path); } else { - std::string s("Copy: " + source_path); - logger::out(logger::level::info, __FILE__, __LINE__, s.c_str()); + METALL_TRACE("Copy: {} to {}", source_path, destination_path); return mdtl::copy_file(source_path, destination_path); } assert(false); @@ -130,7 +128,7 @@ class umap_sparse_segment_storage { /// \param vm_region The address of the VM region. /// \param initial_segment_size_hint Not used. /// \return Returns true on success; otherwise, false. - bool create(const std::string &base_path, const size_type vm_region_size, + bool create(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, [[maybe_unused]] const size_type initial_segment_size_hint) { assert(!priv_inited()); @@ -166,7 +164,7 @@ class umap_sparse_segment_storage { /// \param vm_region The address of the VM region. /// \param read_only If this option is true, opens the datastore with read /// only mode. \return Returns true on success; otherwise, false. - bool open(const std::string &base_path, const size_type vm_region_size, + bool open(const std::filesystem::path &base_path, const size_type vm_region_size, void *const vm_region, const bool read_only) { assert(!priv_inited()); // TODO: align those values to pge size @@ -281,7 +279,7 @@ class umap_sparse_segment_storage { m_segment_size > 0 && m_segment && !m_base_path.empty()); } - bool priv_create_and_map_file(const std::string &base_path, + bool priv_create_and_map_file(const std::filesystem::path &base_path, const size_type file_size, void *const addr) const { assert(!m_segment || @@ -305,7 +303,7 @@ class umap_sparse_segment_storage { return file_granularity; } - bool priv_map_file_create(const std::string &path, const size_type file_size, + bool priv_map_file_create(const std::filesystem::path &path, const size_type file_size, void *const addr) const { assert(!path.empty()); assert(file_size > 0); @@ -335,7 +333,7 @@ class umap_sparse_segment_storage { return true; } - bool priv_map_file_open(const std::string &path, const size_type file_size, + bool priv_map_file_open(const std::filesystem::path &path, const size_type file_size, void *const addr, const bool read_only) { assert(!path.empty()); assert(addr); @@ -436,6 +434,6 @@ class umap_sparse_segment_storage { }; } // namespace kernel -} // namespace metall +} // namespace dice::copperr #endif // METALL_DETAILL_SEGMENT_STORAGE_UMAP_SPARSE_SEGMENT_STORAGE_HPP diff --git a/libs/copperr/src/dice/copperr/logger.hpp b/libs/copperr/src/dice/copperr/logger.hpp new file mode 100644 index 00000000..b7ba4cf9 --- /dev/null +++ b/libs/copperr/src/dice/copperr/logger.hpp @@ -0,0 +1,116 @@ +#ifndef METALL_LOGGER_HPP +#define METALL_LOGGER_HPP + +#include +#include +#include +#include + +#include + +namespace dice::copperr::logger { + /** + * Level of log messages + */ + enum struct level : std::underlying_type_t { + error = COPPERR_LL_ERROR, + warn = COPPERR_LL_WARN, + info = COPPERR_LL_INFO, + debug = COPPERR_LL_DEBUG, + trace = COPPERR_LL_TRACE, + }; + + /** + * Logs a message + * + * @param lvl log level + * @param sloc source location the message originated from + * @param fmt format specifier for the message + * @param args arguments for fmt + */ + template + void log(level lvl, std::source_location sloc, std::format_string fmt, Args &&...args) { + auto const msg = std::format(fmt, std::forward(args)...); + copperr_log(static_cast(lvl), sloc.file_name(), sloc.line(), sloc.function_name(), msg.c_str()); + } + + /** + * Logs a message about the current value of errno, similar to perror + * + * @param lvl log level + * @param sloc source location the message origininated from + * @param fmt format specifier for the message + * @param args arguments for fmt + */ + template + void errno_log(level lvl, std::source_location sloc, std::format_string fmt, Args &&...args) { + auto msg = std::format(fmt, std::forward(args)...); + msg += std::format(": {}", strerror(errno)); + copperr_log(static_cast(lvl), sloc.file_name(), sloc.line(), sloc.function_name(), msg.c_str()); + } +} // namespace dice::copperr::logger + +/** + * Convenience macro for calling dice::copperr::logger::log. + * Automatically populates the function argument with the name of the current function, and forwards the rest (i.e. lvl, fmt, args...) + */ +#define METALL_LOG(lvl, fmt, ...) ::dice::copperr::logger::log((lvl), ::std::source_location::current(), (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_LOG that sets lvl to error + */ +#define METALL_ERROR(fmt, ...) METALL_LOG(::dice::copperr::logger::level::error, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_LOG that sets lvl to warn + */ +#define METALL_WARN(fmt, ...) METALL_LOG(::dice::copperr::logger::level::warn, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_LOG that sets lvl to info + */ +#define METALL_INFO(fmt, ...) METALL_LOG(::dice::copperr::logger::level::info, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_LOG that sets lvl to debug + */ +#define METALL_DEBUG(fmt, ...) METALL_LOG(::dice::copperr::logger::level::debug, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_LOG that sets lvl to trace + */ +#define METALL_TRACE(fmt, ...) METALL_LOG(::dice::copperr::logger::level::trace, (fmt) __VA_OPT__(,) __VA_ARGS__) + + +/** + * Convenience macro for calling dice::copperr::logger::errno_log. + * Automatically populates the function argument with the name of the current function, and forwards the rest (i.e. lvl, fmt, args...) + */ +#define METALL_ERRNO_LOG(lvl, fmt, ...) ::dice::copperr::logger::errno_log((lvl), ::std::source_location::current(), (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_ERRNO_LOG that sets lvl to error + */ +#define METALL_ERRNO_ERROR(fmt, ...) METALL_ERRNO_LOG(::dice::copperr::logger::level::error, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_ERRNO_LOG that sets lvl to warn + */ +#define METALL_ERRNO_WARN(fmt, ...) METALL_ERRNO_LOG(::dice::copperr::logger::level::warn, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_ERRNO_LOG that sets lvl to info + */ +#define METALL_ERRNO_INFO(fmt, ...) METALL_ERRNO_LOG(::dice::copperr::logger::level::info, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_ERRNO_LOG that sets lvl to debug + */ +#define METALL_ERRNO_DEBUG(fmt, ...) METALL_ERRNO_LOG(::dice::copperr::logger::level::debug, (fmt) __VA_OPT__(,) __VA_ARGS__) + +/** + * Convenience macro for METALL_ERRNO_LOG that sets lvl to trace + */ +#define METALL_ERRNO_TRACE(fmt, ...) METALL_ERRNO_LOG(::dice::copperr::logger::level::trace, (fmt) __VA_OPT__(,) __VA_ARGS__) + +#endif // METALL_LOGGER_HPP diff --git a/libs/copperr/src/dice/copperr/logger_interface.h b/libs/copperr/src/dice/copperr/logger_interface.h new file mode 100644 index 00000000..1753c653 --- /dev/null +++ b/libs/copperr/src/dice/copperr/logger_interface.h @@ -0,0 +1,33 @@ +#ifndef METALL_LOGGER_INTERFACE_H +#define METALL_LOGGER_INTERFACE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Level of log messages + */ +typedef enum copperr_log_level { + /// Errors + COPPERR_LL_ERROR = 0, + /// Warnings + COPPERR_LL_WARN = 1, + /// Informational + COPPERR_LL_INFO = 2, + /// Verbose logging + COPPERR_LL_DEBUG = 3, + /// Very Verbose logging + COPPERR_LL_TRACE = 4, +} copperr_log_level; + +/// \brief Log a message +void copperr_log(copperr_log_level lvl, char const *file, size_t line, char const *function, char const *message); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // METALL_LOGGER_INTERFACE_H diff --git a/include/metall/object_attribute_accessor.hpp b/libs/copperr/src/dice/copperr/object_attribute_accessor.hpp similarity index 91% rename from include/metall/object_attribute_accessor.hpp rename to libs/copperr/src/dice/copperr/object_attribute_accessor.hpp index 291dcb58..725debfb 100644 --- a/include/metall/object_attribute_accessor.hpp +++ b/libs/copperr/src/dice/copperr/object_attribute_accessor.hpp @@ -9,12 +9,12 @@ #include #include -#include -#include +#include +#include -namespace metall { +namespace dice::copperr { -/// \namespace metall::attraccs_detail +/// \namespace dice::copperr::attraccs_detail /// \brief Namespace for the details of attribute accessor namespace attraccs_detail { @@ -29,7 +29,7 @@ class general_named_object_attr_accessor { struct core_data { object_directory_type object_directory{}; - std::string object_attribute_file_path{}; + std::filesystem::path object_attribute_file_path{}; }; public: @@ -47,18 +47,17 @@ class general_named_object_attr_accessor { general_named_object_attr_accessor() noexcept = default; explicit general_named_object_attr_accessor( - const std::string &object_attribute_file_path) noexcept { + const std::filesystem::path &object_attribute_file_path) noexcept { priv_alloc_core_data(); try { m_core_data->object_attribute_file_path = object_attribute_file_path; const bool succeeded = m_core_data->object_directory.deserialize( - m_core_data->object_attribute_file_path.c_str()); + m_core_data->object_attribute_file_path); if (!succeeded) { m_core_data.reset(nullptr); } } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to initialize the core data"); + METALL_ERROR("Filed to initialize the core data"); m_core_data.reset(nullptr); } } @@ -144,9 +143,8 @@ class general_named_object_attr_accessor { if (!m_core_data->object_directory.set_description(position, description) || !m_core_data->object_directory.serialize( - m_core_data->object_attribute_file_path.c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to set description"); + m_core_data->object_attribute_file_path)) { + METALL_ERROR("Filed to set description"); return false; } @@ -180,8 +178,7 @@ class general_named_object_attr_accessor { try { m_core_data = other.m_core_data; } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to copy the core data"); + METALL_ERROR("Filed to copy the core data"); m_core_data.reset(nullptr); return false; } @@ -242,7 +239,7 @@ class unique_object_attr_accessor unique_object_attr_accessor() noexcept = default; explicit unique_object_attr_accessor( - const std::string &object_attribute_file_path) noexcept + const std::filesystem::path &object_attribute_file_path) noexcept : base_type(object_attribute_file_path) {} /// \brief Counts the number of objects with the name. @@ -324,7 +321,7 @@ class anonymous_object_attr_accessor { struct core_data { object_directory_type object_directory{}; - std::string object_attribute_file_path{}; + std::filesystem::path object_attribute_file_path{}; }; public: @@ -342,18 +339,17 @@ class anonymous_object_attr_accessor { anonymous_object_attr_accessor() noexcept = default; explicit anonymous_object_attr_accessor( - const std::string &object_attribute_file_path) noexcept { + const std::filesystem::path &object_attribute_file_path) noexcept { priv_alloc_core_data(); try { m_core_data->object_attribute_file_path = object_attribute_file_path; const bool succeeded = m_core_data->object_directory.deserialize( - m_core_data->object_attribute_file_path.c_str()); + m_core_data->object_attribute_file_path); if (!succeeded) { m_core_data.reset(nullptr); } } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to initialize the core data"); + METALL_ERROR("Filed to initialize the core data"); m_core_data.reset(nullptr); } } @@ -418,9 +414,8 @@ class anonymous_object_attr_accessor { if (!m_core_data->object_directory.set_description(position, description) || !m_core_data->object_directory.serialize( - m_core_data->object_attribute_file_path.c_str())) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to set description"); + m_core_data->object_attribute_file_path)) { + METALL_ERROR("Filed to set description"); return false; } @@ -443,8 +438,7 @@ class anonymous_object_attr_accessor { try { m_core_data = other.m_core_data; } catch (...) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Filed to copy the core data"); + METALL_ERROR("Filed to copy the core data"); m_core_data.reset(nullptr); return false; } @@ -453,6 +447,6 @@ class anonymous_object_attr_accessor { std::unique_ptr m_core_data{nullptr}; }; -} // namespace metall +} // namespace dice::copperr #endif // METALL_KERNEL_OBJECT_ATTRIBUTE_ACCESSOR_HPP diff --git a/include/metall/offset_ptr.hpp b/libs/copperr/src/dice/copperr/offset_ptr.hpp similarity index 93% rename from include/metall/offset_ptr.hpp rename to libs/copperr/src/dice/copperr/offset_ptr.hpp index 035e1394..cd4762c0 100644 --- a/include/metall/offset_ptr.hpp +++ b/libs/copperr/src/dice/copperr/offset_ptr.hpp @@ -9,7 +9,7 @@ #include #include -namespace metall { +namespace dice::copperr { /// \tparam T A type. /// \brief Holds an offset between the address pointing at and itself. @@ -18,7 +18,7 @@ using offset_ptr = boost::interprocess::offset_ptr; /// \brief Convert a offset pointer to the corresponding raw pointer using boost::interprocess::ipcdetail::to_raw_pointer; -} // namespace metall +} // namespace dice::copperr /// \example offset_pointer.cpp /// This is an example of how to use offset_pointer. diff --git a/include/metall/stl_allocator.hpp b/libs/copperr/src/dice/copperr/stl_allocator.hpp similarity index 88% rename from include/metall/stl_allocator.hpp rename to libs/copperr/src/dice/copperr/stl_allocator.hpp index eb1297d1..8c39cafd 100644 --- a/include/metall/stl_allocator.hpp +++ b/libs/copperr/src/dice/copperr/stl_allocator.hpp @@ -12,14 +12,14 @@ #include #include -#include -#include +#include +#include -namespace metall { +namespace dice::copperr { /// \brief A STL compatible allocator. /// \tparam T A object type. -/// \tparam metall_manager_kernel_type A manager kernel type. +/// \tparam copperr_manager_kernel_type A manager kernel type. /// \warning /// This allocator does not define propagate_on_* types, as same as /// Boost.Interprocess. Those types are going to be std::false_type in @@ -30,7 +30,7 @@ namespace metall { /// allocated by different Metall managers invokes copy operations instead of /// move operations. Also, swapping containers allocated by different Metall /// managers will result in undefined behavior. -template +template class stl_allocator { public: // -------------------- // @@ -38,7 +38,7 @@ class stl_allocator { // -------------------- // using value_type = T; using pointer = typename std::pointer_traits< - typename metall_manager_kernel_type::void_pointer>:: + typename copperr_manager_kernel_type::void_pointer>:: template rebind; using const_pointer = typename std::pointer_traits::template rebind; @@ -49,7 +49,7 @@ class stl_allocator { using difference_type = typename std::pointer_traits::difference_type; using size_type = typename std::make_unsigned::type; - using manager_kernel_type = metall_manager_kernel_type; + using manager_kernel_type = copperr_manager_kernel_type; /// \brief Makes another allocator type for type T2 /// \tparam T2 The type of the object @@ -161,14 +161,12 @@ class stl_allocator { } if (!get_pointer_to_manager_kernel()) { - logger::out(logger::level::error, __FILE__, __LINE__, - "nullptr: cannot access to manager kernel"); + METALL_ERROR("nullptr: cannot access to manager kernel"); throw std::bad_alloc(); } auto manager_kernel = *get_pointer_to_manager_kernel(); if (!manager_kernel) { - logger::out(logger::level::error, __FILE__, __LINE__, - "nullptr: cannot access to manager kernel"); + METALL_ERROR("nullptr: cannot access to manager kernel"); throw std::bad_alloc(); } @@ -184,14 +182,12 @@ class stl_allocator { void priv_deallocate(pointer ptr, [[maybe_unused]] const size_type size) const noexcept { if (!get_pointer_to_manager_kernel()) { - logger::out(logger::level::error, __FILE__, __LINE__, - "nullptr: cannot access to manager kernel"); + METALL_ERROR("nullptr: cannot access to manager kernel"); return; } auto manager_kernel = *get_pointer_to_manager_kernel(); if (!manager_kernel) { - logger::out(logger::level::error, __FILE__, __LINE__, - "nullptr: cannot access to manager kernel"); + METALL_ERROR("nullptr: cannot access to manager kernel"); return; } manager_kernel->deallocate(to_raw_pointer(ptr)); @@ -203,14 +199,13 @@ class stl_allocator { template void priv_construct(const pointer &ptr, arg_types &&...args) const { - ::new ((void *)to_raw_pointer(ptr)) + ::new (to_raw_pointer(ptr)) value_type(std::forward(args)...); } void priv_destroy(const pointer &ptr) const { if (!ptr) { - logger::out(logger::level::error, __FILE__, __LINE__, - "pointer is nullptr"); + METALL_ERROR("pointer is nullptr"); } (*ptr).~value_type(); } @@ -240,6 +235,6 @@ inline bool operator!=(const stl_allocator &rhd, return !(rhd == lhd); } -} // namespace metall +} // namespace dice::copperr #endif // METALL_STL_ALLOCATOR_HPP diff --git a/include/metall/tags.hpp b/libs/copperr/src/dice/copperr/tags.hpp similarity index 92% rename from include/metall/tags.hpp rename to libs/copperr/src/dice/copperr/tags.hpp index 7ae67b98..34e777b1 100644 --- a/include/metall/tags.hpp +++ b/libs/copperr/src/dice/copperr/tags.hpp @@ -6,9 +6,9 @@ #ifndef METALL_TAGS_HPP #define METALL_TAGS_HPP -#include +#include -namespace metall { +namespace dice::copperr { /// \brief Tag type to create the segment always. /// The existing segment with the same name is over written. @@ -37,6 +37,6 @@ struct open_read_only_t {}; /// \brief Tag to construct a unique instance of a type [[maybe_unused]] static const mtlldetail::unique_instance_t *unique_instance = nullptr; -} // namespace metall +} // namespace dice::copperr #endif // METALL_TAGS_HPP diff --git a/include/metall/utility/container_of_containers_iterator_adaptor.hpp b/libs/copperr/src/dice/copperr/utility/container_of_containers_iterator_adaptor.hpp similarity index 97% rename from include/metall/utility/container_of_containers_iterator_adaptor.hpp rename to libs/copperr/src/dice/copperr/utility/container_of_containers_iterator_adaptor.hpp index 4d713652..09c99b72 100644 --- a/include/metall/utility/container_of_containers_iterator_adaptor.hpp +++ b/libs/copperr/src/dice/copperr/utility/container_of_containers_iterator_adaptor.hpp @@ -8,9 +8,9 @@ #include -/// \namespace metall::utility +/// \namespace dice::copperr::utility /// \brief Namespace for utility items -namespace metall::utility { +namespace dice::copperr::utility { /// \brief Utility class that provides an iterator for a container of /// containers, e.g., map of vectors This is an experimental implementation and @@ -135,6 +135,6 @@ inline bool operator!=( return !(lhs == rhs); } -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_CONTAINER_OF_CONTAINERS_ITERATOR_ADAPTOR_HPP diff --git a/include/metall/utility/metall_mpi_adaptor.hpp b/libs/copperr/src/dice/copperr/utility/copperr_mpi_adaptor.hpp similarity index 82% rename from include/metall/utility/metall_mpi_adaptor.hpp rename to libs/copperr/src/dice/copperr/utility/copperr_mpi_adaptor.hpp index 9af343a8..df9ce6a1 100644 --- a/include/metall/utility/metall_mpi_adaptor.hpp +++ b/libs/copperr/src/dice/copperr/utility/copperr_mpi_adaptor.hpp @@ -8,26 +8,26 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace metall::utility { +namespace dice::copperr::utility { namespace { -namespace ds = metall::utility::mpi_datastore; +namespace ds = dice::copperr::utility::mpi_datastore; } /// \brief A utility class for using Metall with MPI /// This is an experimental implementation -class metall_mpi_adaptor { +class copperr_mpi_adaptor { public: // -------------------- // // Public types and static values // -------------------- // /// \brief Metall manager type - using manager_type = metall::manager; + using manager_type = dice::copperr::manager; // -------------------- // // Constructor & assign operator @@ -35,16 +35,16 @@ class metall_mpi_adaptor { /// \brief Opens an existing Metall datastore. /// \param root_dir_prefix A root directory path of a Metall datastore. /// \param comm A MPI communicator. - metall_mpi_adaptor(metall::open_only_t, const std::string &root_dir_prefix, + copperr_mpi_adaptor(dice::copperr::open_only_t, const std::string &root_dir_prefix, const MPI_Comm &comm = MPI_COMM_WORLD) : m_mpi_comm(comm), m_root_dir_prefix(root_dir_prefix), - m_local_metall_manager(nullptr) { + m_local_copperr_manager(nullptr) { if (!priv_verify_num_partitions(root_dir_prefix, comm)) { ::MPI_Abort(comm, -1); } - m_local_metall_manager = std::make_unique( - metall::open_only, + m_local_copperr_manager = std::make_unique( + dice::copperr::open_only, ds::make_local_dir_path(m_root_dir_prefix, priv_mpi_comm_rank(comm)) .c_str()); } @@ -52,17 +52,17 @@ class metall_mpi_adaptor { /// \brief Opens an existing Metall datastore with the read-only mode. /// \param root_dir_prefix A root directory path of a Metall datastore. /// \param comm A MPI communicator. - metall_mpi_adaptor(metall::open_read_only_t, + copperr_mpi_adaptor(dice::copperr::open_read_only_t, const std::string &root_dir_prefix, const MPI_Comm &comm = MPI_COMM_WORLD) : m_mpi_comm(comm), m_root_dir_prefix(root_dir_prefix), - m_local_metall_manager(nullptr) { + m_local_copperr_manager(nullptr) { if (!priv_verify_num_partitions(root_dir_prefix, comm)) { ::MPI_Abort(comm, -1); } - m_local_metall_manager = std::make_unique( - metall::open_read_only, + m_local_copperr_manager = std::make_unique( + dice::copperr::open_read_only, ds::make_local_dir_path(m_root_dir_prefix, priv_mpi_comm_rank(comm)) .c_str()); } @@ -74,15 +74,15 @@ class metall_mpi_adaptor { /// \param overwrite If true, overwrite an existing datastore. /// This mode does not overwrite an existing datastore if it is not Metall /// datastore created by the same number of MPI processes. - metall_mpi_adaptor(metall::create_only_t, const std::string &root_dir_prefix, + copperr_mpi_adaptor(dice::copperr::create_only_t, const std::string &root_dir_prefix, const MPI_Comm &comm = MPI_COMM_WORLD, bool overwrite = false) : m_mpi_comm(comm), m_root_dir_prefix(root_dir_prefix), - m_local_metall_manager(nullptr) { + m_local_copperr_manager(nullptr) { priv_setup_root_dir(root_dir_prefix, overwrite, comm); - m_local_metall_manager = std::make_unique( - metall::create_only, + m_local_copperr_manager = std::make_unique( + dice::copperr::create_only, ds::make_local_dir_path(m_root_dir_prefix, priv_mpi_comm_rank(comm)) .c_str()); } @@ -95,16 +95,16 @@ class metall_mpi_adaptor { /// \param overwrite If true, overwrite an existing datastore. /// This mode does not overwrite an existing datastore if it is not Metall /// datastore created by the same number of MPI processes. - metall_mpi_adaptor(metall::create_only_t, const std::string &root_dir_prefix, + copperr_mpi_adaptor(dice::copperr::create_only_t, const std::string &root_dir_prefix, const std::size_t capacity, const MPI_Comm &comm = MPI_COMM_WORLD, bool overwrite = false) : m_mpi_comm(comm), m_root_dir_prefix(root_dir_prefix), - m_local_metall_manager(nullptr) { + m_local_copperr_manager(nullptr) { priv_setup_root_dir(root_dir_prefix, overwrite, comm); - m_local_metall_manager = std::make_unique( - metall::create_only, + m_local_copperr_manager = std::make_unique( + dice::copperr::create_only, ds::make_local_dir_path(m_root_dir_prefix, priv_mpi_comm_rank(comm)) .c_str(), capacity); @@ -112,8 +112,8 @@ class metall_mpi_adaptor { /// \brief Destructor that globally synchronizes the close operations of all /// sub-Metall datastores. - ~metall_mpi_adaptor() { - m_local_metall_manager.reset(nullptr); + ~copperr_mpi_adaptor() { + m_local_copperr_manager.reset(nullptr); priv_mpi_barrier(m_mpi_comm); } @@ -123,23 +123,23 @@ class metall_mpi_adaptor { /// \brief Returns the Metall manager object of the process. /// \return A reference to a Metall manager object. - manager_type &get_local_manager() { return *m_local_metall_manager; } + manager_type &get_local_manager() { return *m_local_copperr_manager; } /// \brief Returns the Metall manager object of the process. /// \return A reference to a Metall manager object. const manager_type &get_local_manager() const { - return *m_local_metall_manager; + return *m_local_copperr_manager; } /// \brief Returns the root path of a Metall datastore /// \return A root path of a Metall datastore. - std::string root_dir_path() const { + std::filesystem::path root_dir_path() const { return ds::make_root_dir_path(m_root_dir_prefix); } /// \brief Returns the path of the sub-Metall datastore of the process. /// \return A path of a sub-Metall datastore. - std::string local_dir_path() const { + std::filesystem::path local_dir_path() const { return ds::make_local_dir_path(ds::make_root_dir_path(m_root_dir_prefix), priv_mpi_comm_rank(m_mpi_comm)); } @@ -173,7 +173,7 @@ class metall_mpi_adaptor { ss << "Source directory is not consistnt (may not have closed properly " "or may still be open): " << source_dir_path; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR(ss.str().c_str()); } return false; } @@ -198,7 +198,7 @@ class metall_mpi_adaptor { priv_setup_root_dir(destination_dir_path, overwrite, m_mpi_comm); const int rank = priv_mpi_comm_rank(m_mpi_comm); return priv_global_and( - m_local_metall_manager->snapshot( + m_local_copperr_manager->snapshot( ds::make_local_dir_path(destination_dir_path, rank).c_str()), m_mpi_comm); } @@ -214,7 +214,7 @@ class metall_mpi_adaptor { const int rank = priv_mpi_comm_rank(comm); const int size = priv_mpi_comm_size(comm); - if (!metall::mtlldetail::file_exist( + if (!copperr::mtlldetail::file_exist( ds::make_root_dir_path(root_dir_prefix))) { // As long as the root directory does not exist, we consider it as a // success. @@ -222,17 +222,17 @@ class metall_mpi_adaptor { } // ----- Check if this is a Metall datastore ----- // - bool metall_dir = true; - if (!metall::mtlldetail::file_exist( + bool copperr_dir = true; + if (!copperr::mtlldetail::file_exist( ds::make_root_dir_path(root_dir_prefix) + "/" + k_datastore_mark_file_name)) { - metall_dir = false; + copperr_dir = false; } - if (!priv_global_and(metall_dir, comm)) { + if (!priv_global_and(copperr_dir, comm)) { if (rank == 0) { std::string s("This is not a Metall datastore: " + ds::make_root_dir_path(root_dir_prefix)); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR("{}", s); } return false; } @@ -244,13 +244,13 @@ class metall_mpi_adaptor { bool ret = true; for (int i = 0; i < size; ++i) { if (i == rank) { - if (metall::mtlldetail::file_exist( + if (dice::copperr::mtlldetail::file_exist( ds::make_root_dir_path(root_dir_prefix)) && - !metall::mtlldetail::remove_file( + !copperr::mtlldetail::remove_file( ds::make_root_dir_path(root_dir_prefix))) { std::string s("Failed to remove directory: " + ds::make_root_dir_path(root_dir_prefix)); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ret = false; } } @@ -284,9 +284,9 @@ class metall_mpi_adaptor { private: static constexpr const char *k_datastore_mark_file_name = - "metall_mpi_datastore"; + "copperr_mpi_datastore"; static constexpr const char *k_partition_size_file_name = - "metall_mpi_adaptor_partition_size"; + "copperr_mpi_adaptor_partition_size"; // -------------------- // // Private methods @@ -314,31 +314,31 @@ class metall_mpi_adaptor { } // Make sure the root directory and a file with the same name do not exist - const auto local_ret = metall::mtlldetail::file_exist(root_dir_path); + const auto local_ret = dice::copperr::mtlldetail::file_exist(root_dir_path); if (priv_global_or(local_ret, comm)) { if (rank == 0) { std::string s( "Root directory (or a file with the same name) already exists: " + root_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } } priv_mpi_barrier(comm); for (int i = 0; i < size; ++i) { - if (i == rank && !metall::mtlldetail::directory_exist(root_dir_path)) { - if (!metall::mtlldetail::create_directory(root_dir_path)) { + if (i == rank && !copperr::mtlldetail::directory_exist(root_dir_path)) { + if (!copperr::mtlldetail::create_directory(root_dir_path)) { std::string s("Failed to create directory: " + root_dir_path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } const std::string mark_file = root_dir_path + "/" + k_datastore_mark_file_name; - if (!metall::mtlldetail::create_file(mark_file)) { + if (!copperr::mtlldetail::create_file(mark_file)) { std::string s("Failed to create file: " + mark_file); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } @@ -357,13 +357,13 @@ class metall_mpi_adaptor { std::ofstream ofs(path); if (!ofs) { std::string s("Failed to create a file: " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } ofs << size; if (!ofs) { std::string s("Failed to write data to a file: " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } ofs.close(); @@ -376,13 +376,13 @@ class metall_mpi_adaptor { std::ifstream ifs(path); if (!ifs) { std::string s("Failed to open a file: " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } int read_size = -1; if (!(ifs >> read_size)) { std::string s("Failed to read data from: " + path); - logger::out(logger::level::error, __FILE__, __LINE__, s.c_str()); + METALL_ERROR(s.c_str()); ::MPI_Abort(comm, -1); } @@ -402,7 +402,7 @@ class metall_mpi_adaptor { std::stringstream ss; ss << "Invalid number of MPI processes (provided " << size << ", " << "expected " << read_size << ")"; - logger::out(logger::level::error, __FILE__, __LINE__, ss.str().c_str()); + METALL_ERROR("{}", ss.str()); } } return priv_global_and(correct_mpi_size, comm); @@ -449,8 +449,7 @@ class metall_mpi_adaptor { static int priv_determine_local_root_rank(const MPI_Comm &comm) { const int rank = mpi::determine_local_root(comm); if (rank == -1) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed at determining a local root rank"); + METALL_ERROR("Failed at determining a local root rank"); ::MPI_Abort(comm, -1); } return rank; @@ -458,9 +457,9 @@ class metall_mpi_adaptor { MPI_Comm m_mpi_comm; std::string m_root_dir_prefix; - std::unique_ptr m_local_metall_manager; + std::unique_ptr m_local_copperr_manager; }; -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_METALL_MPI_ADAPTOR_HPP diff --git a/include/metall/utility/metall_mpi_datastore.hpp b/libs/copperr/src/dice/copperr/utility/copperr_mpi_datastore.hpp similarity index 83% rename from include/metall/utility/metall_mpi_datastore.hpp rename to libs/copperr/src/dice/copperr/utility/copperr_mpi_datastore.hpp index 949882fe..fa31b401 100644 --- a/include/metall/utility/metall_mpi_datastore.hpp +++ b/libs/copperr/src/dice/copperr/utility/copperr_mpi_datastore.hpp @@ -8,9 +8,9 @@ #include -/// \namespace metall::utility::mpi_datastore +/// \namespace dice::copperr::utility::mpi_datastore /// \brief Namespace for MPI datastore -namespace metall::utility::mpi_datastore { +namespace dice::copperr::utility::mpi_datastore { /// \brief Makes a path of a root directory. /// The MPI ranks that share the same storage space create their data stores @@ -24,7 +24,7 @@ inline std::string make_root_dir_path(const std::string &root_dir_prefix) { /// \param root_dir_prefix A prefix of a root directory path. /// \param rank A MPI rank. /// \return A path to a local data store directory. -/// The path can be passed to, for example, metall::manager to perform +/// The path can be passed to, for example, dice::copperr::manager to perform /// operations. inline std::string make_local_dir_path(const std::string &root_dir_prefix, const int rank) { @@ -32,6 +32,6 @@ inline std::string make_local_dir_path(const std::string &root_dir_prefix, std::to_string(rank); } -} // namespace metall::utility::mpi_datastore +} // namespace dice::copperr::utility::mpi_datastore #endif // METALL_UTILITY_METALL_MPI_DATASTORE_HPP diff --git a/include/metall/utility/datastore_ls.hpp b/libs/copperr/src/dice/copperr/utility/datastore_ls.hpp similarity index 87% rename from include/metall/utility/datastore_ls.hpp rename to libs/copperr/src/dice/copperr/utility/datastore_ls.hpp index cee205be..8c57c6f5 100644 --- a/include/metall/utility/datastore_ls.hpp +++ b/libs/copperr/src/dice/copperr/utility/datastore_ls.hpp @@ -13,9 +13,9 @@ #include #include -#include +#include -namespace metall::utility { +namespace dice::copperr::utility { #ifndef DOXYGEN_SKIP namespace datastore_ls_detail { @@ -62,10 +62,10 @@ inline void aligned_show(const std::vector> &buf) { } // namespace datastore_ls_detail #endif // DOXYGEN_SKIP -inline void ls_named_object(const std::string &datastore_path) { +inline void ls_named_object(const std::filesystem::path &datastore_path) { std::cout << "[Named Object]" << std::endl; auto accessor = - metall::manager::access_named_object_attribute(datastore_path.c_str()); + dice::copperr::manager::access_named_object_attribute(datastore_path); if (!accessor.good()) { std::cerr << "Failed to open datastore" << std::endl; std::abort(); @@ -86,10 +86,10 @@ inline void ls_named_object(const std::string &datastore_path) { datastore_ls_detail::aligned_show(buf); } -inline void ls_unique_object(const std::string &datastore_path) { +inline void ls_unique_object(const std::filesystem::path &datastore_path) { std::cout << "[Unique Object]" << std::endl; auto accessor = - metall::manager::access_unique_object_attribute(datastore_path.c_str()); + dice::copperr::manager::access_unique_object_attribute(datastore_path); if (!accessor.good()) { std::cerr << "Failed to open datastore" << std::endl; std::abort(); @@ -110,9 +110,9 @@ inline void ls_unique_object(const std::string &datastore_path) { datastore_ls_detail::aligned_show(buf); } -inline void ls_anonymous_object(const std::string &datastore_path) { +inline void ls_anonymous_object(const std::filesystem::path &datastore_path) { std::cout << "[Anonymous Object]" << std::endl; - auto accessor = metall::manager::access_anonymous_object_attribute( + auto accessor = dice::copperr::manager::access_anonymous_object_attribute( datastore_path.c_str()); if (!accessor.good()) { std::cerr << "Failed to open datastore" << std::endl; @@ -133,6 +133,6 @@ inline void ls_anonymous_object(const std::string &datastore_path) { datastore_ls_detail::aligned_show(buf); } -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_DATASTORE_LS_HPP diff --git a/include/metall/utility/fallback_allocator_adaptor.hpp b/libs/copperr/src/dice/copperr/utility/fallback_allocator_adaptor.hpp similarity index 96% rename from include/metall/utility/fallback_allocator_adaptor.hpp rename to libs/copperr/src/dice/copperr/utility/fallback_allocator_adaptor.hpp index 8e93e70c..6a7555ed 100644 --- a/include/metall/utility/fallback_allocator_adaptor.hpp +++ b/libs/copperr/src/dice/copperr/utility/fallback_allocator_adaptor.hpp @@ -10,27 +10,27 @@ #include #include -#include +#include -namespace metall::utility { +namespace dice::copperr::utility { /// \brief A STL compatible allocator which fallbacks to a heap allocator (e.g., /// malloc) if its constructor receives no argument. \tparam primary_alloc A -/// primary allocator type, i.e., metall::stl_allocator. +/// primary allocator type, i.e., dice::copperr::stl_allocator. /// /// \details /// Using this allocator, the following code will work: /// \code /// { /// using alloc = -/// fallback_allocator_adaptor>; +/// fallback_allocator_adaptor>; /// vector temp_vec; // Allocate an vector object temporarily in /// 'DRAM'. /// } /// \endcode /// \attention /// The purpose of this allocator is providing a way to quickly integrate Metall -/// into an application which wants to allocate 'metallized' classes temporarily +/// into an application which wants to allocate 'copperrized' classes temporarily /// in 'DRAM' occasionally. This allocator could cause difficult bugs to debug. /// Use this allocator with great care. template @@ -250,7 +250,7 @@ class fallback_allocator_adaptor { template void priv_fallback_construct(const pointer &ptr, arg_types &&...args) const { - ::new ((void *)to_raw_pointer(ptr)) + ::new (to_raw_pointer(ptr)) value_type(std::forward(args)...); } @@ -275,7 +275,7 @@ inline bool operator!=( return !(rhd == lhd); } -} // namespace metall::utility +} // namespace dice::copperr::utility /// \example fallback_allocator_adaptor.cpp /// This is an example of how to use fallback_allocator_adaptor. diff --git a/include/metall/utility/filesystem.hpp b/libs/copperr/src/dice/copperr/utility/filesystem.hpp similarity index 67% rename from include/metall/utility/filesystem.hpp rename to libs/copperr/src/dice/copperr/utility/filesystem.hpp index 0b9bc45f..8339e4ae 100644 --- a/include/metall/utility/filesystem.hpp +++ b/libs/copperr/src/dice/copperr/utility/filesystem.hpp @@ -6,17 +6,17 @@ #ifndef METALL_UTILITY_FILESYSTEM_HPP #define METALL_UTILITY_FILESYSTEM_HPP -#include +#include -namespace metall::utility::filesystem { +namespace dice::copperr::utility::filesystem { /// \brief Remove a file or directory /// \return Upon successful completion, returns true; otherwise, false is /// returned. If the file or directory does not exist, true is returned. -inline bool remove(std::string_view path) { - return metall::mtlldetail::remove_file(path.data()); +inline bool remove(const std::filesystem::path &path) { + return dice::copperr::mtlldetail::remove_file(path); } -} // namespace metall::utility::filesystem +} // namespace dice::copperr::utility::filesystem #endif // METALL_UTILITY_FILESYSTEM_HPP diff --git a/include/metall/utility/hash.hpp b/libs/copperr/src/dice/copperr/utility/hash.hpp similarity index 75% rename from include/metall/utility/hash.hpp rename to libs/copperr/src/dice/copperr/utility/hash.hpp index b1d63119..402e7da1 100644 --- a/include/metall/utility/hash.hpp +++ b/libs/copperr/src/dice/copperr/utility/hash.hpp @@ -6,22 +6,22 @@ #ifndef METALL_UTILITY_HASH_HPP #define METALL_UTILITY_HASH_HPP -#include +#include -namespace metall::utility { +namespace dice::copperr::utility { /// \brief Hash a value of type T. /// \tparam T Data type to hash. /// If void is specified, the hash data type is determined by () operator. /// \tparam seed A seed value used for hashing. template -using hash = metall::mtlldetail::hash; +using hash = dice::copperr::mtlldetail::hash; /// \brief Hash function for std::string-compatible string container. /// \tparam seed A seed value used for hashing. template -using str_hash = metall::mtlldetail::str_hash; +using str_hash = dice::copperr::mtlldetail::str_hash; -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_HASH_HPP diff --git a/include/metall/utility/mpi.hpp b/libs/copperr/src/dice/copperr/utility/mpi.hpp similarity index 76% rename from include/metall/utility/mpi.hpp rename to libs/copperr/src/dice/copperr/utility/mpi.hpp index 8c19e048..b6751247 100644 --- a/include/metall/utility/mpi.hpp +++ b/libs/copperr/src/dice/copperr/utility/mpi.hpp @@ -12,19 +12,18 @@ #include -#include -#include -#include +#include +#include +#include -/// \namespace metall::utility::mpi +/// \namespace dice::copperr::utility::mpi /// \brief Namespace for MPI utilities -namespace metall::utility::mpi { +namespace dice::copperr::utility::mpi { inline int comm_rank(const MPI_Comm &comm) { int rank; if (::MPI_Comm_rank(comm, &rank) != MPI_SUCCESS) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed MPI_Comm_rank"); + METALL_ERROR("Failed MPI_Comm_rank"); return -1; } return rank; @@ -33,8 +32,7 @@ inline int comm_rank(const MPI_Comm &comm) { inline int comm_size(const MPI_Comm &comm) { int size; if (::MPI_Comm_size(comm, &size) != MPI_SUCCESS) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed MPI_Comm_size"); + METALL_ERROR("Failed MPI_Comm_size"); return -1; } return size; @@ -42,7 +40,7 @@ inline int comm_size(const MPI_Comm &comm) { inline bool barrier(const MPI_Comm &comm) { if (::MPI_Barrier(comm) != MPI_SUCCESS) { - logger::out(logger::level::error, __FILE__, __LINE__, "Failed MPI_Barrier"); + METALL_ERROR("Failed MPI_Barrier"); return false; } return true; @@ -82,7 +80,7 @@ inline std::pair global_logical_or(const bool local_value, /// \param comm MPI communicator. /// \return Returns a local rank number. On error, returns -1. inline int determine_local_root(const MPI_Comm &comm) { - const char *shm_name = "metall_local_root"; + const char *shm_name = "copperr_local_root"; ::shm_unlink(shm_name); barrier(comm); @@ -93,7 +91,7 @@ inline int determine_local_root(const MPI_Comm &comm) { if (world_rank > 0) { if (::MPI_Recv(nullptr, 0, MPI_BYTE, world_rank - 1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE) != MPI_SUCCESS) { - logger::out(logger::level::error, __FILE__, __LINE__, "Failed MPI_Recv"); + METALL_ERROR("Failed MPI_Recv"); return -1; } } @@ -105,13 +103,12 @@ inline int determine_local_root(const MPI_Comm &comm) { if (shm_fd == -1) { shm_fd = ::shm_open(shm_name, O_CREAT | O_RDWR, 0666); if (shm_fd == -1) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to open & create a shm file"); + METALL_ERROR("Failed to open & create a shm file"); return -1; } this_rank_created = true; - if (!metall::mtlldetail::extend_file_size(shm_fd, shm_size, false)) { + if (!copperr::mtlldetail::extend_file_size(shm_fd, shm_size, false)) { logger::out(logger::level::warning, __FILE__, __LINE__, "Failed to extend a shm file; however, continue work"); } @@ -119,10 +116,9 @@ inline int determine_local_root(const MPI_Comm &comm) { // By now, should be ready & correct size void *const ptr = - metall::mtlldetail::map_file_write_mode(shm_fd, nullptr, shm_size, 0, 0); + dice::copperr::mtlldetail::map_file_write_mode(shm_fd, nullptr, shm_size, 0, 0); if (!ptr) { - logger::out(logger::level::error, __FILE__, __LINE__, - "Failed to map a shm file"); + METALL_ERROR("Failed to map a shm file"); return -1; } @@ -139,7 +135,7 @@ inline int determine_local_root(const MPI_Comm &comm) { if (world_rank < world_size - 1) { if (MPI_Send(nullptr, 0, MPI_BYTE, world_rank + 1, 1, MPI_COMM_WORLD) != MPI_SUCCESS) { - logger::out(logger::level::error, __FILE__, __LINE__, "Failed MPI_Send"); + METALL_ERROR("Failed MPI_Send"); return -1; } } @@ -149,17 +145,16 @@ inline int determine_local_root(const MPI_Comm &comm) { const int local_root_rank = p_min_rank_size->first; // Close shared segment - if (!metall::mtlldetail::munmap(shm_fd, ptr, shm_size, false)) { + if (!copperr::mtlldetail::munmap(shm_fd, ptr, shm_size, false)) { logger::out(logger::level::warning, __FILE__, __LINE__, "Failed to unmap the shm file; however, continue work."); } barrier(comm); if (this_rank_created && ::shm_unlink(shm_name) != 0) { - logger::perror(logger::level::warning, __FILE__, __LINE__, - "Failed to remove the shm file; however, continue work."); + METALL_ERRNO_WARN("Failed to remove the shm file; however, continue work."); } return local_root_rank; } -} // namespace metall::utility::mpi +} // namespace dice::copperr::utility::mpi #endif // METALL_METALL_UTILITY_MPI_HPP diff --git a/include/metall/utility/mutex.hpp b/libs/copperr/src/dice/copperr/utility/mutex.hpp similarity index 82% rename from include/metall/utility/mutex.hpp rename to libs/copperr/src/dice/copperr/utility/mutex.hpp index 7e0030e4..5b231c90 100644 --- a/include/metall/utility/mutex.hpp +++ b/libs/copperr/src/dice/copperr/utility/mutex.hpp @@ -9,16 +9,16 @@ #include #include -namespace metall::utility { +namespace dice::copperr::utility { -/// \namespace metall::utility::mutex +/// \namespace dice::copperr::utility::mutex /// \brief Namespace for mutex namespace mutex { /// \brief A utility function that returns a mutex lock allocated as a static /// object. This is an experimental implementation. Example: { // Mutex region /// const int bank_index = hash(key) % num_banks; -/// auto guard = metall::utility::mutex::mutex_lock(bank_index); +/// auto guard = dice::copperr::utility::mutex::mutex_lock(bank_index); /// // do some mutex work /// } template @@ -29,7 +29,7 @@ inline std::unique_lock mutex_lock(const std::size_t index) { } } // namespace mutex -} // namespace metall::utility +} // namespace dice::copperr::utility /// \example static_mutex.cpp /// This is an example of how to use the mutex_lock function. diff --git a/include/metall/utility/open_mp.hpp b/libs/copperr/src/dice/copperr/utility/open_mp.hpp similarity index 90% rename from include/metall/utility/open_mp.hpp rename to libs/copperr/src/dice/copperr/utility/open_mp.hpp index 1ed6c8a4..b2987ec9 100644 --- a/include/metall/utility/open_mp.hpp +++ b/libs/copperr/src/dice/copperr/utility/open_mp.hpp @@ -28,9 +28,9 @@ #define OMP_DIRECTIVE(directive) #endif -namespace metall::utility { +namespace dice::copperr::utility { -/// \namespace metall::utility::omp +/// \namespace dice::copperr::utility::omp /// \brief Namespace for utility items for OpenMP namespace omp { @@ -60,7 +60,7 @@ inline std::string schedule_kind_name( kind == (omp_sched_auto | omp_sched_monotonic)) { name = "omp_sched_auto"; } else { - name = "Unknown kind (" + std::to_string((uint64_t)kind) + ")"; + name = "Unknown kind (" + std::to_string(static_cast(kind)) + ")"; } if (kind & omp_sched_monotonic) { name += " with omp_sched_monotonic"; @@ -75,7 +75,7 @@ inline std::string schedule_kind_name( } else if (kind == omp_sched_auto) { name = "omp_sched_auto"; } else { - name = "Unknown kind (" + std::to_string((uint64_t)kind) + ")"; + name = "Unknown kind (" + std::to_string(static_cast(kind)) + ")"; } #endif #else @@ -120,6 +120,6 @@ inline void set_num_threads([[maybe_unused]] const int n) noexcept { } } // namespace omp -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_OPEN_MP_HPP diff --git a/include/metall/utility/random.hpp b/libs/copperr/src/dice/copperr/utility/random.hpp similarity index 99% rename from include/metall/utility/random.hpp rename to libs/copperr/src/dice/copperr/utility/random.hpp index ed6a39c2..838d669b 100644 --- a/include/metall/utility/random.hpp +++ b/libs/copperr/src/dice/copperr/utility/random.hpp @@ -10,7 +10,7 @@ #include #include -namespace metall::utility { +namespace dice::copperr::utility { #if !defined(DOXYGEN_SKIP) namespace detail { @@ -349,6 +349,6 @@ using rand_512 = detail::base_rand_xoshiro; /// ones in STL The actual algorithm is uses xoshiro1024++ whose period is /// 2^(1024-1) using rand_1024 = detail::base_rand_xoshiro; -} // namespace metall::utility +} // namespace dice::copperr::utility #endif // METALL_UTILITY_RANDOM_HPP diff --git a/include/metall/version.hpp b/libs/copperr/src/dice/copperr/version.hpp similarity index 94% rename from include/metall/version.hpp rename to libs/copperr/src/dice/copperr/version.hpp index 0aac9c1e..93ed4bd6 100644 --- a/include/metall/version.hpp +++ b/libs/copperr/src/dice/copperr/version.hpp @@ -16,14 +16,14 @@ /// \endcode #define METALL_VERSION 2600 -namespace metall { +namespace dice::copperr { /// \brief Variable type to handle a version data. using version_type = uint32_t; static_assert(std::numeric_limits::max() >= METALL_VERSION, "version_type cannot handle the current version"); #ifndef DOXYGEN_SKIP -/// \namespace metall::ver_detail +/// \namespace dice::copperr::ver_detail /// \brief Namespace for the details of Metall version namespace ver_detail { static constexpr version_type k_error_version = 0; @@ -44,6 +44,6 @@ inline std::string to_version_string(const version_type version) { std::to_string(version / 100 % 1000) + "." + std::to_string(version % 100); } -} // namespace metall +} // namespace dice::copperr #endif // METALL_VERSION_HPP diff --git a/libs/default-logger/CMakeLists.txt b/libs/default-logger/CMakeLists.txt new file mode 100644 index 00000000..e819722f --- /dev/null +++ b/libs/default-logger/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.22) +set(lib_suffix "default-logger") +set(lib "${PROJECT_NAME}-${lib_suffix}") + +add_library(${lib} + src/dice/copperr/default_logger.cpp + ) +add_library(${PROJECT_NAME}::${lib_suffix} ALIAS ${lib}) + +target_include_directories(${lib} + PUBLIC + $ + ) + +target_link_libraries(${lib} + PRIVATE + ${PROJECT_NAME}::${PROJECT_NAME} + ) + +include(${CMAKE_SOURCE_DIR}/cmake/install_components.cmake) +install_component(PUBLIC ${lib_suffix} src) diff --git a/libs/default-logger/src/dice/copperr/default_logger.cpp b/libs/default-logger/src/dice/copperr/default_logger.cpp new file mode 100644 index 00000000..751fc386 --- /dev/null +++ b/libs/default-logger/src/dice/copperr/default_logger.cpp @@ -0,0 +1,34 @@ +#include + +#include + +static char const *log_level_to_string(copperr_log_level lvl) noexcept { + switch (lvl) { + case COPPERR_LL_ERROR: { + return "ERROR"; + } + case COPPERR_LL_WARN: { + return "WARNING"; + } + case COPPERR_LL_INFO: { + return "INFO"; + } + case COPPERR_LL_DEBUG: { + return "DEBUG"; + } + case COPPERR_LL_TRACE: { + return "TRACE"; + } + default: { + return "UNKNOWN"; + } + } +} + +extern "C" void copperr_log(copperr_log_level lvl, + [[maybe_unused]] char const *file, + [[maybe_unused]] size_t line, + char const *function, + char const *message) { + std::cerr << log_level_to_string(lvl) << " (" << function << "): " << message << std::endl; +} diff --git a/libs/ffi/CMakeLists.txt b/libs/ffi/CMakeLists.txt new file mode 100644 index 00000000..8e708d89 --- /dev/null +++ b/libs/ffi/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.22) +set(lib_suffix "ffi") +set(lib "${PROJECT_NAME}-${lib_suffix}") + +add_library(${lib} + src/dice/ffi/copperr.cpp + ) +add_library(${PROJECT_NAME}::${lib_suffix} ALIAS ${lib}) + +target_link_libraries(${lib} + PUBLIC + ${PROJECT_NAME}::${PROJECT_NAME} + ) + +target_include_directories(${lib} + PUBLIC + $ + ) + +set_target_properties(${lib} + PROPERTIES + CXX_STANDARD 20 + ) + +## Packaging and exporting the target +include(${CMAKE_SOURCE_DIR}/cmake/install_components.cmake) +install_component(PUBLIC ${lib_suffix} src) diff --git a/libs/ffi/src/dice/ffi/copperr.cpp b/libs/ffi/src/dice/ffi/copperr.cpp new file mode 100644 index 00000000..7ca85ca2 --- /dev/null +++ b/libs/ffi/src/dice/ffi/copperr.cpp @@ -0,0 +1,111 @@ +#include +#include + +using copperr_manager_t = dice::copperr::ffi::internal::copperr_manager; + +template +copperr_manager *open_impl(char const *path) { + if (!dice::copperr::manager::consistent(path)) { + // prevents opening the same datastore twice + // (because opening removes the properly_closed_mark and this checks for it) + errno = ENOTRECOVERABLE; + return nullptr; + } + + auto *manager = new copperr_manager_t{open_mode, path}; + if (!manager->check_sanity()) { + delete manager; + errno = ENOTRECOVERABLE; + return nullptr; + } + + return reinterpret_cast(manager); +} + +copperr_manager *copperr_open(char const *path) { + return open_impl(path); +} + +copperr_manager *copperr_open_read_only(char const *path) { + return open_impl(path); +} + +copperr_manager *copperr_create(char const *path) { + if (std::filesystem::exists(path)) { + // prevent accidental overwrite + errno = EEXIST; + return nullptr; + } + + auto *manager = new copperr_manager_t{dice::copperr::create_only, path}; + if (!manager->check_sanity()) { + delete manager; + errno = ENOTRECOVERABLE; + return nullptr; + } + + return reinterpret_cast(manager); +} + +bool copperr_snapshot(copperr_manager *manager, char const *dst_path) { + return reinterpret_cast(manager)->snapshot(dst_path); +} + +void copperr_close(copperr_manager *manager) { + delete reinterpret_cast(manager); +} + +bool copperr_remove(char const *path) { + return dice::copperr::manager::remove(path); +} + +void *copperr_named_malloc(copperr_manager *manager, char const *name, + size_t size) { + auto *ptr = + reinterpret_cast(manager)->construct( + name)[size](); + if (ptr == nullptr) { + errno = ENOMEM; + } + + return ptr; +} + +void *copperr_find(copperr_manager *manager, char const *name) { + auto *ptr = reinterpret_cast(manager) + ->find(name) + .first; + if (ptr == nullptr) { + errno = ENOENT; + } + + return ptr; +} + +bool copperr_named_free(copperr_manager *manager, char const *name) { + auto const res = + reinterpret_cast(manager)->destroy( + name); + if (!res) { + errno = ENOENT; + } + + return res; +} + +void *copperr_malloc(copperr_manager *manager, size_t size) { + auto *ptr = reinterpret_cast(manager)->allocate(size); + if (ptr == nullptr) { + errno = ENOMEM; + } + + return ptr; +} + +void copperr_free(copperr_manager *manager, void *addr) { + reinterpret_cast(manager)->deallocate(addr); +} + +void copperr_flush(copperr_manager *manager) { + reinterpret_cast(manager)->flush(); +} diff --git a/libs/ffi/src/dice/ffi/copperr.h b/libs/ffi/src/dice/ffi/copperr.h new file mode 100644 index 00000000..86382c2c --- /dev/null +++ b/libs/ffi/src/dice/ffi/copperr.h @@ -0,0 +1,115 @@ +#ifndef DICE_METALLFFI_METALL_H +#define DICE_METALLFFI_METALL_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct copperr_manager copperr_manager; + +/** + * @brief Attempts to open the copperr datastore at path + * @param path path to datastore + * @return pointer to copperr manager on success, NULL on failure. On failure, sets errno to one of the following values: + * - ENOTRECOVERABLE if the given copperr datastore is inconsistent or already opened as writable + */ +copperr_manager *copperr_open(char const *path); + +/** + * @brief Attempts to open the copperr datastore at path in read only mode + * @param path path to datastore + * @return pointer to copperr manager on success, NULL on failure. On failure, sets errno to one of the following values: + * - ENOTRECOVERABLE if the given copperr datastore is inconsistent or already opened as writable + */ +copperr_manager *copperr_open_read_only(char const *path); + +/** + * @brief Attempts to create a copperr datastore at path + * @param path path at which to create a datastore + * @return pointer to copperr manager on success, NULL on failure. On failure, sets errno to one of the following values: + * - EEXIST if the given path already exists + * - ENOTRECOVERABLE if the datastore could not be created for some other reason + */ +copperr_manager *copperr_create(char const *path); + +/** + * @brief Creates a snapshot of the copperr datastore of manager and places it at dst_path + * @param manager manager to perform snapshot + * @param dst_path path where to place the snapshot + * @return true if the snapshot was successfully created otherwise false. + */ +bool copperr_snapshot(copperr_manager *manager, char const *dst_path); + +/** + * @brief Closes a copperr manager + */ +void copperr_close(copperr_manager *manager); + +/** + * @brief Removes the copperr datastore at path + * @param path path to datastore to remove + * @return true on successful removal, false otherwise. On failure, sets errno to one of the following values: + * - EADDRINUSE if there is a copperr manager open for the given path + * + * @warning Behaviour is undefined if there is still a copperr manager for path open + */ +bool copperr_remove(char const *path); + +/** + * @brief Allocates size bytes and associates the allocated memory with a name + * @param manager copperr manager to allocate with + * @param name A name of the allocated memory + * @param size number of bytes to allocate + * @return pointer to the allocated memory if sucessful otherwise returns NULL and sets errno to one of the following values + * - ENOMEM if the memory could not be allocated + */ +void *copperr_named_malloc(copperr_manager *manager, char const *name, size_t size); + +/** + * @brief Finds memory that was previously allocated using copperr_named_alloc + * @param manager manager to find the object in + * @param name name of the allocated memory to find + * @return pointer to the allocated memory if found. Otherwise, returns NULL and sets errno to one of the following values + * - ENOTENT if the object could not be found + */ +void *copperr_find(copperr_manager *manager, char const *name); + +/** + * @brief Frees memory previously allocated by copperr_named_malloc + * @param manager manager from which to free + * @param name name of the allocated memory to free + * @return true if sucessfully freed, otherwise returns false and sets errno to one of the following values + * - ENOENT if the referred to object does not exist + */ +bool copperr_named_free(copperr_manager *manager, char const *name); + +/** + * @brief Allocates size bytes + * @param manager copperr manager to allocate with + * @param size number of bytes to allocate + * @return pointer to the allocated memory if sucessful otherwise returns NULL and sets errno to one of the following values + * - ENOMEM if the memory could not be allocated + */ +void *copperr_malloc(copperr_manager *manager, size_t size); + +/** + * @brief Frees memory previously allocated by copperr_malloc + * @param manager manager from which to free + * @param addr pointer to allocation + */ +void copperr_free(copperr_manager *manager, void *addr); + +/** + * @brief Flush data to persistent memory + * @param manager manager to flush + */ +void copperr_flush(copperr_manager *manager); + +#ifdef __cplusplus +} +#endif + +#endif//DICE_METALLFFI_METALL_H diff --git a/libs/ffi/src/dice/ffi/copperr_internal.hpp b/libs/ffi/src/dice/ffi/copperr_internal.hpp new file mode 100644 index 00000000..f9928563 --- /dev/null +++ b/libs/ffi/src/dice/ffi/copperr_internal.hpp @@ -0,0 +1,15 @@ +#ifndef DICE_METALLFFI_METALLINTERNAL_HPP +#define DICE_METALLFFI_METALLINTERNAL_HPP + +#include + +namespace dice::copperr::ffi::internal { +/** + * @brief The copperr manager type used internally. + * This object type is whats actually behind the opaque ::copperr_manager * + * in the interface + */ +using copperr_manager = copperr::manager; +} // namespace dice::copperr::ffi::internal + +#endif // DICE_METALLFFI_METALLINTERNAL_HPP diff --git a/mkdocs.yml b/mkdocs.yml index 632147ad..22359cef 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -8,7 +8,7 @@ theme: 'readthedocs' extra_css: - ./css/custom.css -repo_url: https://github.com/LLNL/metall +repo_url: https://github.com/dice-group/copperr edit_uri: 'tree/develop/docs/readthedocs' nav: diff --git a/scripts/release_test/run_tests.sh b/scripts/release_test/run_tests.sh index a9d9c471..67c3a9a1 100644 --- a/scripts/release_test/run_tests.sh +++ b/scripts/release_test/run_tests.sh @@ -12,8 +12,8 @@ BOOST_VERSiONS=('1.74.0' '1.73.0' '1.72.0' '1.71.0' '1.70.0' '1.69.0' '1.68.0' ' for GCC_VER in "${GCC_VERSIONS[@]}"; do for BOOST_VER in "${BOOST_VERSiONS[@]}"; do - export METALL_TEST_DIR="/dev/shm/metall_test_gcc${GCC_VER}_boost${BOOST_VER}" - export METALL_BUILD_DIR="/dev/shm/metall_test_build_gcc${GCC_VER}_boost${BOOST_VER}" + export METALL_TEST_DIR="/dev/shm/copperr_test_gcc${GCC_VER}_boost${BOOST_VER}" + export METALL_BUILD_DIR="/dev/shm/copperr_test_build_gcc${GCC_VER}_boost${BOOST_VER}" spack load gcc@${GCC_VER} spack load boost@${BOOST_VER} diff --git a/scripts/test_kernel.sh b/scripts/test_kernel.sh index b4f75acb..014ce340 100644 --- a/scripts/test_kernel.sh +++ b/scripts/test_kernel.sh @@ -14,12 +14,12 @@ run_build_and_test_kernel() { local test_dir=${METALL_TEST_DIR} if [ -d ${test_dir} ]; then - test_dir="${test_dir}/metall-test-${RANDOM}" + test_dir="${test_dir}/copperr-test-${RANDOM}" fi local build_dir=${METALL_BUILD_DIR} if [ -d ${build_dir} ]; then - build_dir="${build_dir}/metall-build-${RANDOM}" + build_dir="${build_dir}/copperr-build-${RANDOM}" fi mkdir -p ${build_dir} @@ -72,7 +72,7 @@ build_docs() { local build_dir=${METALL_BUILD_DIR} if [ -d ${build_dir} ]; then - build_dir="${build_dir}/metall-build-${RANDOM}" + build_dir="${build_dir}/copperr-build-${RANDOM}" fi mkdir -p ${build_dir} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index f23be9ff..00000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -if (BUILD_UTILITY) - add_metall_executable(datastore_ls datastore_ls.cpp) - install(TARGETS datastore_ls RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - - add_metall_executable(mpi_datastore_ls mpi_datastore_ls.cpp) - install(TARGETS mpi_datastore_ls RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif () - -if (BUILD_C) - if (NOT Boost_FOUND) - return() - endif () - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") - - add_library(metall_c metall_c.cpp) - add_library(${PROJECT_NAME}::metall_c ALIAS metall_c) - - target_include_directories(metall_c PUBLIC - $ - $) - - common_setup_for_metall_executable(metall_c) - - install(TARGETS metall_c - EXPORT ${PROJECT_NAME}_Targets - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif () \ No newline at end of file diff --git a/src/metall_c.cpp b/src/metall_c.cpp deleted file mode 100644 index 5c920481..00000000 --- a/src/metall_c.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include -#include - -metall::manager *g_manager = nullptr; - -int metall_open(const int mode, const char *const path) { - if (mode == METALL_CREATE_ONLY) { - g_manager = new metall::manager(metall::create_only, path); - } else if (mode == METALL_OPEN_ONLY) { - g_manager = new metall::manager(metall::open_only, path); - } else if (mode == METALL_OPEN_READ_ONLY) { - g_manager = new metall::manager(metall::open_read_only, path); - } else { - g_manager = nullptr; - } - - if (g_manager) { - return 0; - } else { - return -1; // error - } -} - -void metall_close() { delete g_manager; } - -void metall_flush() { g_manager->flush(); } - -void *metall_malloc(const uint64_t nbytes) { - return g_manager->allocate(nbytes); -} - -void metall_free(void *const ptr) { g_manager->deallocate(ptr); } - -void *metall_named_malloc(const char *name, const uint64_t nbytes) { - return g_manager->construct(name)[nbytes](); -} - -void *metall_find(char *name) { return g_manager->find(name).first; } - -void metall_named_free(const char *name) { g_manager->destroy(name); } - -int snapshot(const char *destination_path) { - if (g_manager->snapshot(destination_path)) return 0; - return -1; // Error -} - -int copy(const char *source_path, const char *destination_path) { - if (metall::manager::copy(source_path, destination_path)) return 0; - return -1; // Error -} - -int consistent(const char *path) { - if (metall::manager::consistent(path)) return 1; - return 0; -} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index eb33327d..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -# -# Finds an already downloaded and built googletest in local (i.e., this build directory) by download_and_build_gtest(). -# -macro(find_local_gtest) - if ((EXISTS ${CMAKE_CURRENT_BINARY_DIR}/googletest-src) AND (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/googletest-build)) - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL) - set(FOUND_LOCAL_GTEST ON) - endif() -endmacro() - -# -# Finds a system-wide googletest -# -macro(find_global_gtest) - # Find a system-wide one - find_package(GTest REQUIRED) - message(STATUS "Found a system-wide googletest") - message(VERBOSE "GTEST_INCLUDE_DIRS=${GTEST_INCLUDE_DIRS}") - message(VERBOSE "GTEST_LIBRARIES=${GTEST_LIBRARIES}") - message(VERBOSE "GTEST_MAIN_LIBRARIES=${GTEST_MAIN_LIBRARIES}") - set(FOUND_GLOBAL_GTEST ON) -endmacro() - -# -# Downloads and unpacks googletest -# (see https://github.com/google/googletest/blob/master/googletest/README.md) -# -macro(download_and_build_gtest) - configure_file(CMakeListsGTest.txt.in googletest-download/CMakeLists.txt) - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE failed - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) - if (failed) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif () - - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE failed - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download) - if (failed) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif () -endmacro() - -# -# Link googltest library -# -macro(link_gtest_lib target) - if (DEFINED FOUND_LOCAL_GTEST) - target_link_libraries(${target} PRIVATE gtest_main) - elseif (DEFINED FOUND_GLOBAL_GTEST) - target_link_libraries(${target} PRIVATE GTest::Main) - endif () -endmacro() - -# ------------------------------------------------------------ # -# Set up googletest -# ------------------------------------------------------------ # -if(ONLY_DOWNLOAD_GTEST) - download_and_build_gtest() - return() -elseif (SKIP_DOWNLOAD_GTEST) - find_local_gtest() - if (DEFINED FOUND_LOCAL_GTEST) - message(STATUS "Found already downloaded googletest") - else () - find_global_gtest() - endif() -else () - download_and_build_gtest() - find_local_gtest() - if (NOT DEFINED FOUND_LOCAL_GTEST) - message(FATAL_ERROR "Cannot find the just downloaded googletest") - endif() -endif () - -# ------------------------------------------------------------ # - -include(GoogleTest) - -# -------------------------------------------------------------------------------- # -# Add executable functions -# -------------------------------------------------------------------------------- # -function(add_metall_test_executable name source) - add_metall_executable(${name} ${source}) - if (ADDED_METALL_EXE) - link_gtest_lib(${name}) - gtest_discover_tests(${name}) - if (RUN_LARGE_SCALE_TEST) - target_compile_definitions(${name} PRIVATE "METALL_RUN_LARGE_SCALE_TEST") - endif() - endif() -endfunction() - -add_subdirectory(utility) -add_subdirectory(kernel) -add_subdirectory(container) \ No newline at end of file diff --git a/test/CMakeListsGTest.txt.in b/test/CMakeListsGTest.txt.in deleted file mode 100644 index 226cf8c4..00000000 --- a/test/CMakeListsGTest.txt.in +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG main - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) \ No newline at end of file diff --git a/test/container/CMakeLists.txt b/test/container/CMakeLists.txt deleted file mode 100644 index 4715b596..00000000 --- a/test/container/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_metall_test_executable(concurrent_map_test concurrent_map_test.cpp) - -add_metall_test_executable(stl_allocator_test stl_allocator_test.cpp) - -add_metall_test_executable(fallback_allocator_adaptor_test fallback_allocator_adaptor_test.cpp) - -add_metall_test_executable(string_key_store_test string_key_store_test.cpp) - -add_subdirectory(json) \ No newline at end of file diff --git a/test/container/json/CMakeLists.txt b/test/container/json/CMakeLists.txt deleted file mode 100644 index 404cfae8..00000000 --- a/test/container/json/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") - add_metall_test_executable(json_value json_value.cpp) - add_metall_test_executable(json_object json_object.cpp) - add_metall_test_executable(json_array json_array.cpp) -endif () \ No newline at end of file diff --git a/test/gtest_main.cpp b/test/gtest_main.cpp deleted file mode 100644 index b57ebb91..00000000 --- a/test/gtest_main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include -#include "gtest/gtest.h" - -GTEST_API_ int main(int argc, char **argv) { - printf("Running main() from %s\n", __FILE__); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} \ No newline at end of file diff --git a/test/kernel/CMakeLists.txt b/test/kernel/CMakeLists.txt deleted file mode 100644 index 20604e2b..00000000 --- a/test/kernel/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_metall_test_executable(attributed_object_directory_test attributed_object_directory_test.cpp) - -add_metall_test_executable(bin_manager_test bin_manager_test.cpp) - -add_metall_test_executable(bin_directory_test bin_directory_test.cpp) - -add_metall_test_executable(multilayer_bitset_test multilayer_bitset_test.cpp) - -add_metall_test_executable(chunk_directory_test chunk_directory_test.cpp) - -add_metall_test_executable(object_cache_test object_cache_test.cpp) - -add_metall_test_executable(manager_test manager_test.cpp) - -add_metall_test_executable(manager_test_single_thread manager_test.cpp) -target_compile_definitions(manager_test_single_thread PRIVATE "METALL_DISABLE_CONCURRENCY") - -add_metall_test_executable(snapshot_test snapshot_test.cpp) - -add_metall_test_executable(copy_file_test copy_file_test.cpp) - -include(setup_omp) -if (OpenMP_CXX_FOUND) - add_metall_test_executable(manager_multithread_test manager_multithread_test.cpp) - setup_omp_target(manager_multithread_test) -else() - MESSAGE(STATUS "OpenMP is not found. Will not run multi-thread test.") -endif() - -add_metall_test_executable(multimanager_test multimanager_test.cpp) - -add_metall_test_executable(mmap_segment_storage_test mmap_segment_storage_test.cpp) - -add_metall_test_executable(object_attribute_accessor_test object_attribute_accessor_test.cpp) \ No newline at end of file diff --git a/test/kernel/copy_file_test.cpp b/test/kernel/copy_file_test.cpp deleted file mode 100644 index 6a561f16..00000000 --- a/test/kernel/copy_file_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include "gtest/gtest.h" - -#include - -#include -#include "../test_utility.hpp" - -namespace { - -void create(const std::string &dir_path) { - metall::manager manager(metall::create_only, dir_path.c_str()); - - manager.construct("a")(1); - manager.construct("b")(2); -} - -void open(const std::string &dir_path) { - metall::manager manager(metall::open_read_only, dir_path.c_str()); - - auto a = manager.find("a").first; - ASSERT_EQ(*a, 1); - - auto b = manager.find("b").first; - ASSERT_EQ(*b, 2); -} - -const std::string &original_dir_path() { - const static std::string path(test_utility::make_test_path("/original")); - return path; -} - -const std::string ©_dir_path() { - const static std::string path(test_utility::make_test_path("/copy")); - return path; -} - -TEST(CopyFileTest, SyncCopy) { - metall::manager::remove(original_dir_path().c_str()); - metall::manager::remove(copy_dir_path().c_str()); - - create(original_dir_path()); - - ASSERT_TRUE(metall::manager::copy(original_dir_path().c_str(), - copy_dir_path().c_str())); - - open(copy_dir_path()); -} - -TEST(CopyFileTest, AsyncCopy) { - metall::manager::remove(original_dir_path().c_str()); - metall::manager::remove(copy_dir_path().c_str()); - - create(original_dir_path()); - - auto handler = metall::manager::copy_async(original_dir_path().c_str(), - copy_dir_path().c_str()); - ASSERT_TRUE(handler.get()); - - open(copy_dir_path()); -} -} // namespace \ No newline at end of file diff --git a/test/kernel/snapshot_test.cpp b/test/kernel/snapshot_test.cpp deleted file mode 100644 index 3f4b25cf..00000000 --- a/test/kernel/snapshot_test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#include "gtest/gtest.h" - -#include - -#include - -#include "../test_utility.hpp" - -namespace { - -std::string original_dir_path() { - const std::string path(test_utility::make_test_path("original")); - return path; -} - -std::string snapshot_dir_path() { - const std::string path(test_utility::make_test_path("snapshot")); - return path; -} - -TEST(SnapshotTest, Snapshot) { - metall::manager::remove(original_dir_path().c_str()); - metall::manager::remove(snapshot_dir_path().c_str()); - - { - metall::manager manager(metall::create_only, original_dir_path().c_str()); - - [[maybe_unused]] auto a = manager.construct("a")(1); - [[maybe_unused]] auto b = - manager.construct(metall::unique_instance)(2); - - ASSERT_TRUE(manager.snapshot(snapshot_dir_path().c_str())); - ASSERT_TRUE(metall::manager::consistent(snapshot_dir_path().c_str())); - - // UUID - const auto original_uuid = - metall::manager::get_uuid(original_dir_path().c_str()); - ASSERT_FALSE(original_uuid.empty()); - const auto snapshot_uuid = - metall::manager::get_uuid(snapshot_dir_path().c_str()); - ASSERT_FALSE(snapshot_uuid.empty()); - ASSERT_NE(original_uuid, snapshot_uuid); - - // Version - ASSERT_EQ(metall::manager::get_version(original_dir_path().c_str()), - metall::manager::get_version(snapshot_dir_path().c_str())); - } - - { - metall::manager manager(metall::open_read_only, - snapshot_dir_path().c_str()); - - auto a = manager.find("a").first; - ASSERT_EQ(*a, 1); - - auto b = manager.find(metall::unique_instance).first; - ASSERT_EQ(*b, 2); - } -} -} // namespace \ No newline at end of file diff --git a/test/test_utility.hpp b/test/test_utility.hpp deleted file mode 100644 index fd656bd8..00000000 --- a/test/test_utility.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall -// Project Developers. See the top-level COPYRIGHT file for details. -// -// SPDX-License-Identifier: (Apache-2.0 OR MIT) - -#ifndef METALL_TEST_UTILITY_HPP -#define METALL_TEST_UTILITY_HPP - -#include "gtest/gtest.h" - -#include -#include - -#include - -namespace test_utility { - -const char *k_test_dir_env_name = "METALL_TEST_DIR"; -const char *k_default_test_dir = "/tmp/metall_test_dir"; - -namespace detail { -inline std::string get_test_dir() { - if (const char *env_p = std::getenv(k_test_dir_env_name)) { - return std::string(env_p); - } - return std::string(k_default_test_dir); -} -} // namespace detail - -inline bool create_test_dir() { - if (!metall::mtlldetail::directory_exist(detail::get_test_dir())) - return metall::mtlldetail::create_directory(detail::get_test_dir()); - return true; -} - -inline std::string make_test_path(const std::string &name = std::string()) { - return detail::get_test_dir() + "/metalltest" + "-" + - ::testing::UnitTest::GetInstance()->current_test_case()->name() + "-" + - ::testing::UnitTest::GetInstance()->current_test_info()->name() + "-" + - name; -} - -} // namespace test_utility -#endif // METALL_TEST_UTILITY_HPP diff --git a/test/utility/CMakeLists.txt b/test/utility/CMakeLists.txt deleted file mode 100644 index 4542864d..00000000 --- a/test/utility/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_metall_test_executable(bitset_test bitset_test.cpp) \ No newline at end of file diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 00000000..4d4ad706 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +find_package(copperr REQUIRED) + +add_executable(example example.cpp) + +target_link_libraries(example PUBLIC + copperr::copperr) + +set_target_properties( + example PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF +) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 00000000..37603a5d --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,31 @@ +import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout + + +required_conan_version = ">=1.59" + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "CMakeToolchain" + + def requirements(self): + self.requires(self.tested_reference_str) + + def configure(self): + self.options["copperr"].with_default_logger = True + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "example") + self.run(cmd, env="conanrun") diff --git a/test_package/example.cpp b/test_package/example.cpp new file mode 100644 index 00000000..b177ca38 --- /dev/null +++ b/test_package/example.cpp @@ -0,0 +1,51 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall Project Developers. +// See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#include +#include + +#include // Only one header file is required to be included + +// Type alias +// This is a standard way to give a custom allocator to a container +using vector_t = boost::container::vector>; + +int main() { + + { + // Construct a manager object + // A process can allocate multiple manager objects + dice::copperr::manager manager(dice::copperr::create_only, // Create a new one + "/tmp/dir"); // The directory to store backing datastore + + // Allocate and construct a vector object in the persistent memory with a name "vec" + auto pvec = manager.construct // Allocate and construct an object of vector_t + ("vec") // Name of the allocated object + (manager.get_allocator()); // Arguments passed to vector_t's constructor + + pvec->push_back(5); // Can use containers normally + + } // Implicitly sync with backing files, i.e., sync() is called in copperr::manager's destructor + + // ---------- Assume exit and restart the program at this point ---------- // + + { + // Reattach the manager object + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); + + // Find the previously constructed object + // Please do not forget to use ".first" at the end + auto pvec = manager.find("vec").first; + + pvec->push_back(10); // Can restart to use containers normally + + std::cout << (*pvec)[0] << std::endl; // Will print "5" + std::cout << (*pvec)[1] << std::endl; // Will print "10" + + manager.destroy("vec"); // Destroy the object + } + + return 0; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..bf85ef8f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(GTest REQUIRED) +include(GoogleTest) + +function(add_copperr_test_executable name source) + add_copperr_executable(${name} ${source}) + + target_link_libraries(${name} PRIVATE GTest::gtest_main GTest::gtest) + gtest_discover_tests(${name}) + if (RUN_LARGE_SCALE_TESTS) + target_compile_definitions(${name} PRIVATE "METALL_RUN_LARGE_SCALE_TEST") + endif() +endfunction() + +add_subdirectory(utility) +add_subdirectory(kernel) +add_subdirectory(container) +add_subdirectory(ffi) diff --git a/tests/container/CMakeLists.txt b/tests/container/CMakeLists.txt new file mode 100644 index 00000000..db452be8 --- /dev/null +++ b/tests/container/CMakeLists.txt @@ -0,0 +1,9 @@ +add_copperr_test_executable(concurrent_map_test concurrent_map_test.cpp) + +add_copperr_test_executable(stl_allocator_test stl_allocator_test.cpp) + +add_copperr_test_executable(fallback_allocator_adaptor_test fallback_allocator_adaptor_test.cpp) + +add_copperr_test_executable(string_key_store_test string_key_store_test.cpp) + +add_subdirectory(json) \ No newline at end of file diff --git a/test/container/concurrent_map_test.cpp b/tests/container/concurrent_map_test.cpp similarity index 84% rename from test/container/concurrent_map_test.cpp rename to tests/container/concurrent_map_test.cpp index 16fc3943..8322e55b 100644 --- a/test/container/concurrent_map_test.cpp +++ b/tests/container/concurrent_map_test.cpp @@ -8,8 +8,8 @@ #include #include #include -#include -#include +#include +#include #include "../test_utility.hpp" namespace bip = boost::interprocess; @@ -18,7 +18,7 @@ namespace { TEST(ConcurrentMapTest, SequentialInsert) { boost::container::map ref_map; - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; const auto v1 = std::make_pair('a', 0); const auto v1_2 = std::make_pair('a', 0); @@ -33,7 +33,7 @@ TEST(ConcurrentMapTest, SequentialInsert) { } TEST(ConcurrentMapTest, Count) { - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; const auto v1 = std::make_pair('a', 0); GTEST_ASSERT_EQ(map.count(v1.first), 0); @@ -47,7 +47,7 @@ TEST(ConcurrentMapTest, Count) { } TEST(ConcurrentMapTest, Size) { - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; GTEST_ASSERT_EQ(map.size(), 0); @@ -63,7 +63,7 @@ TEST(ConcurrentMapTest, Size) { TEST(ConcurrentMapTest, SequentialEdit) { boost::container::map ref_map; - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; const auto v1 = std::make_pair('a', 0); ref_map[v1.first] = v1.second; @@ -81,7 +81,7 @@ TEST(ConcurrentMapTest, SequentialEdit) { TEST(ConcurrentMapTest, Find) { boost::container::map ref_map; - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; const auto v1 = std::make_pair('a', 0); GTEST_ASSERT_EQ(map.find(v1.first), map.cend()); @@ -102,7 +102,7 @@ TEST(ConcurrentMapTest, Find) { TEST(ConcurrentMapTest, Iterator) { boost::container::map ref_map; - metall::container::concurrent_map map; + dice::copperr::container::concurrent_map map; const auto v1 = std::make_pair('a', 0); ref_map.insert(v1); @@ -115,7 +115,7 @@ TEST(ConcurrentMapTest, Iterator) { int num_elems = 0; for (auto itr = map.cbegin(), end = map.cend(); itr != end; ++itr) { GTEST_ASSERT_EQ(ref_map.count(itr->first), 1) - << "Invalid key was found: " << (char)itr->first; + << "Invalid key was found: " << itr->first; GTEST_ASSERT_EQ(ref_map.at(itr->first), itr->second); ++num_elems; } @@ -127,18 +127,18 @@ TEST(ConcurrentMapTest, Persistence) { bip::allocator, bip::managed_mapped_file::segment_manager>; using map_type = - metall::container::concurrent_map, - std::hash, allocator_type, 2>; + dice::copperr::container::concurrent_map, + std::hash, allocator_type, 2>; const std::string file_path(test_utility::make_test_path()); test_utility::create_test_dir(); - metall::mtlldetail::remove_file(file_path); + dice::copperr::mtlldetail::remove_file(file_path); std::vector> inputs(10); - for (int i = 0; i < (int)inputs.size(); ++i) { - inputs[i].first = (char)('a' + i); - inputs[i].second = i; + for (size_t i = 0; i < inputs.size(); ++i) { + inputs[i].first = static_cast('a' + i); + inputs[i].second = static_cast(i); } { diff --git a/test/container/fallback_allocator_adaptor_test.cpp b/tests/container/fallback_allocator_adaptor_test.cpp similarity index 87% rename from test/container/fallback_allocator_adaptor_test.cpp rename to tests/container/fallback_allocator_adaptor_test.cpp index 34d0e6b3..5c467af2 100644 --- a/test/container/fallback_allocator_adaptor_test.cpp +++ b/tests/container/fallback_allocator_adaptor_test.cpp @@ -9,13 +9,13 @@ #include #include #include -#include -#include +#include +#include #include "../test_utility.hpp" template -using fb_alloc_type = metall::utility::fallback_allocator_adaptor< - metall::manager::allocator_type>; +using fb_alloc_type = dice::copperr::utility::fallback_allocator_adaptor< + dice::copperr::manager::allocator_type>; const std::string &dir_path() { const static std::string path(test_utility::make_test_path()); @@ -36,28 +36,28 @@ TEST(FallbackAllocatorAdaptorTest, Types) { GTEST_ASSERT_EQ(typeid(std::allocator_traits>::pointer), typeid(fb_alloc_type::pointer)); GTEST_ASSERT_EQ(typeid(std::allocator_traits>::pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::const_pointer), typeid(fb_alloc_type::const_pointer)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::const_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::void_pointer), typeid(fb_alloc_type::void_pointer)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::void_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::const_void_pointer), typeid(fb_alloc_type::const_void_pointer)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::const_void_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ( typeid(std::allocator_traits>::difference_type), @@ -127,10 +127,11 @@ TEST(FallbackAllocatorAdaptorTest, Types) { { auto p = std::allocator_traits::allocate(alloc, 1); std::allocator_traits::construct( - alloc, metall::to_raw_pointer(p), 10, 20.0); + alloc, dice::copperr::to_raw_pointer(p), 10, 20.0); GTEST_ASSERT_EQ(p->a, 10); GTEST_ASSERT_EQ(p->b, 20.0); - std::allocator_traits::destroy(alloc, metall::to_raw_pointer(p)); + std::allocator_traits::destroy(alloc, dice::copperr::to_raw_pointer(p)); + std::allocator_traits::deallocate(alloc, dice::copperr::to_raw_pointer(p), 1); } GTEST_ASSERT_EQ(std::allocator_traits::max_size(alloc), @@ -199,7 +200,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructFind) { boost::interprocess::vector>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); int *a = manager.construct("int")(10); @@ -212,7 +213,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); const auto ret1 = manager.find("int"); ASSERT_NE(ret1.first, nullptr); @@ -229,7 +230,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); ASSERT_FALSE(manager.destroy("int")); @@ -244,7 +245,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructOrFind) { boost::interprocess::vector>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); int *a = manager.find_or_construct("int")(10); ASSERT_EQ(*a, 10); @@ -256,7 +257,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructOrFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); int *a = manager.find_or_construct("int")(20); ASSERT_EQ(*a, 10); @@ -268,7 +269,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentConstructOrFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); ASSERT_FALSE(manager.destroy("int")); @@ -291,7 +292,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentNestedContainer) { map_alloc_type>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); map_type *map = manager.construct("map")(manager.get_allocator<>()); @@ -300,7 +301,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentNestedContainer) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); map_type *map; std::size_t n; std::tie(map, n) = manager.find("map"); @@ -311,7 +312,7 @@ TEST(FallbackAllocatorAdaptorTest, PersistentNestedContainer) { } { - metall::manager manager(metall::open_read_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_read_only, dir_path()); map_type *map; std::size_t n; std::tie(map, n) = manager.find("map"); diff --git a/tests/container/json/CMakeLists.txt b/tests/container/json/CMakeLists.txt new file mode 100644 index 00000000..48effdc1 --- /dev/null +++ b/tests/container/json/CMakeLists.txt @@ -0,0 +1,5 @@ +if (Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.75") + add_copperr_test_executable(json_value json_value.cpp) + add_copperr_test_executable(json_object json_object.cpp) + add_copperr_test_executable(json_array json_array.cpp) +endif () \ No newline at end of file diff --git a/test/container/json/json_array.cpp b/tests/container/json/json_array.cpp similarity index 97% rename from test/container/json/json_array.cpp rename to tests/container/json/json_array.cpp index d8030aa2..edc334ab 100644 --- a/test/container/json/json_array.cpp +++ b/tests/container/json/json_array.cpp @@ -5,9 +5,9 @@ #include "gtest/gtest.h" #include -#include +#include -namespace mj = metall::json; +namespace mj = dice::copperr::json; namespace { using array_type = mj::array>; diff --git a/test/container/json/json_object.cpp b/tests/container/json/json_object.cpp similarity index 98% rename from test/container/json/json_object.cpp rename to tests/container/json/json_object.cpp index 8b46cc50..2fd3db0b 100644 --- a/test/container/json/json_object.cpp +++ b/tests/container/json/json_object.cpp @@ -5,9 +5,9 @@ #include "gtest/gtest.h" #include -#include +#include -namespace mj = metall::json; +namespace mj = dice::copperr::json; namespace { diff --git a/test/container/json/json_value.cpp b/tests/container/json/json_value.cpp similarity index 77% rename from test/container/json/json_value.cpp rename to tests/container/json/json_value.cpp index d2d6c279..ec605e44 100644 --- a/test/container/json/json_value.cpp +++ b/tests/container/json/json_value.cpp @@ -5,11 +5,11 @@ #include "gtest/gtest.h" #include -#include -#include +#include +#include #include "../../test_utility.hpp" -namespace mj = metall::json; +namespace mj = dice::copperr::json; namespace { @@ -34,61 +34,61 @@ TEST(JSONValueTest, Assign) { } { - val = (signed char)-1; + val = static_cast(-1); GTEST_ASSERT_TRUE(val.is_int64()); - GTEST_ASSERT_EQ(val.as_int64(), (signed char)-1); + GTEST_ASSERT_EQ(val.as_int64(), static_cast(-1)); } { - val = (int)-3; + val = -3; GTEST_ASSERT_TRUE(val.is_int64()); - GTEST_ASSERT_EQ(val.as_int64(), (int)-3); + GTEST_ASSERT_EQ(val.as_int64(), -3); } { - val = (long)-4; + val = -4l; GTEST_ASSERT_TRUE(val.is_int64()); - GTEST_ASSERT_EQ(val.as_int64(), (long)-4); + GTEST_ASSERT_EQ(val.as_int64(), -4l); } { - val = (long long)-5; + val = -5ll; GTEST_ASSERT_TRUE(val.is_int64()); - GTEST_ASSERT_EQ(val.as_int64(), (long long)-5); + GTEST_ASSERT_EQ(val.as_int64(), -5ll); } { - val = (unsigned char)1; + val = static_cast(1); GTEST_ASSERT_TRUE(val.is_uint64()); - GTEST_ASSERT_EQ(val.as_uint64(), (unsigned char)1); + GTEST_ASSERT_EQ(val.as_uint64(), static_cast(1)); } { - val = (unsigned short)2; + val = static_cast(2); GTEST_ASSERT_TRUE(val.is_uint64()); - GTEST_ASSERT_EQ(val.as_uint64(), (unsigned short)2); + GTEST_ASSERT_EQ(val.as_uint64(), static_cast(2)); } { - val = (unsigned int)3; + val = 3u; GTEST_ASSERT_TRUE(val.is_uint64()); - GTEST_ASSERT_EQ(val.as_uint64(), (unsigned int)3); + GTEST_ASSERT_EQ(val.as_uint64(), 3u); } { - val = (unsigned long)4; + val = 4ul; GTEST_ASSERT_TRUE(val.is_uint64()); - GTEST_ASSERT_EQ(val.as_uint64(), (unsigned long)4); + GTEST_ASSERT_EQ(val.as_uint64(), 4ul); } { - val = (unsigned long long)5; + val = 5ull; GTEST_ASSERT_TRUE(val.is_uint64()); - GTEST_ASSERT_EQ(val.as_uint64(), (unsigned long)5); + GTEST_ASSERT_EQ(val.as_uint64(), 5ul); } { - val = (double)1.5; + val = 1.5; GTEST_ASSERT_TRUE(val.is_double()); GTEST_ASSERT_EQ(val.as_double(), 1.5); } @@ -174,7 +174,7 @@ TEST(JSONValueTest, Emplace) { { val.emplace_int64() = -1; GTEST_ASSERT_TRUE(val.is_int64()); - GTEST_ASSERT_EQ(val.as_int64(), (int64_t)-1); + GTEST_ASSERT_EQ(val.as_int64(), -1); } { @@ -359,16 +359,16 @@ TEST(JSONValueTest, Move) { } TEST(JSONValueTest, CopyDifferentMetallAllocator) { - using valut_t = mj::value>; + using valut_t = mj::value>; { SCOPED_TRACE("Copy Assignment"); { - metall::manager manager_copy( - metall::create_only, - (test_utility::make_test_path() + "_copy").c_str()); - metall::manager manager_src( - metall::create_only, - (test_utility::make_test_path() + "_src").c_str()); + dice::copperr::manager manager_copy( + dice::copperr::create_only, + (test_utility::make_test_path() / "copy")); + dice::copperr::manager manager_src( + dice::copperr::create_only, + (test_utility::make_test_path() / "src")); auto *jv_copy = manager_copy.construct("jv")(manager_copy.get_allocator()); @@ -378,9 +378,9 @@ TEST(JSONValueTest, CopyDifferentMetallAllocator) { } { - metall::manager manager_copy( - metall::open_read_only, - (test_utility::make_test_path() + "_copy").c_str()); + dice::copperr::manager manager_copy( + dice::copperr::open_read_only, + (test_utility::make_test_path() / "copy")); const auto *const jv_copy = manager_copy.find("jv").first; check_json_string(*jv_copy); } @@ -389,12 +389,12 @@ TEST(JSONValueTest, CopyDifferentMetallAllocator) { { SCOPED_TRACE("Copy Constructor"); { - metall::manager manager_src( - metall::create_only, - (test_utility::make_test_path() + "_src").c_str()); - metall::manager manager_copy( - metall::create_only, - (test_utility::make_test_path() + "_copy").c_str()); + dice::copperr::manager manager_src( + dice::copperr::create_only, + (test_utility::make_test_path() / "src")); + dice::copperr::manager manager_copy( + dice::copperr::create_only, + (test_utility::make_test_path() / "copy")); auto json_src = mj::parse(json_string, manager_src.get_allocator()); // Construct a new one from another instance that was allocated by another // allocator @@ -404,9 +404,9 @@ TEST(JSONValueTest, CopyDifferentMetallAllocator) { } { - metall::manager manager_copy( - metall::open_read_only, - (test_utility::make_test_path() + "_copy").c_str()); + dice::copperr::manager manager_copy( + dice::copperr::open_read_only, + (test_utility::make_test_path() / "copy")); const auto *const jv_copy = manager_copy.find("jv").first; check_json_string(*jv_copy); } @@ -414,16 +414,16 @@ TEST(JSONValueTest, CopyDifferentMetallAllocator) { } TEST(JSONValueTest, MoveDifferentMetallAllocator) { - using valut_t = mj::value>; + using valut_t = mj::value>; { SCOPED_TRACE("Move Assignment"); { - metall::manager manager_move( - metall::create_only, - (test_utility::make_test_path() + "_move").c_str()); - metall::manager manager_src( - metall::create_only, - (test_utility::make_test_path() + "_src").c_str()); + dice::copperr::manager manager_move( + dice::copperr::create_only, + (test_utility::make_test_path() / "move")); + dice::copperr::manager manager_src( + dice::copperr::create_only, + (test_utility::make_test_path() / "src")); auto *jv_move = manager_move.construct("jv")(manager_move.get_allocator()); @@ -432,9 +432,9 @@ TEST(JSONValueTest, MoveDifferentMetallAllocator) { } { - metall::manager manager_move( - metall::open_read_only, - (test_utility::make_test_path() + "_move").c_str()); + dice::copperr::manager manager_move( + dice::copperr::open_read_only, + (test_utility::make_test_path() / "move")); const auto *const jv_move = manager_move.find("jv").first; check_json_string(*jv_move); } @@ -443,12 +443,12 @@ TEST(JSONValueTest, MoveDifferentMetallAllocator) { { SCOPED_TRACE("Move Constructor"); { - metall::manager manager_src( - metall::create_only, - (test_utility::make_test_path() + "_src").c_str()); - metall::manager manager_move( - metall::create_only, - (test_utility::make_test_path() + "_move").c_str()); + dice::copperr::manager manager_src( + dice::copperr::create_only, + (test_utility::make_test_path() / "src")); + dice::copperr::manager manager_move( + dice::copperr::create_only, + (test_utility::make_test_path() / "move")); // Construct a new one from another instance that was allocated by another // allocator auto *jv_move = manager_move.construct("jv")( @@ -458,9 +458,9 @@ TEST(JSONValueTest, MoveDifferentMetallAllocator) { } { - metall::manager manager_move( - metall::open_read_only, - (test_utility::make_test_path() + "_move").c_str()); + dice::copperr::manager manager_move( + dice::copperr::open_read_only, + (test_utility::make_test_path() / "move")); const auto *const jv_move = manager_move.find("jv").first; check_json_string(*jv_move); } diff --git a/test/container/stl_allocator_test.cpp b/tests/container/stl_allocator_test.cpp similarity index 84% rename from test/container/stl_allocator_test.cpp rename to tests/container/stl_allocator_test.cpp index 7935186a..adf34abe 100644 --- a/test/container/stl_allocator_test.cpp +++ b/tests/container/stl_allocator_test.cpp @@ -9,14 +9,14 @@ #include #include #include -#include +#include #include "../test_utility.hpp" template -using alloc_type = metall::manager::allocator_type; +using alloc_type = dice::copperr::manager::allocator_type; -const std::string &dir_path() { - const static std::string path(test_utility::make_test_path()); +const std::filesystem::path &dir_path() { + const static std::filesystem::path path(test_utility::make_test_path()); return path; } @@ -34,22 +34,22 @@ TEST(StlAllocatorTest, Types) { GTEST_ASSERT_EQ(typeid(std::allocator_traits::pointer), typeid(alloc_t::pointer)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::const_pointer), typeid(alloc_t::const_pointer)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::const_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::void_pointer), typeid(alloc_t::void_pointer)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::void_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::const_void_pointer), typeid(alloc_t::const_void_pointer)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::const_void_pointer), - typeid(metall::offset_ptr)); + typeid(dice::copperr::offset_ptr)); GTEST_ASSERT_EQ(typeid(std::allocator_traits::difference_type), typeid(alloc_t::difference_type)); @@ -100,7 +100,7 @@ TEST(StlAllocatorTest, Types) { }; using alloc_t = alloc_type; - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 24UL); alloc_t alloc = manager.get_allocator(); @@ -113,10 +113,10 @@ TEST(StlAllocatorTest, Types) { { auto p = std::allocator_traits::allocate(alloc, 1); std::allocator_traits::construct( - alloc, metall::to_raw_pointer(p), 10, 20.0); + alloc, dice::copperr::to_raw_pointer(p), 10, 20.0); GTEST_ASSERT_EQ(p->a, 10); GTEST_ASSERT_EQ(p->b, 20.0); - std::allocator_traits::destroy(alloc, metall::to_raw_pointer(p)); + std::allocator_traits::destroy(alloc, dice::copperr::to_raw_pointer(p)); } GTEST_ASSERT_EQ(std::allocator_traits::max_size(alloc), @@ -130,27 +130,21 @@ TEST(StlAllocatorTest, Types) { } TEST(StlAllocatorTest, Exception) { - metall::manager manager(metall::create_only, dir_path().c_str(), 1UL << 24UL); + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 24UL); alloc_type allocator = manager.get_allocator(); ASSERT_NO_THROW({ allocator.deallocate(allocator.allocate(1), 1); }); - // Turn off log temporary because the following exception test cases could - // show error messages - metall::logger::set_log_level(metall::logger::level::critical); - ASSERT_THROW({ allocator.allocate(1UL << 24UL); }, std::bad_alloc); ASSERT_THROW({ allocator.allocate(allocator.max_size() + 1); }, std::bad_array_new_length); - - metall::logger::set_log_level(metall::logger::level::error); } TEST(StlAllocatorTest, Container) { { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); using element_type = std::pair; @@ -178,7 +172,7 @@ TEST(StlAllocatorTest, NestedContainer) { alloc_type>>>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); map_type map(manager.get_allocator<>()); @@ -198,7 +192,7 @@ TEST(StlAllocatorTest, PersistentConstructFind) { boost::interprocess::vector>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); int *a = manager.construct("int")(10); @@ -211,7 +205,7 @@ TEST(StlAllocatorTest, PersistentConstructFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); const auto ret1 = manager.find("int"); ASSERT_NE(ret1.first, nullptr); @@ -228,7 +222,7 @@ TEST(StlAllocatorTest, PersistentConstructFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); ASSERT_FALSE(manager.destroy("int")); @@ -243,7 +237,7 @@ TEST(StlAllocatorTest, PersistentConstructOrFind) { boost::interprocess::vector>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); int *a = manager.find_or_construct("int")(10); ASSERT_EQ(*a, 10); @@ -255,7 +249,7 @@ TEST(StlAllocatorTest, PersistentConstructOrFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); int *a = manager.find_or_construct("int")(20); ASSERT_EQ(*a, 10); @@ -267,7 +261,7 @@ TEST(StlAllocatorTest, PersistentConstructOrFind) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); ASSERT_FALSE(manager.destroy("int")); @@ -289,7 +283,7 @@ TEST(StlAllocatorTest, PersistentNestedContainer) { alloc_type>>>; { - metall::manager manager(metall::create_only, dir_path().c_str(), + dice::copperr::manager manager(dice::copperr::create_only, dir_path(), 1UL << 27UL); map_type *map = manager.construct("map")(manager.get_allocator<>()); @@ -298,7 +292,7 @@ TEST(StlAllocatorTest, PersistentNestedContainer) { } { - metall::manager manager(metall::open_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_only, dir_path()); map_type *map; std::size_t n; std::tie(map, n) = manager.find("map"); @@ -309,7 +303,7 @@ TEST(StlAllocatorTest, PersistentNestedContainer) { } { - metall::manager manager(metall::open_read_only, dir_path().c_str()); + dice::copperr::manager manager(dice::copperr::open_read_only, dir_path()); map_type *map; std::size_t n; std::tie(map, n) = manager.find("map"); diff --git a/test/container/string_key_store_test.cpp b/tests/container/string_key_store_test.cpp similarity index 88% rename from test/container/string_key_store_test.cpp rename to tests/container/string_key_store_test.cpp index 1bc05d93..6a831205 100644 --- a/test/container/string_key_store_test.cpp +++ b/tests/container/string_key_store_test.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "../test_utility.hpp" #define METALL_CONTAINER_STRING_KEY_STORE_USE_SIMPLE_HASH @@ -18,7 +18,7 @@ namespace { namespace bip = boost::interprocess; TEST(StringKeyStoreTest, DuplicateInsert) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); ASSERT_FALSE(store.unique()); @@ -48,7 +48,7 @@ TEST(StringKeyStoreTest, DuplicateInsert) { } TEST(StringKeyStoreTest, UniqueInsert) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); ASSERT_TRUE(store.unique()); @@ -78,7 +78,7 @@ TEST(StringKeyStoreTest, UniqueInsert) { } TEST(StringKeyStoreTest, CopyConstructorDuplicate) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); store.insert("a"); store.insert("b"); @@ -103,7 +103,7 @@ TEST(StringKeyStoreTest, CopyConstructorDuplicate) { } TEST(StringKeyStoreTest, CopyConstructorUnique) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); store.insert("a"); store.insert("b"); @@ -127,7 +127,7 @@ TEST(StringKeyStoreTest, CopyConstructorUnique) { } TEST(StringKeyStoreTest, CopyAsignmentDuplicate) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); store.insert("a"); store.insert("b"); @@ -152,7 +152,7 @@ TEST(StringKeyStoreTest, CopyAsignmentDuplicate) { } TEST(StringKeyStoreTest, CopyAsignmentUnique) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); store.insert("a"); store.insert("b"); @@ -176,7 +176,7 @@ TEST(StringKeyStoreTest, CopyAsignmentUnique) { } TEST(StringKeyStoreTest, MoveConstructorDuplicate) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); store.insert("a"); store.insert("b"); @@ -193,7 +193,7 @@ TEST(StringKeyStoreTest, MoveConstructorDuplicate) { } TEST(StringKeyStoreTest, MoveConstructorUnique) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); store.insert("a"); store.insert("b"); @@ -209,7 +209,7 @@ TEST(StringKeyStoreTest, MoveConstructorUnique) { } TEST(StringKeyStoreTest, MoveAsignmentDuplicate) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); store.insert("a"); store.insert("b"); @@ -226,7 +226,7 @@ TEST(StringKeyStoreTest, MoveAsignmentDuplicate) { } TEST(StringKeyStoreTest, MoveAsignmentUnique) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); store.insert("a"); store.insert("b"); @@ -242,7 +242,7 @@ TEST(StringKeyStoreTest, MoveAsignmentUnique) { } TEST(StringKeyStoreTest, Clear) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); store.insert("a"); store.insert("b", "0"); @@ -251,7 +251,7 @@ TEST(StringKeyStoreTest, Clear) { } TEST(StringKeyStoreTest, EraseMultipleWithKey) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); ASSERT_EQ(store.erase("a"), 0); store.insert("a"); @@ -265,7 +265,7 @@ TEST(StringKeyStoreTest, EraseMultipleWithKey) { } TEST(StringKeyStoreTest, EraseSingleWithKey) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); ASSERT_EQ(store.erase("a"), 0); store.insert("a"); @@ -279,7 +279,7 @@ TEST(StringKeyStoreTest, EraseSingleWithKey) { } TEST(StringKeyStoreTest, EraseMultipleWithLocator) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); ASSERT_EQ(store.erase(store.find("a")), store.end()); store.insert("a"); @@ -294,7 +294,7 @@ TEST(StringKeyStoreTest, EraseMultipleWithLocator) { } TEST(StringKeyStoreTest, EraseSingleWithLocator) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); ASSERT_EQ(store.erase(store.find("a")), store.end()); store.insert("a"); @@ -308,7 +308,7 @@ TEST(StringKeyStoreTest, EraseSingleWithLocator) { } TEST(StringKeyStoreTest, LocatorDuplicate) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(false, 111); ASSERT_EQ(store.begin(), store.end()); ASSERT_EQ(store.find("a"), store.end()); @@ -370,7 +370,7 @@ TEST(StringKeyStoreTest, LocatorDuplicate) { } TEST(StringKeyStoreTest, LocatorUnique) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store(true, 111); ASSERT_EQ(store.begin(), store.end()); ASSERT_EQ(store.find("a"), store.end()); @@ -432,7 +432,7 @@ TEST(StringKeyStoreTest, LocatorUnique) { } TEST(StringKeyStoreTest, MaxProbeDistance) { - metall::container::string_key_store> store; + dice::copperr::container::string_key_store> store; ASSERT_EQ(store.max_id_probe_distance(), 0); store.insert("a"); ASSERT_EQ(store.max_id_probe_distance(), 0); @@ -441,7 +441,7 @@ TEST(StringKeyStoreTest, MaxProbeDistance) { } TEST(StringKeyStoreTest, Rehash) { - metall::container::string_key_store> + dice::copperr::container::string_key_store> store; store.insert("a", "0"); store.insert("b", "1"); @@ -459,12 +459,12 @@ TEST(StringKeyStoreTest, Rehash) { TEST(StringKeyStoreTest, Persistence) { using value_type = boost::container::vector< int, bip::allocator>; - using store_type = metall::container::string_key_store< + using store_type = dice::copperr::container::string_key_store< value_type, bip::allocator>; const std::string file_path(test_utility::make_test_path()); test_utility::create_test_dir(); - metall::mtlldetail::remove_file(file_path); + dice::copperr::mtlldetail::remove_file(file_path); // Create { diff --git a/tests/ffi/CMakeLists.txt b/tests/ffi/CMakeLists.txt new file mode 100644 index 00000000..ae3bf652 --- /dev/null +++ b/tests/ffi/CMakeLists.txt @@ -0,0 +1,2 @@ +add_copperr_test_executable(ffi_test ffi_test.cpp) +target_link_libraries(ffi_test PRIVATE copperr::ffi) \ No newline at end of file diff --git a/tests/ffi/ffi_test.cpp b/tests/ffi/ffi_test.cpp new file mode 100644 index 00000000..cc658a8a --- /dev/null +++ b/tests/ffi/ffi_test.cpp @@ -0,0 +1,115 @@ +#include "gtest/gtest.h" +#include + +#include +#include + +TEST(FFI, SanityCheck) { + char const *obj_name = "obj"; + std::string const path = "/tmp/copperr-ffi" + std::to_string(std::random_device{}()); + std::string const snap_path = path + "-snap"; + + { + copperr_manager *manager = copperr_create(path.c_str()); + if (manager == nullptr) { + std::cerr << "failed to create: " << strerror(errno) << std::endl; + FAIL(); + } + + { + auto *ptr = static_cast(copperr_named_malloc(manager, obj_name, sizeof(size_t))); + ASSERT_NE(ptr, nullptr); + ASSERT_EQ(reinterpret_cast(ptr) % alignof(size_t), 0); + + *ptr = 55; + ASSERT_EQ(*ptr, 55); + } + + copperr_close(manager); + } + + { + copperr_manager *manager = copperr_open(path.c_str()); + if (manager == nullptr) { + std::cerr << "failed to create: " << strerror(errno) << std::endl; + FAIL(); + } + + auto *ptr = static_cast(copperr_find(manager, obj_name)); + ASSERT_NE(ptr, nullptr); + ASSERT_EQ(reinterpret_cast(ptr) % alignof(size_t), 0); + + *ptr = 66; + ASSERT_EQ(*ptr, 66); + + if (!copperr_snapshot(manager, snap_path.c_str())) { + std::cerr << "failed to snapshot: " << strerror(errno) << std::endl; + FAIL(); + } + + copperr_close(manager); + } + + auto check = [obj_name](auto const &path) { + { + copperr_manager *manager = copperr_open_read_only(path.c_str()); + if (manager == nullptr) { + std::cerr << "failed to open: " << strerror(errno) << std::endl; + FAIL(); + } + + auto *ptr = static_cast(copperr_find(manager, obj_name)); + if (ptr == nullptr) { + std::cerr << "failed to load: " << strerror(errno) << std::endl; + FAIL(); + } + + ASSERT_EQ(*ptr, 66); + + ASSERT_FALSE(copperr_named_free(manager, obj_name)); + + copperr_close(manager); + } + + { + copperr_manager *manager = copperr_open(path.c_str()); + if (manager == nullptr) { + std::cerr << "failed to open: " << strerror(errno) << std::endl; + FAIL(); + } + + if (!copperr_named_free(manager, obj_name)) { + std::cerr << "failed to dealloc: " << strerror(errno) << std::endl; + FAIL(); + } + + copperr_close(manager); + + ASSERT_TRUE(copperr_remove(path.c_str())); + ASSERT_TRUE(!copperr_open(path.c_str())); + } + }; + + check(snap_path); + check(path); +} + +TEST(FFI, PreventOpenSameDatastoreTwice) { + std::string const path = "/tmp/" + std::to_string(std::random_device{}()); + copperr_manager *manager = copperr_create(path.c_str()); + if (manager == nullptr) { + std::cerr << "failed to create datastore: " << strerror(errno) << std::endl; + FAIL(); + } + + copperr_manager *manager2 = copperr_open(path.c_str()); + ASSERT_EQ(manager2, nullptr); + ASSERT_EQ(errno, ENOTRECOVERABLE); + + copperr_manager *manager3 = copperr_open(path.c_str()); + ASSERT_EQ(manager3, nullptr); + ASSERT_EQ(errno, ENOTRECOVERABLE); + + copperr_close(manager); + ASSERT_TRUE(copperr_remove(path.c_str())); +} diff --git a/tests/kernel/CMakeLists.txt b/tests/kernel/CMakeLists.txt new file mode 100644 index 00000000..bfec0c3d --- /dev/null +++ b/tests/kernel/CMakeLists.txt @@ -0,0 +1,34 @@ +add_copperr_test_executable(attributed_object_directory_test attributed_object_directory_test.cpp) + +add_copperr_test_executable(bin_manager_test bin_manager_test.cpp) + +add_copperr_test_executable(bin_directory_test bin_directory_test.cpp) + +add_copperr_test_executable(multilayer_bitset_test multilayer_bitset_test.cpp) + +add_copperr_test_executable(chunk_directory_test chunk_directory_test.cpp) + +add_copperr_test_executable(object_cache_test object_cache_test.cpp) + +add_copperr_test_executable(manager_test manager_test.cpp) + +add_copperr_test_executable(manager_test_single_thread manager_test.cpp) +target_compile_definitions(manager_test_single_thread PRIVATE "METALL_DISABLE_CONCURRENCY") + +add_copperr_test_executable(snapshot_test snapshot_test.cpp) + +add_copperr_test_executable(copy_file_test copy_file_test.cpp) + +include(${CMAKE_SOURCE_DIR}/cmake/setup_omp.cmake) +if (OpenMP_CXX_FOUND) + add_copperr_test_executable(manager_multithread_test manager_multithread_test.cpp) + setup_omp_target(manager_multithread_test) +else() + MESSAGE(STATUS "OpenMP is not found. Will not run multi-thread test.") +endif() + +add_copperr_test_executable(multimanager_test multimanager_test.cpp) + +add_copperr_test_executable(mmap_segment_storage_test mmap_segment_storage_test.cpp) + +add_copperr_test_executable(object_attribute_accessor_test object_attribute_accessor_test.cpp) diff --git a/test/kernel/attributed_object_directory_test.cpp b/tests/kernel/attributed_object_directory_test.cpp similarity index 95% rename from test/kernel/attributed_object_directory_test.cpp rename to tests/kernel/attributed_object_directory_test.cpp index c5b59750..c19063a9 100644 --- a/test/kernel/attributed_object_directory_test.cpp +++ b/tests/kernel/attributed_object_directory_test.cpp @@ -5,13 +5,13 @@ #include "gtest/gtest.h" #include -#include +#include #include "../test_utility.hpp" namespace { using directory_type = - metall::kernel::attributed_object_directory; + dice::copperr::kernel::attributed_object_directory; TEST(AttributedObjectDirectoryTest, Insert) { directory_type obj; @@ -176,7 +176,7 @@ TEST(AttributedObjectDirectoryTest, Serialize) { test_utility::create_test_dir(); const auto file(test_utility::make_test_path()); - ASSERT_TRUE(obj.serialize(file.c_str())); + ASSERT_TRUE(obj.serialize(file)); } TEST(AttributedObjectDirectoryTest, Deserialize) { @@ -187,12 +187,12 @@ TEST(AttributedObjectDirectoryTest, Deserialize) { directory_type obj; obj.insert("item1", 1, 2, 5); obj.insert("item2", 3, 4, 6, "description2"); - obj.serialize(file.c_str()); + obj.serialize(file); } { directory_type obj; - ASSERT_TRUE(obj.deserialize(file.c_str())); + ASSERT_TRUE(obj.deserialize(file)); // Get values correctly const auto itr1 = obj.find("item1"); diff --git a/test/kernel/bin_directory_test.cpp b/tests/kernel/bin_directory_test.cpp similarity index 85% rename from test/kernel/bin_directory_test.cpp rename to tests/kernel/bin_directory_test.cpp index b1c38a9f..cfcdc5c6 100644 --- a/test/kernel/bin_directory_test.cpp +++ b/tests/kernel/bin_directory_test.cpp @@ -5,19 +5,19 @@ #include "gtest/gtest.h" #include -#include -#include -#include +#include +#include +#include #include "../test_utility.hpp" namespace { using bin_no_mngr = - metall::kernel::bin_number_manager; constexpr int num_small_bins = - bin_no_mngr::to_bin_no(metall::manager::chunk_size() / 2) + 1; -using directory_type = metall::kernel::bin_directory< - num_small_bins, metall::manager::chunk_number_type, std::allocator>; + bin_no_mngr::to_bin_no(dice::copperr::manager::chunk_size() / 2) + 1; +using directory_type = dice::copperr::kernel::bin_directory< + num_small_bins, dice::copperr::manager::chunk_number_type, std::allocator>; TEST(BinDirectoryTest, Front) { std::allocator allocator; @@ -98,7 +98,7 @@ TEST(BinDirectoryTest, Serialize) { test_utility::create_test_dir(); const auto file = test_utility::make_test_path(); - ASSERT_TRUE(obj.serialize(file.c_str())); + ASSERT_TRUE(obj.serialize(file)); } TEST(BinDirectoryTest, Deserialize) { @@ -114,13 +114,13 @@ TEST(BinDirectoryTest, Deserialize) { obj.insert(num_small_bins - 1, 3); obj.insert(num_small_bins - 1, 4); - obj.serialize(file.c_str()); + obj.serialize(file); } { std::allocator allocator; directory_type obj(allocator); - ASSERT_TRUE(obj.deserialize(file.c_str())); + ASSERT_TRUE(obj.deserialize(file)); #ifdef METALL_USE_SORTED_BIN ASSERT_EQ(obj.front(0), 1); diff --git a/test/kernel/bin_manager_test.cpp b/tests/kernel/bin_manager_test.cpp similarity index 87% rename from test/kernel/bin_manager_test.cpp rename to tests/kernel/bin_manager_test.cpp index 5b37e777..541a72eb 100644 --- a/test/kernel/bin_manager_test.cpp +++ b/tests/kernel/bin_manager_test.cpp @@ -7,17 +7,17 @@ #include -#include -#include -#include +#include +#include +#include namespace { -using namespace metall::kernel::object_size_manager_detail; +using namespace dice::copperr::kernel::object_size_manager_detail; -constexpr std::size_t k_chunk_size = metall::manager::chunk_size(); +constexpr std::size_t k_chunk_size = dice::copperr::manager::chunk_size(); constexpr std::size_t k_max_size = 1ULL << 48ULL; using bin_no_mngr = - metall::kernel::bin_number_manager; + dice::copperr::kernel::bin_number_manager; TEST(BinManagerTest, BinNoType) { ASSERT_GE(std::numeric_limits::max(), diff --git a/test/kernel/chunk_directory_test.cpp b/tests/kernel/chunk_directory_test.cpp similarity index 91% rename from test/kernel/chunk_directory_test.cpp rename to tests/kernel/chunk_directory_test.cpp index 5e26bc39..1103d82a 100644 --- a/test/kernel/chunk_directory_test.cpp +++ b/tests/kernel/chunk_directory_test.cpp @@ -6,21 +6,21 @@ #include "gtest/gtest.h" #include #include -#include -#include -#include +#include +#include +#include #include "../test_utility.hpp" namespace { -using chunk_no_type = metall::manager::chunk_number_type; -constexpr std::size_t k_chunk_size = metall::manager::chunk_size(); +using chunk_no_type = dice::copperr::manager::chunk_number_type; +constexpr std::size_t k_chunk_size = dice::copperr::manager::chunk_size(); using bin_no_mngr = - metall::kernel::bin_number_manager; + dice::copperr::kernel::bin_number_manager; constexpr int k_num_small_bins = bin_no_mngr::num_small_bins(); using chunk_directory_type = - metall::kernel::chunk_directory; + dice::copperr::kernel::chunk_directory; TEST(ChunkDirectoryTest, InsertSmallChunk) { chunk_directory_type directory(k_num_small_bins); @@ -124,7 +124,7 @@ TEST(ChunkDirectoryTest, Serialize) { test_utility::create_test_dir(); const auto file(test_utility::make_test_path()); - ASSERT_TRUE(directory.serialize(file.c_str())); + ASSERT_TRUE(directory.serialize(file)); } TEST(ChunkDirectoryTest, Deserialize) { @@ -146,13 +146,13 @@ TEST(ChunkDirectoryTest, Deserialize) { directory.insert(bin_no_mngr::num_small_bins()); // 1 chunk directory.insert(bin_no_mngr::num_small_bins() + 1); // 2 chunks - directory.serialize(file.c_str()); + directory.serialize(file); } { chunk_directory_type directory(bin_no_mngr::num_small_bins() + 4); - ASSERT_TRUE(directory.deserialize(file.c_str())); + ASSERT_TRUE(directory.deserialize(file)); for (uint64_t i = 0; i < bin_no_mngr::num_small_bins(); ++i) { const auto bin_no = static_cast(i); const auto chunk_no = static_cast(i); diff --git a/tests/kernel/copy_file_test.cpp b/tests/kernel/copy_file_test.cpp new file mode 100644 index 00000000..33183a4a --- /dev/null +++ b/tests/kernel/copy_file_test.cpp @@ -0,0 +1,415 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#include "gtest/gtest.h" + +#include + +#include +#include "../test_utility.hpp" + +#include +#include + +namespace { + +void create(const std::string &dir_path) { + dice::copperr::manager manager(dice::copperr::create_only, dir_path); + + manager.construct("a")(1); + manager.construct("b")(2); +} + +void open(const std::string &dir_path) { + dice::copperr::manager manager(dice::copperr::open_read_only, dir_path); + + auto a = manager.find("a").first; + ASSERT_EQ(*a, 1); + + auto b = manager.find("b").first; + ASSERT_EQ(*b, 2); +} + +const std::filesystem::path &original_dir_path() { + const static std::filesystem::path path(test_utility::make_test_path("/original")); + return path; +} + +const std::filesystem::path ©_dir_path() { + const static std::filesystem::path path(test_utility::make_test_path("/copy")); + return path; +} + +TEST(CopyFileTest, SyncCopy) { + dice::copperr::manager::remove(original_dir_path()); + dice::copperr::manager::remove(copy_dir_path()); + + create(original_dir_path()); + + ASSERT_TRUE(dice::copperr::manager::copy(original_dir_path(), + copy_dir_path())); + + open(copy_dir_path()); +} + +TEST(CopyFileTest, AsyncCopy) { + dice::copperr::manager::remove(original_dir_path()); + dice::copperr::manager::remove(copy_dir_path()); + + create(original_dir_path()); + + auto handler = dice::copperr::manager::copy_async(original_dir_path(), + copy_dir_path()); + ASSERT_TRUE(handler.get()); + + open(copy_dir_path()); +} + + + +constexpr size_t FILE_SIZE = 4096*4*11; +std::default_random_engine rng{std::random_device{}()}; + +// Utility functions + +/** + * Fills file at fd with FILE_SIZE random bytes + */ +void fill_file(int fd); + +/** + * Randomly punches 1-9 holes into fd. + * + * @param hole_at_start forces a hole to be created at the start of the file + * @param hole_at_end forces a hole to be created at the end of the file + */ +void punch_holes(int fd, bool hole_at_start = false, bool hole_at_end = false); + +/** + * Convenience wrapper around ::mmap + * @param fd file descriptor to mmap + * @return pair (pointer to mapped range, size of mapped range) + */ +std::pair mmap(int fd); + +/** + * Checks if files a and b are equal byte by byte + */ +void check_files_eq(int a, int b); + +/** + * Returns a list of all holes in the given file + */ +std::vector> get_holes(int fd); + +/** + * print all given holes + */ + void list_holes(std::vector> const &holes); + +/** + * Checks if the holes in a and b are in the same places and of the same size + */ +void check_holes_eq(std::vector> const &holes_a, std::vector> const &holes_b); + +template +void sparse_copy_test(std::filesystem::path const &srcp, + std::filesystem::path const &dstp, + std::filesystem::path const &dst2p, + P &&punch_holes) { + std::filesystem::remove(srcp); + std::filesystem::remove(dstp); + std::filesystem::remove(dst2p); + + { + int src = ::open(srcp.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (src == -1) { + perror("open"); + std::exit(1); + } + + fill_file(src); + punch_holes(src); + close(src); + } + + { // copy using copy_file_sparse_linux + int src = ::open(srcp.c_str(), O_RDONLY); + if (src == -1) { + perror("open"); + std::exit(1); + } + + struct stat st; + fstat(src, &st); + + int dst = ::open(dstp.c_str(), O_CREAT | O_WRONLY | O_TRUNC, st.st_mode); + if (dst == -1) { + perror("open"); + std::exit(1); + } + + ::dice::copperr::mtlldetail::file_copy_detail::copy_file_sparse_linux(src, dst, st.st_size); + close(src); + close(dst); + } + + { // copy using cp + std::ostringstream srcoss; + srcoss << srcp; + + std::ostringstream dstoss; + dstoss << dst2p; + + auto cmd = std::format("cp --sparse=always {} {}", srcoss.str(), dstoss.str()); + int res = std::system(cmd.c_str()); + assert(WIFEXITED(res)); + } + + int src = ::open(srcp.c_str(), O_RDONLY); + if (src == -1) { + perror("open"); + std::exit(1); + } + + int dst = ::open(dstp.c_str(), O_RDONLY); + if (dst == -1) { + perror("open"); + std::exit(1); + } + + int dst2 = ::open(dst2p.c_str(), O_RDONLY); + if (dst2 == -1) { + perror("open"); + std::exit(1); + } + + auto holes_src = get_holes(src); + auto holes_dst = get_holes(dst); + auto holes_dst2 = get_holes(dst2); + + std::cout << "src holes:\n"; + list_holes(holes_src); + std::cout << std::endl; + + std::cout << "dst holes:\n"; + list_holes(holes_dst); + std::cout << std::endl; + + std::cout << "dst2 holes:\n"; + list_holes(holes_dst2); + std::cout << std::endl; + + std::cout << "comparing src, dst" << std::endl; + check_files_eq(src, dst); + check_holes_eq(holes_src, holes_dst); + + // Not comparing holes to what cp produced because + // it tries to find more holes in the file or extend existing ones + std::cout << "comparing dst, dst2" << std::endl; + check_files_eq(dst, dst2); + + std::cout << "comparing dst2, src" << std::endl; + check_files_eq(dst2, src); + + std::cout << std::endl; +} + +TEST(CopyFileTest, RandomizedCopyFileSparseLinux) { + auto srcp = test_utility::make_test_path("copy_file_sparse-src.bin"); + auto dstp = test_utility::make_test_path("copy_file_sparse-dst.bin"); + auto dst2p = test_utility::make_test_path("copy_file_sparse-dst2.bin"); + + std::uniform_int_distribution b{0, 1}; + + for (size_t ix = 0; ix < 1000; ++ix) { + sparse_copy_test(srcp, dstp, dst2p, [&](int fd) { + punch_holes(fd, b(rng), b(rng)); + }); + } + + std::filesystem::remove(srcp); + std::filesystem::remove(dstp); + std::filesystem::remove(dst2p); +} + +TEST(CopyFileTest, AdjacentHolesCopyFileSparseLinux) { + auto srcp = test_utility::make_test_path("adj-copy_file_sparse-src.bin"); + auto dstp = test_utility::make_test_path("adj-copy_file_sparse-dst.bin"); + auto dst2p = test_utility::make_test_path("adj-copy_file_sparse-dst2.bin"); + + sparse_copy_test(srcp, dstp, dst2p, [&](int fd) { + std::cout << "punched holes:\n"; + + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096, 4096) == -1) { + perror("fallocate (punch_holes)"); + std::exit(1); + } + + std::cout << 4096 << ".." << (4096 * 2) << std::endl; + + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 4096 * 2, 4096) == -1) { + perror("fallocate (punch_holes)"); + std::exit(1); + } + + std::cout << (4096 * 2) << ".." << (4096 * 3) << std::endl; + }); + + std::filesystem::remove(srcp); + std::filesystem::remove(dstp); + std::filesystem::remove(dst2p); +} + + +void fill_file(int fd) { + std::vector buf; + std::uniform_int_distribution dist{1, std::numeric_limits::max()}; + + for (size_t ix = 0; ix < FILE_SIZE; ++ix) { + buf.push_back(dist(rng)); + assert(buf.back() != 0); + } + + size_t bytes_written = write(fd, buf.data(), buf.size()); + assert(bytes_written == FILE_SIZE); + + struct stat st; + fstat(fd, &st); + assert(st.st_size == FILE_SIZE); + + auto [ptr, sz] = mmap(fd); + for (size_t ix = 0; ix < static_cast(sz); ++ix) { + assert(ptr[ix] != 0); + } +} + +void punch_holes(int fd, bool hole_at_start, bool hole_at_end) { + std::vector> holes; + + std::uniform_int_distribution hole_num_dist{static_cast(1 + hole_at_start + hole_at_end), 10}; + std::uniform_int_distribution hole_size_dist{1, FILE_SIZE/10}; + std::uniform_int_distribution hole_off_dist{0, FILE_SIZE - FILE_SIZE/10}; + + std::cout << "punched holes:\n"; + + auto num_holes = hole_num_dist(rng); + for (size_t ix = 0; ix < num_holes - hole_at_end - hole_at_end; ++ix) { + auto hole_start = hole_off_dist(rng); + auto hole_size = hole_size_dist(rng); + + holes.emplace_back(hole_start, hole_start + hole_size); + + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, hole_start, hole_size) == -1) { + perror("fallocate (punch_holes)"); + std::exit(1); + } + } + + if (hole_at_start) { + auto sz = hole_size_dist(rng); + holes.emplace_back(0, sz); + + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, sz) == -1) { + perror("fallocate (punch_holes)"); + std::exit(1); + } + } + + if (hole_at_end) { + auto sz = hole_size_dist(rng); + holes.emplace_back(FILE_SIZE - sz, FILE_SIZE); + + if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, FILE_SIZE - sz, sz) == -1) { + perror("fallocate (punch_holes)"); + std::exit(1); + } + } + + std::ranges::sort(holes); + for (auto const &[start, end] : holes) { + std::cout << start << ".." << end << std::endl; + } + + std::cout << std::endl; +} + +std::pair mmap(int fd) { + struct stat st; + int res = fstat(fd, &st); + assert(res >= 0); + + auto *ptr = ::mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + assert(ptr != MAP_FAILED); + + return {static_cast(ptr), st.st_size}; +} + +void check_files_eq(int a, int b) { + auto am = mmap(a); + auto a_ptr = am.first; + auto a_size = am.second; + + auto bm = mmap(b); + auto b_ptr = bm.first; + auto b_size = bm.second; + + assert(a_size == b_size); + + for (size_t ix = 0; ix < static_cast(a_size); ++ix) { + if (a_ptr[ix] != b_ptr[ix]) { + std::cerr << "found different bytes: " << std::hex << static_cast(a_ptr[ix]) << " vs " << static_cast(b_ptr[ix]) << std::endl; + assert(false); + } + } +} + +std::vector> get_holes(int fd) { + lseek(fd, 0, SEEK_SET); + std::vector> holes; + + off_t off = 0; + off_t hole_start = 0; + + while (true) { + hole_start = lseek(fd, off, SEEK_HOLE); + off_t const hole_end = lseek(fd, hole_start, SEEK_DATA); + + if (hole_end == -1) { + break; + } + + off = hole_end; + holes.emplace_back(hole_start, hole_end); + } + + struct stat st; + fstat(fd, &st); + + if (hole_start < st.st_size) { + holes.emplace_back(hole_start, st.st_size); + } + + return holes; +} + +void list_holes(std::vector> const &holes) { + for (auto const &hole : holes) { + std::cout << "hole: " << hole.first << ".." << hole.second << std::endl; + } +} + +void check_holes_eq(std::vector> const &holes_a, std::vector> const &holes_b) { + assert(holes_a.size() == holes_b.size()); + + for (size_t ix = 0; ix < holes_a.size(); ++ix) { + if (holes_a[ix] != holes_b[ix]) { + std::cerr << "hole mismatch: " << holes_a[ix].first << ".." << holes_a[ix].second << " vs " << holes_b[ix].first << ".." << holes_b[ix].second << std::endl; + assert(false); + } + } +} + +} // namespace diff --git a/test/kernel/manager_multithread_test.cpp b/tests/kernel/manager_multithread_test.cpp similarity index 96% rename from test/kernel/manager_multithread_test.cpp rename to tests/kernel/manager_multithread_test.cpp index ac742faf..68010988 100644 --- a/test/kernel/manager_multithread_test.cpp +++ b/tests/kernel/manager_multithread_test.cpp @@ -18,13 +18,13 @@ #include #include -#include -#include +#include +#include #include "../test_utility.hpp" namespace { -namespace omp = metall::utility::omp; +namespace omp = dice::copperr::utility::omp; // -------------------- // // Manage Type @@ -32,7 +32,7 @@ namespace omp = metall::utility::omp; using chunk_no_type = uint32_t; static constexpr std::size_t k_chunk_size = 1ULL << 21; constexpr std::size_t k_min_object_size = 8; // TODO: take from the file -using manager_type = metall::basic_manager; +using manager_type = dice::copperr::basic_manager; template using allocator_type = typename manager_type::allocator_type; @@ -99,10 +99,9 @@ template void run_alloc_dealloc_separated_test(const list_type &allocation_size_list) { // Allocate manager const auto dir(test_utility::make_test_path()); - manager_type manager(metall::create_only, dir.c_str()); + manager_type manager(dice::copperr::create_only, dir); // Main loop - std::pair previous_allocation_rage(nullptr, nullptr); for (int k = 0; k < 2; ++k) { std::vector> addr_and_size_array( allocation_size_list.size(), {nullptr, 0}); @@ -134,7 +133,7 @@ void run_alloc_dealloc_mixed_and_write_value_test( const list_type &allocation_size_list) { // Allocate manager const auto dir(test_utility::make_test_path()); - manager_type manager(metall::create_only, dir.c_str()); + manager_type manager(dice::copperr::create_only, dir); // Main loop std::vector> previous_addr_and_size_array( @@ -295,7 +294,7 @@ TEST(ManagerMultithreadsTest, ConstructAndFind) { constexpr std::size_t num_allocates = 1024; const auto dir(test_utility::make_test_path()); - manager_type manager(metall::create_only, dir.c_str()); + manager_type manager(dice::copperr::create_only, dir); std::vector keys; for (std::size_t i = 0; i < num_allocates; ++i) { diff --git a/test/kernel/manager_test.cpp b/tests/kernel/manager_test.cpp similarity index 63% rename from test/kernel/manager_test.cpp rename to tests/kernel/manager_test.cpp index 491c8bb3..a972a3c4 100644 --- a/test/kernel/manager_test.cpp +++ b/tests/kernel/manager_test.cpp @@ -7,20 +7,20 @@ #include -#include -#include +#include +#include #include "../test_utility.hpp" namespace { -using namespace metall::mtlldetail; +using namespace dice::copperr::mtlldetail; -using manager_type = metall::manager; +using manager_type = dice::copperr::manager; template using allocator_type = typename manager_type::allocator_type; constexpr auto k_chunk_size = manager_type::chunk_size(); using object_size_mngr = - metall::kernel::object_size_manager; + dice::copperr::kernel::object_size_manager; constexpr std::size_t k_min_object_size = object_size_mngr::at(0); const std::string &dir_path() { @@ -30,15 +30,15 @@ const std::string &dir_path() { TEST(ManagerTest, CreateAndOpenModes) { { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.construct("int")(10), nullptr); ASSERT_TRUE(manager.destroy("int")); } { - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); auto ret = manager.find("int"); ASSERT_EQ(ret.first, nullptr); @@ -47,14 +47,14 @@ TEST(ManagerTest, CreateAndOpenModes) { } { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.construct("int")(10), nullptr); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); auto ret = manager.find("int"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(*(static_cast(ret.first)), 10); @@ -63,20 +63,20 @@ TEST(ManagerTest, CreateAndOpenModes) { } { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.construct("int")(10), nullptr); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); auto ret = manager.find("int"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(*(static_cast(ret.first)), 10); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); auto ret = manager.find("int"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(*(static_cast(ret.first)), 10); @@ -87,26 +87,38 @@ TEST(ManagerTest, CreateAndOpenModes) { TEST(ManagerTest, ConstructArray) { { + manager_type::remove(dir_path()); + manager_type::remove(dir_path() + "-snap"); + { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); - ASSERT_NE(manager.construct("int")[2](10), nullptr); + ASSERT_NE(manager.construct("arr")[8]('a'), nullptr); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); - auto ret = manager.find("int"); + manager_type manager(dice::copperr::open_read_only, dir_path()); + auto ret = manager.find("arr"); ASSERT_NE(ret.first, nullptr); - ASSERT_EQ(ret.second, 2); + ASSERT_EQ(ret.second, 8); auto a = ret.first; - ASSERT_EQ(a[0], 10); - ASSERT_EQ(a[1], 10); + ASSERT_EQ(a[0], 'a'); + ASSERT_EQ(a[1], 'a'); + + manager.snapshot(dir_path() + "-snap"); } { - manager_type manager(metall::open_only, dir_path().c_str()); - ASSERT_TRUE(manager.destroy("int")); + manager_type manager(dice::copperr::open_only, dir_path() + "-snap"); + auto [ptr, _] = manager.find("arr"); + ASSERT_EQ(ptr[0], 'a'); + + ASSERT_TRUE(manager.destroy("arr")); + } + + { + manager_type manager(dice::copperr::open_only, dir_path()); + ASSERT_TRUE(manager.destroy("arr")); } } } @@ -114,20 +126,20 @@ TEST(ManagerTest, ConstructArray) { TEST(ManagerTest, findOrConstruct) { { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.find_or_construct("int")(10), nullptr); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); int *a = manager.find_or_construct("int")(20); ASSERT_EQ(*a, 10); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); } } @@ -136,21 +148,21 @@ TEST(ManagerTest, findOrConstruct) { TEST(ManagerTest, findOrConstructArray) { { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.find_or_construct("int")[2](10), nullptr); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); int *a = manager.find_or_construct("int")[2](20); ASSERT_EQ(a[0], 10); ASSERT_EQ(a[1], 10); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); } } @@ -158,10 +170,10 @@ TEST(ManagerTest, findOrConstructArray) { TEST(ManagerTest, ConstructContainers) { { - using vec_t = std::vector>; + using vec_t = std::vector>; { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_NE(manager.construct("vecs")[2]( 2, 10, manager.get_allocator()), @@ -169,7 +181,7 @@ TEST(ManagerTest, ConstructContainers) { } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); auto ret = manager.find("vecs"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(ret.second, 2); @@ -183,7 +195,7 @@ TEST(ManagerTest, ConstructContainers) { } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("vecs")); ASSERT_TRUE(manager.all_memory_deallocated()); } @@ -193,15 +205,15 @@ TEST(ManagerTest, ConstructContainers) { TEST(ManagerTest, ConstructWithIterator) { { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); int values[2] = {10, 20}; ASSERT_NE(manager.construct_it("int")[2](&values[0]), nullptr); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); auto ret = manager.find("int"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(ret.second, 2); @@ -211,7 +223,7 @@ TEST(ManagerTest, ConstructWithIterator) { } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); } } @@ -226,8 +238,8 @@ TEST(ManagerTest, ConstructObjectsWithIterator) { { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); int values1[2] = {10, 20}; float values2[2] = {0.1, 0.2}; @@ -236,19 +248,19 @@ TEST(ManagerTest, ConstructObjectsWithIterator) { } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); auto ret = manager.find("data"); ASSERT_NE(ret.first, nullptr); ASSERT_EQ(ret.second, 2); data *d = ret.first; ASSERT_EQ(d[0].a, 10); - ASSERT_EQ(d[0].b, (float)0.1); + ASSERT_EQ(d[0].b, 0.1f); ASSERT_EQ(d[1].a, 20); - ASSERT_EQ(d[1].b, (float)0.2); + ASSERT_EQ(d[1].b, 0.2f); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("data")); } } @@ -257,8 +269,8 @@ TEST(ManagerTest, ConstructObjectsWithIterator) { TEST(ManagerTest, FindOrConstructWithIterator) { { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); int values[2] = {10, 20}; ASSERT_NE(manager.find_or_construct_it("int")[2](&values[0]), @@ -266,7 +278,7 @@ TEST(ManagerTest, FindOrConstructWithIterator) { } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); int values[2] = {30, 40}; int *a = manager.find_or_construct_it("int")[2](&values[0]); ASSERT_NE(a, nullptr); @@ -275,7 +287,7 @@ TEST(ManagerTest, FindOrConstructWithIterator) { } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("int")); } } @@ -283,22 +295,22 @@ TEST(ManagerTest, FindOrConstructWithIterator) { TEST(ManagerTest, Destroy) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_FALSE(manager.destroy("named_obj")); - ASSERT_FALSE(manager.destroy(metall::unique_instance)); + ASSERT_FALSE(manager.destroy(dice::copperr::unique_instance)); ASSERT_FALSE(manager.destroy("array_obj")); manager.construct("named_obj")(); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); manager.construct("array_obj")[2](10); ASSERT_TRUE(manager.destroy("named_obj")); ASSERT_FALSE(manager.destroy("named_obj")); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); - ASSERT_FALSE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); + ASSERT_FALSE(manager.destroy(dice::copperr::unique_instance)); ASSERT_TRUE(manager.destroy("array_obj")); ASSERT_FALSE(manager.destroy("array_obj")); @@ -307,20 +319,20 @@ TEST(ManagerTest, Destroy) { } { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); manager.construct("named_obj")(); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); manager.construct("array_obj")[2](10); } // Destroy after restoring { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy("named_obj")); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_TRUE(manager.destroy("array_obj")); ASSERT_TRUE(manager.all_memory_deallocated()); @@ -329,12 +341,12 @@ TEST(ManagerTest, Destroy) { TEST(ManagerTest, DestroyPtr) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); int *named_obj = manager.construct("named_obj")(); - int *unique_obj = manager.construct(metall::unique_instance)(); - int *anonymous_obj = manager.construct(metall::anonymous_instance)(); + int *unique_obj = manager.construct(dice::copperr::unique_instance)(); + int *anonymous_obj = manager.construct(dice::copperr::anonymous_instance)(); int *array_obj = manager.construct("array_obj")[2](10); ASSERT_TRUE(manager.destroy_ptr(named_obj)); @@ -351,27 +363,27 @@ TEST(ManagerTest, DestroyPtr) { } { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); manager.construct("named_obj")(); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); manager.construct("array_obj")[2](10); - int *anonymous_obj = manager.construct(metall::anonymous_instance)(); - manager.construct>("metall::offset_ptr")( + int *anonymous_obj = manager.construct(dice::copperr::anonymous_instance)(); + manager.construct>("copperr::offset_ptr")( anonymous_obj); } // Destroy after restoring { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_TRUE(manager.destroy_ptr(manager.find("named_obj").first)); ASSERT_TRUE( - manager.destroy_ptr(manager.find(metall::unique_instance).first)); + manager.destroy_ptr(manager.find(dice::copperr::unique_instance).first)); ASSERT_TRUE(manager.destroy_ptr(manager.find("array_obj").first)); - metall::offset_ptr *ptr = - manager.find>("metall::offset_ptr").first; + dice::copperr::offset_ptr *ptr = + manager.find>("copperr::offset_ptr").first; ASSERT_TRUE(manager.destroy_ptr(ptr->get())); // destroy anonymous object ASSERT_TRUE(manager.destroy_ptr(ptr)); } @@ -385,8 +397,8 @@ TEST(ManagerTest, DestroyDestruct) { // -- Check if destructors are called in destroy() -- // { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); int count = 3; auto *data_obj = manager.construct("named_obj")(); @@ -406,36 +418,36 @@ TEST(ManagerTest, DestroyDestruct) { TEST(ManagerTest, GetInstanceName) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_STREQ( manager.get_instance_name(manager.construct("named_obj")()), "named_obj"); ASSERT_STREQ(manager.get_instance_name( - manager.construct(metall::unique_instance)()), + manager.construct(dice::copperr::unique_instance)()), typeid(int).name()); ASSERT_STREQ(manager.get_instance_name( - manager.construct(metall::anonymous_instance)()), - (const char *)0); + manager.construct(dice::copperr::anonymous_instance)()), + nullptr); - manager.construct>("ptr")( - manager.construct(metall::anonymous_instance)()); + manager.construct>("ptr")( + manager.construct(dice::copperr::anonymous_instance)()); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); ASSERT_STREQ( manager.get_instance_name(manager.find("named_obj").first), "named_obj"); ASSERT_STREQ(manager.get_instance_name( - manager.find(metall::unique_instance).first), + manager.find(dice::copperr::unique_instance).first), typeid(int).name()); - metall::offset_ptr *ptr = - manager.find>("ptr").first; + dice::copperr::offset_ptr *ptr = + manager.find>("ptr").first; int *anonymous_obj = ptr->get(); - ASSERT_STREQ(manager.get_instance_name(anonymous_obj), (const char *)0); + ASSERT_STREQ(manager.get_instance_name(anonymous_obj), nullptr); } } @@ -453,9 +465,9 @@ TEST(ManagerTest, ConstructException) { } }; - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); bool do_throw[2] = {false, true}; bool wrong_destroy = false; bool *flags[2] = {&wrong_destroy, &wrong_destroy}; @@ -477,65 +489,65 @@ TEST(ManagerTest, DestructException) { ~object() noexcept(false) { throw std::runtime_error(""); } }; - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); - manager.construct(metall::unique_instance)(); - ASSERT_THROW(manager.destroy(metall::unique_instance), + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); + manager.construct(dice::copperr::unique_instance)(); + ASSERT_THROW(manager.destroy(dice::copperr::unique_instance), std::exception); } } TEST(ManagerTest, GetInstanceType) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_EQ(manager.get_instance_kind(manager.construct("named_obj")()), - metall::manager::instance_kind::named_kind); + dice::copperr::manager::instance_kind::named_kind); ASSERT_EQ(manager.get_instance_kind( - manager.construct(metall::unique_instance)()), - metall::manager::instance_kind::unique_kind); + manager.construct(dice::copperr::unique_instance)()), + dice::copperr::manager::instance_kind::unique_kind); ASSERT_EQ(manager.get_instance_kind( - manager.construct(metall::anonymous_instance)()), - metall::manager::instance_kind::anonymous_kind); + manager.construct(dice::copperr::anonymous_instance)()), + dice::copperr::manager::instance_kind::anonymous_kind); - manager.construct>("ptr")( - manager.construct(metall::anonymous_instance)()); + manager.construct>("ptr")( + manager.construct(dice::copperr::anonymous_instance)()); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); ASSERT_EQ(manager.get_instance_kind(manager.find("named_obj").first), - metall::manager::instance_kind::named_kind); + dice::copperr::manager::instance_kind::named_kind); ASSERT_EQ(manager.get_instance_kind( - manager.find(metall::unique_instance).first), - metall::manager::instance_kind::unique_kind); + manager.find(dice::copperr::unique_instance).first), + dice::copperr::manager::instance_kind::unique_kind); - metall::offset_ptr *ptr = - manager.find>("ptr").first; + dice::copperr::offset_ptr *ptr = + manager.find>("ptr").first; int *anonymous_obj = ptr->get(); ASSERT_EQ(manager.get_instance_kind(anonymous_obj), - metall::manager::instance_kind::anonymous_kind); + dice::copperr::manager::instance_kind::anonymous_kind); } } TEST(ManagerTest, GetInstanceLength) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_EQ( manager.get_instance_length(manager.construct("named_obj")()), 1); ASSERT_EQ(manager.get_instance_length( - manager.construct(metall::unique_instance)()), + manager.construct(dice::copperr::unique_instance)()), 1); ASSERT_EQ(manager.get_instance_length( - manager.construct(metall::anonymous_instance)()), + manager.construct(dice::copperr::anonymous_instance)()), 1); - manager.construct>("ptr")( - manager.construct(metall::anonymous_instance)()); + manager.construct>("ptr")( + manager.construct(dice::copperr::anonymous_instance)()); // Change data type to avoid duplicate unique instances and anonymous // instances @@ -543,26 +555,26 @@ TEST(ManagerTest, GetInstanceLength) { manager.get_instance_length(manager.construct("array_obj")[2]()), 2); ASSERT_EQ(manager.get_instance_length( - manager.construct(metall::unique_instance)[2]()), + manager.construct(dice::copperr::unique_instance)[2]()), 2); ASSERT_EQ(manager.get_instance_length( - manager.construct(metall::anonymous_instance)[2]()), + manager.construct(dice::copperr::anonymous_instance)[2]()), 2); - manager.construct>("ptr")( - manager.construct(metall::anonymous_instance)[2]()); + manager.construct>("ptr")( + manager.construct(dice::copperr::anonymous_instance)[2]()); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); { ASSERT_EQ( manager.get_instance_length(manager.find("named_obj").first), 1); ASSERT_EQ(manager.get_instance_length( - manager.find(metall::unique_instance).first), + manager.find(dice::copperr::unique_instance).first), 1); - metall::offset_ptr *ptr = - manager.find>("ptr").first; + dice::copperr::offset_ptr *ptr = + manager.find>("ptr").first; int *anonymous_obj = ptr->get(); ASSERT_EQ(manager.get_instance_length(anonymous_obj), 1); } @@ -572,10 +584,10 @@ TEST(ManagerTest, GetInstanceLength) { manager.get_instance_length(manager.find("array_obj").first), 2); ASSERT_EQ(manager.get_instance_length( - manager.find(metall::unique_instance).first), + manager.find(dice::copperr::unique_instance).first), 2); - metall::offset_ptr *ptr = - manager.find>("ptr").first; + dice::copperr::offset_ptr *ptr = + manager.find>("ptr").first; float *anonymous_obj = ptr->get(); ASSERT_EQ(manager.get_instance_length(anonymous_obj), 2); } @@ -584,38 +596,38 @@ TEST(ManagerTest, GetInstanceLength) { TEST(ManagerTest, IsInstanceType) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_TRUE( manager.is_instance_type(manager.construct("named_obj")())); ASSERT_FALSE( manager.is_instance_type(manager.construct("named_obj")())); ASSERT_TRUE(manager.is_instance_type( - manager.construct(metall::unique_instance)())); + manager.construct(dice::copperr::unique_instance)())); ASSERT_FALSE(manager.is_instance_type( - manager.construct(metall::unique_instance)())); + manager.construct(dice::copperr::unique_instance)())); ASSERT_TRUE(manager.is_instance_type( - manager.construct(metall::anonymous_instance)())); + manager.construct(dice::copperr::anonymous_instance)())); ASSERT_FALSE(manager.is_instance_type( - manager.construct(metall::anonymous_instance)())); - manager.construct>("ptr")( - manager.construct(metall::anonymous_instance)()); + manager.construct(dice::copperr::anonymous_instance)())); + manager.construct>("ptr")( + manager.construct(dice::copperr::anonymous_instance)()); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); ASSERT_TRUE( manager.is_instance_type(manager.find("named_obj").first)); ASSERT_FALSE( manager.is_instance_type(manager.find("named_obj").first)); ASSERT_TRUE(manager.is_instance_type( - manager.find(metall::unique_instance).first)); + manager.find(dice::copperr::unique_instance).first)); ASSERT_FALSE(manager.is_instance_type( - manager.find(metall::unique_instance).first)); - metall::offset_ptr *ptr = - manager.find>("ptr").first; + manager.find(dice::copperr::unique_instance).first)); + dice::copperr::offset_ptr *ptr = + manager.find>("ptr").first; int *anonymous_obj = ptr->get(); ASSERT_TRUE(manager.is_instance_type(anonymous_obj)); ASSERT_FALSE(manager.is_instance_type(anonymous_obj)); @@ -624,17 +636,17 @@ TEST(ManagerTest, IsInstanceType) { TEST(ManagerTest, InstanceDescription) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); auto *named_obj = manager.construct("named_obj")(); std::string desc_name = "desc name"; ASSERT_TRUE(manager.set_instance_description(named_obj, desc_name)); - auto *unique_obj = manager.construct(metall::unique_instance)(); + auto *unique_obj = manager.construct(dice::copperr::unique_instance)(); ASSERT_TRUE(manager.set_instance_description(unique_obj, "desc unique")); - auto *anonymous_obj = manager.construct(metall::anonymous_instance)(); + auto *anonymous_obj = manager.construct(dice::copperr::anonymous_instance)(); ASSERT_TRUE( manager.set_instance_description(anonymous_obj, "desc anonymous")); @@ -647,11 +659,11 @@ TEST(ManagerTest, InstanceDescription) { ASSERT_TRUE(manager.get_instance_description(anonymous_obj, &buf)); ASSERT_EQ(buf, "desc anonymous"); - manager.construct>("ptr")(anonymous_obj); + manager.construct>("ptr")(anonymous_obj); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); std::string buf; @@ -660,24 +672,24 @@ TEST(ManagerTest, InstanceDescription) { ASSERT_EQ(buf, "desc name"); ASSERT_TRUE(manager.get_instance_description( - manager.find(metall::unique_instance).first, &buf)); + manager.find(dice::copperr::unique_instance).first, &buf)); ASSERT_EQ(buf, "desc unique"); ASSERT_TRUE(manager.get_instance_description( - manager.find>("ptr").first->get(), &buf)); + manager.find>("ptr").first->get(), &buf)); ASSERT_EQ(buf, "desc anonymous"); ASSERT_TRUE(manager.set_instance_description( manager.find("named_obj").first, "desc name 2")); ASSERT_TRUE(manager.set_instance_description( - manager.find(metall::unique_instance).first, "desc unique 2")); + manager.find(dice::copperr::unique_instance).first, "desc unique 2")); ASSERT_TRUE(manager.set_instance_description( - manager.find>("ptr").first->get(), + manager.find>("ptr").first->get(), "desc anonymous 2")); } { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); std::string buf; @@ -686,28 +698,28 @@ TEST(ManagerTest, InstanceDescription) { ASSERT_EQ(buf, "desc name 2"); ASSERT_TRUE(manager.get_instance_description( - manager.find(metall::unique_instance).first, &buf)); + manager.find(dice::copperr::unique_instance).first, &buf)); ASSERT_EQ(buf, "desc unique 2"); ASSERT_TRUE(manager.get_instance_description( - manager.find>("ptr").first->get(), &buf)); + manager.find>("ptr").first->get(), &buf)); ASSERT_EQ(buf, "desc anonymous 2"); // Cannot change with the read only mode ASSERT_FALSE(manager.set_instance_description( manager.find("named_obj").first, "desc name 3")); ASSERT_FALSE(manager.set_instance_description( - manager.find(metall::unique_instance).first, "desc unique 3")); + manager.find(dice::copperr::unique_instance).first, "desc unique 3")); ASSERT_FALSE(manager.set_instance_description( - manager.find>("ptr").first->get(), + manager.find>("ptr").first->get(), "desc anonymous 3")); } } TEST(ManagerTest, CountObjects) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_EQ(manager.get_num_named_objects(), 0); manager.construct("named_obj1")(); @@ -716,15 +728,15 @@ TEST(ManagerTest, CountObjects) { ASSERT_EQ(manager.get_num_named_objects(), 2); ASSERT_EQ(manager.get_num_unique_objects(), 0); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); ASSERT_EQ(manager.get_num_unique_objects(), 1); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); ASSERT_EQ(manager.get_num_unique_objects(), 2); ASSERT_EQ(manager.get_num_anonymous_objects(), 0); - auto *anony_obj1 = manager.construct(metall::anonymous_instance)(); + auto *anony_obj1 = manager.construct(dice::copperr::anonymous_instance)(); ASSERT_EQ(manager.get_num_anonymous_objects(), 1); - auto *anony_obj2 = manager.construct(metall::anonymous_instance)(); + auto *anony_obj2 = manager.construct(dice::copperr::anonymous_instance)(); ASSERT_EQ(manager.get_num_anonymous_objects(), 2); ASSERT_TRUE(manager.destroy("named_obj1")); @@ -732,9 +744,9 @@ TEST(ManagerTest, CountObjects) { ASSERT_TRUE(manager.destroy("named_obj2")); ASSERT_EQ(manager.get_num_named_objects(), 0); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_EQ(manager.get_num_unique_objects(), 1); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_EQ(manager.get_num_unique_objects(), 0); ASSERT_TRUE(manager.destroy_ptr(anony_obj1)); @@ -746,23 +758,23 @@ TEST(ManagerTest, CountObjects) { ptrdiff_t anony_offset1 = 0; ptrdiff_t anony_offset2 = 0; { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); manager.construct("named_obj1")(); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); anony_offset1 = reinterpret_cast( - manager.construct(metall::anonymous_instance)()) - + manager.construct(dice::copperr::anonymous_instance)()) - reinterpret_cast(manager.get_address()); manager.construct("named_obj2")(); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); anony_offset2 = reinterpret_cast(manager.construct( - metall::anonymous_instance)()) - + dice::copperr::anonymous_instance)()) - reinterpret_cast(manager.get_address()); } { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); ASSERT_EQ(manager.get_num_named_objects(), 2); ASSERT_TRUE(manager.destroy("named_obj1")); @@ -771,9 +783,9 @@ TEST(ManagerTest, CountObjects) { ASSERT_EQ(manager.get_num_named_objects(), 0); ASSERT_EQ(manager.get_num_unique_objects(), 2); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_EQ(manager.get_num_unique_objects(), 1); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_EQ(manager.get_num_unique_objects(), 0); ASSERT_EQ(manager.get_num_anonymous_objects(), 2); @@ -788,8 +800,8 @@ TEST(ManagerTest, CountObjects) { TEST(ManagerTest, NamedObjectIterator) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); // Everyone is at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -832,8 +844,8 @@ TEST(ManagerTest, NamedObjectIterator) { TEST(ManagerTest, UniqueObjectIterator) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); // Everyone is at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -841,10 +853,10 @@ TEST(ManagerTest, UniqueObjectIterator) { ASSERT_EQ(manager.anonymous_begin(), manager.anonymous_end()); // Begin points the first object - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); ASSERT_STREQ(manager.unique_begin()->name().c_str(), typeid(int).name()); - manager.construct(metall::unique_instance)(); + manager.construct(dice::copperr::unique_instance)(); // The other directories are still at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -864,9 +876,9 @@ TEST(ManagerTest, UniqueObjectIterator) { ASSERT_TRUE(found2); ASSERT_EQ(count, 2); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); ASSERT_STREQ(manager.unique_begin()->name().c_str(), typeid(float).name()); - ASSERT_TRUE(manager.destroy(metall::unique_instance)); + ASSERT_TRUE(manager.destroy(dice::copperr::unique_instance)); // Everyone is at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -877,8 +889,8 @@ TEST(ManagerTest, UniqueObjectIterator) { TEST(ManagerTest, AnonymoustObjectIterator) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); // Everyone is at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -887,12 +899,12 @@ TEST(ManagerTest, AnonymoustObjectIterator) { // Begin points the first object auto *obj1 = reinterpret_cast( - manager.construct(metall::anonymous_instance)()); + manager.construct(dice::copperr::anonymous_instance)()); auto *segment = reinterpret_cast(manager.get_address()); ASSERT_EQ(manager.anonymous_begin()->offset(), obj1 - segment); auto *obj2 = reinterpret_cast( - manager.construct(metall::anonymous_instance)()); + manager.construct(dice::copperr::anonymous_instance)()); // The other directories are still at the end ASSERT_EQ(manager.named_begin(), manager.named_end()); @@ -924,10 +936,10 @@ TEST(ManagerTest, AnonymoustObjectIterator) { } TEST(ManagerTest, GetSegment) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); - auto *obj = manager.construct(metall::unique_instance)(); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); + auto *obj = manager.construct(dice::copperr::unique_instance)(); ASSERT_EQ(manager.unique_begin()->offset() + static_cast(manager.get_address()), reinterpret_cast(obj)); @@ -935,46 +947,46 @@ TEST(ManagerTest, GetSegment) { } TEST(ManagerTest, Consistency) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); // Must be inconsistent before closing - ASSERT_FALSE(manager_type::consistent(dir_path().c_str())); + ASSERT_FALSE(manager_type::consistent(dir_path())); manager.construct("dummy")(10); } - ASSERT_TRUE(manager_type::consistent(dir_path().c_str())); + ASSERT_TRUE(manager_type::consistent(dir_path())); { // To make sure the consistent mark is cleared even after creating a new // data store using an old dir path - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); - ASSERT_FALSE(manager_type::consistent(dir_path().c_str())); + ASSERT_FALSE(manager_type::consistent(dir_path())); manager.construct("dummy")(10); } - ASSERT_TRUE(manager_type::consistent(dir_path().c_str())); + ASSERT_TRUE(manager_type::consistent(dir_path())); { - manager_type manager(metall::open_only, dir_path().c_str()); - ASSERT_FALSE(manager_type::consistent(dir_path().c_str())); + manager_type manager(dice::copperr::open_only, dir_path()); + ASSERT_FALSE(manager_type::consistent(dir_path())); } - ASSERT_TRUE(manager_type::consistent(dir_path().c_str())); + ASSERT_TRUE(manager_type::consistent(dir_path())); { - manager_type manager(metall::open_read_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_read_only, dir_path()); // Still consistent if it is opened with the read-only mode - ASSERT_TRUE(manager_type::consistent(dir_path().c_str())); + ASSERT_TRUE(manager_type::consistent(dir_path())); } - ASSERT_TRUE(manager_type::consistent(dir_path().c_str())); + ASSERT_TRUE(manager_type::consistent(dir_path())); } TEST(ManagerTest, TinyAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); const std::size_t alloc_size = k_min_object_size / 2; @@ -995,8 +1007,8 @@ TEST(ManagerTest, TinyAllocation) { TEST(ManagerTest, SmallAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); const std::size_t alloc_size = k_min_object_size; @@ -1017,8 +1029,8 @@ TEST(ManagerTest, SmallAllocation) { TEST(ManagerTest, AllSmallAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); for (std::size_t s = 1; s < k_chunk_size; ++s) manager.deallocate(manager.allocate(s)); } @@ -1026,8 +1038,8 @@ TEST(ManagerTest, AllSmallAllocation) { TEST(ManagerTest, MaxSmallAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); // Max small allocation size const std::size_t alloc_size = @@ -1057,8 +1069,8 @@ TEST(ManagerTest, MaxSmallAllocation) { TEST(ManagerTest, MixedSmallAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path()); const std::size_t alloc_size1 = k_min_object_size * 2; const std::size_t alloc_size2 = k_min_object_size * 4; @@ -1097,8 +1109,8 @@ TEST(ManagerTest, MixedSmallAllocation) { TEST(ManagerTest, LargeAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path()); // Assume that the object cache is not used for large allocation char *base_addr = nullptr; @@ -1132,8 +1144,8 @@ TEST(ManagerTest, LargeAllocation) { TEST(ManagerTest, AllMemoryDeallocated) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str(), 1UL << 30UL); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path(), 1UL << 30UL); ASSERT_TRUE(manager.all_memory_deallocated()); @@ -1153,8 +1165,8 @@ TEST(ManagerTest, AllMemoryDeallocated) { TEST(ManagerTest, AlignedAllocation) { { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path()); for (std::size_t alignment = k_min_object_size; alignment <= k_chunk_size; alignment *= 2) { @@ -1208,27 +1220,27 @@ TEST(ManagerTest, AlignedAllocation) { } TEST(ManagerTest, Flush) { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path()); manager.construct("int")(10); manager.flush(); - ASSERT_FALSE(manager_type::consistent(dir_path().c_str())); + ASSERT_FALSE(manager_type::consistent(dir_path())); } TEST(ManagerTest, AnonymousConstruct) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); manager_type *manager; manager = - new manager_type(metall::create_only, dir_path().c_str(), 1UL << 30UL); + new manager_type(dice::copperr::create_only, dir_path(), 1UL << 30UL); - int *const a = manager->construct(metall::anonymous_instance)(); + int *const a = manager->construct(dice::copperr::anonymous_instance)(); ASSERT_NE(a, nullptr); // They have to be fail (return false values) - const auto ret = manager->find(metall::anonymous_instance); + const auto ret = manager->find(dice::copperr::anonymous_instance); ASSERT_EQ(ret.first, nullptr); ASSERT_EQ(ret.second, 0); @@ -1238,69 +1250,69 @@ TEST(ManagerTest, AnonymousConstruct) { } TEST(ManagerTest, UniqueConstruct) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); manager_type *manager; manager = - new manager_type(metall::create_only, dir_path().c_str(), 1UL << 30UL); + new manager_type(dice::copperr::create_only, dir_path(), 1UL << 30UL); - int *const a = manager->construct(metall::unique_instance)(); + int *const a = manager->construct(dice::copperr::unique_instance)(); ASSERT_NE(a, nullptr); double *const b = - manager->find_or_construct(metall::unique_instance)(); + manager->find_or_construct(dice::copperr::unique_instance)(); ASSERT_NE(b, nullptr); - ASSERT_EQ(manager->find(metall::unique_instance).first, a); - ASSERT_EQ(manager->find(metall::unique_instance).second, 1); + ASSERT_EQ(manager->find(dice::copperr::unique_instance).first, a); + ASSERT_EQ(manager->find(dice::copperr::unique_instance).second, 1); - ASSERT_EQ(manager->find(metall::unique_instance).first, b); - ASSERT_EQ(manager->find(metall::unique_instance).second, 1); + ASSERT_EQ(manager->find(dice::copperr::unique_instance).first, b); + ASSERT_EQ(manager->find(dice::copperr::unique_instance).second, 1); - ASSERT_EQ(manager->destroy(metall::unique_instance), true); - ASSERT_EQ(manager->destroy(metall::unique_instance), true); + ASSERT_EQ(manager->destroy(dice::copperr::unique_instance), true); + ASSERT_EQ(manager->destroy(dice::copperr::unique_instance), true); delete manager; } TEST(ManagerTest, UUID) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); std::string uuid; { - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type manager(dice::copperr::create_only, dir_path()); - uuid = manager_type::get_uuid(dir_path().c_str()); + uuid = manager_type::get_uuid(dir_path()); ASSERT_FALSE(uuid.empty()); } { // Returns the same UUID? - manager_type manager(metall::open_only, dir_path().c_str()); - ASSERT_EQ(manager_type::get_uuid(dir_path().c_str()), uuid); + manager_type manager(dice::copperr::open_only, dir_path()); + ASSERT_EQ(manager_type::get_uuid(dir_path()), uuid); } { // Returns a new UUID? - manager_type manager(metall::create_only, dir_path().c_str()); - ASSERT_NE(manager_type::get_uuid(dir_path().c_str()), uuid); + manager_type manager(dice::copperr::create_only, dir_path()); + ASSERT_NE(manager_type::get_uuid(dir_path()), uuid); } } TEST(ManagerTest, Version) { - manager_type::remove(dir_path().c_str()); + manager_type::remove(dir_path()); { - manager_type manager(metall::create_only, dir_path().c_str()); - ASSERT_EQ(manager_type::get_version(dir_path().c_str()), METALL_VERSION); + manager_type manager(dice::copperr::create_only, dir_path()); + ASSERT_EQ(manager_type::get_version(dir_path()), METALL_VERSION); } { - manager_type manager(metall::open_only, dir_path().c_str()); - ASSERT_EQ(manager_type::get_version(dir_path().c_str()), METALL_VERSION); + manager_type manager(dice::copperr::open_only, dir_path()); + ASSERT_EQ(manager_type::get_version(dir_path()), METALL_VERSION); } } TEST(ManagerTest, Description) { // Set and get with non-static method { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, dir_path().c_str()); + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, dir_path()); ASSERT_TRUE(manager.set_description("description1")); std::string description; @@ -1312,22 +1324,22 @@ TEST(ManagerTest, Description) { { std::string description; ASSERT_TRUE( - manager_type::get_description(dir_path().c_str(), &description)); + manager_type::get_description(dir_path(), &description)); ASSERT_STREQ(description.c_str(), "description1"); } // Set with static method { - manager_type::remove(dir_path().c_str()); - manager_type manager(metall::create_only, - dir_path().c_str()); // Make a new data store + manager_type::remove(dir_path()); + manager_type manager(dice::copperr::create_only, + dir_path()); // Make a new data store ASSERT_TRUE( - manager_type::set_description(dir_path().c_str(), "description2")); + manager_type::set_description(dir_path(), "description2")); } // Get with non-static method { - manager_type manager(metall::open_only, dir_path().c_str()); + manager_type manager(dice::copperr::open_only, dir_path()); std::string description; ASSERT_TRUE(manager.get_description(&description)); ASSERT_STREQ(description.c_str(), "description2"); @@ -1335,20 +1347,14 @@ TEST(ManagerTest, Description) { } TEST(ManagerTest, CheckSanity) { - // This test should be run at the end of this execution unless reset the - // values below: - metall::logger::set_log_level(metall::logger::level::silent); - metall::logger::abort_on_critical_error(false); - { - auto *manager = new manager_type(metall::create_only, dir_path().c_str()); - ASSERT_TRUE(manager->check_sanity()); + manager_type manager(dice::copperr::create_only, dir_path()); + ASSERT_TRUE(manager.check_sanity()); } { - auto *bad_manager = - new manager_type(metall::open_only, (dir_path() + "-invalid").c_str()); - ASSERT_FALSE(bad_manager->check_sanity()); + manager_type bad_manager(dice::copperr::open_only, (dir_path() + "-invalid").c_str()); + ASSERT_FALSE(bad_manager.check_sanity()); } } } // namespace diff --git a/test/kernel/mmap_segment_storage_test.cpp b/tests/kernel/mmap_segment_storage_test.cpp similarity index 81% rename from test/kernel/mmap_segment_storage_test.cpp rename to tests/kernel/mmap_segment_storage_test.cpp index e76c8064..bc700ecb 100644 --- a/test/kernel/mmap_segment_storage_test.cpp +++ b/tests/kernel/mmap_segment_storage_test.cpp @@ -5,26 +5,26 @@ #include "gtest/gtest.h" -#include +#include #include "../test_utility.hpp" namespace { using segment_storage_type = - metall::kernel::mmap_segment_storage; + dice::copperr::kernel::mmap_segment_storage; -const std::string &test_dir() { - const static std::string path(test_utility::make_test_path()); +const std::filesystem::path &test_dir() { + const static auto path = test_utility::make_test_path(); return path; } -const std::string &test_file_prefix() { - const static std::string path(test_dir() + "/backing_file"); +const std::filesystem::path &test_file_prefix() { + const static auto path = test_dir() / "backing_file"; return path; } void prepare_test_dir() { - ASSERT_TRUE(metall::mtlldetail::remove_file(test_dir())); - ASSERT_TRUE(metall::mtlldetail::create_directory(test_dir())); + ASSERT_TRUE(dice::copperr::mtlldetail::remove_file(test_dir())); + ASSERT_TRUE(dice::copperr::mtlldetail::create_directory(test_dir())); } TEST(MultifileSegmentStorageTest, PageSize) { @@ -34,7 +34,7 @@ TEST(MultifileSegmentStorageTest, PageSize) { TEST(MultifileSegmentStorageTest, Create) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); { @@ -67,12 +67,12 @@ TEST(MultifileSegmentStorageTest, Create) { } } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); } TEST(MultifileSegmentStorageTest, GetSize) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); // vm_size < single_file_size @@ -95,12 +95,12 @@ TEST(MultifileSegmentStorageTest, GetSize) { ASSERT_GE(segment_storage_type::get_size(test_file_prefix()), vm_size); } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); } TEST(MultifileSegmentStorageTest, Extend) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); { @@ -125,12 +125,12 @@ TEST(MultifileSegmentStorageTest, Extend) { } } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); } TEST(MultifileSegmentStorageTest, Openable) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); { prepare_test_dir(); @@ -138,15 +138,15 @@ TEST(MultifileSegmentStorageTest, Openable) { ASSERT_TRUE( segment_storage.create(test_file_prefix(), vm_size, addr, vm_size)); } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); ASSERT_TRUE(segment_storage_type::openable(test_file_prefix())); - ASSERT_FALSE(segment_storage_type::openable(test_file_prefix() + "_dummy")); + ASSERT_FALSE(segment_storage_type::openable(test_file_prefix() / "dummy")); } TEST(MultifileSegmentStorageTest, Open) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); { @@ -187,12 +187,12 @@ TEST(MultifileSegmentStorageTest, Open) { ASSERT_EQ(buf[i], '2'); } } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); } TEST(MultifileSegmentStorageTest, Sync) { constexpr std::size_t vm_size = 1ULL << 22ULL; - auto addr = metall::mtlldetail::reserve_vm_region(vm_size); + auto addr = dice::copperr::mtlldetail::reserve_vm_region(vm_size); ASSERT_NE(addr, nullptr); { @@ -223,6 +223,6 @@ TEST(MultifileSegmentStorageTest, Sync) { } } - ASSERT_TRUE(metall::mtlldetail::munmap(addr, vm_size, true)); + ASSERT_TRUE(dice::copperr::mtlldetail::munmap(addr, vm_size, true)); } } // namespace \ No newline at end of file diff --git a/test/kernel/multilayer_bitset_test.cpp b/tests/kernel/multilayer_bitset_test.cpp similarity index 85% rename from test/kernel/multilayer_bitset_test.cpp rename to tests/kernel/multilayer_bitset_test.cpp index 4fbc6cff..15a1a0bd 100644 --- a/test/kernel/multilayer_bitset_test.cpp +++ b/tests/kernel/multilayer_bitset_test.cpp @@ -10,15 +10,15 @@ #include #include -#include -#include +#include +#include namespace { TEST(MultilayerBitsetTest, FindAndSet) { for (uint64_t num_bits = 1; num_bits <= (64ULL * 64 * 64 * 32); num_bits *= 64) { // Test up to 4 layers, - metall::kernel::multilayer_bitset bitset; + dice::copperr::kernel::multilayer_bitset bitset; bitset.allocate(num_bits); for (uint64_t i = 0; i < num_bits; ++i) { ASSERT_EQ(bitset.find_and_set(num_bits), i); @@ -31,7 +31,7 @@ TEST(MultilayerBitsetTest, FindAndSet) { TEST(MultilayerBitsetTest, Reset) { for (uint64_t num_bits = 1; num_bits <= (64ULL * 64 * 64 * 32); num_bits *= 64) { // Test up to 4 layers - metall::kernel::multilayer_bitset bitset; + dice::copperr::kernel::multilayer_bitset bitset; bitset.allocate(num_bits); for (uint64_t i = 0; i < num_bits; ++i) { bitset.find_and_set(num_bits); @@ -49,13 +49,13 @@ TEST(MultilayerBitsetTest, Reset) { void FindAndSetManyHelper( const std::size_t num_bits, const std::size_t num_to_find, - metall::kernel::multilayer_bitset &bitset, - std::unordered_set + dice::copperr::kernel::multilayer_bitset &bitset, + std::unordered_set &used_bits) { SCOPED_TRACE("#of bits = " + std::to_string(num_bits) + ", #of finds = " + std::to_string(num_to_find)); - metall::kernel::multilayer_bitset::bit_position_type buf[num_to_find]; + dice::copperr::kernel::multilayer_bitset::bit_position_type buf[num_to_find]; bitset.find_and_set_many(num_bits, num_to_find, buf); @@ -74,10 +74,10 @@ void FindAndSetManyHelper( TEST(MultilayerBitsetTest, FindAndSetMany) { for (std::size_t num_bits = 1; num_bits <= (64ULL * 64 * 64 * 32); num_bits *= 64) { // Test up to 4 layers, - metall::kernel::multilayer_bitset bitset; + dice::copperr::kernel::multilayer_bitset bitset; bitset.allocate(num_bits); - std::unordered_set + std::unordered_set used_bits; FindAndSetManyHelper(num_bits, 1, bitset, used_bits); @@ -97,7 +97,7 @@ enum mode : uint8_t { set, reset, set_many }; void RandomSetAndResetHelper2(const std::size_t num_bits) { SCOPED_TRACE("num_bits = " + std::to_string(num_bits)); - metall::kernel::multilayer_bitset bitset; + dice::copperr::kernel::multilayer_bitset bitset; bitset.allocate(num_bits); std::vector reference(num_bits, false); @@ -128,8 +128,8 @@ void RandomSetAndResetHelper2(const std::size_t num_bits) { reference[position] = false; } } else { - const auto n = std::min((size_t)dist(rnd_gen), num_bits - cnt_trues); - metall::kernel::multilayer_bitset::bit_position_type buf[n]; + const auto n = std::min(dist(rnd_gen), num_bits - cnt_trues); + dice::copperr::kernel::multilayer_bitset::bit_position_type buf[n]; bitset.find_and_set_many(num_bits, n, buf); cnt_trues += n; for (std::size_t i = 0; i < n; ++i) { @@ -156,7 +156,7 @@ void RandomSetAndResetHelper2(const std::size_t num_bits) { // Set the remaining bits { const auto num_rem = num_bits - cnt_trues; - metall::kernel::multilayer_bitset::bit_position_type buf[num_rem]; + dice::copperr::kernel::multilayer_bitset::bit_position_type buf[num_rem]; bitset.find_and_set_many(num_bits, num_rem, buf); } for (std::size_t pos = 0; pos < num_bits; ++pos) { diff --git a/test/kernel/multimanager_test.cpp b/tests/kernel/multimanager_test.cpp similarity index 76% rename from test/kernel/multimanager_test.cpp rename to tests/kernel/multimanager_test.cpp index 26b4140b..161b997e 100644 --- a/test/kernel/multimanager_test.cpp +++ b/tests/kernel/multimanager_test.cpp @@ -9,34 +9,34 @@ #include #include -#include -#include +#include +#include #include "../test_utility.hpp" namespace { -namespace omp = metall::utility::omp; +namespace omp = dice::copperr::utility::omp; using chunk_no_type = uint32_t; constexpr std::size_t k_chunk_size = 1UL << 21UL; -using manager_type = metall::basic_manager; +using manager_type = dice::copperr::basic_manager; template -using metall_allocator = typename manager_type::allocator_type; +using copperr_allocator = typename manager_type::allocator_type; TEST(MultiManagerTest, SingleThread) { using element_type = uint64_t; using vector_type = - boost::interprocess::vector>; + boost::interprocess::vector>; test_utility::create_test_dir(); const auto dir_path1(test_utility::make_test_path(std::to_string(1))); const auto dir_path2(test_utility::make_test_path(std::to_string(2))); { - manager_type manager1(metall::create_only, dir_path1.c_str(), + manager_type manager1(dice::copperr::create_only, dir_path1, k_chunk_size * 8); - manager_type manager2(metall::create_only, dir_path2.c_str(), + manager_type manager2(dice::copperr::create_only, dir_path2, k_chunk_size * 8); vector_type *vector1 = @@ -52,8 +52,8 @@ TEST(MultiManagerTest, SingleThread) { } { - manager_type manager1(metall::open_only, dir_path1.c_str()); - manager_type manager2(metall::open_only, dir_path2.c_str()); + manager_type manager1(dice::copperr::open_only, dir_path1); + manager_type manager2(dice::copperr::open_only, dir_path2); vector_type *vector1; std::size_t n1; @@ -73,8 +73,8 @@ TEST(MultiManagerTest, SingleThread) { } { - manager_type manager1(metall::open_only, dir_path1.c_str()); - manager_type manager2(metall::open_only, dir_path2.c_str()); + manager_type manager1(dice::copperr::open_only, dir_path1); + manager_type manager2(dice::copperr::open_only, dir_path2); vector_type *vector1; std::size_t n1; @@ -105,13 +105,13 @@ int get_num_threads() { TEST(MultiManagerTest, MultiThread) { using element_type = uint64_t; using vector_type = - boost::interprocess::vector>; + boost::interprocess::vector>; OMP_DIRECTIVE(parallel) { const auto dir_path(test_utility::make_test_path( "/" + std::to_string(omp::get_thread_num()))); - manager_type manager(metall::create_only, dir_path.c_str(), + manager_type manager(dice::copperr::create_only, dir_path, k_chunk_size * 16); vector_type *vector = manager.construct("vector")(manager.get_allocator<>()); @@ -123,7 +123,7 @@ TEST(MultiManagerTest, MultiThread) { for (int t = 0; t < get_num_threads(); ++t) { const auto dir_path(test_utility::make_test_path("/" + std::to_string(t))); - manager_type manager(metall::open_only, dir_path.c_str()); + manager_type manager(dice::copperr::open_only, dir_path); vector_type *vector; std::size_t n; diff --git a/test/kernel/object_attribute_accessor_test.cpp b/tests/kernel/object_attribute_accessor_test.cpp similarity index 80% rename from test/kernel/object_attribute_accessor_test.cpp rename to tests/kernel/object_attribute_accessor_test.cpp index e1f9b96f..1223a8f0 100644 --- a/test/kernel/object_attribute_accessor_test.cpp +++ b/tests/kernel/object_attribute_accessor_test.cpp @@ -7,32 +7,32 @@ #include -#include +#include #include "../test_utility.hpp" namespace { -using namespace metall; +using namespace dice::copperr; auto attr_accessor_named() { return manager::access_named_object_attribute( - test_utility::make_test_path().c_str()); + test_utility::make_test_path()); } auto attr_accessor_unique() { return manager::access_unique_object_attribute( - test_utility::make_test_path().c_str()); + test_utility::make_test_path()); } auto attr_accessor_anonymous() { return manager::access_anonymous_object_attribute( - test_utility::make_test_path().c_str()); + test_utility::make_test_path()); } TEST(ObjectAttributeAccessorTest, Constructor) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -42,10 +42,10 @@ TEST(ObjectAttributeAccessorTest, Constructor) { } TEST(ObjectAttributeAccessorTest, NumObjects) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -56,7 +56,7 @@ TEST(ObjectAttributeAccessorTest, NumObjects) { } { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); mngr.construct("int1")(); mngr.construct("int2")(); mngr.construct(unique_instance)(); @@ -71,10 +71,10 @@ TEST(ObjectAttributeAccessorTest, NumObjects) { } TEST(ObjectAttributeAccessorTest, Count) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -84,7 +84,7 @@ TEST(ObjectAttributeAccessorTest, Count) { } { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); mngr.construct("int1")(); mngr.construct(unique_instance)(); } @@ -97,10 +97,10 @@ TEST(ObjectAttributeAccessorTest, Count) { } TEST(ObjectAttributeAccessorTest, Find) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -113,7 +113,7 @@ TEST(ObjectAttributeAccessorTest, Find) { } { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); mngr.construct("int1")(); mngr.construct(unique_instance)(); } @@ -127,10 +127,10 @@ TEST(ObjectAttributeAccessorTest, Find) { } TEST(ObjectAttributeAccessorTest, Iterator) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -148,7 +148,7 @@ TEST(ObjectAttributeAccessorTest, Iterator) { ptrdiff_t anony_off_obj1 = 0; ptrdiff_t anony_off_obj2 = 0; { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); mngr.construct("int1")(); mngr.construct("float1")(); @@ -210,10 +210,10 @@ TEST(ObjectAttributeAccessorTest, Iterator) { } TEST(ObjectAttributeAccessorTest, Description) { - manager::remove(test_utility::make_test_path().c_str()); + manager::remove(test_utility::make_test_path()); { - manager mngr(create_only, test_utility::make_test_path().c_str(), + manager mngr(create_only, test_utility::make_test_path(), 1ULL << 30ULL); } @@ -224,7 +224,7 @@ TEST(ObjectAttributeAccessorTest, Description) { } { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); mngr.construct("int1")(); mngr.construct(unique_instance)(); } @@ -236,7 +236,7 @@ TEST(ObjectAttributeAccessorTest, Description) { } { - manager mngr(open_only, test_utility::make_test_path().c_str()); + manager mngr(open_only, test_utility::make_test_path()); std::string buf1; ASSERT_TRUE( mngr.get_instance_description(mngr.find("int1").first, &buf1)); diff --git a/test/kernel/object_cache_test.cpp b/tests/kernel/object_cache_test.cpp similarity index 91% rename from test/kernel/object_cache_test.cpp rename to tests/kernel/object_cache_test.cpp index 6cd199fe..f79a9ab6 100644 --- a/test/kernel/object_cache_test.cpp +++ b/tests/kernel/object_cache_test.cpp @@ -10,13 +10,13 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../test_utility.hpp" using bin_no_manager = - metall::kernel::bin_number_manager<1ULL << 21, 1ULL << 40>; + dice::copperr::kernel::bin_number_manager<1ULL << 21, 1ULL << 40>; // Dummy allocator for testing // It keeps track of allocated objects @@ -28,7 +28,7 @@ class dummy_allocator { void allocate(const bin_no_manager::bin_no_type bin_no, const std::size_t n, std::ptrdiff_t *const offsets) { for (std::size_t i = 0; i < n; ++i) { - offsets[i] = (std::ptrdiff_t)(num_allocs[bin_no]++); + offsets[i] = static_cast(num_allocs[bin_no]++); records[bin_no].insert(offsets[i]); } } @@ -46,8 +46,8 @@ class dummy_allocator { }; using cache_type = - metall::kernel::object_cache; + dice::copperr::kernel::object_cache; namespace { TEST(ObjectCacheTest, Construct) { diff --git a/tests/kernel/snapshot_test.cpp b/tests/kernel/snapshot_test.cpp new file mode 100644 index 00000000..5802becf --- /dev/null +++ b/tests/kernel/snapshot_test.cpp @@ -0,0 +1,65 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#include "gtest/gtest.h" + +#include + +#include + +#include "../test_utility.hpp" + +namespace { + +std::filesystem::path original_dir_path() { + const std::filesystem::path path(test_utility::make_test_path("original")); + return path; +} + +std::filesystem::path snapshot_dir_path() { + const std::filesystem::path path(test_utility::make_test_path("snapshot")); + return path; +} + +TEST(SnapshotTest, Snapshot) { + dice::copperr::manager::remove(original_dir_path()); + dice::copperr::manager::remove(snapshot_dir_path()); + + { + dice::copperr::manager manager(dice::copperr::create_only, original_dir_path()); + + [[maybe_unused]] auto a = manager.construct("a")(1); + [[maybe_unused]] auto b = + manager.construct(dice::copperr::unique_instance)(2); + + ASSERT_TRUE(manager.snapshot(snapshot_dir_path())); + ASSERT_TRUE(dice::copperr::manager::consistent(snapshot_dir_path())); + + // UUID + const auto original_uuid = + dice::copperr::manager::get_uuid(original_dir_path()); + ASSERT_FALSE(original_uuid.empty()); + const auto snapshot_uuid = + dice::copperr::manager::get_uuid(snapshot_dir_path()); + ASSERT_FALSE(snapshot_uuid.empty()); + ASSERT_NE(original_uuid, snapshot_uuid); + + // Version + ASSERT_EQ(dice::copperr::manager::get_version(original_dir_path()), + dice::copperr::manager::get_version(snapshot_dir_path())); + } + + { + dice::copperr::manager manager(dice::copperr::open_read_only, + snapshot_dir_path()); + + auto a = manager.find("a").first; + ASSERT_EQ(*a, 1); + + auto b = manager.find(dice::copperr::unique_instance).first; + ASSERT_EQ(*b, 2); + } +} +} // namespace \ No newline at end of file diff --git a/tests/test_utility.hpp b/tests/test_utility.hpp new file mode 100644 index 00000000..39f4a6ba --- /dev/null +++ b/tests/test_utility.hpp @@ -0,0 +1,45 @@ +// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall +// Project Developers. See the top-level COPYRIGHT file for details. +// +// SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#ifndef METALL_TEST_UTILITY_HPP +#define METALL_TEST_UTILITY_HPP + +#include "gtest/gtest.h" + +#include +#include + +#include + +namespace test_utility { + +const char *k_test_dir_env_name = "COPPERR_TEST_DIR"; +const char *k_default_test_dir = "/tmp/copperr_test_dir"; + +namespace detail { +inline std::filesystem::path get_test_dir() { + if (const char *env_p = std::getenv(k_test_dir_env_name)) { + return std::string(env_p); + } + return k_default_test_dir; +} +} // namespace detail + +inline bool create_test_dir() { + if (!dice::copperr::mtlldetail::directory_exist(detail::get_test_dir())) + return dice::copperr::mtlldetail::create_directory(detail::get_test_dir()); + return true; +} + +inline std::filesystem::path make_test_path(const std::string &name = std::string()) { + return detail::get_test_dir() / + std::format("copperrtest-{}-{}-{}", + ::testing::UnitTest::GetInstance()->current_test_case()->name(), + ::testing::UnitTest::GetInstance()->current_test_info()->name(), + name); +} + +} // namespace test_utility +#endif // METALL_TEST_UTILITY_HPP diff --git a/tests/utility/CMakeLists.txt b/tests/utility/CMakeLists.txt new file mode 100644 index 00000000..0cab4059 --- /dev/null +++ b/tests/utility/CMakeLists.txt @@ -0,0 +1 @@ +add_copperr_test_executable(bitset_test bitset_test.cpp) \ No newline at end of file diff --git a/test/utility/bitset_test.cpp b/tests/utility/bitset_test.cpp similarity index 90% rename from test/utility/bitset_test.cpp rename to tests/utility/bitset_test.cpp index 5d16cb69..97b2068e 100644 --- a/test/utility/bitset_test.cpp +++ b/tests/utility/bitset_test.cpp @@ -6,23 +6,23 @@ #include "gtest/gtest.h" #include #include -#include +#include namespace { template using block_type = - typename metall::mtlldetail::bitset_detail::block_type::type; - -using metall::mtlldetail::bitset_detail::empty_block; -using metall::mtlldetail::bitset_detail::erase; -using metall::mtlldetail::bitset_detail::fill; -using metall::mtlldetail::bitset_detail::full_block; -using metall::mtlldetail::bitset_detail::generate_mask; -using metall::mtlldetail::bitset_detail::get; -using metall::mtlldetail::bitset_detail::num_blocks; -using metall::mtlldetail::bitset_detail::reset; -using metall::mtlldetail::bitset_detail::set; + typename dice::copperr::mtlldetail::bitset_detail::block_type::type; + +using dice::copperr::mtlldetail::bitset_detail::empty_block; +using dice::copperr::mtlldetail::bitset_detail::erase; +using dice::copperr::mtlldetail::bitset_detail::fill; +using dice::copperr::mtlldetail::bitset_detail::full_block; +using dice::copperr::mtlldetail::bitset_detail::generate_mask; +using dice::copperr::mtlldetail::bitset_detail::get; +using dice::copperr::mtlldetail::bitset_detail::num_blocks; +using dice::copperr::mtlldetail::bitset_detail::reset; +using dice::copperr::mtlldetail::bitset_detail::set; TEST(BitsetTest, BaseType) { ASSERT_LE(0, sizeof(block_type<0>) * 8); diff --git a/tutorial/hands_on/README.md b/tutorial/hands_on/README.md index a520303b..09d089b9 100644 --- a/tutorial/hands_on/README.md +++ b/tutorial/hands_on/README.md @@ -17,7 +17,7 @@ In this hands-on, we use the terminal available on the system. Click the button below (recommend to open in a new tab/window): -[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/LLNL/metall-tutorial/HEAD) +[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/LLNL/copperr-tutorial/HEAD) Binder runs on Kubernetes, and it sometime takes more than a few minutes to launch. @@ -37,7 +37,7 @@ Here is how to build a tutorial example. ```bash # Metall's git repository is available in the home directory. -cd $HOME/metall/tutorial/hands_on +cd $HOME/copperr/tutorial/hands_on # Build all examples make @@ -103,8 +103,8 @@ wget https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz tar xvf boost_1_75_0.tar.gz export BOOST_ROOT=$PWD/boost_1_75_0 -git clone https://github.com/LLNL/metall -cd metall/tutorial/hands_on +git clone https://github.com/LLNL/copperr +cd copperr/tutorial/hands_on g++ -std=c++17 [tutorial_program.cpp] -lstdc++fs -I../../include -I${BOOST_ROOT} # If one gets an error related to pthread, please add '-pthread' at the end of the command above @@ -130,9 +130,4 @@ clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} **On macOS < 10.15** The C++17 library is not available on macOS < 10.15. -One has to stop using C++17 library in Metall. -If METALL_DISABLE_CXX17_FILESYSTEM_LIB macro is defined, Metall uses its own file system operation implementation. - -```bash -clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} -DMETALL_DISABLE_CXX17_FILESYSTEM_LIB -``` \ No newline at end of file +Metall does not compile without . \ No newline at end of file diff --git a/tutorial/hands_on/t0.cpp b/tutorial/hands_on/t0.cpp index fef8893a..87aa18d8 100644 --- a/tutorial/hands_on/t0.cpp +++ b/tutorial/hands_on/t0.cpp @@ -6,10 +6,10 @@ // This program shows how to allocate memory using Metall. #include -#include +#include int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); // Allocate 'sizeof(int)' bytes, like malloc(sizeof(int)) // The object is allocated into persistent memory; diff --git a/tutorial/hands_on/t1-1.cpp b/tutorial/hands_on/t1-1.cpp index 2ac12970..95b44f04 100644 --- a/tutorial/hands_on/t1-1.cpp +++ b/tutorial/hands_on/t1-1.cpp @@ -6,12 +6,12 @@ // This program allocates an simple (int) object and reattaches it using Metall. #include -#include +#include int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); int *n = manager.construct // Allocates an 'int' object ("name") // Stores the allocated memory address with key "name" @@ -25,7 +25,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); int *n = manager.find("name").first; std::cout << *n << std::endl; diff --git a/tutorial/hands_on/t1-2.cpp b/tutorial/hands_on/t1-2.cpp index b42d7759..294b2c6c 100644 --- a/tutorial/hands_on/t1-2.cpp +++ b/tutorial/hands_on/t1-2.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include +#include // This program allocates a user-defined struct/class object and reattaches it // using Metall. One can learn how non-primitive data type object is constructed @@ -24,7 +24,7 @@ struct my_data { int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); std::cout << "Allocate and construct an object" << std::endl; manager.construct // Allocates an 'my_data' object @@ -39,7 +39,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); auto *data = manager.find("data").first; std::cout << data->n << " " << data->f << std::endl; diff --git a/tutorial/hands_on/t2-1.cpp b/tutorial/hands_on/t2-1.cpp index 7e58e08a..667ef50e 100644 --- a/tutorial/hands_on/t2-1.cpp +++ b/tutorial/hands_on/t2-1.cpp @@ -6,18 +6,18 @@ // This program shows how to use STL containers with Metall #include -#include +#include -// Metall contains basic STL containers that use metall as their default +// Metall contains basic STL containers that use copperr as their default // allocators. -#include +#include int main() { { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); // Allocate a vector object, passing an allocator object - auto* vec = manager.construct>("vec")( + auto* vec = manager.construct>("vec")( manager.get_allocator()); vec->resize(1); (*vec)[0] = 10; @@ -25,9 +25,9 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); - auto* vec = manager.find>("vec").first; + auto* vec = manager.find>("vec").first; std::cout << "Size = " << vec->size() << std::endl; std::cout << "Value at 0 = " << (*vec)[0] << std::endl; std::cout << "Value at 1 = " << (*vec)[1] << std::endl; @@ -36,9 +36,9 @@ int main() { } { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); - auto* vec = manager.find>("vec").first; + auto* vec = manager.find>("vec").first; std::cout << "Value at 2 = " << (*vec)[2] << std::endl; } diff --git a/tutorial/hands_on/t2-2.cpp b/tutorial/hands_on/t2-2.cpp index 2bc10a7e..31aa2078 100644 --- a/tutorial/hands_on/t2-2.cpp +++ b/tutorial/hands_on/t2-2.cpp @@ -6,25 +6,25 @@ // This program shows how to use multi-layer STL containers with Metall #include -#include -#include +#include +#include // Vector of int -using inner_vector_t = metall::container::vector; +using inner_vector_t = dice::copperr::container::vector; // Vector of vectors with scoped allocator adaptor // In multi-level containers, one has to use scoped_allocator_adaptor in the // most outer container so that the inner containers obtain their allocator // arguments from the outer container's scoped_allocator_adaptor (see details: // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor) -// metall::manager has an allocator that is already wrapped with scoped +// dice::copperr::manager has an allocator that is already wrapped with scoped // allocator adaptor so that applications can use simple statements. -using outer_vector_type = metall::container::vector< - inner_vector_t, metall::manager::scoped_allocator_type>; +using outer_vector_type = dice::copperr::container::vector< + inner_vector_t, dice::copperr::manager::scoped_allocator_type>; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto* vec = manager.construct("vec-of-vecs")( manager.get_allocator()); @@ -34,7 +34,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto* vec = manager.find("vec-of-vecs").first; std::cout << (*vec)[0][0] << std::endl; // Will print out 0 diff --git a/tutorial/hands_on/t3.cpp b/tutorial/hands_on/t3.cpp index 89ce62bc..dd2038d0 100644 --- a/tutorial/hands_on/t3.cpp +++ b/tutorial/hands_on/t3.cpp @@ -7,19 +7,19 @@ // offset pointer #include -#include +#include -// metall::offset_ptr is just an alias of offset_ptr in Boost.Interprocess +// dice::copperr::offset_ptr is just an alias of offset_ptr in Boost.Interprocess // https://www.boost.org/doc/libs/release/doc/html/interprocess/offset_ptr.html struct my_data { int len{0}; - metall::offset_ptr array{nullptr}; + dice::copperr::offset_ptr array{nullptr}; }; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto* data = manager.construct("data")(); data->len = 10; @@ -28,7 +28,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto* data = manager.find("data").first; for (int i = 0; i < data->len; ++i) diff --git a/tutorial/hands_on/t4-1.cpp b/tutorial/hands_on/t4-1.cpp index c407ef08..d7b32125 100644 --- a/tutorial/hands_on/t4-1.cpp +++ b/tutorial/hands_on/t4-1.cpp @@ -6,15 +6,15 @@ // This program shows how to make and use an allocator-aware data structure. #include -#include +#include #include "t4-1.hpp" -using persit_array = dynamic_array>; +using persit_array = dynamic_array>; int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto* array = manager.construct("array")(manager.get_allocator()); init(*array); @@ -22,7 +22,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); auto* array = manager.find("array").first; print(*array); manager.destroy_ptr(array); diff --git a/tutorial/hands_on/t4-2.cpp b/tutorial/hands_on/t4-2.cpp index baa4271a..242c1a90 100644 --- a/tutorial/hands_on/t4-2.cpp +++ b/tutorial/hands_on/t4-2.cpp @@ -6,22 +6,22 @@ // This program shows how to make and use an allocator-aware data structure. #include -#include +#include #include "t4-2.hpp" -using persit_matrix = matrix>; +using persit_matrix = matrix>; int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto* mx = manager.construct("mx")(manager.get_allocator()); init_matrix(*mx); } // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); auto* mx = manager.find("mx").first; print_matrix(*mx); manager.destroy_ptr(mx); diff --git a/tutorial/hands_on/t5-1.cpp b/tutorial/hands_on/t5-1.cpp index fb4d6804..99030f34 100644 --- a/tutorial/hands_on/t5-1.cpp +++ b/tutorial/hands_on/t5-1.cpp @@ -6,11 +6,11 @@ // This program shows how to use the snapshot feature in Metall #include -#include +#include int main() { { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto *n = manager.construct("n")(); *n = 10; @@ -23,7 +23,7 @@ int main() { // Reattach the original data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); std::cout << "Opened the original data" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; // Show '20' @@ -32,7 +32,7 @@ int main() { // Reattach the snapshot // A snapshot can be used as a normal Metall data store { - metall::manager manager(metall::open_only, "/tmp/snapshot"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/snapshot"); std::cout << "Opened the snapshot" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; // Show '10' since this snapshot was created diff --git a/tutorial/hands_on/t5-2_create.cpp b/tutorial/hands_on/t5-2_create.cpp index cfccbb3f..60253147 100644 --- a/tutorial/hands_on/t5-2_create.cpp +++ b/tutorial/hands_on/t5-2_create.cpp @@ -6,10 +6,10 @@ // This program shows the crash consistency of Metall snapshot #include -#include +#include int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto *n = manager.construct("n")(); *n = 10; diff --git a/tutorial/hands_on/t5-2_open.cpp b/tutorial/hands_on/t5-2_open.cpp index aea35c9b..4a60ce75 100644 --- a/tutorial/hands_on/t5-2_open.cpp +++ b/tutorial/hands_on/t5-2_open.cpp @@ -7,11 +7,11 @@ // it is consistent Please execute t5-2_create.cpp beforehand #include -#include +#include int main() { - if (metall::manager::consistent("/tmp/dir")) { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + if (dice::copperr::manager::consistent("/tmp/dir")) { + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); std::cout << "Opened /tmp/dir" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; @@ -22,8 +22,8 @@ int main() { << std::endl; } - if (metall::manager::consistent("/tmp/snapshot")) { - metall::manager manager(metall::open_read_only, "/tmp/snapshot"); + if (dice::copperr::manager::consistent("/tmp/snapshot")) { + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/snapshot"); std::cout << "Opened /tmp/snapshot" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; diff --git a/tutorial/ics21/README.md b/tutorial/ics21/README.md index d5496ffb..599138b7 100644 --- a/tutorial/ics21/README.md +++ b/tutorial/ics21/README.md @@ -39,5 +39,5 @@ Thanks to the recent notable performance improvements and cost reductions in non ## Tutorial Materials -* [Lecture slides](metall_101.pdf) +* [Lecture slides](copperr_101.pdf) * [Hands-on Examples](../hands_on) \ No newline at end of file diff --git a/tutorial/nvmw21/CMakeLists.txt b/tutorial/nvmw21/CMakeLists.txt index 0efa9a25..963d6791 100644 --- a/tutorial/nvmw21/CMakeLists.txt +++ b/tutorial/nvmw21/CMakeLists.txt @@ -32,20 +32,20 @@ find_package(MPI) # Targets # ---------------------------------------- # -function(add_metall_exe name) +function(add_copperr_exe name) add_executable(${name} ${name}.cpp) target_include_directories(${name} PRIVATE ../../include ${Boost_INCLUDE_DIRS}) target_link_libraries(${name} PRIVATE stdc++fs) endfunction() -add_metall_exe(t0) -add_metall_exe(t1-1) -add_metall_exe(t1-2) -add_metall_exe(t2-1) -add_metall_exe(t2-2) -add_metall_exe(t3) -add_metall_exe(t4-1) -add_metall_exe(t4-2) -add_metall_exe(t5-1) -add_metall_exe(t5-2_create) -add_metall_exe(t5-2_open) \ No newline at end of file +add_copperr_exe(t0) +add_copperr_exe(t1-1) +add_copperr_exe(t1-2) +add_copperr_exe(t2-1) +add_copperr_exe(t2-2) +add_copperr_exe(t3) +add_copperr_exe(t4-1) +add_copperr_exe(t4-2) +add_copperr_exe(t5-1) +add_copperr_exe(t5-2_create) +add_copperr_exe(t5-2_open) \ No newline at end of file diff --git a/tutorial/nvmw21/README.md b/tutorial/nvmw21/README.md index df098202..2a0752eb 100644 --- a/tutorial/nvmw21/README.md +++ b/tutorial/nvmw21/README.md @@ -31,7 +31,7 @@ tar xvf boost_1_75_0.tar.gz # 1. Lecture Materials -* [Metall 101 slides](metall_101.pdf) +* [Metall 101 slides](copperr_101.pdf) # 2. Hands-on @@ -54,8 +54,8 @@ wget https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz tar xvf boost_1_75_0.tar.gz export BOOST_ROOT=$PWD/boost_1_75_0 -git clone https://github.com/LLNL/metall -cd metall/tutorial/nvmw21 +git clone https://github.com/LLNL/copperr +cd copperr/tutorial/nvmw21 g++ -std=c++17 [tutorial_program.cpp] -lstdc++fs -I../../include -I${BOOST_ROOT} # All tutorial programs does not take command-line options @@ -76,13 +76,7 @@ However, please note that we haven't tested it intensively. clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} ``` - **On macOS < 10.15** The C++17 library is not available on macOS < 10.15. -One has to stop using C++17 library in Metall. -If METALL_DISABLE_CXX17_FILESYSTEM_LIB macro is defined, Metall uses its own file system operation implementation. - -```bash -clang++ -std=c++17 [tutorial_program.cpp] -I../../include -I${BOOST_ROOT} -DMETALL_DISABLE_CXX17_FILESYSTEM_LIB -``` \ No newline at end of file +Metall does not compile without . \ No newline at end of file diff --git a/tutorial/nvmw21/t0.cpp b/tutorial/nvmw21/t0.cpp index fef8893a..87aa18d8 100644 --- a/tutorial/nvmw21/t0.cpp +++ b/tutorial/nvmw21/t0.cpp @@ -6,10 +6,10 @@ // This program shows how to allocate memory using Metall. #include -#include +#include int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); // Allocate 'sizeof(int)' bytes, like malloc(sizeof(int)) // The object is allocated into persistent memory; diff --git a/tutorial/nvmw21/t1-1.cpp b/tutorial/nvmw21/t1-1.cpp index 2ac12970..95b44f04 100644 --- a/tutorial/nvmw21/t1-1.cpp +++ b/tutorial/nvmw21/t1-1.cpp @@ -6,12 +6,12 @@ // This program allocates an simple (int) object and reattaches it using Metall. #include -#include +#include int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); int *n = manager.construct // Allocates an 'int' object ("name") // Stores the allocated memory address with key "name" @@ -25,7 +25,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); int *n = manager.find("name").first; std::cout << *n << std::endl; diff --git a/tutorial/nvmw21/t1-2.cpp b/tutorial/nvmw21/t1-2.cpp index b42d7759..294b2c6c 100644 --- a/tutorial/nvmw21/t1-2.cpp +++ b/tutorial/nvmw21/t1-2.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include +#include // This program allocates a user-defined struct/class object and reattaches it // using Metall. One can learn how non-primitive data type object is constructed @@ -24,7 +24,7 @@ struct my_data { int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); std::cout << "Allocate and construct an object" << std::endl; manager.construct // Allocates an 'my_data' object @@ -39,7 +39,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); auto *data = manager.find("data").first; std::cout << data->n << " " << data->f << std::endl; diff --git a/tutorial/nvmw21/t2-1.cpp b/tutorial/nvmw21/t2-1.cpp index 7e58e08a..667ef50e 100644 --- a/tutorial/nvmw21/t2-1.cpp +++ b/tutorial/nvmw21/t2-1.cpp @@ -6,18 +6,18 @@ // This program shows how to use STL containers with Metall #include -#include +#include -// Metall contains basic STL containers that use metall as their default +// Metall contains basic STL containers that use copperr as their default // allocators. -#include +#include int main() { { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); // Allocate a vector object, passing an allocator object - auto* vec = manager.construct>("vec")( + auto* vec = manager.construct>("vec")( manager.get_allocator()); vec->resize(1); (*vec)[0] = 10; @@ -25,9 +25,9 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); - auto* vec = manager.find>("vec").first; + auto* vec = manager.find>("vec").first; std::cout << "Size = " << vec->size() << std::endl; std::cout << "Value at 0 = " << (*vec)[0] << std::endl; std::cout << "Value at 1 = " << (*vec)[1] << std::endl; @@ -36,9 +36,9 @@ int main() { } { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); - auto* vec = manager.find>("vec").first; + auto* vec = manager.find>("vec").first; std::cout << "Value at 2 = " << (*vec)[2] << std::endl; } diff --git a/tutorial/nvmw21/t2-2.cpp b/tutorial/nvmw21/t2-2.cpp index 2bc10a7e..31aa2078 100644 --- a/tutorial/nvmw21/t2-2.cpp +++ b/tutorial/nvmw21/t2-2.cpp @@ -6,25 +6,25 @@ // This program shows how to use multi-layer STL containers with Metall #include -#include -#include +#include +#include // Vector of int -using inner_vector_t = metall::container::vector; +using inner_vector_t = dice::copperr::container::vector; // Vector of vectors with scoped allocator adaptor // In multi-level containers, one has to use scoped_allocator_adaptor in the // most outer container so that the inner containers obtain their allocator // arguments from the outer container's scoped_allocator_adaptor (see details: // https://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor) -// metall::manager has an allocator that is already wrapped with scoped +// dice::copperr::manager has an allocator that is already wrapped with scoped // allocator adaptor so that applications can use simple statements. -using outer_vector_type = metall::container::vector< - inner_vector_t, metall::manager::scoped_allocator_type>; +using outer_vector_type = dice::copperr::container::vector< + inner_vector_t, dice::copperr::manager::scoped_allocator_type>; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto* vec = manager.construct("vec-of-vecs")( manager.get_allocator()); @@ -34,7 +34,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto* vec = manager.find("vec-of-vecs").first; std::cout << (*vec)[0][0] << std::endl; // Will print out 0 diff --git a/tutorial/nvmw21/t3.cpp b/tutorial/nvmw21/t3.cpp index 89ce62bc..dd2038d0 100644 --- a/tutorial/nvmw21/t3.cpp +++ b/tutorial/nvmw21/t3.cpp @@ -7,19 +7,19 @@ // offset pointer #include -#include +#include -// metall::offset_ptr is just an alias of offset_ptr in Boost.Interprocess +// dice::copperr::offset_ptr is just an alias of offset_ptr in Boost.Interprocess // https://www.boost.org/doc/libs/release/doc/html/interprocess/offset_ptr.html struct my_data { int len{0}; - metall::offset_ptr array{nullptr}; + dice::copperr::offset_ptr array{nullptr}; }; int main() { { - metall::manager manager(metall::create_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/datastore"); auto* data = manager.construct("data")(); data->len = 10; @@ -28,7 +28,7 @@ int main() { } { - metall::manager manager(metall::open_only, "/tmp/datastore"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/datastore"); auto* data = manager.find("data").first; for (int i = 0; i < data->len; ++i) diff --git a/tutorial/nvmw21/t4-1.cpp b/tutorial/nvmw21/t4-1.cpp index c407ef08..d7b32125 100644 --- a/tutorial/nvmw21/t4-1.cpp +++ b/tutorial/nvmw21/t4-1.cpp @@ -6,15 +6,15 @@ // This program shows how to make and use an allocator-aware data structure. #include -#include +#include #include "t4-1.hpp" -using persit_array = dynamic_array>; +using persit_array = dynamic_array>; int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto* array = manager.construct("array")(manager.get_allocator()); init(*array); @@ -22,7 +22,7 @@ int main() { // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); auto* array = manager.find("array").first; print(*array); manager.destroy_ptr(array); diff --git a/tutorial/nvmw21/t4-2.cpp b/tutorial/nvmw21/t4-2.cpp index baa4271a..242c1a90 100644 --- a/tutorial/nvmw21/t4-2.cpp +++ b/tutorial/nvmw21/t4-2.cpp @@ -6,22 +6,22 @@ // This program shows how to make and use an allocator-aware data structure. #include -#include +#include #include "t4-2.hpp" -using persit_matrix = matrix>; +using persit_matrix = matrix>; int main() { // Creating data into persistent memory { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto* mx = manager.construct("mx")(manager.get_allocator()); init_matrix(*mx); } // Reattaching the data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); auto* mx = manager.find("mx").first; print_matrix(*mx); manager.destroy_ptr(mx); diff --git a/tutorial/nvmw21/t5-1.cpp b/tutorial/nvmw21/t5-1.cpp index fb4d6804..99030f34 100644 --- a/tutorial/nvmw21/t5-1.cpp +++ b/tutorial/nvmw21/t5-1.cpp @@ -6,11 +6,11 @@ // This program shows how to use the snapshot feature in Metall #include -#include +#include int main() { { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto *n = manager.construct("n")(); *n = 10; @@ -23,7 +23,7 @@ int main() { // Reattach the original data { - metall::manager manager(metall::open_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/dir"); std::cout << "Opened the original data" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; // Show '20' @@ -32,7 +32,7 @@ int main() { // Reattach the snapshot // A snapshot can be used as a normal Metall data store { - metall::manager manager(metall::open_only, "/tmp/snapshot"); + dice::copperr::manager manager(dice::copperr::open_only, "/tmp/snapshot"); std::cout << "Opened the snapshot" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; // Show '10' since this snapshot was created diff --git a/tutorial/nvmw21/t5-2_create.cpp b/tutorial/nvmw21/t5-2_create.cpp index cfccbb3f..60253147 100644 --- a/tutorial/nvmw21/t5-2_create.cpp +++ b/tutorial/nvmw21/t5-2_create.cpp @@ -6,10 +6,10 @@ // This program shows the crash consistency of Metall snapshot #include -#include +#include int main() { - metall::manager manager(metall::create_only, "/tmp/dir"); + dice::copperr::manager manager(dice::copperr::create_only, "/tmp/dir"); auto *n = manager.construct("n")(); *n = 10; diff --git a/tutorial/nvmw21/t5-2_open.cpp b/tutorial/nvmw21/t5-2_open.cpp index aea35c9b..4a60ce75 100644 --- a/tutorial/nvmw21/t5-2_open.cpp +++ b/tutorial/nvmw21/t5-2_open.cpp @@ -7,11 +7,11 @@ // it is consistent Please execute t5-2_create.cpp beforehand #include -#include +#include int main() { - if (metall::manager::consistent("/tmp/dir")) { - metall::manager manager(metall::open_read_only, "/tmp/dir"); + if (dice::copperr::manager::consistent("/tmp/dir")) { + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/dir"); std::cout << "Opened /tmp/dir" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; @@ -22,8 +22,8 @@ int main() { << std::endl; } - if (metall::manager::consistent("/tmp/snapshot")) { - metall::manager manager(metall::open_read_only, "/tmp/snapshot"); + if (dice::copperr::manager::consistent("/tmp/snapshot")) { + dice::copperr::manager manager(dice::copperr::open_read_only, "/tmp/snapshot"); std::cout << "Opened /tmp/snapshot" << std::endl; auto *n = manager.find("n").first; std::cout << *n << std::endl; diff --git a/verification/file_clone/CMakeLists.txt b/verification/file_clone/CMakeLists.txt index d8472997..77095406 100644 --- a/verification/file_clone/CMakeLists.txt +++ b/verification/file_clone/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(verify_file_clone verify_file_clone.cpp) +add_copperr_executable(verify_file_clone verify_file_clone.cpp) diff --git a/verification/file_clone/verify_file_clone.cpp b/verification/file_clone/verify_file_clone.cpp index 8689c6d3..9d2a33e3 100644 --- a/verification/file_clone/verify_file_clone.cpp +++ b/verification/file_clone/verify_file_clone.cpp @@ -6,11 +6,11 @@ #include #include -#include -#include -#include +#include +#include +#include -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; void init_file(const std::string &file_path, const std::size_t size) { mdtl::create_file(file_path); diff --git a/verification/file_io/CMakeLists.txt b/verification/file_io/CMakeLists.txt index 0b073a85..748e1f50 100644 --- a/verification/file_io/CMakeLists.txt +++ b/verification/file_io/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(verify_64bits_file_io verify_64bits_file_io.cpp) \ No newline at end of file +add_copperr_executable(verify_64bits_file_io verify_64bits_file_io.cpp) \ No newline at end of file diff --git a/verification/file_io/verify_64bits_file_io.cpp b/verification/file_io/verify_64bits_file_io.cpp index 29ce470e..a5252acb 100644 --- a/verification/file_io/verify_64bits_file_io.cpp +++ b/verification/file_io/verify_64bits_file_io.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include int main(int argc, char *argv[]) { #ifdef _FILE_OFFSET_BITS @@ -29,8 +29,7 @@ int main(int argc, char *argv[]) { const int fd = ::open(file_name.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd == -1) { - metall::logger::perror(metall::logger::level::critical, __FILE__, __LINE__, - "open"); + METALL_ERRNO_ERROR("open"); std::abort(); } @@ -45,14 +44,12 @@ int main(int argc, char *argv[]) { } else { std::cerr << "Requested write size " << size << std::endl; std::cerr << "Actually written size " << written_size << std::endl; - metall::logger::perror(metall::logger::level::critical, __FILE__, __LINE__, - "write"); + METALL_ERRNO_ERROR("write"); std::abort(); } if (::close(fd) == -1) { - metall::logger::perror(metall::logger::level::critical, __FILE__, __LINE__, - "close"); + METALL_ERRNO_ERROR("close"); std::abort(); } diff --git a/verification/free_mmap_region/CMakeLists.txt b/verification/free_mmap_region/CMakeLists.txt index 9644775d..8a228b4d 100644 --- a/verification/free_mmap_region/CMakeLists.txt +++ b/verification/free_mmap_region/CMakeLists.txt @@ -1,2 +1,2 @@ -add_metall_executable(run_free_file_space_bench run_free_file_space_bench.cpp) -add_metall_executable(verify_mmap_region_free verify_mmap_region_free.cpp) \ No newline at end of file +add_copperr_executable(run_free_file_space_bench run_free_file_space_bench.cpp) +add_copperr_executable(verify_mmap_region_free verify_mmap_region_free.cpp) \ No newline at end of file diff --git a/verification/free_mmap_region/free_mmap_region.hpp b/verification/free_mmap_region/free_mmap_region.hpp index decd4553..ba5cd3a9 100644 --- a/verification/free_mmap_region/free_mmap_region.hpp +++ b/verification/free_mmap_region/free_mmap_region.hpp @@ -12,20 +12,19 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; static constexpr int k_map_nosync = #ifdef MAP_NOSYNC MAP_NOSYNC; #else 0; -#warning "MAP_NOSYNC is not defined" #endif std::size_t get_page_size() { @@ -34,7 +33,7 @@ std::size_t get_page_size() { std::cerr << __LINE__ << " Failed to get the page size" << std::endl; std::abort(); } - return (std::size_t)page_size; + return static_cast(page_size); } std::pair map_file_share(const std::string &file_path, diff --git a/verification/free_mmap_region/run_free_file_space_bench.cpp b/verification/free_mmap_region/run_free_file_space_bench.cpp index a1c7959e..4d1a1c6b 100644 --- a/verification/free_mmap_region/run_free_file_space_bench.cpp +++ b/verification/free_mmap_region/run_free_file_space_bench.cpp @@ -18,12 +18,12 @@ void commit_pages(const std::size_t size, void *const addr) { assert(size % page_size == 0); const std::size_t num_pages = size / page_size; - const auto num_threads = (int)std::min( - (std::size_t)num_pages, (std::size_t)std::thread::hardware_concurrency()); + const auto num_threads = std::min( + num_pages, std::thread::hardware_concurrency()); std::vector threads(num_threads, nullptr); const auto start = mdtl::elapsed_time_sec(); - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { const auto range = mdtl::partial_range(num_pages, t, num_threads); threads[t] = new std::thread([range, page_size, addr]() { for (std::size_t p = range.first; p < range.second; ++p) { @@ -55,7 +55,7 @@ void free_file_space(const std::size_t size, std::cout << __FUNCTION__ << " took\t" << elapsed_time << std::endl; } -int main(int, char *argv[]) { +int main([[maybe_unused]] int argc, char *argv[]) { const int mode = std::stoul(argv[1]); const std::string file_path(argv[2]); @@ -67,19 +67,19 @@ int main(int, char *argv[]) { void *map_addr = nullptr; std::tie(fd, map_addr) = map_file_share(file_path, map_size); std::cout << "DRAM usage (GB)" - << "\t" << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) + << "\t" << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)" - << "\t" << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << "\t" << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; commit_pages(map_size, map_addr); sync_mmap(map_addr, map_size); std::cout << "DRAM usage (GB)" - << "\t" << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) + << "\t" << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)" - << "\t" << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << "\t" << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; if (mode == 0) { @@ -139,10 +139,10 @@ int main(int, char *argv[]) { unmap(map_addr, map_size); std::cout << "File size (GB)\t" - << (double)mdtl::get_file_size(file_path) / (1ULL << 30ULL) + << static_cast(mdtl::get_file_size(file_path)) / (1ULL << 30ULL) << std::endl; std::cout << "Actual file size (GB)\t" - << (double)mdtl::get_actual_file_size(file_path) / (1ULL << 30ULL) + << static_cast(mdtl::get_actual_file_size(file_path)) / (1ULL << 30ULL) << std::endl; return 0; diff --git a/verification/free_mmap_region/verify_mmap_region_free.cpp b/verification/free_mmap_region/verify_mmap_region_free.cpp index b0101af6..724ef880 100644 --- a/verification/free_mmap_region/verify_mmap_region_free.cpp +++ b/verification/free_mmap_region/verify_mmap_region_free.cpp @@ -7,9 +7,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef __linux__ #include // For FALLOC_FL_PUNCH_HOLE and FALLOC_FL_KEEP_SIZE @@ -51,9 +51,9 @@ void free_file_backed_mmap( std::tie(fd, addr) = map_file(file_name, file_size); close_file(fd); std::cout << "DRAM usage (GB)\t" - << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) << std::endl; + << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)\t" - << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; // Commit pages @@ -64,9 +64,9 @@ void free_file_backed_mmap( map[i] = 1; } std::cout << "DRAM usage (GB)\t" - << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) << std::endl; + << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)\t" - << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; std::cout << "\n----- Uncommit pages -----" << std::endl; @@ -76,9 +76,9 @@ void free_file_backed_mmap( std::cout << "The current file size\t" << mdtl::get_actual_file_size(file_name) << std::endl; std::cout << "DRAM usage (GB)\t" - << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) << std::endl; + << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)\t" - << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; std::cout << "\n----- munmap -----" << std::endl; @@ -87,9 +87,9 @@ void free_file_backed_mmap( std::cout << "The current file size\t" << mdtl::get_actual_file_size(file_name) << std::endl; std::cout << "DRAM usage (GB)\t" - << (double)mdtl::get_used_ram_size() / (1ULL << 30ULL) << std::endl; + << static_cast(mdtl::get_used_ram_size()) / (1ULL << 30ULL) << std::endl; std::cout << "DRAM cache usage (GB)\t" - << (double)mdtl::get_page_cache_size() / (1ULL << 30ULL) + << static_cast(mdtl::get_page_cache_size()) / (1ULL << 30ULL) << std::endl; } diff --git a/verification/logger/CMakeLists.txt b/verification/logger/CMakeLists.txt index 88e53691..5fe79504 100644 --- a/verification/logger/CMakeLists.txt +++ b/verification/logger/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(verify_logger verify_logger.cpp) \ No newline at end of file +add_copperr_executable(verify_logger verify_logger.cpp) \ No newline at end of file diff --git a/verification/logger/verify_logger.cpp b/verification/logger/verify_logger.cpp index e8a4ba28..6044c2e9 100644 --- a/verification/logger/verify_logger.cpp +++ b/verification/logger/verify_logger.cpp @@ -4,72 +4,27 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include +#include -using namespace metall; +using namespace dice::copperr; void log_cerr() { - logger::out(logger::level::silent, __FILE__, __LINE__, "silent logger"); - logger::out(logger::level::critical, __FILE__, __LINE__, "critical logger"); - logger::out(logger::level::error, __FILE__, __LINE__, "error logger"); - logger::out(logger::level::warning, __FILE__, __LINE__, "warning logger"); - logger::out(logger::level::info, __FILE__, __LINE__, "info logger"); - logger::out(logger::level::debug, __FILE__, __LINE__, "debug logger"); - logger::out(logger::level::verbose, __FILE__, __LINE__, "verbose logger"); + METALL_ERROR("error logger"); + METALL_WARN("warning logger"); + METALL_INFO("info logger"); + METALL_DEBUG("debug logger"); + METALL_TRACE("verbose logger"); } void log_perror() { - logger::perror(logger::level::silent, __FILE__, __LINE__, "silent logger"); - logger::perror(logger::level::critical, __FILE__, __LINE__, - "critical logger"); - logger::perror(logger::level::error, __FILE__, __LINE__, "error logger"); - logger::perror(logger::level::warning, __FILE__, __LINE__, "warning logger"); - logger::perror(logger::level::info, __FILE__, __LINE__, "info logger"); - logger::perror(logger::level::debug, __FILE__, __LINE__, "debug logger"); - logger::perror(logger::level::verbose, __FILE__, __LINE__, "verbose logger"); + METALL_ERRNO_ERROR("error logger"); + METALL_ERRNO_WARN("warning logger"); + METALL_ERRNO_INFO("info logger"); + METALL_ERRNO_DEBUG("debug logger"); + METALL_ERRNO_TRACE("verbose logger"); } int main() { - logger::abort_on_critical_error(false); - - std::cerr << "--- Log level : unset ---" << std::endl; - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : silent ---" << std::endl; - logger::set_log_level(logger::level::silent); - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : critical ---" << std::endl; - logger::set_log_level(logger::level::critical); - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : error ---" << std::endl; - logger::set_log_level(logger::level::error); log_cerr(); log_perror(); - - std::cerr << "\n--- Log level : warning ---" << std::endl; - logger::set_log_level(logger::level::warning); - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : info ---" << std::endl; - logger::set_log_level(logger::level::info); - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : debug ---" << std::endl; - logger::set_log_level(logger::level::debug); - log_cerr(); - log_perror(); - - std::cerr << "\n--- Log level : verbose ---" << std::endl; - logger::set_log_level(logger::level::verbose); - log_cerr(); - log_perror(); - - return 0; } \ No newline at end of file diff --git a/verification/mmap/CMakeLists.txt b/verification/mmap/CMakeLists.txt index 51707cbe..91aee2f8 100644 --- a/verification/mmap/CMakeLists.txt +++ b/verification/mmap/CMakeLists.txt @@ -1,2 +1,2 @@ -add_metall_executable(run_many_files_mmap_bench run_many_files_mmap_bench.cpp) -add_metall_executable(verify_mmap verify_mmap.cpp) \ No newline at end of file +add_copperr_executable(run_many_files_mmap_bench run_many_files_mmap_bench.cpp) +add_copperr_executable(verify_mmap verify_mmap.cpp) \ No newline at end of file diff --git a/verification/mmap/run_many_files_mmap_bench.cpp b/verification/mmap/run_many_files_mmap_bench.cpp index c9a88a06..735be96b 100644 --- a/verification/mmap/run_many_files_mmap_bench.cpp +++ b/verification/mmap/run_many_files_mmap_bench.cpp @@ -12,30 +12,29 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -namespace mdtl = metall::mtlldetail; +namespace mdtl = dice::copperr::mtlldetail; static constexpr int k_map_nosync = #ifdef MAP_NOSYNC MAP_NOSYNC; #else 0; -#warning "MAP_NOSYNC is not defined" #endif template void init_array(random_iterator_type first, random_iterator_type last) { const std::size_t length = std::abs(std::distance(first, last)); - const auto num_threads = (int)std::min( - (std::size_t)length, (std::size_t)std::thread::hardware_concurrency()); + const auto num_threads = std::min( + length, std::thread::hardware_concurrency()); std::vector threads(num_threads, nullptr); const auto start = mdtl::elapsed_time_sec(); - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { const auto range = mdtl::partial_range(length, t, num_threads); threads[t] = new std::thread( [](random_iterator_type partial_first, @@ -57,12 +56,12 @@ void init_array(random_iterator_type first, random_iterator_type last) { template void run_sort(random_iterator_type first, random_iterator_type last) { const std::size_t length = std::abs(std::distance(first, last)); - const auto num_threads = (int)std::min( - (std::size_t)length, (std::size_t)std::thread::hardware_concurrency()); + const auto num_threads = std::min( + length, std::thread::hardware_concurrency()); std::vector threads(num_threads, nullptr); const auto start = mdtl::elapsed_time_sec(); - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { const auto range = mdtl::partial_range(length, t, num_threads); threads[t] = new std::thread( [](random_iterator_type partial_first, @@ -90,11 +89,11 @@ void sync_region(void *const address, const std::size_t size) { template void validate_array(random_iterator_type first, random_iterator_type last) { const std::size_t length = std::abs(std::distance(first, last)); - const auto num_threads = (int)std::min( - (std::size_t)length, (std::size_t)std::thread::hardware_concurrency()); + const auto num_threads = std::min( + length, std::thread::hardware_concurrency()); const auto start = mdtl::elapsed_time_sec(); - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { const auto range = mdtl::partial_range(length, t, num_threads); if (range.second - range.first == 1) continue; diff --git a/verification/mmap/verify_mmap.cpp b/verification/mmap/verify_mmap.cpp index d60faa16..5ad8271d 100644 --- a/verification/mmap/verify_mmap.cpp +++ b/verification/mmap/verify_mmap.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include inline std::chrono::high_resolution_clock::time_point elapsed_time_sec() { @@ -36,8 +37,7 @@ inline double elapsed_time_sec( void remove_file(const std::string &file_name) { std::cout << "Remove " << file_name << std::endl; - std::string rm_command("rm -rf " + file_name); - std::system(rm_command.c_str()); + std::filesystem::remove_all(file_name); std::cout << __FUNCTION__ << " done" << std::endl; } @@ -79,7 +79,7 @@ void *map_file_read_mode(const std::string &file_name, const std::size_t size) { std::cerr << "errno: " << errno << std::endl; std::abort(); } - std::cout << "Mapped to address " << (uint64_t)mapped_addr << std::endl; + std::cout << "Mapped to address " << reinterpret_cast(mapped_addr) << std::endl; std::cout << __FUNCTION__ << " done" << std::endl; @@ -120,7 +120,7 @@ void *map_file_write_mode(const std::string &file_name, std::cerr << "errno: " << errno << std::endl; std::abort(); } - std::cout << "Mapped to address " << (uint64_t)mapped_addr << std::endl; + std::cout << "Mapped to address " << reinterpret_cast(mapped_addr) << std::endl; std::cout << __FUNCTION__ << " done" << std::endl; @@ -128,7 +128,7 @@ void *map_file_write_mode(const std::string &file_name, } void unmap(void *const addr, const std::size_t size) { - std::cout << "Unmap file: address " << (uint64_t)addr << ", size " << size + std::cout << "Unmap file: address " << reinterpret_cast(addr) << ", size " << size << std::endl; if (::munmap(addr, size) != 0) { ::perror("munmap"); @@ -208,8 +208,8 @@ void write_data_with_multiple_threads(const std::string &file_name, static_cast(map_file_write_mode(file_name, file_size)); const std::size_t length = file_size / sizeof(uint64_t); - const auto num_threads = (int)std::min( - (std::size_t)length, (std::size_t)std::thread::hardware_concurrency()); + const auto num_threads = std::min( + length, std::thread::hardware_concurrency()); std::cout << "#of threads: " << num_threads << std::endl; std::cout << "Generate index" << std::endl; @@ -217,7 +217,7 @@ void write_data_with_multiple_threads(const std::string &file_name, { std::vector threads(num_threads, nullptr); const std::size_t num_indices = (length + num_threads - 1) / num_threads; - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { threads[t] = new std::thread( [&length, &num_indices, &index_list](const int thread_no) { index_list[thread_no] = gen_random_index(length - 1, num_indices); @@ -242,7 +242,7 @@ void write_data_with_multiple_threads(const std::string &file_name, std::vector threads(num_threads, nullptr); const auto start = elapsed_time_sec(); - for (int t = 0; t < num_threads; ++t) { + for (size_t t = 0; t < num_threads; ++t) { threads[t] = new std::thread( [&index_list, &mutex_list, buf](const int thread_no) { for (const auto idx : index_list[thread_no]) { @@ -264,7 +264,7 @@ void write_data_with_multiple_threads(const std::string &file_name, } // a.out file_name file_size -int main(int argc, char *argv[]) { +int main([[maybe_unused]] int argc, char *argv[]) { const std::string file_name(argv[1]); const std::size_t file_size = std::stoll(argv[2]); diff --git a/verification/object_size/CMakeLists.txt b/verification/object_size/CMakeLists.txt index c326c3cd..39529a11 100644 --- a/verification/object_size/CMakeLists.txt +++ b/verification/object_size/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(show_object_sizes show_object_sizes.cpp) \ No newline at end of file +add_copperr_executable(show_object_sizes show_object_sizes.cpp) \ No newline at end of file diff --git a/verification/object_size/show_object_sizes.cpp b/verification/object_size/show_object_sizes.cpp index bb369397..19a0d72e 100644 --- a/verification/object_size/show_object_sizes.cpp +++ b/verification/object_size/show_object_sizes.cpp @@ -4,12 +4,12 @@ // SPDX-License-Identifier: (Apache-2.0 OR MIT) #include -#include -#include +#include +#include static constexpr std::size_t k_max_segment_size = 1ULL << 48ULL; using object_size_manager = - metall::kernel::object_size_manager; int main() { @@ -22,7 +22,7 @@ int main() { std::cout << i << "\t" << size << "\tN/A" << std::endl; else std::cout << i << "\t" << size << "\t" - << (double)(size - pre_size - 1) / (pre_size + 1) << std::endl; + << static_cast(size - pre_size - 1) / static_cast(pre_size + 1) << std::endl; pre_size = size; } diff --git a/verification/soft_dirty/CMakeLists.txt b/verification/soft_dirty/CMakeLists.txt index c28aa4d7..7e78bea6 100644 --- a/verification/soft_dirty/CMakeLists.txt +++ b/verification/soft_dirty/CMakeLists.txt @@ -1 +1 @@ -add_metall_executable(verify_soft_dirty verify_soft_dirty.cpp) \ No newline at end of file +add_copperr_executable(verify_soft_dirty verify_soft_dirty.cpp) \ No newline at end of file diff --git a/verification/soft_dirty/verify_soft_dirty.cpp b/verification/soft_dirty/verify_soft_dirty.cpp index c6b129f3..be02b3e9 100644 --- a/verification/soft_dirty/verify_soft_dirty.cpp +++ b/verification/soft_dirty/verify_soft_dirty.cpp @@ -3,29 +3,29 @@ // // SPDX-License-Identifier: (Apache-2.0 OR MIT) -#include -#include -#include -#include +#include +#include +#include +#include bool run_in_core_test(const ssize_t page_size, const std::size_t num_pages, char *const map) { const uint64_t page_no_offset = reinterpret_cast(map) / page_size; for (uint64_t i = 0; i < 2; ++i) { - if (!metall::mtlldetail::reset_soft_dirty_bit()) { + if (!dice::copperr::mtlldetail::reset_soft_dirty_bit()) { std::cerr << "Failed to reset soft dirty bit" << std::endl; return false; } { - metall::mtlldetail::pagemap_reader pr; + dice::copperr::mtlldetail::pagemap_reader pr; for (uint64_t p = 0; p < num_pages; ++p) { const auto pagemap = pr.at(page_no_offset + p); - if (pagemap == metall::mtlldetail::pagemap_reader::error_value) { + if (pagemap == dice::copperr::mtlldetail::pagemap_reader::error_value) { std::cerr << "Failed to read pagemap at " << p << std::endl; return false; } - if (metall::mtlldetail::check_soft_dirty_page(pagemap)) { + if (dice::copperr::mtlldetail::check_soft_dirty_page(pagemap)) { std::cerr << "Page is dirty at " << p << std::endl; } } @@ -37,18 +37,18 @@ bool run_in_core_test(const ssize_t page_size, const std::size_t num_pages, map[page_size * p] = 0; } } - // metall::mtlldetail::os_msync(map, page_size * num_pages); + // dice::copperr::mtlldetail::os_msync(map, page_size * num_pages); { - metall::mtlldetail::pagemap_reader pr; + dice::copperr::mtlldetail::pagemap_reader pr; for (uint64_t p = 0; p < num_pages; ++p) { const auto pagemap = pr.at(page_no_offset + p); - if (pagemap == metall::mtlldetail::pagemap_reader::error_value) { + if (pagemap == dice::copperr::mtlldetail::pagemap_reader::error_value) { std::cerr << "Failed to read pagemap at " << p << std::endl; return false; } const bool desired_dirty_flag = (p % 2 == i % 2); - if (metall::mtlldetail::check_soft_dirty_page(pagemap) != + if (dice::copperr::mtlldetail::check_soft_dirty_page(pagemap) != desired_dirty_flag) { std::cerr << "Dirty flag must be " << desired_dirty_flag << " at " << p << std::endl; @@ -61,23 +61,23 @@ bool run_in_core_test(const ssize_t page_size, const std::size_t num_pages, } int main(int argc, char *argv[]) { - if (!metall::mtlldetail::file_exist("/proc/self/pagemap")) { + if (!dice::copperr::mtlldetail::file_exist("/proc/self/pagemap")) { std::cerr << "Pagemap file does not exist" << std::endl; std::abort(); } - const ssize_t page_size = metall::mtlldetail::get_page_size(); + const ssize_t page_size = dice::copperr::mtlldetail::get_page_size(); if (page_size <= 0) { std::abort(); } const std::size_t k_num_pages = 1024; { - auto map = static_cast(metall::mtlldetail::map_anonymous_write_mode( + auto map = static_cast(dice::copperr::mtlldetail::map_anonymous_write_mode( nullptr, page_size * k_num_pages)); if (map) { run_in_core_test(page_size, k_num_pages, map); - metall::mtlldetail::munmap(map, page_size * k_num_pages, false); + dice::copperr::mtlldetail::munmap(map, page_size * k_num_pages, false); } else { std::cerr << "Failed anonymous mapping" << std::endl; } @@ -92,34 +92,34 @@ int main(int argc, char *argv[]) { } { - metall::mtlldetail::remove_file(file_name); - metall::mtlldetail::create_file(file_name); - metall::mtlldetail::extend_file_size(file_name, page_size * k_num_pages); + dice::copperr::mtlldetail::remove_file(file_name); + dice::copperr::mtlldetail::create_file(file_name); + dice::copperr::mtlldetail::extend_file_size(file_name, page_size * k_num_pages); auto map = - static_cast(metall::mtlldetail::map_file_write_mode( + static_cast(dice::copperr::mtlldetail::map_file_write_mode( file_name, nullptr, page_size * k_num_pages, 0) .second); if (map) { run_in_core_test(page_size, k_num_pages, map); - metall::mtlldetail::munmap(map, page_size * k_num_pages, false); + dice::copperr::mtlldetail::munmap(map, page_size * k_num_pages, false); } else { std::cerr << "Failed file mapping" << std::endl; } } { - metall::mtlldetail::remove_file(file_name); - metall::mtlldetail::create_file(file_name); - metall::mtlldetail::extend_file_size(file_name, page_size * k_num_pages); + dice::copperr::mtlldetail::remove_file(file_name); + dice::copperr::mtlldetail::create_file(file_name); + dice::copperr::mtlldetail::extend_file_size(file_name, page_size * k_num_pages); auto map = - static_cast(metall::mtlldetail::map_file_write_private_mode( + static_cast(dice::copperr::mtlldetail::map_file_write_private_mode( file_name, nullptr, page_size * k_num_pages, 0) .second); if (map) { run_in_core_test(page_size, k_num_pages, map); - metall::mtlldetail::munmap(map, page_size * k_num_pages, false); + dice::copperr::mtlldetail::munmap(map, page_size * k_num_pages, false); } else { std::cerr << "Failed file mapping" << std::endl; }