diff --git a/.clang-format b/.clang-format index 3f817f7246..314723e0d9 100644 --- a/.clang-format +++ b/.clang-format @@ -10,7 +10,7 @@ CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false FixNamespaceComments: false Standard: Cpp11 -ColumnLimit: 80 +ColumnLimit: 100 AllowAllParametersOfDeclarationOnNextLine: true AlignEscapedNewlines: Right AlignAfterOpenBracket: Align diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..e59188800a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.cxx text +*.h text +*.hxx text +*.tcc text +*.cu text +*.c text +*.h text +*.py text +*.f90 text +*.F90 text +*.sh text + +*.cmake whitespace=tab-in-indent +*.md whitespace=tab-in-indent whitespace=-blank-at-eol conflict-marker-size=79 +*.rst whitespace=tab-in-indent conflict-marker-size=79 +*.txt whitespace=tab-in-indent +*.xml whitespace=tab-in-indent diff --git a/.github/ISSUE_TEMPLATE/new_release.md b/.github/ISSUE_TEMPLATE/new_release.md index 1406f04e30..a60870a8a8 100644 --- a/.github/ISSUE_TEMPLATE/new_release.md +++ b/.github/ISSUE_TEMPLATE/new_release.md @@ -44,10 +44,27 @@ git push git fetch origin git checkout -b release_@MAJOR@@MINOR@ origin/master # Use the following command with care -git push origin +git push origin release_@MAJOR@@MINOR@:release_@MAJOR@@MINOR@ ``` -- [ ] Create PR that merges release_@MAJOR@@MINOR@ into master +- [ ] Remove older patch releases for @MAJOR@.@MINOR@.X in ReadTheDocs. +- [ ] Create merge -sours commit in master: +``` +git fetch origin +git checkout master +git reset --hard origin/master +# We do not want the changes master from the release branch +git -s ours release_@MAJOR@@MINOR@ +# Be very careful here +git push origin master +``` + - [ ] Submit a PR in Spack that adds this new version of ADIOS (if not RC mark this new version as preferred) + - Run `spack checksum -a adios2` to add it, create commit; push it; Create + PR in Spack repo. +- [ ] Submit a PR in Conda that adds this new version of ADIOS (if not RC mark this new version as preferred) + - CondaForge robot should do this for you automatically, expect a new PR at + https://github.com/conda-forge/adios2-feedstock a couple of hours after the + release. - [ ] Write an announcement in the ADIOS-ECP mail-list (https://groups.google.com/a/kitware.com/g/adios-ecp) diff --git a/.github/workflows/everything.yml b/.github/workflows/everything.yml index 7447ed908a..a2eb4a60de 100644 --- a/.github/workflows/everything.yml +++ b/.github/workflows/everything.yml @@ -13,6 +13,17 @@ # may have made it to the target branch after the pull_request was started. ####################################### +####################################### +# Note regarding restore/save of cache for use by ccache: +# +# We only save cache on main branch runs. PR workflows only consume the +# cache to avoid exceeding the 10 GB limit, which can cause cache thrashing. +# Also, we only save the cache if there was *not* an exact match when cache +# was restored. This avoids attempting to write to an existing cache key, +# which results in failure to save the cache. While failure to save doesn't +# cause job failures, it seems a waste and is easily avoidable. +####################################### + name: GitHub Actions on: @@ -40,7 +51,7 @@ jobs: outputs: num_code_changes: ${{ steps.get_code_changes.outputs.num_code_changes }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Check for appropriately named topic branch @@ -66,13 +77,13 @@ jobs: runs-on: ubuntu-latest container: - image: ornladios/adios2:ci-formatting + image: ghcr.io/ornladios/adios2:ci-formatting steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: gha - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} path: source @@ -91,49 +102,74 @@ jobs: # Build and test jobs ####################################### - linux: + linux_ubuntu: needs: [format, git_checks] if: needs.git_checks.outputs.num_code_changes > 0 - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 container: - image: ornladios/adios2:ci-spack-el8-${{ matrix.compiler }}-${{ matrix.parallel }} + image: ghcr.io/ornladios/adios2:ci-spack-ubuntu20.04-${{ matrix.compiler }} options: --shm-size=1g env: - GH_YML_JOBNAME: ${{ matrix.os }}-${{ matrix.gpu_backend }}${{ matrix.compiler }}-${{ matrix.parallel }} + GH_YML_JOBNAME: ${{ matrix.os }}-${{ matrix.compiler }}${{ matrix.shared == 'static' && '-static' || ''}}-${{ matrix.parallel }} GH_YML_BASE_OS: Linux GH_YML_MATRIX_OS: ${{ matrix.os }} GH_YML_MATRIX_COMPILER: ${{ matrix.compiler }} GH_YML_MATRIX_PARALLEL: ${{ matrix.parallel }} + CCACHE_BASEDIR: "${GITHUB_WORKSPACE}" + CCACHE_DIR: "${GITHUB_WORKSPACE}/.ccache" + CCACHE_COMPRESS: true + CCACHE_COMPRESSLEVEL: 6 strategy: fail-fast: false matrix: - os: [el8] - compiler: [gcc8, gcc9, gcc10, gcc11, icc, oneapi, nvhpc222] - parallel: [serial, mpi] + os: [ubuntu20.04] + compiler: [gcc8, gcc9, gcc10, gcc11, clang6, clang10] + shared: [shared] + parallel: [ompi] include: - - os: el8 - compiler: cuda + - os: ubuntu20.04 + compiler: gcc10 + parallel: mpich + - os: ubuntu20.04 + compiler: gcc8 parallel: serial - constrains: build_only - - os: el8 - compiler: cuda + - os: ubuntu20.04 + compiler: clang6 parallel: serial - gpu_backend: kokkos + - os: ubuntu20.04 + compiler: gcc8 + shared: static + parallel: ompi constrains: build_only - - os: el8 - compiler: gcc10 - parallel: mpich - + - os: ubuntu20.04 + compiler: clang6 + shared: static + parallel: ompi + constrains: build_only + - os: ubuntu20.04 + compiler: gcc8 + shared: static + parallel: serial steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: gha - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} path: source + - name: Restore cache + uses: actions/cache/restore@v3 + id: restore-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} + restore-keys: | + ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }} + - name: Configure cache + run: ccache -z - name: Setup run: gha/scripts/ci/gh-actions/linux-setup.sh - name: Update @@ -142,10 +178,83 @@ jobs: run: gha/scripts/ci/gh-actions/run.sh configure - name: Build run: gha/scripts/ci/gh-actions/run.sh build + - name: Print ccache statistics + run: ccache -s + - name: Save cache + uses: actions/cache/save@v3 + if: ${{ github.ref_name == 'master' && steps.restore-cache.outputs.cache-hit != 'true' }} + id: save-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} - name: Test if: ${{ matrix.constrains != 'build_only' }} run: gha/scripts/ci/gh-actions/run.sh test + linux_el8: + needs: [format, git_checks] + if: needs.git_checks.outputs.num_code_changes > 0 + + runs-on: ubuntu-latest + container: + image: ghcr.io/ornladios/adios2:ci-el8-${{ matrix.compiler }} + options: --shm-size=1g + env: + GH_YML_JOBNAME: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }} + GH_YML_BASE_OS: Linux + GH_YML_MATRIX_OS: ${{ matrix.os }} + GH_YML_MATRIX_COMPILER: ${{ matrix.compiler }} + GH_YML_MATRIX_PARALLEL: ${{ matrix.parallel }} + CCACHE_BASEDIR: "${GITHUB_WORKSPACE}" + CCACHE_DIR: "${GITHUB_WORKSPACE}/.ccache" + CCACHE_COMPRESS: true + CCACHE_COMPRESSLEVEL: 6 + + strategy: + fail-fast: false + matrix: + os: [el8] + compiler: [icc, oneapi] + parallel: [ompi] + + steps: + - uses: actions/checkout@v4 + with: + path: gha + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: source + - name: Restore cache + uses: actions/cache/restore@v3 + id: restore-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} + restore-keys: | + ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }} + - name: Configure cache + run: ccache -z + - name: Setup + run: gha/scripts/ci/gh-actions/linux-setup.sh + - name: Update + run: gha/scripts/ci/gh-actions/run.sh update + - name: Configure + run: gha/scripts/ci/gh-actions/run.sh configure + - name: Build + run: gha/scripts/ci/gh-actions/run.sh build + - name: Print ccache statistics + run: ccache -s + - name: Save cache + uses: actions/cache/save@v3 + if: ${{ github.ref_name == 'master' && steps.restore-cache.outputs.cache-hit != 'true' }} + id: save-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} + - name: Test + run: gha/scripts/ci/gh-actions/run.sh test + macos: needs: [format, git_checks] if: needs.git_checks.outputs.num_code_changes > 0 @@ -157,6 +266,10 @@ jobs: GH_YML_MATRIX_OS: ${{ matrix.os }} GH_YML_MATRIX_COMPILER: ${{ matrix.compiler }} GH_YML_MATRIX_PARALLEL: ${{ matrix.parallel }} + CCACHE_BASEDIR: "${GITHUB_WORKSPACE}" + CCACHE_DIR: "${GITHUB_WORKSPACE}/.ccache" + CCACHE_COMPRESS: true + CCACHE_COMPRESSLEVEL: 6 strategy: fail-fast: false @@ -172,25 +285,43 @@ jobs: compiler: xcode13_4_1 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: gha - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} path: source - name: Setup run: gha/scripts/ci/gh-actions/macos-setup.sh + - name: Restore cache + uses: actions/cache/restore@v3 + id: restore-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} + restore-keys: | + ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }} + - name: Configure cache + run: ccache -z - name: Update run: gha/scripts/ci/gh-actions/run.sh update - name: Configure run: gha/scripts/ci/gh-actions/run.sh configure - name: Build run: gha/scripts/ci/gh-actions/run.sh build + - name: Print ccache statistics + run: ccache -s + - name: Save cache + uses: actions/cache/save@v3 + if: ${{ github.ref_name == 'master' && steps.restore-cache.outputs.cache-hit != 'true' }} + id: save-cache + with: + path: .ccache + key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.parallel }}-${{ github.sha }} - name: Test run: gha/scripts/ci/gh-actions/run.sh test - windows: needs: [format, git_checks] if: needs.git_checks.outputs.num_code_changes > 0 @@ -207,7 +338,7 @@ jobs: fail-fast: false matrix: os: [win2019, win2022] - parallel: [serial, mpi] + parallel: [serial, ompi] include: - os: win2019 image: windows-2019 @@ -221,10 +352,10 @@ jobs: shell: bash steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: path: gha - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} path: source @@ -255,7 +386,7 @@ jobs: baseos: [ubuntu-bionic] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} path: ci-source @@ -317,24 +448,19 @@ jobs: strategy: fail-fast: false matrix: - code: [examples, lammps, tau] + code: [lammps, tau] include: - - code: examples - repo: ornladios/ADIOS2-Examples - ref: master - code: lammps repo: pnorbert/lammps ref: fix-deprecated-adios-init - code: tau - repo: ornladios/ADIOS2-Examples - ref: master - defaults: run: shell: bash -c "docker exec adios2-ci bash --login -e $(echo {0} | sed 's|/home/runner/work|/__w|g')" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + if: ${{ matrix.repo != '' }} with: repository: ${{ matrix.repo }} ref: ${{ matrix.ref }} @@ -365,12 +491,68 @@ jobs: - name: Test run: /opt/adios2/source/testing/contract/${{ matrix.code }}/test.sh +####################################### +# Code analysis builds +####################################### + + analyze: + needs: [format, git_checks] + name: CodeQL + runs-on: ubuntu-latest + container: + image: 'ghcr.io/ornladios/adios2:ci-spack-ubuntu20.04-gcc8' + env: + GH_YML_JOBNAME: ubuntu20.04-gcc8-serial-codeql + GH_YML_BASE_OS: Linux + GH_YML_MATRIX_OS: ubuntu20.04 + GH_YML_MATRIX_COMPILER: gcc8 + GH_YML_MATRIX_PARALLEL: serial + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + + steps: + - uses: actions/checkout@v4 + with: + path: gha + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: source + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + config: | + paths: + - source + paths-ignore: + - source/thirdparty + - name: Setup + run: gha/scripts/ci/gh-actions/linux-setup.sh + - name: Update + run: gha/scripts/ci/gh-actions/run.sh update + - name: Configure + run: gha/scripts/ci/gh-actions/run.sh configure + - name: Build + run: gha/scripts/ci/gh-actions/run.sh build + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" + ####################################### # Workaround for skipping matrix jobs ####################################### build_and_test: - needs: [linux, macos, docker, contract] + needs: [linux_el8, linux_ubuntu, macos, docker, contract] runs-on: ubuntu-latest steps: - run: echo "All required jobs complete" diff --git a/.gitlab/config/SpackCIBridge.py b/.gitlab/config/SpackCIBridge.py index 72c189e480..07838725dd 100755 --- a/.gitlab/config/SpackCIBridge.py +++ b/.gitlab/config/SpackCIBridge.py @@ -169,7 +169,7 @@ def list_github_prs(self): # Check if we should defer pushing/testing this PR because it is based on "too new" of a commit # of the main branch. tmp_pr_branch = f"temporary_{pr_string}" - subprocess.run(["git", "fetch", "--unshallow", "github", + subprocess.run(["git", "fetch", "github", f"refs/pull/{pull.number}/head:{tmp_pr_branch}"], check=True) # Get the merge base between this PR and the main branch. try: @@ -226,7 +226,7 @@ def list_github_prs(self): # then we will push the merge commit that was automatically created by GitHub to GitLab # where it will kick off a CI pipeline. try: - subprocess.run(["git", "fetch", "--unshallow", "github", + subprocess.run(["git", "fetch", "github", f"{pull.merge_commit_sha}:{pr_string}"], check=True) except subprocess.CalledProcessError: print("Failed to locally checkout PR {0} ({1}). Skipping" @@ -306,7 +306,7 @@ def setup_git_repo(self): self.gitlab_shallow_fetch() if self.main_branch: - subprocess.run(["git", "fetch", "--unshallow", "github", self.main_branch], check=True) + subprocess.run(["git", "fetch", "github", self.main_branch], check=True) def get_gitlab_pr_branches(self): """Query GitLab for branches that have already been copied over from GitHub PRs. @@ -350,7 +350,7 @@ def update_refspecs_for_tags(self, tags, open_refspecs, fetch_refspecs): def fetch_github_branches(self, fetch_refspecs): """Perform `git fetch` for a given list of refspecs.""" print("Fetching GitHub refs for open PRs") - fetch_args = ["git", "fetch", "-q", "--unshallow", "github"] + fetch_refspecs + fetch_args = ["git", "fetch", "-q", "github"] + fetch_refspecs subprocess.run(fetch_args, check=True) def build_local_branches(self, protected_branches): diff --git a/.gitlab/config/generate_pipelines.py b/.gitlab/config/generate_pipelines.py index 17b8068b99..15a70cfde3 100755 --- a/.gitlab/config/generate_pipelines.py +++ b/.gitlab/config/generate_pipelines.py @@ -5,11 +5,11 @@ # # generate_pipeline.py # -# Created: May 19, 2023 # Author: Vicente Adolfo Bolea Sanchez from datetime import datetime import argparse +import itertools import requests import time import re @@ -18,18 +18,43 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -def is_date_after(date, days): - deadline_sec = int(time.time()) - (days * 86400) - utc_dt = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ') - timestamp_sec = (utc_dt - datetime(1970, 1, 1)).total_seconds() - return timestamp_sec > deadline_sec - - -def request_dict(url): +def request_as_dict(url): r = requests.get(url + '?per_page=100', verify=False) return r.json() +def add_timestamp(branch): + date_str = branch['commit']['committed_date'] + # We ignore the TZ since Gitlab/GitHub always reports in UTC + branch['dt'] = int( + datetime.strptime(date_str.split(".")[0], + '%Y-%m-%dT%H:%M:%S').timestamp()) + return branch + + +def is_recent(branch): + deadline_sec = int(time.time()) - (args.days * 86400) + return branch['dt'] > deadline_sec + + +def has_no_status(branch): + gh_commit_sha = branch['commit']['id'] + # Backported branches use the merge head + if re.fullmatch(r'^pr\d+_.*$', branch['name']): + gh_commit_sha = branch['commit']['parent_ids'][1] + + # Query GitHub for the status of this commit + commit = request_as_dict(gh_url + '/commits/' + gh_commit_sha + '/status') + if commit is None or 'sha' not in commit: + return False + + for status in commit['statuses']: + if status['context'] == args.gh_context: + return False + + return True + + parser = argparse.ArgumentParser( prog='generate_pipeline.py', description='Generate Dynamic pipelines for Gitlab') @@ -39,12 +64,12 @@ def request_dict(url): parser.add_argument( '-n', '--gh-name', required=True, help='Full name of the GitHub project. Ex: ornladios/ADIOS2') -parser.add_argument( - '-c', '--gh-context', default='OLCF Crusher (Frontier)', - help='Name of the status in GitHub (A.K.A context)') parser.add_argument( '-p', '--project_id', required=True, help='Gitlab internal project ID of the project.') +parser.add_argument( + '-c', '--gh-context', default='OLCF Crusher (Frontier)', + help='Name of the status in GitHub (A.K.A context)') parser.add_argument( '-d', '--days', type=int, default=1, help='How many days back to search for commits') @@ -57,34 +82,21 @@ def request_dict(url): args = parser.parse_args() -with open(args.template_file, "r") as fd: +gl_url = args.gl_url + '/api/v4/projects/' + str(args.project_id) +gh_url = 'https://api.github.com/repos/' + args.gh_name + +with open(args.template_file, 'r') as fd: template_str = fd.read() - gl_url = args.gl_url + "/api/v4/projects/" + str(args.project_id) - gh_url = 'https://api.github.com/repos/' + args.gh_name - branches = request_dict(gl_url + "/repository/branches") - num_pipeline = 0 + + branches = request_as_dict(gl_url + '/repository/branches') + branches = map(add_timestamp, branches) + branches = filter(is_recent, branches) + branches = filter(has_no_status, branches) + + # Select the arg.max most least recent branches + branches = sorted(branches, key=lambda x: x['dt']) + branches = itertools.islice(branches, args.max) + for branch in branches: - # Convert to ISO 8601 date format. - date_stamp = branch['commit']['committed_date'].split('.')[0] + "Z" - if num_pipeline < args.max and is_date_after(date_stamp, args.days): - commit_sha = branch['commit']['id'] - # Backported branches use the merge head - gh_commit_sha = commit_sha - if re.fullmatch(r'^pr\d+_.*$', branch['name']): - gh_commit_sha = branch['commit']['parent_ids'][1] - - # Quit if GitHub does not have the commit - if 'sha' not in request_dict(gh_url + "/commits/" + gh_commit_sha): - continue - - # Query GitHub for the status of this commit - commit = request_dict(gh_url + "/commits/" + - gh_commit_sha + "/status") - status_found = False - for status in commit['statuses']: - if status['context'] == args.gh_context: - status_found = True - if not status_found: - num_pipeline += 1 - print(template_str.format( - branch=branch['name'], commit=commit_sha)) + print(template_str.format( + branch=branch['name'], commit=branch['commit']['id'])) diff --git a/.shellcheck_exclude_paths b/.shellcheck_exclude_paths index 81763742e8..1ef95d56a2 100644 --- a/.shellcheck_exclude_paths +++ b/.shellcheck_exclude_paths @@ -1,42 +1,12 @@ -scripts/ci/azure/linux-setup.sh -scripts/ci/azure/macos-setup.sh -scripts/ci/azure/run.sh scripts/ci/circle/postCDashStatus.sh scripts/ci/circle/run.sh scripts/ci/gh-actions/check-branch-name.sh scripts/ci/gh-actions/get-changed-files.sh -scripts/ci/gh-actions/linux-setup.sh scripts/ci/gh-actions/macos-setup.sh scripts/ci/gh-actions/run.sh -scripts/ci/images-v2/build-base.sh -scripts/ci/images-v2/build-clang-base.sh -scripts/ci/images-v2/build-clang.sh -scripts/ci/images-v2/build-cuda.sh -scripts/ci/images-v2/build-functions.sh -scripts/ci/images-v2/build-gcc-base.sh -scripts/ci/images-v2/build-gcc.sh -scripts/ci/images-v2/build-intel-base.sh -scripts/ci/images-v2/build-intel.sh -scripts/ci/images-v2/build-mpich.sh -scripts/ci/images-v2/build-nvhpc.sh -scripts/ci/images-v2/build.sh -scripts/ci/images/build-native-images.sh -scripts/ci/images/emu-el7/entrypoint.sh -scripts/ci/images/emu-el7/qemu-binfmt-conf.sh -scripts/ci/images/emu-el7/register.sh scripts/ci/scripts/github-prs-to-gitlab.sh scripts/ci/scripts/run-clang-format.sh scripts/ci/scripts/run-flake8.sh -scripts/ci/setup-run/ci-el8-gcc10.sh -scripts/ci/setup-run/ci-el8-gcc11.sh -scripts/ci/setup-run/ci-el8-gcc9.sh -scripts/ci/setup-run/ci-el8-icc.sh -scripts/ci/setup-run/ci-el8-nvhpc222-mpi.sh -scripts/ci/setup-run/ci-el8-nvhpc222.sh -scripts/ci/setup-run/ci-el8-oneapi.sh -scripts/dashboard/nightly/aaargh.sh -scripts/dashboard/nightly/cori.sh -scripts/dashboard/nightly/summitdev.sh scripts/developer/git/setup-aliases scripts/developer/git/setup-hooks scripts/developer/git/setup-remotes @@ -45,6 +15,3 @@ scripts/developer/setup.sh scripts/docker/setup-user.sh scripts/runconf/runconf.sh scripts/runconf/runconf_olcf.sh -scripts/travis/run-docker.sh -scripts/travis/run-format.sh -scripts/travis/run.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 93d76a790a..ebb992c1f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,11 @@ if((NOT BUILD_SHARED_LIBS) AND (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() +# Ctest creates BUILD_TESTING option and sets it to true by default +# Here we disable BUILD_TESTING option by default +option(BUILD_TESTING "Build testing" OFF) include(CTest) +mark_as_advanced(CLEAR BUILD_TESTING) adios_option(Blosc2 "Enable support for c-blosc-2 transforms" AUTO) adios_option(BZip2 "Enable support for BZip2 transforms" AUTO) @@ -154,9 +158,9 @@ adios_option(DataMan "Enable support for DataMan" AUTO) adios_option(DataSpaces "Enable support for DATASPACES" AUTO) adios_option(MHS "Enable support for MHS" AUTO) adios_option(SST "Enable support for SST" AUTO) -adios_option(BP5 "Enable support for BP5" AUTO) adios_option(ZeroMQ "Enable support for ZeroMQ" AUTO) adios_option(HDF5 "Enable support for the HDF5 engine" AUTO) +adios_option(HDF5_VOL "Enable support for HDF5 ADIOS2 VOL" AUTO) adios_option(IME "Enable support for DDN IME transport" AUTO) adios_option(Python "Enable support for Python bindings" AUTO) adios_option(Fortran "Enable support for Fortran bindings" AUTO) @@ -166,7 +170,7 @@ adios_option(Profiling "Enable support for profiling" AUTO) adios_option(Endian_Reverse "Enable support for Little/Big Endian Interoperability" AUTO) adios_option(Sodium "Enable support for Sodium for encryption" AUTO) adios_option(Catalyst "Enable support for in situ visualization plugin using ParaView Catalyst" AUTO) -adios_option(AWSSDK "Enable support for S3 compatible storage using AWS SDK's S3 module" AUTO) +adios_option(AWSSDK "Enable support for S3 compatible storage using AWS SDK's S3 module" OFF) include(${PROJECT_SOURCE_DIR}/cmake/DetectOptions.cmake) if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) @@ -176,7 +180,7 @@ if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) if(DEFINED Kokkos_CUDA_ARCHITECTURES) set(CMAKE_CUDA_ARCHITECTURES ${Kokkos_CUDA_ARCHITECTURES}) else() - # Mininum common non-deprecated architecture + # Minimum common non-deprecated architecture set(CMAKE_CUDA_ARCHITECTURES 52) endif() endif() @@ -196,6 +200,8 @@ if(ADIOS2_HAVE_MPI) add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) endif() +cmake_dependent_option(ADIOS2_Blosc2_PREFER_SHARED "Prefer shared Blosc2 libraries" + ON "Blosc2_shlib_available" OFF) #------------------------------------------------------------------------------# # POSIX O_DIRECT is only working for Unix in adios for now @@ -235,9 +241,10 @@ endif() set(ADIOS2_CONFIG_OPTS - BP5 DataMan DataSpaces HDF5 HDF5_VOL MHS SST Fortran MPI Python Blosc2 - BZip2 LIBPRESSIO MGARD PNG SZ ZFP DAOS IME O_DIRECT Sodium Catalyst SysVShMem UCX ZeroMQ - Profiling Endian_Reverse AWSSDK GPU_Support CUDA Kokkos Kokkos_CUDA Kokkos_HIP Kokkos_SYCL + DataMan DataSpaces HDF5 HDF5_VOL MHS SST Fortran MPI Python Blosc2 BZip2 + LIBPRESSIO MGARD PNG SZ ZFP DAOS IME O_DIRECT Sodium Catalyst SysVShMem UCX + ZeroMQ Profiling Endian_Reverse AWSSDK GPU_Support CUDA Kokkos Kokkos_CUDA + Kokkos_HIP Kokkos_SYCL ) GenerateADIOSHeaderConfig(${ADIOS2_CONFIG_OPTS}) @@ -284,12 +291,15 @@ if(BUILD_SHARED_LIBS AND ADIOS2_RUN_INSTALL_TEST) endif() endif() +if(MSVC AND BUILD_SHARED_LIBS AND ADIOS2_HAVE_HDF5) + # See note about building with visual studio and shared libs, here: + # https://github.com/HDFGroup/hdf5/blob/develop/release_docs/USING_HDF5_VS.txt + add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB=1) +endif() #------------------------------------------------------------------------------# # Third party libraries #------------------------------------------------------------------------------# -include(CTest) -mark_as_advanced(BUILD_TESTING) add_subdirectory(thirdparty) #------------------------------------------------------------------------------# @@ -310,8 +320,7 @@ add_subdirectory(plugins) #------------------------------------------------------------------------------# # Examples #------------------------------------------------------------------------------# -option(ADIOS2_BUILD_EXAMPLES "Build examples" ON) -option(ADIOS2_BUILD_EXAMPLES_EXPERIMENTAL "Build experimental examples" OFF) +option(ADIOS2_BUILD_EXAMPLES "Build examples" OFF) if(ADIOS2_BUILD_EXAMPLES) add_subdirectory(examples) endif() diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in index e118eb3e31..8356e4f57f 100644 --- a/CTestCustom.cmake.in +++ b/CTestCustom.cmake.in @@ -24,6 +24,7 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION "Warning #20208-D: '.*' is treated as '.*' in device code" "Warning: '.*' is treated as '.*' in device code" ".*was specified as both a system and non-system include directory.*" + "Wunused-command-line-argument" ) list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE ".*/thirdparty/.*" diff --git a/ReadMe.md b/ReadMe.md index f89f815133..3998d14f9b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -6,8 +6,6 @@ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/adios2)](https://anaconda.org/conda-forge/adios2) [![Circle CI](https://circleci.com/gh/ornladios/ADIOS2.svg?style=shield)](https://circleci.com/gh/ornladios/ADIOS2) -[![Travis CI](https://api.travis-ci.com/ornladios/ADIOS2.svg)](https://travis-ci.com/ornladios/ADIOS2) -[![AppVeyor CI](https://ci.appveyor.com/api/projects/status/0s2a3qp57hgbvlhj?svg=true)](https://ci.appveyor.com/project/ornladios/adios2) [![Coverity Scan Build Status](https://scan.coverity.com/projects/11116/badge.svg)](https://scan.coverity.com/projects/ornladios-adios2) @@ -76,6 +74,13 @@ Once ADIOS2 is installed refer to: * Previous releases: [https://github.com/ornladios/ADIOS2/releases](https://github.com/ornladios/ADIOS2/releases) +## Community + +ADIOS2 is an open source project: Questions, discussion, and contributions are welcome. Join us at: + +- Mailing list: adios-ecp@kitware.com +- Github Discussions: https://github.com/ornladios/ADIOS2/discussions + ## Reporting Bugs If you find a bug, please open an [issue on ADIOS2 github repository](https://github.com/ornladios/ADIOS2/issues) @@ -88,8 +93,8 @@ See the [Contributor's Guide to ADIOS 2](Contributing.md) for instructions on ho ADIOS2 is licensed under the Apache License v2.0. See the accompanying [Copyright.txt](Copyright.txt) for more details. - ## Directory layout + * bindings - public application programming interface, API, language bindings (C++11, C, Fortran, Python and Matlab) * cmake - Project specific CMake modules diff --git a/bindings/C/adios2/c/adios2_c_adios.cpp b/bindings/C/adios2/c/adios2_c_adios.cpp index cf376e8770..bfcfe238a4 100644 --- a/bindings/C/adios2/c/adios2_c_adios.cpp +++ b/bindings/C/adios2/c/adios2_c_adios.cpp @@ -41,17 +41,15 @@ adios2::ArrayOrdering adios2_ToArrayOrdering(const adios2_arrayordering Corder) return order; } -adios2_adios *adios2_init_config_glue_serial(const char *config_file, - const char *host_language) +adios2_adios *adios2_init_config_glue_serial(const char *config_file, const char *host_language) { adios2_adios *adios = nullptr; try { adios2::helper::CheckForNullptr( - config_file, - "for config_file, in call to adios2_init or adios2_init_config"); - adios = reinterpret_cast( - new adios2::core::ADIOS(config_file, host_language)); + config_file, "for config_file, in call to adios2_init or adios2_init_config"); + adios = + reinterpret_cast(new adios2::core::ADIOS(config_file, host_language)); } catch (...) { @@ -60,10 +58,7 @@ adios2_adios *adios2_init_config_glue_serial(const char *config_file, return adios; } -adios2_adios *adios2_init_serial() -{ - return adios2_init_config_glue_serial("", "C"); -} +adios2_adios *adios2_init_serial() { return adios2_init_config_glue_serial("", "C"); } adios2_adios *adios2_init_config_serial(const char *config_file) { @@ -75,8 +70,7 @@ adios2_io *adios2_declare_io(adios2_adios *adios, const char *name) adios2_io *io = nullptr; try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_declare_io"); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_declare_io"); io = reinterpret_cast( &reinterpret_cast(adios)->DeclareIO(name)); } @@ -93,8 +87,7 @@ adios2_io *adios2_declare_io_order(adios2_adios *adios, const char *name, adios2_io *io = nullptr; try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_declare_io"); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_declare_io"); io = reinterpret_cast( &reinterpret_cast(adios)->DeclareIO( name, adios2_ToArrayOrdering(order))); @@ -111,8 +104,7 @@ adios2_io *adios2_at_io(adios2_adios *adios, const char *name) adios2_io *io = nullptr; try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_at_io"); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_at_io"); io = reinterpret_cast( &reinterpret_cast(adios)->AtIO(name)); } @@ -123,17 +115,15 @@ adios2_io *adios2_at_io(adios2_adios *adios, const char *name) return io; } -adios2_operator *adios2_define_operator(adios2_adios *adios, const char *name, - const char *type) +adios2_operator *adios2_define_operator(adios2_adios *adios, const char *name, const char *type) { adios2_operator *op = nullptr; try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_define_operator"); + adios2::helper::CheckForNullptr(adios, + "for adios2_adios, in call to adios2_define_operator"); op = reinterpret_cast( - &reinterpret_cast(adios)->DefineOperator( - name, type)); + &reinterpret_cast(adios)->DefineOperator(name, type)); } catch (...) { @@ -147,11 +137,10 @@ adios2_operator *adios2_inquire_operator(adios2_adios *adios, const char *name) adios2_operator *op = nullptr; try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_inquire_operator"); + adios2::helper::CheckForNullptr(adios, + "for adios2_adios, in call to adios2_inquire_operator"); op = reinterpret_cast( - reinterpret_cast(adios)->InquireOperator( - name)); + reinterpret_cast(adios)->InquireOperator(name)); } catch (...) { @@ -164,34 +153,28 @@ adios2_error adios2_flush_all(adios2_adios *adios) { try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_flush_all"); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_flush_all"); reinterpret_cast(adios)->FlushAll(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_flush_all")); + return static_cast(adios2::helper::ExceptionToError("adios2_flush_all")); } } -adios2_error adios2_remove_io(adios2_bool *result, adios2_adios *adios, - const char *name) +adios2_error adios2_remove_io(adios2_bool *result, adios2_adios *adios, const char *name) { try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_remove_io"); - const bool resultCpp = - reinterpret_cast(adios)->RemoveIO(name); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_remove_io"); + const bool resultCpp = reinterpret_cast(adios)->RemoveIO(name); *result = resultCpp ? adios2_true : adios2_false; return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_remove_io")); + return static_cast(adios2::helper::ExceptionToError("adios2_remove_io")); } } @@ -199,15 +182,14 @@ adios2_error adios2_remove_all_ios(adios2_adios *adios) { try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_remove_all_ios"); + adios2::helper::CheckForNullptr(adios, + "for adios2_adios, in call to adios2_remove_all_ios"); reinterpret_cast(adios)->RemoveAllIOs(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_remove_all_ios")); + return static_cast(adios2::helper::ExceptionToError("adios2_remove_all_ios")); } } @@ -215,15 +197,13 @@ adios2_error adios2_finalize(adios2_adios *adios) { try { - adios2::helper::CheckForNullptr( - adios, "for adios2_adios, in call to adios2_finalize"); + adios2::helper::CheckForNullptr(adios, "for adios2_adios, in call to adios2_finalize"); delete reinterpret_cast(adios); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_finalize")); + return static_cast(adios2::helper::ExceptionToError("adios2_finalize")); } } @@ -234,8 +214,7 @@ adios2_error adios2_enter_computation_block(adios2_adios *adios) try { adios2::helper::CheckForNullptr( - adios, - "for adios2_adios, in call to adios2_enter_computation_block"); + adios, "for adios2_adios, in call to adios2_enter_computation_block"); reinterpret_cast(adios)->EnterComputationBlock(); return adios2_error_none; } @@ -253,8 +232,7 @@ adios2_error adios2_exit_computation_block(adios2_adios *adios) try { adios2::helper::CheckForNullptr( - adios, - "for adios2_adios, in call to adios2_exit_computation_block"); + adios, "for adios2_adios, in call to adios2_exit_computation_block"); reinterpret_cast(adios)->ExitComputationBlock(); return adios2_error_none; } diff --git a/bindings/C/adios2/c/adios2_c_adios.h b/bindings/C/adios2/c/adios2_c_adios.h index 02fc4671f5..b5044b0447 100644 --- a/bindings/C/adios2/c/adios2_c_adios.h +++ b/bindings/C/adios2/c/adios2_c_adios.h @@ -23,8 +23,7 @@ extern "C" { #if ADIOS2_USE_MPI #define adios2_init(comm) adios2_init_mpi(comm) -#define adios2_init_config(config_file, comm) \ - adios2_init_config_mpi(config_file, comm) +#define adios2_init_config(config_file, comm) adios2_init_config_mpi(config_file, comm) /** * Starting point for MPI apps. Creates an ADIOS handler. @@ -97,8 +96,7 @@ adios2_io *adios2_at_io(adios2_adios *adios, const char *name); * @param type supported ADIOS2 operator type: zfp, sz * @return success: handler, failure: NULL */ -adios2_operator *adios2_define_operator(adios2_adios *adios, const char *name, - const char *type); +adios2_operator *adios2_define_operator(adios2_adios *adios, const char *name, const char *type); /** * Retrieves a previously defined operator handler @@ -136,8 +134,7 @@ adios2_error adios2_finalize(adios2_adios *adios); * @param name input unique identifier for io to be removed * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_remove_io(adios2_bool *result, adios2_adios *adios, - const char *name); +adios2_error adios2_remove_io(adios2_bool *result, adios2_adios *adios, const char *name); /** * DANGER ZONE: removes all ios created with adios2_declare_io. diff --git a/bindings/C/adios2/c/adios2_c_adios_mpi.cpp b/bindings/C/adios2/c/adios2_c_adios_mpi.cpp index 7ae76381ce..ba3aa0889d 100644 --- a/bindings/C/adios2/c/adios2_c_adios_mpi.cpp +++ b/bindings/C/adios2/c/adios2_c_adios_mpi.cpp @@ -15,8 +15,7 @@ extern "C" { // to be called from other languages, hidden from the public apis -adios2_adios *adios2_init_config_glue_mpi(const char *config_file, - MPI_Comm comm, +adios2_adios *adios2_init_config_glue_mpi(const char *config_file, MPI_Comm comm, const char *host_language) { adios2_adios *adios = nullptr; @@ -24,10 +23,9 @@ adios2_adios *adios2_init_config_glue_mpi(const char *config_file, try { adios2::helper::CheckForNullptr( - config_file, - "for config_file, in call to adios2_init or adios2_init_config"); - adios = reinterpret_cast(new adios2::core::ADIOS( - config_file, adios2::helper::CommDupMPI(comm), host_language)); + config_file, "for config_file, in call to adios2_init or adios2_init_config"); + adios = reinterpret_cast( + new adios2::core::ADIOS(config_file, adios2::helper::CommDupMPI(comm), host_language)); } catch (...) { @@ -36,10 +34,7 @@ adios2_adios *adios2_init_config_glue_mpi(const char *config_file, return adios; } -adios2_adios *adios2_init_mpi(MPI_Comm comm) -{ - return adios2_init_config_glue_mpi("", comm, "C"); -} +adios2_adios *adios2_init_mpi(MPI_Comm comm) { return adios2_init_config_glue_mpi("", comm, "C"); } adios2_adios *adios2_init_config_mpi(const char *config_file, MPI_Comm comm) { diff --git a/bindings/C/adios2/c/adios2_c_attribute.cpp b/bindings/C/adios2/c/adios2_c_attribute.cpp index 98da6c6da1..c08b6629b9 100644 --- a/bindings/C/adios2/c/adios2_c_attribute.cpp +++ b/bindings/C/adios2/c/adios2_c_attribute.cpp @@ -18,13 +18,12 @@ extern "C" { #endif -adios2_error adios2_attribute_name(char *name, size_t *size, - const adios2_attribute *attribute) +adios2_error adios2_attribute_name(char *name, size_t *size, const adios2_attribute *attribute) { try { - adios2::helper::CheckForNullptr( - attribute, "for attribute, in call to adios2_attribute_name"); + adios2::helper::CheckForNullptr(attribute, + "for attribute, in call to adios2_attribute_name"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -33,18 +32,15 @@ adios2_error adios2_attribute_name(char *name, size_t *size, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_attribute_name")); + return static_cast(adios2::helper::ExceptionToError("adios2_attribute_name")); } } -adios2_error adios2_attribute_type(adios2_type *type, - const adios2_attribute *attribute) +adios2_error adios2_attribute_type(adios2_type *type, const adios2_attribute *attribute) { try { - adios2::helper::CheckForNullptr(attribute, - "in call to adios2_attribute_type"); + adios2::helper::CheckForNullptr(attribute, "in call to adios2_attribute_type"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -53,20 +49,22 @@ adios2_error adios2_attribute_type(adios2_type *type, { *type = adios2_type_string; } -#define make_case(T) \ - else if (type_s == adios2::helper::GetDataType::Type>()) \ - { \ - *type = T; \ +#define make_case(T) \ + else if (type_s == adios2::helper::GetDataType::Type>()) \ + { \ + *type = T; \ } ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(make_case) #undef make_case - else { *type = adios2_type_unknown; } + else + { + *type = adios2_type_unknown; + } return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_attribute_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_attribute_type")); } } @@ -75,12 +73,10 @@ adios2_error adios2_attribute_type_string(char *type, size_t *size, { try { + adios2::helper::CheckForNullptr(attribute, "for const adios2_attribute, in call to " + "adios2_attribute_type_string"); adios2::helper::CheckForNullptr( - attribute, "for const adios2_attribute, in call to " - "adios2_attribute_type_string"); - adios2::helper::CheckForNullptr( - size, - "for size_t* length, in call to adios2_attribute_type_string"); + size, "for size_t* length, in call to adios2_attribute_type_string"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -93,13 +89,11 @@ adios2_error adios2_attribute_type_string(char *type, size_t *size, } } -adios2_error adios2_attribute_is_value(adios2_bool *result, - const adios2_attribute *attribute) +adios2_error adios2_attribute_is_value(adios2_bool *result, const adios2_attribute *attribute) { try { - adios2::helper::CheckForNullptr(attribute, - "in call to adios2_attribute_is_value"); + adios2::helper::CheckForNullptr(attribute, "in call to adios2_attribute_is_value"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -113,13 +107,11 @@ adios2_error adios2_attribute_is_value(adios2_bool *result, } } -adios2_error adios2_attribute_size(size_t *size, - const adios2_attribute *attribute) +adios2_error adios2_attribute_size(size_t *size, const adios2_attribute *attribute) { try { - adios2::helper::CheckForNullptr(attribute, - "in call to adios2_attribute_size"); + adios2::helper::CheckForNullptr(attribute, "in call to adios2_attribute_size"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -128,20 +120,16 @@ adios2_error adios2_attribute_size(size_t *size, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_attribute_size")); + return static_cast(adios2::helper::ExceptionToError("adios2_attribute_size")); } } -adios2_error adios2_attribute_data(void *data, size_t *size, - const adios2_attribute *attribute) +adios2_error adios2_attribute_data(void *data, size_t *size, const adios2_attribute *attribute) { try { - adios2::helper::CheckForNullptr(attribute, - "in call to adios2_attribute_data"); - adios2::helper::CheckForNullptr( - data, "for data, in call to adios2_attribute_data"); + adios2::helper::CheckForNullptr(attribute, "in call to adios2_attribute_data"); + adios2::helper::CheckForNullptr(data, "for data, in call to adios2_attribute_data"); const adios2::core::AttributeBase *attributeBase = reinterpret_cast(attribute); @@ -155,13 +143,11 @@ adios2_error adios2_attribute_data(void *data, size_t *size, else if (type == adios2::helper::GetDataType()) { const adios2::core::Attribute *attributeCpp = - dynamic_cast *>( - attributeBase); + dynamic_cast *>(attributeBase); if (attributeCpp->m_IsSingleValue) { char *dataT = reinterpret_cast(data); - attributeCpp->m_DataSingleValue.copy( - dataT, attributeCpp->m_DataSingleValue.size()); + attributeCpp->m_DataSingleValue.copy(dataT, attributeCpp->m_DataSingleValue.size()); dataT[attributeCpp->m_DataSingleValue.size()] = '\0'; *size = 1; } @@ -172,40 +158,37 @@ adios2_error adios2_attribute_data(void *data, size_t *size, for (size_t e = 0; e < *size; ++e) { - attributeCpp->m_DataArray[e].copy( - dataT[e], attributeCpp->m_DataArray[e].size()); + attributeCpp->m_DataArray[e].copy(dataT[e], + attributeCpp->m_DataArray[e].size()); dataT[e][attributeCpp->m_DataArray[e].size()] = '\0'; } } } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Attribute *attributeCpp = \ - dynamic_cast *>(attributeBase); \ - T *dataT = reinterpret_cast(data); \ - if (attributeCpp->m_IsSingleValue) \ - { \ - *dataT = attributeCpp->m_DataSingleValue; \ - *size = 1; \ - } \ - else \ - { \ - std::copy(attributeCpp->m_DataArray.begin(), \ - attributeCpp->m_DataArray.end(), dataT); \ - *size = attributeCpp->m_Elements; \ - } \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Attribute *attributeCpp = \ + dynamic_cast *>(attributeBase); \ + T *dataT = reinterpret_cast(data); \ + if (attributeCpp->m_IsSingleValue) \ + { \ + *dataT = attributeCpp->m_DataSingleValue; \ + *size = 1; \ + } \ + else \ + { \ + std::copy(attributeCpp->m_DataArray.begin(), attributeCpp->m_DataArray.end(), dataT); \ + *size = attributeCpp->m_Elements; \ + } \ } - ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG( - declare_template_instantiation) + ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_attribute_data")); + return static_cast(adios2::helper::ExceptionToError("adios2_attribute_data")); } } diff --git a/bindings/C/adios2/c/adios2_c_attribute.h b/bindings/C/adios2/c/adios2_c_attribute.h index 2209383f48..58435c3488 100644 --- a/bindings/C/adios2/c/adios2_c_attribute.h +++ b/bindings/C/adios2/c/adios2_c_attribute.h @@ -28,8 +28,7 @@ extern "C" { * @param attribute handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_attribute_name(char *name, size_t *size, - const adios2_attribute *attribute); +adios2_error adios2_attribute_name(char *name, size_t *size, const adios2_attribute *attribute); /** * Retrieve attribute type @@ -37,8 +36,7 @@ adios2_error adios2_attribute_name(char *name, size_t *size, * @param attribute handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_attribute_type(adios2_type *type, - const adios2_attribute *attribute); +adios2_error adios2_attribute_type(adios2_type *type, const adios2_attribute *attribute); /** * Retrieve attribute type in string form "char", "unsigned long", etc. @@ -60,8 +58,7 @@ adios2_error adios2_attribute_type_string(char *type, size_t *size, * @param attribute handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_attribute_is_value(adios2_bool *result, - const adios2_attribute *attribute); +adios2_error adios2_attribute_is_value(adios2_bool *result, const adios2_attribute *attribute); /** * Returns the number of elements (as in C++ STL size() function) if attribute @@ -70,8 +67,7 @@ adios2_error adios2_attribute_is_value(adios2_bool *result, * @param attribute handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_attribute_size(size_t *size, - const adios2_attribute *attribute); +adios2_error adios2_attribute_size(size_t *size, const adios2_attribute *attribute); /** * Retrieve attribute data pointer (read-only) @@ -80,8 +76,7 @@ adios2_error adios2_attribute_size(size_t *size, * @param attribute handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_attribute_data(void *data, size_t *size, - const adios2_attribute *attribute); +adios2_error adios2_attribute_data(void *data, size_t *size, const adios2_attribute *attribute); #ifdef __cplusplus } // end extern C diff --git a/bindings/C/adios2/c/adios2_c_engine.cpp b/bindings/C/adios2/c/adios2_c_engine.cpp index c933c96a41..1707552972 100644 --- a/bindings/C/adios2/c/adios2_c_engine.cpp +++ b/bindings/C/adios2/c/adios2_c_engine.cpp @@ -41,8 +41,7 @@ adios2::Mode adios2_ToMode(const adios2_mode mode, const std::string &hint) modeCpp = adios2::Mode::Sync; break; default: - throw std::invalid_argument("ERROR: invalid adios2_mode, " + hint + - "\n"); + throw std::invalid_argument("ERROR: invalid adios2_mode, " + hint + "\n"); } return modeCpp; } @@ -71,14 +70,12 @@ adios2_mode adios2_fromMode(const adios2::Mode mode, const std::string &hint) modeC = adios2_mode_sync; break; default: - throw std::invalid_argument("ERROR: invalid adios2::Mode, " + hint + - "\n"); + throw std::invalid_argument("ERROR: invalid adios2::Mode, " + hint + "\n"); } return modeC; } -adios2::StepMode ToStepMode(const adios2_step_mode mode, - const std::string &hint) +adios2::StepMode ToStepMode(const adios2_step_mode mode, const std::string &hint) { adios2::StepMode stepModeCpp = adios2::StepMode::Read; switch (mode) @@ -94,14 +91,12 @@ adios2::StepMode ToStepMode(const adios2_step_mode mode, break; default: - throw std::invalid_argument("ERROR: invalid adios2_step_mode, " + hint + - "\n"); + throw std::invalid_argument("ERROR: invalid adios2_step_mode, " + hint + "\n"); } return stepModeCpp; } -adios2_step_status ToStepStatus(const adios2::StepStatus statusCpp, - const std::string &hint) +adios2_step_status ToStepStatus(const adios2::StepStatus statusCpp, const std::string &hint) { adios2_step_status status = adios2_step_status_other_error; @@ -121,51 +116,45 @@ adios2_step_status ToStepStatus(const adios2::StepStatus statusCpp, break; default: - throw std::invalid_argument("ERROR: invalid adios2_step_status, " + - hint + "\n"); + throw std::invalid_argument("ERROR: invalid adios2_step_status, " + hint + "\n"); } return status; } } // end anonymous namespace -adios2_error adios2_engine_name(char *name, size_t *size, - const adios2_engine *engine) +adios2_error adios2_engine_name(char *name, size_t *size, const adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for const adios2_engine, in call to adios2_engine_name"); + adios2::helper::CheckForNullptr(engine, + "for const adios2_engine, in call to adios2_engine_name"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr( - size, "for size_t* size, in call to adios2_engine_name"); + adios2::helper::CheckForNullptr(size, "for size_t* size, in call to adios2_engine_name"); return String2CAPI(engineCpp->m_Name, name, size); } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_engine_name")); + return static_cast(adios2::helper::ExceptionToError("adios2_engine_name")); } } -adios2_error adios2_engine_get_type(char *type, size_t *size, - const adios2_engine *engine) +adios2_error adios2_engine_get_type(char *type, size_t *size, const adios2_engine *engine) { try { adios2::helper::CheckForNullptr( - engine, - "for const adios2_engine, in call to adios2_engine_get_type"); + engine, "for const adios2_engine, in call to adios2_engine_get_type"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr( - size, "for size_t* size, in call to adios2_engine_get_type"); + adios2::helper::CheckForNullptr(size, + "for size_t* size, in call to adios2_engine_get_type"); return String2CAPI(engineCpp->m_EngineType, type, size); } @@ -176,14 +165,12 @@ adios2_error adios2_engine_get_type(char *type, size_t *size, } } -adios2_error adios2_engine_openmode(adios2_mode *mode, - const adios2_engine *engine) +adios2_error adios2_engine_openmode(adios2_mode *mode, const adios2_engine *engine) { try { adios2::helper::CheckForNullptr( - engine, - "for const adios2_engine, in call to adios2_engine_openmode"); + engine, "for const adios2_engine, in call to adios2_engine_openmode"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); @@ -199,21 +186,17 @@ adios2_error adios2_engine_openmode(adios2_mode *mode, } } -adios2_error adios2_begin_step(adios2_engine *engine, - const adios2_step_mode mode, - const float timeout_seconds, - adios2_step_status *status) +adios2_error adios2_begin_step(adios2_engine *engine, const adios2_step_mode mode, + const float timeout_seconds, adios2_step_status *status) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_begin_step"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_begin_step"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); - const adios2::StepStatus statusCpp = engineCpp->BeginStep( - ToStepMode(mode, "in call to adios2_begin_step"), timeout_seconds); + const adios2::StepStatus statusCpp = + engineCpp->BeginStep(ToStepMode(mode, "in call to adios2_begin_step"), timeout_seconds); *status = ToStepStatus(statusCpp, "in call to adios2_begin_step"); return adios2_error_none; @@ -221,18 +204,16 @@ adios2_error adios2_begin_step(adios2_engine *engine, catch (...) { *status = adios2_step_status_other_error; - return static_cast( - adios2::helper::ExceptionToError("adios2_begin_step")); + return static_cast(adios2::helper::ExceptionToError("adios2_begin_step")); } } -adios2_error adios2_between_step_pairs(size_t *between_step_pairs, - const adios2_engine *engine) +adios2_error adios2_between_step_pairs(size_t *between_step_pairs, const adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_between_step_pairs"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_between_step_pairs"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); @@ -247,13 +228,12 @@ adios2_error adios2_between_step_pairs(size_t *between_step_pairs, } } -adios2_error adios2_current_step(size_t *current_step, - const adios2_engine *engine) +adios2_error adios2_current_step(size_t *current_step, const adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_current_step"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_current_step"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); @@ -263,8 +243,7 @@ adios2_error adios2_current_step(size_t *current_step, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_current_step")); + return static_cast(adios2::helper::ExceptionToError("adios2_current_step")); } } @@ -272,8 +251,7 @@ adios2_error adios2_steps(size_t *steps, const adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_steps"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_steps"); const adios2::core::Engine *engineCpp = reinterpret_cast(engine); @@ -283,32 +261,28 @@ adios2_error adios2_steps(size_t *steps, const adios2_engine *engine) } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_steps")); + return static_cast(adios2::helper::ExceptionToError("adios2_steps")); } } -adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, - const void *data, const adios2_mode mode) +adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, const void *data, + const adios2_mode mode) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_put"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_put"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr( - variable, "for adios2_variable, in call to adios2_put"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to adios2_put"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); const adios2::DataType type(variableBase->m_Type); - const adios2::Mode modeCpp = adios2_ToMode( - mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " - "in call to adios2_put"); + const adios2::Mode modeCpp = + adios2_ToMode(mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " + "in call to adios2_put"); if (type == adios2::DataType::Struct) { @@ -317,16 +291,14 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, else if (type == adios2::helper::GetDataType()) { const std::string dataStr(reinterpret_cast(data)); - engineCpp->Put(*dynamic_cast *>( - variableBase), + engineCpp->Put(*dynamic_cast *>(variableBase), dataStr, modeCpp); } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - engineCpp->Put( \ - *dynamic_cast *>(variableBase), \ - reinterpret_cast(data), modeCpp); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + engineCpp->Put(*dynamic_cast *>(variableBase), \ + reinterpret_cast(data), modeCpp); \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -335,33 +307,27 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_put")); + return static_cast(adios2::helper::ExceptionToError("adios2_put")); } } -adios2_error adios2_put_by_name(adios2_engine *engine, - const char *variable_name, const void *data, +adios2_error adios2_put_by_name(adios2_engine *engine, const char *variable_name, const void *data, const adios2_mode mode) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_put_by_name"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_put_by_name"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); adios2::helper::CheckForNullptr( - variable_name, - "for const char* variable_name, in call to adios2_put_by_name"); + variable_name, "for const char* variable_name, in call to adios2_put_by_name"); - const adios2::Mode modeCpp = adios2_ToMode( - mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " - "in call to adios2_put_by_name"); + const adios2::Mode modeCpp = + adios2_ToMode(mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " + "in call to adios2_put_by_name"); - const adios2::DataType type( - engineCpp->m_IO.InquireVariableType(variable_name)); + const adios2::DataType type(engineCpp->m_IO.InquireVariableType(variable_name)); if (type == adios2::DataType::Struct) { @@ -372,11 +338,10 @@ adios2_error adios2_put_by_name(adios2_engine *engine, const std::string dataStr(reinterpret_cast(data)); engineCpp->Put(variable_name, dataStr, modeCpp); } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - engineCpp->Put(variable_name, reinterpret_cast(data), \ - modeCpp); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + engineCpp->Put(variable_name, reinterpret_cast(data), modeCpp); \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -384,8 +349,7 @@ adios2_error adios2_put_by_name(adios2_engine *engine, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_put_by_name")); + return static_cast(adios2::helper::ExceptionToError("adios2_put_by_name")); } } @@ -393,19 +357,17 @@ adios2_error adios2_perform_puts(adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_perform_puts"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_perform_puts"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->PerformPuts(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_perform_puts")); + return static_cast(adios2::helper::ExceptionToError("adios2_perform_puts")); } } @@ -413,11 +375,10 @@ adios2_error adios2_perform_data_write(adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_perform_data_write"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_perform_data_write"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->PerformDataWrite(); return adios2_error_none; @@ -429,20 +390,17 @@ adios2_error adios2_perform_data_write(adios2_engine *engine) } } -adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, - void *values, const adios2_mode mode) +adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, void *values, + const adios2_mode mode) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_get"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_get"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call " - "to adios2_get"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call " + "to adios2_get"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -456,20 +414,18 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, else if (type == adios2::helper::GetDataType()) { std::string dataStr; - engineCpp->Get(*dynamic_cast *>( - variableBase), + engineCpp->Get(*dynamic_cast *>(variableBase), dataStr); dataStr.copy(reinterpret_cast(values), dataStr.size()); } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - const adios2::Mode modeCpp = adios2_ToMode( \ - mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " \ - "in call to adios2_get"); \ - engineCpp->Get( \ - *dynamic_cast *>(variableBase), \ - reinterpret_cast(values), modeCpp); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + const adios2::Mode modeCpp = \ + adios2_ToMode(mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " \ + "in call to adios2_get"); \ + engineCpp->Get(*dynamic_cast *>(variableBase), \ + reinterpret_cast(values), modeCpp); \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -477,32 +433,26 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_get")); + return static_cast(adios2::helper::ExceptionToError("adios2_get")); } } -adios2_error adios2_get_by_name(adios2_engine *engine, - const char *variable_name, void *data, +adios2_error adios2_get_by_name(adios2_engine *engine, const char *variable_name, void *data, const adios2_mode mode) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_get_by_name"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_get_by_name"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr( - variable_name, "for const char* variable_name, in call to " - "adios2_get_by_name"); + adios2::helper::CheckForNullptr(variable_name, "for const char* variable_name, in call to " + "adios2_get_by_name"); - const adios2::Mode modeCpp = adios2_ToMode( - mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " - "in call to adios2_get_by_name"); - const adios2::DataType type( - engineCpp->m_IO.InquireVariableType(variable_name)); + const adios2::Mode modeCpp = + adios2_ToMode(mode, "only adios2_mode_deferred or adios2_mode_sync are valid, " + "in call to adios2_get_by_name"); + const adios2::DataType type(engineCpp->m_IO.InquireVariableType(variable_name)); if (type == adios2::DataType::Struct) { @@ -514,10 +464,10 @@ adios2_error adios2_get_by_name(adios2_engine *engine, engineCpp->Get(variable_name, dataStr); dataStr.copy(reinterpret_cast(data), dataStr.size()); } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - engineCpp->Get(variable_name, reinterpret_cast(data), modeCpp); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + engineCpp->Get(variable_name, reinterpret_cast(data), modeCpp); \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -525,8 +475,7 @@ adios2_error adios2_get_by_name(adios2_engine *engine, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_get_by_name")); + return static_cast(adios2::helper::ExceptionToError("adios2_get_by_name")); } } @@ -534,19 +483,17 @@ adios2_error adios2_perform_gets(adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_perform_gets"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_perform_gets"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->PerformGets(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_perform_gets")); + return static_cast(adios2::helper::ExceptionToError("adios2_perform_gets")); } } @@ -554,37 +501,29 @@ adios2_error adios2_end_step(adios2_engine *engine) { try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_end_step"); + adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to adios2_end_step"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->EndStep(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_end_step")); + return static_cast(adios2::helper::ExceptionToError("adios2_end_step")); } } -adios2_error adios2_flush(adios2_engine *engine) -{ - return adios2_flush_by_index(engine, -1); -} +adios2_error adios2_flush(adios2_engine *engine) { return adios2_flush_by_index(engine, -1); } -adios2_error adios2_flush_by_index(adios2_engine *engine, - const int transport_index) +adios2_error adios2_flush_by_index(adios2_engine *engine, const int transport_index) { try { adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to " "adios2_flush or " "adios2_flush_by_index"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->Flush(transport_index); @@ -592,31 +531,25 @@ adios2_error adios2_flush_by_index(adios2_engine *engine, } catch (...) { - return static_cast(adios2::helper::ExceptionToError( - "adios2_flush or adios2_flush_by_index")); + return static_cast( + adios2::helper::ExceptionToError("adios2_flush or adios2_flush_by_index")); } } -adios2_error adios2_close(adios2_engine *engine) -{ - return adios2_close_by_index(engine, -1); -} +adios2_error adios2_close(adios2_engine *engine) { return adios2_close_by_index(engine, -1); } adios2_error adios2_lock_writer_definitions(adios2_engine *engine) { try { adios2::helper::CheckForNullptr( - engine, - "for adios2_engine, in call to adios2_lock_writer_definitions"); - reinterpret_cast(engine) - ->LockWriterDefinitions(); + engine, "for adios2_engine, in call to adios2_lock_writer_definitions"); + reinterpret_cast(engine)->LockWriterDefinitions(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_engine_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_engine_type")); } } @@ -625,21 +558,17 @@ adios2_error adios2_lock_reader_selections(adios2_engine *engine) try { adios2::helper::CheckForNullptr( - engine, - "for adios2_engine, in call to adios2_lock_reader_selections"); - reinterpret_cast(engine) - ->LockReaderSelections(); + engine, "for adios2_engine, in call to adios2_lock_reader_selections"); + reinterpret_cast(engine)->LockReaderSelections(); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_engine_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_engine_type")); } } -adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, - adios2_variable *variable, +adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, adios2_variable *variable, const size_t step) { auto lf_CopyDims = [](const std::vector &dims) -> size_t * { @@ -657,31 +586,28 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, try { - adios2::helper::CheckForNullptr( - engine, "for adios2_engine, in call to adios2_inquire_blockinfo"); + adios2::helper::CheckForNullptr(engine, + "for adios2_engine, in call to adios2_inquire_blockinfo"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call " - "to adios2_get"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call " + "to adios2_get"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); const adios2::DataType type(variableBase->m_Type); - const auto minBlocksInfo = - engineCpp->MinBlocksInfo(*variableBase, step); + const auto minBlocksInfo = engineCpp->MinBlocksInfo(*variableBase, step); if (minBlocksInfo) { varinfo = (adios2_varinfo *)malloc(sizeof(adios2_varinfo)); varinfo->nblocks = minBlocksInfo->BlocksInfo.size(); varinfo->Shape = NULL; - varinfo->BlocksInfo = (adios2_blockinfo *)malloc( - varinfo->nblocks * sizeof(adios2_blockinfo)); + varinfo->BlocksInfo = + (adios2_blockinfo *)malloc(varinfo->nblocks * sizeof(adios2_blockinfo)); auto *b = varinfo->BlocksInfo; varinfo->Dims = minBlocksInfo->Dims; @@ -694,8 +620,7 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, { if (minBlocksInfo->Shape) { - varinfo->Shape = - (size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims); + varinfo->Shape = (size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims); memcpy(varinfo->Shape, minBlocksInfo->Shape, sizeof(size_t) * minBlocksInfo->Dims); } @@ -709,42 +634,35 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, if (minBlocksInfo->WasLocalValue) { b[i].Start = (size_t *)malloc(sizeof(size_t)); - b[i].Start[0] = - (intptr_t)minBlocksInfo->BlocksInfo[i].Start; + b[i].Start[0] = (intptr_t)minBlocksInfo->BlocksInfo[i].Start; b[i].Count = (size_t *)malloc(sizeof(size_t)); - b[i].Count[0] = - (intptr_t)minBlocksInfo->BlocksInfo[i].Count; + b[i].Count[0] = (intptr_t)minBlocksInfo->BlocksInfo[i].Count; } else { b[i].Start = b[i].Count = NULL; if (minBlocksInfo->BlocksInfo[i].Start) { - b[i].Start = (size_t *)malloc(sizeof(size_t) * - minBlocksInfo->Dims); + b[i].Start = (size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims); memcpy(b[i].Start, minBlocksInfo->BlocksInfo[i].Start, sizeof(size_t) * minBlocksInfo->Dims); } if (minBlocksInfo->BlocksInfo[i].Count) { - b[i].Count = (size_t *)malloc(sizeof(size_t) * - minBlocksInfo->Dims); + b[i].Count = (size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims); memcpy(b[i].Count, minBlocksInfo->BlocksInfo[i].Count, sizeof(size_t) * minBlocksInfo->Dims); } } if (minBlocksInfo->IsValue) { - memcpy(&b[i].Value, minBlocksInfo->BlocksInfo[i].BufferP, - sizeof(b[i].Value)); + memcpy(&b[i].Value, minBlocksInfo->BlocksInfo[i].BufferP, sizeof(b[i].Value)); } else { - memcpy(&b[i].MinUnion, - &minBlocksInfo->BlocksInfo[i].MinMax.MinUnion, + memcpy(&b[i].MinUnion, &minBlocksInfo->BlocksInfo[i].MinMax.MinUnion, sizeof(b[i].MinUnion)); - memcpy(&b[i].MaxUnion, - &minBlocksInfo->BlocksInfo[i].MinMax.MaxUnion, + memcpy(&b[i].MaxUnion, &minBlocksInfo->BlocksInfo[i].MinMax.MaxUnion, sizeof(b[i].MaxUnion)); } } @@ -760,13 +678,11 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, else if (type == adios2::helper::GetDataType()) { const auto blocksInfo = engineCpp->BlocksInfo( - *dynamic_cast *>( - variableBase), - step); + *dynamic_cast *>(variableBase), step); varinfo = (adios2_varinfo *)malloc(sizeof(adios2_varinfo)); varinfo->nblocks = blocksInfo.size(); - varinfo->BlocksInfo = (adios2_blockinfo *)malloc( - varinfo->nblocks * sizeof(adios2_blockinfo)); + varinfo->BlocksInfo = + (adios2_blockinfo *)malloc(varinfo->nblocks * sizeof(adios2_blockinfo)); auto *b = varinfo->BlocksInfo; varinfo->Dims = static_cast(blocksInfo[0].Shape.size()); @@ -787,31 +703,31 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, std::strcpy(b[i].Value.str, blocksInfo[i].Value.data()); }; } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - const auto blocksInfo = engineCpp->BlocksInfo( \ - *dynamic_cast *>(variableBase), step); \ - varinfo = (adios2_varinfo *)malloc(sizeof(adios2_varinfo)); \ - varinfo->nblocks = blocksInfo.size(); \ - varinfo->BlocksInfo = (adios2_blockinfo *)malloc( \ - varinfo->nblocks * sizeof(adios2_blockinfo)); \ - auto *b = varinfo->BlocksInfo; \ - \ - varinfo->Dims = static_cast(blocksInfo[0].Shape.size()); \ - varinfo->Shape = lf_CopyDims(blocksInfo[0].Shape); \ - varinfo->IsValue = (int)blocksInfo[0].IsValue; \ - varinfo->IsReverseDims = (int)blocksInfo[0].IsReverseDims; \ - for (size_t i = 0; i < varinfo->nblocks; ++i) \ - { \ - b[i].WriterID = blocksInfo[i].WriterID; \ - b[i].BlockID = blocksInfo[i].BlockID; \ - b[i].Start = lf_CopyDims(blocksInfo[i].Start); \ - b[i].Count = lf_CopyDims(blocksInfo[i].Count); \ - b[i].MinUnion.uint64 = 0; \ - b[i].MaxUnion.uint64 = 0; \ - b[i].Value.uint64 = 0; \ - }; \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + const auto blocksInfo = engineCpp->BlocksInfo( \ + *dynamic_cast *>(variableBase), step); \ + varinfo = (adios2_varinfo *)malloc(sizeof(adios2_varinfo)); \ + varinfo->nblocks = blocksInfo.size(); \ + varinfo->BlocksInfo = \ + (adios2_blockinfo *)malloc(varinfo->nblocks * sizeof(adios2_blockinfo)); \ + auto *b = varinfo->BlocksInfo; \ + \ + varinfo->Dims = static_cast(blocksInfo[0].Shape.size()); \ + varinfo->Shape = lf_CopyDims(blocksInfo[0].Shape); \ + varinfo->IsValue = (int)blocksInfo[0].IsValue; \ + varinfo->IsReverseDims = (int)blocksInfo[0].IsReverseDims; \ + for (size_t i = 0; i < varinfo->nblocks; ++i) \ + { \ + b[i].WriterID = blocksInfo[i].WriterID; \ + b[i].BlockID = blocksInfo[i].BlockID; \ + b[i].Start = lf_CopyDims(blocksInfo[i].Start); \ + b[i].Count = lf_CopyDims(blocksInfo[i].Count); \ + b[i].MinUnion.uint64 = 0; \ + b[i].MaxUnion.uint64 = 0; \ + b[i].Value.uint64 = 0; \ + }; \ } ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -838,16 +754,14 @@ void adios2_free_blockinfo(adios2_varinfo *data_blocks) } } -adios2_error adios2_close_by_index(adios2_engine *engine, - const int transport_index) +adios2_error adios2_close_by_index(adios2_engine *engine, const int transport_index) { try { adios2::helper::CheckForNullptr(engine, "for adios2_engine, in call to " "adios2_close or " "adios2_close_by_index"); - adios2::core::Engine *engineCpp = - reinterpret_cast(engine); + adios2::core::Engine *engineCpp = reinterpret_cast(engine); engineCpp->Close(transport_index); @@ -860,7 +774,7 @@ adios2_error adios2_close_by_index(adios2_engine *engine, } catch (...) { - return static_cast(adios2::helper::ExceptionToError( - "adios2_close or adios2_close_by_index")); + return static_cast( + adios2::helper::ExceptionToError("adios2_close or adios2_close_by_index")); } } diff --git a/bindings/C/adios2/c/adios2_c_engine.h b/bindings/C/adios2/c/adios2_c_engine.h index 984591dc7f..b5e0422651 100644 --- a/bindings/C/adios2/c/adios2_c_engine.h +++ b/bindings/C/adios2/c/adios2_c_engine.h @@ -29,8 +29,7 @@ extern "C" { * @param engine handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_engine_name(char *name, size_t *size, - const adios2_engine *engine); +adios2_error adios2_engine_name(char *name, size_t *size, const adios2_engine *engine); /** * Return engine type string and length without '\0\ character @@ -44,8 +43,7 @@ adios2_error adios2_engine_name(char *name, size_t *size, * @param engine handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_engine_get_type(char *type, size_t *size, - const adios2_engine *engine); +adios2_error adios2_engine_get_type(char *type, size_t *size, const adios2_engine *engine); /** * @brief Return the engine's Open mode @@ -53,8 +51,7 @@ adios2_error adios2_engine_get_type(char *type, size_t *size, * @param engine handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_engine_openmode(adios2_mode *mode, - const adios2_engine *engine); +adios2_error adios2_engine_openmode(adios2_mode *mode, const adios2_engine *engine); /** * @brief Begin a logical adios2 step stream @@ -67,18 +64,15 @@ adios2_error adios2_engine_openmode(adios2_mode *mode, * @param status output from enum adios2_step_status in adios2_c_types.h * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_begin_step(adios2_engine *engine, - const adios2_step_mode mode, - const float timeout_seconds, - adios2_step_status *status); +adios2_error adios2_begin_step(adios2_engine *engine, const adios2_step_mode mode, + const float timeout_seconds, adios2_step_status *status); /** * Inspect current logical step * @param current_step output * @param engine input handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_current_step(size_t *current_step, - const adios2_engine *engine); +adios2_error adios2_current_step(size_t *current_step, const adios2_engine *engine); /** * Inspect current between step status @@ -86,8 +80,7 @@ adios2_error adios2_current_step(size_t *current_step, * @param engine input handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_between_step_pairs(size_t *between_step_pairs, - const adios2_engine *engine); +adios2_error adios2_between_step_pairs(size_t *between_step_pairs, const adios2_engine *engine); /** * Inspect total number of available steps, use for file engines in read mode @@ -116,8 +109,8 @@ adios2_error adios2_steps(size_t *steps, const adios2_engine *engine); * * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, - const void *data, const adios2_mode launch); +adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, const void *data, + const adios2_mode launch); /** * Put data associated with a Variable in an engine, used for engines with @@ -137,8 +130,7 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable, * * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_put_by_name(adios2_engine *engine, - const char *variable_name, const void *data, +adios2_error adios2_put_by_name(adios2_engine *engine, const char *variable_name, const void *data, const adios2_mode launch); /** @@ -180,8 +172,8 @@ adios2_error adios2_perform_data_write(adios2_engine *engine); * * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, - void *data, const adios2_mode launch); +adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, void *data, + const adios2_mode launch); /** * Gets data associated with a Variable from an engine, used for engines with @@ -204,8 +196,7 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable, * * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_get_by_name(adios2_engine *engine, - const char *variable_name, void *data, +adios2_error adios2_get_by_name(adios2_engine *engine, const char *variable_name, void *data, const adios2_mode launch); /** @@ -239,8 +230,7 @@ adios2_error adios2_flush(adios2_engine *engine); * @param transport_index index to be flushed * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_flush_by_index(adios2_engine *engine, - const int transport_index); +adios2_error adios2_flush_by_index(adios2_engine *engine, const int transport_index); /** * Close all transports in adios2_Engine. Call is required to close system @@ -259,8 +249,7 @@ adios2_error adios2_close(adios2_engine *engine); * @param transport_index handler from adios2_add_transport * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_close_by_index(adios2_engine *engine, - const int transport_index); +adios2_error adios2_close_by_index(adios2_engine *engine, const int transport_index); /** * Promise that no more definitions or changes to defined variables will @@ -287,8 +276,7 @@ adios2_error adios2_lock_reader_selections(adios2_engine *engine); * @return Newly allocated adios2_varinfo structure, NULL pointer if step does * not exist. The memory must be freed by the adios2_free_blockinfo function */ -adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, - adios2_variable *variable, +adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine, adios2_variable *variable, const size_t step); /** * free adios2_varinfo structure diff --git a/bindings/C/adios2/c/adios2_c_internal.h b/bindings/C/adios2/c/adios2_c_internal.h index 82f07fc232..0c30924462 100644 --- a/bindings/C/adios2/c/adios2_c_internal.h +++ b/bindings/C/adios2/c/adios2_c_internal.h @@ -33,35 +33,35 @@ adios2_error String2CAPI(const std::string &s, char *buf, size_t *size); #include "adios2_c_internal.inl" -#define ADIOS2_FOREACH_C_TYPE_1ARG(MACRO) \ - MACRO(adios2_type_int8_t) \ - MACRO(adios2_type_int16_t) \ - MACRO(adios2_type_int32_t) \ - MACRO(adios2_type_int64_t) \ - MACRO(adios2_type_uint8_t) \ - MACRO(adios2_type_uint16_t) \ - MACRO(adios2_type_uint32_t) \ - MACRO(adios2_type_uint64_t) \ - MACRO(adios2_type_float) \ - MACRO(adios2_type_double) \ - MACRO(adios2_type_long_double) \ - MACRO(adios2_type_float_complex) \ +#define ADIOS2_FOREACH_C_TYPE_1ARG(MACRO) \ + MACRO(adios2_type_int8_t) \ + MACRO(adios2_type_int16_t) \ + MACRO(adios2_type_int32_t) \ + MACRO(adios2_type_int64_t) \ + MACRO(adios2_type_uint8_t) \ + MACRO(adios2_type_uint16_t) \ + MACRO(adios2_type_uint32_t) \ + MACRO(adios2_type_uint64_t) \ + MACRO(adios2_type_float) \ + MACRO(adios2_type_double) \ + MACRO(adios2_type_long_double) \ + MACRO(adios2_type_float_complex) \ MACRO(adios2_type_double_complex) // calls MACRO for all adios2_type attribute types except for adios2_type_string -#define ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(MACRO) \ - MACRO(adios2_type_int8_t) \ - MACRO(adios2_type_int16_t) \ - MACRO(adios2_type_int32_t) \ - MACRO(adios2_type_int64_t) \ - MACRO(adios2_type_uint8_t) \ - MACRO(adios2_type_uint16_t) \ - MACRO(adios2_type_uint32_t) \ - MACRO(adios2_type_uint64_t) \ - MACRO(adios2_type_float) \ - MACRO(adios2_type_double) \ - MACRO(adios2_type_long_double) \ - MACRO(adios2_type_float_complex) \ +#define ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(MACRO) \ + MACRO(adios2_type_int8_t) \ + MACRO(adios2_type_int16_t) \ + MACRO(adios2_type_int32_t) \ + MACRO(adios2_type_int64_t) \ + MACRO(adios2_type_uint8_t) \ + MACRO(adios2_type_uint16_t) \ + MACRO(adios2_type_uint32_t) \ + MACRO(adios2_type_uint64_t) \ + MACRO(adios2_type_float) \ + MACRO(adios2_type_double) \ + MACRO(adios2_type_long_double) \ + MACRO(adios2_type_float_complex) \ MACRO(adios2_type_double_complex) #endif /* ADIOS2_BINDINGS_C_C_ADIOS2_C_INTERNAL_H_ */ diff --git a/bindings/C/adios2/c/adios2_c_io.cpp b/bindings/C/adios2/c/adios2_c_io.cpp index 839f6a3a86..a4b8921224 100644 --- a/bindings/C/adios2/c/adios2_c_io.cpp +++ b/bindings/C/adios2/c/adios2_c_io.cpp @@ -25,17 +25,14 @@ adios2_error adios2_in_config_file(adios2_bool *result, const adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_in_config_file"); - *result = reinterpret_cast(io)->InConfigFile() - ? adios2_true - : adios2_false; + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_in_config_file"); + *result = reinterpret_cast(io)->InConfigFile() ? adios2_true + : adios2_false; return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_in_config_file")); + return static_cast(adios2::helper::ExceptionToError("adios2_in_config_file")); } } @@ -43,15 +40,13 @@ adios2_error adios2_set_engine(adios2_io *io, const char *engine_type) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_set_engine"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_set_engine"); reinterpret_cast(io)->SetEngine(engine_type); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_engine")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_engine")); } } @@ -59,48 +54,39 @@ adios2_error adios2_set_parameters(adios2_io *io, const char *parameters) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_set_parameters"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_set_parameters"); reinterpret_cast(io)->SetParameters(parameters); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_parameters")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_parameters")); } } -adios2_error adios2_set_parameter(adios2_io *io, const char *key, - const char *value) +adios2_error adios2_set_parameter(adios2_io *io, const char *key, const char *value) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_set_parameter"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_set_parameter"); reinterpret_cast(io)->SetParameter(key, value); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_parameter")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_parameter")); } } -adios2_error adios2_get_parameter(char *value, size_t *size, - const adios2_io *io, const char *key) +adios2_error adios2_get_parameter(char *value, size_t *size, const adios2_io *io, const char *key) { try { - adios2::helper::CheckForNullptr( - io, "for const adios2_io, in call to adios2_get_parameter"); + adios2::helper::CheckForNullptr(io, "for const adios2_io, in call to adios2_get_parameter"); - const adios2::core::IO *ioCpp = - reinterpret_cast(io); + const adios2::core::IO *ioCpp = reinterpret_cast(io); - adios2::helper::CheckForNullptr( - size, "for size_t* size, in call to adios2_get_parameter"); + adios2::helper::CheckForNullptr(size, "for size_t* size, in call to adios2_get_parameter"); auto itParameter = ioCpp->m_Parameters.find(key); if (itParameter == ioCpp->m_Parameters.end()) @@ -113,8 +99,7 @@ adios2_error adios2_get_parameter(char *value, size_t *size, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_get_parameter")); + return static_cast(adios2::helper::ExceptionToError("adios2_get_parameter")); } } @@ -122,8 +107,7 @@ adios2_error adios2_clear_parameters(adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_clear_parameters"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_clear_parameters"); reinterpret_cast(io)->ClearParameters(); return adios2_error_none; } @@ -134,34 +118,29 @@ adios2_error adios2_clear_parameters(adios2_io *io) } } -adios2_error adios2_add_transport(size_t *transport_index, adios2_io *io, - const char *type) +adios2_error adios2_add_transport(size_t *transport_index, adios2_io *io, const char *type) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_add_transport"); - *transport_index = - reinterpret_cast(io)->AddTransport(type); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_add_transport"); + *transport_index = reinterpret_cast(io)->AddTransport(type); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_add_transport")); + return static_cast(adios2::helper::ExceptionToError("adios2_add_transport")); } } -adios2_error adios2_set_transport_parameter(adios2_io *io, - const size_t transport_index, +adios2_error adios2_set_transport_parameter(adios2_io *io, const size_t transport_index, const char *key, const char *value) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_set_transport_parameter"); - reinterpret_cast(io)->SetTransportParameter( - transport_index, key, value); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_set_transport_parameter"); + reinterpret_cast(io)->SetTransportParameter(transport_index, key, + value); return adios2_error_none; } catch (...) @@ -171,26 +150,22 @@ adios2_error adios2_set_transport_parameter(adios2_io *io, } } -adios2_variable * -adios2_define_variable(adios2_io *io, const char *name, const adios2_type type, - const size_t ndims, const size_t *shape, - const size_t *start, const size_t *count, - const adios2_constant_dims constant_dims) +adios2_variable *adios2_define_variable(adios2_io *io, const char *name, const adios2_type type, + const size_t ndims, const size_t *shape, + const size_t *start, const size_t *count, + const adios2_constant_dims constant_dims) { adios2_variable *variable = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_define_variable"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_define_variable"); adios2::core::VariableBase *variableCpp = nullptr; adios2::core::IO &ioCpp = *reinterpret_cast(io); - const bool constantSizeBool = - (constant_dims == adios2_constant_dims_true) ? true : false; + const bool constantSizeBool = (constant_dims == adios2_constant_dims_true) ? true : false; - auto lf_ConvertDims = [](const size_t ndims, - const size_t *in) -> adios2::Dims { + auto lf_ConvertDims = [](const size_t ndims, const size_t *in) -> adios2::Dims { if (in != nullptr) { return adios2::Dims(in, in + ndims); @@ -205,23 +180,20 @@ adios2_define_variable(adios2_io *io, const char *name, const adios2_type type, switch (type) { - case (adios2_type_string): - { - variableCpp = &ioCpp.DefineVariable( - name, shapeV, startV, countV, constantSizeBool); + case (adios2_type_string): { + variableCpp = + &ioCpp.DefineVariable(name, shapeV, startV, countV, constantSizeBool); break; } -#define make_case(adios2_type) \ - case (adios2_type): \ - { \ - variableCpp = &ioCpp.DefineVariable::Type>( \ - name, shapeV, startV, countV, constantSizeBool); \ - break; \ +#define make_case(adios2_type) \ + case (adios2_type): { \ + variableCpp = &ioCpp.DefineVariable::Type>( \ + name, shapeV, startV, countV, constantSizeBool); \ + break; \ } ADIOS2_FOREACH_C_TYPE_1ARG(make_case) #undef make_case - default: - { + default: { throw std::invalid_argument("ERROR: unsupported type " + std::to_string(static_cast(type)) + ", see enum adios2_type for acceptable " @@ -246,8 +218,7 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name) try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_variable"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_inquire_variable"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMap = ioCpp.GetVariables(); @@ -265,10 +236,10 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name) { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - variableCpp = ioCpp.InquireVariable(name); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + variableCpp = ioCpp.InquireVariable(name); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -283,20 +254,18 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name) return variable; } -adios2_error adios2_inquire_all_variables(adios2_variable ***variables, - size_t *size, adios2_io *io) +adios2_error adios2_inquire_all_variables(adios2_variable ***variables, size_t *size, adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_all_variables"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_inquire_all_variables"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMap = ioCpp.GetVariables(); *size = dataMap.size(); - adios2_variable **list = - (adios2_variable **)calloc(*size, sizeof(adios2_variable *)); + adios2_variable **list = (adios2_variable **)calloc(*size, sizeof(adios2_variable *)); // Sort the names so that we return the same order as the // C++, python APIs @@ -315,11 +284,11 @@ adios2_error adios2_inquire_all_variables(adios2_variable ***variables, { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - variable = ioCpp.InquireVariable(name); \ - list[n] = reinterpret_cast(variable); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + variable = ioCpp.InquireVariable(name); \ + list[n] = reinterpret_cast(variable); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -336,13 +305,13 @@ adios2_error adios2_inquire_all_variables(adios2_variable ***variables, } } -adios2_error adios2_inquire_subgroups(char ***results, const char *full_prefix, - size_t *size, adios2_io *io) +adios2_error adios2_inquire_subgroups(char ***results, const char *full_prefix, size_t *size, + adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_all_variables"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_inquire_all_variables"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMapVar = ioCpp.GetVariables(); @@ -358,8 +327,7 @@ adios2_error adios2_inquire_subgroups(char ***results, const char *full_prefix, { auto pos = curr.find("/", prefix_size + 1); if (pos != std::string::npos) - subGrpNames.insert( - curr.substr(prefix_size, pos - prefix_size)); + subGrpNames.insert(curr.substr(prefix_size, pos - prefix_size)); } } @@ -373,8 +341,7 @@ adios2_error adios2_inquire_subgroups(char ***results, const char *full_prefix, { auto hasVar = dataMapVar.find(curr.substr(0, pos)); if (hasVar == dataMapVar.end()) - subGrpNames.insert( - curr.substr(prefix_size, pos - prefix_size)); + subGrpNames.insert(curr.substr(prefix_size, pos - prefix_size)); // else // std::cout<<" .. found a variable! "<(io); const auto &dataMap = ioCpp.GetVariables(); @@ -434,8 +400,7 @@ adios2_error adios2_inquire_group_variables(adios2_variable ***variables, } *size = names.size(); - adios2_variable **list = - (adios2_variable **)calloc(*size, sizeof(adios2_variable *)); + adios2_variable **list = (adios2_variable **)calloc(*size, sizeof(adios2_variable *)); size_t n = 0; for (auto &name : names) @@ -448,11 +413,11 @@ adios2_error adios2_inquire_group_variables(adios2_variable ***variables, { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - variable = ioCpp.InquireVariable(name); \ - list[n] = reinterpret_cast(variable); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + variable = ioCpp.InquireVariable(name); \ + list[n] = reinterpret_cast(variable); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -469,25 +434,22 @@ adios2_error adios2_inquire_group_variables(adios2_variable ***variables, } } -adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name, - const adios2_type type, +adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name, const adios2_type type, const void *value) { return adios2_define_variable_attribute(io, name, type, value, "", ""); } adios2_attribute *adios2_define_attribute_array(adios2_io *io, const char *name, - const adios2_type type, - const void *data, + const adios2_type type, const void *data, const size_t size) { - return adios2_define_variable_attribute_array(io, name, type, data, size, - "", ""); + return adios2_define_variable_attribute_array(io, name, type, data, size, "", ""); } -adios2_attribute *adios2_define_variable_attribute( - adios2_io *io, const char *name, const adios2_type type, const void *value, - const char *variable_name, const char *separator) +adios2_attribute *adios2_define_variable_attribute(adios2_io *io, const char *name, + const adios2_type type, const void *value, + const char *variable_name, const char *separator) { adios2_attribute *attribute = nullptr; @@ -498,38 +460,31 @@ adios2_attribute *adios2_define_variable_attribute( "adios2_define_variable_attribute"); adios2::helper::CheckForNullptr( - value, - "for const void* data, in call to adios2_define_attribute or " - "adios2_define_variable_attribute"); + value, "for const void* data, in call to adios2_define_attribute or " + "adios2_define_variable_attribute"); adios2::core::IO &ioCpp = *reinterpret_cast(io); adios2::core::AttributeBase *attributeCpp = nullptr; switch (type) { - case (adios2_type_string): - { + case (adios2_type_string): { // relying on null terminated character for the size - const std::string singleString( - reinterpret_cast(value)); - attributeCpp = &ioCpp.DefineAttribute( - name, singleString, variable_name, separator); + const std::string singleString(reinterpret_cast(value)); + attributeCpp = + &ioCpp.DefineAttribute(name, singleString, variable_name, separator); break; } -#define make_case(adios2_type) \ - case (adios2_type): \ - { \ - attributeCpp = &ioCpp.DefineAttribute( \ - name, \ - *reinterpret_cast::Type *>( \ - value), \ - variable_name, separator); \ - break; \ +#define make_case(adios2_type) \ + case (adios2_type): { \ + attributeCpp = &ioCpp.DefineAttribute( \ + name, *reinterpret_cast::Type *>(value), \ + variable_name, separator); \ + break; \ } ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(make_case) #undef make_case - default: - { + default: { throw std::invalid_argument("ERROR: unsupported type " + std::to_string(static_cast(type)) + ", see enum adios2_type for acceptable " @@ -549,26 +504,26 @@ adios2_attribute *adios2_define_variable_attribute( return attribute; } -adios2_attribute *adios2_define_variable_attribute_array( - adios2_io *io, const char *name, const adios2_type type, const void *data, - const size_t size, const char *variable_name, const char *separator) +adios2_attribute *adios2_define_variable_attribute_array(adios2_io *io, const char *name, + const adios2_type type, const void *data, + const size_t size, + const char *variable_name, + const char *separator) { adios2_attribute *attribute = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_define_attribute"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_define_attribute"); - adios2::helper::CheckForNullptr( - data, "for const void* data, in call to adios2_define_attribute"); + adios2::helper::CheckForNullptr(data, + "for const void* data, in call to adios2_define_attribute"); if (size == 0) { - throw std::invalid_argument( - "ERROR: size of attribute array " + std::string(name) + - " can't be 0, in call to adios2_define_attribute or " - "adios2_define_variable_attribute"); + throw std::invalid_argument("ERROR: size of attribute array " + std::string(name) + + " can't be 0, in call to adios2_define_attribute or " + "adios2_define_variable_attribute"); } adios2::core::IO &ioCpp = *reinterpret_cast(io); @@ -576,38 +531,31 @@ adios2_attribute *adios2_define_variable_attribute_array( switch (type) { - case (adios2_type_string): - { - const char **char2D = - reinterpret_cast(const_cast(data)); + case (adios2_type_string): { + const char **char2D = reinterpret_cast(const_cast(data)); std::vector arrayStrings(char2D, char2D + size); attributeCpp = &ioCpp.DefineAttribute( - name, arrayStrings.data(), arrayStrings.size(), variable_name, - separator); + name, arrayStrings.data(), arrayStrings.size(), variable_name, separator); break; } -#define make_case(adios2_type) \ - case (adios2_type): \ - { \ - attributeCpp = &ioCpp.DefineAttribute( \ - name, \ - reinterpret_cast::Type *>(data), \ - size, variable_name, separator); \ - break; \ +#define make_case(adios2_type) \ + case (adios2_type): { \ + attributeCpp = &ioCpp.DefineAttribute( \ + name, reinterpret_cast::Type *>(data), size, \ + variable_name, separator); \ + break; \ } ADIOS2_FOREACH_C_ATTRIBUTE_TYPE_1ARG(make_case) #undef make_case - default: - { - throw std::invalid_argument( - "ERROR: unsupported type " + - std::to_string(static_cast(type)) + - ", see enum adios2_type for acceptable " - "types, in call to " - "adios2_define_attribute_array or " - "adios2_define_variable_attribute_array\n"); + default: { + throw std::invalid_argument("ERROR: unsupported type " + + std::to_string(static_cast(type)) + + ", see enum adios2_type for acceptable " + "types, in call to " + "adios2_define_attribute_array or " + "adios2_define_variable_attribute_array\n"); } } @@ -615,9 +563,8 @@ adios2_attribute *adios2_define_variable_attribute_array( } catch (...) { - adios2::helper::ExceptionToError( - "adios2_define_attribute_array or " - "adios_define_variable_attribute_array"); + adios2::helper::ExceptionToError("adios2_define_attribute_array or " + "adios_define_variable_attribute_array"); } return attribute; } @@ -627,8 +574,7 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name) adios2_attribute *attribute = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_attribute"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_inquire_attribute"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMap = ioCpp.GetAttributes(); @@ -646,10 +592,10 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name) { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - attributeCpp = ioCpp.InquireAttribute(name); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + attributeCpp = ioCpp.InquireAttribute(name); \ } ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -664,8 +610,7 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name) return attribute; } -adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, - const char *name, +adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, const char *name, const char *variable_name, const char *separator) { @@ -675,20 +620,19 @@ adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, return adios2_inquire_attribute(io, globalName.c_str()); } -adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, - size_t *size, adios2_io *io) +adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, size_t *size, + adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_all_attributes"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_inquire_all_attributes"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMap = ioCpp.GetAttributes(); *size = dataMap.size(); - adios2_attribute **list = - (adios2_attribute **)calloc(*size, sizeof(adios2_attribute *)); + adios2_attribute **list = (adios2_attribute **)calloc(*size, sizeof(adios2_attribute *)); // Sort the names so that we return the same order as the // C++, python APIs @@ -707,14 +651,13 @@ adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - attribute = ioCpp.InquireAttribute(name); \ - list[n] = reinterpret_cast(attribute); \ - } - ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG( - declare_template_instantiation) +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + attribute = ioCpp.InquireAttribute(name); \ + list[n] = reinterpret_cast(attribute); \ + } + ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation n++; @@ -730,13 +673,12 @@ adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, } adios2_error adios2_inquire_group_attributes(adios2_attribute ***attributes, - const char *full_prefix, - size_t *size, adios2_io *io) + const char *full_prefix, size_t *size, adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_inquire_all_attributes"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_inquire_all_attributes"); adios2::core::IO &ioCpp = *reinterpret_cast(io); const auto &dataMap = ioCpp.GetAttributes(); @@ -763,8 +705,7 @@ adios2_error adios2_inquire_group_attributes(adios2_attribute ***attributes, if (0 == *size) return adios2_error_none; - adios2_attribute **list = - (adios2_attribute **)calloc(*size, sizeof(adios2_attribute *)); + adios2_attribute **list = (adios2_attribute **)calloc(*size, sizeof(adios2_attribute *)); size_t n = 0; for (auto &name : names) @@ -777,14 +718,13 @@ adios2_error adios2_inquire_group_attributes(adios2_attribute ***attributes, { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - attribute = ioCpp.InquireAttribute(name); \ - list[n] = reinterpret_cast(attribute); \ - } - ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG( - declare_template_instantiation) +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + attribute = ioCpp.InquireAttribute(name); \ + list[n] = reinterpret_cast(attribute); \ + } + ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation n++; @@ -800,17 +740,14 @@ adios2_error adios2_inquire_group_attributes(adios2_attribute ***attributes, } // DANGEROUS -adios2_error adios2_remove_variable(adios2_bool *result, adios2_io *io, - const char *name) +adios2_error adios2_remove_variable(adios2_bool *result, adios2_io *io, const char *name) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_remove_variable"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_remove_variable"); - *result = reinterpret_cast(io)->RemoveVariable(name) - ? adios2_true - : adios2_false; + *result = reinterpret_cast(io)->RemoveVariable(name) ? adios2_true + : adios2_false; return adios2_error_none; } @@ -825,8 +762,8 @@ adios2_error adios2_remove_all_variables(adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_remove_all_variables"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_remove_all_variables"); reinterpret_cast(io)->RemoveAllVariables(); return adios2_error_none; @@ -838,17 +775,13 @@ adios2_error adios2_remove_all_variables(adios2_io *io) } } -adios2_error adios2_remove_attribute(adios2_bool *result, adios2_io *io, - const char *name) +adios2_error adios2_remove_attribute(adios2_bool *result, adios2_io *io, const char *name) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_remove_attribute"); - *result = - reinterpret_cast(io)->RemoveAttribute(name) - ? adios2_true - : adios2_false; + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_remove_attribute"); + *result = reinterpret_cast(io)->RemoveAttribute(name) ? adios2_true + : adios2_false; return adios2_error_none; } catch (...) @@ -862,8 +795,8 @@ adios2_error adios2_remove_all_attributes(adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_remove_all_attributes"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_remove_all_attributes"); reinterpret_cast(io)->RemoveAllAttributes(); return adios2_error_none; } @@ -878,8 +811,7 @@ char **adios2_available_variables(adios2_io *io, size_t *size) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_available_variables"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_available_variables"); std::map> varInfo = reinterpret_cast(io)->GetAvailableVariables(); *size = varInfo.size(); @@ -905,8 +837,8 @@ char **adios2_available_attributes(adios2_io *io, size_t *size) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_available_attributes"); + adios2::helper::CheckForNullptr(io, + "for adios2_io, in call to adios2_available_attributes"); std::map> varInfo = reinterpret_cast(io)->GetAvailableAttributes(); *size = varInfo.size(); @@ -928,17 +860,14 @@ char **adios2_available_attributes(adios2_io *io, size_t *size) return NULL; } } -adios2_engine *adios2_open(adios2_io *io, const char *name, - const adios2_mode mode) +adios2_engine *adios2_open(adios2_io *io, const char *name, const adios2_mode mode) { adios2_engine *engine = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_open"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_open"); engine = reinterpret_cast( - &reinterpret_cast(io)->Open( - name, adios2_ToOpenMode(mode))); + &reinterpret_cast(io)->Open(name, adios2_ToOpenMode(mode))); } catch (...) { @@ -951,8 +880,7 @@ adios2_error adios2_flush_all_engines(adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_flush_all_engines"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_flush_all_engines"); reinterpret_cast(io)->FlushAll(); return adios2_error_none; } @@ -963,25 +891,21 @@ adios2_error adios2_flush_all_engines(adios2_io *io) } } -adios2_error adios2_engine_type(char *engine_type, size_t *size, - const adios2_io *io) +adios2_error adios2_engine_type(char *engine_type, size_t *size, const adios2_io *io) { try { - adios2::helper::CheckForNullptr( - io, "for const adios2_io, in call to adios2_io_engine_type"); - adios2::helper::CheckForNullptr( - size, "for size_t* size, in call to adios2_io_engine_type"); + adios2::helper::CheckForNullptr(io, + "for const adios2_io, in call to adios2_io_engine_type"); + adios2::helper::CheckForNullptr(size, "for size_t* size, in call to adios2_io_engine_type"); - const adios2::core::IO *ioCpp = - reinterpret_cast(io); + const adios2::core::IO *ioCpp = reinterpret_cast(io); return String2CAPI(ioCpp->m_EngineType, engine_type, size); } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_engine_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_engine_type")); } } @@ -990,8 +914,7 @@ adios2_engine *adios2_get_engine(adios2_io *io, const char *name) adios2_engine *engine = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_open"); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_open"); engine = reinterpret_cast( &reinterpret_cast(io)->GetEngine(name)); } diff --git a/bindings/C/adios2/c/adios2_c_io.h b/bindings/C/adios2/c/adios2_c_io.h index 271c2d87c6..8a8272c5a7 100644 --- a/bindings/C/adios2/c/adios2_c_io.h +++ b/bindings/C/adios2/c/adios2_c_io.h @@ -54,8 +54,7 @@ adios2_error adios2_set_parameters(adios2_io *io, const char *parameters); * @param value parameter value * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_parameter(adios2_io *io, const char *key, - const char *value); +adios2_error adios2_set_parameter(adios2_io *io, const char *key, const char *value); /** * Return IO parameter value string and length without '\0\ character @@ -70,8 +69,7 @@ adios2_error adios2_set_parameter(adios2_io *io, const char *key, * untouched * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_get_parameter(char *value, size_t *size, - const adios2_io *io, const char *key); +adios2_error adios2_get_parameter(char *value, size_t *size, const adios2_io *io, const char *key); /** * @brief Clear all parameters. @@ -90,8 +88,7 @@ adios2_error adios2_clear_parameters(adios2_io *io); * CAN'T use the keywords "Transport" or "transport" * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_add_transport(size_t *transport_index, adios2_io *io, - const char *type); +adios2_error adios2_add_transport(size_t *transport_index, adios2_io *io, const char *type); /** * @brief Set a single parameter to an existing transport identified @@ -103,8 +100,7 @@ adios2_error adios2_add_transport(size_t *transport_index, adios2_io *io, * @param value parameter value * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_transport_parameter(adios2_io *io, - const size_t transport_index, +adios2_error adios2_set_transport_parameter(adios2_io *io, const size_t transport_index, const char *key, const char *value); /** @@ -121,11 +117,10 @@ adios2_error adios2_set_transport_parameter(adios2_io *io, * after definition * @return success: handler, failure: NULL */ -adios2_variable * -adios2_define_variable(adios2_io *io, const char *name, const adios2_type type, - const size_t ndims, const size_t *shape, - const size_t *start, const size_t *count, - const adios2_constant_dims constant_dims); +adios2_variable *adios2_define_variable(adios2_io *io, const char *name, const adios2_type type, + const size_t ndims, const size_t *shape, + const size_t *start, const size_t *count, + const adios2_constant_dims constant_dims); /** * @brief Retrieve a variable handler within current io handler @@ -144,15 +139,15 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name); * @param io handler to variables io owner * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_inquire_all_variables(adios2_variable ***variables, - size_t *size, adios2_io *io); +adios2_error adios2_inquire_all_variables(adios2_variable ***variables, size_t *size, + adios2_io *io); /* * list all variables under full_group_name */ adios2_error adios2_inquire_group_variables(adios2_variable ***variables, - const char *full_group_name, - size_t *size, adios2_io *io); + const char *full_group_name, size_t *size, + adios2_io *io); /** * @brief Define an attribute value inside io @@ -162,8 +157,7 @@ adios2_error adios2_inquire_group_variables(adios2_variable ***variables, * @param value attribute single value * @return success: handler, failure: NULL */ -adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name, - const adios2_type type, +adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name, const adios2_type type, const void *value); /** @@ -176,8 +170,7 @@ adios2_attribute *adios2_define_attribute(adios2_io *io, const char *name, * @return success: handler, failure: NULL */ adios2_attribute *adios2_define_attribute_array(adios2_io *io, const char *name, - const adios2_type type, - const void *data, + const adios2_type type, const void *data, const size_t size); /** @@ -192,9 +185,10 @@ adios2_attribute *adios2_define_attribute_array(adios2_io *io, const char *name, * @param separator hierarchy separator (e.g. "/" in variable_name/name ) * @return success: handler, failure: NULL */ -adios2_attribute *adios2_define_variable_attribute( - adios2_io *io, const char *name, const adios2_type type, const void *value, - const char *variable_name, const char *separator); +adios2_attribute *adios2_define_variable_attribute(adios2_io *io, const char *name, + const adios2_type type, const void *value, + const char *variable_name, + const char *separator); /** * Define an attribute array associated to an existing variable by its name @@ -208,9 +202,11 @@ adios2_attribute *adios2_define_variable_attribute( * @param separator hierarchy separator (e.g. "/" in variable/attribute ) * @return success: handler, failure: NULL */ -adios2_attribute *adios2_define_variable_attribute_array( - adios2_io *io, const char *name, const adios2_type type, const void *data, - const size_t size, const char *variable_name, const char *separator); +adios2_attribute *adios2_define_variable_attribute_array(adios2_io *io, const char *name, + const adios2_type type, const void *data, + const size_t size, + const char *variable_name, + const char *separator); /** * Returns a handler to a previously defined attribute by name @@ -228,8 +224,7 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name); * @param separator hierarchy separator (e.g. "/" in variable/attribute ) * @return found: handler, not found: NULL */ -adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, - const char *name, +adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, const char *name, const char *variable_name, const char *separator); /** @@ -241,18 +236,16 @@ adios2_attribute *adios2_inquire_variable_attribute(adios2_io *io, * @param io handler to attributes io owner * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, - size_t *size, adios2_io *io); +adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes, size_t *size, + adios2_io *io); adios2_error adios2_inquire_group_attributes(adios2_attribute ***attributes, - const char *full_prefix, - size_t *size, adios2_io *io); + const char *full_prefix, size_t *size, adios2_io *io); /** * Return a list of list sub group names * */ -adios2_error adios2_inquire_subgroups(char ***subGroupNames, - const char *full_prefix, size_t *size, +adios2_error adios2_inquire_subgroups(char ***subGroupNames, const char *full_prefix, size_t *size, adios2_io *io); /** @@ -264,8 +257,7 @@ adios2_error adios2_inquire_subgroups(char ***subGroupNames, * @param name unique variable name within io handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_remove_variable(adios2_bool *result, adios2_io *io, - const char *name); +adios2_error adios2_remove_variable(adios2_bool *result, adios2_io *io, const char *name); /** * @brief DANGEROUS! Removes all existing variables in current IO object. @@ -301,8 +293,7 @@ char **adios2_available_attributes(adios2_io *io, size_t *size); * @param name unique attribute name within io handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_remove_attribute(adios2_bool *result, adios2_io *io, - const char *name); +adios2_error adios2_remove_attribute(adios2_bool *result, adios2_io *io, const char *name); /** * @brief DANGEROUS! Removes all existing attributes in current IO object. @@ -322,8 +313,7 @@ adios2_error adios2_remove_all_attributes(adios2_io *io); * adios2_mode_readRandomAccess * @return success: handler, failure: NULL */ -adios2_engine *adios2_open(adios2_io *io, const char *name, - const adios2_mode mode); +adios2_engine *adios2_open(adios2_io *io, const char *name, const adios2_mode mode); #if ADIOS2_USE_MPI /** @@ -336,8 +326,8 @@ adios2_engine *adios2_open(adios2_io *io, const char *name, * @param comm communicator other than adios' handler comm. MPI only. * @return success: handler, failure: NULL */ -adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, - const adios2_mode mode, MPI_Comm comm); +adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, const adios2_mode mode, + MPI_Comm comm); #endif /** @@ -359,8 +349,7 @@ adios2_error adios2_flush_all_engines(adios2_io *io); * @param io handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_engine_type(char *engine_type, size_t *size, - const adios2_io *io); +adios2_error adios2_engine_type(char *engine_type, size_t *size, const adios2_io *io); adios2_engine *adios2_get_engine(adios2_io *io, const char *name); diff --git a/bindings/C/adios2/c/adios2_c_io_mpi.cpp b/bindings/C/adios2/c/adios2_c_io_mpi.cpp index 58344cbe45..d7b7e3d24a 100644 --- a/bindings/C/adios2/c/adios2_c_io_mpi.cpp +++ b/bindings/C/adios2/c/adios2_c_io_mpi.cpp @@ -18,18 +18,15 @@ extern "C" { -adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, - const adios2_mode mode, MPI_Comm comm) +adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, const adios2_mode mode, + MPI_Comm comm) { adios2_engine *engine = nullptr; try { - adios2::helper::CheckForNullptr( - io, "for adios2_io, in call to adios2_open"); - engine = reinterpret_cast( - &reinterpret_cast(io)->Open( - name, adios2_ToOpenMode(mode), - adios2::helper::CommDupMPI(comm))); + adios2::helper::CheckForNullptr(io, "for adios2_io, in call to adios2_open"); + engine = reinterpret_cast(&reinterpret_cast(io)->Open( + name, adios2_ToOpenMode(mode), adios2::helper::CommDupMPI(comm))); } catch (...) { diff --git a/bindings/C/adios2/c/adios2_c_operator.cpp b/bindings/C/adios2/c/adios2_c_operator.cpp index 7c90c583f1..b61d8cf9df 100644 --- a/bindings/C/adios2/c/adios2_c_operator.cpp +++ b/bindings/C/adios2/c/adios2_c_operator.cpp @@ -13,23 +13,18 @@ #include "adios2/helper/adiosFunctions.h" #include "adios2_c_internal.h" -adios2_error adios2_operator_type(char *type, size_t *size, - const adios2_operator *op) +adios2_error adios2_operator_type(char *type, size_t *size, const adios2_operator *op) { try { - adios2::helper::CheckForNullptr( - op, "for adios2_operator, in call to adios2_operator_type"); + adios2::helper::CheckForNullptr(op, "for adios2_operator, in call to adios2_operator_type"); - auto *opCpp = - reinterpret_cast *>( - op); + auto *opCpp = reinterpret_cast *>(op); return String2CAPI(opCpp->first, type, size); } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_operator_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_operator_type")); } } diff --git a/bindings/C/adios2/c/adios2_c_operator.h b/bindings/C/adios2/c/adios2_c_operator.h index b79e82ae1d..c9d359326e 100644 --- a/bindings/C/adios2/c/adios2_c_operator.h +++ b/bindings/C/adios2/c/adios2_c_operator.h @@ -28,8 +28,7 @@ extern "C" { * @param op operator handler to be inspected * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_operator_type(char *type, size_t *size, - const adios2_operator *op); +adios2_error adios2_operator_type(char *type, size_t *size, const adios2_operator *op); #ifdef __cplusplus } // end extern C diff --git a/bindings/C/adios2/c/adios2_c_variable.cpp b/bindings/C/adios2/c/adios2_c_variable.cpp index 55d9b387ee..0dc04d7ef2 100644 --- a/bindings/C/adios2/c/adios2_c_variable.cpp +++ b/bindings/C/adios2/c/adios2_c_variable.cpp @@ -16,8 +16,7 @@ namespace { -adios2_shapeid adios2_ToShapeID(const adios2::ShapeID shapeIDCpp, - const std::string &hint) +adios2_shapeid adios2_ToShapeID(const adios2::ShapeID shapeIDCpp, const std::string &hint) { adios2_shapeid shapeID = adios2_shapeid_unknown; switch (shapeIDCpp) @@ -44,8 +43,7 @@ adios2_shapeid adios2_ToShapeID(const adios2::ShapeID shapeIDCpp, break; default: - throw std::invalid_argument("ERROR: invalid adios2_shapeid, " + hint + - "\n"); + throw std::invalid_argument("ERROR: invalid adios2_shapeid, " + hint + "\n"); } return shapeID; @@ -57,14 +55,12 @@ adios2_shapeid adios2_ToShapeID(const adios2::ShapeID shapeIDCpp, extern "C" { #endif -adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, - const size_t *shape) +adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, const size_t *shape) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_shape"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_shape"); adios2::helper::CheckForNullptr(shape, "for start, in call to " "adios2_set_shape"); @@ -77,19 +73,16 @@ adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_shape")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_shape")); } } -adios2_error adios2_set_block_selection(adios2_variable *variable, - const size_t block_id) +adios2_error adios2_set_block_selection(adios2_variable *variable, const size_t block_id) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_block_selection"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_block_selection"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -108,17 +101,15 @@ adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims, { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_selection"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_selection"); adios2::helper::CheckForNullptr(count, "for count, in call to " "adios2_set_selection"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); - const adios2::Dims startV = (start == nullptr) - ? adios2::Dims() - : adios2::Dims(start, start + ndims); + const adios2::Dims startV = + (start == nullptr) ? adios2::Dims() : adios2::Dims(start, start + ndims); const adios2::Dims countV = adios2::Dims(count, count + ndims); variableBase->SetSelection({startV, countV}); @@ -127,27 +118,21 @@ adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_selection")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_selection")); } } -adios2_error adios2_set_memory_selection(adios2_variable *variable, - const size_t ndims, - const size_t *memory_start, - const size_t *memory_count) +adios2_error adios2_set_memory_selection(adios2_variable *variable, const size_t ndims, + const size_t *memory_start, const size_t *memory_count) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_memory_selection"); - adios2::helper::CheckForNullptr(memory_start, - "for start, in call to " - "adios2_set_memory_selection"); - adios2::helper::CheckForNullptr(memory_count, - "for count, in call to " - "adios2_set_memory_selection"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_memory_selection"); + adios2::helper::CheckForNullptr(memory_start, "for start, in call to " + "adios2_set_memory_selection"); + adios2::helper::CheckForNullptr(memory_count, "for count, in call to " + "adios2_set_memory_selection"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -163,38 +148,31 @@ adios2_error adios2_set_memory_selection(adios2_variable *variable, } } -adios2_error adios2_set_step_selection(adios2_variable *variable, - const size_t step_start, +adios2_error adios2_set_step_selection(adios2_variable *variable, const size_t step_start, const size_t step_count) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_step_selection"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_step_selection"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); - variableBase->SetStepSelection( - adios2::Box{step_start, step_count}); + variableBase->SetStepSelection(adios2::Box{step_start, step_count}); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_set_selection")); + return static_cast(adios2::helper::ExceptionToError("adios2_set_selection")); } } -adios2_error adios2_variable_name(char *name, size_t *size, - const adios2_variable *variable) +adios2_error adios2_variable_name(char *name, size_t *size, const adios2_variable *variable) { try { adios2::helper::CheckForNullptr( - variable, - "for const adios2_variable, in call to adios2_variable_name"); - adios2::helper::CheckForNullptr( - size, "for size_t* size, in call to adios2_variable_name"); + variable, "for const adios2_variable, in call to adios2_variable_name"); + adios2::helper::CheckForNullptr(size, "for size_t* size, in call to adios2_variable_name"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -202,19 +180,16 @@ adios2_error adios2_variable_name(char *name, size_t *size, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_name")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_name")); } } -adios2_error adios2_variable_type(adios2_type *type, - const adios2_variable *variable) +adios2_error adios2_variable_type(adios2_type *type, const adios2_variable *variable) { try { adios2::helper::CheckForNullptr( - variable, - "for const adios2_variable, in call to adios2_variable_type"); + variable, "for const adios2_variable, in call to adios2_variable_type"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -224,31 +199,31 @@ adios2_error adios2_variable_type(adios2_type *type, { *type = adios2_type_string; } -#define make_case(T) \ - else if (typeCpp == adios2::helper::GetDataType::Type>()) \ - { \ - *type = T; \ +#define make_case(T) \ + else if (typeCpp == adios2::helper::GetDataType::Type>()) \ + { \ + *type = T; \ } ADIOS2_FOREACH_C_TYPE_1ARG(make_case) #undef make_case - else { *type = adios2_type_unknown; } + else + { + *type = adios2_type_unknown; + } return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_type")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_type")); } } -adios2_error adios2_variable_type_string(char *type, size_t *size, - const adios2_variable *variable) +adios2_error adios2_variable_type_string(char *type, size_t *size, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_type_string"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_type_string"); adios2::helper::CheckForNullptr( size, "for size_t* length, in call to adios2_variable_type_string"); @@ -263,19 +238,16 @@ adios2_error adios2_variable_type_string(char *type, size_t *size, } } -adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, - const adios2_variable *variable) +adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_shapeid"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_shapeid"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); - *shapeid = adios2_ToShapeID(variableBase->m_ShapeID, - "in call to adios2_variable_shapeid"); + *shapeid = adios2_ToShapeID(variableBase->m_ShapeID, "in call to adios2_variable_shapeid"); return adios2_error_none; } catch (...) @@ -285,14 +257,12 @@ adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, } } -adios2_error adios2_variable_ndims(size_t *ndims, - const adios2_variable *variable) +adios2_error adios2_variable_ndims(size_t *ndims, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_ndims"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_ndims"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); *ndims = variableBase->m_Count.size(); @@ -300,19 +270,16 @@ adios2_error adios2_variable_ndims(size_t *ndims, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_ndims")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_ndims")); } } -adios2_error adios2_variable_shape(size_t *shape, - const adios2_variable *variable) +adios2_error adios2_variable_shape(size_t *shape, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_shape"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_shape"); adios2::helper::CheckForNullptr(shape, "for size_t* shape, in call to " "adios2_variable_shape"); @@ -324,14 +291,13 @@ adios2_error adios2_variable_shape(size_t *shape, { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(variableBase); \ - const adios2::Dims shapeCpp = \ - variable->Shape(adios2::EngineCurrentStep); \ - std::copy(shapeCpp.begin(), shapeCpp.end(), shape); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(variableBase); \ + const adios2::Dims shapeCpp = variable->Shape(adios2::EngineCurrentStep); \ + std::copy(shapeCpp.begin(), shapeCpp.end(), shape); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -340,44 +306,36 @@ adios2_error adios2_variable_shape(size_t *shape, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_shape")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_shape")); } } -adios2_error adios2_variable_start(size_t *start, - const adios2_variable *variable) +adios2_error adios2_variable_start(size_t *start, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_start"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_start"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); - std::copy(variableBase->m_Start.begin(), variableBase->m_Start.end(), - start); + std::copy(variableBase->m_Start.begin(), variableBase->m_Start.end(), start); return adios2_error_none; } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_shape")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_shape")); } } -adios2_error adios2_variable_count(size_t *count, - const adios2_variable *variable) +adios2_error adios2_variable_count(size_t *count, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_count"); - adios2::helper::CheckForNullptr(count, - "for const adios2_count, in call to " - "adios2_variable_count"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_count"); + adios2::helper::CheckForNullptr(count, "for const adios2_count, in call to " + "adios2_variable_count"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -387,13 +345,13 @@ adios2_error adios2_variable_count(size_t *count, { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(variableBase); \ - const adios2::Dims countCpp = variable->Count(); \ - std::copy(countCpp.begin(), countCpp.end(), count); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(variableBase); \ + const adios2::Dims countCpp = variable->Count(); \ + std::copy(countCpp.begin(), countCpp.end(), count); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -402,19 +360,16 @@ adios2_error adios2_variable_count(size_t *count, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_count")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_count")); } } -adios2_error adios2_variable_steps_start(size_t *steps_start, - const adios2_variable *variable) +adios2_error adios2_variable_steps_start(size_t *steps_start, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_steps_start"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_steps_start"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); *steps_start = variableBase->m_AvailableStepsStart; @@ -427,14 +382,12 @@ adios2_error adios2_variable_steps_start(size_t *steps_start, } } -adios2_error adios2_variable_steps(size_t *steps, - const adios2_variable *variable) +adios2_error adios2_variable_steps(size_t *steps, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for const adios2_variable, in call to " - "adios2_variable_steps"); + adios2::helper::CheckForNullptr(variable, "for const adios2_variable, in call to " + "adios2_variable_steps"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); *steps = variableBase->m_AvailableStepsCount; @@ -442,19 +395,16 @@ adios2_error adios2_variable_steps(size_t *steps, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_steps")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_steps")); } } -adios2_error adios2_selection_size(size_t *size, - const adios2_variable *variable) +adios2_error adios2_selection_size(size_t *size, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_selection_size"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_selection_size"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -464,12 +414,12 @@ adios2_error adios2_selection_size(size_t *size, { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(variableBase); \ - *size = variable->SelectionSize(); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(variableBase); \ + *size = variable->SelectionSize(); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -478,21 +428,17 @@ adios2_error adios2_selection_size(size_t *size, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_selection_size")); + return static_cast(adios2::helper::ExceptionToError("adios2_selection_size")); } } -adios2_error adios2_add_operation(size_t *operation_index, - adios2_variable *variable, - adios2_operator *op, const char *key, - const char *value) +adios2_error adios2_add_operation(size_t *operation_index, adios2_variable *variable, + adios2_operator *op, const char *key, const char *value) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_add_operation"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_add_operation"); adios2::helper::CheckForNullptr(op, "for adios2_operator, in call to " "adios2_add_operation"); @@ -505,8 +451,7 @@ adios2_error adios2_add_operation(size_t *operation_index, adios2::core::VariableBase *variableBase = reinterpret_cast(variable); - auto *opCpp = - reinterpret_cast *>(op); + auto *opCpp = reinterpret_cast *>(op); auto params = adios2::Params{{key, value}}; @@ -521,20 +466,17 @@ adios2_error adios2_add_operation(size_t *operation_index, } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_add_operation")); + return static_cast(adios2::helper::ExceptionToError("adios2_add_operation")); } } -adios2_error adios2_set_operation_parameter(adios2_variable *variable, - const size_t operation_id, +adios2_error adios2_set_operation_parameter(adios2_variable *variable, const size_t operation_id, const char *key, const char *value) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_set_operation_parameter"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_set_operation_parameter"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -552,9 +494,8 @@ adios2_error adios2_remove_operations(adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call to " - "adios2_remove_operations"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call to " + "adios2_remove_operations"); adios2::core::VariableBase *variableBase = reinterpret_cast(variable); variableBase->RemoveOperations(); @@ -571,11 +512,9 @@ adios2_error adios2_variable_min(void *min, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call " - "to adios2_variable_min"); - adios2::helper::CheckForNullptr( - min, "for void* min, in call to adios2_variable_min"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call " + "to adios2_variable_min"); + adios2::helper::CheckForNullptr(min, "for void* min, in call to adios2_variable_min"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -585,13 +524,13 @@ adios2_error adios2_variable_min(void *min, const adios2_variable *variable) { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - T *minT = reinterpret_cast(min); \ - const adios2::core::Variable *variableT = \ - dynamic_cast *>(variableBase); \ - *minT = variableT->Min(adios2::EngineCurrentStep); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + T *minT = reinterpret_cast(min); \ + const adios2::core::Variable *variableT = \ + dynamic_cast *>(variableBase); \ + *minT = variableT->Min(adios2::EngineCurrentStep); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -599,8 +538,7 @@ adios2_error adios2_variable_min(void *min, const adios2_variable *variable) } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_min")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_min")); } } @@ -608,11 +546,9 @@ adios2_error adios2_variable_max(void *max, const adios2_variable *variable) { try { - adios2::helper::CheckForNullptr(variable, - "for adios2_variable, in call " - "to adios2_variable_max"); - adios2::helper::CheckForNullptr( - max, "for void* max, in call to adios2_variable_max"); + adios2::helper::CheckForNullptr(variable, "for adios2_variable, in call " + "to adios2_variable_max"); + adios2::helper::CheckForNullptr(max, "for void* max, in call to adios2_variable_max"); const adios2::core::VariableBase *variableBase = reinterpret_cast(variable); @@ -622,13 +558,13 @@ adios2_error adios2_variable_max(void *max, const adios2_variable *variable) { // not supported } -#define declare_template_instantiation(T) \ - else if (type == adios2::helper::GetDataType()) \ - { \ - T *maxT = reinterpret_cast(max); \ - const adios2::core::Variable *variableT = \ - dynamic_cast *>(variableBase); \ - *maxT = variableT->Max(adios2::EngineCurrentStep); \ +#define declare_template_instantiation(T) \ + else if (type == adios2::helper::GetDataType()) \ + { \ + T *maxT = reinterpret_cast(max); \ + const adios2::core::Variable *variableT = \ + dynamic_cast *>(variableBase); \ + *maxT = variableT->Max(adios2::EngineCurrentStep); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -636,8 +572,7 @@ adios2_error adios2_variable_max(void *max, const adios2_variable *variable) } catch (...) { - return static_cast( - adios2::helper::ExceptionToError("adios2_variable_max")); + return static_cast(adios2::helper::ExceptionToError("adios2_variable_max")); } } diff --git a/bindings/C/adios2/c/adios2_c_variable.h b/bindings/C/adios2/c/adios2_c_variable.h index 75ee704206..165e5881f2 100644 --- a/bindings/C/adios2/c/adios2_c_variable.h +++ b/bindings/C/adios2/c/adios2_c_variable.h @@ -27,8 +27,7 @@ extern "C" { * @param shape new shape dimensions array * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, - const size_t *shape); +adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, const size_t *shape); /** * Read mode only. Required for reading local variables. For Global Arrays it @@ -40,8 +39,7 @@ adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims, * inspected with bpls -D variableName * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_block_selection(adios2_variable *variable, - const size_t block_id); +adios2_error adios2_set_block_selection(adios2_variable *variable, const size_t block_id); /** * Set new start and count dimensions @@ -70,10 +68,8 @@ adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims, * variable count = {Ny,Nx}, then memory_count = {Ny+2,Nx+2} * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_memory_selection(adios2_variable *variable, - const size_t ndims, - const size_t *memory_start, - const size_t *memory_count); +adios2_error adios2_set_memory_selection(adios2_variable *variable, const size_t ndims, + const size_t *memory_start, const size_t *memory_count); /** * Set new step selection using step_start and step_count. Used mostly for @@ -83,8 +79,7 @@ adios2_error adios2_set_memory_selection(adios2_variable *variable, * @param step_count number of steps to read from step start * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_step_selection(adios2_variable *variable, - const size_t step_start, +adios2_error adios2_set_step_selection(adios2_variable *variable, const size_t step_start, const size_t step_count); /** @@ -98,8 +93,7 @@ adios2_error adios2_set_step_selection(adios2_variable *variable, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_name(char *name, size_t *size, - const adios2_variable *variable); +adios2_error adios2_variable_name(char *name, size_t *size, const adios2_variable *variable); /** * Retrieve variable type @@ -107,8 +101,7 @@ adios2_error adios2_variable_name(char *name, size_t *size, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_type(adios2_type *type, - const adios2_variable *variable); +adios2_error adios2_variable_type(adios2_type *type, const adios2_variable *variable); /** * Retrieve variable type in string form "char", "unsigned long", etc. @@ -121,8 +114,7 @@ adios2_error adios2_variable_type(adios2_type *type, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_type_string(char *type, size_t *size, - const adios2_variable *variable); +adios2_error adios2_variable_type_string(char *type, size_t *size, const adios2_variable *variable); /** * Retrieve variable shapeid @@ -130,8 +122,7 @@ adios2_error adios2_variable_type_string(char *type, size_t *size, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, - const adios2_variable *variable); +adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, const adios2_variable *variable); /** * Retrieve current variable number of dimensions @@ -139,8 +130,7 @@ adios2_error adios2_variable_shapeid(adios2_shapeid *shapeid, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_ndims(size_t *ndims, - const adios2_variable *variable); +adios2_error adios2_variable_ndims(size_t *ndims, const adios2_variable *variable); /** * Retrieve current variable shape @@ -148,8 +138,7 @@ adios2_error adios2_variable_ndims(size_t *ndims, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_shape(size_t *shape, - const adios2_variable *variable); +adios2_error adios2_variable_shape(size_t *shape, const adios2_variable *variable); /** * Retrieve current variable start @@ -157,8 +146,7 @@ adios2_error adios2_variable_shape(size_t *shape, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_start(size_t *start, - const adios2_variable *variable); +adios2_error adios2_variable_start(size_t *start, const adios2_variable *variable); /** * Retrieve current variable start @@ -166,8 +154,7 @@ adios2_error adios2_variable_start(size_t *start, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_count(size_t *count, - const adios2_variable *variable); +adios2_error adios2_variable_count(size_t *count, const adios2_variable *variable); /** * Read API, get available steps start from available steps count @@ -177,8 +164,7 @@ adios2_error adios2_variable_count(size_t *count, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_steps_start(size_t *steps_start, - const adios2_variable *variable); +adios2_error adios2_variable_steps_start(size_t *steps_start, const adios2_variable *variable); /** * Read API, get available steps count from available steps count @@ -187,8 +173,7 @@ adios2_error adios2_variable_steps_start(size_t *steps_start, * @param variable handler * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_variable_steps(size_t *steps, - const adios2_variable *variable); +adios2_error adios2_variable_steps(size_t *steps, const adios2_variable *variable); /** * Returns the minimum required allocation (in number of elements of a certain @@ -198,8 +183,7 @@ adios2_error adios2_variable_steps(size_t *steps, * @param variable handler for which data size will be inspected from * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_selection_size(size_t *size, - const adios2_variable *variable); +adios2_error adios2_selection_size(size_t *size, const adios2_variable *variable); /** * Adds an operation to a variable (e.g. compression) @@ -211,10 +195,8 @@ adios2_error adios2_selection_size(size_t *size, * @param value parameter value supported by the operation, empty if none * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_add_operation(size_t *operation_index, - adios2_variable *variable, - adios2_operator *op, const char *key, - const char *value); +adios2_error adios2_add_operation(size_t *operation_index, adios2_variable *variable, + adios2_operator *op, const char *key, const char *value); /** * Adds a parameter to an operation created with adios2_add_operation @@ -224,8 +206,7 @@ adios2_error adios2_add_operation(size_t *operation_index, * @param value parameter value supported by the operation * @return adios2_error 0: success, see enum adios2_error for errors */ -adios2_error adios2_set_operation_parameter(adios2_variable *variable, - const size_t operation_id, +adios2_error adios2_set_operation_parameter(adios2_variable *variable, const size_t operation_id, const char *key, const char *value); /** diff --git a/bindings/CXX11/CMakeLists.txt b/bindings/CXX11/CMakeLists.txt index 2be90fb64e..861764313b 100644 --- a/bindings/CXX11/CMakeLists.txt +++ b/bindings/CXX11/CMakeLists.txt @@ -24,7 +24,7 @@ add_library(adios2_cxx11 set_property(TARGET adios2_cxx11 PROPERTY EXPORT_NAME cxx11) set_property(TARGET adios2_cxx11 PROPERTY OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUFFIX}_cxx11) -target_link_libraries(adios2_cxx11 PRIVATE adios2_core adios2::thirdparty::pugixml) +target_link_libraries(adios2_cxx11 PRIVATE adios2_core) target_compile_features(adios2_cxx11 INTERFACE ${ADIOS2_CXX11_FEATURES}) target_include_directories(adios2_cxx11 diff --git a/bindings/CXX11/adios2/cxx11/ADIOS.cpp b/bindings/CXX11/adios2/cxx11/ADIOS.cpp index 1cff5be4cb..5dc00cc797 100644 --- a/bindings/CXX11/adios2/cxx11/ADIOS.cpp +++ b/bindings/CXX11/adios2/cxx11/ADIOS.cpp @@ -62,8 +62,7 @@ void ADIOS::ExitComputationBlock() noexcept Operator ADIOS::DefineOperator(const std::string name, const std::string type, const Params ¶meters) { - CheckPointer("for operator name " + name + - ", in call to ADIOS::DefineOperator"); + CheckPointer("for operator name " + name + ", in call to ADIOS::DefineOperator"); auto op = &m_ADIOS->DefineOperator(name, type, parameters); return Operator(op->first, &op->second); } diff --git a/bindings/CXX11/adios2/cxx11/ADIOS.h b/bindings/CXX11/adios2/cxx11/ADIOS.h index fddc335ad1..01b6834df6 100644 --- a/bindings/CXX11/adios2/cxx11/ADIOS.h +++ b/bindings/CXX11/adios2/cxx11/ADIOS.h @@ -43,8 +43,7 @@ class ADIOS public: template - using enable_if_bool = - typename std::enable_if::value, bool>::type; + using enable_if_bool = typename std::enable_if::value, bool>::type; #if ADIOS2_USE_MPI /** @@ -75,8 +74,7 @@ class ADIOS * treat all arrays column-major * e.g. adios2::ADIOS("", comm, "Fortran", false); */ - ADIOS(const std::string &configFile, MPI_Comm comm, - const std::string &hostLanguage); + ADIOS(const std::string &configFile, MPI_Comm comm, const std::string &hostLanguage); #endif @@ -143,8 +141,7 @@ class ADIOS * @exception std::invalid_argument if IO with unique name is already * declared */ - IO DeclareIO(const std::string name, - const ArrayOrdering ArrayOrder = ArrayOrdering::Auto); + IO DeclareIO(const std::string name, const ArrayOrdering ArrayOrder = ArrayOrdering::Auto); /** * Retrieve an existing IO object previously created with DeclareIO. @@ -180,8 +177,7 @@ class ADIOS * operator due to missing dependency or unsupported type */ template - Operator DefineOperator(const std::string name, - const std::function &function, + Operator DefineOperator(const std::string name, const std::function &function, const Params ¶meters = Params()); /** @@ -228,25 +224,23 @@ class ADIOS void CheckPointer(const std::string hint); /* CallBack1 signature */ -#define declare_type(T) \ - Operator DefineCallBack( \ - const std::string name, \ - const std::function &function, \ +#define declare_type(T) \ + Operator DefineCallBack( \ + const std::string name, \ + const std::function &function, \ const Params ¶meters); ADIOS2_FOREACH_TYPE_1ARG(declare_type) #undef declare_type /* CallBack2 signature */ - Operator DefineCallBack( - const std::string name, - const std::function &function, - const Params ¶meters); + Operator + DefineCallBack(const std::string name, + const std::function &function, + const Params ¶meters); }; } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/ADIOSMPI.cpp b/bindings/CXX11/adios2/cxx11/ADIOSMPI.cpp index 541a57753d..62afa773cb 100644 --- a/bindings/CXX11/adios2/cxx11/ADIOSMPI.cpp +++ b/bindings/CXX11/adios2/cxx11/ADIOSMPI.cpp @@ -13,17 +13,14 @@ namespace adios2 { ADIOS::ADIOS(const std::string &configFile, MPI_Comm comm) -: m_ADIOS(std::make_shared(configFile, helper::CommDupMPI(comm), - "C++")) +: m_ADIOS(std::make_shared(configFile, helper::CommDupMPI(comm), "C++")) { } ADIOS::ADIOS(MPI_Comm comm) : ADIOS("", comm) {} -ADIOS::ADIOS(const std::string &configFile, MPI_Comm comm, - const std::string &hostLanguage) -: m_ADIOS(std::make_shared(configFile, helper::CommDupMPI(comm), - hostLanguage)) +ADIOS::ADIOS(const std::string &configFile, MPI_Comm comm, const std::string &hostLanguage) +: m_ADIOS(std::make_shared(configFile, helper::CommDupMPI(comm), hostLanguage)) { } diff --git a/bindings/CXX11/adios2/cxx11/Attribute.cpp b/bindings/CXX11/adios2/cxx11/Attribute.cpp index 0627a8c21a..df64fac4f7 100644 --- a/bindings/CXX11/adios2/cxx11/Attribute.cpp +++ b/bindings/CXX11/adios2/cxx11/Attribute.cpp @@ -17,65 +17,60 @@ namespace adios2 { -#define declare_type(T) \ - \ - template <> \ - Attribute::Attribute(core::Attribute *attribute) \ - : m_Attribute(attribute) \ - { \ - } \ - \ - template <> \ - Attribute::operator bool() const noexcept \ - { \ - return (m_Attribute == nullptr) ? false : true; \ - } \ - \ - template <> \ - std::string Attribute::Name() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Name()"); \ - return m_Attribute->m_Name; \ - } \ - \ - template <> \ - std::string Attribute::Type() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Type()"); \ - return ToString(m_Attribute->m_Type); \ - } \ - \ - template <> \ - std::vector Attribute::Data() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::Data()"); \ - \ - if (m_Attribute->m_IsSingleValue) \ - { \ - return std::vector{m_Attribute->m_DataSingleValue}; \ - } \ - else \ - { \ - return helper::NewVectorType(m_Attribute->m_DataArray); \ - } \ - } \ - \ - template <> \ - bool Attribute::IsValue() const \ - { \ - helper::CheckForNullptr(m_Attribute, \ - "in call to Attribute::IsValue()"); \ - return m_Attribute->m_IsSingleValue; \ - } \ - \ - template <> \ - std::string ToString(const Attribute &attribute) \ - { \ - return std::string("Attribute<") + attribute.Type() + ">(Name: \"" + \ - attribute.Name() + "\")"; \ +#define declare_type(T) \ + \ + template <> \ + Attribute::Attribute(core::Attribute *attribute) : m_Attribute(attribute) \ + { \ + } \ + \ + template <> \ + Attribute::operator bool() const noexcept \ + { \ + return (m_Attribute == nullptr) ? false : true; \ + } \ + \ + template <> \ + std::string Attribute::Name() const \ + { \ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Name()"); \ + return m_Attribute->m_Name; \ + } \ + \ + template <> \ + std::string Attribute::Type() const \ + { \ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Type()"); \ + return ToString(m_Attribute->m_Type); \ + } \ + \ + template <> \ + std::vector Attribute::Data() const \ + { \ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::Data()"); \ + \ + if (m_Attribute->m_IsSingleValue) \ + { \ + return std::vector{m_Attribute->m_DataSingleValue}; \ + } \ + else \ + { \ + return helper::NewVectorType(m_Attribute->m_DataArray); \ + } \ + } \ + \ + template <> \ + bool Attribute::IsValue() const \ + { \ + helper::CheckForNullptr(m_Attribute, "in call to Attribute::IsValue()"); \ + return m_Attribute->m_IsSingleValue; \ + } \ + \ + template <> \ + std::string ToString(const Attribute &attribute) \ + { \ + return std::string("Attribute<") + attribute.Type() + ">(Name: \"" + attribute.Name() + \ + "\")"; \ } ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_type) diff --git a/bindings/CXX11/adios2/cxx11/Engine.cpp b/bindings/CXX11/adios2/cxx11/Engine.cpp index 748af4e041..c37d8e1624 100644 --- a/bindings/CXX11/adios2/cxx11/Engine.cpp +++ b/bindings/CXX11/adios2/cxx11/Engine.cpp @@ -21,8 +21,7 @@ namespace adios2 void Engine::CheckMemorySpace(MemorySpace variableMem, MemorySpace bufferMem) { if (variableMem != MemorySpace::Detect && variableMem != bufferMem) - helper::Throw("CXX-Bindings", "Engine", "Put", - "Memory space mismatch"); + helper::Throw("CXX-Bindings", "Engine", "Put", "Memory space mismatch"); } #endif @@ -68,8 +67,7 @@ bool Engine::BetweenStepPairs() StepStatus Engine::BeginStep(const StepMode mode, const float timeoutSeconds) { - helper::CheckForNullptr( - m_Engine, "in call to Engine::BeginStep(const StepMode, const float)"); + helper::CheckForNullptr(m_Engine, "in call to Engine::BeginStep(const StepMode, const float)"); return m_Engine->BeginStep(mode, timeoutSeconds); } @@ -99,15 +97,13 @@ void Engine::PerformGets() void Engine::LockWriterDefinitions() { - helper::CheckForNullptr(m_Engine, - "in call to Engine::LockWriterDefinitions"); + helper::CheckForNullptr(m_Engine, "in call to Engine::LockWriterDefinitions"); m_Engine->LockWriterDefinitions(); } void Engine::LockReaderSelections() { - helper::CheckForNullptr(m_Engine, - "in call to Engine::LockReaderSelections"); + helper::CheckForNullptr(m_Engine, "in call to Engine::LockReaderSelections"); m_Engine->LockReaderSelections(); } @@ -146,34 +142,27 @@ Engine::Engine(core::Engine *engine) : m_Engine(engine) {} void Engine::Put(VariableNT &variable, const void *data, const Mode launch) { helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); - helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Put"); -#define declare_type(T) \ - if (variable.m_Variable->m_Type == helper::GetDataType()) \ - { \ - m_Engine->Put( \ - *reinterpret_cast *>(variable.m_Variable), \ - reinterpret_cast(data), launch); \ + helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Put"); +#define declare_type(T) \ + if (variable.m_Variable->m_Type == helper::GetDataType()) \ + { \ + m_Engine->Put(*reinterpret_cast *>(variable.m_Variable), \ + reinterpret_cast(data), launch); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type else if (variable.m_Variable->m_Type == DataType::Struct) { - m_Engine->Put( - *reinterpret_cast(variable.m_Variable), - data, launch); + m_Engine->Put(*reinterpret_cast(variable.m_Variable), data, launch); } } -#define declare_type(T) \ - void Engine::Put(VariableNT &variable, const T &datum, const Mode launch) \ - { \ - helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); \ - helper::CheckForNullptr(variable.m_Variable, \ - "for variable in call to Engine::Put"); \ - m_Engine->Put( \ - *reinterpret_cast *>(variable.m_Variable), \ - datum, launch); \ +#define declare_type(T) \ + void Engine::Put(VariableNT &variable, const T &datum, const Mode launch) \ + { \ + helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); \ + helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Put"); \ + m_Engine->Put(*reinterpret_cast *>(variable.m_Variable), datum, launch); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type @@ -181,57 +170,47 @@ ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) void Engine::Get(VariableNT &variable, void *data, const Mode launch) { adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Get"); -#define declare_type(T) \ - if (variable.m_Variable->m_Type == helper::GetDataType()) \ - { \ - m_Engine->Get( \ - *reinterpret_cast *>(variable.m_Variable), \ - reinterpret_cast(data), launch); \ + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Get"); +#define declare_type(T) \ + if (variable.m_Variable->m_Type == helper::GetDataType()) \ + { \ + m_Engine->Get(*reinterpret_cast *>(variable.m_Variable), \ + reinterpret_cast(data), launch); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type else if (variable.m_Variable->m_Type == DataType::Struct) { - m_Engine->Get( - *reinterpret_cast(variable.m_Variable), - data, launch); + m_Engine->Get(*reinterpret_cast(variable.m_Variable), data, launch); } } -#define declare_type(T) \ - void Engine::Get(VariableNT &variable, T &datum, const Mode launch) \ - { \ - adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); \ - adios2::helper::CheckForNullptr( \ - variable.m_Variable, "for variable in call to Engine::Get"); \ - m_Engine->Get( \ - *reinterpret_cast *>(variable.m_Variable), \ - datum, launch); \ +#define declare_type(T) \ + void Engine::Get(VariableNT &variable, T &datum, const Mode launch) \ + { \ + adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); \ + adios2::helper::CheckForNullptr(variable.m_Variable, \ + "for variable in call to Engine::Get"); \ + m_Engine->Get(*reinterpret_cast *>(variable.m_Variable), datum, launch); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type -#define declare_type(T) \ - void Engine::Get(VariableNT &variable, std::vector &datum, \ - const Mode launch) \ - { \ - adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); \ - adios2::helper::CheckForNullptr( \ - variable.m_Variable, "for variable in call to Engine::Get"); \ - m_Engine->Get( \ - *reinterpret_cast *>(variable.m_Variable), \ - datum, launch); \ +#define declare_type(T) \ + void Engine::Get(VariableNT &variable, std::vector &datum, const Mode launch) \ + { \ + adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); \ + adios2::helper::CheckForNullptr(variable.m_Variable, \ + "for variable in call to Engine::Get"); \ + m_Engine->Get(*reinterpret_cast *>(variable.m_Variable), datum, launch); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type -#define declare_template_instantiation(T) \ - \ - template typename Variable::Span Engine::Put(Variable, const bool, \ - const T &); \ - template typename Variable::Span Engine::Put(Variable); \ +#define declare_template_instantiation(T) \ + \ + template typename Variable::Span Engine::Put(Variable, const bool, const T &); \ + template typename Variable::Span Engine::Put(Variable); \ template void Engine::Get(Variable, T **) const; ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) @@ -243,13 +222,11 @@ std::vector Engine::BlocksInfo(const VariableNT &variable, std::vector ret; if (variable.m_Variable->m_Type == DataType::Struct) { - adios2::helper::CheckForNullptr( - m_Engine, "for Engine in call to Engine::BlocksInfo"); - adios2::helper::CheckForNullptr( - variable.m_Variable, "for variable in call to Engine::BlocksInfo"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::BlocksInfo"); + adios2::helper::CheckForNullptr(variable.m_Variable, + "for variable in call to Engine::BlocksInfo"); auto blocksInfo = m_Engine->BlocksInfoStruct( - *reinterpret_cast(variable.m_Variable), - step); + *reinterpret_cast(variable.m_Variable), step); for (const auto &b : blocksInfo) { ret.emplace_back(); @@ -262,31 +239,29 @@ std::vector Engine::BlocksInfo(const VariableNT &variable, br.IsValue = b.IsValue; } } -#define declare_type(T) \ - else if (variable.m_Variable->m_Type == helper::GetDataType()) \ - { \ - auto blocksInfoT = \ - BlocksInfo(Variable(reinterpret_cast *>( \ - variable.m_Variable)), \ - step); \ - for (const auto &b : blocksInfoT) \ - { \ - ret.emplace_back(); \ - auto &br = ret.back(); \ - br.Start = b.Start; \ - br.Count = b.Count; \ - br.WriterID = b.WriterID; \ - br.Step = b.Step; \ - br.IsReverseDims = b.IsReverseDims; \ - br.IsValue = b.IsValue; \ - } \ +#define declare_type(T) \ + else if (variable.m_Variable->m_Type == helper::GetDataType()) \ + { \ + auto blocksInfoT = BlocksInfo( \ + Variable(reinterpret_cast *>(variable.m_Variable)), step); \ + for (const auto &b : blocksInfoT) \ + { \ + ret.emplace_back(); \ + auto &br = ret.back(); \ + br.Start = b.Start; \ + br.Count = b.Count; \ + br.WriterID = b.WriterID; \ + br.Step = b.Step; \ + br.IsReverseDims = b.IsReverseDims; \ + br.IsValue = b.IsValue; \ + } \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type else { - helper::Throw("bindings::CXX11", "Engine", - "BlocksInfo", "invalid data type"); + helper::Throw("bindings::CXX11", "Engine", "BlocksInfo", + "invalid data type"); } return ret; } @@ -297,11 +272,10 @@ Engine::AllStepsBlocksInfo(const VariableNT &variable) const std::map> ret; if (variable.m_Variable->m_Type == DataType::Struct) { - adios2::helper::CheckForNullptr( - m_Engine, "for Engine in call to Engine::AllStepsBlocksInfo"); - adios2::helper::CheckForNullptr( - variable.m_Variable, - "for variable in call to Engine::AllStepsBlocksInfo"); + adios2::helper::CheckForNullptr(m_Engine, + "for Engine in call to Engine::AllStepsBlocksInfo"); + adios2::helper::CheckForNullptr(variable.m_Variable, + "for variable in call to Engine::AllStepsBlocksInfo"); auto blocksInfo = m_Engine->AllStepsBlocksInfoStruct( *reinterpret_cast(variable.m_Variable)); for (const auto &bv : blocksInfo) @@ -320,81 +294,75 @@ Engine::AllStepsBlocksInfo(const VariableNT &variable) const } } } -#define declare_type(T) \ - else if (variable.m_Variable->m_Type == helper::GetDataType()) \ - { \ - auto blocksInfoT = AllStepsBlocksInfo(Variable( \ - reinterpret_cast *>(variable.m_Variable))); \ - for (const auto &bv : blocksInfoT) \ - { \ - auto &bvr = ret[bv.first]; \ - for (const auto &b : bv.second) \ - { \ - bvr.emplace_back(); \ - auto &br = bvr.back(); \ - br.Start = b.Start; \ - br.Count = b.Count; \ - br.WriterID = b.WriterID; \ - br.Step = b.Step; \ - br.IsReverseDims = b.IsReverseDims; \ - br.IsValue = b.IsValue; \ - } \ - } \ +#define declare_type(T) \ + else if (variable.m_Variable->m_Type == helper::GetDataType()) \ + { \ + auto blocksInfoT = AllStepsBlocksInfo( \ + Variable(reinterpret_cast *>(variable.m_Variable))); \ + for (const auto &bv : blocksInfoT) \ + { \ + auto &bvr = ret[bv.first]; \ + for (const auto &b : bv.second) \ + { \ + bvr.emplace_back(); \ + auto &br = bvr.back(); \ + br.Start = b.Start; \ + br.Count = b.Count; \ + br.WriterID = b.WriterID; \ + br.Step = b.Step; \ + br.IsReverseDims = b.IsReverseDims; \ + br.IsValue = b.IsValue; \ + } \ + } \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type else { - helper::Throw("bindings::CXX11", "Engine", - "AllStepsBlocksInfo", + helper::Throw("bindings::CXX11", "Engine", "AllStepsBlocksInfo", "invalid data type"); } return ret; } -#define declare_template_instantiation(T) \ - template void Engine::Put(Variable, const T *, const Mode); \ - template void Engine::Put(const std::string &, const T *, const Mode); \ - template void Engine::Put(Variable, const T &, const Mode); \ - template void Engine::Put(const std::string &, const T &, const Mode); \ - \ - template void Engine::Get(Variable, T *, const Mode); \ - template void Engine::Get(const std::string &, T *, const Mode); \ - template void Engine::Get(Variable, T &, const Mode); \ - template void Engine::Get(const std::string &, T &, const Mode); \ - \ - template void Engine::Get(Variable, std::vector &, const Mode); \ - template void Engine::Get(const std::string &, std::vector &, \ - const Mode); \ - \ - template void Engine::Get( \ - Variable, typename Variable::Info & info, const Mode); \ - template void Engine::Get( \ - const std::string &, typename Variable::Info &info, const Mode); \ - \ - template std::map::Info>> \ - Engine::AllStepsBlocksInfo(const Variable variable) const; \ - \ - template std::vector::Info> Engine::BlocksInfo( \ - const Variable variable, const size_t step) const; \ - \ - template std::vector Engine::GetAbsoluteSteps( \ - const Variable variable) const; +#define declare_template_instantiation(T) \ + template void Engine::Put(Variable, const T *, const Mode); \ + template void Engine::Put(const std::string &, const T *, const Mode); \ + template void Engine::Put(Variable, const T &, const Mode); \ + template void Engine::Put(const std::string &, const T &, const Mode); \ + \ + template void Engine::Get(Variable, T *, const Mode); \ + template void Engine::Get(const std::string &, T *, const Mode); \ + template void Engine::Get(Variable, T &, const Mode); \ + template void Engine::Get(const std::string &, T &, const Mode); \ + \ + template void Engine::Get(Variable, std::vector &, const Mode); \ + template void Engine::Get(const std::string &, std::vector &, const Mode); \ + \ + template void Engine::Get(Variable, typename Variable::Info & info, const Mode); \ + template void Engine::Get(const std::string &, typename Variable::Info &info, \ + const Mode); \ + \ + template std::map::Info>> Engine::AllStepsBlocksInfo( \ + const Variable variable) const; \ + \ + template std::vector::Info> Engine::BlocksInfo( \ + const Variable variable, const size_t step) const; \ + \ + template std::vector Engine::GetAbsoluteSteps(const Variable variable) const; ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation size_t Engine::DebugGetDataBufferSize() const { - helper::CheckForNullptr(m_Engine, - "in call to Engine::DebugGetDataBufferSize"); + helper::CheckForNullptr(m_Engine, "in call to Engine::DebugGetDataBufferSize"); return m_Engine->DebugGetDataBufferSize(); } std::string ToString(const Engine &engine) { - return std::string("Engine(Name: \"" + engine.Name() + "\", Type: \"" + - engine.Type() + "\")"); + return std::string("Engine(Name: \"" + engine.Name() + "\", Type: \"" + engine.Type() + "\")"); } } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/Engine.h b/bindings/CXX11/adios2/cxx11/Engine.h index 1043315e91..533912758a 100644 --- a/bindings/CXX11/adios2/cxx11/Engine.h +++ b/bindings/CXX11/adios2/cxx11/Engine.h @@ -94,8 +94,7 @@ class Engine * @param timeoutSeconds * @return current step status */ - StepStatus BeginStep(const StepMode mode, - const float timeoutSeconds = -1.f); + StepStatus BeginStep(const StepMode mode, const float timeoutSeconds = -1.f); /** * Inspect current logical step @@ -117,8 +116,7 @@ class Engine * @return span to variable data in engine internal buffer */ template - typename Variable::Span Put(Variable variable, const bool initialize, - const T &value); + typename Variable::Span Put(Variable variable, const bool initialize, const T &value); /** * Put signature that provides access to an internal engine buffer (decided @@ -145,11 +143,9 @@ class Engine * @exception std::invalid_argument for invalid variable or nullptr data */ template - void Put(Variable variable, const T *data, - const Mode launch = Mode::Deferred); + void Put(Variable variable, const T *data, const Mode launch = Mode::Deferred); - void Put(VariableNT &variable, const void *data, - const Mode launch = Mode::Deferred); + void Put(VariableNT &variable, const void *data, const Mode launch = Mode::Deferred); /** * Put data associated with a Variable in the Engine @@ -167,8 +163,7 @@ class Engine * @exception std::invalid_argument if variable not found or nullptr data */ template - void Put(const std::string &variableName, const T *data, - const Mode launch = Mode::Deferred); + void Put(const std::string &variableName, const T *data, const Mode launch = Mode::Deferred); /** * Put data associated with a Variable in the Engine @@ -181,12 +176,10 @@ class Engine * @exception std::invalid_argument if variable is invalid or nullptr &datum */ template - void Put(Variable variable, const T &datum, - const Mode launch = Mode::Deferred); + void Put(Variable variable, const T &datum, const Mode launch = Mode::Deferred); -#define declare_type(T) \ - void Put(VariableNT &variable, const T &datum, \ - const Mode launch = Mode::Deferred); +#define declare_type(T) \ + void Put(VariableNT &variable, const T &datum, const Mode launch = Mode::Deferred); ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type @@ -203,8 +196,7 @@ class Engine * @exception std::invalid_argument if variable is invalid or nullptr &datum */ template - void Put(const std::string &variableName, const T &datum, - const Mode launch = Mode::Deferred); + void Put(const std::string &variableName, const T &datum, const Mode launch = Mode::Deferred); /** * The next two Put functions are used to accept a variable, and an @@ -216,10 +208,8 @@ class Engine * always sync */ template >::value>::type> - void Put(Variable variable, U const &data, - const Mode launch = Mode::Deferred) + class = typename std::enable_if>::value>::type> + void Put(Variable variable, U const &data, const Mode launch = Mode::Deferred) { auto bufferView = static_cast>(data); #ifdef ADIOS2_HAVE_GPU_SUPPORT @@ -258,8 +248,7 @@ class Engine template void Get(Variable variable, T *data, const Mode launch = Mode::Deferred); - void Get(VariableNT &variable, void *data, - const Mode launch = Mode::Deferred); + void Get(VariableNT &variable, void *data, const Mode launch = Mode::Deferred); /** * Get data associated with a Variable from the Engine. Overloaded version @@ -281,8 +270,7 @@ class Engine * doesn't exist in IO) or nullptr data */ template - void Get(const std::string &variableName, T *data, - const Mode launch = Mode::Deferred); + void Get(const std::string &variableName, T *data, const Mode launch = Mode::Deferred); /** * Get single value data associated with a Variable from the Engine @@ -294,18 +282,15 @@ class Engine * @exception std::invalid_argument if variable is invalid or nullptr &datum */ template - void Get(Variable variable, T &datum, - const Mode launch = Mode::Deferred); + void Get(Variable variable, T &datum, const Mode launch = Mode::Deferred); -#define declare_type(T) \ - void Get(VariableNT &variable, T &datum, \ - const Mode launch = Mode::Deferred); +#define declare_type(T) \ + void Get(VariableNT &variable, T &datum, const Mode launch = Mode::Deferred); ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type -#define declare_type(T) \ - void Get(VariableNT &variable, std::vector &datum, \ - const Mode launch = Mode::Deferred); +#define declare_type(T) \ + void Get(VariableNT &variable, std::vector &datum, const Mode launch = Mode::Deferred); ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type @@ -321,8 +306,7 @@ class Engine * doesn't exist in IO) or nullptr data */ template - void Get(const std::string &variableName, T &datum, - const Mode launch = Mode::Deferred); + void Get(const std::string &variableName, T &datum, const Mode launch = Mode::Deferred); /** * Get data associated with a Variable from the Engine. @@ -341,8 +325,7 @@ class Engine * @exception std::invalid_argument for invalid variable */ template - void Get(Variable variable, std::vector &dataV, - const Mode launch = Mode::Deferred); + void Get(Variable variable, std::vector &dataV, const Mode launch = Mode::Deferred); /** * Get data associated with a Variable from the Engine. @@ -430,10 +413,8 @@ class Engine * always sync */ template >::value>::type> - void Get(Variable variable, U const &data, - const Mode launch = Mode::Deferred) + class = typename std::enable_if>::value>::type> + void Get(Variable variable, U const &data, const Mode launch = Mode::Deferred) { auto adios_data = static_cast>(data); auto mem_space = adios_data.memory_space(); @@ -499,11 +480,10 @@ class Engine * found it returns an empty vector */ template - std::vector::Info> - BlocksInfo(const Variable variable, const size_t step) const; + std::vector::Info> BlocksInfo(const Variable variable, + const size_t step) const; - std::vector BlocksInfo(const VariableNT &variable, - const size_t step) const; + std::vector BlocksInfo(const VariableNT &variable, const size_t step) const; /** * Get the absolute steps of a variable in a file. This is for diff --git a/bindings/CXX11/adios2/cxx11/Engine.tcc b/bindings/CXX11/adios2/cxx11/Engine.tcc index e7bcebd917..4f4a5962fa 100644 --- a/bindings/CXX11/adios2/cxx11/Engine.tcc +++ b/bindings/CXX11/adios2/cxx11/Engine.tcc @@ -24,16 +24,15 @@ namespace { template static std::vector::Info> -ToBlocksInfo(const std::vector::IOType>::BPInfo> &coreBlocksInfo) +ToBlocksInfo(const std::vector::IOType>::BPInfo> + &coreBlocksInfo) { using IOType = typename TypeInfo::IOType; std::vector::Info> blocksInfo; blocksInfo.reserve(coreBlocksInfo.size()); - for (const typename core::Variable::BPInfo &coreBlockInfo : - coreBlocksInfo) + for (const typename core::Variable::BPInfo &coreBlockInfo : coreBlocksInfo) { typename Variable::Info blockInfo; // doesn't work because coreBlockInfo is transient. @@ -62,20 +61,16 @@ ToBlocksInfo(const std::vector -typename Variable::Span Engine::Put(Variable variable, - const bool initialize, const T &value) +typename Variable::Span Engine::Put(Variable variable, const bool initialize, const T &value) { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr(m_Engine, - "for Engine in call to Engine::Array"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::Array"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Array"); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Array"); typename Variable::Span::CoreSpan *coreSpan = - reinterpret_cast::Span::CoreSpan *>( - &m_Engine->Put(*variable.m_Variable, initialize, - reinterpret_cast(value))); + reinterpret_cast::Span::CoreSpan *>(&m_Engine->Put( + *variable.m_Variable, initialize, reinterpret_cast(value))); return typename Variable::Span(coreSpan); } @@ -83,11 +78,9 @@ typename Variable::Span Engine::Put(Variable variable, template typename Variable::Span Engine::Put(Variable variable) { - adios2::helper::CheckForNullptr(m_Engine, - "for Engine in call to Engine::Array"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::Array"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Array"); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Array"); typename Variable::Span::CoreSpan *coreSpan = reinterpret_cast::Span::CoreSpan *>( @@ -101,15 +94,12 @@ void Engine::Put(Variable variable, const T *data, const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Put"); - m_Engine->Put(*variable.m_Variable, reinterpret_cast(data), - launch); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Put"); + m_Engine->Put(*variable.m_Variable, reinterpret_cast(data), launch); } template -void Engine::Put(const std::string &variableName, const T *data, - const Mode launch) +void Engine::Put(const std::string &variableName, const T *data, const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); @@ -121,20 +111,16 @@ void Engine::Put(Variable variable, const T &datum, const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Put"); - m_Engine->Put(*variable.m_Variable, reinterpret_cast(datum), - launch); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Put"); + m_Engine->Put(*variable.m_Variable, reinterpret_cast(datum), launch); } template -void Engine::Put(const std::string &variableName, const T &datum, - const Mode launch) +void Engine::Put(const std::string &variableName, const T &datum, const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put"); - m_Engine->Put(variableName, reinterpret_cast(datum), - launch); + m_Engine->Put(variableName, reinterpret_cast(datum), launch); } template @@ -142,10 +128,8 @@ void Engine::Get(Variable variable, T *data, const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Get"); - m_Engine->Get(*variable.m_Variable, reinterpret_cast(data), - launch); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Get"); + m_Engine->Get(*variable.m_Variable, reinterpret_cast(data), launch); } template @@ -161,14 +145,12 @@ void Engine::Get(Variable variable, T &datum, const Mode /*launch*/) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Get"); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Get"); m_Engine->Get(*variable.m_Variable, reinterpret_cast(datum)); } template -void Engine::Get(const std::string &variableName, T &datum, - const Mode /*launch*/) +void Engine::Get(const std::string &variableName, T &datum, const Mode /*launch*/) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); @@ -179,39 +161,31 @@ template void Engine::Get(Variable variable, std::vector &dataV, const Mode launch) { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr( - m_Engine, "in call to Engine::Get with std::vector argument"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Get"); - m_Engine->Get(*variable.m_Variable, - reinterpret_cast &>(dataV), launch); + adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get with std::vector argument"); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Get"); + m_Engine->Get(*variable.m_Variable, reinterpret_cast &>(dataV), launch); } template -void Engine::Get(const std::string &variableName, std::vector &dataV, - const Mode launch) +void Engine::Get(const std::string &variableName, std::vector &dataV, const Mode launch) { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr( - m_Engine, "in call to Engine::Get with std::vector argument"); - m_Engine->Get(variableName, reinterpret_cast &>(dataV), - launch); + adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get with std::vector argument"); + m_Engine->Get(variableName, reinterpret_cast &>(dataV), launch); } template -void Engine::Get(Variable variable, typename Variable::Info &info, - const Mode launch) +void Engine::Get(Variable variable, typename Variable::Info &info, const Mode launch) { adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); - adios2::helper::CheckForNullptr(variable.m_Variable, - "for variable in call to Engine::Get"); + adios2::helper::CheckForNullptr(variable.m_Variable, "for variable in call to Engine::Get"); info.m_Info = reinterpret_cast::Info::CoreInfo *>( m_Engine->Get(*variable.m_Variable, launch)); } template -void Engine::Get(const std::string &variableName, - typename Variable::Info &info, const Mode launch) +void Engine::Get(const std::string &variableName, typename Variable::Info &info, + const Mode launch) { using IOType = typename TypeInfo::IOType; adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get"); @@ -224,13 +198,11 @@ void Engine::Get(Variable variable, T **data) const { if (m_Engine->m_EngineType != "InlineReader") { - throw std::domain_error( - "Get calls with T** are only supported with the InlineReader."); + throw std::domain_error("Get calls with T** are only supported with the InlineReader."); } using IOType = typename TypeInfo::IOType; - m_Engine->Get(*variable.m_Variable, - reinterpret_cast(data)); + m_Engine->Get(*variable.m_Variable, reinterpret_cast(data)); return; } @@ -239,12 +211,10 @@ std::map::Info>> Engine::AllStepsBlocksInfo(const Variable variable) const { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr( - m_Engine, "for Engine in call to Engine::AllStepsBlocksInfo"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::AllStepsBlocksInfo"); - adios2::helper::CheckForNullptr( - variable.m_Variable, - "for variable in call to Engine::AllStepsBlocksInfo"); + adios2::helper::CheckForNullptr(variable.m_Variable, + "for variable in call to Engine::AllStepsBlocksInfo"); try { @@ -256,17 +226,14 @@ Engine::AllStepsBlocksInfo(const Variable variable) const } const std::map::BPInfo>> - coreAllStepsBlockInfo = - m_Engine->AllStepsBlocksInfo(*variable.m_Variable); + coreAllStepsBlockInfo = m_Engine->AllStepsBlocksInfo(*variable.m_Variable); - std::map::Info>> - allStepsBlocksInfo; + std::map::Info>> allStepsBlocksInfo; for (const auto &pair : coreAllStepsBlockInfo) { const size_t step = pair.first; - const std::vector::BPInfo> - &coreBlocksInfo = pair.second; + const std::vector::BPInfo> &coreBlocksInfo = pair.second; allStepsBlocksInfo[step] = ToBlocksInfo(coreBlocksInfo); } @@ -280,29 +247,25 @@ Engine::AllStepsBlocksInfo(const Variable variable) const // of the Variable, and those could contain pointers to the Core Info structs, // enabling users of the Inline engine to do Info.Data() template -std::vector::Info> -Engine::BlocksInfo(const Variable variable, const size_t step) const +std::vector::Info> Engine::BlocksInfo(const Variable variable, + const size_t step) const { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr(m_Engine, - "for Engine in call to Engine::BlocksInfo"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::BlocksInfo"); - adios2::helper::CheckForNullptr( - variable.m_Variable, "for variable in call to Engine::BlocksInfo"); + adios2::helper::CheckForNullptr(variable.m_Variable, + "for variable in call to Engine::BlocksInfo"); - const auto minBlocksInfo = - m_Engine->MinBlocksInfo(*variable.m_Variable, step); + const auto minBlocksInfo = m_Engine->MinBlocksInfo(*variable.m_Variable, step); if (minBlocksInfo) { - std::vector::Info> Ret = - variable.ToBlocksInfoMin(minBlocksInfo); + std::vector::Info> Ret = variable.ToBlocksInfoMin(minBlocksInfo); delete minBlocksInfo; return Ret; } - const auto blocksInfo = - m_Engine->BlocksInfo(*variable.m_Variable, step); + const auto blocksInfo = m_Engine->BlocksInfo(*variable.m_Variable, step); return ToBlocksInfo(blocksInfo); } @@ -310,11 +273,9 @@ template std::vector Engine::GetAbsoluteSteps(const Variable variable) const { using IOType = typename TypeInfo::IOType; - adios2::helper::CheckForNullptr( - m_Engine, "for Engine in call to Engine::GetAbsoluteSteps"); - adios2::helper::CheckForNullptr( - variable.m_Variable, - "for variable in call to Engine::GetAbsoluteSteps"); + adios2::helper::CheckForNullptr(m_Engine, "for Engine in call to Engine::GetAbsoluteSteps"); + adios2::helper::CheckForNullptr(variable.m_Variable, + "for variable in call to Engine::GetAbsoluteSteps"); return m_Engine->GetAbsoluteSteps(*variable.m_Variable); } diff --git a/bindings/CXX11/adios2/cxx11/Group.cpp b/bindings/CXX11/adios2/cxx11/Group.cpp index a7220b4c2c..2919602264 100644 --- a/bindings/CXX11/adios2/cxx11/Group.cpp +++ b/bindings/CXX11/adios2/cxx11/Group.cpp @@ -21,18 +21,9 @@ Group Group::InquireGroup(std::string group_name) auto m = m_Group->InquireGroup(group_name); return Group(m); } -std::vector Group::AvailableVariables() -{ - return m_Group->AvailableVariables(); -} -std::vector Group::AvailableAttributes() -{ - return m_Group->AvailableAttributes(); -} -std::vector Group::AvailableGroups() -{ - return m_Group->AvailableGroups(); -} +std::vector Group::AvailableVariables() { return m_Group->AvailableVariables(); } +std::vector Group::AvailableAttributes() { return m_Group->AvailableAttributes(); } +std::vector Group::AvailableGroups() { return m_Group->AvailableGroups(); } std::string Group::InquirePath() { return m_Group->InquirePath(); } @@ -52,7 +43,7 @@ Group::~Group() = default; ; // Explicit declaration of the public template methods // Limits the types -#define declare_template_instantiation(T) \ +#define declare_template_instantiation(T) \ template Variable Group::InquireVariable(const std::string &); ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) diff --git a/bindings/CXX11/adios2/cxx11/Group.h b/bindings/CXX11/adios2/cxx11/Group.h index d54a39b75b..9d08f74c90 100644 --- a/bindings/CXX11/adios2/cxx11/Group.h +++ b/bindings/CXX11/adios2/cxx11/Group.h @@ -96,8 +96,7 @@ class Group * found */ template - Attribute InquireAttribute(const std::string &name, - const std::string &variableName = "", + Attribute InquireAttribute(const std::string &name, const std::string &variableName = "", const std::string separator = "/"); /** diff --git a/bindings/CXX11/adios2/cxx11/Group.tcc b/bindings/CXX11/adios2/cxx11/Group.tcc index 57966c0532..e5d067ac95 100644 --- a/bindings/CXX11/adios2/cxx11/Group.tcc +++ b/bindings/CXX11/adios2/cxx11/Group.tcc @@ -19,22 +19,19 @@ namespace adios2 template Variable Group::InquireVariable(const std::string &name) { - helper::CheckForNullptr(m_Group, "for variable name " + name + - ", in call to Group::InquireVariable"); - return Variable( - m_Group->InquireVariable::IOType>(name)); + helper::CheckForNullptr(m_Group, + "for variable name " + name + ", in call to Group::InquireVariable"); + return Variable(m_Group->InquireVariable::IOType>(name)); } template -Attribute Group::InquireAttribute(const std::string &name, - const std::string &variableName, +Attribute Group::InquireAttribute(const std::string &name, const std::string &variableName, const std::string separator) { using IOType = typename TypeInfo::IOType; - helper::CheckForNullptr(m_Group, "for attribute name " + name + - ", in call to IO::InquireAttribute"); - return Attribute( - m_Group->InquireAttribute(name, variableName, separator)); + helper::CheckForNullptr(m_Group, + "for attribute name " + name + ", in call to IO::InquireAttribute"); + return Attribute(m_Group->InquireAttribute(name, variableName, separator)); } } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/IO.cpp b/bindings/CXX11/adios2/cxx11/IO.cpp index e1eee598b6..8018c06d77 100644 --- a/bindings/CXX11/adios2/cxx11/IO.cpp +++ b/bindings/CXX11/adios2/cxx11/IO.cpp @@ -72,8 +72,8 @@ size_t IO::AddTransport(const std::string type, const Params ¶meters) return m_IO->AddTransport(type, parameters); } -void IO::SetTransportParameter(const size_t transportIndex, - const std::string key, const std::string value) +void IO::SetTransportParameter(const size_t transportIndex, const std::string key, + const std::string value) { helper::CheckForNullptr(m_IO, "in call to IO::SetTransportParameter"); m_IO->SetTransportParameter(transportIndex, key, value); @@ -105,14 +105,10 @@ void IO::RemoveAllAttributes() Engine IO::Open(const std::string &name, const Mode mode) { - helper::CheckForNullptr(m_IO, - "for engine " + name + ", in call to IO::Open"); + helper::CheckForNullptr(m_IO, "for engine " + name + ", in call to IO::Open"); return Engine(&m_IO->Open(name, mode)); } -Group IO::InquireGroup(char delimiter) -{ - return Group(&m_IO->CreateGroup(delimiter)); -}; +Group IO::InquireGroup(char delimiter) { return Group(&m_IO->CreateGroup(delimiter)); }; void IO::FlushAll() { helper::CheckForNullptr(m_IO, "in call to IO::FlushAll"); @@ -132,9 +128,9 @@ std::map IO::AvailableVariables(bool namesOnly) } } -std::map -IO::AvailableAttributes(const std::string &variableName, - const std::string separator, const bool fullNameKeys) +std::map IO::AvailableAttributes(const std::string &variableName, + const std::string separator, + const bool fullNameKeys) { helper::CheckForNullptr(m_IO, "in call to IO::AvailableAttributes"); return m_IO->GetAvailableAttributes(variableName, separator, fullNameKeys); @@ -152,8 +148,8 @@ std::string IO::AttributeType(const std::string &name) const return ToString(m_IO->InquireAttributeType(name)); } -void IO::AddOperation(const std::string &variable, - const std::string &operatorType, const Params ¶meters) +void IO::AddOperation(const std::string &variable, const std::string &operatorType, + const Params ¶meters) { helper::CheckForNullptr(m_IO, "in call to IO::AddOperation"); return m_IO->AddOperation(variable, operatorType, parameters); @@ -165,51 +161,48 @@ std::string IO::EngineType() const return m_IO->m_EngineType; } -VariableNT IO::DefineVariable(const DataType type, const std::string &name, - const Dims &shape, const Dims &start, - const Dims &count, const bool constantDims) +VariableNT IO::DefineVariable(const DataType type, const std::string &name, const Dims &shape, + const Dims &start, const Dims &count, const bool constantDims) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::DefineVariable"); -#define declare_type(T) \ - if (ToString(type) == GetType()) \ - { \ - return VariableNT(&m_IO->DefineVariable::IOType>( \ - name, shape, start, count, constantDims)); \ + helper::CheckForNullptr(m_IO, "for variable name " + name + ", in call to IO::DefineVariable"); +#define declare_type(T) \ + if (ToString(type) == GetType()) \ + { \ + return VariableNT(&m_IO->DefineVariable::IOType>( \ + name, shape, start, count, constantDims)); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type - else { return nullptr; } + else + { + return nullptr; + } } StructDefinition IO::DefineStruct(const std::string &name, const size_t size) { - helper::CheckForNullptr(m_IO, "for struct name " + name + - ", in call to IO::DefineStruct"); + helper::CheckForNullptr(m_IO, "for struct name " + name + ", in call to IO::DefineStruct"); return StructDefinition(&m_IO->DefineStruct(name, size)); } -VariableNT IO::DefineStructVariable(const std::string &name, - const StructDefinition &def, - const Dims &shape, const Dims &start, - const Dims &count, const bool constantDims) +VariableNT IO::DefineStructVariable(const std::string &name, const StructDefinition &def, + const Dims &shape, const Dims &start, const Dims &count, + const bool constantDims) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::DefineStructVariable"); - return VariableNT(&m_IO->DefineStructVariable( - name, *def.m_StructDefinition, shape, start, count, constantDims)); + helper::CheckForNullptr(m_IO, + "for variable name " + name + ", in call to IO::DefineStructVariable"); + return VariableNT(&m_IO->DefineStructVariable(name, *def.m_StructDefinition, shape, start, + count, constantDims)); } VariableNT IO::InquireVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::InquireVariable"); + helper::CheckForNullptr(m_IO, "for variable name " + name + ", in call to IO::InquireVariable"); auto type = m_IO->InquireVariableType(name); -#define declare_type(T) \ - if (type == helper::GetDataType()) \ - { \ - return VariableNT( \ - m_IO->InquireVariable::IOType>(name)); \ +#define declare_type(T) \ + if (type == helper::GetDataType()) \ + { \ + return VariableNT(m_IO->InquireVariable::IOType>(name)); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type @@ -217,25 +210,26 @@ VariableNT IO::InquireVariable(const std::string &name) { return VariableNT(m_IO->InquireStructVariable(name)); } - else { return nullptr; } + else + { + return nullptr; + } } VariableNT IO::InquireStructVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::InquireStructVariable"); + helper::CheckForNullptr(m_IO, + "for variable name " + name + ", in call to IO::InquireStructVariable"); return VariableNT(m_IO->InquireStructVariable(name)); } -VariableNT IO::InquireStructVariable(const std::string &name, - const StructDefinition def) +VariableNT IO::InquireStructVariable(const std::string &name, const StructDefinition def) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::InquireStructVariable"); + helper::CheckForNullptr(m_IO, + "for variable name " + name + ", in call to IO::InquireStructVariable"); - return VariableNT( - m_IO->InquireStructVariable(name, *def.m_StructDefinition)); + return VariableNT(m_IO->InquireStructVariable(name, *def.m_StructDefinition)); } // PRIVATE @@ -243,34 +237,28 @@ IO::IO(core::IO *io) : m_IO(io) {} // Explicit declaration of the public template methods // Limits the types -#define declare_template_instantiation(T) \ - template Variable IO::DefineVariable(const std::string &, const Dims &, \ - const Dims &, const Dims &, \ - const bool); \ - \ +#define declare_template_instantiation(T) \ + template Variable IO::DefineVariable(const std::string &, const Dims &, const Dims &, \ + const Dims &, const bool); \ + \ template Variable IO::InquireVariable(const std::string &); ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation -#define declare_template_instantiation(T) \ - template Attribute IO::DefineAttribute( \ - const std::string &, const T *, const size_t, const std::string &, \ - const std::string, const bool); \ - \ - template Attribute IO::DefineAttribute(const std::string &, const T &, \ - const std::string &, \ - const std::string, const bool); \ - \ - template Attribute IO::InquireAttribute( \ - const std::string &, const std::string &, const std::string); +#define declare_template_instantiation(T) \ + template Attribute IO::DefineAttribute(const std::string &, const T *, const size_t, \ + const std::string &, const std::string, const bool); \ + \ + template Attribute IO::DefineAttribute(const std::string &, const T &, const std::string &, \ + const std::string, const bool); \ + \ + template Attribute IO::InquireAttribute(const std::string &, const std::string &, \ + const std::string); ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation -std::string ToString(const IO &io) -{ - return std::string("IO(Name: \"" + io.Name() + "\")"); -} +std::string ToString(const IO &io) { return std::string("IO(Name: \"" + io.Name() + "\")"); } } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/IO.h b/bindings/CXX11/adios2/cxx11/IO.h index cb8a44a2e9..1702c769f4 100644 --- a/bindings/CXX11/adios2/cxx11/IO.h +++ b/bindings/CXX11/adios2/cxx11/IO.h @@ -134,8 +134,8 @@ class IO * @exception std::invalid_argument if transportIndex not valid, e.g. not a * handler from AddTransport. */ - void SetTransportParameter(const size_t transportIndex, - const std::string key, const std::string value); + void SetTransportParameter(const size_t transportIndex, const std::string key, + const std::string value); /** * Define a Variable object within IO @@ -148,25 +148,19 @@ class IO * @return Variable object */ template - Variable - DefineVariable(const std::string &name, const Dims &shape = Dims(), - const Dims &start = Dims(), const Dims &count = Dims(), - const bool constantDims = false); + Variable DefineVariable(const std::string &name, const Dims &shape = Dims(), + const Dims &start = Dims(), const Dims &count = Dims(), + const bool constantDims = false); VariableNT DefineVariable(const DataType type, const std::string &name, - const Dims &shape = Dims(), - const Dims &start = Dims(), - const Dims &count = Dims(), - const bool constantDims = false); + const Dims &shape = Dims(), const Dims &start = Dims(), + const Dims &count = Dims(), const bool constantDims = false); StructDefinition DefineStruct(const std::string &name, const size_t size); - VariableNT DefineStructVariable(const std::string &name, - const StructDefinition &def, - const Dims &shape = Dims(), - const Dims &start = Dims(), - const Dims &count = Dims(), - const bool constantDims = false); + VariableNT DefineStructVariable(const std::string &name, const StructDefinition &def, + const Dims &shape = Dims(), const Dims &start = Dims(), + const Dims &count = Dims(), const bool constantDims = false); /** * Retrieve a Variable object within current IO object @@ -181,8 +175,7 @@ class IO VariableNT InquireStructVariable(const std::string &name); - VariableNT InquireStructVariable(const std::string &name, - const StructDefinition def); + VariableNT InquireStructVariable(const std::string &name, const StructDefinition def); /** * @brief Define attribute inside io. Array input version @@ -201,8 +194,7 @@ class IO * Variable) is already defined */ template - Attribute DefineAttribute(const std::string &name, const T *data, - const size_t size, + Attribute DefineAttribute(const std::string &name, const T *data, const size_t size, const std::string &variableName = "", const std::string separator = "/", const bool allowModification = false); @@ -223,10 +215,9 @@ class IO * Variable) is already defined */ template - Attribute DefineAttribute(const std::string &name, const T &value, - const std::string &variableName = "", - const std::string separator = "/", - const bool allowModification = false); + Attribute + DefineAttribute(const std::string &name, const T &value, const std::string &variableName = "", + const std::string separator = "/", const bool allowModification = false); /** * @brief Retrieve an existing attribute @@ -241,8 +232,7 @@ class IO * Attribute is not found */ template - Attribute InquireAttribute(const std::string &name, - const std::string &variableName = "", + Attribute InquireAttribute(const std::string &name, const std::string &variableName = "", const std::string separator = "/"); /** @@ -342,10 +332,9 @@ class IO * string value: attribute info value * */ - std::map - AvailableAttributes(const std::string &variableName = "", - const std::string separator = "/", - const bool fullNameKeys = false); + std::map AvailableAttributes(const std::string &variableName = "", + const std::string separator = "/", + const bool fullNameKeys = false); /** * Inspects variable type. This function can be used in conjunction with @@ -372,8 +361,7 @@ class IO * @param parameters key/value settings particular to the IO, not to * be confused by op own parameters */ - void AddOperation(const std::string &variable, - const std::string &operatorType, + void AddOperation(const std::string &variable, const std::string &operatorType, const Params ¶meters = Params()); /** diff --git a/bindings/CXX11/adios2/cxx11/IO.tcc b/bindings/CXX11/adios2/cxx11/IO.tcc index ede52d25d6..aad6912dc9 100644 --- a/bindings/CXX11/adios2/cxx11/IO.tcc +++ b/bindings/CXX11/adios2/cxx11/IO.tcc @@ -18,64 +18,53 @@ namespace adios2 { template -Variable IO::DefineVariable(const std::string &name, const Dims &shape, - const Dims &start, const Dims &count, - const bool constantDims) +Variable IO::DefineVariable(const std::string &name, const Dims &shape, const Dims &start, + const Dims &count, const bool constantDims) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::DefineVariable"); - return Variable(&m_IO->DefineVariable::IOType>( - name, shape, start, count, constantDims)); + helper::CheckForNullptr(m_IO, "for variable name " + name + ", in call to IO::DefineVariable"); + return Variable(&m_IO->DefineVariable::IOType>(name, shape, start, + count, constantDims)); } template Variable IO::InquireVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable name " + name + - ", in call to IO::InquireVariable"); - return Variable( - m_IO->InquireVariable::IOType>(name)); + helper::CheckForNullptr(m_IO, "for variable name " + name + ", in call to IO::InquireVariable"); + return Variable(m_IO->InquireVariable::IOType>(name)); } template -Attribute -IO::DefineAttribute(const std::string &name, const T *data, const size_t size, - const std::string &variableName, - const std::string separator, const bool allowModification) +Attribute IO::DefineAttribute(const std::string &name, const T *data, const size_t size, + const std::string &variableName, const std::string separator, + const bool allowModification) { using IOType = typename TypeInfo::IOType; - helper::CheckForNullptr(m_IO, "for attribute name " + name + - " and variable name " + variableName + - ", in call to IO::DefineAttribute"); - return Attribute(&m_IO->DefineAttribute( - name, reinterpret_cast(data), size, variableName, - separator, allowModification)); + helper::CheckForNullptr(m_IO, "for attribute name " + name + " and variable name " + + variableName + ", in call to IO::DefineAttribute"); + return Attribute(&m_IO->DefineAttribute(name, reinterpret_cast(data), size, + variableName, separator, allowModification)); } template Attribute IO::DefineAttribute(const std::string &name, const T &value, - const std::string &variableName, - const std::string separator, + const std::string &variableName, const std::string separator, const bool allowModification) { using IOType = typename TypeInfo::IOType; - helper::CheckForNullptr(m_IO, "for attribute name " + name + - ", in call to IO::DefineAttribute"); - return Attribute( - &m_IO->DefineAttribute(name, reinterpret_cast(value), - variableName, separator, allowModification)); + helper::CheckForNullptr(m_IO, + "for attribute name " + name + ", in call to IO::DefineAttribute"); + return Attribute(&m_IO->DefineAttribute(name, reinterpret_cast(value), + variableName, separator, allowModification)); } template -Attribute IO::InquireAttribute(const std::string &name, - const std::string &variableName, +Attribute IO::InquireAttribute(const std::string &name, const std::string &variableName, const std::string separator) { using IOType = typename TypeInfo::IOType; - helper::CheckForNullptr(m_IO, "for attribute name " + name + - ", in call to IO::InquireAttribute"); - return Attribute( - m_IO->InquireAttribute(name, variableName, separator)); + helper::CheckForNullptr(m_IO, + "for attribute name " + name + ", in call to IO::InquireAttribute"); + return Attribute(m_IO->InquireAttribute(name, variableName, separator)); } } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/IOMPI.cpp b/bindings/CXX11/adios2/cxx11/IOMPI.cpp index 2baa4935ff..68cf7ed863 100644 --- a/bindings/CXX11/adios2/cxx11/IOMPI.cpp +++ b/bindings/CXX11/adios2/cxx11/IOMPI.cpp @@ -16,8 +16,7 @@ namespace adios2 Engine IO::Open(const std::string &name, const Mode mode, MPI_Comm comm) { - helper::CheckForNullptr(m_IO, - "for engine " + name + ", in call to IO::Open"); + helper::CheckForNullptr(m_IO, "for engine " + name + ", in call to IO::Open"); return Engine(&m_IO->Open(name, mode, helper::CommDupMPI(comm))); } diff --git a/bindings/CXX11/adios2/cxx11/KokkosView.h b/bindings/CXX11/adios2/cxx11/KokkosView.h index e83560bd14..20fa32ae03 100644 --- a/bindings/CXX11/adios2/cxx11/KokkosView.h +++ b/bindings/CXX11/adios2/cxx11/KokkosView.h @@ -42,8 +42,8 @@ class AdiosView> AdiosView(Kokkos::View v) { pointer = v.data(); - mem_space = detail::memspace_kokkos_to_adios2< - typename Kokkos::View::memory_space>::value; + mem_space = + detail::memspace_kokkos_to_adios2::memory_space>::value; } data_type const *data() const { return pointer; } diff --git a/bindings/CXX11/adios2/cxx11/Operator.cpp b/bindings/CXX11/adios2/cxx11/Operator.cpp index 46931280e6..80169466a3 100644 --- a/bindings/CXX11/adios2/cxx11/Operator.cpp +++ b/bindings/CXX11/adios2/cxx11/Operator.cpp @@ -33,9 +33,6 @@ Params &Operator::Parameters() const } // PRIVATE -Operator::Operator(const std::string &type, Params *params) -: m_Parameters(params), m_Type(type) -{ -} +Operator::Operator(const std::string &type, Params *params) : m_Parameters(params), m_Type(type) {} } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/Query.cpp b/bindings/CXX11/adios2/cxx11/Query.cpp index 73acb3a149..099b68a818 100644 --- a/bindings/CXX11/adios2/cxx11/Query.cpp +++ b/bindings/CXX11/adios2/cxx11/Query.cpp @@ -7,19 +7,29 @@ namespace adios2 { QueryWorker::QueryWorker(const std::string &configFile, adios2::Engine &reader) { - adios2::query::Worker *m = - adios2::query::GetWorker(configFile, reader.m_Engine); + adios2::query::Worker *m = adios2::query::GetWorker(configFile, reader.m_Engine); if (m == nullptr) throw std::invalid_argument("ERROR: unable to construct query. "); m_Worker = std::make_shared(std::move(*m)); delete m; } -void QueryWorker::GetResultCoverage( - adios2::Box &outputSelection, - std::vector> &touched_blocks) +void QueryWorker::GetResultCoverage(std::vector &touched_blockIDs) +{ + m_Worker->GetResultCoverage(touched_blockIDs); +} + +void QueryWorker::GetResultCoverage(std::vector> &touched_blocks) +{ + adios2::Box empty; + GetResultCoverage(empty, touched_blocks); +} + +void QueryWorker::GetResultCoverage(const adios2::Box &outputSelection, + std::vector> &touched_blocks) { if (m_Worker) return m_Worker->GetResultCoverage(outputSelection, touched_blocks); } -} + +} // namespace diff --git a/bindings/CXX11/adios2/cxx11/Query.h b/bindings/CXX11/adios2/cxx11/Query.h index 0872124aa9..0cd5750bbf 100644 --- a/bindings/CXX11/adios2/cxx11/Query.h +++ b/bindings/CXX11/adios2/cxx11/Query.h @@ -26,11 +26,17 @@ class Worker; class QueryWorker { public: + // configFile has query, can be either xml or json QueryWorker(const std::string &configFile, adios2::Engine &engine); - void - GetResultCoverage(adios2::Box &, - std::vector> &touched_blocks); + void GetResultCoverage(std::vector &touched_block_ids); + // touched_blocks is a list of regions specified by (start, count), + // that contains data that satisfies the query file + void GetResultCoverage(std::vector> &touched_blocks); + + // supply output bound for the results + void GetResultCoverage(const adios2::Box &, + std::vector> &touched_blocks); private: std::shared_ptr m_Worker; diff --git a/bindings/CXX11/adios2/cxx11/Types.cpp b/bindings/CXX11/adios2/cxx11/Types.cpp index 9303e8a6a6..6d3beaed5b 100644 --- a/bindings/CXX11/adios2/cxx11/Types.cpp +++ b/bindings/CXX11/adios2/cxx11/Types.cpp @@ -13,8 +13,7 @@ namespace adios2 { -#define declare_template_instantiation(T) \ - template std::string GetType() noexcept; +#define declare_template_instantiation(T) template std::string GetType() noexcept; ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/adios2/cxx11/Variable.cpp b/bindings/CXX11/adios2/cxx11/Variable.cpp index b58d92a517..cc1944fae9 100644 --- a/bindings/CXX11/adios2/cxx11/Variable.cpp +++ b/bindings/CXX11/adios2/cxx11/Variable.cpp @@ -17,254 +17,234 @@ namespace adios2 { -#define declare_type(T) \ - \ - template <> \ - Variable::Variable(core::Variable *variable) \ - : m_Variable(variable) \ - { \ - } \ - \ - template <> \ - Variable::operator bool() const noexcept \ - { \ - return (m_Variable == nullptr) ? false : true; \ - } \ - \ - template <> \ - void Variable::SetMemorySpace(const MemorySpace mem) \ - { \ - m_Variable->SetMemorySpace(mem); \ - } \ - \ - template <> \ - MemorySpace Variable::GetMemorySpace() \ - { \ - return m_Variable->m_MemSpace; \ - } \ - \ - template <> \ - void Variable::SetShape(const Dims &shape) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetShape"); \ - m_Variable->SetShape(shape); \ - } \ - \ - template <> \ - void Variable::SetBlockSelection(const size_t blockID) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetBlockSelection"); \ - m_Variable->SetBlockSelection(blockID); \ - } \ - \ - template <> \ - void Variable::SetSelection(const Box &selection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetSelection"); \ - m_Variable->SetSelection(selection); \ - } \ - \ - template <> \ - void Variable::SetMemorySelection(const Box &memorySelection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetMemorySelection"); \ - m_Variable->SetMemorySelection(memorySelection); \ - } \ - \ - template <> \ - void Variable::SetStepSelection(const Box &stepSelection) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SetStepSelection"); \ - m_Variable->SetStepSelection(stepSelection); \ - } \ - \ - template <> \ - size_t Variable::SelectionSize() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::SelectionSize"); \ - return m_Variable->SelectionSize(); \ - } \ - \ - template <> \ - std::string Variable::Name() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Name"); \ - return m_Variable->m_Name; \ - } \ - \ - template <> \ - std::string Variable::Type() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Type"); \ - return ToString(m_Variable->m_Type); \ - } \ - template <> \ - size_t Variable::Sizeof() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Sizeof"); \ - return m_Variable->m_ElementSize; \ - } \ - \ - template <> \ - adios2::ShapeID Variable::ShapeID() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::ShapeID"); \ - return m_Variable->m_ShapeID; \ - } \ - \ - template <> \ - Dims Variable::Shape(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Shape"); \ - return m_Variable->Shape(step); \ - } \ - \ - template <> \ - Dims Variable::Start() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Start"); \ - return m_Variable->m_Start; \ - } \ - \ - template <> \ - Dims Variable::Count() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Count"); \ - return m_Variable->Count(); \ - } \ - \ - template <> \ - size_t Variable::Steps() const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Steps"); \ - return m_Variable->m_AvailableStepsCount; \ - } \ - \ - template <> \ - size_t Variable::StepsStart() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::StepsStart"); \ - return m_Variable->m_AvailableStepsStart; \ - } \ - \ - template <> \ - size_t Variable::BlockID() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::BlockID"); \ - return m_Variable->m_BlockID; \ - } \ - \ - template <> \ - size_t Variable::AddOperation(const Operator op, \ - const Params ¶meters) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::AddOperation"); \ - if (!op) \ - { \ - throw std::invalid_argument("ERROR: invalid operator, in call to " \ - "Variable::AddOperation"); \ - } \ - auto params = op.Parameters(); \ - for (const auto &p : parameters) \ - { \ - params[p.first] = p.second; \ - } \ - return m_Variable->AddOperation(op.m_Type, params); \ - } \ - \ - template <> \ - size_t Variable::AddOperation(const std::string &type, \ - const Params ¶meters) \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::AddOperation"); \ - return m_Variable->AddOperation(type, parameters); \ - } \ - \ - template <> \ - std::vector Variable::Operations() const \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::Operations"); \ - std::vector operations; \ - operations.reserve(m_Variable->m_Operations.size()); \ - for (const auto &op : m_Variable->m_Operations) \ - { \ - operations.push_back( \ - Operator(op->m_TypeString, &op->GetParameters())); \ - } \ - return operations; \ - } \ - \ - template <> \ - void Variable::RemoveOperations() \ - { \ - helper::CheckForNullptr(m_Variable, \ - "in call to Variable::RemoveOperations"); \ - m_Variable->RemoveOperations(); \ - } \ - \ - template <> \ - std::pair Variable::MinMax(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::MinMax"); \ - return m_Variable->MinMax(step); \ - } \ - \ - template <> \ - T Variable::Min(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Min"); \ - return m_Variable->Min(step); \ - } \ - \ - template <> \ - T Variable::Max(const size_t step) const \ - { \ - helper::CheckForNullptr(m_Variable, "in call to Variable::Max"); \ - return m_Variable->Max(step); \ - } \ - \ - template <> \ - std::vector::Info>> \ - Variable::AllStepsBlocksInfo() \ - { \ - return DoAllStepsBlocksInfo(); \ - } \ - \ - template <> \ - std::map::Info>> \ - Variable::AllStepsBlocksInfoMap() const \ - { \ - return DoAllStepsBlocksInfoMap(); \ - } \ - \ - template <> \ - const T *Variable::Info::Data() const \ - { \ - const core::Variable::BPInfo *coreInfo = \ - reinterpret_cast::BPInfo *>(m_Info); \ - \ - return m_Info ? (coreInfo->BufferP ? coreInfo->BufferP \ - : coreInfo->BufferV.data()) \ - : nullptr; \ +#define declare_type(T) \ + \ + template <> \ + Variable::Variable(core::Variable *variable) : m_Variable(variable) \ + { \ + } \ + \ + template <> \ + Variable::operator bool() const noexcept \ + { \ + return (m_Variable == nullptr) ? false : true; \ + } \ + \ + template <> \ + void Variable::SetMemorySpace(const MemorySpace mem) \ + { \ + m_Variable->SetMemorySpace(mem); \ + } \ + \ + template <> \ + MemorySpace Variable::GetMemorySpace() \ + { \ + return m_Variable->m_MemSpace; \ + } \ + \ + template <> \ + void Variable::SetShape(const Dims &shape) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetShape"); \ + m_Variable->SetShape(shape); \ + } \ + \ + template <> \ + void Variable::SetBlockSelection(const size_t blockID) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetBlockSelection"); \ + m_Variable->SetBlockSelection(blockID); \ + } \ + \ + template <> \ + void Variable::SetSelection(const Box &selection) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetSelection"); \ + m_Variable->SetSelection(selection); \ + } \ + \ + template <> \ + void Variable::SetMemorySelection(const Box &memorySelection) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetMemorySelection"); \ + m_Variable->SetMemorySelection(memorySelection); \ + } \ + \ + template <> \ + void Variable::SetStepSelection(const Box &stepSelection) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SetStepSelection"); \ + m_Variable->SetStepSelection(stepSelection); \ + } \ + \ + template <> \ + size_t Variable::SelectionSize() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::SelectionSize"); \ + return m_Variable->SelectionSize(); \ + } \ + \ + template <> \ + std::string Variable::Name() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Name"); \ + return m_Variable->m_Name; \ + } \ + \ + template <> \ + std::string Variable::Type() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Type"); \ + return ToString(m_Variable->m_Type); \ + } \ + template <> \ + size_t Variable::Sizeof() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Sizeof"); \ + return m_Variable->m_ElementSize; \ + } \ + \ + template <> \ + adios2::ShapeID Variable::ShapeID() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::ShapeID"); \ + return m_Variable->m_ShapeID; \ + } \ + \ + template <> \ + Dims Variable::Shape(const size_t step) const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Shape"); \ + return m_Variable->Shape(step); \ + } \ + \ + template <> \ + Dims Variable::Start() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Start"); \ + return m_Variable->m_Start; \ + } \ + \ + template <> \ + Dims Variable::Count() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Count"); \ + return m_Variable->Count(); \ + } \ + \ + template <> \ + size_t Variable::Steps() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Steps"); \ + return m_Variable->m_AvailableStepsCount; \ + } \ + \ + template <> \ + size_t Variable::StepsStart() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::StepsStart"); \ + return m_Variable->m_AvailableStepsStart; \ + } \ + \ + template <> \ + size_t Variable::BlockID() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::BlockID"); \ + return m_Variable->m_BlockID; \ + } \ + \ + template <> \ + size_t Variable::AddOperation(const Operator op, const Params ¶meters) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::AddOperation"); \ + if (!op) \ + { \ + throw std::invalid_argument("ERROR: invalid operator, in call to " \ + "Variable::AddOperation"); \ + } \ + auto params = op.Parameters(); \ + for (const auto &p : parameters) \ + { \ + params[p.first] = p.second; \ + } \ + return m_Variable->AddOperation(op.m_Type, params); \ + } \ + \ + template <> \ + size_t Variable::AddOperation(const std::string &type, const Params ¶meters) \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::AddOperation"); \ + return m_Variable->AddOperation(type, parameters); \ + } \ + \ + template <> \ + std::vector Variable::Operations() const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Operations"); \ + std::vector operations; \ + operations.reserve(m_Variable->m_Operations.size()); \ + for (const auto &op : m_Variable->m_Operations) \ + { \ + operations.push_back(Operator(op->m_TypeString, &op->GetParameters())); \ + } \ + return operations; \ + } \ + \ + template <> \ + void Variable::RemoveOperations() \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::RemoveOperations"); \ + m_Variable->RemoveOperations(); \ + } \ + \ + template <> \ + std::pair Variable::MinMax(const size_t step) const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::MinMax"); \ + return m_Variable->MinMax(step); \ + } \ + \ + template <> \ + T Variable::Min(const size_t step) const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Min"); \ + return m_Variable->Min(step); \ + } \ + \ + template <> \ + T Variable::Max(const size_t step) const \ + { \ + helper::CheckForNullptr(m_Variable, "in call to Variable::Max"); \ + return m_Variable->Max(step); \ + } \ + \ + template <> \ + std::vector::Info>> Variable::AllStepsBlocksInfo() \ + { \ + return DoAllStepsBlocksInfo(); \ + } \ + \ + template <> \ + std::map::Info>> Variable::AllStepsBlocksInfoMap() \ + const \ + { \ + return DoAllStepsBlocksInfoMap(); \ + } \ + \ + template <> \ + const T *Variable::Info::Data() const \ + { \ + const core::Variable::BPInfo *coreInfo = \ + reinterpret_cast::BPInfo *>(m_Info); \ + \ + return m_Info ? (coreInfo->BufferP ? coreInfo->BufferP : coreInfo->BufferV.data()) \ + : nullptr; \ } ADIOS2_FOREACH_TYPE_1ARG(declare_type) #undef declare_type -#define declare_template_instantiation(T) \ - template std::string ToString(const Variable &var); +#define declare_template_instantiation(T) template std::string ToString(const Variable &var); ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -272,9 +252,9 @@ ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation -#define declare_template_instantiation(T) \ - template std::vector::Info> \ - Variable::ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const; +#define declare_template_instantiation(T) \ + template std::vector::Info> Variable::ToBlocksInfoMin( \ + const MinVarInfo *coreVarInfo) const; ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/adios2/cxx11/Variable.h b/bindings/CXX11/adios2/cxx11/Variable.h index 5cf2fb0d9e..398d001667 100644 --- a/bindings/CXX11/adios2/cxx11/Variable.h +++ b/bindings/CXX11/adios2/cxx11/Variable.h @@ -288,8 +288,7 @@ class Variable * be confused by op own parameters * @return operation index handler in Operations() */ - size_t AddOperation(const Operator op, - const adios2::Params ¶meters = adios2::Params()); + size_t AddOperation(const Operator op, const adios2::Params ¶meters = adios2::Params()); size_t AddOperation(const std::string &type, const adios2::Params ¶meters = adios2::Params()); @@ -384,22 +383,19 @@ class Variable /** */ - std::map::Info>> - AllStepsBlocksInfoMap() const; + std::map::Info>> AllStepsBlocksInfoMap() const; using Span = adios2::detail::Span; private: core::Variable *m_Variable = nullptr; - std::vector::Info> - ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const; + std::vector::Info> ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const; Variable(core::Variable *variable); std::vector::Info>> DoAllStepsBlocksInfo(); - std::map::Info>> - DoAllStepsBlocksInfoMap() const; + std::map::Info>> DoAllStepsBlocksInfoMap() const; }; template diff --git a/bindings/CXX11/adios2/cxx11/Variable.tcc b/bindings/CXX11/adios2/cxx11/Variable.tcc index a776cde227..cb212e3a61 100644 --- a/bindings/CXX11/adios2/cxx11/Variable.tcc +++ b/bindings/CXX11/adios2/cxx11/Variable.tcc @@ -24,16 +24,15 @@ namespace template std::vector::Info> -ToBlocksInfo(const std::vector::IOType>::BPInfo> &coreBlocksInfo) +ToBlocksInfo(const std::vector::IOType>::BPInfo> + &coreBlocksInfo) { using IOType = typename TypeInfo::IOType; std::vector::Info> blocksInfo; blocksInfo.reserve(coreBlocksInfo.size()); - for (const typename core::Variable::BPInfo &coreBlockInfo : - coreBlocksInfo) + for (const typename core::Variable::BPInfo &coreBlockInfo : coreBlocksInfo) { typename Variable::Info blockInfo; blockInfo.Start = coreBlockInfo.Start; @@ -70,8 +69,7 @@ Variable::DoAllStepsBlocksInfoMap() const minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo(*m_Variable, 0); if (!minBlocksInfo) throw std::logic_error("not implemented"); - std::map::Info>> - allStepsBlocksInfo; + std::map::Info>> allStepsBlocksInfo; size_t gotCount = 1; size_t curStep = 1; @@ -79,12 +77,10 @@ Variable::DoAllStepsBlocksInfoMap() const delete (minBlocksInfo); while (gotCount < m_Variable->m_AvailableStepsCount) { - minBlocksInfo = - m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep); + minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep); if (minBlocksInfo) { - allStepsBlocksInfo.insert( - {curStep, ToBlocksInfoMin(minBlocksInfo)}); + allStepsBlocksInfo.insert({curStep, ToBlocksInfoMin(minBlocksInfo)}); delete (minBlocksInfo); gotCount++; } @@ -94,21 +90,18 @@ Variable::DoAllStepsBlocksInfoMap() const } template -std::vector::Info>> -Variable::DoAllStepsBlocksInfo() +std::vector::Info>> Variable::DoAllStepsBlocksInfo() { - helper::CheckForNullptr(m_Variable, - "in call to Variable::AllStepsBlocksInfo"); + helper::CheckForNullptr(m_Variable, "in call to Variable::AllStepsBlocksInfo"); MinVarInfo *minBlocksInfo = nullptr; if (m_Variable->m_Engine) { - minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo( - *m_Variable, m_Variable->m_AvailableStepsStart); + minBlocksInfo = + m_Variable->m_Engine->MinBlocksInfo(*m_Variable, m_Variable->m_AvailableStepsStart); if (minBlocksInfo) { - std::vector::Info>> - allStepsBlocksInfo; + std::vector::Info>> allStepsBlocksInfo; // PUBLIC OUTPUT size_t gotCount = 1; size_t curStep = m_Variable->m_AvailableStepsStart + 1; @@ -116,12 +109,10 @@ Variable::DoAllStepsBlocksInfo() delete (minBlocksInfo); while (gotCount < m_Variable->m_AvailableStepsCount) { - minBlocksInfo = - m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep); + minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep); if (minBlocksInfo) { - allStepsBlocksInfo.push_back( - ToBlocksInfoMin(minBlocksInfo)); + allStepsBlocksInfo.push_back(ToBlocksInfoMin(minBlocksInfo)); delete (minBlocksInfo); gotCount++; } @@ -132,8 +123,8 @@ Variable::DoAllStepsBlocksInfo() } // PRIVATE INPUT - const std::vector::BPInfo>> - coreAllStepsBlocksInfo = m_Variable->AllStepsBlocksInfo(); + const std::vector::BPInfo>> coreAllStepsBlocksInfo = + m_Variable->AllStepsBlocksInfo(); // PUBLIC OUTPUT std::vector::Info>> allStepsBlocksInfo( @@ -221,8 +212,7 @@ Variable::ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const template std::string ToString(const Variable &variable) { - return std::string("Variable<") + variable.Type() + ">(Name: \"" + - variable.Name() + "\")"; + return std::string("Variable<") + variable.Type() + ">(Name: \"" + variable.Name() + "\")"; } namespace detail diff --git a/bindings/CXX11/adios2/cxx11/VariableNT.cpp b/bindings/CXX11/adios2/cxx11/VariableNT.cpp index 066da5c9f2..a69ece133f 100644 --- a/bindings/CXX11/adios2/cxx11/VariableNT.cpp +++ b/bindings/CXX11/adios2/cxx11/VariableNT.cpp @@ -16,68 +16,56 @@ namespace adios2 { -StructDefinition::StructDefinition(core::StructDefinition *ptr) -: m_StructDefinition(ptr) -{ -} +StructDefinition::StructDefinition(core::StructDefinition *ptr) : m_StructDefinition(ptr) {} -void StructDefinition::AddField(const std::string &name, const size_t offset, - const DataType type, const size_t size) +void StructDefinition::AddField(const std::string &name, const size_t offset, const DataType type, + const size_t size) { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::AddField"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::AddField"); m_StructDefinition->AddField(name, offset, type, size); } void StructDefinition::Freeze() noexcept { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::Freeze"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::Freeze"); m_StructDefinition->Freeze(); } size_t StructDefinition::StructSize() const noexcept { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::StructSize"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::StructSize"); return m_StructDefinition->StructSize(); } std::string StructDefinition::StructName() const noexcept { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::StructName"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::StructName"); return m_StructDefinition->StructName(); } size_t StructDefinition::Fields() const noexcept { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::Fields"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::Fields"); return m_StructDefinition->Fields(); } std::string StructDefinition::Name(const size_t index) const { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::Name"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::Name"); return m_StructDefinition->Name(index); } size_t StructDefinition::Offset(const size_t index) const { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::Offset"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::Offset"); return m_StructDefinition->Offset(index); } DataType StructDefinition::Type(const size_t index) const { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::Type"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::Type"); return m_StructDefinition->Type(index); } size_t StructDefinition::ElementCount(const size_t index) const { - helper::CheckForNullptr(m_StructDefinition, - "in call to StructDefinition::ElementCount"); + helper::CheckForNullptr(m_StructDefinition, "in call to StructDefinition::ElementCount"); return m_StructDefinition->ElementCount(index); } @@ -87,8 +75,7 @@ VariableNT::operator bool() const noexcept { return m_Variable != nullptr; } void VariableNT::SetMemorySpace(const MemorySpace mem) { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::SetMemorySpace"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::SetMemorySpace"); m_Variable->SetMemorySpace(mem); } @@ -100,8 +87,7 @@ void VariableNT::SetShape(const Dims &shape) void VariableNT::SetBlockSelection(const size_t blockID) { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::SetBlockSelection"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::SetBlockSelection"); m_Variable->SetBlockSelection(blockID); } @@ -113,15 +99,13 @@ void VariableNT::SetSelection(const Box &selection) void VariableNT::SetMemorySelection(const Box &memorySelection) { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::SetMemorySelection"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::SetMemorySelection"); m_Variable->SetMemorySelection(memorySelection); } void VariableNT::SetStepSelection(const Box &stepSelection) { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::SetStepSelection"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::SetStepSelection"); m_Variable->SetStepSelection(stepSelection); } @@ -129,16 +113,14 @@ size_t VariableNT::SelectionSize() const { helper::CheckForNullptr(m_Variable, "in call to VariableNT::SelectionSize"); auto type = ToString(m_Variable->m_Type); -#define declare_type(T) \ - if (type == GetType()) \ - { \ - return reinterpret_cast *>(m_Variable) \ - ->SelectionSize(); \ +#define declare_type(T) \ + if (type == GetType()) \ + { \ + return reinterpret_cast *>(m_Variable)->SelectionSize(); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type - helper::Throw("bindings::CXX11", "VariableNT", - "SelectionSize", + helper::Throw("bindings::CXX11", "VariableNT", "SelectionSize", "invalid data type " + type); return 0; } @@ -183,10 +165,10 @@ Dims VariableNT::Count() const { helper::CheckForNullptr(m_Variable, "in call to VariableNT::Count"); auto type = m_Variable->m_Type; -#define declare_type(T) \ - if (type == helper::GetDataType()) \ - { \ - return reinterpret_cast *>(m_Variable)->Count(); \ +#define declare_type(T) \ + if (type == helper::GetDataType()) \ + { \ + return reinterpret_cast *>(m_Variable)->Count(); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type @@ -222,8 +204,7 @@ size_t VariableNT::AddOperation(const Operator op, const Params ¶meters) helper::CheckForNullptr(m_Variable, "in call to VariableNT::AddOperation"); if (!op) { - helper::Throw("bindings::CXX11", "VariableNT", - "AddOperation", + helper::Throw("bindings::CXX11", "VariableNT", "AddOperation", "invalid operation"); } auto params = op.Parameters(); @@ -234,8 +215,7 @@ size_t VariableNT::AddOperation(const Operator op, const Params ¶meters) return m_Variable->AddOperation(op.m_Type, params); } -size_t VariableNT::AddOperation(const std::string &type, - const Params ¶meters) +size_t VariableNT::AddOperation(const std::string &type, const Params ¶meters) { helper::CheckForNullptr(m_Variable, "in call to VariableNT::AddOperation"); return m_Variable->AddOperation(type, parameters); @@ -255,8 +235,7 @@ std::vector VariableNT::Operations() const void VariableNT::RemoveOperations() { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::RemoveOperations"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::RemoveOperations"); m_Variable->RemoveOperations(); } @@ -265,13 +244,11 @@ size_t VariableNT::StructFields() const helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFields"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFields", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", "StructFields", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - if (reinterpret_cast(m_Variable) - ->m_ReadStructDefinition) + if (reinterpret_cast(m_Variable)->m_ReadStructDefinition) return reinterpret_cast(m_Variable) ->m_ReadStructDefinition->Fields(); else @@ -280,17 +257,14 @@ size_t VariableNT::StructFields() const } std::string VariableNT::StructFieldName(const size_t index) const { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldName"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldName"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldName", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", "StructFieldName", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - if (reinterpret_cast(m_Variable) - ->m_ReadStructDefinition) + if (reinterpret_cast(m_Variable)->m_ReadStructDefinition) return reinterpret_cast(m_Variable) ->m_ReadStructDefinition->Name(index); else @@ -299,17 +273,14 @@ std::string VariableNT::StructFieldName(const size_t index) const } size_t VariableNT::StructFieldOffset(const size_t index) const { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldOffset"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldOffset"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldOffset", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", "StructFieldOffset", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - if (reinterpret_cast(m_Variable) - ->m_ReadStructDefinition) + if (reinterpret_cast(m_Variable)->m_ReadStructDefinition) return reinterpret_cast(m_Variable) ->m_ReadStructDefinition->Offset(index); else @@ -318,17 +289,14 @@ size_t VariableNT::StructFieldOffset(const size_t index) const } DataType VariableNT::StructFieldType(const size_t index) const { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldType"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldType"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldType", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", "StructFieldType", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - if (reinterpret_cast(m_Variable) - ->m_ReadStructDefinition) + if (reinterpret_cast(m_Variable)->m_ReadStructDefinition) return reinterpret_cast(m_Variable) ->m_ReadStructDefinition->Type(index); else @@ -337,17 +305,15 @@ DataType VariableNT::StructFieldType(const size_t index) const } size_t VariableNT::StructFieldElementCount(const size_t index) const { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldElementCount"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldElementCount"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldElementCount", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", + "StructFieldElementCount", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - if (reinterpret_cast(m_Variable) - ->m_ReadStructDefinition) + if (reinterpret_cast(m_Variable)->m_ReadStructDefinition) return reinterpret_cast(m_Variable) ->m_ReadStructDefinition->ElementCount(index); else @@ -355,8 +321,7 @@ size_t VariableNT::StructFieldElementCount(const size_t index) const ->m_WriteStructDefinition->ElementCount(index); } -std::pair -VariableNT::MinMax(const size_t step) const +std::pair VariableNT::MinMax(const size_t step) const { helper::CheckForNullptr(m_Variable, "in call to VariableNT::MinMax"); return {Min(step), Max(step)}; @@ -368,77 +333,66 @@ VariableNT::T VariableNT::Min(const size_t step) const if (m_Variable->m_Type == DataType::Int8) { VariableNT::T ret = {0}; - ret.Int8 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Int8 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::UInt8) { VariableNT::T ret = {0}; - ret.UInt8 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.UInt8 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::Int16) { VariableNT::T ret = {0}; - ret.Int16 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Int16 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::UInt16) { VariableNT::T ret = {0}; - ret.UInt16 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.UInt16 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::Int32) { VariableNT::T ret = {0}; - ret.Int32 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Int32 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::UInt32) { VariableNT::T ret = {0}; - ret.UInt32 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.UInt32 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::Int64) { VariableNT::T ret = {0}; - ret.Int64 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Int64 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::UInt64) { VariableNT::T ret = {0}; - ret.UInt64 = - reinterpret_cast *>(m_Variable)->Min(step); + ret.UInt64 = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::Float) { VariableNT::T ret = {0}; - ret.Float = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Float = reinterpret_cast *>(m_Variable)->Min(step); return ret; } else if (m_Variable->m_Type == DataType::Double) { VariableNT::T ret = {0}; - ret.Double = - reinterpret_cast *>(m_Variable)->Min(step); + ret.Double = reinterpret_cast *>(m_Variable)->Min(step); return ret; } - helper::Throw( - "bindings::CXX11", "VariableNT", "Min", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only basic numeric types support this API"); + helper::Throw("bindings::CXX11", "VariableNT", "Min", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only basic numeric types support this API"); return {0}; } @@ -448,77 +402,66 @@ VariableNT::T VariableNT::Max(const size_t step) const if (m_Variable->m_Type == DataType::Int8) { VariableNT::T ret = {0}; - ret.Int8 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Int8 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::UInt8) { VariableNT::T ret = {0}; - ret.UInt8 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.UInt8 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::Int16) { VariableNT::T ret = {0}; - ret.Int16 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Int16 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::UInt16) { VariableNT::T ret = {0}; - ret.UInt16 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.UInt16 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::Int32) { VariableNT::T ret = {0}; - ret.Int32 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Int32 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::UInt32) { VariableNT::T ret = {0}; - ret.UInt32 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.UInt32 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::Int64) { VariableNT::T ret = {0}; - ret.Int64 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Int64 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::UInt64) { VariableNT::T ret = {0}; - ret.UInt64 = - reinterpret_cast *>(m_Variable)->Max(step); + ret.UInt64 = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::Float) { VariableNT::T ret = {0}; - ret.Float = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Float = reinterpret_cast *>(m_Variable)->Max(step); return ret; } else if (m_Variable->m_Type == DataType::Double) { VariableNT::T ret = {0}; - ret.Double = - reinterpret_cast *>(m_Variable)->Max(step); + ret.Double = reinterpret_cast *>(m_Variable)->Max(step); return ret; } - helper::Throw( - "bindings::CXX11", "VariableNT", "Max", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only basic numeric types support this API"); + helper::Throw("bindings::CXX11", "VariableNT", "Max", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only basic numeric types support this API"); return {0}; } @@ -543,8 +486,7 @@ double VariableNT::MinDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt16) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Min(step)); + reinterpret_cast *>(m_Variable)->Min(step)); } else if (m_Variable->m_Type == DataType::Int32) { @@ -554,8 +496,7 @@ double VariableNT::MinDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt32) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Min(step)); + reinterpret_cast *>(m_Variable)->Min(step)); } else if (m_Variable->m_Type == DataType::Int64) { @@ -565,8 +506,7 @@ double VariableNT::MinDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt64) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Min(step)); + reinterpret_cast *>(m_Variable)->Min(step)); } else if (m_Variable->m_Type == DataType::Float) { @@ -578,10 +518,9 @@ double VariableNT::MinDouble(const size_t step) const return static_cast( reinterpret_cast *>(m_Variable)->Min(step)); } - helper::Throw( - "bindings::CXX11", "VariableNT", "MinDouble", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only basic numeric types support this API"); + helper::Throw("bindings::CXX11", "VariableNT", "MinDouble", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only basic numeric types support this API"); return 0; } @@ -606,8 +545,7 @@ double VariableNT::MaxDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt16) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Max(step)); + reinterpret_cast *>(m_Variable)->Max(step)); } else if (m_Variable->m_Type == DataType::Int32) { @@ -617,8 +555,7 @@ double VariableNT::MaxDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt32) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Max(step)); + reinterpret_cast *>(m_Variable)->Max(step)); } else if (m_Variable->m_Type == DataType::Int64) { @@ -628,8 +565,7 @@ double VariableNT::MaxDouble(const size_t step) const else if (m_Variable->m_Type == DataType::UInt64) { return static_cast( - reinterpret_cast *>(m_Variable) - ->Max(step)); + reinterpret_cast *>(m_Variable)->Max(step)); } else if (m_Variable->m_Type == DataType::Float) { @@ -641,10 +577,9 @@ double VariableNT::MaxDouble(const size_t step) const return static_cast( reinterpret_cast *>(m_Variable)->Max(step)); } - helper::Throw( - "bindings::CXX11", "VariableNT", "MaxDouble", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only basic numeric types support this API"); + helper::Throw("bindings::CXX11", "VariableNT", "MaxDouble", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only basic numeric types support this API"); return 0; } @@ -656,50 +591,44 @@ std::pair VariableNT::MinMaxDouble(const size_t step) const StructDefinition VariableNT::GetWriteStructDef() noexcept { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldElementCount"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldElementCount"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldElementCount", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", + "StructFieldElementCount", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } core::StructDefinition *CoreSD = - reinterpret_cast(m_Variable) - ->GetWriteStructDef(); + reinterpret_cast(m_Variable)->GetWriteStructDef(); return StructDefinition(CoreSD); } StructDefinition VariableNT::GetReadStructDef() noexcept { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldElementCount"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldElementCount"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldElementCount", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", + "StructFieldElementCount", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - auto CoreSD = reinterpret_cast(m_Variable) - ->GetReadStructDef(); + auto CoreSD = reinterpret_cast(m_Variable)->GetReadStructDef(); return StructDefinition(CoreSD); } void VariableNT::SetReadStructDef(const StructDefinition &def) { - helper::CheckForNullptr(m_Variable, - "in call to VariableNT::StructFieldElementCount"); + helper::CheckForNullptr(m_Variable, "in call to VariableNT::StructFieldElementCount"); if (m_Variable->m_Type != DataType::Struct) { - helper::Throw( - "bindings::CXX11", "VariableNT", "StructFieldElementCount", - "invalid data type " + ToString(m_Variable->m_Type) + - ", only Struct type supports this API"); + helper::Throw("bindings::CXX11", "VariableNT", + "StructFieldElementCount", + "invalid data type " + ToString(m_Variable->m_Type) + + ", only Struct type supports this API"); } - reinterpret_cast(m_Variable) - ->SetReadStructDef(def.m_StructDefinition); + reinterpret_cast(m_Variable)->SetReadStructDef(def.m_StructDefinition); } } // end namespace adios2 diff --git a/bindings/CXX11/adios2/cxx11/VariableNT.h b/bindings/CXX11/adios2/cxx11/VariableNT.h index b0f01de6d2..8589ac0e95 100644 --- a/bindings/CXX11/adios2/cxx11/VariableNT.h +++ b/bindings/CXX11/adios2/cxx11/VariableNT.h @@ -28,8 +28,8 @@ class StructDefinition { public: - void AddField(const std::string &name, const size_t offset, - const DataType type, const size_t size = 1); + void AddField(const std::string &name, const size_t offset, const DataType type, + const size_t size = 1); void Freeze() noexcept; size_t StructSize() const noexcept; std::string StructName() const noexcept; @@ -194,8 +194,7 @@ class VariableNT * be confused by op own parameters * @return operation index handler in Operations() */ - size_t AddOperation(const Operator op, - const adios2::Params ¶meters = adios2::Params()); + size_t AddOperation(const Operator op, const adios2::Params ¶meters = adios2::Params()); size_t AddOperation(const std::string &type, const adios2::Params ¶meters = adios2::Params()); @@ -251,8 +250,7 @@ class VariableNT double MinDouble(const size_t step = adios2::DefaultSizeT) const; double MaxDouble(const size_t step = adios2::DefaultSizeT) const; - std::pair - MinMaxDouble(const size_t step = adios2::DefaultSizeT) const; + std::pair MinMaxDouble(const size_t step = adios2::DefaultSizeT) const; StructDefinition GetWriteStructDef() noexcept; StructDefinition GetReadStructDef() noexcept; diff --git a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.cpp b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.cpp index effd096239..03b881e7fa 100644 --- a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.cpp +++ b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.cpp @@ -14,36 +14,29 @@ namespace adios2 { -fstream::fstream(const std::string &name, const openmode mode, - const std::string engineType) -: m_Stream( - std::make_shared(name, ToMode(mode), engineType, "C++")) +fstream::fstream(const std::string &name, const openmode mode, const std::string engineType) +: m_Stream(std::make_shared(name, ToMode(mode), engineType, "C++")) { } -fstream::fstream(const std::string &name, const openmode mode, - const std::string &configFile, +fstream::fstream(const std::string &name, const openmode mode, const std::string &configFile, const std::string ioInConfigFile) -: m_Stream(std::make_shared(name, ToMode(mode), configFile, - ioInConfigFile, "C++")) +: m_Stream(std::make_shared(name, ToMode(mode), configFile, ioInConfigFile, "C++")) { } -void fstream::open(const std::string &name, const openmode mode, - const std::string engineType) +void fstream::open(const std::string &name, const openmode mode, const std::string engineType) { CheckOpen(name); - m_Stream = - std::make_shared(name, ToMode(mode), engineType, "C++"); + m_Stream = std::make_shared(name, ToMode(mode), engineType, "C++"); } -void fstream::open(const std::string &name, const openmode mode, - const std::string configFile, +void fstream::open(const std::string &name, const openmode mode, const std::string configFile, const std::string ioInConfigFile) { CheckOpen(name); - m_Stream = std::make_shared(name, ToMode(mode), configFile, - ioInConfigFile, "C++"); + m_Stream = + std::make_shared(name, ToMode(mode), configFile, ioInConfigFile, "C++"); } fstream::operator bool() const noexcept @@ -64,8 +57,7 @@ void fstream::close() m_Stream.reset(); } -void fstream::set_parameter(const std::string key, - const std::string value) noexcept +void fstream::set_parameter(const std::string key, const std::string value) noexcept { m_Stream->m_IO->SetParameter(key, value); } @@ -81,10 +73,7 @@ bool getstep(adios2::fstream &stream, adios2::fstep &step) return step.m_Stream->GetStep(); } -size_t fstream::current_step() const noexcept -{ - return m_Stream->CurrentStep(); -} +size_t fstream::current_step() const noexcept { return m_Stream->CurrentStep(); } adios2::Mode fstream::ToMode(const openmode mode) const noexcept { @@ -119,63 +108,53 @@ void fstream::CheckOpen(const std::string &name) const } } -#define declare_template_instantiation(T) \ - template void fstream::write_attribute(const std::string &, const T &, \ - const std::string &, \ - const std::string, const bool); \ - \ - template void fstream::write_attribute( \ - const std::string &, const T *, const size_t, const std::string &, \ - const std::string, const bool); \ - \ - template std::vector fstream::read_attribute( \ - const std::string &, const std::string &, const std::string); +#define declare_template_instantiation(T) \ + template void fstream::write_attribute(const std::string &, const T &, const std::string &, \ + const std::string, const bool); \ + \ + template void fstream::write_attribute(const std::string &, const T *, const size_t, \ + const std::string &, const std::string, const bool); \ + \ + template std::vector fstream::read_attribute(const std::string &, const std::string &, \ + const std::string); ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation -#define declare_template_instantiation(T) \ - template void fstream::write(const std::string &, const T *, \ - const Dims &, const Dims &, const Dims &, \ - const bool); \ - \ - template void fstream::write(const std::string &, const T *, \ - const Dims &, const Dims &, const Dims &, \ - const vParams &, const bool); \ - \ - template void fstream::write(const std::string &, const T &, \ - const bool, const bool); \ - \ - template std::vector fstream::read(const std::string &, \ - const size_t); \ - \ - template std::vector fstream::read( \ - const std::string &, const size_t, const size_t, const size_t); \ - \ - template std::vector fstream::read( \ - const std::string &, const Dims &, const Dims &, const size_t); \ - \ - template std::vector fstream::read( \ - const std::string &, const Dims &, const Dims &, const size_t, \ - const size_t, const size_t); \ - \ - template void fstream::read(const std::string &, T *, const size_t); \ - \ - template void fstream::read(const std::string &, T *, const size_t, \ - const size_t, const size_t); \ - \ - template void fstream::read(const std::string &name, T &, \ - const size_t); \ - \ - template void fstream::read(const std::string &name, T &, const size_t, \ - const size_t); \ - \ - template void fstream::read(const std::string &, T *, const Dims &, \ - const Dims &, const size_t); \ - \ - template void fstream::read(const std::string &, T *, const Dims &, \ - const Dims &, const size_t, const size_t, \ - const size_t); +#define declare_template_instantiation(T) \ + template void fstream::write(const std::string &, const T *, const Dims &, const Dims &, \ + const Dims &, const bool); \ + \ + template void fstream::write(const std::string &, const T *, const Dims &, const Dims &, \ + const Dims &, const vParams &, const bool); \ + \ + template void fstream::write(const std::string &, const T &, const bool, const bool); \ + \ + template std::vector fstream::read(const std::string &, const size_t); \ + \ + template std::vector fstream::read(const std::string &, const size_t, const size_t, \ + const size_t); \ + \ + template std::vector fstream::read(const std::string &, const Dims &, const Dims &, \ + const size_t); \ + \ + template std::vector fstream::read(const std::string &, const Dims &, const Dims &, \ + const size_t, const size_t, const size_t); \ + \ + template void fstream::read(const std::string &, T *, const size_t); \ + \ + template void fstream::read(const std::string &, T *, const size_t, const size_t, \ + const size_t); \ + \ + template void fstream::read(const std::string &name, T &, const size_t); \ + \ + template void fstream::read(const std::string &name, T &, const size_t, const size_t); \ + \ + template void fstream::read(const std::string &, T *, const Dims &, const Dims &, \ + const size_t); \ + \ + template void fstream::read(const std::string &, T *, const Dims &, const Dims &, \ + const size_t, const size_t, const size_t); ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.h b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.h index fdc05fc625..546bf54ccb 100644 --- a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.h +++ b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.h @@ -63,8 +63,8 @@ class fstream * @throws std::invalid_argument (user input error) or std::runtime_error * (system error) */ - fstream(const std::string &name, adios2::fstream::openmode mode, - MPI_Comm comm, const std::string engineType = "BPFile"); + fstream(const std::string &name, adios2::fstream::openmode mode, MPI_Comm comm, + const std::string engineType = "BPFile"); /** * High-level API MPI constructor, based on C++11 fstream. Allows for @@ -79,9 +79,8 @@ class fstream * std::runtime_error * (system error) */ - fstream(const std::string &name, const adios2::fstream::openmode mode, - MPI_Comm comm, const std::string &configFile, - const std::string ioInConfigFile); + fstream(const std::string &name, const adios2::fstream::openmode mode, MPI_Comm comm, + const std::string &configFile, const std::string ioInConfigFile); #endif /** @@ -177,8 +176,8 @@ class fstream * @exception std::invalid_argument (user input error) or * std::runtime_error (system error) */ - void open(const std::string &name, const openmode mode, - const std::string configFile, const std::string ioInConfigFile); + void open(const std::string &name, const openmode mode, const std::string configFile, + const std::string ioInConfigFile); /** * Set a single stream parameter based on Engine supported parameters. @@ -214,8 +213,7 @@ class fstream */ template void write_attribute(const std::string &name, const T &value, - const std::string &variableName = "", - const std::string separator = "/", + const std::string &variableName = "", const std::string separator = "/", const bool endStep = false); /** @@ -235,10 +233,8 @@ class fstream * Use adios2::endStep for true. */ template - void write_attribute(const std::string &name, const T *data, - const size_t size, - const std::string &variableName = "", - const std::string separator = "/", + void write_attribute(const std::string &name, const T *data, const size_t size, + const std::string &variableName = "", const std::string separator = "/", const bool endStep = false); /** @@ -257,11 +253,9 @@ class fstream * std::runtime_error (system error) */ template - void write(const std::string &name, const T *data, - const adios2::Dims &shape = adios2::Dims(), + void write(const std::string &name, const T *data, const adios2::Dims &shape = adios2::Dims(), const adios2::Dims &start = adios2::Dims(), - const adios2::Dims &count = adios2::Dims(), - const bool endStep = false); + const adios2::Dims &count = adios2::Dims(), const bool endStep = false); /** * write overload that allows passing supported operations @@ -286,10 +280,9 @@ class fstream * std::runtime_error (system error) */ template - void write(const std::string &name, const T *data, - const adios2::Dims &shape, const adios2::Dims &start, - const adios2::Dims &count, const adios2::vParams &operations, - const bool endStep = false); + void write(const std::string &name, const T *data, const adios2::Dims &shape, + const adios2::Dims &start, const adios2::Dims &count, + const adios2::vParams &operations, const bool endStep = false); /** * Write a self-describing single-value variable @@ -303,8 +296,8 @@ class fstream * std::runtime_error (system error) */ template - void write(const std::string &name, const T &value, - const bool isLocalValue = false, const bool endStep = false); + void write(const std::string &name, const T &value, const bool isLocalValue = false, + const bool endStep = false); /** * Reads into a pre-allocated pointer. When @@ -365,8 +358,7 @@ class fstream * found */ template - void read(const std::string &name, T &value, const size_t step, - const size_t blockID = 0); + void read(const std::string &name, T &value, const size_t step, const size_t blockID = 0); /** * Reads into a pre-allocated pointer a selection piece in dimension. When @@ -405,8 +397,8 @@ class fstream */ template void read(const std::string &name, T *data, const adios2::Dims &start, - const adios2::Dims &count, const size_t stepsStart, - const size_t stepsCount, const size_t blockID = 0); + const adios2::Dims &count, const size_t stepsStart, const size_t stepsCount, + const size_t blockID = 0); /** * Reads entire variable for current step (streaming mode: step by step) @@ -455,8 +447,8 @@ class fstream * found */ template - std::vector read(const std::string &name, const Dims &start, - const Dims &count, const size_t blockID = 0); + std::vector read(const std::string &name, const Dims &start, const Dims &count, + const size_t blockID = 0); /** * Reads a selection piece in dimension and a selection piece in steps @@ -476,9 +468,8 @@ class fstream * found */ template - std::vector read(const std::string &name, const Dims &start, - const Dims &count, const size_t stepsStart, - const size_t stepsCount, const size_t blockID = 0); + std::vector read(const std::string &name, const Dims &start, const Dims &count, + const size_t stepsStart, const size_t stepsCount, const size_t blockID = 0); /** * Reads an attribute returning a vector @@ -492,8 +483,7 @@ class fstream * @return vector containing attribute data */ template - std::vector read_attribute(const std::string &name, - const std::string &variableName = "", + std::vector read_attribute(const std::string &name, const std::string &variableName = "", const std::string separator = "/"); /** @@ -536,67 +526,60 @@ class fstream void CheckOpen(const std::string &name) const; }; -#define declare_template_instantiation(T) \ - extern template void fstream::write_attribute( \ - const std::string &, const T &, const std::string &, \ - const std::string, const bool); \ - \ - extern template void fstream::write_attribute( \ - const std::string &, const T *, const size_t, const std::string &, \ - const std::string, const bool); \ - \ - extern template std::vector fstream::read_attribute( \ +#define declare_template_instantiation(T) \ + extern template void fstream::write_attribute( \ + const std::string &, const T &, const std::string &, const std::string, const bool); \ + \ + extern template void fstream::write_attribute(const std::string &, const T *, const size_t, \ + const std::string &, const std::string, \ + const bool); \ + \ + extern template std::vector fstream::read_attribute( \ const std::string &, const std::string &, const std::string); ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation -#define declare_template_instantiation(T) \ - extern template void fstream::write(const std::string &, const T *, \ - const Dims &, const Dims &, \ - const Dims &, const bool); \ - \ - extern template void fstream::write( \ - const std::string &, const T *, const Dims &, const Dims &, \ - const Dims &, const vParams &, const bool); \ - \ - extern template void fstream::write(const std::string &, const T &, \ - const bool, const bool); \ - \ - extern template std::vector fstream::read(const std::string &, \ - const size_t); \ - \ - extern template std::vector fstream::read( \ - const std::string &, const size_t, const size_t, const size_t); \ - \ - extern template std::vector fstream::read( \ - const std::string &, const Dims &, const Dims &, const size_t); \ - \ - extern template std::vector fstream::read( \ - const std::string &, const Dims &, const Dims &, const size_t, \ - const size_t, const size_t); \ - \ - extern template void fstream::read(const std::string &, T *, \ - const size_t); \ - \ - extern template void fstream::read(const std::string &, T *, const size_t, \ - const size_t, const size_t); \ - \ - extern template void fstream::read(const std::string &name, T &, \ - const size_t); \ - \ - extern template void fstream::read(const std::string &name, T &, \ - const size_t); \ - \ - extern template void fstream::read( \ - const std::string &, T *, const Dims &, const Dims &, const size_t); \ - \ - extern template void fstream::read( \ - const std::string &, T *, const size_t, const size_t, const size_t); \ - \ - extern template void fstream::read( \ - const std::string &, T *, const Dims &, const Dims &, const size_t, \ - const size_t, const size_t); +#define declare_template_instantiation(T) \ + extern template void fstream::write(const std::string &, const T *, const Dims &, \ + const Dims &, const Dims &, const bool); \ + \ + extern template void fstream::write(const std::string &, const T *, const Dims &, \ + const Dims &, const Dims &, const vParams &, \ + const bool); \ + \ + extern template void fstream::write(const std::string &, const T &, const bool, \ + const bool); \ + \ + extern template std::vector fstream::read(const std::string &, const size_t); \ + \ + extern template std::vector fstream::read(const std::string &, const size_t, \ + const size_t, const size_t); \ + \ + extern template std::vector fstream::read(const std::string &, const Dims &, \ + const Dims &, const size_t); \ + \ + extern template std::vector fstream::read(const std::string &, const Dims &, \ + const Dims &, const size_t, const size_t, \ + const size_t); \ + \ + extern template void fstream::read(const std::string &, T *, const size_t); \ + \ + extern template void fstream::read(const std::string &, T *, const size_t, const size_t, \ + const size_t); \ + \ + extern template void fstream::read(const std::string &name, T &, const size_t); \ + \ + extern template void fstream::read(const std::string &name, T &, const size_t); \ + \ + extern template void fstream::read(const std::string &, T *, const Dims &, const Dims &, \ + const size_t); \ + \ + extern template void fstream::read(const std::string &, T *, const size_t, const size_t, \ + const size_t); \ + \ + extern template void fstream::read(const std::string &, T *, const Dims &, const Dims &, \ + const size_t, const size_t, const size_t); ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.tcc b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.tcc index e9e258455e..4170515f86 100644 --- a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.tcc +++ b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstream.tcc @@ -20,52 +20,49 @@ namespace adios2 template void fstream::write_attribute(const std::string &name, const T &value, - const std::string &variableName, - const std::string separator, const bool endStep) + const std::string &variableName, const std::string separator, + const bool endStep) { using IOType = typename TypeInfo::IOType; - m_Stream->WriteAttribute(name, reinterpret_cast(value), - variableName, separator, endStep); + m_Stream->WriteAttribute(name, reinterpret_cast(value), variableName, separator, + endStep); } template -void fstream::write_attribute(const std::string &name, const T *data, - const size_t size, - const std::string &variableName, - const std::string separator, const bool endStep) +void fstream::write_attribute(const std::string &name, const T *data, const size_t size, + const std::string &variableName, const std::string separator, + const bool endStep) { using IOType = typename TypeInfo::IOType; - m_Stream->WriteAttribute(name, reinterpret_cast(data), size, - variableName, separator, endStep); + m_Stream->WriteAttribute(name, reinterpret_cast(data), size, variableName, + separator, endStep); } template -void fstream::write(const std::string &name, const T *data, const Dims &shape, - const Dims &start, const Dims &count, const bool endStep) +void fstream::write(const std::string &name, const T *data, const Dims &shape, const Dims &start, + const Dims &count, const bool endStep) { using IOType = typename TypeInfo::IOType; - m_Stream->Write(name, reinterpret_cast(data), shape, start, - count, vParams(), endStep); + m_Stream->Write(name, reinterpret_cast(data), shape, start, count, vParams(), + endStep); } template -void fstream::write(const std::string &name, const T *data, - const adios2::Dims &shape, const adios2::Dims &start, - const adios2::Dims &count, +void fstream::write(const std::string &name, const T *data, const adios2::Dims &shape, + const adios2::Dims &start, const adios2::Dims &count, const adios2::vParams &operations, const bool endStep) { using IOType = typename TypeInfo::IOType; - m_Stream->Write(name, reinterpret_cast(data), shape, start, - count, operations, endStep); + m_Stream->Write(name, reinterpret_cast(data), shape, start, count, operations, + endStep); } template -void fstream::write(const std::string &name, const T &value, - const bool isLocalValue, const bool endStep) +void fstream::write(const std::string &name, const T &value, const bool isLocalValue, + const bool endStep) { using IOType = typename TypeInfo::IOType; - m_Stream->Write(name, reinterpret_cast(value), isLocalValue, - endStep); + m_Stream->Write(name, reinterpret_cast(value), isLocalValue, endStep); } template @@ -76,12 +73,12 @@ void fstream::read(const std::string &name, T *data, const size_t blockID) } template -void fstream::read(const std::string &name, T *data, const size_t stepStart, - const size_t stepCount, const size_t blockID) +void fstream::read(const std::string &name, T *data, const size_t stepStart, const size_t stepCount, + const size_t blockID) { using IOType = typename TypeInfo::IOType; - m_Stream->Read(name, reinterpret_cast(data), - Box{stepStart, stepCount}, blockID); + m_Stream->Read(name, reinterpret_cast(data), Box{stepStart, stepCount}, + blockID); } template @@ -101,23 +98,19 @@ void fstream::read(const std::string &name, T *data, const Dims &selectionStart, } template -void fstream::read(const std::string &name, T *data, const Dims &start, - const Dims &count, const size_t stepStart, - const size_t stepCount, const size_t blockID) +void fstream::read(const std::string &name, T *data, const Dims &start, const Dims &count, + const size_t stepStart, const size_t stepCount, const size_t blockID) { using IOType = typename TypeInfo::IOType; - m_Stream->Read(name, reinterpret_cast(data), - Box(start, count), Box(stepStart, stepCount), - blockID); + m_Stream->Read(name, reinterpret_cast(data), Box(start, count), + Box(stepStart, stepCount), blockID); } template -void fstream::read(const std::string &name, T &value, const size_t stepStart, - const size_t blockID) +void fstream::read(const std::string &name, T &value, const size_t stepStart, const size_t blockID) { using IOType = typename TypeInfo::IOType; - m_Stream->Read(name, &reinterpret_cast(value), - Box(stepStart, 1), blockID); + m_Stream->Read(name, &reinterpret_cast(value), Box(stepStart, 1), blockID); } template @@ -133,14 +126,13 @@ std::vector fstream::read(const std::string &name, const size_t stepsStart, const size_t stepsCount, const size_t blockID) { using IOType = typename TypeInfo::IOType; - auto vec = m_Stream->Read(name, Box(stepsStart, stepsCount), - blockID); + auto vec = m_Stream->Read(name, Box(stepsStart, stepsCount), blockID); return reinterpret_cast &>(vec); } template -std::vector fstream::read(const std::string &name, const Dims &start, - const Dims &count, const size_t blockID) +std::vector fstream::read(const std::string &name, const Dims &start, const Dims &count, + const size_t blockID) { using IOType = typename TypeInfo::IOType; auto vec = m_Stream->Read(name, Box(start, count), blockID); @@ -148,26 +140,22 @@ std::vector fstream::read(const std::string &name, const Dims &start, } template -std::vector fstream::read(const std::string &name, const Dims &start, - const Dims &count, const size_t stepStart, - const size_t stepCount, const size_t blockID) +std::vector fstream::read(const std::string &name, const Dims &start, const Dims &count, + const size_t stepStart, const size_t stepCount, const size_t blockID) { using IOType = typename TypeInfo::IOType; - auto vec = - m_Stream->Read(name, Box(start, count), - Box(stepStart, stepCount), blockID); + auto vec = m_Stream->Read(name, Box(start, count), + Box(stepStart, stepCount), blockID); return reinterpret_cast &>(vec); } template -std::vector fstream::read_attribute(const std::string &name, - const std::string &variableName, +std::vector fstream::read_attribute(const std::string &name, const std::string &variableName, const std::string separator) { using IOType = typename TypeInfo::IOType; std::vector data; - core::Attribute *attribute = - m_Stream->m_IO->InquireAttribute(name); + core::Attribute *attribute = m_Stream->m_IO->InquireAttribute(name); if (attribute == nullptr) { @@ -175,8 +163,7 @@ std::vector fstream::read_attribute(const std::string &name, } data.resize(attribute->m_Elements); - m_Stream->ReadAttribute(name, reinterpret_cast(data.data()), - variableName, separator); + m_Stream->ReadAttribute(name, reinterpret_cast(data.data()), variableName, separator); return data; } diff --git a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstreamMPI.cpp b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstreamMPI.cpp index 38f4e7ef1f..ba0ea4ae99 100644 --- a/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstreamMPI.cpp +++ b/bindings/CXX11/adios2/cxx11/fstream/ADIOS2fstreamMPI.cpp @@ -15,16 +15,14 @@ namespace adios2 fstream::fstream(const std::string &name, const openmode mode, MPI_Comm comm, const std::string engineType) -: m_Stream(std::make_shared( - name, ToMode(mode), helper::CommDupMPI(comm), engineType, "C++")) +: m_Stream(std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), engineType, + "C++")) { } fstream::fstream(const std::string &name, const openmode mode, MPI_Comm comm, - const std::string &configFile, - const std::string ioInConfigFile) -: m_Stream(std::make_shared(name, ToMode(mode), - helper::CommDupMPI(comm), configFile, + const std::string &configFile, const std::string ioInConfigFile) +: m_Stream(std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), configFile, ioInConfigFile, "C++")) { } @@ -33,18 +31,16 @@ void fstream::open(const std::string &name, const openmode mode, MPI_Comm comm, const std::string engineType) { CheckOpen(name); - m_Stream = std::make_shared( - name, ToMode(mode), helper::CommDupMPI(comm), engineType, "C++"); + m_Stream = std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), + engineType, "C++"); } void fstream::open(const std::string &name, const openmode mode, MPI_Comm comm, - const std::string configFile, - const std::string ioInConfigFile) + const std::string configFile, const std::string ioInConfigFile) { CheckOpen(name); - m_Stream = std::make_shared( - name, ToMode(mode), helper::CommDupMPI(comm), configFile, - ioInConfigFile, "C++"); + m_Stream = std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), + configFile, ioInConfigFile, "C++"); } } // end namespace adios2 diff --git a/bindings/Fortran/CMakeLists.txt b/bindings/Fortran/CMakeLists.txt index 2e0cb2c1b3..1a998bbe95 100644 --- a/bindings/Fortran/CMakeLists.txt +++ b/bindings/Fortran/CMakeLists.txt @@ -103,7 +103,7 @@ if(ADIOS2_HAVE_MPI) PRIVATE adios2_c_mpi adios2_core_mpi - PUBLIC + INTERFACE MPI::MPI_Fortran ) target_compile_definitions(adios2_fortran_mpi PRIVATE "$<$:ADIOS2_HAVE_FORTRAN_SUBMODULES;ADIOS2_HAVE_MPI_F>") diff --git a/bindings/Fortran/f2c/adios2_f2c_adios.cpp b/bindings/Fortran/f2c/adios2_f2c_adios.cpp index 5129208458..da8ac4bf50 100644 --- a/bindings/Fortran/f2c/adios2_f2c_adios.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_adios.cpp @@ -19,8 +19,7 @@ extern adios2_adios *adios2_init_config_glue_serial(const char *config_file, const char *host_language); void FC_GLOBAL(adios2_init_config_serial_f2c, - ADIOS2_INIT_CONFIG_SERIAL_F2C)(adios2_adios **adios, - const char *config_file, + ADIOS2_INIT_CONFIG_SERIAL_F2C)(adios2_adios **adios, const char *config_file, int *ierr) { *adios = adios2_init_config_glue_serial(config_file, "Fortran"); @@ -28,16 +27,14 @@ void FC_GLOBAL(adios2_init_config_serial_f2c, : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_init_serial_f2c, - ADIOS2_INIT_SERIAL_F2C)(adios2_adios **adios, int *ierr) +void FC_GLOBAL(adios2_init_serial_f2c, ADIOS2_INIT_SERIAL_F2C)(adios2_adios **adios, int *ierr) { FC_GLOBAL(adios2_init_config_serial_f2c, ADIOS2_INIT_CONFIG_SERIAL_F2C) (adios, "", ierr); } -void FC_GLOBAL(adios2_declare_io_f2c, - ADIOS2_DECLARE_IO_F2C)(adios2_io **io, adios2_adios **adios, - const char *name, int *ierr) +void FC_GLOBAL(adios2_declare_io_f2c, ADIOS2_DECLARE_IO_F2C)(adios2_io **io, adios2_adios **adios, + const char *name, int *ierr) { *io = adios2_declare_io(*adios, name); @@ -45,8 +42,7 @@ void FC_GLOBAL(adios2_declare_io_f2c, : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_at_io_f2c, ADIOS2_at_IO_F2C)(adios2_io **io, - adios2_adios **adios, +void FC_GLOBAL(adios2_at_io_f2c, ADIOS2_at_IO_F2C)(adios2_io **io, adios2_adios **adios, const char *name, int *ierr) { *io = adios2_at_io(*adios, name); @@ -55,10 +51,8 @@ void FC_GLOBAL(adios2_at_io_f2c, ADIOS2_at_IO_F2C)(adios2_io **io, } void FC_GLOBAL(adios2_define_operator_f2c, - ADIOS2_DEFINE_OPERATOR_F2C)(adios2_operator **op, - adios2_adios **adios, - const char *op_name, - const char *op_type, int *ierr) + ADIOS2_DEFINE_OPERATOR_F2C)(adios2_operator **op, adios2_adios **adios, + const char *op_name, const char *op_type, int *ierr) { *op = adios2_define_operator(*adios, op_name, op_type); *ierr = (*op == NULL) ? static_cast(adios2_error_exception) @@ -66,8 +60,7 @@ void FC_GLOBAL(adios2_define_operator_f2c, } void FC_GLOBAL(adios2_inquire_operator_f2c, - ADIOS2_INQUIRE_OPERATOR_F2C)(adios2_operator **op, - adios2_adios **adios, + ADIOS2_INQUIRE_OPERATOR_F2C)(adios2_operator **op, adios2_adios **adios, const char *op_name, int *ierr) { *op = adios2_inquire_operator(*adios, op_name); @@ -75,15 +68,13 @@ void FC_GLOBAL(adios2_inquire_operator_f2c, : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_flush_all_f2c, ADIOS2_FLUSH_ALL_F2C)(adios2_adios **adios, - int *ierr) +void FC_GLOBAL(adios2_flush_all_f2c, ADIOS2_FLUSH_ALL_F2C)(adios2_adios **adios, int *ierr) { *ierr = static_cast(adios2_flush_all(*adios)); } -void FC_GLOBAL(adios2_remove_io_f2c, - ADIOS2_REMOVE_IO_F2C)(int *result, adios2_adios **adios, - const char *name, int *ierr) +void FC_GLOBAL(adios2_remove_io_f2c, ADIOS2_REMOVE_IO_F2C)(int *result, adios2_adios **adios, + const char *name, int *ierr) { adios2_bool resultC; *ierr = static_cast(adios2_remove_io(&resultC, *adios, name)); @@ -93,28 +84,25 @@ void FC_GLOBAL(adios2_remove_io_f2c, } } -void FC_GLOBAL(adios2_remove_all_ios_f2c, - ADIOS2_REMOVE_ALL_IOS_F2C)(adios2_adios **adios, int *ierr) +void FC_GLOBAL(adios2_remove_all_ios_f2c, ADIOS2_REMOVE_ALL_IOS_F2C)(adios2_adios **adios, + int *ierr) { *ierr = static_cast(adios2_remove_all_ios(*adios)); } -void FC_GLOBAL(adios2_finalize_f2c, ADIOS2_FINALIZE_F2C)(adios2_adios **adios, - int *ierr) +void FC_GLOBAL(adios2_finalize_f2c, ADIOS2_FINALIZE_F2C)(adios2_adios **adios, int *ierr) { *ierr = static_cast(adios2_finalize(*adios)); } void FC_GLOBAL(adios2_enter_computation_block_f2c, - ADIOS2_ENTER_COMPUTATION_BLOCK_F2C)(adios2_adios **adios, - int *ierr) + ADIOS2_ENTER_COMPUTATION_BLOCK_F2C)(adios2_adios **adios, int *ierr) { *ierr = static_cast(adios2_enter_computation_block(*adios)); } void FC_GLOBAL(adios2_exit_computation_block_f2c, - ADIOS2_EXIT_COMPUTATION_BLOCK_F2C)(adios2_adios **adios, - int *ierr) + ADIOS2_EXIT_COMPUTATION_BLOCK_F2C)(adios2_adios **adios, int *ierr) { *ierr = static_cast(adios2_exit_computation_block(*adios)); } diff --git a/bindings/Fortran/f2c/adios2_f2c_adios_mpi.cpp b/bindings/Fortran/f2c/adios2_f2c_adios_mpi.cpp index 0677d76e08..ca5974d96f 100644 --- a/bindings/Fortran/f2c/adios2_f2c_adios_mpi.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_adios_mpi.cpp @@ -12,23 +12,19 @@ extern "C" { // this function is not exposed in the public APIs -extern adios2_adios *adios2_init_config_glue_mpi(const char *config_file, - MPI_Comm comm, +extern adios2_adios *adios2_init_config_glue_mpi(const char *config_file, MPI_Comm comm, const char *host_language); -void FC_GLOBAL(adios2_init_config_mpi_f2c, - ADIOS2_INIT_CONFIG_MPI_F2C)(adios2_adios **adios, - const char *config_file, - MPI_Fint *comm, int *ierr) +void FC_GLOBAL(adios2_init_config_mpi_f2c, ADIOS2_INIT_CONFIG_MPI_F2C)(adios2_adios **adios, + const char *config_file, + MPI_Fint *comm, int *ierr) { - *adios = adios2_init_config_glue_mpi(config_file, MPI_Comm_f2c(*comm), - "Fortran"); + *adios = adios2_init_config_glue_mpi(config_file, MPI_Comm_f2c(*comm), "Fortran"); *ierr = (*adios == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_init_mpi_f2c, ADIOS2_INIT_MPI_F2C)(adios2_adios **adios, - MPI_Fint *comm, +void FC_GLOBAL(adios2_init_mpi_f2c, ADIOS2_INIT_MPI_F2C)(adios2_adios **adios, MPI_Fint *comm, int *ierr) { FC_GLOBAL(adios2_init_config_mpi_f2c, ADIOS2_INIT_CONFIG_MPI_F2C) diff --git a/bindings/Fortran/f2c/adios2_f2c_attribute.cpp b/bindings/Fortran/f2c/adios2_f2c_attribute.cpp index bec1ee733d..4fa18d8c34 100644 --- a/bindings/Fortran/f2c/adios2_f2c_attribute.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_attribute.cpp @@ -18,30 +18,28 @@ extern "C" { #endif void FC_GLOBAL(adios2_attribute_name_f2c, - ADIOS2_ATTRIBUTE_NAME_F2C)(char *name, - const adios2_attribute **attribute, - int *ierr) + ADIOS2_ATTRIBUTE_NAME_F2C)(char *name, const adios2_attribute **attribute, int *ierr) { size_t sizeC; *ierr = static_cast(adios2_attribute_name(name, &sizeC, *attribute)); } void FC_GLOBAL(adios2_attribute_name_length_f2c, - ADIOS2_ATTRIBUTE_NAME_LENGTH_F2C)( - int *size, const adios2_attribute **attribute, int *ierr) + ADIOS2_ATTRIBUTE_NAME_LENGTH_F2C)(int *size, const adios2_attribute **attribute, + int *ierr) { *size = -1; size_t sizeC; - *ierr = - static_cast(adios2_attribute_name(nullptr, &sizeC, *attribute)); + *ierr = static_cast(adios2_attribute_name(nullptr, &sizeC, *attribute)); if (*ierr == static_cast(adios2_error_none)) { *size = static_cast(sizeC); } } -void FC_GLOBAL(adios2_attribute_is_value_f2c, ADIOS2_ATTRIBUTE_IS_VALUE_F2C)( - int *is_value, const adios2_attribute **attribute, int *ierr) +void FC_GLOBAL(adios2_attribute_is_value_f2c, + ADIOS2_ATTRIBUTE_IS_VALUE_F2C)(int *is_value, const adios2_attribute **attribute, + int *ierr) { adios2_bool isValueC; *ierr = static_cast(adios2_attribute_is_value(&isValueC, *attribute)); @@ -52,9 +50,7 @@ void FC_GLOBAL(adios2_attribute_is_value_f2c, ADIOS2_ATTRIBUTE_IS_VALUE_F2C)( } void FC_GLOBAL(adios2_attribute_type_f2c, - ADIOS2_ATTRIBUTE_TYPE_F2C)(int *type, - const adios2_attribute **attribute, - int *ierr) + ADIOS2_ATTRIBUTE_TYPE_F2C)(int *type, const adios2_attribute **attribute, int *ierr) { *type = -1; adios2_type typeC; @@ -66,8 +62,7 @@ void FC_GLOBAL(adios2_attribute_type_f2c, } void FC_GLOBAL(adios2_attribute_length_f2c, - ADIOS2_ATTRIBUTE_LENGTH_F2C)(int *length, - const adios2_attribute **attribute, + ADIOS2_ATTRIBUTE_LENGTH_F2C)(int *length, const adios2_attribute **attribute, int *ierr) { *length = -1; @@ -80,8 +75,7 @@ void FC_GLOBAL(adios2_attribute_length_f2c, } void FC_GLOBAL(adios2_attribute_value_f2c, - ADIOS2_ATTRIBUTE_VALUE_F2C)(void *data, - const adios2_attribute **attribute, + ADIOS2_ATTRIBUTE_VALUE_F2C)(void *data, const adios2_attribute **attribute, int *ierr) { size_t size = 0; @@ -89,8 +83,7 @@ void FC_GLOBAL(adios2_attribute_value_f2c, } void FC_GLOBAL(adios2_attribute_data_f2c, - ADIOS2_ATTRIBUTE_DATA_F2C)(void *data, int *size, - const adios2_attribute **attribute, + ADIOS2_ATTRIBUTE_DATA_F2C)(void *data, int *size, const adios2_attribute **attribute, int *ierr) { try @@ -102,23 +95,20 @@ void FC_GLOBAL(adios2_attribute_data_f2c, if (type == adios2_type_string) { const adios2::core::Attribute *attributeCpp = - reinterpret_cast *>( - *attribute); + reinterpret_cast *>(*attribute); char *dataT = reinterpret_cast(data); for (auto e = 0; e < *size; ++e) { - attributeCpp->m_DataArray[e].copy( - &dataT[e * adios2_string_array_element_max_size], - attributeCpp->m_DataArray[e].size()); + attributeCpp->m_DataArray[e].copy(&dataT[e * adios2_string_array_element_max_size], + attributeCpp->m_DataArray[e].size()); } } else { size_t sizeC; - *ierr = static_cast( - adios2_attribute_data(data, &sizeC, *attribute)); + *ierr = static_cast(adios2_attribute_data(data, &sizeC, *attribute)); } } catch (...) diff --git a/bindings/Fortran/f2c/adios2_f2c_engine.cpp b/bindings/Fortran/f2c/adios2_f2c_engine.cpp index 8678a3bdb5..ccc01c6b82 100644 --- a/bindings/Fortran/f2c/adios2_f2c_engine.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_engine.cpp @@ -15,17 +15,14 @@ extern "C" { #endif void FC_GLOBAL(adios2_begin_step_f2c, - ADIOS2_BEGIN_STEP_F2C)(adios2_engine **engine, - const int *step_mode, - const float *timeout_seconds, int *status, - int *ierr) + ADIOS2_BEGIN_STEP_F2C)(adios2_engine **engine, const int *step_mode, + const float *timeout_seconds, int *status, int *ierr) { *status = -1; adios2_step_status statusC; - *ierr = static_cast( - adios2_begin_step(*engine, static_cast(*step_mode), - *timeout_seconds, &statusC)); + *ierr = static_cast(adios2_begin_step(*engine, static_cast(*step_mode), + *timeout_seconds, &statusC)); if (*ierr == static_cast(adios2_error_none)) { @@ -34,8 +31,7 @@ void FC_GLOBAL(adios2_begin_step_f2c, } void FC_GLOBAL(adios2_current_step_f2c, - ADIOS2_CURRENT_STEP_F2C)(int64_t *step, - const adios2_engine **engine, int *ierr) + ADIOS2_CURRENT_STEP_F2C)(int64_t *step, const adios2_engine **engine, int *ierr) { *step = -1; size_t stepC; @@ -47,8 +43,7 @@ void FC_GLOBAL(adios2_current_step_f2c, } } -void FC_GLOBAL(adios2_steps_f2c, ADIOS2_STEPS_F2C)(int64_t *steps, - const adios2_engine **engine, +void FC_GLOBAL(adios2_steps_f2c, ADIOS2_STEPS_F2C)(int64_t *steps, const adios2_engine **engine, int *ierr) { *steps = -1; @@ -62,95 +57,82 @@ void FC_GLOBAL(adios2_steps_f2c, ADIOS2_STEPS_F2C)(int64_t *steps, } void FC_GLOBAL(adios2_lock_writer_definitions_f2c, - ADIOS2_LOCK_WRITER_DEFINITIONS_F2C)(adios2_engine **engine, - int *ierr) + ADIOS2_LOCK_WRITER_DEFINITIONS_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_lock_writer_definitions(*engine)); } void FC_GLOBAL(adios2_lock_reader_selections_f2c, - ADIOS2_LOCK_READER_SELECTIONS_F2C)(adios2_engine **engine, - int *ierr) + ADIOS2_LOCK_READER_SELECTIONS_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_lock_reader_selections(*engine)); } // ******** PUTS */ -void FC_GLOBAL(adios2_put_f2c, ADIOS2_PUT_F2C)(adios2_engine **engine, - adios2_variable **variable, - const void *data, - const int *launch, int *ierr) +void FC_GLOBAL(adios2_put_f2c, ADIOS2_PUT_F2C)(adios2_engine **engine, adios2_variable **variable, + const void *data, const int *launch, int *ierr) { - *ierr = static_cast(adios2_put(*engine, *variable, data, - static_cast(*launch))); + *ierr = + static_cast(adios2_put(*engine, *variable, data, static_cast(*launch))); } -void FC_GLOBAL(adios2_put_by_name_f2c, - ADIOS2_PUT_BY_NAME_F2C)(adios2_engine **engine, const char *name, - const void *data, const int *launch, - int *ierr) +void FC_GLOBAL(adios2_put_by_name_f2c, ADIOS2_PUT_BY_NAME_F2C)(adios2_engine **engine, + const char *name, const void *data, + const int *launch, int *ierr) { - *ierr = static_cast(adios2_put_by_name( - *engine, name, data, static_cast(*launch))); + *ierr = static_cast( + adios2_put_by_name(*engine, name, data, static_cast(*launch))); } -void FC_GLOBAL(adios2_perform_puts_f2c, - ADIOS2_PERFORM_PUTS_F2C)(adios2_engine **engine, int *ierr) +void FC_GLOBAL(adios2_perform_puts_f2c, ADIOS2_PERFORM_PUTS_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_perform_puts(*engine)); } -void FC_GLOBAL(adios2_perform_data_write_f2c, - ADIOS2_PERFORM_DATA_WRITE_F2C)(adios2_engine **engine, int *ierr) +void FC_GLOBAL(adios2_perform_data_write_f2c, ADIOS2_PERFORM_DATA_WRITE_F2C)(adios2_engine **engine, + int *ierr) { *ierr = static_cast(adios2_perform_data_write(*engine)); } // ******** GETS */ -void FC_GLOBAL(adios2_get_f2c, ADIOS2_get_F2C)(adios2_engine **engine, - adios2_variable **variable, - void *data, const int *launch, - int *ierr) +void FC_GLOBAL(adios2_get_f2c, ADIOS2_get_F2C)(adios2_engine **engine, adios2_variable **variable, + void *data, const int *launch, int *ierr) { - *ierr = static_cast(adios2_get(*engine, *variable, data, - static_cast(*launch))); + *ierr = + static_cast(adios2_get(*engine, *variable, data, static_cast(*launch))); } -void FC_GLOBAL(adios2_get_by_name_f2c, - ADIOS2_get_BY_NAME_F2C)(adios2_engine **engine, const char *name, - void *data, const int *launch, int *ierr) +void FC_GLOBAL(adios2_get_by_name_f2c, ADIOS2_get_BY_NAME_F2C)(adios2_engine **engine, + const char *name, void *data, + const int *launch, int *ierr) { - *ierr = static_cast(adios2_get_by_name( - *engine, name, data, static_cast(*launch))); + *ierr = static_cast( + adios2_get_by_name(*engine, name, data, static_cast(*launch))); } -void FC_GLOBAL(adios2_perform_gets_f2c, - ADIOS2_PERFORM_GETS_F2C)(adios2_engine **engine, int *ierr) +void FC_GLOBAL(adios2_perform_gets_f2c, ADIOS2_PERFORM_GETS_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_perform_gets(*engine)); } -void FC_GLOBAL(adios2_end_step_f2c, ADIOS2_END_STEP_F2C)(adios2_engine **engine, - int *ierr) +void FC_GLOBAL(adios2_end_step_f2c, ADIOS2_END_STEP_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_end_step(*engine)); } -void FC_GLOBAL(adios2_flush_f2c, ADIOS2_FLUSH_F2C)(adios2_engine **engine, - int *ierr) +void FC_GLOBAL(adios2_flush_f2c, ADIOS2_FLUSH_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_flush(*engine)); } -void FC_GLOBAL(adios2_close_f2c, ADIOS2_CLOSE_F2C)(adios2_engine **engine, - int *ierr) +void FC_GLOBAL(adios2_close_f2c, ADIOS2_CLOSE_F2C)(adios2_engine **engine, int *ierr) { *ierr = static_cast(adios2_close(*engine)); } void FC_GLOBAL(adios2_engine_get_type_f2c, - ADIOS2_ENGINE_GET_TYPE_F2C)(char *type, adios2_engine **engine, - int *ierr) + ADIOS2_ENGINE_GET_TYPE_F2C)(char *type, adios2_engine **engine, int *ierr) { size_t size; *ierr = static_cast(adios2_engine_get_type(type, &size, *engine)); diff --git a/bindings/Fortran/f2c/adios2_f2c_io.cpp b/bindings/Fortran/f2c/adios2_f2c_io.cpp index 74234501c4..ef3899d5a0 100644 --- a/bindings/Fortran/f2c/adios2_f2c_io.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_io.cpp @@ -23,8 +23,7 @@ extern "C" { #endif void FC_GLOBAL(adios2_in_config_file_f2c, - ADIOS2_IN_CONFIG_FILE_F2C)(int *result, const adios2_io **io, - int *ierr) + ADIOS2_IN_CONFIG_FILE_F2C)(int *result, const adios2_io **io, int *ierr) { adios2_bool resultC; *ierr = static_cast(adios2_in_config_file(&resultC, *io)); @@ -34,38 +33,35 @@ void FC_GLOBAL(adios2_in_config_file_f2c, } } -void FC_GLOBAL(adios2_set_engine_f2c, - ADIOS2_SET_ENGINE_F2C)(adios2_io **io, const char *engine_type, - int *ierr) +void FC_GLOBAL(adios2_set_engine_f2c, ADIOS2_SET_ENGINE_F2C)(adios2_io **io, + const char *engine_type, int *ierr) { *ierr = static_cast(adios2_set_engine(*io, engine_type)); } void FC_GLOBAL(adios2_set_parameters_f2c, - ADIOS2_SET_PARAMETERS_F2C)(adios2_io **io, - const char *parameters, int *ierr) + ADIOS2_SET_PARAMETERS_F2C)(adios2_io **io, const char *parameters, int *ierr) { *ierr = static_cast(adios2_set_parameters(*io, parameters)); } -void FC_GLOBAL(adios2_set_parameter_f2c, - ADIOS2_SET_PARAMETER_F2C)(adios2_io **io, const char *key, - const char *value, int *ierr) +void FC_GLOBAL(adios2_set_parameter_f2c, ADIOS2_SET_PARAMETER_F2C)(adios2_io **io, const char *key, + const char *value, int *ierr) { *ierr = static_cast(adios2_set_parameter(*io, key, value)); } -void FC_GLOBAL(adios2_get_parameter_f2c, - ADIOS2_GET_PARAMETER_F2C)(char *value, const adios2_io **io, - const char *key, int *ierr) +void FC_GLOBAL(adios2_get_parameter_f2c, ADIOS2_GET_PARAMETER_F2C)(char *value, + const adios2_io **io, + const char *key, int *ierr) { size_t sizeC; *ierr = static_cast(adios2_get_parameter(value, &sizeC, *io, key)); } void FC_GLOBAL(adios2_get_parameter_length_f2c, - ADIOS2_GET_PARAMETER_LENGTH_F2C)(int *size, const adios2_io **io, - const char *key, int *ierr) + ADIOS2_GET_PARAMETER_LENGTH_F2C)(int *size, const adios2_io **io, const char *key, + int *ierr) { *size = -1; size_t sizeC; @@ -76,8 +72,7 @@ void FC_GLOBAL(adios2_get_parameter_length_f2c, } } -void FC_GLOBAL(adios2_clear_parameters_f2c, - ADIOS2_CLEAR_PARAMETERS_F2C)(adios2_io **io, int *ierr) +void FC_GLOBAL(adios2_clear_parameters_f2c, ADIOS2_CLEAR_PARAMETERS_F2C)(adios2_io **io, int *ierr) { *ierr = static_cast(adios2_clear_parameters(*io)); } @@ -89,8 +84,7 @@ void FC_GLOBAL(adios2_add_transport_f2c, *transport_index = -1; std::size_t transport_indexC; - *ierr = static_cast( - adios2_add_transport(&transport_indexC, *io, transport_type)); + *ierr = static_cast(adios2_add_transport(&transport_indexC, *io, transport_type)); if (*ierr == static_cast(adios2_error_none)) { *transport_index = static_cast(transport_indexC); @@ -98,10 +92,8 @@ void FC_GLOBAL(adios2_add_transport_f2c, } void FC_GLOBAL(adios2_set_transport_parameter_f2c, - ADIOS2_SET_TRANSPORT_PARAMETER_F2C)(adios2_io **io, - const int *transport_index, - const char *key, - const char *value, int *ierr) + ADIOS2_SET_TRANSPORT_PARAMETER_F2C)(adios2_io **io, const int *transport_index, + const char *key, const char *value, int *ierr) { if (*transport_index < 0) { @@ -109,31 +101,27 @@ void FC_GLOBAL(adios2_set_transport_parameter_f2c, "in call to " "adios2_set_transport_parameter"); } - const std::size_t transport_indexC = - static_cast(*transport_index); - *ierr = static_cast( - adios2_set_transport_parameter(*io, transport_indexC, key, value)); + const std::size_t transport_indexC = static_cast(*transport_index); + *ierr = static_cast(adios2_set_transport_parameter(*io, transport_indexC, key, value)); } // needed due to lack of nullptr in Fortran void FC_GLOBAL(adios2_define_global_variable_f2c, - ADIOS2_DEFINE_GLOBAL_VARIABLE_F2C)(adios2_variable **variable, - adios2_io **io, - const char *name, - const int *type, int *ierr) + ADIOS2_DEFINE_GLOBAL_VARIABLE_F2C)(adios2_variable **variable, adios2_io **io, + const char *name, const int *type, int *ierr) { - *variable = adios2_define_variable( - *io, name, static_cast(*type), 0, nullptr, nullptr, - nullptr, adios2_constant_dims_true); + *variable = adios2_define_variable(*io, name, static_cast(*type), 0, nullptr, + nullptr, nullptr, adios2_constant_dims_true); *ierr = (*variable == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( - adios2_variable **variable, adios2_io **io, const char *name, - const int *type, const int *ndims, const int64_t *shape, - const int64_t *start, const int64_t *count, const int *constant_dims, - int *ierr) +void FC_GLOBAL(adios2_define_variable_f2c, + ADIOS2_DEFINE_VARIABLE_F2C)(adios2_variable **variable, adios2_io **io, + const char *name, const int *type, const int *ndims, + const int64_t *shape, const int64_t *start, + const int64_t *count, const int *constant_dims, + int *ierr) { auto lf_IntToSizeT = [](const int64_t *dimensions, const int size, const std::string hint) -> adios2::Dims { @@ -143,9 +131,8 @@ void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( { if (dimensions[d] < 0) { - throw std::invalid_argument( - "ERROR: negative dimension " + hint + - ", in call to adios2_define_variable"); + throw std::invalid_argument("ERROR: negative dimension " + hint + + ", in call to adios2_define_variable"); } output[d] = dimensions[d]; } @@ -156,9 +143,8 @@ void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( { if (*ndims <= 0) { - throw std::invalid_argument( - "ERROR: negative ndims in Fortran, in call to " - "adios2_define_variable"); + throw std::invalid_argument("ERROR: negative ndims in Fortran, in call to " + "adios2_define_variable"); } // Check for local value @@ -170,12 +156,10 @@ void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( shapeC[0] = adios2_local_value_dim; *variable = adios2_define_variable( - *io, name, static_cast(*type), *ndims, shapeC, - nullptr, nullptr, + *io, name, static_cast(*type), *ndims, shapeC, nullptr, nullptr, static_cast(*constant_dims)); - *ierr = (*variable == NULL) - ? static_cast(adios2_error_exception) - : static_cast(adios2_error_none); + *ierr = (*variable == NULL) ? static_cast(adios2_error_exception) + : static_cast(adios2_error_none); return; } } @@ -184,22 +168,19 @@ void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( { if (start[0] != -1) { - throw std::invalid_argument( - "ERROR: both shape and start must be " - "adios2_null_dims when declaring " - "local variables in Fortran, in call to " - "adios2_define_variable"); + throw std::invalid_argument("ERROR: both shape and start must be " + "adios2_null_dims when declaring " + "local variables in Fortran, in call to " + "adios2_define_variable"); } const adios2::Dims countV = lf_IntToSizeT(count, *ndims, "count"); - *variable = adios2_define_variable( - *io, name, static_cast(*type), *ndims, nullptr, - nullptr, countV.data(), - static_cast(*constant_dims)); - *ierr = (*variable == NULL) - ? static_cast(adios2_error_exception) - : static_cast(adios2_error_none); + *variable = adios2_define_variable(*io, name, static_cast(*type), *ndims, + nullptr, nullptr, countV.data(), + static_cast(*constant_dims)); + *ierr = (*variable == NULL) ? static_cast(adios2_error_exception) + : static_cast(adios2_error_none); return; } @@ -207,17 +188,16 @@ void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)( const adios2::Dims startV = lf_IntToSizeT(start, *ndims, "start"); const adios2::Dims countV = lf_IntToSizeT(count, *ndims, "count"); - *variable = adios2_define_variable( - *io, name, static_cast(*type), - static_cast(*ndims), shapeV.data(), startV.data(), - countV.data(), static_cast(*constant_dims)); + *variable = adios2_define_variable(*io, name, static_cast(*type), + static_cast(*ndims), shapeV.data(), + startV.data(), countV.data(), + static_cast(*constant_dims)); *ierr = (*variable == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } catch (std::exception &e) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_define_variable")); + *ierr = static_cast(adios2::helper::ExceptionToError("adios2_define_variable")); } } @@ -228,9 +208,7 @@ struct cnamelist }; void FC_GLOBAL(adios2_available_variables_f2c, - ADIOS2_AVAILABLE_VARIABLES_F2C)(adios2_io **io, - int64_t *namestruct, - int *vars_count, + ADIOS2_AVAILABLE_VARIABLES_F2C)(adios2_io **io, int64_t *namestruct, int *vars_count, int *max_var_name_len, int *ierr) { cnamelist *info = new (cnamelist); @@ -251,11 +229,8 @@ void FC_GLOBAL(adios2_available_variables_f2c, } void FC_GLOBAL(adios2_available_attributes_f2c, - ADIOS2_AVAILABLE_ATTRIBUTES_F2C)(adios2_io **io, - int64_t *namestruct, - int *attrs_count, - int *max_attr_name_len, - int *ierr) + ADIOS2_AVAILABLE_ATTRIBUTES_F2C)(adios2_io **io, int64_t *namestruct, + int *attrs_count, int *max_attr_name_len, int *ierr) { cnamelist *info = new (cnamelist); info->names = adios2_available_attributes(*io, &info->count); @@ -277,8 +252,7 @@ void FC_GLOBAL(adios2_available_attributes_f2c, } void FC_GLOBAL(adios2_retrieve_namelist_f2c, - ADIOS2_RETRIEVE_NAMELIST_F2C)(int64_t *namestruct, - void *namelist, int *ierr, + ADIOS2_RETRIEVE_NAMELIST_F2C)(int64_t *namestruct, void *namelist, int *ierr, int namelist_len) { cnamelist *info = reinterpret_cast(*namestruct); @@ -308,9 +282,8 @@ void FC_GLOBAL(adios2_retrieve_namelist_f2c, } void FC_GLOBAL(adios2_inquire_variable_f2c, - ADIOS2_INQUIRE_VARIABLE_F2C)(adios2_variable **variable, - adios2_io **io, const char *name, - int *ierr) + ADIOS2_INQUIRE_VARIABLE_F2C)(adios2_variable **variable, adios2_io **io, + const char *name, int *ierr) { *variable = adios2_inquire_variable(*io, name); @@ -318,9 +291,8 @@ void FC_GLOBAL(adios2_inquire_variable_f2c, : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_remove_variable_f2c, - ADIOS2_REMOVE_VARIABLE_F2C)(int *result, adios2_io **io, - const char *name, int *ierr) +void FC_GLOBAL(adios2_remove_variable_f2c, ADIOS2_REMOVE_VARIABLE_F2C)(int *result, adios2_io **io, + const char *name, int *ierr) { adios2_bool resultC; *ierr = static_cast(adios2_remove_variable(&resultC, *io, name)); @@ -330,40 +302,37 @@ void FC_GLOBAL(adios2_remove_variable_f2c, } } -void FC_GLOBAL(adios2_remove_all_variables_f2c, - ADIOS2_REMOVE_ALL_VARIABLES_F2C)(adios2_io **io, int *ierr) +void FC_GLOBAL(adios2_remove_all_variables_f2c, ADIOS2_REMOVE_ALL_VARIABLES_F2C)(adios2_io **io, + int *ierr) { *ierr = static_cast(adios2_remove_all_variables(*io)); } void FC_GLOBAL(adios2_define_vattr_f2c, - ADIOS2_DEFINE_VATTR_F2C)(adios2_attribute **attribute, - adios2_io **io, const char *name, - const int *type, const void *value, - const char *variable_name, - const char *separator, int *ierr) + ADIOS2_DEFINE_VATTR_F2C)(adios2_attribute **attribute, adios2_io **io, + const char *name, const int *type, const void *value, + const char *variable_name, const char *separator, int *ierr) { - *attribute = adios2_define_variable_attribute( - *io, name, static_cast(*type), value, variable_name, - separator); + *attribute = adios2_define_variable_attribute(*io, name, static_cast(*type), value, + variable_name, separator); *ierr = (*attribute == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_define_vattr_array_f2c, ADIOS2_DEFINE_VATTR_ARRAY_F2C)( - adios2_attribute **attribute, adios2_io **io, const char *name, - const int *type, const void *data, const int *size, - const char *variable_name, const char *separator, int *ierr) +void FC_GLOBAL(adios2_define_vattr_array_f2c, + ADIOS2_DEFINE_VATTR_ARRAY_F2C)(adios2_attribute **attribute, adios2_io **io, + const char *name, const int *type, const void *data, + const int *size, const char *variable_name, + const char *separator, int *ierr) { try { if (*size < 1) { - throw std::invalid_argument( - "ERROR: attribute " + std::string(name) + - " array size must be larger or equal to 1, in call to " - "adios2_define_attribute\n"); + throw std::invalid_argument("ERROR: attribute " + std::string(name) + + " array size must be larger or equal to 1, in call to " + "adios2_define_attribute\n"); } if (*type == adios2_type_string) @@ -376,17 +345,13 @@ void FC_GLOBAL(adios2_define_vattr_array_f2c, ADIOS2_DEFINE_VATTR_ARRAY_F2C)( { char2D[i] = new char[adios2_string_array_element_max_size]; - const char *fstringMemory = - reinterpret_cast(data); + const char *fstringMemory = reinterpret_cast(data); - strcpy( - char2D[i], - &fstringMemory[i * adios2_string_array_element_max_size]); + strcpy(char2D[i], &fstringMemory[i * adios2_string_array_element_max_size]); } *attribute = adios2_define_variable_attribute_array( - *io, name, static_cast(*type), - static_cast(char2D), + *io, name, static_cast(*type), static_cast(char2D), static_cast(*size), variable_name, separator); delete[] char2D; @@ -394,8 +359,8 @@ void FC_GLOBAL(adios2_define_vattr_array_f2c, ADIOS2_DEFINE_VATTR_ARRAY_F2C)( else { *attribute = adios2_define_variable_attribute_array( - *io, name, static_cast(*type), data, - static_cast(*size), variable_name, separator); + *io, name, static_cast(*type), data, static_cast(*size), + variable_name, separator); } *ierr = (*attribute == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); @@ -407,10 +372,8 @@ void FC_GLOBAL(adios2_define_vattr_array_f2c, ADIOS2_DEFINE_VATTR_ARRAY_F2C)( } void FC_GLOBAL(adios2_inquire_attribute_f2c, - ADIOS2_INQUIRE_ATTRIBUTE_F2C)(adios2_attribute **attribute, - adios2_io **io, - const char *attribute_name, - int *ierr) + ADIOS2_INQUIRE_ATTRIBUTE_F2C)(adios2_attribute **attribute, adios2_io **io, + const char *attribute_name, int *ierr) { *attribute = adios2_inquire_attribute(*io, attribute_name); *ierr = (*attribute == NULL) ? static_cast(adios2_error_exception) @@ -418,19 +381,19 @@ void FC_GLOBAL(adios2_inquire_attribute_f2c, } void FC_GLOBAL(adios2_inquire_variable_attribute_f2c, - ADIOS2_INQUIRE_VARIABLE_ATTRIBUTE_F2C)( - adios2_attribute **attribute, adios2_io **io, const char *attribute_name, - const char *variable_name, const char *separator, int *ierr) + ADIOS2_INQUIRE_VARIABLE_ATTRIBUTE_F2C)(adios2_attribute **attribute, adios2_io **io, + const char *attribute_name, + const char *variable_name, + const char *separator, int *ierr) { - *attribute = adios2_inquire_variable_attribute(*io, attribute_name, - variable_name, separator); + *attribute = adios2_inquire_variable_attribute(*io, attribute_name, variable_name, separator); *ierr = (*attribute == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } void FC_GLOBAL(adios2_remove_attribute_f2c, - ADIOS2_REMOVE_ATTRIBUTE_F2C)(int *result, adios2_io **io, - const char *name, int *ierr) + ADIOS2_REMOVE_ATTRIBUTE_F2C)(int *result, adios2_io **io, const char *name, + int *ierr) { adios2_bool resultC; *ierr = static_cast(adios2_remove_attribute(&resultC, *io, name)); @@ -440,40 +403,35 @@ void FC_GLOBAL(adios2_remove_attribute_f2c, } } -void FC_GLOBAL(adios2_remove_all_attributes_f2c, - ADIOS2_REMOVE_ALL_ATTRIBUTES_F2C)(adios2_io **io, int *ierr) +void FC_GLOBAL(adios2_remove_all_attributes_f2c, ADIOS2_REMOVE_ALL_ATTRIBUTES_F2C)(adios2_io **io, + int *ierr) { *ierr = static_cast(adios2_remove_all_attributes(*io)); } -void FC_GLOBAL(adios2_open_f2c, - ADIOS2_OPEN_F2C)(adios2_engine **engine, adios2_io **io, - const char *name, const int *open_mode, - int *ierr) +void FC_GLOBAL(adios2_open_f2c, ADIOS2_OPEN_F2C)(adios2_engine **engine, adios2_io **io, + const char *name, const int *open_mode, int *ierr) { *engine = adios2_open(*io, name, static_cast(*open_mode)); *ierr = (*engine == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } -void FC_GLOBAL(adios2_flush_all_engines_f2c, - ADIOS2_FLUSH_ALL_ENGINES_F2C)(adios2_io **io, int *ierr) +void FC_GLOBAL(adios2_flush_all_engines_f2c, ADIOS2_FLUSH_ALL_ENGINES_F2C)(adios2_io **io, + int *ierr) { *ierr = static_cast(adios2_flush_all_engines(*io)); } void FC_GLOBAL(adios2_io_engine_type_f2c, - ADIOS2_IO_ENGINE_TYPE_F2C)(char *type, const adios2_io **io, - int *ierr) + ADIOS2_IO_ENGINE_TYPE_F2C)(char *type, const adios2_io **io, int *ierr) { size_t sizeC; *ierr = static_cast(adios2_engine_type(type, &sizeC, *io)); } void FC_GLOBAL(adios2_io_engine_type_length_f2c, - ADIOS2_io_ENGINE_TYPE_LENGTH_F2C)(int *size, - const adios2_io **io, - int *ierr) + ADIOS2_io_ENGINE_TYPE_LENGTH_F2C)(int *size, const adios2_io **io, int *ierr) { *size = -1; size_t sizeC; diff --git a/bindings/Fortran/f2c/adios2_f2c_io_mpi.cpp b/bindings/Fortran/f2c/adios2_f2c_io_mpi.cpp index 1953a3c870..d4dd8bd18a 100644 --- a/bindings/Fortran/f2c/adios2_f2c_io_mpi.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_io_mpi.cpp @@ -12,17 +12,15 @@ extern "C" { -extern adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, - const adios2_mode mode, +extern adios2_engine *adios2_open_new_comm(adios2_io *io, const char *name, const adios2_mode mode, MPI_Comm comm); void FC_GLOBAL(adios2_open_new_comm_f2c, - ADIOS2_OPEN_NEW_COMM_F2C)(adios2_engine **engine, adios2_io **io, - const char *name, const int *open_mode, - MPI_Fint *comm, int *ierr) + ADIOS2_OPEN_NEW_COMM_F2C)(adios2_engine **engine, adios2_io **io, const char *name, + const int *open_mode, MPI_Fint *comm, int *ierr) { - *engine = adios2_open_new_comm( - *io, name, static_cast(*open_mode), MPI_Comm_f2c(*comm)); + *engine = + adios2_open_new_comm(*io, name, static_cast(*open_mode), MPI_Comm_f2c(*comm)); *ierr = (*engine == NULL) ? static_cast(adios2_error_exception) : static_cast(adios2_error_none); } diff --git a/bindings/Fortran/f2c/adios2_f2c_operator.cpp b/bindings/Fortran/f2c/adios2_f2c_operator.cpp index 1168d54602..9341a11df3 100644 --- a/bindings/Fortran/f2c/adios2_f2c_operator.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_operator.cpp @@ -15,17 +15,14 @@ extern "C" { #endif void FC_GLOBAL(adios2_operator_type_f2c, - ADIOS2_OPERATOR_TYPE_F2C)(char *type, const adios2_operator **op, - int *ierr) + ADIOS2_OPERATOR_TYPE_F2C)(char *type, const adios2_operator **op, int *ierr) { size_t sizeC; *ierr = static_cast(adios2_operator_type(type, &sizeC, *op)); } void FC_GLOBAL(adios2_operator_type_length_f2c, - ADIOS2_OPERATOR_TYPE_LENGTH_F2C)(int *size, - const adios2_operator **op, - int *ierr) + ADIOS2_OPERATOR_TYPE_LENGTH_F2C)(int *size, const adios2_operator **op, int *ierr) { *size = -1; size_t sizeC; diff --git a/bindings/Fortran/f2c/adios2_f2c_variable.cpp b/bindings/Fortran/f2c/adios2_f2c_variable.cpp index 79bf50a3a6..b03ac1ef84 100644 --- a/bindings/Fortran/f2c/adios2_f2c_variable.cpp +++ b/bindings/Fortran/f2c/adios2_f2c_variable.cpp @@ -17,17 +17,15 @@ extern "C" { #endif void FC_GLOBAL(adios2_variable_name_f2c, - ADIOS2_VARIABLE_NAME_F2C)(char *name, - const adios2_variable **variable, - int *ierr) + ADIOS2_VARIABLE_NAME_F2C)(char *name, const adios2_variable **variable, int *ierr) { size_t sizeC; *ierr = static_cast(adios2_variable_name(name, &sizeC, *variable)); } void FC_GLOBAL(adios2_variable_name_length_f2c, - ADIOS2_VARIABLE_NAME_LENGTH_F2C)( - int *size, const adios2_variable **variable, int *ierr) + ADIOS2_VARIABLE_NAME_LENGTH_F2C)(int *size, const adios2_variable **variable, + int *ierr) { *size = -1; size_t sizeC; @@ -39,9 +37,7 @@ void FC_GLOBAL(adios2_variable_name_length_f2c, } void FC_GLOBAL(adios2_variable_type_f2c, - ADIOS2_VARIABLE_TYPE_F2C)(int *type, - const adios2_variable **variable, - int *ierr) + ADIOS2_VARIABLE_TYPE_F2C)(int *type, const adios2_variable **variable, int *ierr) { *type = -1; adios2_type typeC; @@ -53,9 +49,7 @@ void FC_GLOBAL(adios2_variable_type_f2c, } void FC_GLOBAL(adios2_variable_ndims_f2c, - ADIOS2_VARIABLE_NDIMS_F2C)(int *ndims, - const adios2_variable **variable, - int *ierr) + ADIOS2_VARIABLE_NDIMS_F2C)(int *ndims, const adios2_variable **variable, int *ierr) { *ndims = -1; size_t ndimsC; @@ -67,8 +61,7 @@ void FC_GLOBAL(adios2_variable_ndims_f2c, } void FC_GLOBAL(adios2_variable_shape_f2c, - ADIOS2_VARIABLE_SHAPE_F2C)(int64_t *shape, - const adios2_variable **variable, + ADIOS2_VARIABLE_SHAPE_F2C)(int64_t *shape, const adios2_variable **variable, int *ierr) { size_t ndims; @@ -92,8 +85,7 @@ void FC_GLOBAL(adios2_variable_shape_f2c, } void FC_GLOBAL(adios2_variable_steps_f2c, - adios2_variable_STEPS_F2C)(int64_t *steps, - const adios2_variable **variable, + adios2_variable_STEPS_F2C)(int64_t *steps, const adios2_variable **variable, int *ierr) { *steps = -1; @@ -105,10 +97,9 @@ void FC_GLOBAL(adios2_variable_steps_f2c, } } -void FC_GLOBAL(adios2_set_shape_f2c, - ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable, - const int *ndims, const int64_t *shape, - int *ierr) +void FC_GLOBAL(adios2_set_shape_f2c, ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable, + const int *ndims, const int64_t *shape, + int *ierr) { auto lf_IntToSizeT = [](const int64_t *dimensions, const int size, std::vector &output) { @@ -130,31 +121,26 @@ void FC_GLOBAL(adios2_set_shape_f2c, } std::vector shapeV; lf_IntToSizeT(shape, *ndims, shapeV); - *ierr = static_cast( - adios2_set_shape(*variable, *ndims, shapeV.data())); + *ierr = static_cast(adios2_set_shape(*variable, *ndims, shapeV.data())); } catch (...) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_set_shape")); + *ierr = static_cast(adios2::helper::ExceptionToError("adios2_set_shape")); } } void FC_GLOBAL(adios2_set_block_selection_f2c, - ADIOS2_SET_BLOCK_SELECTION_F2C)(adios2_variable **variable, - const int64_t *block_id, + ADIOS2_SET_BLOCK_SELECTION_F2C)(adios2_variable **variable, const int64_t *block_id, int *ierr) { *ierr = static_cast(adios2_set_block_selection(*variable, *block_id)); } void FC_GLOBAL(adios2_set_selection_f2c, - ADIOS2_SET_SELECTION_F2C)(adios2_variable **variable, - const int *ndims, const int64_t *start, - const int64_t *count, int *ierr) + ADIOS2_SET_SELECTION_F2C)(adios2_variable **variable, const int *ndims, + const int64_t *start, const int64_t *count, int *ierr) { - auto lf_IntToSizeT = [](const int64_t *input, - const int size) -> std::vector { + auto lf_IntToSizeT = [](const int64_t *input, const int size) -> std::vector { std::vector output; output.reserve(size); @@ -184,31 +170,27 @@ void FC_GLOBAL(adios2_set_selection_f2c, // local array selection if (start[0] == -1) { - *ierr = static_cast(adios2_set_selection( - *variable, *ndims, nullptr, countV.data())); + *ierr = + static_cast(adios2_set_selection(*variable, *ndims, nullptr, countV.data())); } // global array selection else { - const std::vector startV = - lf_IntToSizeT(start, *ndims); - *ierr = static_cast(adios2_set_selection( - *variable, *ndims, startV.data(), countV.data())); + const std::vector startV = lf_IntToSizeT(start, *ndims); + *ierr = static_cast( + adios2_set_selection(*variable, *ndims, startV.data(), countV.data())); } } catch (...) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_set_selection")); + *ierr = static_cast(adios2::helper::ExceptionToError("adios2_set_selection")); } } void FC_GLOBAL(adios2_set_memory_selection_f2c, - ADIOS2_SET_MEMORY_SELECTION_F2C)(adios2_variable **variable, - const int *ndims, + ADIOS2_SET_MEMORY_SELECTION_F2C)(adios2_variable **variable, const int *ndims, const int64_t *memory_start, - const int64_t *memory_count, - int *ierr) + const int64_t *memory_count, int *ierr) { auto lf_IntToSizeT = [](const int64_t *dimensions, const int size, std::vector &output) { @@ -222,8 +204,7 @@ void FC_GLOBAL(adios2_set_memory_selection_f2c, try { - if (memory_start == nullptr || memory_count == nullptr || - ndims == nullptr) + if (memory_start == nullptr || memory_count == nullptr || ndims == nullptr) { throw std::invalid_argument("ERROR: either start_dims, count_dims " "or ndims is a null pointer, in call " @@ -232,30 +213,26 @@ void FC_GLOBAL(adios2_set_memory_selection_f2c, std::vector memoryStartV, memoryCountV; lf_IntToSizeT(memory_start, *ndims, memoryStartV); lf_IntToSizeT(memory_count, *ndims, memoryCountV); - *ierr = static_cast(adios2_set_memory_selection( - *variable, *ndims, memoryStartV.data(), memoryCountV.data())); + *ierr = static_cast(adios2_set_memory_selection(*variable, *ndims, memoryStartV.data(), + memoryCountV.data())); } catch (...) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_set_memory_selection")); + *ierr = static_cast(adios2::helper::ExceptionToError("adios2_set_memory_selection")); } } void FC_GLOBAL(adios2_set_step_selection_f2c, - ADIOS2_SET_STEP_SELECTION_F2C)(adios2_variable **variable, - const int64_t *step_start, - const int64_t *step_count, - int *ierr) + ADIOS2_SET_STEP_SELECTION_F2C)(adios2_variable **variable, const int64_t *step_start, + const int64_t *step_count, int *ierr) { try { if (step_start == nullptr || step_count == nullptr) { - throw std::invalid_argument( - "ERROR: either step_start or step_count " - "are null pointers, in call to " - "adios2_set_step_selection\n"); + throw std::invalid_argument("ERROR: either step_start or step_count " + "are null pointers, in call to " + "adios2_set_step_selection\n"); } if (step_start[0] < 0) @@ -276,21 +253,18 @@ void FC_GLOBAL(adios2_set_step_selection_f2c, } catch (...) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_set_selection")); + *ierr = static_cast(adios2::helper::ExceptionToError("adios2_set_selection")); } } void FC_GLOBAL(adios2_add_operation_f2c, - ADIOS2_ADD_OPERATION_F2C)(int *operation_id, - adios2_variable **variable, - adios2_operator **op, const char *key, - const char *value, int *ierr) + ADIOS2_ADD_OPERATION_F2C)(int *operation_id, adios2_variable **variable, + adios2_operator **op, const char *key, const char *value, + int *ierr) { *operation_id = -1; size_t operation_idC; - *ierr = static_cast( - adios2_add_operation(&operation_idC, *variable, *op, key, value)); + *ierr = static_cast(adios2_add_operation(&operation_idC, *variable, *op, key, value)); if (*ierr == static_cast(adios2_error_none)) { *operation_id = static_cast(operation_idC); @@ -299,8 +273,7 @@ void FC_GLOBAL(adios2_add_operation_f2c, void FC_GLOBAL(adios2_set_operation_parameter_f2c, ADIOS2_SET_OPERATION_PARAMETER_F2C)(adios2_variable **variable, - const int *operation_id, - const char *key, + const int *operation_id, const char *key, const char *value, int *ierr) { try @@ -317,30 +290,25 @@ void FC_GLOBAL(adios2_set_operation_parameter_f2c, } catch (...) { - *ierr = static_cast( - adios2::helper::ExceptionToError("adios2_set_operation_parameter")); + *ierr = + static_cast(adios2::helper::ExceptionToError("adios2_set_operation_parameter")); } } void FC_GLOBAL(adios2_remove_operations_f2c, - ADIOS2_REMOVE_OPERATIONS_F2C)(adios2_variable **variable, - int *ierr) + ADIOS2_REMOVE_OPERATIONS_F2C)(adios2_variable **variable, int *ierr) { *ierr = static_cast(adios2_remove_operations(*variable)); } void FC_GLOBAL(adios2_variable_min_f2c, - ADIOS2_VARIABLE_MIN_F2C)(void *min, - const adios2_variable **variable, - int *ierr) + ADIOS2_VARIABLE_MIN_F2C)(void *min, const adios2_variable **variable, int *ierr) { *ierr = static_cast(adios2_variable_min(min, *variable)); } void FC_GLOBAL(adios2_variable_max_f2c, - ADIOS2_VARIABLE_MAX_F2C)(void *max, - const adios2_variable **variable, - int *ierr) + ADIOS2_VARIABLE_MAX_F2C)(void *max, const adios2_variable **variable, int *ierr) { *ierr = static_cast(adios2_variable_max(max, *variable)); } diff --git a/bindings/Matlab/README.txt b/bindings/Matlab/README.txt index 4c43c89ffe..0a5b412ce0 100644 --- a/bindings/Matlab/README.txt +++ b/bindings/Matlab/README.txt @@ -43,5 +43,5 @@ $ cd $ git pull $ mkdir build.lean $ cd build.lean -$ cmake -DCMAKE_INSTALL_PREFIX=/opt/adios/lean -DADIOS2_USE_MPI=OFF -DADIOS2_USE_Fortran=OFF -DADIOS2_USE_Python=OFF -DADIOS2_BUILD_EXAMPLES_EXPERIMENTAL=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DADIOS2_ENABLE_PIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_TESTING=OFF -DADIOS2_USE_SST=OFF -DADIOS2_USE_BZip2=OFF -DADIOS2_USE_DataMan=OFF .. +$ cmake -DCMAKE_INSTALL_PREFIX=/opt/adios/lean -DADIOS2_USE_MPI=OFF -DADIOS2_USE_Fortran=OFF -DADIOS2_USE_Python=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DADIOS2_ENABLE_PIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DADIOS2_USE_SST=OFF -DADIOS2_USE_BZip2=OFF -DADIOS2_USE_DataMan=OFF .. diff --git a/bindings/Matlab/adiosclosec.c b/bindings/Matlab/adiosclosec.c index 73b1af5941..b5f089b66d 100644 --- a/bindings/Matlab/adiosclosec.c +++ b/bindings/Matlab/adiosclosec.c @@ -84,16 +84,14 @@ void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]) if (nrhs != 3) { - mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs", - "This function needs exactly 3 arguments: " - "FileHandler, ADIOSHandler, Verbose"); + mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs", "This function needs exactly 3 arguments: " + "FileHandler, ADIOSHandler, Verbose"); } if (!mxIsUint64(prhs[0])) { - mexErrMsgIdAndTxt( - "MATLAB:adiosclosec:rhs", - "First arg must be an uint64 handler to an ADIOS file ."); + mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs", + "First arg must be an uint64 handler to an ADIOS file ."); } if (!mxIsUint64(prhs[1])) @@ -104,8 +102,7 @@ void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]) if (!mxIsNumeric(prhs[2])) { - mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs", - "Third arg must be a number."); + mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs", "Third arg must be a number."); } if (nlhs > 0) diff --git a/bindings/Matlab/adiosopenc.c b/bindings/Matlab/adiosopenc.c index 1147ee32e9..95dc6d41b3 100644 --- a/bindings/Matlab/adiosopenc.c +++ b/bindings/Matlab/adiosopenc.c @@ -50,10 +50,9 @@ static int verbose = 0; mxClassID adiostypeToMatlabClass(int adiostype, mxComplexity *complexity); size_t adiostypeToMemSize(adios2_type adiostype); -mxArray *valueToMatlabValue(const void *data, mxClassID mxtype, +mxArray *valueToMatlabValue(const void *data, mxClassID mxtype, mxComplexity complexFlag); +mxArray *arrayToMatlabArray(const void *data, const size_t nelems, mxClassID mxtype, mxComplexity complexFlag); -mxArray *arrayToMatlabArray(const void *data, const size_t nelems, - mxClassID mxtype, mxComplexity complexFlag); void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]); char *getString(const mxArray *mxstr); static size_t *swap_order(size_t n, const size_t *array); @@ -71,8 +70,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) size_t nvars, nattrs; /* Number of variables and attributes */ adios2_variable **adios_vars; /* List of variable objects */ adios2_attribute **adios_attrs; /* List of attribute objects */ - int mpi_comm_dummy; /* ADIOS read API needs an MPI communicator */ - void *data; /* Attributes return their values */ + int mpi_comm_dummy; /* ADIOS read API needs an MPI communicator */ + void *data; /* Attributes return their values */ size_t vi, ai, i; /* loop variables for vars and attrs */ mxArray *arr; /* temp array for constructions */ @@ -81,32 +80,27 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxComplexity complexFlag; /* Output structure definition */ - const char *top_field_names[] = { - "Name", "Handlers", "Variables", - "Attributes"}; /* top level struct fields */ + const char *top_field_names[] = {"Name", "Handlers", "Variables", + "Attributes"}; /* top level struct fields */ mwSize ntopfields = 4; - mwSize top_struct_dims[] = { - 1, 1}; /* dimensions for top level struct array: 1-by-1 */ + mwSize top_struct_dims[] = {1, 1}; /* dimensions for top level struct array: 1-by-1 */ int top_field_Name; int top_field_Handlers; int top_field_Variables; int top_field_Attributes; /* Handlers structure definition */ - const char *handler_field_names[] = { - "FileHandler", "GroupHandler", - "ADIOSHandler"}; /* handler level struct fields */ + const char *handler_field_names[] = {"FileHandler", "GroupHandler", + "ADIOSHandler"}; /* handler level struct fields */ mwSize nhandlerfields = 3; - mwSize handler_struct_dims[] = { - 1, 1}; /* dimensions for handler level struct array: 1-by-1 */ + mwSize handler_struct_dims[] = {1, 1}; /* dimensions for handler level struct array: 1-by-1 */ int handler_field_FileHandler; int handler_field_GroupHandler; int handler_field_ADIOSHandler; - const char - *var_field_names[] = {"Name", "Type", "Dims", - "StepsStart", "StepsCount", "GlobalMin", - "GlobalMax"}; /* variable level struct fields */ + const char *var_field_names[] = { + "Name", "Type", "Dims", "StepsStart", + "StepsCount", "GlobalMin", "GlobalMax"}; /* variable level struct fields */ mwSize nvarfields = 7; mwSize var_struct_dims[2]; /* dimensions for variable level struct array: 1-by-sth */ @@ -118,8 +112,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) int var_field_GlobalMin; int var_field_GlobalMax; - const char *attr_field_names[] = { - "Name", "Type", "Value"}; /* attribute level struct fields */ + const char *attr_field_names[] = {"Name", "Type", "Value"}; /* attribute level struct fields */ mwSize nattrfields = 3; mwSize attr_struct_dims[2]; /* dimensions for attribute level struct array: 1-by-sth */ @@ -152,22 +145,19 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) fp = adios2_open(group, fname, adios2_mode_read); if (fp == NULL) { - mexErrMsgIdAndTxt("MATLAB:adiosopenc:open", - "Opening the file failed\n"); + mexErrMsgIdAndTxt("MATLAB:adiosopenc:open", "Opening the file failed\n"); } adios2_inquire_all_variables(&adios_vars, &nvars, group); adios2_inquire_all_attributes(&adios_attrs, &nattrs, group); if (verbose) - mexPrintf("Opened file fp=%lld nvars=%zu nattrs=%zu\n", (int64_t)fp, - nvars, nattrs); + mexPrintf("Opened file fp=%lld nvars=%zu nattrs=%zu\n", (int64_t)fp, nvars, nattrs); /******************************/ /* Create top level structure */ if (verbose) mexPrintf("Create top struct array, 1-by-1\n"); - plhs[0] = - mxCreateStructArray(2, top_struct_dims, ntopfields, top_field_names); + plhs[0] = mxCreateStructArray(2, top_struct_dims, ntopfields, top_field_names); top_field_Name = mxGetFieldNumber(plhs[0], "Name"); top_field_Handlers = mxGetFieldNumber(plhs[0], "Handlers"); top_field_Variables = mxGetFieldNumber(plhs[0], "Variables"); @@ -177,8 +167,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) /* Create top.Handlers structure array */ if (verbose) mexPrintf("Create top.Handlers struct array, 1-by-1\n"); - handlers = mxCreateStructArray(2, handler_struct_dims, nhandlerfields, - handler_field_names); + handlers = mxCreateStructArray(2, handler_struct_dims, nhandlerfields, handler_field_names); mxSetFieldByNumber(plhs[0], 0, top_field_Handlers, handlers); /* Create top.Variables structure array */ @@ -194,8 +183,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mexPrintf("Create top.Attributes struct array, 1-by-%zu\n", nattrs); attr_struct_dims[0] = 1; attr_struct_dims[1] = nattrs; - attrs = - mxCreateStructArray(2, attr_struct_dims, nattrfields, attr_field_names); + attrs = mxCreateStructArray(2, attr_struct_dims, nattrfields, attr_field_names); mxSetFieldByNumber(plhs[0], 0, top_field_Attributes, attrs); /****************************/ @@ -246,8 +234,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) adios2_variable_type(&adiostype, avar); mxtype = adiostypeToMatlabClass(adiostype, &complexFlag); arr = mxCreateNumericMatrix(1, 1, mxtype, complexFlag); - mxSetFieldByNumber(vars, vi, var_field_Type, - mxCreateString(mxGetClassName(arr))); + mxSetFieldByNumber(vars, vi, var_field_Type, mxCreateString(mxGetClassName(arr))); mxDestroyArray(arr); /* field DIMS */ size_t ndim; @@ -260,8 +247,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (verbose > 1) { - mexPrintf(" %s: ndims=%d, adios type=%d, dimensions [", - varname, ndim, adiostype); + mexPrintf(" %s: ndims=%d, adios type=%d, dimensions [", varname, ndim, adiostype); for (i = 0; i < ndim; i++) mexPrintf("%lld ", mxdims[i]); mexPrintf("]\n"); @@ -338,8 +324,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) adios2_attribute_name(attrname, &namelen, aa); attrname[namelen] = '\0'; - mxSetFieldByNumber(attrs, ai, attr_field_Name, - mxCreateString(attrname)); + mxSetFieldByNumber(attrs, ai, attr_field_Name, mxCreateString(attrname)); /* field TYPE */ size_t typelen; adios2_type adiostype; @@ -351,8 +336,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxtype = adiostypeToMatlabClass(adiostype, &complexFlag); arr = mxCreateNumericMatrix(1, 1, mxtype, complexFlag); - mxSetFieldByNumber(attrs, ai, attr_field_Type, - mxCreateString(mxGetClassName(arr))); + mxSetFieldByNumber(attrs, ai, attr_field_Type, mxCreateString(mxGetClassName(arr))); mxDestroyArray(arr); /* field VALUE */ size_t aelems; @@ -404,8 +388,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxSetFieldByNumber(attrs, ai, attr_field_Value, arr); } if (verbose > 1) - mexPrintf(" %s: adios type=%s size=%zu\n", attrname, - mxGetClassName(arr), aelems); + mexPrintf(" %s: adios type=%s size=%zu\n", attrname, mxGetClassName(arr), aelems); mxFree(data); } @@ -416,8 +399,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mexPrintf("return from adiosopenc\n"); } -mxArray *valueToMatlabValue(const void *data, mxClassID mxtype, - mxComplexity complexFlag) +mxArray *valueToMatlabValue(const void *data, mxClassID mxtype, mxComplexity complexFlag) { /* copies values in all cases, so one can free(data) later */ mxArray *arr; @@ -451,8 +433,8 @@ mxArray *valueToMatlabValue(const void *data, mxClassID mxtype, return arr; } -mxArray *arrayToMatlabArray(const void *data, const size_t nelems, - mxClassID mxtype, mxComplexity complexFlag) +mxArray *arrayToMatlabArray(const void *data, const size_t nelems, mxClassID mxtype, + mxComplexity complexFlag) { /* copies values in all cases, so one can free(data) later */ mxArray *arr; @@ -498,27 +480,23 @@ void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]) if (nrhs != 2) { - mexErrMsgIdAndTxt( - "MATLAB:adiosopenc:rhs", - "This function needs exactly 2 arguments: File, Verbose"); + mexErrMsgIdAndTxt("MATLAB:adiosopenc:rhs", + "This function needs exactly 2 arguments: File, Verbose"); } if (!mxIsChar(prhs[0])) { - mexErrMsgIdAndTxt("MATLAB:adiosopenc:rhs", - "First arg must be a string."); + mexErrMsgIdAndTxt("MATLAB:adiosopenc:rhs", "First arg must be a string."); } if (!mxIsNumeric(prhs[1])) { - mexErrMsgIdAndTxt("MATLAB:adiosopenc:rhs", - "Second arg must be a number."); + mexErrMsgIdAndTxt("MATLAB:adiosopenc:rhs", "Second arg must be a number."); } if (nlhs > 1) { - mexErrMsgIdAndTxt("MATLAB:adiosopenc:lhs", - "Too many output arguments."); + mexErrMsgIdAndTxt("MATLAB:adiosopenc:lhs", "Too many output arguments."); } } @@ -537,8 +515,7 @@ char *getString(const mxArray *mxstr) } /** return the appropriate class for an adios type (and complexity too) */ -mxClassID adiostypeToMatlabClass(adios2_type adiostype, - mxComplexity *complexity) +mxClassID adiostypeToMatlabClass(adios2_type adiostype, mxComplexity *complexity) { *complexity = mxREAL; switch (adiostype) @@ -581,8 +558,7 @@ mxClassID adiostypeToMatlabClass(adios2_type adiostype, default: mexErrMsgIdAndTxt("MATLAB:adiosopenc.c:dimensionTooLarge", - "Adios type id=%d not supported in matlab.\n", - adiostype); + "Adios type id=%d not supported in matlab.\n", adiostype); break; } return 0; /* just to avoid warnings. never executed */ @@ -625,8 +601,7 @@ size_t adiostypeToMemSize(adios2_type adiostype) default: mexErrMsgIdAndTxt("MATLAB:adiosopenc.c:dimensionTooLarge", - "Adios type id=%d not supported in matlab.\n", - adiostype); + "Adios type id=%d not supported in matlab.\n", adiostype); break; } return 0; /* just to avoid warnings. never executed */ diff --git a/bindings/Matlab/adiosreadc.c b/bindings/Matlab/adiosreadc.c index 224667d5be..bfa40645c7 100644 --- a/bindings/Matlab/adiosreadc.c +++ b/bindings/Matlab/adiosreadc.c @@ -32,9 +32,8 @@ static int verbose = 0; -mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, - mwSize in_noffsets, const int64_t *in_offsets, - const int64_t *in_counts, const int64_t in_stepstart, +mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, mwSize in_noffsets, + const int64_t *in_offsets, const int64_t *in_counts, const int64_t in_stepstart, const int64_t in_stepcount); void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]); void checkDimSize(const int ndims, const size_t *dims); @@ -42,11 +41,10 @@ char *getString(const mxArray *mxstr); mxClassID adiostypeToMatlabClass(int adiostype, mxComplexity *complexity); mxArray *createMatlabArray(int adiostype, size_t ndim, size_t *dims); void recalc_offsets(const size_t ndim, const size_t *dims, mwSize in_noffsets, - const int64_t *in_offsets, const int64_t *in_counts, - size_t *offsets, size_t *counts); -void recalc_steps(const size_t varStepStart, const size_t varStepCount, - const int64_t in_stepstart, const int64_t in_stepcount, - size_t *start, size_t *count); + const int64_t *in_offsets, const int64_t *in_counts, size_t *offsets, + size_t *counts); +void recalc_steps(const size_t varStepStart, const size_t varStepCount, const int64_t in_stepstart, + const int64_t in_stepcount, size_t *start, size_t *count); static void swap_order(size_t n, size_t *array); void printArrayInt64(size_t nelems, void *array); @@ -108,8 +106,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) /*********************************************************************/ /* 5. read in variable */ - out = readdata(fp, group, path, in_noffsets, in_offsets, in_counts, - in_stepstart, in_stepcount); + out = readdata(fp, group, path, in_noffsets, in_offsets, in_counts, in_stepstart, in_stepcount); if (nlhs >= 1) { plhs[0] = out; @@ -118,9 +115,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mxFree(path); } -mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, - mwSize in_noffsets, const int64_t *in_offsets, - const int64_t *in_counts, const int64_t in_stepstart, +mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, mwSize in_noffsets, + const int64_t *in_offsets, const int64_t *in_counts, const int64_t in_stepstart, const int64_t in_stepcount) { /* FIXME: does not work for COMPLEX data because @@ -186,16 +182,14 @@ mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, size_t qstepstart = varStepStart; // default value in case there are no // steps for the variable size_t qstepcount = varStepCount; - recalc_offsets(varNdim, mxdims, in_noffsets, in_offsets, in_counts, - qoffsets, qcounts); - recalc_steps(varStepStart, varStepCount, in_stepstart, in_stepcount, - &qstepstart, &qstepcount); + recalc_offsets(varNdim, mxdims, in_noffsets, in_offsets, in_counts, qoffsets, qcounts); + recalc_steps(varStepStart, varStepCount, in_stepstart, in_stepcount, &qstepstart, &qstepcount); if (mxndim > varNdim) { if (verbose) - mexPrintf("Add steps as extra dimension, start=%zu count=%zu ", - qstepstart, qstepcount); + mexPrintf("Add steps as extra dimension, start=%zu count=%zu ", qstepstart, + qstepcount); qoffsets[varNdim] = qstepstart; qcounts[varNdim] = qstepcount; // steps become slowest dimension } @@ -235,8 +229,8 @@ mxArray *readdata(adios2_engine *fp, adios2_io *group, const char *path, mexPrintf(" count = "); printArrayInt64(varNdim, qcounts); mexPrintf("\n"); - mexPrintf("Set step-selection for variable: start = %zu count = %zu\n", - qstepstart, qstepcount); + mexPrintf("Set step-selection for variable: start = %zu count = %zu\n", qstepstart, + qstepcount); } if (varNdim > 0) @@ -271,34 +265,29 @@ void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]) if (nrhs != 8) { - mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", - "This function needs exactly 6 arguments: File, " - "Group, Varpath, Offsets, Counts, StepStart, " - "StepCount, Verbose"); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", "This function needs exactly 6 arguments: File, " + "Group, Varpath, Offsets, Counts, StepStart, " + "StepCount, Verbose"); } if (!mxIsUint64(prhs[0])) { - mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", - "First arg must be an uint64 handler."); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", "First arg must be an uint64 handler."); } if (!mxIsUint64(prhs[1])) { - mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", - "Second arg must be an uint64 handler."); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", "Second arg must be an uint64 handler."); } if (!mxIsChar(prhs[2])) { - mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", - "Third arg must be a string."); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:rhs", "Third arg must be a string."); } if (nlhs > 1) { - mexErrMsgIdAndTxt("MATLAB:adiosreadc:lhs", - "Too many output arguments."); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:lhs", "Too many output arguments."); } } @@ -309,12 +298,11 @@ void checkDimSize(const int ndims, const size_t *dims) { if (dims[i] > MWSIZE_MAX) { - mexErrMsgIdAndTxt( - "MATLAB:adiosreadc:dimensionTooLarge", - "The selected dimension size, %zu, is larger than the " - "maximum supported value of mwSize, %u, so we cannot create " - "the result array\n", - dims[i], MWSIZE_MAX); + mexErrMsgIdAndTxt("MATLAB:adiosreadc:dimensionTooLarge", + "The selected dimension size, %zu, is larger than the " + "maximum supported value of mwSize, %u, so we cannot create " + "the result array\n", + dims[i], MWSIZE_MAX); } } } @@ -334,8 +322,7 @@ char *getString(const mxArray *mxstr) } /** return the appropriate class for an adios type (and complexity too) */ -mxClassID adiostypeToMatlabClass(adios2_type adiostype, - mxComplexity *complexity) +mxClassID adiostypeToMatlabClass(adios2_type adiostype, mxComplexity *complexity) { *complexity = mxREAL; switch (adiostype) @@ -378,8 +365,7 @@ mxClassID adiostypeToMatlabClass(adios2_type adiostype, default: mexErrMsgIdAndTxt("MATLAB:adiosopenc.c:dimensionTooLarge", - "Adios type id=%d not supported in matlab.\n", - adiostype); + "Adios type id=%d not supported in matlab.\n", adiostype); break; } return 0; /* just to avoid warnings. never executed */ @@ -429,8 +415,8 @@ mxArray *createMatlabArray(int adiostype, size_t ndim, size_t *dims) !!! Provide the output arrays in the caller !!! */ void recalc_offsets(const size_t ndim, const size_t *dims, mwSize in_noffsets, - const int64_t *in_offsets, const int64_t *in_counts, - size_t *offsets, size_t *counts) + const int64_t *in_offsets, const int64_t *in_counts, size_t *offsets, + size_t *counts) { int i; for (i = 0; i < ndim; i++) @@ -442,8 +428,7 @@ void recalc_offsets(const size_t ndim, const size_t *dims, mwSize in_noffsets, else offsets[i] = in_offsets[i] - 1; /* C index start from 0 */ - if (in_counts[i] < - 0) /* negative count means last-|count|+1-start */ + if (in_counts[i] < 0) /* negative count means last-|count|+1-start */ counts[i] = dims[i] + in_counts[i] - offsets[i] + 1; else counts[i] = in_counts[i]; @@ -452,18 +437,15 @@ void recalc_offsets(const size_t ndim, const size_t *dims, mwSize in_noffsets, { /* extend offset/count array to match variable's dimensions */ if (verbose) - mexPrintf( - "Extend offset/counts for dim %d: offset=%d count=%d\n", i, - 0, dims[i]); + mexPrintf("Extend offset/counts for dim %d: offset=%d count=%d\n", i, 0, dims[i]); offsets[i] = 0; counts[i] = dims[i]; } } } -void recalc_steps(const size_t varStepStart, const size_t varStepCount, - const int64_t in_stepstart, const int64_t in_stepcount, - size_t *start, size_t *count) +void recalc_steps(const size_t varStepStart, const size_t varStepCount, const int64_t in_stepstart, + const int64_t in_stepcount, size_t *start, size_t *count) { /* handle steps for variables with multiple steps */ if (in_stepstart < 0) /* negative offset means last step -|start| */ diff --git a/bindings/Python/py11ADIOS.cpp b/bindings/Python/py11ADIOS.cpp index bdb9113b4d..837e699cfb 100644 --- a/bindings/Python/py11ADIOS.cpp +++ b/bindings/Python/py11ADIOS.cpp @@ -39,8 +39,7 @@ IO ADIOS::AtIO(const std::string name) Operator ADIOS::DefineOperator(const std::string name, const std::string type, const Params ¶meters) { - CheckPointer("for operator name " + name + - ", in call to ADIOS::DefineOperator"); + CheckPointer("for operator name " + name + ", in call to ADIOS::DefineOperator"); auto op = &m_ADIOS->DefineOperator(name, type, parameters); return Operator(op->first, &op->second); } diff --git a/bindings/Python/py11ADIOSMPI.cpp b/bindings/Python/py11ADIOSMPI.cpp index 1d89f8492b..bfd36bc1aa 100644 --- a/bindings/Python/py11ADIOSMPI.cpp +++ b/bindings/Python/py11ADIOSMPI.cpp @@ -15,8 +15,7 @@ namespace py11 { ADIOS::ADIOS(const std::string &configFile, MPI4PY_Comm mpiComm) -: m_ADIOS(std::make_shared( - configFile, helper::CommDupMPI(mpiComm), "Python")) +: m_ADIOS(std::make_shared(configFile, helper::CommDupMPI(mpiComm), "Python")) { } diff --git a/bindings/Python/py11Attribute.cpp b/bindings/Python/py11Attribute.cpp index b8afa9ae01..6eb1c0e44b 100644 --- a/bindings/Python/py11Attribute.cpp +++ b/bindings/Python/py11Attribute.cpp @@ -22,10 +22,7 @@ namespace py11 Attribute::Attribute(core::AttributeBase *attribute) : m_Attribute(attribute) {} -Attribute::operator bool() const noexcept -{ - return (m_Attribute == nullptr) ? false : true; -} +Attribute::operator bool() const noexcept { return (m_Attribute == nullptr) ? false : true; } std::string Attribute::Name() const { @@ -63,9 +60,8 @@ std::vector Attribute::DataString() } else { - throw std::invalid_argument( - "ERROR: data type for attribute " + m_Attribute->m_Name + - " is not string, in call to Attribute::DataStrings\n"); + throw std::invalid_argument("ERROR: data type for attribute " + m_Attribute->m_Name + + " is not string, in call to Attribute::DataStrings\n"); } return data; } @@ -79,26 +75,23 @@ pybind11::array Attribute::Data() { // not supported } -#define declare_type(T) \ - else if (type == helper::GetDataType()) \ - { \ - pybind11::array pyArray(pybind11::dtype::of(), \ - m_Attribute->m_Elements); \ - if (m_Attribute->m_IsSingleValue) \ - { \ - const T value = dynamic_cast *>(m_Attribute) \ - ->m_DataSingleValue; \ - std::memcpy(const_cast(pyArray.data()), &value, \ - sizeof(T)); \ - } \ - else \ - { \ - const std::vector &values = \ - dynamic_cast *>(m_Attribute)->m_DataArray; \ - std::memcpy(const_cast(pyArray.data()), values.data(), \ - sizeof(T) * m_Attribute->m_Elements); \ - } \ - return pyArray; \ +#define declare_type(T) \ + else if (type == helper::GetDataType()) \ + { \ + pybind11::array pyArray(pybind11::dtype::of(), m_Attribute->m_Elements); \ + if (m_Attribute->m_IsSingleValue) \ + { \ + const T value = dynamic_cast *>(m_Attribute)->m_DataSingleValue; \ + std::memcpy(const_cast(pyArray.data()), &value, sizeof(T)); \ + } \ + else \ + { \ + const std::vector &values = \ + dynamic_cast *>(m_Attribute)->m_DataArray; \ + std::memcpy(const_cast(pyArray.data()), values.data(), \ + sizeof(T) * m_Attribute->m_Elements); \ + } \ + return pyArray; \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type diff --git a/bindings/Python/py11Engine.cpp b/bindings/Python/py11Engine.cpp index a1227e93c5..3bdce6316f 100644 --- a/bindings/Python/py11Engine.cpp +++ b/bindings/Python/py11Engine.cpp @@ -47,26 +47,23 @@ StepStatus Engine::BeginStep() return m_Engine->BeginStep(); } -void Engine::Put(Variable variable, const pybind11::array &array, - const Mode launch) +void Engine::Put(Variable variable, const pybind11::array &array, const Mode launch) { helper::CheckForNullptr(m_Engine, "in call to Engine::Put numpy array"); helper::CheckForNullptr(variable.m_VariableBase, "for variable, in call to Engine::Put numpy array"); - const adios2::DataType type = - helper::GetDataTypeFromString(variable.Type()); + const adios2::DataType type = helper::GetDataTypeFromString(variable.Type()); if (type == adios2::DataType::Struct) { // not supported } -#define declare_type(T) \ - else if (type == helper::GetDataType()) \ - { \ - m_Engine->Put( \ - *dynamic_cast *>(variable.m_VariableBase), \ - reinterpret_cast(array.data()), launch); \ +#define declare_type(T) \ + else if (type == helper::GetDataType()) \ + { \ + m_Engine->Put(*dynamic_cast *>(variable.m_VariableBase), \ + reinterpret_cast(array.data()), launch); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type @@ -81,22 +78,17 @@ void Engine::Put(Variable variable, const pybind11::array &array, void Engine::Put(Variable variable, const std::string &string) { - helper::CheckForNullptr(m_Engine, - "for engine, in call to Engine::Put string"); - helper::CheckForNullptr(variable.m_VariableBase, - "for variable, in call to Engine::Put string"); + helper::CheckForNullptr(m_Engine, "for engine, in call to Engine::Put string"); + helper::CheckForNullptr(variable.m_VariableBase, "for variable, in call to Engine::Put string"); - if (helper::GetDataTypeFromString(variable.Type()) != - helper::GetDataType()) + if (helper::GetDataTypeFromString(variable.Type()) != helper::GetDataType()) { - throw std::invalid_argument( - "ERROR: variable " + variable.Name() + - " is not of string type, in call to Engine::Put"); + throw std::invalid_argument("ERROR: variable " + variable.Name() + + " is not of string type, in call to Engine::Put"); } - m_Engine->Put( - *dynamic_cast *>(variable.m_VariableBase), - string, adios2::Mode::Sync); + m_Engine->Put(*dynamic_cast *>(variable.m_VariableBase), string, + adios2::Mode::Sync); } void Engine::PerformPuts() @@ -113,67 +105,57 @@ void Engine::PerformDataWrite() void Engine::Get(Variable variable, pybind11::array &array, const Mode launch) { - helper::CheckForNullptr(m_Engine, - "for engine, in call to Engine::Get a numpy array"); - helper::CheckForNullptr( - variable.m_VariableBase, - "for variable, in call to Engine::Get a numpy array"); + helper::CheckForNullptr(m_Engine, "for engine, in call to Engine::Get a numpy array"); + helper::CheckForNullptr(variable.m_VariableBase, + "for variable, in call to Engine::Get a numpy array"); - const adios2::DataType type = - helper::GetDataTypeFromString(variable.Type()); + const adios2::DataType type = helper::GetDataTypeFromString(variable.Type()); if (type == adios2::DataType::Struct) { // not supported } -#define declare_type(T) \ - else if (type == helper::GetDataType()) \ - { \ - if (!array.dtype().is(pybind11::dtype::of())) \ - { \ - throw std::invalid_argument( \ - "In ADIOS2 Get - Type mismatch between Python buffer and " \ - "incoming data."); \ - } \ - m_Engine->Get( \ - *dynamic_cast *>(variable.m_VariableBase), \ - reinterpret_cast(const_cast(array.data())), launch); \ +#define declare_type(T) \ + else if (type == helper::GetDataType()) \ + { \ + if (!array.dtype().is(pybind11::dtype::of())) \ + { \ + throw std::invalid_argument("In ADIOS2 Get - Type mismatch between Python buffer and " \ + "incoming data."); \ + } \ + m_Engine->Get(*dynamic_cast *>(variable.m_VariableBase), \ + reinterpret_cast(const_cast(array.data())), launch); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type else { - throw std::invalid_argument( - "ERROR: in variable " + variable.Name() + " of type " + - variable.Type() + - ", numpy array type is 1) not supported, 2) a type mismatch or" - "3) is not memory contiguous " - ", in call to Get\n"); + throw std::invalid_argument("ERROR: in variable " + variable.Name() + " of type " + + variable.Type() + + ", numpy array type is 1) not supported, 2) a type mismatch or" + "3) is not memory contiguous " + ", in call to Get\n"); } } std::string Engine::Get(Variable variable, const Mode launch) { std::string string; - helper::CheckForNullptr(m_Engine, - "for engine, in call to Engine::Get a numpy array"); + helper::CheckForNullptr(m_Engine, "for engine, in call to Engine::Get a numpy array"); helper::CheckForNullptr(variable.m_VariableBase, "for variable, in call to Engine::Get a string"); - const adios2::DataType type = - helper::GetDataTypeFromString(variable.Type()); + const adios2::DataType type = helper::GetDataTypeFromString(variable.Type()); if (type == helper::GetDataType()) { - m_Engine->Get(*dynamic_cast *>( - variable.m_VariableBase), - string, launch); + m_Engine->Get(*dynamic_cast *>(variable.m_VariableBase), string, + launch); } else { - throw std::invalid_argument("ERROR: variable " + variable.Name() + - " of type " + variable.Type() + - " is not string, in call to Engine::Get"); + throw std::invalid_argument("ERROR: variable " + variable.Name() + " of type " + + variable.Type() + " is not string, in call to Engine::Get"); } return string; } @@ -209,8 +191,7 @@ void Engine::Close(const int transportIndex) size_t Engine::CurrentStep() const { - helper::CheckForNullptr(m_Engine, - "for engine, in call to Engine::CurrentStep"); + helper::CheckForNullptr(m_Engine, "for engine, in call to Engine::CurrentStep"); return m_Engine->CurrentStep(); } @@ -234,20 +215,18 @@ size_t Engine::Steps() const void Engine::LockWriterDefinitions() const { - helper::CheckForNullptr(m_Engine, - "in call to Engine::LockWriterDefinitions"); + helper::CheckForNullptr(m_Engine, "in call to Engine::LockWriterDefinitions"); m_Engine->LockWriterDefinitions(); } void Engine::LockReaderSelections() const { - helper::CheckForNullptr(m_Engine, - "in call to Engine::LockReaderSelections"); + helper::CheckForNullptr(m_Engine, "in call to Engine::LockReaderSelections"); m_Engine->LockReaderSelections(); } -std::vector> -Engine::BlocksInfo(std::string &var_name, const size_t step) const +std::vector> Engine::BlocksInfo(std::string &var_name, + const size_t step) const { std::vector> rv; @@ -335,8 +314,7 @@ Engine::BlocksInfo(std::string &var_name, const size_t step) const } info_map["Max"] = osMax.str(); info_map["Min"] = osMin.str(); - info_map["IsReverseDims"] = - minBlocksInfo->IsReverseDims ? "True" : "False"; + info_map["IsReverseDims"] = minBlocksInfo->IsReverseDims ? "True" : "False"; rv.push_back(info_map); } return rv; @@ -347,41 +325,41 @@ Engine::BlocksInfo(std::string &var_name, const size_t step) const if (false) { } -#define GET_BLOCKS_INFO(T) \ - else if (var_type == helper::GetDataType()) \ - { \ - auto variable = m_Engine->GetIO().InquireVariable(var_name); \ - auto infoVec = m_Engine->BlocksInfo(*variable, step); \ - for (auto &info : infoVec) \ - { \ - std::map info_map; \ - std::stringstream start_ss; \ - for (size_t i = 0; i < info.Start.size(); ++i) \ - { \ - if (i != 0) \ - start_ss << ","; \ - start_ss << info.Start[i]; \ - } \ - info_map["Start"] = start_ss.str(); \ - std::stringstream count_ss; \ - for (size_t i = 0; i < info.Count.size(); ++i) \ - { \ - if (i != 0) \ - count_ss << ","; \ - count_ss << info.Count[i]; \ - } \ - info_map["Count"] = count_ss.str(); \ - info_map["WriterID"] = std::to_string(info.WriterID); \ - info_map["BlockID"] = std::to_string(info.BlockID); \ - info_map["IsValue"] = info.IsValue ? "True" : "False"; \ - std::ostringstream osMax, osMin; \ - osMax << info.Max; \ - osMin << info.Min; \ - info_map["Max"] = osMax.str(); \ - info_map["Min"] = osMin.str(); \ - info_map["IsReverseDims"] = info.IsReverseDims ? "True" : "False"; \ - rv.push_back(info_map); \ - } \ +#define GET_BLOCKS_INFO(T) \ + else if (var_type == helper::GetDataType()) \ + { \ + auto variable = m_Engine->GetIO().InquireVariable(var_name); \ + auto infoVec = m_Engine->BlocksInfo(*variable, step); \ + for (auto &info : infoVec) \ + { \ + std::map info_map; \ + std::stringstream start_ss; \ + for (size_t i = 0; i < info.Start.size(); ++i) \ + { \ + if (i != 0) \ + start_ss << ","; \ + start_ss << info.Start[i]; \ + } \ + info_map["Start"] = start_ss.str(); \ + std::stringstream count_ss; \ + for (size_t i = 0; i < info.Count.size(); ++i) \ + { \ + if (i != 0) \ + count_ss << ","; \ + count_ss << info.Count[i]; \ + } \ + info_map["Count"] = count_ss.str(); \ + info_map["WriterID"] = std::to_string(info.WriterID); \ + info_map["BlockID"] = std::to_string(info.BlockID); \ + info_map["IsValue"] = info.IsValue ? "True" : "False"; \ + std::ostringstream osMax, osMin; \ + osMax << info.Max; \ + osMin << info.Min; \ + info_map["Max"] = osMax.str(); \ + info_map["Min"] = osMin.str(); \ + info_map["IsReverseDims"] = info.IsReverseDims ? "True" : "False"; \ + rv.push_back(info_map); \ + } \ } ADIOS2_FOREACH_PYTHON_TYPE_1ARG(GET_BLOCKS_INFO) diff --git a/bindings/Python/py11Engine.h b/bindings/Python/py11Engine.h index daee8f0ed1..ab713472f2 100644 --- a/bindings/Python/py11Engine.h +++ b/bindings/Python/py11Engine.h @@ -45,18 +45,15 @@ class Engine explicit operator bool() const noexcept; - StepStatus BeginStep(const StepMode mode, - const float timeoutSeconds = -1.f); + StepStatus BeginStep(const StepMode mode, const float timeoutSeconds = -1.f); StepStatus BeginStep(); - void Put(Variable variable, const pybind11::array &array, - const Mode launch = Mode::Deferred); + void Put(Variable variable, const pybind11::array &array, const Mode launch = Mode::Deferred); void Put(Variable variable, const std::string &string); void PerformPuts(); void PerformDataWrite(); - void Get(Variable variable, pybind11::array &array, - const Mode launch = Mode::Deferred); + void Get(Variable variable, pybind11::array &array, const Mode launch = Mode::Deferred); std::string Get(Variable variable, const Mode launch = Mode::Deferred); void PerformGets(); @@ -75,8 +72,8 @@ class Engine void LockWriterDefinitions() const; void LockReaderSelections() const; - std::vector> - BlocksInfo(std::string &string, const size_t step) const; + std::vector> BlocksInfo(std::string &string, + const size_t step) const; private: Engine(core::Engine *engine); diff --git a/bindings/Python/py11File.cpp b/bindings/Python/py11File.cpp index a3ba208a34..17b456e4d5 100644 --- a/bindings/Python/py11File.cpp +++ b/bindings/Python/py11File.cpp @@ -24,18 +24,16 @@ namespace adios2 namespace py11 { -File::File(const std::string &name, const std::string mode, - const std::string engineType) -: m_Name(name), m_Mode(mode), m_Stream(std::make_shared( - name, ToMode(mode), engineType, "Python")) +File::File(const std::string &name, const std::string mode, const std::string engineType) +: m_Name(name), m_Mode(mode), + m_Stream(std::make_shared(name, ToMode(mode), engineType, "Python")) { } -File::File(const std::string &name, const std::string mode, - const std::string &configFile, const std::string ioInConfigFile) +File::File(const std::string &name, const std::string mode, const std::string &configFile, + const std::string ioInConfigFile) : m_Name(name), m_Mode(mode), - m_Stream(std::make_shared(name, ToMode(mode), configFile, - ioInConfigFile, "Python")) + m_Stream(std::make_shared(name, ToMode(mode), configFile, ioInConfigFile, "Python")) { } @@ -67,88 +65,78 @@ std::map File::AvailableAttributes() noexcept } void File::WriteAttribute(const std::string &name, const pybind11::array &array, - const std::string &variableName, - const std::string separator, const bool endStep) + const std::string &variableName, const std::string separator, + const bool endStep) { if (false) { } -#define declare_type(T) \ - else if (pybind11::isinstance< \ - pybind11::array_t>(array)) \ - { \ - m_Stream->WriteAttribute(name, \ - reinterpret_cast(array.data()), \ - static_cast(array.size()), \ - variableName, separator, endStep); \ +#define declare_type(T) \ + else if (pybind11::isinstance>(array)) \ + { \ + m_Stream->WriteAttribute(name, reinterpret_cast(array.data()), \ + static_cast(array.size()), variableName, separator, \ + endStep); \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type else { - throw std::invalid_argument( - "ERROR: adios2 file write attribute " + name + - ", either numpy type is not supported or is not " - "c_style memory contiguous, in call to write\n"); + throw std::invalid_argument("ERROR: adios2 file write attribute " + name + + ", either numpy type is not supported or is not " + "c_style memory contiguous, in call to write\n"); } } -void File::WriteAttribute(const std::string &name, - const std::string &stringValue, - const std::string &variableName, - const std::string separator, const bool endStep) +void File::WriteAttribute(const std::string &name, const std::string &stringValue, + const std::string &variableName, const std::string separator, + const bool endStep) { - m_Stream->WriteAttribute(name, stringValue, variableName, separator, - endStep); + m_Stream->WriteAttribute(name, stringValue, variableName, separator, endStep); } -void File::WriteAttribute(const std::string &name, - const std::vector &stringArray, - const std::string &variableName, - const std::string separator, const bool endStep) +void File::WriteAttribute(const std::string &name, const std::vector &stringArray, + const std::string &variableName, const std::string separator, + const bool endStep) { - m_Stream->WriteAttribute(name, stringArray.data(), stringArray.size(), - variableName, separator, endStep); + m_Stream->WriteAttribute(name, stringArray.data(), stringArray.size(), variableName, separator, + endStep); } -void File::Write(const std::string &name, const pybind11::array &array, - const Dims &shape, const Dims &start, const Dims &count, - const bool endStep) +void File::Write(const std::string &name, const pybind11::array &array, const Dims &shape, + const Dims &start, const Dims &count, const bool endStep) { if (false) { } -#define declare_type(T) \ - else if (pybind11::isinstance< \ - pybind11::array_t>(array)) \ - { \ - m_Stream->Write(name, reinterpret_cast(array.data()), \ - shape, start, count, vParams(), endStep); \ +#define declare_type(T) \ + else if (pybind11::isinstance>(array)) \ + { \ + m_Stream->Write(name, reinterpret_cast(array.data()), shape, start, count, \ + vParams(), endStep); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type else { - throw std::invalid_argument( - "ERROR: adios2 file write variable " + name + - ", either numpy type is not supported or is not " - "c_style memory contiguous, in call to write\n"); + throw std::invalid_argument("ERROR: adios2 file write variable " + name + + ", either numpy type is not supported or is not " + "c_style memory contiguous, in call to write\n"); } } -void File::Write(const std::string &name, const pybind11::array &array, - const Dims &shape, const Dims &start, const Dims &count, - const adios2::vParams &operations, const bool endStep) +void File::Write(const std::string &name, const pybind11::array &array, const Dims &shape, + const Dims &start, const Dims &count, const adios2::vParams &operations, + const bool endStep) { if (false) { } -#define declare_type(T) \ - else if (pybind11::isinstance< \ - pybind11::array_t>(array)) \ - { \ - m_Stream->Write(name, reinterpret_cast(array.data()), \ - shape, start, count, operations, endStep); \ +#define declare_type(T) \ + else if (pybind11::isinstance>(array)) \ + { \ + m_Stream->Write(name, reinterpret_cast(array.data()), shape, start, count, \ + operations, endStep); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type @@ -161,8 +149,8 @@ void File::Write(const std::string &name, const pybind11::array &array, } } -void File::Write(const std::string &name, const pybind11::array &array, - const bool isLocalValue, const bool endStep) +void File::Write(const std::string &name, const pybind11::array &array, const bool isLocalValue, + const bool endStep) { if (isLocalValue) { @@ -174,30 +162,23 @@ void File::Write(const std::string &name, const pybind11::array &array, } } -void File::Write(const std::string &name, const std::string &stringValue, - const bool isLocalValue, const bool endStep) +void File::Write(const std::string &name, const std::string &stringValue, const bool isLocalValue, + const bool endStep) { m_Stream->Write(name, stringValue, isLocalValue, endStep); } -bool File::GetStep() const -{ - return const_cast(this)->m_Stream->GetStep(); -} +bool File::GetStep() const { return const_cast(this)->m_Stream->GetStep(); } -std::vector File::ReadString(const std::string &name, - const size_t blockID) +std::vector File::ReadString(const std::string &name, const size_t blockID) { return m_Stream->Read(name, blockID); } -std::vector File::ReadString(const std::string &name, - const size_t stepStart, - const size_t stepCount, - const size_t blockID) +std::vector File::ReadString(const std::string &name, const size_t stepStart, + const size_t stepCount, const size_t blockID) { - return m_Stream->Read(name, Box(stepStart, stepCount), - blockID); + return m_Stream->Read(name, Box(stepStart, stepCount), blockID); } pybind11::array File::Read(const std::string &name, const size_t blockID) @@ -205,15 +186,14 @@ pybind11::array File::Read(const std::string &name, const size_t blockID) return Read(name, {}, {}, blockID); } -pybind11::array File::Read(const std::string &name, const Dims &start, - const Dims &count, const size_t blockID) +pybind11::array File::Read(const std::string &name, const Dims &start, const Dims &count, + const size_t blockID) { const DataType type = m_Stream->m_IO->InquireVariableType(name); if (type == helper::GetDataType()) { - const std::string value = - m_Stream->Read(name, blockID).front(); + const std::string value = m_Stream->Read(name, blockID).front(); pybind11::array_t pyArray(Dims{value.size()}); std::copy(value.begin(), value.end(), pyArray.mutable_data()); return std::move(pyArray); @@ -222,75 +202,67 @@ pybind11::array File::Read(const std::string &name, const Dims &start, return Read(name, start, count, 0, 0, blockID); } -pybind11::array File::Read(const std::string &name, const Dims &start, - const Dims &count, const size_t stepStart, - const size_t stepCount, const size_t blockID) +pybind11::array File::Read(const std::string &name, const Dims &start, const Dims &count, + const size_t stepStart, const size_t stepCount, const size_t blockID) { const DataType type = m_Stream->m_IO->InquireVariableType(name); if (type == DataType::None) { } -#define declare_type(T) \ - else if (type == helper::GetDataType()) \ - { \ - return DoRead(name, start, count, stepStart, stepCount, blockID); \ +#define declare_type(T) \ + else if (type == helper::GetDataType()) \ + { \ + return DoRead(name, start, count, stepStart, stepCount, blockID); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type else { - throw std::invalid_argument( - "ERROR: adios2 file read variable " + name + - ", type can't be mapped to a numpy type, in call to read\n"); + throw std::invalid_argument("ERROR: adios2 file read variable " + name + + ", type can't be mapped to a numpy type, in call to read\n"); } return pybind11::array(); } -pybind11::array File::ReadAttribute(const std::string &name, - const std::string &variableName, +pybind11::array File::ReadAttribute(const std::string &name, const std::string &variableName, const std::string separator) { - const DataType type = - m_Stream->m_IO->InquireAttributeType(name, variableName, separator); + const DataType type = m_Stream->m_IO->InquireAttributeType(name, variableName, separator); if (type == DataType::None) { } -#define declare_type(T) \ - else if (type == helper::GetDataType()) \ - { \ - core::Attribute *attribute = m_Stream->m_IO->InquireAttribute( \ - name, variableName, separator); \ - if (attribute->m_IsSingleValue) \ - { \ - pybind11::array_t pyArray({}); \ - pyArray.mutable_data()[0] = attribute->m_DataSingleValue; \ - } \ - pybind11::array_t pyArray(attribute->m_Elements); \ - m_Stream->ReadAttribute(name, pyArray.mutable_data(), variableName, \ - separator); \ - return std::move(pyArray); \ +#define declare_type(T) \ + else if (type == helper::GetDataType()) \ + { \ + core::Attribute *attribute = \ + m_Stream->m_IO->InquireAttribute(name, variableName, separator); \ + if (attribute->m_IsSingleValue) \ + { \ + pybind11::array_t pyArray({}); \ + pyArray.mutable_data()[0] = attribute->m_DataSingleValue; \ + } \ + pybind11::array_t pyArray(attribute->m_Elements); \ + m_Stream->ReadAttribute(name, pyArray.mutable_data(), variableName, separator); \ + return std::move(pyArray); \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type else { - throw std::invalid_argument( - "ERROR: adios2 file read attribute " + name + - ", type can't be mapped to a numpy type, in call to read\n"); + throw std::invalid_argument("ERROR: adios2 file read attribute " + name + + ", type can't be mapped to a numpy type, in call to read\n"); } return pybind11::array(); } -std::vector -File::ReadAttributeString(const std::string &name, - const std::string &variableName, - const std::string separator) +std::vector File::ReadAttributeString(const std::string &name, + const std::string &variableName, + const std::string separator) { const core::Attribute *attribute = - m_Stream->m_IO->InquireAttribute(name, variableName, - separator); + m_Stream->m_IO->InquireAttribute(name, variableName, separator); if (attribute == nullptr) { @@ -298,8 +270,7 @@ File::ReadAttributeString(const std::string &name, } std::vector data(attribute->m_Elements); - m_Stream->ReadAttribute(name, data.data(), variableName, - separator); + m_Stream->ReadAttribute(name, data.data(), variableName, separator); return data; } @@ -337,11 +308,10 @@ adios2::Mode File::ToMode(const std::string mode) const } else { - throw std::invalid_argument( - "ERROR: adios2 mode " + mode + " for file " + m_Name + - " not supported, only \"r\", \"rra\", \"w\" and \"a\" (read, " - "readRandomAccess, write, append) " - "are valid modes, in call to open\n"); + throw std::invalid_argument("ERROR: adios2 mode " + mode + " for file " + m_Name + + " not supported, only \"r\", \"rra\", \"w\" and \"a\" (read, " + "readRandomAccess, write, append) " + "are valid modes, in call to open\n"); } return modeCpp; diff --git a/bindings/Python/py11File.h b/bindings/Python/py11File.h index 5b1b8883a9..ef83a41def 100644 --- a/bindings/Python/py11File.h +++ b/bindings/Python/py11File.h @@ -39,11 +39,10 @@ class File const std::string &configFile, const std::string ioInConfigFile); #endif - File(const std::string &name, const std::string mode, - const std::string engineType = "BPFile"); + File(const std::string &name, const std::string mode, const std::string engineType = "BPFile"); - File(const std::string &name, const std::string mode, - const std::string &configFile, const std::string ioInConfigFile); + File(const std::string &name, const std::string mode, const std::string &configFile, + const std::string ioInConfigFile); ~File() = default; @@ -51,38 +50,31 @@ class File void SetParameters(const Params ¶meters) noexcept; - size_t AddTransport(const std::string type, - const Params ¶meters = Params()); + size_t AddTransport(const std::string type, const Params ¶meters = Params()); std::map - AvailableVariables(const std::vector &keys = - std::vector()) noexcept; + AvailableVariables(const std::vector &keys = std::vector()) noexcept; std::map AvailableAttributes() noexcept; void WriteAttribute(const std::string &name, const pybind11::array &array, - const std::string &variableName = "", - const std::string separator = "/", + const std::string &variableName = "", const std::string separator = "/", const bool endStep = false); void WriteAttribute(const std::string &name, const std::string &stringValue, - const std::string &variableName = "", - const std::string separator = "/", + const std::string &variableName = "", const std::string separator = "/", const bool endStep = false); - void WriteAttribute(const std::string &name, - const std::vector &stringArray, - const std::string &variableName = "", - const std::string separator = "/", + void WriteAttribute(const std::string &name, const std::vector &stringArray, + const std::string &variableName = "", const std::string separator = "/", const bool endStep = false); - void Write(const std::string &name, const pybind11::array &array, - const Dims &shape, const Dims &start, const Dims &count, - const bool endStep = false); + void Write(const std::string &name, const pybind11::array &array, const Dims &shape, + const Dims &start, const Dims &count, const bool endStep = false); - void Write(const std::string &name, const pybind11::array &array, - const Dims &shape, const Dims &start, const Dims &count, - const adios2::vParams &operations, const bool endStep = false); + void Write(const std::string &name, const pybind11::array &array, const Dims &shape, + const Dims &start, const Dims &count, const adios2::vParams &operations, + const bool endStep = false); void Write(const std::string &name, const pybind11::array &array, const bool isLocalValue = false, const bool endStep = false); @@ -92,31 +84,25 @@ class File bool GetStep() const; - std::vector ReadString(const std::string &name, - const size_t blockID = 0); + std::vector ReadString(const std::string &name, const size_t blockID = 0); - std::vector ReadString(const std::string &name, - const size_t stepStart, - const size_t stepCount, - const size_t blockID = 0); + std::vector ReadString(const std::string &name, const size_t stepStart, + const size_t stepCount, const size_t blockID = 0); pybind11::array Read(const std::string &name, const size_t blockID = 0); - pybind11::array Read(const std::string &name, const Dims &start, - const Dims &count, const size_t blockID = 0); + pybind11::array Read(const std::string &name, const Dims &start, const Dims &count, + const size_t blockID = 0); - pybind11::array Read(const std::string &name, const Dims &start, - const Dims &count, const size_t stepStart, - const size_t stepCount, const size_t blockID = 0); + pybind11::array Read(const std::string &name, const Dims &start, const Dims &count, + const size_t stepStart, const size_t stepCount, const size_t blockID = 0); - pybind11::array ReadAttribute(const std::string &name, - const std::string &variableName = "", + pybind11::array ReadAttribute(const std::string &name, const std::string &variableName = "", const std::string separator = "/"); - std::vector - ReadAttributeString(const std::string &name, - const std::string &variableName = "", - const std::string separator = "/"); + std::vector ReadAttributeString(const std::string &name, + const std::string &variableName = "", + const std::string separator = "/"); void EndStep(); @@ -131,9 +117,8 @@ class File adios2::Mode ToMode(const std::string mode) const; template - pybind11::array DoRead(const std::string &name, const Dims &start, - const Dims &count, const size_t stepStart, - const size_t stepCount, const size_t blockID); + pybind11::array DoRead(const std::string &name, const Dims &start, const Dims &count, + const size_t stepStart, const size_t stepCount, const size_t blockID); }; } // end namespace py11 diff --git a/bindings/Python/py11File.tcc b/bindings/Python/py11File.tcc index e102c1bfdf..6cf41d4d4f 100644 --- a/bindings/Python/py11File.tcc +++ b/bindings/Python/py11File.tcc @@ -19,9 +19,8 @@ namespace py11 { template -pybind11::array File::DoRead(const std::string &name, const Dims &_start, - const Dims &_count, const size_t stepStart, - const size_t stepCount, const size_t blockID) +pybind11::array File::DoRead(const std::string &name, const Dims &_start, const Dims &_count, + const size_t stepStart, const size_t stepCount, const size_t blockID) { core::Variable &variable = *m_Stream->m_IO->InquireVariable(name); Dims &shape = variable.m_Shape; @@ -45,8 +44,7 @@ pybind11::array File::DoRead(const std::string &name, const Dims &_start, { if (blockID != 0) { - throw std::invalid_argument( - "blockId can only be specified when reading LocalArrays."); + throw std::invalid_argument("blockId can only be specified when reading LocalArrays."); } } diff --git a/bindings/Python/py11FileMPI.cpp b/bindings/Python/py11FileMPI.cpp index 66395562df..e38383203d 100644 --- a/bindings/Python/py11FileMPI.cpp +++ b/bindings/Python/py11FileMPI.cpp @@ -17,16 +17,15 @@ namespace py11 File::File(const std::string &name, const std::string mode, MPI_Comm comm, const std::string engineType) : m_Name(name), m_Mode(mode), - m_Stream(std::make_shared( - name, ToMode(mode), helper::CommDupMPI(comm), engineType, "Python")) + m_Stream(std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), engineType, + "Python")) { } File::File(const std::string &name, const std::string mode, MPI_Comm comm, const std::string &configFile, const std::string ioInConfigFile) : m_Name(name), m_Mode(mode), - m_Stream(std::make_shared(name, ToMode(mode), - helper::CommDupMPI(comm), configFile, + m_Stream(std::make_shared(name, ToMode(mode), helper::CommDupMPI(comm), configFile, ioInConfigFile, "Python")) { } diff --git a/bindings/Python/py11IO.cpp b/bindings/Python/py11IO.cpp index 72feffc6c9..2d57abe554 100644 --- a/bindings/Python/py11IO.cpp +++ b/bindings/Python/py11IO.cpp @@ -60,8 +60,8 @@ size_t IO::AddTransport(const std::string type, const Params ¶meters) return m_IO->AddTransport(type, parameters); } -void IO::SetTransportParameter(const size_t transportIndex, - const std::string key, const std::string value) +void IO::SetTransportParameter(const size_t transportIndex, const std::string key, + const std::string value) { helper::CheckForNullptr(m_IO, "in call to IO::SetTransportParameter"); m_IO->SetTransportParameter(transportIndex, key, value); @@ -69,29 +69,24 @@ void IO::SetTransportParameter(const size_t transportIndex, Variable IO::DefineVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable " + name + - ", in call to IO::DefineVariable"); + helper::CheckForNullptr(m_IO, "for variable " + name + ", in call to IO::DefineVariable"); return Variable(&m_IO->DefineVariable(name)); } -Variable IO::DefineVariable(const std::string &name, - const pybind11::array &array, const Dims &shape, - const Dims &start, const Dims &count, +Variable IO::DefineVariable(const std::string &name, const pybind11::array &array, + const Dims &shape, const Dims &start, const Dims &count, const bool isConstantDims) { - helper::CheckForNullptr(m_IO, "for variable " + name + - ", in call to IO::DefineVariable"); + helper::CheckForNullptr(m_IO, "for variable " + name + ", in call to IO::DefineVariable"); core::VariableBase *variable = nullptr; if (false) { } -#define declare_type(T) \ - else if (pybind11::isinstance< \ - pybind11::array_t>(array)) \ - { \ - variable = &m_IO->DefineVariable(name, shape, start, count, \ - isConstantDims); \ +#define declare_type(T) \ + else if (pybind11::isinstance>(array)) \ + { \ + variable = &m_IO->DefineVariable(name, shape, start, count, isConstantDims); \ } ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type @@ -108,8 +103,7 @@ Variable IO::DefineVariable(const std::string &name, Variable IO::InquireVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable " + name + - ", in call to IO::InquireVariable"); + helper::CheckForNullptr(m_IO, "for variable " + name + ", in call to IO::InquireVariable"); const DataType type(m_IO->InquireVariableType(name)); core::VariableBase *variable = nullptr; @@ -117,10 +111,10 @@ Variable IO::InquireVariable(const std::string &name) if (type == DataType::None) { } -#define declare_template_instantiation(T) \ - else if (type == helper::GetDataType()) \ - { \ - variable = m_IO->InquireVariable(name); \ +#define declare_template_instantiation(T) \ + else if (type == helper::GetDataType()) \ + { \ + variable = m_IO->InquireVariable(name); \ } ADIOS2_FOREACH_PYTHON_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -128,27 +122,22 @@ Variable IO::InquireVariable(const std::string &name) return Variable(variable); } -Attribute IO::DefineAttribute(const std::string &name, - const pybind11::array &array, - const std::string &variableName, - const std::string separator) +Attribute IO::DefineAttribute(const std::string &name, const pybind11::array &array, + const std::string &variableName, const std::string separator) { - helper::CheckForNullptr(m_IO, "for attribute " + name + - ", in call to IO::DefineAttribute"); + helper::CheckForNullptr(m_IO, "for attribute " + name + ", in call to IO::DefineAttribute"); core::AttributeBase *attribute = nullptr; if (false) { } -#define declare_type(T) \ - else if (pybind11::isinstance< \ - pybind11::array_t>(array)) \ - { \ - const T *data = reinterpret_cast(array.data()); \ - const size_t size = static_cast(array.size()); \ - attribute = &m_IO->DefineAttribute(name, data, size, variableName, \ - separator); \ +#define declare_type(T) \ + else if (pybind11::isinstance>(array)) \ + { \ + const T *data = reinterpret_cast(array.data()); \ + const size_t size = static_cast(array.size()); \ + attribute = &m_IO->DefineAttribute(name, data, size, variableName, separator); \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type @@ -163,34 +152,27 @@ Attribute IO::DefineAttribute(const std::string &name, return Attribute(attribute); } -Attribute IO::DefineAttribute(const std::string &name, - const std::string &stringValue, - const std::string &variableName, - const std::string separator) +Attribute IO::DefineAttribute(const std::string &name, const std::string &stringValue, + const std::string &variableName, const std::string separator) { - helper::CheckForNullptr(m_IO, "for attribute " + name + - ", in call to IO::DefineAttribute"); + helper::CheckForNullptr(m_IO, "for attribute " + name + ", in call to IO::DefineAttribute"); - return Attribute(&m_IO->DefineAttribute( - name, stringValue, variableName, separator)); + return Attribute( + &m_IO->DefineAttribute(name, stringValue, variableName, separator)); } -Attribute IO::DefineAttribute(const std::string &name, - const std::vector &strings, - const std::string &variableName, - const std::string separator) +Attribute IO::DefineAttribute(const std::string &name, const std::vector &strings, + const std::string &variableName, const std::string separator) { - helper::CheckForNullptr(m_IO, "for attribute " + name + - ", in call to IO::DefineAttribute"); + helper::CheckForNullptr(m_IO, "for attribute " + name + ", in call to IO::DefineAttribute"); - return Attribute(&m_IO->DefineAttribute( - name, strings.data(), strings.size(), variableName, separator)); + return Attribute(&m_IO->DefineAttribute(name, strings.data(), strings.size(), + variableName, separator)); } Attribute IO::InquireAttribute(const std::string &name) { - helper::CheckForNullptr(m_IO, "for attribute " + name + - ", in call to IO::InquireAttribute"); + helper::CheckForNullptr(m_IO, "for attribute " + name + ", in call to IO::InquireAttribute"); core::AttributeBase *attribute = nullptr; const DataType type(m_IO->InquireAttributeType(name)); @@ -198,10 +180,10 @@ Attribute IO::InquireAttribute(const std::string &name) if (type == DataType::None) { } -#define declare_template_instantiation(T) \ - else if (type == helper::GetDataType()) \ - { \ - attribute = m_IO->InquireAttribute(name); \ +#define declare_template_instantiation(T) \ + else if (type == helper::GetDataType()) \ + { \ + attribute = m_IO->InquireAttribute(name); \ } ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -211,8 +193,7 @@ Attribute IO::InquireAttribute(const std::string &name) bool IO::RemoveVariable(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable " + name + - ", in call to IO::RemoveVariable"); + helper::CheckForNullptr(m_IO, "for variable " + name + ", in call to IO::RemoveVariable"); return m_IO->RemoveVariable(name); } @@ -224,8 +205,7 @@ void IO::RemoveAllVariables() bool IO::RemoveAttribute(const std::string &name) { - helper::CheckForNullptr(m_IO, "for variable " + name + - ", in call to IO::RemoveAttribute"); + helper::CheckForNullptr(m_IO, "for variable " + name + ", in call to IO::RemoveAttribute"); return m_IO->RemoveAttribute(name); } @@ -237,8 +217,7 @@ void IO::RemoveAllAttributes() Engine IO::Open(const std::string &name, const int mode) { - helper::CheckForNullptr(m_IO, - "for engine " + name + ", in call to IO::Open"); + helper::CheckForNullptr(m_IO, "for engine " + name + ", in call to IO::Open"); return Engine(&m_IO->Open(name, static_cast(mode))); } @@ -262,15 +241,13 @@ std::map IO::AvailableAttributes() std::string IO::VariableType(const std::string &name) const { - helper::CheckForNullptr(m_IO, "for variable " + name + - " in call to IO::VariableType"); + helper::CheckForNullptr(m_IO, "for variable " + name + " in call to IO::VariableType"); return ToString(m_IO->InquireVariableType(name)); } std::string IO::AttributeType(const std::string &name) const { - helper::CheckForNullptr(m_IO, "for attribute " + name + - " in call to IO::AttributeType"); + helper::CheckForNullptr(m_IO, "for attribute " + name + " in call to IO::AttributeType"); return ToString(m_IO->InquireAttributeType(name)); } diff --git a/bindings/Python/py11IO.h b/bindings/Python/py11IO.h index 2e6126624a..35ac6e269d 100644 --- a/bindings/Python/py11IO.h +++ b/bindings/Python/py11IO.h @@ -48,30 +48,26 @@ class IO size_t AddTransport(const std::string type, const Params ¶meters); - void SetTransportParameter(const size_t transportIndex, - const std::string key, const std::string value); + void SetTransportParameter(const size_t transportIndex, const std::string key, + const std::string value); Variable DefineVariable(const std::string &name); - Variable DefineVariable(const std::string &name, - const pybind11::array &array, const Dims &shape, - const Dims &start, const Dims &count, + Variable DefineVariable(const std::string &name, const pybind11::array &array, + const Dims &shape, const Dims &start, const Dims &count, const bool isConstantDims); Variable InquireVariable(const std::string &name); - Attribute DefineAttribute(const std::string &name, - const pybind11::array &array, + Attribute DefineAttribute(const std::string &name, const pybind11::array &array, const std::string &variableName = "", const std::string separator = "/"); - Attribute DefineAttribute(const std::string &name, - const std::string &stringValue, + Attribute DefineAttribute(const std::string &name, const std::string &stringValue, const std::string &variableName = "", const std::string separator = "/"); - Attribute DefineAttribute(const std::string &name, - const std::vector &strings, + Attribute DefineAttribute(const std::string &name, const std::vector &strings, const std::string &variableName = "", const std::string separator = "/"); diff --git a/bindings/Python/py11IOMPI.cpp b/bindings/Python/py11IOMPI.cpp index 1a95f2c5e6..bae122dc7c 100644 --- a/bindings/Python/py11IOMPI.cpp +++ b/bindings/Python/py11IOMPI.cpp @@ -19,11 +19,9 @@ namespace py11 Engine IO::Open(const std::string &name, const int mode, MPI4PY_Comm comm) { - helper::CheckForNullptr(m_IO, - "for engine " + name + ", in call to IO::Open"); + helper::CheckForNullptr(m_IO, "for engine " + name + ", in call to IO::Open"); - return Engine(&m_IO->Open(name, static_cast(mode), - helper::CommDupMPI(comm))); + return Engine(&m_IO->Open(name, static_cast(mode), helper::CommDupMPI(comm))); } } // end namespace py11 diff --git a/bindings/Python/py11Operator.cpp b/bindings/Python/py11Operator.cpp index 90f706e7dc..f89203394f 100644 --- a/bindings/Python/py11Operator.cpp +++ b/bindings/Python/py11Operator.cpp @@ -33,8 +33,8 @@ void Operator::SetParameter(const std::string key, const std::string value) { if (m_Parameters == nullptr) { - helper::Log("PythonAPI", "Operator", "SetParameter()", - "Operator is nullptr", helper::LogMode::EXCEPTION); + helper::Log("PythonAPI", "Operator", "SetParameter()", "Operator is nullptr", + helper::LogMode::EXCEPTION); } (*m_Parameters)[key] = value; } @@ -43,17 +43,14 @@ Params &Operator::Parameters() const { if (m_Parameters == nullptr) { - helper::Log("PythonAPI", "Operator", "Parameter()", - "Operator is nullptr", helper::LogMode::EXCEPTION); + helper::Log("PythonAPI", "Operator", "Parameter()", "Operator is nullptr", + helper::LogMode::EXCEPTION); } return *m_Parameters; } // PRIVATE -Operator::Operator(const std::string &type, Params *params) -: m_Parameters(params), m_Type(type) -{ -} +Operator::Operator(const std::string &type, Params *params) : m_Parameters(params), m_Type(type) {} } // end namespace py11 } // end namespace adios2 diff --git a/bindings/Python/py11Query.cpp b/bindings/Python/py11Query.cpp index 8d097eeba5..01c8cdb050 100644 --- a/bindings/Python/py11Query.cpp +++ b/bindings/Python/py11Query.cpp @@ -19,27 +19,29 @@ Query::Query(adios2::query::Worker *qw) : m_QueryWorker(qw) {} Query::Query(std::string queryFile, Engine reader) { - adios2::query::Worker *m = - adios2::query::GetWorker(queryFile, reader.m_Engine); + adios2::query::Worker *m = adios2::query::GetWorker(queryFile, reader.m_Engine); if (m == nullptr) throw std::invalid_argument("ERROR: unable to construct query. "); m_QueryWorker = std::make_shared(std::move(*m)); delete m; } -Query::operator bool() const noexcept -{ - return (m_QueryWorker == nullptr) ? false : true; -} +Query::operator bool() const noexcept { return (m_QueryWorker == nullptr) ? false : true; } std::vector> Query::GetResult() { - // std::cout<<"Do something"< empty; // look into all data std::vector> touched_blocks; + adios2::Box empty; m_QueryWorker->GetResultCoverage(empty, touched_blocks); return touched_blocks; } +std::vector Query::GetBlockIDs() +{ + std::vector touched_block_ids; + m_QueryWorker->GetResultCoverage(touched_block_ids); + return touched_block_ids; +} + } // py11 } // adios2 diff --git a/bindings/Python/py11Query.h b/bindings/Python/py11Query.h index 68147e17f2..64768f0b7d 100644 --- a/bindings/Python/py11Query.h +++ b/bindings/Python/py11Query.h @@ -13,7 +13,7 @@ #include -//#include "adios2/toolkit/query/Query.h" +// #include "adios2/toolkit/query/Query.h" #include "adios2/toolkit/query/Worker.h" #include "py11Engine.h" @@ -34,8 +34,7 @@ class Query explicit operator bool() const noexcept; std::vector> GetResult(); - // const Box< Dims > & refinedSelectionIfAny, - // std::vector< Box< Dims > > &touched_blocks + std::vector GetBlockIDs(); private: Query(adios2::query::Worker *qw); diff --git a/bindings/Python/py11Variable.cpp b/bindings/Python/py11Variable.cpp index e333af189c..2a57ef6ba2 100644 --- a/bindings/Python/py11Variable.cpp +++ b/bindings/Python/py11Variable.cpp @@ -19,10 +19,7 @@ namespace py11 Variable::Variable(core::VariableBase *variable) : m_VariableBase(variable) {} -Variable::operator bool() const noexcept -{ - return (m_VariableBase == nullptr) ? false : true; -} +Variable::operator bool() const noexcept { return (m_VariableBase == nullptr) ? false : true; } void Variable::SetShape(const Dims &shape) { @@ -32,29 +29,25 @@ void Variable::SetShape(const Dims &shape) void Variable::SetBlockSelection(const size_t blockID) { - helper::CheckForNullptr(m_VariableBase, - "in call to Variable::SetBlockSelection"); + helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetBlockSelection"); m_VariableBase->SetBlockSelection(blockID); } void Variable::SetSelection(const Box &selection) { - helper::CheckForNullptr(m_VariableBase, - "in call to Variable::SetSelection"); + helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetSelection"); m_VariableBase->SetSelection(selection); } void Variable::SetStepSelection(const Box &stepSelection) { - helper::CheckForNullptr(m_VariableBase, - "in call to Variable::SetStepSelection"); + helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetStepSelection"); m_VariableBase->SetStepSelection(stepSelection); } size_t Variable::SelectionSize() const { - helper::CheckForNullptr(m_VariableBase, - "in call to Variable::SelectionSize"); + helper::CheckForNullptr(m_VariableBase, "in call to Variable::SelectionSize"); const adios2::DataType typeCpp = m_VariableBase->m_Type; size_t size = 0; @@ -63,12 +56,12 @@ size_t Variable::SelectionSize() const { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(m_VariableBase); \ - size = variable->SelectionSize(); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(m_VariableBase); \ + size = variable->SelectionSize(); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -78,8 +71,7 @@ size_t Variable::SelectionSize() const size_t Variable::AddOperation(const Operator op, const Params ¶meters) { - helper::CheckForNullptr(m_VariableBase, - "in call to Variable::AddOperation"); + helper::CheckForNullptr(m_VariableBase, "in call to Variable::AddOperation"); auto params = op.Parameters(); for (const auto &p : parameters) { @@ -136,12 +128,12 @@ Dims Variable::Shape(const size_t step) const { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(m_VariableBase); \ - shape = variable->Shape(step); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(m_VariableBase); \ + shape = variable->Shape(step); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -166,12 +158,12 @@ Dims Variable::Count() const { // not supported } -#define declare_template_instantiation(T) \ - else if (typeCpp == adios2::helper::GetDataType()) \ - { \ - const adios2::core::Variable *variable = \ - dynamic_cast *>(m_VariableBase); \ - count = variable->Count(); \ +#define declare_template_instantiation(T) \ + else if (typeCpp == adios2::helper::GetDataType()) \ + { \ + const adios2::core::Variable *variable = \ + dynamic_cast *>(m_VariableBase); \ + count = variable->Count(); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/Python/py11glue.cpp b/bindings/Python/py11glue.cpp index 60a7cf39af..128c52d941 100644 --- a/bindings/Python/py11glue.cpp +++ b/bindings/Python/py11glue.cpp @@ -58,8 +58,7 @@ struct type_caster { if (import_mpi4py() < 0) { - throw std::runtime_error( - "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ + throw std::runtime_error("ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ } } // If src is not actually a MPI4PY communicator, the next @@ -82,16 +81,13 @@ struct type_caster #if ADIOS2_USE_MPI adios2::py11::File OpenMPI(const std::string &name, const std::string mode, - adios2::py11::MPI4PY_Comm comm, - const std::string enginetype) + adios2::py11::MPI4PY_Comm comm, const std::string enginetype) { return adios2::py11::File(name, mode, comm, enginetype); } -adios2::py11::File OpenConfigMPI(const std::string &name, - const std::string mode, - adios2::py11::MPI4PY_Comm comm, - const std::string &configfile, +adios2::py11::File OpenConfigMPI(const std::string &name, const std::string mode, + adios2::py11::MPI4PY_Comm comm, const std::string &configfile, const std::string ioinconfigfile) { return adios2::py11::File(name, mode, comm, configfile, ioinconfigfile); @@ -105,8 +101,7 @@ adios2::py11::File Open(const std::string &name, const std::string mode, } adios2::py11::File OpenConfig(const std::string &name, const std::string mode, - const std::string configfile, - const std::string ioinconfigfile) + const std::string configfile, const std::string ioinconfigfile) { return adios2::py11::File(name, mode, configfile, ioinconfigfile); } @@ -153,8 +148,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .export_values(); #if ADIOS2_USE_MPI - m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("comm"), pybind11::arg("engine_type") = "BPFile", R"md( + m.def("open", &OpenMPI, pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("comm"), + pybind11::arg("engine_type") = "BPFile", R"md( Simple API MPI open, based on python IO. Allows for passing parameters in source code. @@ -178,8 +173,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md"); m.def("open", &OpenConfigMPI, pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("comm"), pybind11::arg("config_file"), - pybind11::arg("io_in_config_file"), R"md( + pybind11::arg("comm"), pybind11::arg("config_file"), pybind11::arg("io_in_config_file"), + R"md( Simple API MPI open, based on python IO. Allows for passing a runtime configuration file in xml format and the name of the io element related to the returning File. @@ -207,14 +202,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md"); #endif - m.def("open", &Open, "High-level API, file object open", - pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("engine_type") = "BPFile"); + m.def("open", &Open, "High-level API, file object open", pybind11::arg("name"), + pybind11::arg("mode"), pybind11::arg("engine_type") = "BPFile"); - m.def("open", &OpenConfig, - "High-level API, file object open with a runtime config file", - pybind11::arg("name"), pybind11::arg("mode"), - pybind11::arg("config_file"), pybind11::arg("io_in_config_file")); + m.def("open", &OpenConfig, "High-level API, file object open with a runtime config file", + pybind11::arg("name"), pybind11::arg("mode"), pybind11::arg("config_file"), + pybind11::arg("io_in_config_file")); pybind11::class_(m, "ADIOS") // Python 2 @@ -240,8 +233,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def(pybind11::init(), "adios2 module starting point, constructs an ADIOS class object", pybind11::arg("comm")) - .def(pybind11::init(), + .def(pybind11::init(), "adios2 module starting point, constructs an ADIOS class object", pybind11::arg("configFile"), pybind11::arg("comm")) #endif @@ -285,27 +277,22 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) pybind11::arg("parameters") = adios2::Params()) .def("SetParameter", &adios2::py11::IO::SetParameter) .def("Parameters", &adios2::py11::IO::Parameters) - .def("AddTransport", &adios2::py11::IO::AddTransport, - pybind11::arg("type"), + .def("AddTransport", &adios2::py11::IO::AddTransport, pybind11::arg("type"), pybind11::arg("parameters") = adios2::Params()) .def("DefineVariable", (adios2::py11::Variable(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, - const adios2::Dims &, const bool)) & + const std::string &, const pybind11::array &, const adios2::Dims &, + const adios2::Dims &, const adios2::Dims &, const bool)) & adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name"), - pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), - pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), - pybind11::arg("isConstantDims") = false) + pybind11::return_value_policy::move, pybind11::arg("name"), pybind11::arg("array"), + pybind11::arg("shape") = adios2::Dims(), pybind11::arg("start") = adios2::Dims(), + pybind11::arg("count") = adios2::Dims(), pybind11::arg("isConstantDims") = false) - .def( - "DefineVariable", - (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & - adios2::py11::IO::DefineVariable, - pybind11::return_value_policy::move, pybind11::arg("name")) + .def("DefineVariable", + (adios2::py11::Variable(adios2::py11::IO::*)(const std::string &)) & + adios2::py11::IO::DefineVariable, + pybind11::return_value_policy::move, pybind11::arg("name")) .def("InquireVariable", &adios2::py11::IO::InquireVariable, pybind11::return_value_policy::move) @@ -315,41 +302,34 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def("DefineAttribute", (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const pybind11::array &, - const std::string &, const std::string)) & - adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) - - .def("DefineAttribute", - (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const std::string &, const std::string &, + const std::string &, const pybind11::array &, const std::string &, const std::string)) & adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("stringValue"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::return_value_policy::move) + + .def( + "DefineAttribute", + (adios2::py11::Attribute(adios2::py11::IO::*)(const std::string &, const std::string &, + const std::string &, const std::string)) & + adios2::py11::IO::DefineAttribute, + pybind11::arg("name"), pybind11::arg("stringValue"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", + pybind11::return_value_policy::move) .def("DefineAttribute", (adios2::py11::Attribute(adios2::py11::IO::*)( - const std::string &, const std::vector &, - const std::string &, const std::string)) & + const std::string &, const std::vector &, const std::string &, + const std::string)) & adios2::py11::IO::DefineAttribute, - pybind11::arg("name"), pybind11::arg("strings"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::return_value_policy::move) + pybind11::arg("name"), pybind11::arg("strings"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::return_value_policy::move) - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( - const std::string &, const int)) & + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int)) & adios2::py11::IO::Open) #if ADIOS2_USE_MPI - .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)( - const std::string &, const int, - adios2::py11::MPI4PY_Comm comm)) & + .def("Open", (adios2::py11::Engine(adios2::py11::IO::*)(const std::string &, const int, + adios2::py11::MPI4PY_Comm comm)) & adios2::py11::IO::Open) #endif .def("AvailableVariables", &adios2::py11::IO::AvailableVariables) @@ -373,12 +353,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) const bool opBool = query ? true : false; return opBool; }) - .def( - pybind11::init(), - "adios2 query construction, a xml query File and a read engine", - pybind11::arg("queryFile"), pybind11::arg("reader") = true) + .def(pybind11::init(), + "adios2 query construction, a xml query File and a read engine", + pybind11::arg("queryFile"), pybind11::arg("reader") = true) - .def("GetResult", &adios2::py11::Query::GetResult); + .def("GetResult", &adios2::py11::Query::GetResult) + .def("GetBlockIDs", &adios2::py11::Query::GetBlockIDs); pybind11::class_(m, "Variable") // Python 2 @@ -444,27 +424,23 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) return opBool; }) .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)( - const adios2::StepMode, const float)) & + (adios2::StepStatus(adios2::py11::Engine::*)(const adios2::StepMode, const float)) & adios2::py11::Engine::BeginStep, pybind11::arg("mode"), pybind11::arg("timeoutSeconds") = -1.f, pybind11::return_value_policy::move) .def("BeginStep", - (adios2::StepStatus(adios2::py11::Engine::*)()) & - adios2::py11::Engine::BeginStep, + (adios2::StepStatus(adios2::py11::Engine::*)()) & adios2::py11::Engine::BeginStep, pybind11::return_value_policy::move) .def("Put", - (void (adios2::py11::Engine::*)(adios2::py11::Variable, - const pybind11::array &, - const adios2::Mode launch)) & + (void(adios2::py11::Engine::*)(adios2::py11::Variable, const pybind11::array &, + const adios2::Mode launch)) & adios2::py11::Engine::Put, pybind11::arg("variable"), pybind11::arg("array"), pybind11::arg("launch") = adios2::Mode::Deferred) - .def("Put", (void (adios2::py11::Engine::*)(adios2::py11::Variable, - const std::string &)) & + .def("Put", (void(adios2::py11::Engine::*)(adios2::py11::Variable, const std::string &)) & adios2::py11::Engine::Put) .def("PerformPuts", &adios2::py11::Engine::PerformPuts) @@ -472,9 +448,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def("PerformDataWrite", &adios2::py11::Engine::PerformDataWrite) .def("Get", - (void (adios2::py11::Engine::*)(adios2::py11::Variable, - pybind11::array &, - const adios2::Mode launch)) & + (void(adios2::py11::Engine::*)(adios2::py11::Variable, pybind11::array &, + const adios2::Mode launch)) & adios2::py11::Engine::Get, pybind11::arg("variable"), pybind11::arg("array"), pybind11::arg("launch") = adios2::Mode::Deferred) @@ -483,8 +458,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (std::string(adios2::py11::Engine::*)(adios2::py11::Variable, const adios2::Mode launch)) & adios2::py11::Engine::Get, - pybind11::arg("variable"), - pybind11::arg("launch") = adios2::Mode::Deferred) + pybind11::arg("variable"), pybind11::arg("launch") = adios2::Mode::Deferred) .def("PerformGets", &adios2::py11::Engine::PerformGets) @@ -492,8 +466,7 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def("Flush", &adios2::py11::Engine::Flush) - .def("Close", &adios2::py11::Engine::Close, - pybind11::arg("transportIndex") = -1) + .def("Close", &adios2::py11::Engine::Close, pybind11::arg("transportIndex") = -1) .def("CurrentStep", &adios2::py11::Engine::CurrentStep) @@ -503,11 +476,9 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) .def("Steps", &adios2::py11::Engine::Steps) - .def("LockWriterDefinitions", - &adios2::py11::Engine::LockWriterDefinitions) + .def("LockWriterDefinitions", &adios2::py11::Engine::LockWriterDefinitions) - .def("LockReaderSelections", - &adios2::py11::Engine::LockReaderSelections) + .def("LockReaderSelections", &adios2::py11::Engine::LockReaderSelections) .def("BlocksInfo", &adios2::py11::Engine::BlocksInfo); @@ -531,17 +502,16 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) pybind11::class_(m, "File") .def("__repr__", [](const adios2::py11::File &stream) { - return ""; + return ""; }) // enter and exit are defined for the with-as operator in Python - .def("__enter__", - [](const adios2::py11::File &stream) { return stream; }) - .def("__exit__", - [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) - .def("__iter__", [](adios2::py11::File &stream) { return stream; }, - pybind11::keep_alive<0, 1>()) + .def("__enter__", [](const adios2::py11::File &stream) { return stream; }) + .def("__exit__", [](adios2::py11::File &stream, pybind11::args) { stream.Close(); }) + .def( + "__iter__", [](adios2::py11::File &stream) { return stream; }, + pybind11::keep_alive<0, 1>()) .def("__next__", [](adios2::py11::File &stream) { if (!stream.GetStep()) @@ -551,8 +521,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) return stream; }) - .def("set_parameter", &adios2::py11::File::SetParameter, - pybind11::arg("key"), pybind11::arg("value"), R"md( + .def("set_parameter", &adios2::py11::File::SetParameter, pybind11::arg("key"), + pybind11::arg("value"), R"md( Sets a single parameter. Overwrites value if key exists. Parameters @@ -563,8 +533,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) parameter value )md") - .def("set_parameters", &adios2::py11::File::SetParameters, - pybind11::arg("parameters"), R"md( + .def("set_parameters", &adios2::py11::File::SetParameters, pybind11::arg("parameters"), + R"md( Sets parameters using a dictionary. Removes any previous parameter. @@ -630,15 +600,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void (adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, - const adios2::Dims &, const bool)) & + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, + const adios2::Dims &, const adios2::Dims &, + const adios2::Dims &, const bool)) & adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("shape") = adios2::Dims(), - pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape") = adios2::Dims(), + pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), pybind11::arg("end_step") = false, R"md( writes a self-describing array (numpy) variable @@ -667,14 +634,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void (adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const adios2::Dims &, const adios2::Dims &, - const adios2::Dims &, const adios2::vParams &, const bool)) & + (void(adios2::py11::File::*)( + const std::string &, const pybind11::array &, const adios2::Dims &, + const adios2::Dims &, const adios2::Dims &, const adios2::vParams &, const bool)) & adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("shape"), pybind11::arg("start"), - pybind11::arg("count"), pybind11::arg("operations"), + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("shape"), + pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("operations"), pybind11::arg("end_step") = false, R"md( writes a self-describing array (numpy) variable with operations @@ -704,12 +669,10 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void (adios2::py11::File::*)(const std::string &, - const pybind11::array &, const bool, - const bool)) & + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, const bool, + const bool)) & adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("local_value") = false, + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("local_value") = false, pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable @@ -729,12 +692,10 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write", - (void (adios2::py11::File::*)(const std::string &, - const std::string &, const bool, - const bool)) & + (void(adios2::py11::File::*)(const std::string &, const std::string &, const bool, + const bool)) & adios2::py11::File::Write, - pybind11::arg("name"), pybind11::arg("string"), - pybind11::arg("local_value") = false, + pybind11::arg("name"), pybind11::arg("string"), pybind11::arg("local_value") = false, pybind11::arg("end_step") = false, R"md( writes a self-describing single value string variable @@ -754,14 +715,11 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void (adios2::py11::File::*)( - const std::string &, const pybind11::array &, - const std::string &, const std::string, const bool)) & + (void(adios2::py11::File::*)(const std::string &, const pybind11::array &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, - pybind11::arg("name"), pybind11::arg("array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", - pybind11::arg("end_step") = false, R"md( + pybind11::arg("name"), pybind11::arg("array"), pybind11::arg("variable_name") = "", + pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable Parameters @@ -785,13 +743,11 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void (adios2::py11::File::*)( - const std::string &, const std::string &, const std::string &, - const std::string, const bool)) & + (void(adios2::py11::File::*)(const std::string &, const std::string &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, pybind11::arg("name"), pybind11::arg("string_value"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable @@ -816,13 +772,11 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("write_attribute", - (void (adios2::py11::File::*)( - const std::string &, const std::vector &, - const std::string &, const std::string, const bool)) & + (void(adios2::py11::File::*)(const std::string &, const std::vector &, + const std::string &, const std::string, const bool)) & adios2::py11::File::WriteAttribute, pybind11::arg("name"), pybind11::arg("string_array"), - pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", pybind11::arg("end_step") = false, R"md( writes a self-describing single value array (numpy) variable @@ -847,11 +801,10 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("read_string", - (std::vector(adios2::py11::File::*)( - const std::string &, const size_t)) & + (std::vector(adios2::py11::File::*)(const std::string &, const size_t)) & adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("block_id") = 0, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, R"md( Reads string value for current step (use for streaming mode step by step) @@ -873,13 +826,12 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("read_string", - (std::vector(adios2::py11::File::*)( - const std::string &, const size_t, const size_t, - const size_t)) & + (std::vector(adios2::py11::File::*)(const std::string &, const size_t, + const size_t, const size_t)) & adios2::py11::File::ReadString, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("step_start"), - pybind11::arg("step_count"), pybind11::arg("block_id") = 0, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("step_start"), pybind11::arg("step_count"), + pybind11::arg("block_id") = 0, R"md( Reads string value for a certain step (random access mode) @@ -903,11 +855,10 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("read", - (pybind11::array(adios2::py11::File::*)(const std::string &, - const size_t)) & + (pybind11::array(adios2::py11::File::*)(const std::string &, const size_t)) & adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("block_id") = 0, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("block_id") = 0, R"md( Reads entire variable for current step (streaming mode step by step) @@ -926,13 +877,11 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("read", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const adios2::Dims &, - const adios2::Dims &, const size_t)) & + (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, + const adios2::Dims &, const size_t)) & adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("start") = adios2::Dims(), - pybind11::arg("count") = adios2::Dims(), + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start") = adios2::Dims(), pybind11::arg("count") = adios2::Dims(), pybind11::arg("block_id") = 0, R"md( Reads a selection piece in dimension for current step @@ -959,16 +908,14 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) empty if exception is thrown )md") - .def( - "read", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const adios2::Dims &, const adios2::Dims &, - const size_t, const size_t, const size_t)) & - adios2::py11::File::Read, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("start"), - pybind11::arg("count"), pybind11::arg("step_start"), - pybind11::arg("step_count"), pybind11::arg("block_id") = 0, R"md( + .def("read", + (pybind11::array(adios2::py11::File::*)(const std::string &, const adios2::Dims &, + const adios2::Dims &, const size_t, + const size_t, const size_t)) & + adios2::py11::File::Read, + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("start"), pybind11::arg("count"), pybind11::arg("step_start"), + pybind11::arg("step_count"), pybind11::arg("block_id") = 0, R"md( Random access read allowed to select steps, only valid with File Engines @@ -997,12 +944,11 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) )md") .def("read_attribute", - (pybind11::array(adios2::py11::File::*)( - const std::string &, const std::string &, const std::string)) & + (pybind11::array(adios2::py11::File::*)(const std::string &, const std::string &, + const std::string)) & adios2::py11::File::ReadAttribute, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", R"md( + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( Reads a numpy based attribute Parameters @@ -1026,9 +972,8 @@ PYBIND11_MODULE(ADIOS2_PYTHON_MODULE_NAME, m) (std::vector(adios2::py11::File::*)( const std::string &, const std::string &, const std::string)) & adios2::py11::File::ReadAttributeString, - pybind11::return_value_policy::take_ownership, - pybind11::arg("name"), pybind11::arg("variable_name") = "", - pybind11::arg("separator") = "/", R"md( + pybind11::return_value_policy::take_ownership, pybind11::arg("name"), + pybind11::arg("variable_name") = "", pybind11::arg("separator") = "/", R"md( Read a string attribute Parameters diff --git a/bindings/Python/py11types.h b/bindings/Python/py11types.h index 9c130f17bc..96f784ba18 100644 --- a/bindings/Python/py11types.h +++ b/bindings/Python/py11types.h @@ -36,14 +36,11 @@ struct MPI4PY_Comm #endif -#define ADIOS2_FOREACH_PYTHON_TYPE_1ARG(MACRO) \ - ADIOS2_FOREACH_STDTYPE_1ARG(MACRO) +#define ADIOS2_FOREACH_PYTHON_TYPE_1ARG(MACRO) ADIOS2_FOREACH_STDTYPE_1ARG(MACRO) -#define ADIOS2_FOREACH_NUMPY_TYPE_1ARG(MACRO) \ - ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) +#define ADIOS2_FOREACH_NUMPY_TYPE_1ARG(MACRO) ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) -#define ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(MACRO) \ - ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) +#define ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(MACRO) ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) } // end namespace py11 } // end namespace adios2 diff --git a/cmake/ADIOSFunctions.cmake b/cmake/ADIOSFunctions.cmake index 36257e34d6..71d6ab994c 100644 --- a/cmake/ADIOSFunctions.cmake +++ b/cmake/ADIOSFunctions.cmake @@ -97,15 +97,17 @@ function(GenerateADIOSHeaderConfig) foreach(OPT IN LISTS ARGN) string(TOUPPER ${OPT} OPT_UPPER) string(APPEND ADIOS2_CONFIG_DEFINES " -/* CMake Option: ADIOS_USE_${OPT}=OFF */ +/* CMake Option: ADIOS2_USE_${OPT}=OFF */ #cmakedefine ADIOS2_HAVE_${OPT_UPPER} ") if(ADIOS2_HAVE_${OPT}) set(ADIOS2_HAVE_${OPT_UPPER} 1) + string(APPEND ADIOS2_CONFIG_FEATURE_LIST "\"${OPT_UPPER}\",") else() set(ADIOS2_HAVE_${OPT_UPPER}) endif() endforeach() + string(APPEND ADIOS2_CONFIG_FEATURE_LIST "nullptr") configure_file( ${ADIOS2_SOURCE_DIR}/source/adios2/common/ADIOSConfig.h.in diff --git a/cmake/DetectOptions.cmake b/cmake/DetectOptions.cmake index b3c271c647..3f511e02a8 100644 --- a/cmake/DetectOptions.cmake +++ b/cmake/DetectOptions.cmake @@ -69,12 +69,35 @@ endfunction() # Blosc2 if(ADIOS2_USE_Blosc2 STREQUAL AUTO) - find_package(Blosc2 2.4) + # Prefect CONFIG mode + find_package(Blosc2 2.4 CONFIG QUIET) + if(NOT Blosc2_FOUND) + find_package(Blosc2 2.4 MODULE QUIET) + endif() elseif(ADIOS2_USE_Blosc2) - find_package(Blosc2 2.4 REQUIRED) + # Prefect CONFIG mode + find_package(Blosc2 2.4 CONFIG) + if(NOT Blosc2_FOUND) + find_package(Blosc2 2.4 MODULE REQUIRED) + endif() endif() -if(BLOSC2_FOUND) +if(Blosc2_FOUND) set(ADIOS2_HAVE_Blosc2 TRUE) + if(TARGET Blosc2::blosc2_shared) + set(Blosc2_shlib_available ON) + endif() + + set(adios2_blosc2_tgt Blosc2::Blosc2) + if (Blosc2_VERSION VERSION_GREATER_EQUAL 2.10.1) + if (Blosc2_shlib_available) + set(adios2_blosc2_tgt Blosc2::blosc2_$,shared,static>) + else() + set(adios2_blosc2_tgt Blosc2::blosc2_static) + endif() + endif() + + add_library(adios2_blosc2 INTERFACE) + target_link_libraries(adios2_blosc2 INTERFACE ${adios2_blosc2_tgt}) endif() # BZip2 @@ -170,8 +193,8 @@ endif() set(mpi_find_components C) -if(ADIOS_USE_Kokkos AND ADIOS_USE_CUDA) - message(FATAL_ERROR "ADIOS2_USE_Kokkos is incompatible with ADIOS_USE_CUDA") +if(ADIOS2_USE_Kokkos AND ADIOS2_USE_CUDA) + message(FATAL_ERROR "ADIOS2_USE_Kokkos is incompatible with ADIOS2_USE_CUDA") endif() # Kokkos @@ -193,7 +216,7 @@ if(ADIOS2_USE_Kokkos) enable_language(HIP) endif() if(Kokkos_ENABLE_SYCL) - set(ADIOS2_HAVE_Kokkos_SYCL TRUE) + set(ADIOS2_HAVE_Kokkos_SYCL TRUE) endif() set(ADIOS2_HAVE_GPU_Support TRUE) endif() @@ -216,7 +239,7 @@ if(ADIOS2_USE_CUDA) endif() endif() -if(ADIOS_HAVE_Kokkos AND ADIOS_HAVE_CUDA) +if(ADIOS2_HAVE_Kokkos AND ADIOS2_HAVE_CUDA) message(FATAL_ERROR "The Kokkos and CUDA backends cannot be active concurrently") endif() @@ -318,6 +341,18 @@ elseif(ADIOS2_USE_HDF5) message(FATAL_ERROR "MPI is disabled but parallel HDF5 is detected.") endif() set(ADIOS2_HAVE_HDF5 TRUE) + + # HDF5 VOL requires 1.13+ + if(ADIOS2_USE_HDF5_VOL AND ADIOS2_HAVE_HDF5) + if(HDF5_VERSION GREATER_EQUAL 1.14) + set(ADIOS2_HAVE_HDF5_VOL TRUE) + else() + set(ADIOS2_HAVE_HDF5_VOL FALSE) + if(ADIOS2_USE_HDF5_VOL STREQUAL ON) + message(FATAL_ERROR "ADIOS HDF5_VOL requires HDF5>=1.14+") + endif() + endif() + endif() endif() # IME @@ -410,9 +445,11 @@ if(ADIOS2_USE_SST AND NOT WIN32) endif() endif() if(ADIOS2_HAVE_MPI) - set(CMAKE_REQUIRED_LIBRARIES MPI::MPI_C) - include(CheckCSourceRuns) - check_c_source_runs([=[ + set(CMAKE_REQUIRED_LIBRARIES "MPI::MPI_C;Threads::Threads") + include(CheckCXXSourceRuns) + check_cxx_source_runs([=[ + #include + #include #include #include @@ -422,9 +459,18 @@ if(ADIOS2_USE_SST AND NOT WIN32) int main() { + // Timeout after 5 second + auto task = std::async(std::launch::async, []() { + std::this_thread::sleep_for(std::chrono::seconds(5)); + exit(EXIT_FAILURE); + }); + + char* port_name = new char[MPI_MAX_PORT_NAME]; MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, NULL); - MPI_Open_port(MPI_INFO_NULL, malloc(sizeof(char) * MPI_MAX_PORT_NAME)); + MPI_Open_port(MPI_INFO_NULL, port_name); + MPI_Close_port(port_name); MPI_Finalize(); + exit(EXIT_SUCCESS); }]=] ADIOS2_HAVE_MPI_CLIENT_SERVER) unset(CMAKE_REQUIRED_LIBRARIES) @@ -450,11 +496,6 @@ if(DAOS_FOUND) set(ADIOS2_HAVE_DAOS TRUE) endif() -# BP5 -if(ADIOS2_USE_BP5 AND NOT WIN32) - set(ADIOS2_HAVE_BP5 TRUE) -endif() - #SysV IPC if(UNIX) include(CheckSymbolExists) @@ -505,9 +546,9 @@ endif() # AWS S3 if(ADIOS2_USE_AWSSDK STREQUAL AUTO) - find_package(AWSSDK QUIET COMPONENTS s3) + find_package(AWSSDK 1.10.15 COMPONENTS s3) elseif(ADIOS2_USE_AWSSDK) - find_package(AWSSDK REQUIRED COMPONENTS s3) + find_package(AWSSDK 1.10.15 REQUIRED COMPONENTS s3) endif() if(AWSSDK_FOUND) set(ADIOS2_HAVE_AWSSDK TRUE) diff --git a/cmake/adios2-config-common.cmake.in b/cmake/adios2-config-common.cmake.in index 97e98e54b4..04a41531f1 100644 --- a/cmake/adios2-config-common.cmake.in +++ b/cmake/adios2-config-common.cmake.in @@ -12,6 +12,11 @@ endif() set(ADIOS2_HAVE_Fortran @ADIOS2_HAVE_Fortran@) set(ADIOS2_HAVE_MPI @ADIOS2_HAVE_MPI@) +set(ADIOS2_HAVE_CUDA @ADIOS2_HAVE_CUDA@) +set(ADIOS2_HAVE_Kokkos @ADIOS2_HAVE_Kokkos@) +set(ADIOS2_HAVE_Kokkos_CUDA @ADIOS2_HAVE_Kokkos_CUDA@) +set(ADIOS2_HAVE_Kokkos_HIP @ADIOS2_HAVE_Kokkos_HIP@) +set(ADIOS2_HAVE_Kokkos_SYCL @ADIOS2_HAVE_Kokkos_SYCL@) function(adios2_add_thirdparty_target PackageName) add_library(adios2::thirdparty::${PackageName} INTERFACE IMPORTED) @@ -162,6 +167,12 @@ if(NOT @BUILD_SHARED_LIBS@) adios2_add_thirdparty_target(perfstubs-interface) + find_dependency(ffs) + adios2_add_thirdparty_target(ffs) + set_target_properties(adios2::thirdparty::ffs PROPERTIES + INTERFACE_LINK_LIBRARIES ffs::ffs + ) + set(ADIOS2_HAVE_SST @ADIOS2_HAVE_SST@) if(ADIOS2_HAVE_SST) set(ADIOS2_SST_HAVE_LIBFABRIC @ADIOS2_SST_HAVE_LIBFABRIC@) diff --git a/cmake/adios2-config-install.cmake.in b/cmake/adios2-config-install.cmake.in index 86d3ef64ef..a0d6cf1def 100644 --- a/cmake/adios2-config-install.cmake.in +++ b/cmake/adios2-config-install.cmake.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.12) set(_ADIOS2_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}") diff --git a/cmake/adios2-config.cmake.in b/cmake/adios2-config.cmake.in index 4bb68c27da..21946d6fd2 100644 --- a/cmake/adios2-config.cmake.in +++ b/cmake/adios2-config.cmake.in @@ -1,12 +1,15 @@ set(_ADIOS2_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) list(INSERT CMAKE_MODULE_PATH 0 "@ADIOS2_SOURCE_DIR@/cmake") +if(NOT @BUILD_SHARED_LIBS@) + set(atl_DIR @atl_DIR@) + set(dill_DIR @dill_DIR@) + set(ffs_DIR @ffs_DIR@) +endif() + if(@ADIOS2_HAVE_SST@) set(EVPath_DIR @EVPath_DIR@) if(NOT @BUILD_SHARED_LIBS@) - set(atl_DIR @atl_DIR@) - set(dill_DIR @dill_DIR@) - set(ffs_DIR @ffs_DIR@) set(enet_DIR @enet_DIR@) endif() endif() diff --git a/cmake/install/post/adios2-config-dummy/CMakeLists.txt b/cmake/install/post/adios2-config-dummy/CMakeLists.txt index 7b31c5c911..83db648edd 100644 --- a/cmake/install/post/adios2-config-dummy/CMakeLists.txt +++ b/cmake/install/post/adios2-config-dummy/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.12) project(adios2-config-dummy C CXX) diff --git a/cmake/install/post/generate-adios2-config.sh.in b/cmake/install/post/generate-adios2-config.sh.in index 4603420ffd..1c5139367b 100755 --- a/cmake/install/post/generate-adios2-config.sh.in +++ b/cmake/install/post/generate-adios2-config.sh.in @@ -64,6 +64,12 @@ if [ "${1:0:1}" != "/" ] then # Convert relative paths to absolute based on DESTDIR PREFIX="${DESTDIR:-$(pwd)}/$1" +else + # check if the PREFIX directory exists and prepend DESTDIR if not + if [ ! -d "${PREFIX}" ] + then + PREFIX="${DESTDIR}$1" + fi fi shift diff --git a/docs/environment.yml b/docs/environment.yml index 998a6d65b4..20b0939ac2 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -2,17 +2,16 @@ name: adios2-python-docs channels: - conda-forge - - williamfgc dependencies: - - adios2-openmpi - - breathe==4.33.0 + - breathe==4.35.0 + - cmake - docutils==0.17 - - python - - sphinx=4 -# - funcparserlib>=0.3.6 + - libpython-static + - numpy - pip + - sphinx=5.3 - pip: - blockdiag==3.0.0 - sphinxcontrib-blockdiag==3.0.0 - - sphinx_rtd_theme==1.0.0 + - sphinx_rtd_theme==1.1.1 diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index ab7566389f..0000000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,44 +0,0 @@ -alabaster==0.7.12 -Babel==2.11.0 -blockdiag==3.0.0 -breathe==4.33.0 -brotlipy==0.7.0 -certifi==2022.12.7 -cffi==1.15.1 -charset-normalizer==2.1.1 -colorama==0.4.6 -cryptography==41.0.0 -docutils==0.17 -funcparserlib==1.0.1 -idna==3.4 -imagesize==1.4.1 -importlib-metadata==4.11.4 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -mpi4py==3.1.3 -numpy==1.22.0 -packaging==22.0 -Pillow==9.4.0 -pip==22.3.1 -pycparser==2.21 -Pygments==2.14.0 -pyOpenSSL==23.0.0 -PySocks==1.7.1 -pytz==2022.7 -requests==2.31.0 -setuptools==65.6.3 -snowballstemmer==2.2.0 -Sphinx==4.5.0 -sphinx-rtd-theme==1.0.0 -sphinxcontrib-applehelp==1.0.2 -sphinxcontrib-blockdiag==3.0.0 -sphinxcontrib-devhelp==1.0.2 -sphinxcontrib-htmlhelp==2.0.0 -sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-qthelp==1.0.3 -sphinxcontrib-serializinghtml==1.1.5 -typing_extensions==4.4.0 -urllib3==1.26.13 -webcolors==1.12 -wheel==0.38.4 -zipp==3.11.0 diff --git a/docs/user_guide/make.bat b/docs/user_guide/make.bat index 23ab83d412..fec0995b7a 100644 --- a/docs/user_guide/make.bat +++ b/docs/user_guide/make.bat @@ -1,263 +1,263 @@ -@ECHO OFF - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set BUILDDIR=build -set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source -set I18NSPHINXOPTS=%SPHINXOPTS% source -if NOT "%PAPER%" == "" ( - set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% - set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% -) - -if "%1" == "" goto help - -if "%1" == "help" ( - :help - echo.Please use `make ^` where ^ is one of - echo. html to make standalone HTML files - echo. dirhtml to make HTML files named index.html in directories - echo. singlehtml to make a single large HTML file - echo. pickle to make pickle files - echo. json to make JSON files - echo. htmlhelp to make HTML files and a HTML help project - echo. qthelp to make HTML files and a qthelp project - echo. devhelp to make HTML files and a Devhelp project - echo. epub to make an epub - echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter - echo. text to make text files - echo. man to make manual pages - echo. texinfo to make Texinfo files - echo. gettext to make PO message catalogs - echo. changes to make an overview over all changed/added/deprecated items - echo. xml to make Docutils-native XML files - echo. pseudoxml to make pseudoxml-XML files for display purposes - echo. linkcheck to check all external links for integrity - echo. doctest to run all doctests embedded in the documentation if enabled - echo. coverage to run coverage check of the documentation if enabled - goto end -) - -if "%1" == "clean" ( - for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i - del /q /s %BUILDDIR%\* - goto end -) - - -REM Check if sphinx-build is available and fallback to Python version if any -%SPHINXBUILD% 1>NUL 2>NUL -if errorlevel 9009 goto sphinx_python -goto sphinx_ok - -:sphinx_python - -set SPHINXBUILD=python -m sphinx.__init__ -%SPHINXBUILD% 2> nul -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -:sphinx_ok - - -if "%1" == "html" ( - %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/html. - goto end -) - -if "%1" == "dirhtml" ( - %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. - goto end -) - -if "%1" == "singlehtml" ( - %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. - goto end -) - -if "%1" == "pickle" ( - %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the pickle files. - goto end -) - -if "%1" == "json" ( - %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the JSON files. - goto end -) - -if "%1" == "htmlhelp" ( - %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run HTML Help Workshop with the ^ -.hhp project file in %BUILDDIR%/htmlhelp. - goto end -) - -if "%1" == "qthelp" ( - %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run "qcollectiongenerator" with the ^ -.qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ADIOS2.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ADIOS2.ghc - goto end -) - -if "%1" == "devhelp" ( - %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. - goto end -) - -if "%1" == "epub" ( - %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The epub file is in %BUILDDIR%/epub. - goto end -) - -if "%1" == "latex" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "latexpdf" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf - cd %~dp0 - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "latexpdfja" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf-ja - cd %~dp0 - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "text" ( - %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The text files are in %BUILDDIR%/text. - goto end -) - -if "%1" == "man" ( - %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The manual pages are in %BUILDDIR%/man. - goto end -) - -if "%1" == "texinfo" ( - %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. - goto end -) - -if "%1" == "gettext" ( - %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The message catalogs are in %BUILDDIR%/locale. - goto end -) - -if "%1" == "changes" ( - %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes - if errorlevel 1 exit /b 1 - echo. - echo.The overview file is in %BUILDDIR%/changes. - goto end -) - -if "%1" == "linkcheck" ( - %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck - if errorlevel 1 exit /b 1 - echo. - echo.Link check complete; look for any errors in the above output ^ -or in %BUILDDIR%/linkcheck/output.txt. - goto end -) - -if "%1" == "doctest" ( - %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest - if errorlevel 1 exit /b 1 - echo. - echo.Testing of doctests in the sources finished, look at the ^ -results in %BUILDDIR%/doctest/output.txt. - goto end -) - -if "%1" == "coverage" ( - %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage - if errorlevel 1 exit /b 1 - echo. - echo.Testing of coverage in the sources finished, look at the ^ -results in %BUILDDIR%/coverage/python.txt. - goto end -) - -if "%1" == "xml" ( - %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The XML files are in %BUILDDIR%/xml. - goto end -) - -if "%1" == "pseudoxml" ( - %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. - goto end -) - -:end +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source +set I18NSPHINXOPTS=%SPHINXOPTS% source +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 1>NUL 2>NUL +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ADIOS2.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ADIOS2.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/docs/user_guide/source/advanced/query.rst b/docs/user_guide/source/advanced/query.rst new file mode 100644 index 0000000000..852e0e52dc --- /dev/null +++ b/docs/user_guide/source/advanced/query.rst @@ -0,0 +1,93 @@ +################# +ADIOS2 query API +################# + +The query API in ADIOS2 allows a client to pass a query in XML or json format, +and get back a list of blocks or subblocks that contains hits. +Both BP4 and BP5 engines are supported. + + +The interface +============= +User is expected to pass a query file (configFile), and init a read engine (engine) +to construct a query and evaluate using the engine. +(note that the engine and query should be using the same ADIOS IO) + +.. code-block:: c++ + + class QueryWorker + { + public: + // configFile has query, can be either xml or json + QueryWorker(const std::string &configFile, adios2::Engine &engine); + + // touched_blocks is a list of regions specified by (start, count), + // that contains data that satisfies the query file + void GetResultCoverage(std::vector> &touched_blocks); + ... + } + +A Sample Compound Query +---------------------- + +This query targets a 1D variable "doubleV", data of interest is (x > 6.6) or (x < -0.17) or (2.8 < x < 2.9) +In addition, this query also specied an output region [start=5,count=80]. + + +.. code-block:: xml + + + + + + + + + + + + + + + + + + +Code EXAMPLES: +============== +C++: +---- +.. code-block:: c++ + + while (reader.BeginStep() == adios2::StepStatus::OK) + { + adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); + w.GetResultCoverage(touched_blocks); + + std::cout << " ... now can read out touched blocks ... size=" << touched_blocks.size() + << std::endl; + } + + +The Full C++ example is here: + https://github.com/ornladios/ADIOS2/blob/master/examples/query/test.cpp + + +Python: +------- + +.. code-block:: python + + while (reader.BeginStep() == adios2.StepStatus.OK): + # say only rank 0 wants to process result + var = [queryIO.InquireVariable("T")] + + if (rank == 0): + touched_blocks = w.GetResult() + doAnalysis(reader, touched_blocks, var) + +Full python example is here: + https://github.com/ornladios/ADIOS2/blob/master/testing/adios2/bindings/python/TestQuery.py + + This example generates data, the query file (in xml) and runs the query, all in python. + diff --git a/docs/user_guide/source/setting_up/source/cmake.rst b/docs/user_guide/source/setting_up/source/cmake.rst index 8b0e44e54d..0785c00c07 100644 --- a/docs/user_guide/source/setting_up/source/cmake.rst +++ b/docs/user_guide/source/setting_up/source/cmake.rst @@ -84,7 +84,7 @@ VAR VALUE Description ``ADIOS2_USE_MPI`` **ON**/OFF MPI or non-MPI (serial) build. ``ADIOS2_USE_ZeroMQ`` **ON**/OFF `ZeroMQ `_ for the DataMan engine. ``ADIOS2_USE_HDF5`` **ON**/OFF `HDF5 `_ engine. If HDF5 is not on the syspath, it can be set using ``-DHDF5_ROOT=/path/to/hdf5`` -``ADIOS2_USE_Python`` **ON**/OFF Python bindings. Python 3 will be used if found. If you want to specify a particular python version use ``-DPYTHON_EXECUTABLE=/path/to/interpreter/python`` +``ADIOS2_USE_Python`` **ON**/OFF Python bindings. Python 3 will be used if found. If you want to specify a particular python version use ``-DPYTHON_EXECUTABLE=/path/to/interpreter/python -DPython_FIND_STRATEGY=LOCATION`` ``ADIOS2_USE_Fortran`` **ON**/OFF Bindings for Fortran 90 or above. ``ADIOS2_USE_SST`` **ON**/OFF Simplified Staging Engine (SST) and its dependencies, requires MPI. Can optionally use LibFabric/UCX for RDMA transport. You can specify the LibFabric/UCX path manually with the -DLIBFABRIC_ROOT=... or -DUCX_ROOT=... option. ``ADIOS2_USE_BZip2`` **ON**/OFF `BZIP2 `_ compression. @@ -103,8 +103,8 @@ In addition to the ``ADIOS2_USE_Feature`` options, the following options are als CMake VAR Options Values Description | ==================================== =============================================== =============================== ``BUILD_SHARED_LIBS`` **ON**/OFF Build shared libraries. -``ADIOS2_BUILD_EXAMPLES`` **ON**/OFF Build examples. -``BUILD_TESTING`` **ON**/OFF Build test code. +``ADIOS2_BUILD_EXAMPLES`` ON/**OFF** Build examples. +``BUILD_TESTING`` ON/**OFF** Build test code. ``CMAKE_INSTALL_PREFIX`` /path/to/install (``/usr/local``) Installation location. ``CMAKE_BUILD_TYPE`` Debug/**Release**/RelWithDebInfo/MinSizeRel Compiler optimization levels. ==================================== =============================================== =============================== diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e14d76bb05..316e77723e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,27 +5,6 @@ add_subdirectory(basics) add_subdirectory(hello) -add_subdirectory(query) -add_subdirectory(useCases) -add_subdirectory(inlineMWE) add_subdirectory(plugins) -add_subdirectory(fides) - -if(ADIOS2_HAVE_MPI) - add_subdirectory(heatTransfer) -endif() - -if(ADIOS2_BUILD_EXAMPLES_EXPERIMENTAL) - add_subdirectory(experimental) -endif() - -if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) - add_subdirectory(cuda) -endif() - - -if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_HDF5) - if(HDF5_VERSION VERSION_GREATER_EQUAL 1.14) - add_subdirectory(h5subfile) - endif() -endif() +add_subdirectory(simulations) +add_subdirectory(useCases) diff --git a/examples/ReadMe.md b/examples/ReadMe.md new file mode 100644 index 0000000000..b0c91cd9a8 --- /dev/null +++ b/examples/ReadMe.md @@ -0,0 +1,16 @@ +# ADIOS2 Examples + +This directory contains examples of how to use ADIOS2 in different scenarios. +The examples are written mostly in C++, but also C, Fortran, Python, and Julia. + +They can be found in the following subdirectories, and they should be explored in the order that they are listed: + +1. [hello](hello): The _hello_ examples are meant to introduce you to ADIOS2's IO capabilities and engines. +2. [basics](basics): The _basics_ examples are meant to introduce you to basic concepts of ADIOS2, such as + global/joined/local arrays, values, and variables shapes. +3. [useCases](useCases): The _useCases_ examples are meant to demonstrate how to use ADIOS2 in different scenarios, + such as in situ visualization, and fides schema. +4. [plugins](plugins): The _plugins_ examples are meant to introduce you to the plugin capabilities of ADIOS2, such as + how to develop your own engine or operators. +5. [simulations](simulations): The _simulations_ examples are meant to demonstrate how to integrate ADIOS2 within your + simulation code to read, write and/or stream your simulation data. diff --git a/examples/basics/CMakeLists.txt b/examples/basics/CMakeLists.txt index 94fa54cd4c..972125c4df 100644 --- a/examples/basics/CMakeLists.txt +++ b/examples/basics/CMakeLists.txt @@ -3,7 +3,12 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_subdirectory(globalArray) +if(ADIOS2_HAVE_MPI) + add_subdirectory(globalArray1D) +endif() +add_subdirectory(globalArrayND) add_subdirectory(joinedArray) add_subdirectory(localArray) +add_subdirectory(queryWorker) add_subdirectory(values) +add_subdirectory(variablesShapes) diff --git a/examples/basics/ReadMe.md b/examples/basics/ReadMe.md new file mode 100644 index 0000000000..c33c5545c6 --- /dev/null +++ b/examples/basics/ReadMe.md @@ -0,0 +1,29 @@ +## ADIOS2 basics examples + +The _basics_ examples are meant to introduce you to basic concepts of ADIOS2, such as +global/joined/local arrays, values, and variables shapes. + +They can be found in the following subdirectories, and they should be explored in the order that they are listed: + +1. [globalArray1D](globalArray1D): The _globalArray1D_ example demonstrates how to read and write an + 1-D global array with constant dimensions over time from multiple processors using ADIOS2's BP engine. + * Languages: C, Fortran +2. [globalArrayND](globalArrayND): The _globalArrayND_ example demonstrates how to write an N-D global array with + constant dimensions over time from multiple processors using ADIOS2's BP engine. + * Languages: C++ +3. [localArray](localArray): The _localArray_ example demonstrates how to write and read a local array per processor + with the same name from multiple processors using ADIOS2's BP engine. + * Languages: C++ +4. [joinedArray](joinedArray): The _joinedArray_ example demonstrates how to write local array that is different only in + one dimension so that it can be joined into a global array with the same name from multiple processors at read time + using ADIOS2's ADIOS2's BP engine. + * Languages: C++ +5. [values](values): The _values_ example demonstrates how to write and read a multiple types of variables with a single + value, such as global constant, global value, local constant, and local value using ADIOS2's BP engine. + * Languages: C++, Fortran +6. [variablesShapes](variablesShapes): The _variablesShapes_ example demonstrates how to write supported variables + shapes using stepping and ADIOS2's BP engine. + * Languages: C++, C++ using high-level API +7. [queryWorker](queryWorker): The _queryWorker_ example demonstrates how to read variables using ADIOS2's BP engine + and perform queries on the read data and streams the results. + * Languages: C++ diff --git a/examples/basics/globalArray/CMakeLists.txt b/examples/basics/globalArray/CMakeLists.txt deleted file mode 100644 index a145a8939b..0000000000 --- a/examples/basics/globalArray/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(globalArray_write globalArray_write.cpp) -target_link_libraries(globalArray_write adios2::cxx11) - -if(ADIOS2_HAVE_MPI) - add_executable(globalArray_write_mpi globalArray_write.cpp) - target_link_libraries(globalArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) -endif() diff --git a/examples/basics/globalArray1D/CMakeLists.txt b/examples/basics/globalArray1D/CMakeLists.txt new file mode 100644 index 0000000000..1173b5fab5 --- /dev/null +++ b/examples/basics/globalArray1D/CMakeLists.txt @@ -0,0 +1,80 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsGlobalArray1DExample) + +if(NOT TARGET adios2_core) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI) + add_library(adios2_basics_globalArray1D_mpivars_c OBJECT mpivars.c) + target_link_libraries(adios2_basics_globalArray1D_mpivars_c MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1D_mpivars_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_library(adios2_basics_globalArray1D_decomp_c OBJECT decomp.c) + target_link_libraries(adios2_basics_globalArray1D_decomp_c + adios2_basics_globalArray1D_mpivars_c MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1D_decomp_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DWrite_c globalArray1DWrite.c) + target_link_libraries(adios2_basics_globalArray1DWrite_c + adios2_basics_globalArray1D_mpivars_c + adios2_basics_globalArray1D_decomp_c + adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1DWrite_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DRead_c globalArray1DRead.c) + target_link_libraries(adios2_basics_globalArray1DRead_c + adios2_basics_globalArray1D_mpivars_c + adios2_basics_globalArray1D_decomp_c + adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArray1DRead_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_library(adios2_basics_globalArray1D_mpivars_f OBJECT mpivars.F90) + target_link_libraries(adios2_basics_globalArray1D_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1D_mpivars_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_library(adios2_basics_globalArray1D_decomp_f OBJECT decomp.F90) + target_link_libraries(adios2_basics_globalArray1D_decomp_f + adios2_basics_globalArray1D_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1D_decomp_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DWrite_f globalArray1DWrite.F90) + target_link_libraries(adios2_basics_globalArray1DWrite_f + adios2_basics_globalArray1D_mpivars_f + adios2_basics_globalArray1D_decomp_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1DWrite_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_globalArray1DRead_f globalArray1DRead.F90) + target_link_libraries(adios2_basics_globalArray1DRead_f + adios2_basics_globalArray1D_mpivars_f + adios2_basics_globalArray1D_decomp_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_globalArray1DRead_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +endif() diff --git a/examples/basics/globalArray1D/decomp.F90 b/examples/basics/globalArray1D/decomp.F90 new file mode 100644 index 0000000000..b39d93d92c --- /dev/null +++ b/examples/basics/globalArray1D/decomp.F90 @@ -0,0 +1,53 @@ +! Helper functions for all examples +module decomp +contains + +! random integer from {minv, minv+1, ..., maxv} +! including minv and maxv +function get_random(minv, maxv) result(n) + implicit none + integer, intent(in) :: minv, maxv + real :: r + integer :: n + call random_number(r) + n = minv + FLOOR((maxv+1-minv)*r) +end function get_random + +! gather the local sizes of arrays and sum them up +! so that each process knows the global shape +! and its own offset in the global space +subroutine gather_decomp_1d(mysize, myshape, myoffset) + use mpivars + implicit none + integer*8, intent(in) :: mysize + integer*8, intent(out) :: myshape, myoffset + integer*8, dimension(:), allocatable :: sizes + + allocate(sizes(nproc)) + call MPI_Allgather( mysize, 1, MPI_LONG_LONG, & + sizes, 1, MPI_LONG_LONG, & + app_comm, ierr) + myshape = sum(sizes) + myoffset = sum(sizes(1:rank)) + deallocate(sizes) +end subroutine gather_decomp_1d + +subroutine decompose_1d(globalsize, myoffset, mysize) + use mpivars + implicit none + integer*8, intent(in) :: globalsize + integer*8, intent(out) :: myoffset, mysize + integer*8 :: rem + + mysize = globalsize/nproc + rem = globalsize-(nproc*mysize) + if (rank < rem) then + mysize = mysize + 1 + myoffset = rank*mysize + else + myoffset = rank*mysize + rem + endif +end subroutine decompose_1d + +end module decomp + diff --git a/examples/basics/globalArray1D/decomp.c b/examples/basics/globalArray1D/decomp.c new file mode 100644 index 0000000000..bb7d3300a5 --- /dev/null +++ b/examples/basics/globalArray1D/decomp.c @@ -0,0 +1,67 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + * + * Helper functions for all examples + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include +#include + +/* random integer from {minv, minv+1, ..., maxv} + including minv and maxv */ +long long int get_random(int minv, int maxv) +{ + long long int n; + time_t t; + /* Intializes random number generator */ + srand((unsigned)time(&t)); + n = (rand() % (maxv - minv + 1)) + minv; + return n; +} +/* gather the local sizes of arrays and sum them up + so that each process knows the global shape + and its own offset in the global space */ +void gather_decomp_1d(long long int *mysize, long long int *myshape, long long int *myoffset) +{ + long long int *sizes; + int i; + sizes = malloc(sizeof(long long int) * (size_t)nproc); + MPI_Allgather(mysize, 1, MPI_LONG_LONG, sizes, 1, MPI_LONG_LONG, app_comm); + + *myshape = 0; + for (i = 0; i < nproc; i++) + { + *myshape += sizes[i]; + } + *myoffset = 0; + for (i = 0; i < rank; i++) + { + *myoffset += sizes[i]; + } + + free(sizes); + return; +} + +void decomp_1d(long long int globalsize, long long int *myoffset, long long int *mysize) +{ + long long int rem; + *mysize = globalsize / nproc; + rem = globalsize - (nproc * *mysize); + if (rank < rem) + { + mysize = mysize + 1; + *myoffset = rank * *mysize; + } + else + { + *myoffset = rank * *mysize + rem; + } + return; +} diff --git a/examples/basics/globalArray1D/decomp.h b/examples/basics/globalArray1D/decomp.h new file mode 100644 index 0000000000..e972714844 --- /dev/null +++ b/examples/basics/globalArray1D/decomp.h @@ -0,0 +1,14 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ + +#ifndef ADIOS2EXAMPLES_DECOMP_H +#define ADIOS2EXAMPLES_DECOMP_H + +extern long long int get_random(int, int); +extern void gather_decomp_1d(long long int *, long long int *, long long int *); +extern void decomp_1d(long long int, long long int *, long long int *); +#endif // ADIOS2EXAMPLES_DECOMP_H diff --git a/examples/basics/globalArray1D/globalArray1DRead.F90 b/examples/basics/globalArray1D/globalArray1DRead.F90 new file mode 100644 index 0000000000..725f1992cd --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DRead.F90 @@ -0,0 +1,104 @@ +program adios2_global_array_1d_read + use mpivars + use adios2 + implicit none + + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(234) + call adios2_init(adios, app_comm, ierr) + + call reader() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine reader + use mpivars + use decomp + use adios2 + implicit none + + character(len=256), parameter :: streamname = "adios2-global-array-1d-f.bp" + + type(adios2_io) :: io + type(adios2_engine) :: engine + type(adios2_variable) :: var_g + integer :: step, istatus + + ! Application variables + ! g = 1D distributed array, global shape and per-process size is fixed + + real*4, dimension(:), allocatable :: g + integer :: ndims + integer*8, dimension(:), allocatable :: fixed_shape + integer*8, dimension(1) :: fixed_start, fixed_count + + call adios2_declare_io (io, adios, 'input', ierr) + call adios2_open(engine, io, streamname, adios2_mode_read, ierr) + if (ierr .ne. 0) then + print '(" Failed to open stream: ",a)', streamname + print '(" open stream ierr=: ",i0)', ierr + return + endif + + ! Reading steps + step = 0 + do + call adios2_begin_step(engine, adios2_step_mode_read, 0.0, istatus, ierr) + if (ierr /= 0) then + print '(" Failure when trying to get next step: ",a)', streamname + exit + endif + if (istatus == adios2_step_status_end_of_stream) then + ! Stream has terminated, no more steps are available + !print '(" Input stream has terminated: ",a)', streamname + exit + endif + + ! Variable pointer MUST be retrieved every step, the reference + ! will go invalid after adios2_end_step + call adios2_inquire_variable(var_g, io, "GlobalArray", ierr ) + + ! Get variable dimensions and do decomposition in the first step + ! These don't change for the stream in this example + if (step == 0) then + ! fixed_shape is allocated in the next call + call adios2_variable_shape(fixed_shape, ndims, var_g, ierr) + + call decompose_1d(fixed_shape(1), fixed_start(1), fixed_count(1)) + allocate(g(fixed_count(1))) + + write (*,100) "Read plan rank=", rank, & + " global shape = ", fixed_shape(1), & + " local count = ", fixed_count(1), & + " offset = ", fixed_start(1) +100 format (a,i2,a,i4,a,i1,a,i4) + endif + + call adios2_set_selection(var_g, 1, fixed_start, fixed_count, ierr) + call adios2_get(engine, var_g, g, ierr) + call adios2_end_step(engine, ierr) + + ! g[] is now filled with data AFTER adios2_end_step/adios2_perform_gets + ! or should call adios2_get(engine, var_g, g, adios2_mode_sync, ierr) + ! to get it immediately in the get() call + + step = step + 1 + enddo + + ! Close the output + call adios2_close(engine, ierr) + + deallocate(g) + deallocate(fixed_shape) + +end subroutine reader + + +end program adios2_global_array_1d_read diff --git a/examples/basics/globalArray1D/globalArray1DRead.c b/examples/basics/globalArray1D/globalArray1DRead.c new file mode 100644 index 0000000000..288ce9f11b --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DRead.c @@ -0,0 +1,86 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include + +void reader(adios2_adios *adios) +{ + int step; + float *g; + const char *streamname = "adios2-global-array-1d-c.bp"; + adios2_step_status err; + + long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + + adios2_io *io = adios2_declare_io(adios, "input"); + size_t shape[1]; + shape[0] = (size_t)fixed_shape; + + adios2_engine *engine = adios2_open(io, streamname, adios2_mode_read); + step = 0; + do + { + adios2_begin_step(engine, adios2_step_mode_read, 10.0, &err); + adios2_variable *var_g = adios2_inquire_variable(io, "GlobalArray"); + if (step == 0) + { + /* fixed_shape is allocated in the next call*/ + adios2_variable_shape(shape, var_g); + fixed_shape = (long long int)shape[0]; + decomp_1d(fixed_shape, &fixed_start, &fixed_count); + g = malloc((size_t)fixed_count * sizeof(float)); + + printf("Read plan rank = %d global shape = %lld local count = %lld " + "offset = %lld\n", + rank, fixed_shape, fixed_count, fixed_start); + } + adios2_end_step(engine); + step++; + } while (err != adios2_step_status_end_of_stream); + // Close the output + adios2_close(engine); + free(g); + + if (rank == 0) + { + printf("Try the following: \n"); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " + "%lld \n", + fixed_shape); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " + "%lld \n ", + fixed_shape); + printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + } +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + init_mpi(123, argc, argv); +#endif + + { +#if ADIOS2_USE_MPI + + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + reader(adios); + adios2_finalize(adios); + } + +#if ADIOS2_USE_MPI + finalize_mpi(); +#endif + + return 0; +} diff --git a/examples/basics/globalArray1D/globalArray1DWrite.F90 b/examples/basics/globalArray1D/globalArray1DWrite.F90 new file mode 100644 index 0000000000..90d0778909 --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DWrite.F90 @@ -0,0 +1,93 @@ +program adios2_global_array_1d_write + use mpivars + use adios2 + implicit none + integer, parameter :: numsteps = 5 + + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(123) + call adios2_init(adios, app_comm, ierr) + + call writer() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine writer + use mpivars + use decomp + use adios2 + implicit none + + type(adios2_io) :: io + type(adios2_engine) :: engine + type(adios2_variable) :: var_g + type(adios2_attribute) :: attr + integer :: step + + ! Application variables + ! g = 1D distributed array, + ! global shape and per-process size is fixed + + real*4, dimension(:), allocatable :: g + character(80), parameter :: ga = "Global Array with fixed shape and decomposition" + + integer, parameter :: mincount = 2, maxcount = 5 + integer*8, dimension(1) :: fixed_shape, fixed_start, fixed_count + + fixed_count(1) = get_random(mincount, maxcount) + allocate(g(fixed_count(1))) + call gather_decomp_1d(fixed_count(1), fixed_shape(1), fixed_start(1)) + + call adios2_declare_io (io, adios, 'output', ierr) + + call adios2_define_variable(var_g, io, "GlobalArray", & + adios2_type_real4, 1, & + fixed_shape, fixed_start, fixed_count, & + adios2_constant_dims, ierr) + + call adios2_define_attribute(attr, io, "GlobalArray/info", ga, ierr) + + call adios2_open(engine, io, "adios2-global-array-1d-f.bp", adios2_mode_write, ierr) + + write (*,100) "Decomp rank=", rank, & + " global shape = ", fixed_shape(1), & + " local count = ", fixed_count(1), & + " offset = ", fixed_start(1) +100 format (a,i2,a,i4,a,i1,a,i4) + + ! Computation/output loop + do step=0,numsteps-1 + g = rank + (step+1)/100.0 + ! Output all data + call adios2_begin_step(engine, adios2_step_mode_append, ierr) + call adios2_put(engine, var_g, g, ierr); + call adios2_end_step(engine, ierr) + enddo + + ! Close the output + call adios2_close(engine, ierr) + + deallocate(g) + + if (rank == 0) then + write (*,*) "Try the following: " + write (*,'(a,a,i4)') & + " bpls -la adios2-global-array-1d-f.bp ", & + "GlobalArray -d -n ", fixed_shape(1) + write (*,'(a,a,i4)') & + " bpls -la adios2-global-array-1d-f.bp ", & + "GlobalArray -d -t -n ", fixed_shape(1) + write (*,'(a)') & + " mpirun -n 2 ./adios2-global-array-1d-read-f " + endif +end subroutine writer + + +end program adios2_global_array_1d_write diff --git a/examples/basics/globalArray1D/globalArray1DWrite.c b/examples/basics/globalArray1D/globalArray1DWrite.c new file mode 100644 index 0000000000..4ae38ed3da --- /dev/null +++ b/examples/basics/globalArray1D/globalArray1DWrite.c @@ -0,0 +1,99 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "decomp.h" +#include "mpivars.h" +#include +#include +#include + +void writer(adios2_adios *adios) +{ + int step, i; + float *g; + const int mincount = 2; + const int maxcount = 5; + const int numsteps = 5; + adios2_step_status err; + + long long int fixed_shape = 0, fixed_start = 0, fixed_count = 0; + + /* Application variables + g = 1D distributed array, + global shape and per-process size is fixed */ + fixed_count = get_random(mincount, maxcount); + g = malloc((size_t)fixed_count * sizeof(float)); + gather_decomp_1d(&fixed_count, &fixed_shape, &fixed_start); + + adios2_io *io = adios2_declare_io(adios, "output"); + size_t shape[1]; + shape[0] = (size_t)fixed_shape; + + size_t start[1]; + start[0] = (size_t)fixed_start; + + size_t count[1]; + count[0] = (size_t)fixed_count; + + adios2_variable *var_g = adios2_define_variable(io, "GlobalArray", adios2_type_float, 1, shape, + start, count, adios2_constant_dims_true); + + adios2_engine *engine = adios2_open(io, "adios2-global-array-1d-c.bp", adios2_mode_write); + printf("Decmp rank = %d global shape = %lld local count = %lld offset = " + "%lld\n", + rank, fixed_shape, fixed_count, fixed_start); + for (step = 0; step < numsteps; step++) + { + for (i = 0; i < fixed_count; i++) + { + g[i] = (float)(rank + (step + 1) / 100.0); + } + + adios2_begin_step(engine, adios2_step_mode_append, 10.0f, &err); + adios2_put(engine, var_g, g, adios2_mode_deferred); + adios2_end_step(engine); + } + // Close the output + adios2_close(engine); + free(g); + + if (rank == 0) + { + printf("Try the following: \n"); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -n " + "%lld \n", + fixed_shape); + printf(" bpls -la adios2-global-array-1d-c.bp GlobalArray -d -t -n " + "%lld \n ", + fixed_shape); + printf(" mpirun -n 2 ./adios2-global-array-1d-read-c \n"); + } +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + init_mpi(123, argc, argv); +#endif + + { +#if ADIOS2_USE_MPI + + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + + writer(adios); + adios2_finalize(adios); + } + +#if ADIOS2_USE_MPI + finalize_mpi(); +#endif + + return 0; +} diff --git a/examples/basics/globalArray1D/mpivars.F90 b/examples/basics/globalArray1D/mpivars.F90 new file mode 100644 index 0000000000..323e4b0c15 --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.F90 @@ -0,0 +1,30 @@ +module mpivars + implicit none + include 'mpif.h' + + integer:: app_comm, rank, nproc + integer:: wrank, wnproc + integer:: ierr + +contains + +subroutine init_mpi(color) + integer, intent(in):: color + call MPI_Init(ierr) + ! World comm spans all applications started with the same mpirun command + call MPI_Comm_rank(MPI_COMM_WORLD, wrank, ierr) + call MPI_Comm_size(MPI_COMM_WORLD, wnproc, ierr) + + ! Have to split and create a 'world' communicator for this app only + ! color must be unique for each application + call MPI_Comm_split (MPI_COMM_WORLD, color, wrank, app_comm, ierr) + call MPI_Comm_rank (app_comm, rank, ierr) + call MPI_Comm_size (app_comm, nproc , ierr) +end subroutine init_mpi + +subroutine finalize_mpi() + call MPI_Finalize(ierr) +end subroutine finalize_mpi + +end module mpivars + diff --git a/examples/basics/globalArray1D/mpivars.c b/examples/basics/globalArray1D/mpivars.c new file mode 100644 index 0000000000..5c4aa5634b --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.c @@ -0,0 +1,29 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#include "mpivars.h" +#include + +int rank, nproc; +int wrank, wnproc; +MPI_Comm app_comm; + +void init_mpi(int color, int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + /* World comm spans all applications started with the same mpirun command */ + MPI_Comm_rank(MPI_COMM_WORLD, &wrank); + MPI_Comm_size(MPI_COMM_WORLD, &wnproc); + + /* Have to split and create a 'world' communicator for this app only + color must be unique for each application*/ + MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &app_comm); + MPI_Comm_rank(app_comm, &rank); + MPI_Comm_size(app_comm, &nproc); + return; +} + +void finalize_mpi() { MPI_Finalize(); } diff --git a/examples/basics/globalArray1D/mpivars.h b/examples/basics/globalArray1D/mpivars.h new file mode 100644 index 0000000000..98c00586d3 --- /dev/null +++ b/examples/basics/globalArray1D/mpivars.h @@ -0,0 +1,14 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Created by Dmitry Ganyushin ganyushindi@ornl.gov + */ +#ifndef ADIOS2EXAMPLES_MPIVARS_H +#define ADIOS2EXAMPLES_MPIVARS_H +#include +extern int rank, nproc; +extern MPI_Comm app_comm; +void init_mpi(int, int, char *argv[]); +void finalize_mpi(); +#endif // ADIOS2EXAMPLES_MPIVARS_H diff --git a/examples/basics/globalArrayND/CMakeLists.txt b/examples/basics/globalArrayND/CMakeLists.txt new file mode 100644 index 0000000000..f1d131c5fa --- /dev/null +++ b/examples/basics/globalArrayND/CMakeLists.txt @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsGlobalArrayNDExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_globalArrayNDWrite globalArrayNDWrite.cpp) +target_link_libraries(adios2_basics_globalArrayNDWrite adios2::cxx11) +install(TARGETS adios2_basics_globalArrayNDWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_basics_globalArrayNDWrite_mpi globalArrayNDWrite.cpp) + target_link_libraries(adios2_basics_globalArrayNDWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_globalArrayNDWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/basics/globalArray/globalArray_write.cpp b/examples/basics/globalArrayND/globalArrayNDWrite.cpp similarity index 93% rename from examples/basics/globalArray/globalArray_write.cpp rename to examples/basics/globalArrayND/globalArrayNDWrite.cpp index f12f225d1c..b1509b7b54 100644 --- a/examples/basics/globalArray/globalArray_write.cpp +++ b/examples/basics/globalArrayND/globalArrayNDWrite.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - io.SetEngine("BP5"); + io.SetEngine("BPFile"); io.SetParameter("AggregationType", "TwoLevelShm"); io.SetParameter("AggregatorRatio", "4"); @@ -94,14 +94,15 @@ int main(int argc, char *argv[]) for (size_t i = 0; i < Nx; i++) { - row[i] = step * Nx * nproc * 1.0 + rank * Nx * 1.0 + (double)i; + row[i] = static_cast(step) * Nx * nproc * 1.0 + rank * Nx * 1.0 + + static_cast(i); } // Make a 2D selection to describe the local dimensions of the // variable we write and its offsets in the global spaces // adios2::SelectionBoundingBox sel(); - varGlobalArray.SetSelection(adios2::Box( - {static_cast(rank), 0}, {1, static_cast(Nx)})); + varGlobalArray.SetSelection(adios2::Box({static_cast(rank), 0}, + {1, static_cast(Nx)})); writer.Put(varGlobalArray, row.data()); writer.Put(varStep, step); diff --git a/examples/basics/joinedArray/CMakeLists.txt b/examples/basics/joinedArray/CMakeLists.txt index 0ac015c3a1..a342d75293 100644 --- a/examples/basics/joinedArray/CMakeLists.txt +++ b/examples/basics/joinedArray/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(joinedArray_write joinedArray_write.cpp) -target_link_libraries(joinedArray_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsJoinedArrayExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_joinedArrayWrite joinedArrayWrite.cpp) +target_link_libraries(adios2_basics_joinedArrayWrite adios2::cxx11) +install(TARGETS adios2_basics_joinedArrayWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(joinedArray_write_mpi joinedArray_write.cpp) - target_link_libraries(joinedArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_joinedArrayWrite_mpi joinedArrayWrite.cpp) + target_link_libraries(adios2_basics_joinedArrayWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_joinedArrayWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/basics/joinedArray/joinedArray_write.cpp b/examples/basics/joinedArray/joinedArrayWrite.cpp similarity index 92% rename from examples/basics/joinedArray/joinedArray_write.cpp rename to examples/basics/joinedArray/joinedArrayWrite.cpp index fd34596b8f..e54f1206a4 100644 --- a/examples/basics/joinedArray/joinedArray_write.cpp +++ b/examples/basics/joinedArray/joinedArrayWrite.cpp @@ -73,15 +73,15 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - io.SetEngine("BP4"); + io.SetEngine("BPFile"); /* * Define joinable local array: type, name, global and local size * Starting offset can be an empty vector * Only one global dimension can be joined */ - adios2::Variable varTable = io.DefineVariable( - "table", {adios2::JoinedDim, Ncols}, {}, {Nrows, Ncols}); + adios2::Variable varTable = + io.DefineVariable("table", {adios2::JoinedDim, Ncols}, {}, {Nrows, Ncols}); // adios2::Operator op = adios.DefineOperator("blosc", "blosc"); // varTable.AddOperation(op, {{"clevel", std::to_string(1)}}); @@ -98,8 +98,8 @@ int main(int argc, char *argv[]) { for (unsigned int col = 0; col < Ncols; col++) { - mytable[row * Ncols + col] = static_cast( - step * 10.0 + rank * 1.0 + row * 0.1 + col * 0.01); + mytable[row * Ncols + col] = + static_cast(step * 10.0 + rank * 1.0 + row * 0.1 + col * 0.01); } } diff --git a/examples/basics/localArray/CMakeLists.txt b/examples/basics/localArray/CMakeLists.txt index 1d304a647e..a43a61550f 100644 --- a/examples/basics/localArray/CMakeLists.txt +++ b/examples/basics/localArray/CMakeLists.txt @@ -3,13 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(localArray_write localArray_write.cpp) -target_link_libraries(localArray_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsLocalArrayExample) -add_executable(localArray_read localArray_read.cpp) -target_link_libraries(localArray_read adios2::cxx11) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_localArrayWrite localArrayWrite.cpp) +target_link_libraries(adios2_basics_localArrayWrite adios2::cxx11) +install(TARGETS adios2_basics_localArrayWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_basics_localArrayRead localArrayRead.cpp) +target_link_libraries(adios2_basics_localArrayRead adios2::cxx11) +install(TARGETS adios2_basics_localArrayRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(localArray_write_mpi localArray_write.cpp) - target_link_libraries(localArray_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_localArrayWrite_mpi localArrayWrite.cpp) + target_link_libraries(adios2_basics_localArrayWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_localArrayWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/basics/localArray/localArray_read.cpp b/examples/basics/localArray/localArrayRead.cpp similarity index 92% rename from examples/basics/localArray/localArray_read.cpp rename to examples/basics/localArray/localArrayRead.cpp index c3c37cb108..cc3dd6adb9 100644 --- a/examples/basics/localArray/localArray_read.cpp +++ b/examples/basics/localArray/localArrayRead.cpp @@ -57,8 +57,7 @@ std::string DimsToString(const adios2::Dims &dims) return s; } -void ReadVariable(const std::string &name, adios2::IO &io, - adios2::Engine &reader, size_t step) +void ReadVariable(const std::string &name, adios2::IO &io, adios2::Engine &reader, size_t step) { adios2::Variable variable = io.InquireVariable(name); @@ -66,8 +65,8 @@ void ReadVariable(const std::string &name, adios2::IO &io, { auto blocksInfo = reader.BlocksInfo(variable, step); - std::cout << " " << name << " has " << blocksInfo.size() - << " blocks in step " << step << std::endl; + std::cout << " " << name << " has " << blocksInfo.size() << " blocks in step " << step + << std::endl; // create a data vector for each block std::vector> dataSet; @@ -89,8 +88,7 @@ void ReadVariable(const std::string &name, adios2::IO &io, i = 0; for (const auto &info : blocksInfo) { - std::cout << " block " << info.BlockID - << " size = " << DimsToString(info.Count) + std::cout << " block " << info.BlockID << " size = " << DimsToString(info.Count) << " offset = " << DimsToString(info.Start) << " : "; for (const auto datum : dataSet[i]) @@ -103,8 +101,7 @@ void ReadVariable(const std::string &name, adios2::IO &io, } else { - std::cout << " Variable " << name << " not found in step " << step - << std::endl; + std::cout << " Variable " << name << " not found in step " << step << std::endl; } } @@ -127,8 +124,7 @@ int main(int argc, char *argv[]) { // Begin step - adios2::StepStatus read_status = - reader.BeginStep(adios2::StepMode::Read, 10.0f); + adios2::StepStatus read_status = reader.BeginStep(adios2::StepMode::Read, 10.0f); if (read_status == adios2::StepStatus::NotReady) { // std::cout << "Stream not ready yet. Waiting...\n"; diff --git a/examples/basics/localArray/localArray_write.cpp b/examples/basics/localArray/localArrayWrite.cpp similarity index 96% rename from examples/basics/localArray/localArray_write.cpp rename to examples/basics/localArray/localArrayWrite.cpp index d9541d9713..cdef7fbf96 100644 --- a/examples/basics/localArray/localArray_write.cpp +++ b/examples/basics/localArray/localArrayWrite.cpp @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - io.SetEngine("BP5"); + io.SetEngine("BPFile"); io.SetParameters({{"verbose", "4"}}); /* @@ -99,15 +99,13 @@ int main(int argc, char *argv[]) * Global dimension and starting offset must be an empty vector * Here the size of the local array is the same on every process */ - adios2::Variable varV0 = - io.DefineVariable("v0", {}, {}, {Nglobal}); + adios2::Variable varV0 = io.DefineVariable("v0", {}, {}, {Nglobal}); /* * v1 is similar to v0 but on every process the local size * is a different value */ - adios2::Variable varV1 = - io.DefineVariable("v1", {}, {}, {Nx}); + adios2::Variable varV1 = io.DefineVariable("v1", {}, {}, {Nx}); /* * Define local array: type, name diff --git a/examples/basics/queryWorker/CMakeLists.txt b/examples/basics/queryWorker/CMakeLists.txt new file mode 100644 index 0000000000..7cce9e5c4c --- /dev/null +++ b/examples/basics/queryWorker/CMakeLists.txt @@ -0,0 +1,28 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsQueryWorkerExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_basics_queryWorker queryWorker.cpp) + target_link_libraries(adios2_basics_queryWorker adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_queryWorker RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + diff --git a/examples/basics/queryWorker/ReadMe.md b/examples/basics/queryWorker/ReadMe.md new file mode 100644 index 0000000000..a241abfefd --- /dev/null +++ b/examples/basics/queryWorker/ReadMe.md @@ -0,0 +1,11 @@ +### ADIOS2 queryWorker example + +The _queryWorker_ example demonstrates how to read variables using ADIOS2's BP engine +and perform queries on the read data and streams the results. + +1. q1.json is a json query file for one var + +2. q2.json is a composite query + +3. The bp*xml are the from heat transfer example with bp4 engine, and tag is added at the end for xml + query spec diff --git a/examples/query/configs/bp4io.xml b/examples/basics/queryWorker/configs/bp4io.xml similarity index 99% rename from examples/query/configs/bp4io.xml rename to examples/basics/queryWorker/configs/bp4io.xml index 65245c97e6..d921181b65 100644 --- a/examples/query/configs/bp4io.xml +++ b/examples/basics/queryWorker/configs/bp4io.xml @@ -1,6 +1,6 @@ diff --git a/examples/query/configs/bp4io_composite.xml b/examples/basics/queryWorker/configs/bp4io_composite.xml similarity index 98% rename from examples/query/configs/bp4io_composite.xml rename to examples/basics/queryWorker/configs/bp4io_composite.xml index 4e6136b4e4..412f883bcd 100644 --- a/examples/query/configs/bp4io_composite.xml +++ b/examples/basics/queryWorker/configs/bp4io_composite.xml @@ -1,7 +1,7 @@ diff --git a/examples/query/configs/q1.json b/examples/basics/queryWorker/configs/q1.json similarity index 100% rename from examples/query/configs/q1.json rename to examples/basics/queryWorker/configs/q1.json diff --git a/examples/query/configs/q2.json b/examples/basics/queryWorker/configs/q2.json similarity index 100% rename from examples/query/configs/q2.json rename to examples/basics/queryWorker/configs/q2.json diff --git a/examples/basics/queryWorker/queryWorker.cpp b/examples/basics/queryWorker/queryWorker.cpp new file mode 100644 index 0000000000..c6cd4e32b9 --- /dev/null +++ b/examples/basics/queryWorker/queryWorker.cpp @@ -0,0 +1,128 @@ +#include "adios2.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// touched block ids are printed. +void queryIDs(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) +{ + adios2::Engine reader = queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); + // adios2::QueryWorker* worker = NULL; + queryIO.SetParameter("StreamReader", "true"); + std::vector touched_blockIDs; + + while (reader.BeginStep() == adios2::StepStatus::OK) + { + adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); + w.GetResultCoverage(touched_blockIDs); + + std::cout << " Num touched blocks =" << touched_blockIDs.size() << std::endl; + for (auto n : touched_blockIDs) + { + std::cout << "\t[" << n << "] " << std::endl; + } + + reader.EndStep(); + } + reader.Close(); +} + +void queryWithStreaming(adios2::IO &queryIO, std::string &dataFileName, std::string &queryFile) +{ + adios2::Engine reader = queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); + // adios2::QueryWorker* worker = NULL; + queryIO.SetParameter("StreamReader", "true"); + std::vector> touched_blocks; + + while (reader.BeginStep() == adios2::StepStatus::OK) + { + adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); + w.GetResultCoverage(touched_blocks); + + std::cout << " Num touched regions =" + << touched_blocks.size() + // std::cout << " ... now can read out touched blocks ... size=" << + // touched_blocks.size() + << std::endl; + for (auto n : touched_blocks) + { + std::ostringstream startStr; + std::ostringstream countStr; + for (size_t k = 0; k < n.first.size(); k++) + { + startStr << n.first[k] << " "; + countStr << n.second[k] << " "; + } + std::cout << "\t[" << startStr.str() << "] [" << countStr.str() << "]" << std::endl; + } + reader.EndStep(); + } + reader.Close(); +} + +int main(int argc, char *argv[]) +{ + int provided; + + // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + try + { + std::string configFileName = "query.xml"; + std::string dataFileName = "/tmp/heatbp4.bp"; + if (argc <= 2) + { + std::cout << "Usage: " << argv[0] << " configFileName dataFilePath (queryFile)" + << std::endl; + std::cout << " e.g. " << argv[0] << " bp4io.xml heat_bp4.bp/ " << std::endl; + std::cout << " or " << argv[0] << " bp4io.xml heat_bp4.bp/ q1.json" << std::endl; + return 0; + } + + configFileName = argv[1]; + dataFileName = argv[2]; + + adios2::ADIOS ad = adios2::ADIOS(configFileName, MPI_COMM_WORLD); + + adios2::IO queryIO = ad.DeclareIO("query"); + + std::string queryFile = configFileName; + if (argc > 3) + { + queryFile = argv[3]; + } + if (rank == 0) + { + std::cout << " using config file = " << configFileName << std::endl; + std::cout << " data file = " << dataFileName << std::endl; + std::cout << " queryfile = " << queryFile << std::endl; + } + + queryIDs(queryIO, dataFileName, queryFile); + + std::cout << "\n" << std::endl; + queryWithStreaming(queryIO, dataFileName, queryFile); + + return 0; + } + catch (std::exception &e) + { + std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; + std::cout << e.what() << "\n"; + } + + MPI_Finalize(); + + return 0; +} diff --git a/examples/basics/values/CMakeLists.txt b/examples/basics/values/CMakeLists.txt index f36b4c745a..f37b7da6ab 100644 --- a/examples/basics/values/CMakeLists.txt +++ b/examples/basics/values/CMakeLists.txt @@ -3,10 +3,51 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(values_write values_write.cpp) -target_link_libraries(values_write adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsValuesExample) + +if(NOT TARGET adios2_core) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_valuesWrite valuesWrite.cpp) +target_link_libraries(adios2_basics_valuesWrite adios2::cxx11) +install(TARGETS adios2_basics_valuesWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(values_write_mpi values_write.cpp) - target_link_libraries(values_write_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_basics_valuesWrite_mpi valuesWrite.cpp) + target_link_libraries(adios2_basics_valuesWrite_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_valuesWrite_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_library(adios2_basics_values_mpivars_f OBJECT mpivars.F90) + target_link_libraries(adios2_basics_values_mpivars_f MPI::MPI_Fortran) + install(TARGETS adios2_basics_values_mpivars_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_values_f values.F90) + target_link_libraries(adios2_basics_values_f + adios2_basics_values_mpivars_f + adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_basics_values_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/basics/values/mpivars.F90 b/examples/basics/values/mpivars.F90 new file mode 100644 index 0000000000..323e4b0c15 --- /dev/null +++ b/examples/basics/values/mpivars.F90 @@ -0,0 +1,30 @@ +module mpivars + implicit none + include 'mpif.h' + + integer:: app_comm, rank, nproc + integer:: wrank, wnproc + integer:: ierr + +contains + +subroutine init_mpi(color) + integer, intent(in):: color + call MPI_Init(ierr) + ! World comm spans all applications started with the same mpirun command + call MPI_Comm_rank(MPI_COMM_WORLD, wrank, ierr) + call MPI_Comm_size(MPI_COMM_WORLD, wnproc, ierr) + + ! Have to split and create a 'world' communicator for this app only + ! color must be unique for each application + call MPI_Comm_split (MPI_COMM_WORLD, color, wrank, app_comm, ierr) + call MPI_Comm_rank (app_comm, rank, ierr) + call MPI_Comm_size (app_comm, nproc , ierr) +end subroutine init_mpi + +subroutine finalize_mpi() + call MPI_Finalize(ierr) +end subroutine finalize_mpi + +end module mpivars + diff --git a/examples/basics/values/values.F90 b/examples/basics/values/values.F90 new file mode 100644 index 0000000000..608ecf37b6 --- /dev/null +++ b/examples/basics/values/values.F90 @@ -0,0 +1,169 @@ +program adios2_values + use mpivars + use adios2 + implicit none + integer, parameter :: numsteps = 5 + ! ADIOS2 variables + type(adios2_adios) :: adios + + ! MPI then ADIOS2 initialization + call init_mpi(12345) + call adios2_init(adios, app_comm, ierr) + + call writer() + call reader() + + ! ADIOS2 then MPI finalization + call adios2_finalize(adios, ierr) + call finalize_mpi() + +contains + +subroutine writer + use mpivars + use adios2 + implicit none + + type(adios2_variable) :: var_gc, var_gv, var_lc, var_lv, var_gs + type(adios2_io) :: io + type(adios2_engine) :: engine + integer :: step + + ! Application variables + ! gc = Global Constant (a single value from the entire application, once per run (e.g. NPROC)) + ! gv = Global Value (a single value from the entire application, changes over time) + ! lc = Local Constant (one value per process, once per run (e.g. RANK)) + ! lv = Local Value (one value per process, changes over time) + ! gs = a string, same as a global value + integer :: gc, gv, lc, lv + character(len=80) :: gs + + call adios2_declare_io (io, adios, 'Values', ierr) + + call adios2_define_variable(var_gc, io, "GlobalConstant", adios2_type_integer4, ierr) + call adios2_define_variable(var_gv, io, "GlobalValue", adios2_type_integer4, ierr) + ! Local values will show up in reading as a 1D array of nproc elements + ! the write side definition is quite cumbersome in Fortran :-( + ! We have to define it almost like a distributed global array with a special + ! dimension value to indicate its type + call adios2_define_variable(var_lc, io, "LocalConstant", adios2_type_integer4, & + 1, (/ adios2_local_value_dim /), & + adios2_null_dims, & + adios2_null_dims, & + adios2_constant_dims, ierr) + + call adios2_define_variable(var_lv, io, "LocalValue", adios2_type_integer4, & + 1, (/ adios2_local_value_dim /), & + adios2_null_dims, & + adios2_null_dims, & + adios2_constant_dims, ierr) + + call adios2_define_variable(var_gs, io, "GlobalString", adios2_type_string, ierr) + + call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_write, ierr) + + ! Computation/output loop + gc = nproc + lc = rank + do step=0,numsteps-1 + gv = step + lv = nproc*(step)+rank + write (gs,'(a,i3)') "This is step ", step + + call adios2_begin_step(engine, adios2_step_mode_append, ierr) + if (step == 0) then + call adios2_put(engine, var_lc, lc, ierr); + if (rank == 0) then + ! could be written from every process but it is useless + call adios2_put(engine, var_gc, gc, ierr); + endif + endif + if (rank == 0) then + ! could be written from every process but it is useless + call adios2_put(engine, var_gv, gv, ierr); + call adios2_put(engine, var_gs, gs, ierr); + endif + call adios2_put(engine, var_lv, lv, ierr); + call adios2_end_step(engine, ierr) + enddo + + ! Close the output + call adios2_close(engine, ierr) + +end subroutine writer + + +subroutine reader + use mpivars + implicit none + + type(adios2_variable) :: var_gc, var_gv, var_lc, var_lv + type(adios2_io) :: io + type(adios2_engine) :: engine + integer*8 :: numsteps, i + integer*4 :: gc + integer*4, dimension(:), allocatable :: gvs, lcs + integer*4, dimension(:,:), allocatable :: lvs + character(len=80)::fmt + integer*8, dimension(:), allocatable :: shape_lv, shape_lc + integer :: ndims_lv, ndims_lc + + ! Note, every process reads everything in this example + + call adios2_declare_io(io, adios, "ValuesInput", ierr) + call adios2_open(engine, io, "adios2-values-f.bp", adios2_mode_read, MPI_COMM_SELF, ierr) + + call adios2_inquire_variable(var_gc, io, "GlobalConstant", ierr) + call adios2_get(engine, var_gc, gc , ierr) + + call adios2_inquire_variable(var_gv, io, "GlobalValue", ierr) + call adios2_variable_steps(numsteps, var_gv, ierr) + call adios2_set_step_selection(var_gv, 0_8, numsteps, ierr) + allocate(gvs(numsteps)) + call adios2_get(engine, var_gv, gvs , ierr) + + ! Read Local Values and Local Constants as a 1D array + ! shape array is allocated inside adios2_variable_shape() + + call adios2_inquire_variable(var_lc, io, "LocalConstant", ierr) + call adios2_variable_shape(shape_lc, ndims_lc, var_lc, ierr) + allocate(lcs(shape_lc(1))) + call adios2_get(engine, var_lc, lcs , ierr) + + call adios2_inquire_variable(var_lv, io, "LocalValue", ierr) + call adios2_variable_shape(shape_lv, ndims_lv, var_lv, ierr) + call adios2_set_step_selection(var_lv, 0_8, numsteps, ierr) + allocate(lvs(shape_lv(1),numsteps)) + call adios2_get(engine, var_lv, lvs , ierr) + + call adios2_close(engine, ierr) + + ! By default, get()s are deferred and content is available AFTER + ! adios2_close() or adios2_perform_gets() + ! Use adios2_mode_sync option in adios2_get() to get the content immediately + + if (rank == 0) then + write(*,'("Number of steps in file = ",i5)') numsteps + write(*,'("GlobalConstant = ", i5)') gc + + write(fmt,'(a,i5,a)') '(a18,',numsteps,'i4,a2)' + !write(*,'(a)') fmt + write(*,fmt) "GlobalValue(s) = [", gvs, " ]" + + write(fmt,'(a,i5,a)') '(a20,',shape_lc(1),'i4,a2)' + !write(*,'(a)') fmt + write(*,fmt) "LocalConstant(s) = [", lcs, " ]" + + write(fmt,'(a,i5,a)') '(a6,i3,a4,',shape_lv(1),'i4)' + !write(*,'(a)') fmt + write(*,'(a)') "LocalValues = [" + do i = 1, numsteps + write(*,fmt) " step", i-1, ":", lvs(:,i) + enddo + write(*,*) " ]" + endif + + deallocate(gvs, lcs, lvs) +end subroutine reader + +end program adios2_values diff --git a/examples/basics/values/values_write.cpp b/examples/basics/values/valuesWrite.cpp similarity index 97% rename from examples/basics/values/values_write.cpp rename to examples/basics/values/valuesWrite.cpp index c792b111a2..4f9f556798 100644 --- a/examples/basics/values/values_write.cpp +++ b/examples/basics/values/valuesWrite.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) // Get io settings from the config file or // create one with default settings here adios2::IO io = adios.DeclareIO("Output"); - io.SetEngine("BP5"); + io.SetEngine("BPFile"); io.SetParameters({{"verbose", "4"}}); /* * Define variables @@ -106,8 +106,7 @@ int main(int argc, char *argv[]) // 1. Writing a global constant value only once if (step == 0) { - adios2::Variable varNproc = - io.InquireVariable("Nproc"); + adios2::Variable varNproc = io.InquireVariable("Nproc"); writer.Put(varNproc, nproc); } writer.Put(varStep, step); diff --git a/examples/basics/variablesShapes/CMakeLists.txt b/examples/basics/variablesShapes/CMakeLists.txt new file mode 100644 index 0000000000..2dbd92f4fd --- /dev/null +++ b/examples/basics/variablesShapes/CMakeLists.txt @@ -0,0 +1,39 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2BasicsVariablesShapesExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_basics_variablesShapes variablesShapes.cpp) +target_link_libraries(adios2_basics_variablesShapes adios2::cxx11) +install(TARGETS adios2_basics_variablesShapes RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_basics_variablesShapes_hl variablesShapes_hl.cpp) +target_link_libraries(adios2_basics_variablesShapes_hl adios2::cxx11) +install(TARGETS adios2_basics_variablesShapes_hl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_basics_variablesShapes_mpi variablesShapes.cpp) + target_link_libraries(adios2_basics_variablesShapes_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_variablesShapes_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_basics_variablesShapes_hl_mpi variablesShapes_hl.cpp) + target_link_libraries(adios2_basics_variablesShapes_hl_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_basics_variablesShapes_hl_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/basics/variablesShapes/variablesShapes.cpp b/examples/basics/variablesShapes/variablesShapes.cpp new file mode 100644 index 0000000000..6dce0f8fae --- /dev/null +++ b/examples/basics/variablesShapes/variablesShapes.cpp @@ -0,0 +1,269 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * * variablesShapes.cpp : adios2 low-level API example to write and read + * supported Variables shapes using stepping + * (streaming) mode + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //std::size_t +#include // std::cout +#include // std::numeric_limits +#include //std::iota +#include //std::exception + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2::ADIOS &adios, const std::size_t nx, const std::size_t nsteps, const int rank, + const int size) +{ + auto lf_compute = [](const std::size_t step, const std::size_t nx, + const int rank) -> std::vector { + const float value = static_cast(step + rank * nx); + std::vector array(nx); + std::iota(array.begin(), array.end(), value); + return array; + }; + + adios2::IO io = adios.DeclareIO("variables-shapes_writer"); + + // You can define variables according to: + // type : string, uint8_t, int8_t8, ... , float, double + // shape: global : value or array + // local : value (return a global array), array + + /********** GLOBAL VALUE *************/ + // string variables are always of value type, can't pass dimensions + adios2::Variable varGlobalValueString = + io.DefineVariable("GlobalValueString"); + + // global value can change on each step. Example: Step + adios2::Variable varStep = io.DefineVariable("Step"); + + /********** GLOBAL ARRAYS *************/ + // For a regular 1D decomposition: + + // 0*nx 1*nx 2*nx 3*nx shape (4*nx) + //--------//-------//--------//---------// + // nx nx nx nx + + // global shape -> this is the physical dimension across MPI processes + const adios2::Dims shape = {static_cast(size * nx)}; + + // local start for rank offset -> this is the local origin for the rank + // domain + const adios2::Dims start = {static_cast(rank * nx)}; + + // local count -> this is the local size from the local start for the rank + // domain + const adios2::Dims count = {nx}; + + // adios2::Dims is an alias to std::vector + // helps remember the inputs to adios2 functions DefineVariable (write) and + // SetSelection (read) make sure you always pass std::size_t types + + // global array with dimensions (shape, start, count) + // last argument indicates to adios2 that dimensions won't change + adios2::Variable varGlobalArray = + io.DefineVariable("GlobalArray", shape, start, count, adios2::ConstantDims); + + /********** LOCAL VALUE **************/ + // Independent values per rank at write, but presented as a global array at + // read Example: store current rank, but presented as an array of ranks + adios2::Variable varLocalValueInt32 = + io.DefineVariable("Rank", {adios2::LocalValueDim}); + + /********** LOCAL ARRAY **************/ + // Independent values and dimensions per rank, there is no notion of + // "continuity", each start from 0-origin to count. Example: mesh + // nodes-per-rank + adios2::Variable varLocalArray = + io.DefineVariable("LocalArray", {}, {}, count, adios2::ConstantDims); + + adios2::Engine writer = io.Open("variables-shapes.bp", adios2::Mode::Write); + + for (size_t step = 0; step < nsteps; ++step) + { + // this part mimics the compute portion in an application + const std::vector array = lf_compute(step, nx, rank); + + // ADIOS2 I/O portion + + // BeginStep/EndStep is the streaming API -> supported by all engines + writer.BeginStep(); + + // minimize global and local values footprint, by only one rank putting + // the variables + if (rank == 0) + { + // Global value changing over steps + writer.Put(varStep, static_cast(step)); + + if (step == 0) + { + // Global absolute value + writer.Put(varGlobalValueString, std::string("ADIOS2 Basics Variable Example")); + // Local absolute value + writer.Put(varLocalValueInt32, static_cast(rank)); + } + } + + // for this example all ranks put a global and a local array + writer.Put(varGlobalArray, array.data()); + writer.Put(varLocalArray, array.data()); + writer.EndStep(); + } + writer.Close(); +} + +void reader(adios2::ADIOS &adios, const int rank, const int size) +{ + adios2::IO io = adios.DeclareIO("variables-shapes_reader"); + // all ranks opening the bp file have access to the entire metadata + adios2::Engine reader = io.Open("variables-shapes.bp", adios2::Mode::Read); + + // reading in streaming mode + while (reader.BeginStep() != adios2::StepStatus::EndOfStream) + { + // scope between BeginStep and EndStep is only for the current step + const size_t currentStep = reader.CurrentStep(); + + // Typical flow: InquireVariable + adios2::Variable varStep = io.InquireVariable("Step"); + uint64_t step = std::numeric_limits::max(); + // check Variable existence + if (varStep) + { + if (rank == 0) + { + // variable objects are "printable" reporting Name and Type + std::cout << "Found Global Value " << varStep << " in step " << currentStep << "\n"; + // output: Found Global Value Variable(Name: "Step") + // in step 0 + } + reader.Get(varStep, step); + } + + // GlobalValueString + adios2::Variable varGlobalValueString = + io.InquireVariable("GlobalValueString"); + std::string globalValueString; + // check Variable existence and Get + if (varGlobalValueString) + { + if (rank == 0) + { + std::cout << "Found Global Value " << varGlobalValueString << " in step " + << currentStep << "\n"; + } + reader.Get(varGlobalValueString, globalValueString); + } + + // Global Arrays at read from local values at write + adios2::Variable varRanks = io.InquireVariable("Ranks"); + std::vector ranks; + if (varRanks) + { + if (rank == 0) + { + std::cout << "Found Global Array " << varRanks << " in step " << currentStep + << "\n"; + } + // passing a vector convenience: adios2 would resize it + // automatically + reader.Get(varRanks, ranks); + } + + // Global Array + adios2::Variable varGlobalArray = io.InquireVariable("GlobalArray"); + std::vector globalArray; + if (varGlobalArray) + { + if (rank == 0) + { + std::cout << "Found GlobalArray " << varGlobalArray << " in step " << currentStep + << "\n"; + } + reader.Get(varGlobalArray, globalArray); + } + + // Local Array + adios2::Variable varLocalArray = io.InquireVariable("LocalArray"); + std::vector localArray; + if (varLocalArray) + { + // local arrays require an extra step to select the block of + // interest (0 is default) we only select block 0 in this example + varLocalArray.SetBlockSelection(0); + if (rank == 0) + { + std::cout << "Found LocalArray " << varLocalArray << " in step " << currentStep + << "\n"; + } + reader.Get(varLocalArray, localArray); + } + + // since all Get calls are "deferred" all the data would be populated at + // EndStep + reader.EndStep(); + + // data is available + + if (rank == 0) + { + std::cout << "\n"; + } + } + + reader.Close(); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + int rank = 0; + int size = 1; + +#if ADIOS2_USE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); +#endif + + try + { +#if ADIOS2_USE_MPI + adios2::ADIOS adios(MPI_COMM_WORLD); +#else + adios2::ADIOS adios; +#endif + + constexpr std::size_t nx = 10; + constexpr std::size_t nsteps = 3; + + writer(adios, nx, nsteps, rank, size); + reader(adios, rank, size); + } + catch (const std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/basics/variablesShapes/variablesShapes_hl.cpp b/examples/basics/variablesShapes/variablesShapes_hl.cpp new file mode 100644 index 0000000000..5977b2c311 --- /dev/null +++ b/examples/basics/variablesShapes/variablesShapes_hl.cpp @@ -0,0 +1,194 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * variablesShapes_hl.cpp : adios2 high-level API example to write and read + * supported Variables shapes using stepping (streaming) mode + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //std::size_t +#include // std::cout +#include // std::numeric_limits +#include //std::iota +#include //std::exception + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(const std::size_t nx, const std::size_t nsteps, const int rank, const int size) +{ + auto lf_compute = [](const std::size_t step, const std::size_t nx, + const int rank) -> std::vector { + const float value = static_cast(step + rank * nx); + std::vector array(nx); + std::iota(array.begin(), array.end(), value); + return array; + }; + + // You can define variables according to: + // type : string, uint8_t, int8_t8, ... , float, double + // shape: global : value or array + // local : value (return a global array), array + + // global shape -> this is the physical dimension across MPI processes + const adios2::Dims shape = {static_cast(size * nx)}; + + // local start for rank offset -> this is the local origin for the rank + // domain + const adios2::Dims start = {static_cast(rank * nx)}; + + // local count -> this is the local size from the local start for the rank + // domain + const adios2::Dims count = {nx}; + + // adios2::Dims is an alias to std::vector + // helps remember the inputs to adios2 functions DefineVariable (write) and + // SetSelection (read) make sure you always pass std::size_t types + +#if ADIOS2_USE_MPI + adios2::fstream out("variables-shapes_hl.bp", adios2::fstream::out, MPI_COMM_WORLD); +#else + adios2::fstream out("variables-shapes_hl.bp", adios2::fstream::out); +#endif + + for (size_t step = 0; step < nsteps; ++step) + { + // this part mimics the compute portion in an application + const std::vector array = lf_compute(step, nx, rank); + + // ADIOS2 I/O portion + + // minimize global and local values footprint, by only one rank writing + // the variables + if (rank == 0) + { + // Global value changing over steps + out.write("Step", static_cast(step)); + + if (step == 0) + { + // Constant Global value + out.write("GlobalValueString", std::string("ADIOS2 Basics Variable Example")); + + // Constant Local value + out.write("LocalValueInt32", static_cast(rank), adios2::LocalValue); + } + } + + // for this example all ranks write a global and a local array + out.write("GlobalArray", array.data(), shape, start, count); + out.write("LocalArray", array.data(), {}, {}, count); + + out.end_step(); + } + out.close(); +} + +void reader(const int rank, const int size) +{ + auto lf_ArrayToString = [](const std::vector &array) -> std::string { + std::string contents = "{ "; + for (const float value : array) + { + contents += std::to_string(static_cast(value)) + " "; + } + contents += "}"; + return contents; + }; + +// all ranks opening the bp file have access to the entire metadata +#if ADIOS2_USE_MPI + adios2::fstream in("variables-shapes_hl.bp", adios2::fstream::in, MPI_COMM_WORLD); +#else + adios2::fstream in("variables-shapes_hl.bp", adios2::fstream::in); +#endif + + // reading in streaming mode, supported by all engines + // similar to std::getline in std::fstream + adios2::fstep inStep; + while (adios2::getstep(in, inStep)) + { + const std::size_t currentStep = inStep.current_step(); + + const std::vector steps = inStep.read("Step"); + if (!steps.empty() && rank == 0) + { + std::cout << "Found Step " << steps.front() << " in currentStep " << currentStep + << "\n"; + } + + const std::vector globalValueString = + inStep.read("GlobalValueString"); + if (!globalValueString.empty() && rank == 0) + { + std::cout << "Found GlobalValueString " << globalValueString.front() + << " in currentStep " << currentStep << "\n"; + } + + const std::vector ranks = inStep.read("Ranks"); + if (!ranks.empty() && rank == 0) + { + std::cout << "Found rank " << ranks.front() << " in currentStep " << currentStep + << "\n"; + } + + const std::vector globalArray = inStep.read("GlobalArray"); + if (!globalArray.empty() && rank == 0) + { + std::cout << "Found globalArray " << lf_ArrayToString(globalArray) + " in currentStep " + << currentStep << "\n"; + } + + // default reads block 0 + const std::vector localArray = inStep.read("LocalArray"); + if (!localArray.empty() && rank == 0) + { + std::cout << "Found localArray " << lf_ArrayToString(localArray) + " in currentStep " + << currentStep << "\n"; + } + // indicate end of adios2 operations for this step + in.end_step(); + } + in.close(); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + int rank = 0; + int size = 1; + +#if ADIOS2_USE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); +#endif + + try + { + constexpr std::size_t nx = 10; + constexpr std::size_t nsteps = 3; + + writer(nx, nsteps, rank, size); + reader(rank, size); + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/cuda/CMakeLists.txt b/examples/cuda/CMakeLists.txt deleted file mode 100644 index 6a613392f4..0000000000 --- a/examples/cuda/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(CudaBPWriteRead_cuda cudaBPWriteRead.cu) -target_link_libraries(CudaBPWriteRead_cuda PUBLIC adios2::cxx11 CUDA::cudart) -set_target_properties(CudaBPWriteRead_cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) diff --git a/examples/experimental/CMakeLists.txt b/examples/experimental/CMakeLists.txt deleted file mode 100644 index 23240d2bae..0000000000 --- a/examples/experimental/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_subdirectory(runtimeconfig) diff --git a/examples/experimental/runtimeconfig/CMakeLists.txt b/examples/experimental/runtimeconfig/CMakeLists.txt deleted file mode 100644 index 33bde8ad15..0000000000 --- a/examples/experimental/runtimeconfig/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(hello) diff --git a/examples/experimental/runtimeconfig/configs/grandSchema.xml b/examples/experimental/runtimeconfig/configs/grandSchema.xml deleted file mode 100644 index 71d80bd30b..0000000000 --- a/examples/experimental/runtimeconfig/configs/grandSchema.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - BlockSize100K=3; - - - Tolerance=1e-3; - - - - - - - Threads=4; - Verbose=4; - ProfileUnits=Microseconds; - MaxBufferSize=20Mb; - InitialBufferSize=1Mb; - BufferGrowthFactor=2; - - - - ProfileUnits=Microseconds; - Library=stdio; - CacheSize=8192; - CollectiveMetadata=Yes; - - - - ProfileUnits=Microseconds; - Library=hdf5; - Name=data.h5; - - - - ProfileUnits=Microseconds; - Library=SystemV; - Name=data.shmem; - SetSize=10Mb; - - - - ProfileUnits=Microseconds; - Library=POSIX; - Name=/bb_location/data.bb; - SetSize=10Mb; - - - - ProfileUnits=Microseconds; - IPAddress=128.219.4.85; - Port=500; - Library=zmq; - CacheSize=8192; - - - - ProfileUnits=Microseconds; - Library=ibverbs; - Port=18515; - IBPort=1; - SetSize=1Mb; - TXDepth=100; - SocketFD=-1; - ServerName=NULL; - RemoteConnection=NULL; - IBDev=NULL; - - - - - \ No newline at end of file diff --git a/examples/experimental/runtimeconfig/configs/multipleIOResolutions.xml b/examples/experimental/runtimeconfig/configs/multipleIOResolutions.xml deleted file mode 100644 index 28fe854084..0000000000 --- a/examples/experimental/runtimeconfig/configs/multipleIOResolutions.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - Tolerance=1e-2; - - - - - - - - - - Tolerance=1e-5; - - - - - - - \ No newline at end of file diff --git a/examples/experimental/runtimeconfig/configs/multipleTransformedVariables.xml b/examples/experimental/runtimeconfig/configs/multipleTransformedVariables.xml deleted file mode 100644 index 8338320d5c..0000000000 --- a/examples/experimental/runtimeconfig/configs/multipleTransformedVariables.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - Tolerance=1e-2; - - - - - - - - - - - Tolerance=1e-5; - - - - - - - - - diff --git a/examples/experimental/runtimeconfig/hello/CMakeLists.txt b/examples/experimental/runtimeconfig/hello/CMakeLists.txt deleted file mode 100644 index dac3c8499f..0000000000 --- a/examples/experimental/runtimeconfig/hello/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_executable(helloBPWriterXML helloBPWriterXML_nompi.cpp) -target_link_libraries(helloBPWriterXML adios2::cxx11) -target_compile_definitions(helloBPWriterXML PRIVATE - -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/helloBPWriter.xml -) - -if(ADIOS2_HAVE_MPI) - add_executable(helloBPWriterXML_mpi helloBPWriterXML.cpp) - target_link_libraries(helloBPWriterXML_mpi adios2::cxx11_mpi MPI::MPI_C) - target_compile_definitions(helloBPWriterXML_mpi PRIVATE - -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/helloBPWriter.xml - ) -endif() diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriter.xml b/examples/experimental/runtimeconfig/hello/helloBPWriter.xml deleted file mode 100644 index 27a01d5db8..0000000000 --- a/examples/experimental/runtimeconfig/hello/helloBPWriter.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp deleted file mode 100644 index 7aafb756f4..0000000000 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * helloBPWriter.cpp: Simple self-descriptive example of how to write a variable - * to a BP File that lives in several MPI processes. - * - * Created on: Feb 16, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include //std::ios_base::failure -#include //std::cout -#include -#include //std::invalid_argument std::exception -#include - -#include - -#define str_helper(X) #X -#define str(X) str_helper(X) - -#ifndef DEFAULT_CONFIG -#define DEFAULT_CONFIG helloBPWriter.xml -#endif -#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG) - -int main(int argc, char *argv[]) -{ - int provided; - - // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP - MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - std::string configFile; - if (argc == 1) - { - configFile = DEFAULT_CONFIG_STR; - } - else if (argc == 2) - { - configFile = argv[1]; - } - else - { - if (rank == 0) - { - std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]" - << std::endl; - } - return 1; - } - if (rank == 0) - { - std::cout << "Using config file: " << configFile << std::endl; - } - - /** Application variable */ - std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myFloats.size(); - - try - { - /** ADIOS class factory of IO class objects */ - adios2::ADIOS adios(configFile, MPI_COMM_WORLD); - - /*** IO class object: settings and factory of Settings: Variables, - * Parameters, Transports, and Execution: Engines */ - adios2::IO bpIO = adios.DeclareIO("BPFile_N2N"); - - /** global array : name, { shape (total) }, { start (local) }, { count - * (local) }, all are constant dimensions */ - adios2::Variable &bpFloats = bpIO.DefineVariable( - "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); - - /** Engine derived class, spawned to start IO operations */ - auto bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); - - if (!bpWriter) - { - throw std::ios_base::failure( - "ERROR: bpWriter not created at Open\n"); - } - - /** Write variable for buffering */ - bpWriter->Write(bpFloats, myFloats.data()); - - /** Create bp file, engine becomes unreachable after this*/ - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; - std::cout << e.what() << "\n"; - } - - MPI_Finalize(); - - return 0; -} diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.py b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.py deleted file mode 100644 index a4c2c4b6b0..0000000000 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.py +++ /dev/null @@ -1,36 +0,0 @@ -# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -# -# helloBPWriterXML.py -# Created on: Feb 2, 2017 -# Author: William F Godoy godoywf@ornl.gov - -from mpi4py import MPI -import adios2 -import numpy - -# MPI -comm = MPI.COMM_WORLD -rank = comm.Get_rank() -size = comm.Get_size() - -# User data -myArray = numpy.array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) -Nx = myArray.size - -# ADIOS config file, MPI communicator -adios = adios2.ADIOS("helloBPWriter.xml", comm) - -# ADIOS IO, name must be the same as in helloBPWriter.xml for runtime settings -bpIO = adios.DeclareIO("BPFile_N2N") - -# Variable name, shape, start, count, ConstantDims = True -ioArray = bpIO.DefineVariable( - "bpArray", [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims) - -# Engine name, open mode -bpFileWriter = bpIO.Open("npArray.bp", adios2.OpenModeWrite) -# Write variable, numpy object -bpFileWriter.Write(ioArray, myArray) -bpFileWriter.Close() diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp deleted file mode 100644 index 60d4934b64..0000000000 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * helloBPWriterXML_nompi.cpp: sequential non-mpi version of helloBPWriterXML - * - * Created on: Feb 16, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include //std::ios_base::failure -#include //std::cout -#include //std::invalid_argument std::exception -#include - -#include - -#define str_helper(X) #X -#define str(X) str_helper(X) - -#ifndef DEFAULT_CONFIG -#define DEFAULT_CONFIG helloBPWriter.xml -#endif -#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG) - -int main(int argc, char *argv[]) -{ - std::string configFile; - if (argc == 1) - { - configFile = DEFAULT_CONFIG_STR; - } - else if (argc == 2) - { - configFile = argv[1]; - } - else - { - std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]" - << std::endl; - return 1; - } - std::cout << "Using config file: " << configFile << std::endl; - - /** Application variable */ - std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const std::size_t Nx = myFloats.size(); - - try - { - /** ADIOS class factory of IO class objects */ - adios2::ADIOS adios(configFile); - - /*** IO class object: settings and factory of Settings: Variables, - * Parameters, Transports, and Execution: Engines */ - adios2::IO bpIO = adios.DeclareIO("BPFile_N2N"); - - /** global array : name, { shape (total) }, { start (local) }, { count - * (local) }, all are constant dimensions */ - adios2::Variable &bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); - - /** Engine derived class, spawned to start IO operations */ - auto bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); - - if (!bpWriter) - { - throw std::ios_base::failure( - "ERROR: bpWriter not created at Open\n"); - } - - /** Write variable for buffering */ - bpWriter->Write(bpFloats, myFloats.data()); - - /** Create bp file, engine becomes unreachable after this*/ - bpWriter->Close(); - } - catch (std::invalid_argument &e) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::ios_base::failure &e) - { - std::cout << "IO System base failure exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM from rank\n"; - std::cout << e.what() << "\n"; - } - - return 0; -} diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.py b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.py deleted file mode 100644 index 2ef26916ea..0000000000 --- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.py +++ /dev/null @@ -1,30 +0,0 @@ -# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -# -# helloBPWriterXML_nompi.py serial non-MPI version of helloBPWriter.py -# Created on: Feb 2, 2017 -# Author: William F Godoy godoywf@ornl.gov - -import numpy -import adios2 - - -# User data -myArray = numpy.array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) -Nx = myArray.size - -# ADIOS config file -adios = adios2.ADIOS("helloBPWriter.xml") - -# ADIOS IO, name must be the same as in helloBPWriter.xml for runtime settings -bpIO = adios.DeclareIO("BPFile_N2N") - -# ADIOS local array: Variable name, shape, start, offset -ioArray = bpIO.DefineVariable( - "bpArray", [], [], [Nx], adios2.ConstantDims) - -# ADIOS Engine -bpFileWriter = bpIO.Open("npArray.bp", adios2.OpenModeWrite) -bpFileWriter.Write(ioArray, myArray) -bpFileWriter.Close() diff --git a/examples/fides/01_onecell/CMakeLists.txt b/examples/fides/01_onecell/CMakeLists.txt deleted file mode 100644 index e553b37ccc..0000000000 --- a/examples/fides/01_onecell/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(fides_onecell fides_onecell.cpp) -target_link_libraries(fides_onecell adios2::cxx11) diff --git a/examples/fides/01_onecell/README.md b/examples/fides/01_onecell/README.md deleted file mode 100644 index d55174b571..0000000000 --- a/examples/fides/01_onecell/README.md +++ /dev/null @@ -1,28 +0,0 @@ -Single cell example for visualization with Fides schema in ParaView -------------------------------------------------------------------- - -This example writes 8 points in 3D space, the corners of a box, and then defines a single hexagon cell of those eight points. -The coordinates of the points are stored in three 1D arrays, separating the X-Y-Z coordinates. - -The cell is the enumeration of the points connected in the order of a hexagon prescribed by VTK, see -Figure 19-20 in the VTK User Guide, type VTK_HEXAHEDRON in page 480 (page 494 in the PDF). -https://vtk.org/wp-content/uploads/2021/08/VTKUsersGuide.pdf - -The visualization schema is described in the fides-onecell.json file, according to https://fides.readthedocs.io/en/latest/schema/schema.html - -We compose the coordinate system as a composite of the three 1D arrays for X, Y and Z coordinates. This is just an enumeration of the N points in space (N = size of X = size of Y = size of Z) , in contrast to other examples where X, Y, Z is combined to specify a structured grid (number of points = size of X * size of Y * size of Z). - -In ParaView, one opens the fides-onecell.json file and adds an property "source" with the value of the full path of the onecell.bp. See left-middle Properties box in the ParaView window in the image paraview-onecell-step0.png. Then hit Apply button and a gray box should appear (the single cell visualized). which can be rotated on screen. Then one must color the box with the data ("pointdata") to get the pictures shown in the included images. - -Note that the dataset over the points is called "DataOnPoints" in the onecell.bp file, but it is called "pointdata" in the Fides schema to demonstrate which name is which (ParaView presents pointdata to the user while reading the DataOnPoints array from the file). - -First step of onecell.bp in ParaView: - -paraview-onecell-step0.png - -Last step of onecell.bp in ParaView: - -paraview-onecell-step9.png - diff --git a/examples/fides/CMakeLists.txt b/examples/fides/CMakeLists.txt deleted file mode 100644 index 98d3e0e647..0000000000 --- a/examples/fides/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_subdirectory(01_onecell) diff --git a/examples/h5subfile/CMakeLists.txt b/examples/h5subfile/CMakeLists.txt deleted file mode 100644 index 0d94ae241b..0000000000 --- a/examples/h5subfile/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -if(ADIOS2_HAVE_MPI) - add_executable(H5EngineSubfileTest h5_subfile.cpp) - target_link_libraries(H5EngineSubfileTest adios2::cxx11_mpi MPI::MPI_C) -endif() - diff --git a/examples/heatTransfer/ReadMe.md b/examples/heatTransfer/ReadMe.md deleted file mode 100644 index 9ad00c1681..0000000000 --- a/examples/heatTransfer/ReadMe.md +++ /dev/null @@ -1,73 +0,0 @@ -examples/heatTransfer - -This example solves a 2D Poisson equation for temperature in homogeneous media -using finite differences. This examples shows a straight-forward way to hook -an application to the ADIOS2 library for its IO. - - -1. write: illustrates the Write API as well as has implementations of other IO libraries - - * adios 1.x - * hdf5 sequential, separate file per process per step - * phdf5 parallel, steps appended to the same one file - -2. read: illustrates the Read API that allows running the reader either as - - * post-mortem to read all output steps - * in situ to read step by step as the writer outputs them - (need to run with a suitable engine) - -3. read_fileonly: illustrates reading all output steps at once (a single read - statement) into a single contiguous memory block. This approach only works - for post-mortem processing. - - - -Example - - -1. Produce an output - -Writer usage: heatTransfer config output N M nx ny steps iterations - config: XML config file to use - output: name of output data file/stream - N: number of processes in X dimension - M: number of processes in Y dimension - nx: local array size in X dimension per processor - ny: local array size in Y dimension per processor - steps: the total number of steps to output - iterations: one step consist of this many iterations - -The ADIOS2 executable needs an XML config file to select the Engine used for the output. The engines are: File, BP4 and HDF5, the corresponding XML config files are in the examples/heatTransfer/ directory. The "File" engine will be BP4 or HDF5 depending on the extension of the file name. - -The adios1, ph5 and hdf5 versions of the example do not use XML config files, so just type "none" for the config argument. - -$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat_file.xml heat.bp 4 3 5 10 10 10 -$ mpirun -np 12 ./bin/heatTransfer_write_adios2 ../examples/heatTransfer/heat_file.xml heat.h5 4 3 5 10 10 10 - - -2. Read the output step-by-step and print data into text files (data. per reader process) - -Reader Usage: heatRead config input N M - config: XML config file to use - input: name of input data file/stream - N: number of processes in X dimension - M: number of processes in Y dimension - - -$ mpirun -np 2 ./bin/heatTransfer_read ../examples/heatTransfer/heat_file.xml heat 2 1 - - -Notes: -1. Engines for file-based output and post-mortem reading: i - - * BPFileWriter/BPFileReader - * HDF5Writer/HDF5Reader - -2. Engines for in situ execution - - * DataManWriter/DataManReader - (Must run writer and reader with the same number of processes and same decomposition) - - - diff --git a/examples/heatTransfer/inline/CMakeLists.txt b/examples/heatTransfer/inline/CMakeLists.txt deleted file mode 100644 index 54fd8de038..0000000000 --- a/examples/heatTransfer/inline/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_inline_adios2 - main.cpp - InlineIO.cpp - ../write/HeatTransfer.cpp - ../write/Settings.cpp -) -target_link_libraries(heatTransfer_inline_adios2 - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt deleted file mode 100644 index dd1adbe0cb..0000000000 --- a/examples/heatTransfer/read/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_read - heatRead.cpp - PrintDataStep.h - ReadSettings.cpp -) -target_link_libraries(heatTransfer_read adios2::cxx11_mpi MPI::MPI_C) diff --git a/examples/heatTransfer/read_fileonly/CMakeLists.txt b/examples/heatTransfer/read_fileonly/CMakeLists.txt deleted file mode 100644 index d0ab4b830b..0000000000 --- a/examples/heatTransfer/read_fileonly/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_read_fileonly_adios2 heatRead_adios2.cpp PrintData.h) -target_link_libraries(heatTransfer_read_fileonly_adios2 adios2::cxx11_mpi MPI::MPI_C) - -#if(ADIOS2_HAVE_HDF5) - #add_executable(heatTransfer_read_fileonly_h5_mpi heatRead_h5.cpp PrintData.h) - #target_link_libraries(heatTransfer_read_fileonly_h5_mpi adios2::cxx11_mpi MPI::MPI_C) -#endif() diff --git a/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp b/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp deleted file mode 100644 index 2da8ca6f19..0000000000 --- a/examples/heatTransfer/read_fileonly/heatRead_adios1.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "PrintData.h" - -int main(int argc, char *argv[]) -{ - MPI_Init(&argc, &argv); - - if (argc < 2) - { - std::cout << "Not enough arguments: need an input file\n"; - return 1; - } - const char *inputfile = argv[1]; - - /* World comm spans all applications started with the same aprun command - on a Cray XK6. So we have to split and create the local - 'world' communicator for the reader only. - In normal start-up, the communicator will just equal the MPI_COMM_WORLD. - */ - - int wrank, wnproc; - MPI_Comm_rank(MPI_COMM_WORLD, &wrank); - MPI_Comm_size(MPI_COMM_WORLD, &wnproc); - - const unsigned int color = 2; - MPI_Comm mpiReaderComm; - MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &mpiReaderComm); - - int rank, nproc; - MPI_Comm_rank(mpiReaderComm, &rank); - MPI_Comm_size(mpiReaderComm, &nproc); - - adios_read_init_method(ADIOS_READ_METHOD_BP, mpiReaderComm, "verbose=3"); - - ADIOS_FILE *f; - f = adios_read_open_file(inputfile, ADIOS_READ_METHOD_BP, mpiReaderComm); - if (f == NULL) - { - std::cout << adios_errmsg() << std::endl; - return -1; - } - - ADIOS_VARINFO *vgndx = adios_inq_var(f, "gndx"); - ADIOS_VARINFO *vgndy = adios_inq_var(f, "gndy"); - - unsigned int gndx = *(unsigned int *)vgndx->value; - unsigned int gndy = *(unsigned int *)vgndy->value; - - if (rank == 0) - { - std::cout << "gndx = " << gndx << std::endl; - std::cout << "gndy = " << gndy << std::endl; - } - adios_free_varinfo(vgndx); - adios_free_varinfo(vgndy); - - // 1D decomposition of the columns, which is inefficient for reading! - uint64_t readsize[2] = {gndx, gndy / nproc}; - uint64_t offset[2] = {0LL, rank * readsize[1]}; - if (rank == nproc - 1) - { - // last process should read all the rest of columns - readsize[1] = gndy - readsize[1] * (nproc - 1); - } - - std::cout << "rank " << rank << " reads " << readsize[1] - << " columns from offset " << offset[1] << std::endl; - - ADIOS_VARINFO *vT = adios_inq_var(f, "T"); - - double *T = new double[vT->nsteps * readsize[0] * readsize[1]]; - - // Create a 2D selection for the subset - ADIOS_SELECTION *sel = adios_selection_boundingbox(2, offset, readsize); - - // Arrays are read by scheduling one or more of them - // and performing the reads at once - adios_schedule_read(f, sel, "T", 0, vT->nsteps, T); - adios_perform_reads(f, 1); - - printData(T, readsize, offset, rank, vT->nsteps); - adios_read_close(f); - adios_free_varinfo(vT); - delete[] T; - // Terminate - adios_selection_delete(sel); - adios_read_finalize_method(ADIOS_READ_METHOD_BP); - MPI_Finalize(); - return 0; -} diff --git a/examples/heatTransfer/write/CMakeLists.txt b/examples/heatTransfer/write/CMakeLists.txt deleted file mode 100644 index 268b05fe28..0000000000 --- a/examples/heatTransfer/write/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(heatTransfer_write_adios2 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_adios2.cpp -) -target_link_libraries(heatTransfer_write_adios2 - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) - -add_executable(heatTransfer_write_ascii - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_ascii.cpp -) -target_link_libraries(heatTransfer_write_ascii - MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} -) - -if(ADIOS2_HAVE_HDF5) - add_executable(heatTransfer_write_hdf5 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_hdf5_a.cpp - ) - target_include_directories(heatTransfer_write_hdf5 - PRIVATE ${HDF5_C_INCLUDE_DIRS} - ) - target_link_libraries(heatTransfer_write_hdf5 - ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - - if(HDF5_IS_PARALLEL) - add_executable(heatTransfer_write_ph5 - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_ph5.cpp - ) - target_include_directories(heatTransfer_write_ph5 - PRIVATE ${HDF5_C_INCLUDE_DIRS} - ) - target_link_libraries(heatTransfer_write_ph5 - ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - endif() - - if(NOT (HDF5_VERSION VERSION_LESS 1.11)) - add_executable(heatTransfer_write_h5mixer - main.cpp - HeatTransfer.cpp - Settings.cpp - IO_h5mixer.cpp - ) - target_link_libraries(heatTransfer_write_h5mixer - adios2::cxx11_mpi MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT} - ) - endif() -endif() diff --git a/examples/hello/CMakeLists.txt b/examples/hello/CMakeLists.txt index 1de325635a..297ed51882 100644 --- a/examples/hello/CMakeLists.txt +++ b/examples/hello/CMakeLists.txt @@ -3,13 +3,30 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_subdirectory(bpWriter) +add_subdirectory(bpAttributeWriter) +add_subdirectory(bpFlushWriter) + +if(ADIOS2_HAVE_MPI) + add_subdirectory(bpFWriteCRead) +endif() + add_subdirectory(bpReader) +add_subdirectory(bpThreadWrite) add_subdirectory(bpTimeWriter) -add_subdirectory(bpFlushWriter) -add_subdirectory(bpAttributeWriter) -add_subdirectory(inlineReaderWriter) -add_subdirectory(skeleton) +add_subdirectory(bpWriter) + +if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) + add_subdirectory(bpWriteReadCuda) +endif() + +find_package(hip QUIET) +if(ADIOS2_HAVE_Kokkos_HIP OR hip_FOUND) + add_subdirectory(bpWriteReadHip) +endif() + +if(ADIOS2_HAVE_Kokkos) + add_subdirectory(bpWriteReadKokkos) +endif() if(ADIOS2_HAVE_DataMan) add_subdirectory(datamanReader) @@ -21,20 +38,25 @@ if(ADIOS2_HAVE_DataSpaces) add_subdirectory(dataspacesWriter) endif() -if(ADIOS2_HAVE_SST) - add_subdirectory(sstReader) - add_subdirectory(sstWriter) -endif() - if(ADIOS2_HAVE_HDF5) add_subdirectory(hdf5Writer) add_subdirectory(hdf5Reader) + if(HDF5_VERSION VERSION_GREATER_EQUAL 1.14) + add_subdirectory(hdf5SubFile) + endif() endif() -if(ADIOS2_HAVE_MPI) - add_subdirectory(bpFWriteCRead) -endif() +add_subdirectory(helloWorld) if(ADIOS2_HAVE_Fortran) - add_subdirectory(inlineFWriteCppRead) + add_subdirectory(inlineFWriteCppRead) +endif() + +add_subdirectory(inlineMWE) +add_subdirectory(inlineReaderWriter) +add_subdirectory(skeleton) + +if(ADIOS2_HAVE_SST) + add_subdirectory(sstReader) + add_subdirectory(sstWriter) endif() diff --git a/examples/hello/README.md b/examples/hello/README.md deleted file mode 100644 index 01b109ccc7..0000000000 --- a/examples/hello/README.md +++ /dev/null @@ -1,18 +0,0 @@ -examples/hello - -Provides tests and illustrates how to use very basic functionality in adios2 - -1. bpWriter - * Write BP format files for one Variable - -1. bpTimeWriter - * Write BP format files for two Variables (one is timestep) using time aggregation - -1. datamanReader (to be deprecated, ADIOS_USE_DataMan=ON) - * Read real-time WAN streams using dataman - -1. datamanWriter - * Write real-time WAN streams using dataman - -1. hdf5Writer (-DADIOS_USE_HDF5=ON) - * Write HDF5 files using interoperability through the adios2 interface diff --git a/examples/hello/ReadMe.md b/examples/hello/ReadMe.md new file mode 100644 index 0000000000..90341a3957 --- /dev/null +++ b/examples/hello/ReadMe.md @@ -0,0 +1,69 @@ +## ADIOS2 hello examples + +The _hello_ examples are meant to introduce you to ADIOS2's IO capabilities and engines. + +They can be found in the following subdirectories, and they should be explored in the order that they are listed: + +1. [helloWorld](helloWorld): The _helloWorld_ example demonstrates how to write a simple word and read it back using + ADIOS2's BP engine. + * Languages: C++, C++ using high-level API, C, Python, Python using high-level API +2. [bpWriter](bpWriter): The _bpWriter_ examples demonstrate how to write a variable to using ADIOS2's BP engine. + * Languages: C++, C, Fortran, Python +3. [bpReader](bpReader): The _bpReader_ examples demonstrate how to read a 1D/2D/3D variable using ADIOS2's BP engine. + * Languages: C++, Fortran, Python +4. [bpFWriteCRead](bpFWriteCRead): The _bpFWriteCRead_ example demonstrates how to write a 2D variable with Fortran and + read a subset of it with C++, and vice versa using ADIOS2's BP engine. + * Languages: C++, Fortran +5. [bpTimeWriter](bpTimeWriter): The _bpTimeWriter_ example demonstrates how to write two Variables (one is timestep) + using time aggregation using ADIOS2's BP engine. + * Languages: C++, Python +6. [bpAttributeWriter](bpAttributeWriter): The _bpAttributeWriter_ example demonstrates how to write attributes using + ADIOS2's BP engine. + * Languages: C++ +7. [bpFlushWriter](bpFlushWriter): The _bpFlushWriter_ example demonstrates how to flush a variable using ADIOS2's BP + engine. + * Languages: C++ +8. [bpWriteReadCuda](bpWriteReadCuda): The _bpWriteReadCuda_ example demonstrates how to write and read a variable with + multiple time steps using ADIOS2's BP engine and leveraging CUDA. + * Languages: C++ +9. [bpWriteReadHip](bpWriteReadHip): The _bpWriteReadHip_ example demonstrates how to write and read a variable with + multiple time steps using ADIOS2's BP engine and leveraging HIP. + * Languages: C++ +10. [bpWriteReadKokkos](bpWriteReadKokkos): The _bpWriteReadOmp_ example demonstrates how to write and read a variable + with multiple time steps using ADIOS2's BP engine and leveraging Kokkos. + * Languages: C++ +11. [datamanReader](datamanReader): The _datamanReader_ example demonstrates how to read variables in real-time WAN + streams using ADIOS's DataMan engine. + * Languages: C++, Python +12. [datamanWriter](datamanWriter): The _datamanWriter_ example demonstrates how to write variables in real-time WAN + streams using ADIOS's DataMan engine. + * Languages: C++, Python +13. [dataspacesReader](dataspacesReader): The _dataspacesReader_ example demonstrates how to read a variable using + ADIOS2's DATASPACES engine. + * Languages: C++ +14. [dataspacesWriter](dataspacesWriter): The _dataspacesWriter_ example demonstrates how to write a variable using + ADIOS2's DATASPACES engine. + * Languages: C++ +15. [hdf5Reader](hdf5Reader): The _hdf5Reader_ example demonstrates how to read variables using ADIOS2's HDF5 engine. + * Languages: C++ +16. [hdf5Writer](hdf5Writer): The _hdf5Writer_ example demonstrates how to write variables using ADIOS2's HDF5 engine. + * Languages: C++ +17. [hdf5SubFile](hdf5SubFile): The _hdf5SubFile_ example demonstrates how to write variables using ADIOS2's parallel + HDF5 engine leveraging the subfile feature. + * Languages: C++ +18. [inlineMWE](inlineMWE): The _inlineMWE_ example demonstrates how to write and read a variable using ADIOS2's inline + engine. + * Languages: C++ +19. [inlineFWriteCppRead](inlineFWriteCppRead): The _inlineFWriteCppRead_ example demonstrates how to write a 2D + variable with Fortran and read it back a subset of it with C++ using ADIOS2's inline engine. + * Languages: C++, Fortran +20. [inlineReaderWriter](inlineReaderWriter): The _inlineReaderWriter_ example demonstrates how to write two Variables + (one is timestep) using time aggregation and ADIOS2's inline engine. + * Languages: C++ +21. [sstReader](sstReader): The _sstReader_ example demonstrates how to read a variable using ADIOS2's SST engine. + * Languages: C++ +22. [sstWriter](sstWriter): The _sstWriter_ example demonstrates how to write a variable using ADIOS2's SST engine. + * Languages: C++ +23. [skeleton](skeleton): The _skeleton_ example demonstrates how to write and read a variable using an ADIOS2 skeleton + engine. + * Languages: C++ diff --git a/examples/hello/bpAttributeWriter/CMakeLists.txt b/examples/hello/bpAttributeWriter/CMakeLists.txt index 6222de2122..c5eaf598e3 100644 --- a/examples/hello/bpAttributeWriter/CMakeLists.txt +++ b/examples/hello/bpAttributeWriter/CMakeLists.txt @@ -3,12 +3,30 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpAttributeWriter helloBPAttributeWriter_nompi.cpp) -target_link_libraries(hello_bpAttributeWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPAttributeWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpAttributeWriter bpAttributeWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpAttributeWriter adios2::cxx11) +install(TARGETS adios2_hello_bpAttributeWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - find_package(MPI COMPONENTS C REQUIRED) - add_executable(hello_bpAttributeWriter_mpi helloBPAttributeWriter.cpp) - target_link_libraries(hello_bpAttributeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpAttributeWriter_mpi bpAttributeWriter.cpp) + target_link_libraries(adios2_hello_bpAttributeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpAttributeWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp b/examples/hello/bpAttributeWriter/bpAttributeWriter.cpp similarity index 77% rename from examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp rename to examples/hello/bpAttributeWriter/bpAttributeWriter.cpp index 5bcd521adf..1ef46f2e87 100644 --- a/examples/hello/bpAttributeWriter/helloBPAttributeWriter.cpp +++ b/examples/hello/bpAttributeWriter/bpAttributeWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.cpp: Simple self-descriptive example of how to write a variable + * bpAttributeWriter.cpp: Simple self-descriptive example of how to write a variable * to a BP File that lives in several MPI processes. * * Created on: Feb 16, 2017 @@ -46,33 +46,33 @@ int main(int argc, char *argv[]) adios2::Variable bpFloats = bpIO.DefineVariable( "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); - bpIO.DefineAttribute("Single_String", - "File generated with ADIOS2"); + bpIO.DefineAttribute("Single_String", "File generated with ADIOS2"); std::vector myStrings = {"one", "two", "three"}; - bpIO.DefineAttribute("Array_of_Strings", myStrings.data(), - myStrings.size()); + bpIO.DefineAttribute("Array_of_Strings", myStrings.data(), myStrings.size()); bpIO.DefineAttribute("Attr_Double", 0.f); std::vector myDoubles = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - bpIO.DefineAttribute("Array_of_Doubles", myDoubles.data(), - myDoubles.size()); + bpIO.DefineAttribute("Array_of_Doubles", myDoubles.data(), myDoubles.size()); /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpWriter = - bpIO.Open("fileAttributes.bp", adios2::Mode::Write); + adios2::Engine bpWriter = bpIO.Open("fileAttributes.bp", adios2::Mode::Write); + + bpWriter.BeginStep(); /** Write variable for buffering */ bpWriter.Put(bpFloats, myFloats.data()); + bpWriter.EndStep(); + /** Create bp file, engine becomes unreachable after this*/ bpWriter.Close(); adios2::IO bpReader = adios.DeclareIO("BPReader"); - adios2::Engine bpReaderEngine = - bpReader.Open("fileAttributes.bp", adios2::Mode::Read); + adios2::Engine bpReaderEngine = bpReader.Open("fileAttributes.bp", adios2::Mode::Read); + bpReaderEngine.BeginStep(); const auto attributesInfo = bpReader.AvailableAttributes(); for (const auto &attributeInfoPair : attributesInfo) @@ -80,25 +80,24 @@ int main(int argc, char *argv[]) std::cout << "Attribute: " << attributeInfoPair.first; for (const auto &attributePair : attributeInfoPair.second) { - std::cout << "\tKey: " << attributePair.first - << "\tValue: " << attributePair.second << "\n"; + std::cout << "\tKey: " << attributePair.first << "\tValue: " << attributePair.second + << "\n"; } std::cout << "\n"; } + bpReaderEngine.EndStep(); bpReaderEngine.Close(); } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp b/examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp similarity index 82% rename from examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp rename to examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp index 2daaaf1490..bb8aeab6fd 100644 --- a/examples/hello/bpAttributeWriter/helloBPAttributeWriter_nompi.cpp +++ b/examples/hello/bpAttributeWriter/bpAttributeWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter_nompi.cpp sequential non-mpi version of helloBPWriter + * bpAttributeWriter_nompi.cpp sequential non-mpi version of bpAttributeWriter * * Created on: Jan 9, 2017 * Author: William F Godoy godoywf@ornl.gov @@ -33,27 +33,28 @@ int main(int argc, char *argv[]) /** global array: name, { shape (total dimensions) }, { start (local) }, * { count (local) }, all are constant dimensions */ - adios2::Variable bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable bpFloats = + bpIO.DefineVariable("bpFloats", {}, {}, {Nx}, adios2::ConstantDims); - bpIO.DefineAttribute("Single_String", - "File generated with ADIOS2"); + bpIO.DefineAttribute("Single_String", "File generated with ADIOS2"); std::vector myStrings = {"one", "two", "three"}; - bpIO.DefineAttribute("Array_of_Strings", myStrings.data(), - myStrings.size()); + bpIO.DefineAttribute("Array_of_Strings", myStrings.data(), myStrings.size()); bpIO.DefineAttribute("Attr_Double", 0.f); std::vector myDoubles = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - bpIO.DefineAttribute("Array_of_Doubles", myDoubles.data(), - myDoubles.size()); + bpIO.DefineAttribute("Array_of_Doubles", myDoubles.data(), myDoubles.size()); /** Engine derived class, spawned to start IO operations */ adios2::Engine bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); + bpWriter.BeginStep(); + /** Write variable for buffering */ bpWriter.Put(bpFloats, myFloats.data()); + bpWriter.EndStep(); + /** Create bp file, engine becomes unreachable after this*/ bpWriter.Close(); } diff --git a/examples/hello/bpFWriteCRead/CMakeLists.txt b/examples/hello/bpFWriteCRead/CMakeLists.txt index ff5dcc1b2b..759d6919c6 100644 --- a/examples/hello/bpFWriteCRead/CMakeLists.txt +++ b/examples/hello/bpFWriteCRead/CMakeLists.txt @@ -3,18 +3,49 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(CppWriter CppWriter.cpp) -target_link_libraries(CppWriter adios2::cxx11_mpi MPI::MPI_C) - -add_executable(CppReader CppReader.cpp) -target_link_libraries(CppReader adios2::cxx11_mpi MPI::MPI_C) - -if(ADIOS2_HAVE_Fortran) - add_executable(FWriter FWriter.f90) - add_executable(FReader FReader.f90) - target_link_libraries(FWriter adios2::fortran_mpi MPI::MPI_Fortran) - target_link_libraries(FReader adios2::fortran_mpi MPI::MPI_Fortran) - set_target_properties(FWriter FReader PROPERTIES - LINKER_LANGUAGE Fortran - ) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPFWriteCReadExample) + +if(NOT TARGET adios2_core) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if (ADIOS2_HAVE_MPI) + add_executable(adios2_hello_CppWriter CppWriter.cpp) + target_link_libraries(adios2_hello_CppWriter adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_CppWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_CppReader CppReader.cpp) + target_link_libraries(adios2_hello_CppReader adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_CppReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_Fortran) + add_executable(adios2_hello_FWriter FWriter.f90) + target_link_libraries(adios2_hello_FWriter adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_FWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_FReader FReader.f90) + target_link_libraries(adios2_hello_FReader adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_FReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/bpFWriteCRead/CppReader.cpp b/examples/hello/bpFWriteCRead/CppReader.cpp index b9ae5b64ef..0c4af26d6c 100644 --- a/examples/hello/bpFWriteCRead/CppReader.cpp +++ b/examples/hello/bpFWriteCRead/CppReader.cpp @@ -35,8 +35,9 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine bpReader = bpIO.Open("FWriter.bp", adios2::Mode::Read); - const std::map variables = - bpIO.AvailableVariables(); + bpReader.BeginStep(); + + const std::map variables = bpIO.AvailableVariables(); for (const auto &variablePair : variables) { @@ -44,8 +45,7 @@ int main(int argc, char *argv[]) for (const auto ¶meter : variablePair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; } } @@ -54,6 +54,9 @@ int main(int argc, char *argv[]) std::vector data(bpData.SelectionSize()); bpReader.Get(bpData, data.data()); + + bpReader.EndStep(); + bpReader.Close(); std::cout << "Selection size: " << bpData.SelectionSize() << "\n"; diff --git a/examples/hello/bpFWriteCRead/CppWriter.cpp b/examples/hello/bpFWriteCRead/CppWriter.cpp index 6b14659f77..82c82532aa 100644 --- a/examples/hello/bpFWriteCRead/CppWriter.cpp +++ b/examples/hello/bpFWriteCRead/CppWriter.cpp @@ -38,12 +38,13 @@ int main(int argc, char *argv[]) adios2::ADIOS adios(MPI_COMM_WORLD); adios2::IO io = adios.DeclareIO("CppWriter"); - adios2::Variable bpFloats = - io.DefineVariable("data2D", {size * nx, ny}, {rank * nx, 0}, - {nx, ny}, adios2::ConstantDims); + adios2::Variable bpFloats = io.DefineVariable( + "data2D", {size * nx, ny}, {rank * nx, 0}, {nx, ny}, adios2::ConstantDims); adios2::Engine engine = io.Open("CppWriter.bp", adios2::Mode::Write); + engine.BeginStep(); engine.Put(bpFloats, data.data()); + engine.EndStep(); engine.Close(); MPI_Finalize(); diff --git a/examples/hello/bpFlushWriter/CMakeLists.txt b/examples/hello/bpFlushWriter/CMakeLists.txt index 351282fa3c..61c78ebc7b 100644 --- a/examples/hello/bpFlushWriter/CMakeLists.txt +++ b/examples/hello/bpFlushWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpFlushWriter helloBPFlushWriter_nompi.cpp) -target_link_libraries(hello_bpFlushWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPFlushWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpFlushWriter bpFlushWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpFlushWriter adios2::cxx11) +install(TARGETS adios2_hello_bpFlushWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_bpFlushWriter_mpi helloBPFlushWriter.cpp) - target_link_libraries(hello_bpFlushWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpFlushWriter_mpi bpFlushWriter.cpp) + target_link_libraries(adios2_hello_bpFlushWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpFlushWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpFlushWriter/helloBPFlushWriter.cpp b/examples/hello/bpFlushWriter/bpFlushWriter.cpp similarity index 88% rename from examples/hello/bpFlushWriter/helloBPFlushWriter.cpp rename to examples/hello/bpFlushWriter/bpFlushWriter.cpp index 8e662668a8..9299c190e4 100644 --- a/examples/hello/bpFlushWriter/helloBPFlushWriter.cpp +++ b/examples/hello/bpFlushWriter/bpFlushWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPFlushWriter.cpp: Example that tests buffer overflow forcing a flush to + * bpFlushWriter.cpp: Example that tests buffer overflow forcing a flush to * transports when writing a large variable in independent N-to-N mode. This * will have performance penalties, but it's safer. * @@ -53,9 +53,9 @@ int main(int argc, char *argv[]) "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpWriter = - bpIO.Open("myVectorFlush.bp", adios2::Mode::Write); + adios2::Engine bpWriter = bpIO.Open("myVectorFlush.bp", adios2::Mode::Write); + bpWriter.BeginStep(); for (unsigned int t = 0; t < 100; ++t) { /** values to time step */ @@ -63,21 +63,20 @@ int main(int argc, char *argv[]) /** Write variable for buffering */ bpWriter.Put(bpFloats, myFloats.data()); } + bpWriter.EndStep(); /** Create bp file, engine becomes unreachable after this*/ bpWriter.Close(); } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp b/examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp similarity index 87% rename from examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp rename to examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp index 83812f1f91..54565f41bf 100644 --- a/examples/hello/bpFlushWriter/helloBPFlushWriter_nompi.cpp +++ b/examples/hello/bpFlushWriter/bpFlushWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter_nompi.cpp sequential non-mpi version of helloBPWriter + * bpFlushWriter_nompi.cpp sequential non-mpi version of bpFlushWriter * * Created on: Jan 9, 2017 * Author: William F Godoy godoywf@ornl.gov @@ -32,15 +32,19 @@ int main(int argc, char *argv[]) /** global array: name, { shape (total dimensions) }, { start (local) }, * { count (local) }, all are constant dimensions */ - adios2::Variable bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable bpFloats = + bpIO.DefineVariable("bpFloats", {}, {}, {Nx}, adios2::ConstantDims); /** Engine derived class, spawned to start IO operations */ adios2::Engine bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); + bpWriter.BeginStep(); + /** Write variable for buffering */ bpWriter.Put(bpFloats, myFloats.data()); + bpWriter.EndStep(); + /** Create bp file, engine becomes unreachable after this*/ bpWriter.Close(); } diff --git a/examples/hello/bpReader/CMakeLists.txt b/examples/hello/bpReader/CMakeLists.txt index 462227301f..95be573537 100644 --- a/examples/hello/bpReader/CMakeLists.txt +++ b/examples/hello/bpReader/CMakeLists.txt @@ -3,28 +3,59 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpReader helloBPReader_nompi.cpp) -target_link_libraries(hello_bpReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPReaderExample) -if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpReaderHeatMap3D_f helloBPReaderHeatMap3D.F90) - set_property(TARGET hello_bpReaderHeatMap3D_f PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpReaderHeatMap3D_f adios2::fortran) +if(NOT TARGET adios2::cxx11) + set(_components C) + + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) endif() +add_executable(adios2_hello_bpReader bpReader_nompi.cpp) +target_link_libraries(adios2_hello_bpReader adios2::cxx11) +install(TARGETS adios2_hello_bpReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if(ADIOS2_HAVE_MPI) - add_executable(hello_bpReader_mpi helloBPReader.cpp) - target_link_libraries(hello_bpReader_mpi adios2::cxx11_mpi MPI::MPI_C) - - add_executable(hello_bpReaderHeatMap2D helloBPReaderHeatMap2D.cpp) - target_link_libraries(hello_bpReaderHeatMap2D adios2::cxx11_mpi MPI::MPI_C) - - add_executable(hello_bpReaderHeatMap3D helloBPReaderHeatMap3D.cpp) - target_link_libraries(hello_bpReaderHeatMap3D adios2::cxx11_mpi MPI::MPI_C) - - if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpReaderHeatMap3D_f_mpi helloBPReaderHeatMap3D.F90) - target_link_libraries(hello_bpReaderHeatMap3D_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) - set_property(TARGET hello_bpReaderHeatMap3D_f_mpi PROPERTY LINKER_LANGUAGE Fortran) + add_executable(adios2_hello_bpReader_mpi bpReader.cpp) + target_link_libraries(adios2_hello_bpReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_bpReaderHeatMap2D bpReaderHeatMap2D.cpp) + target_link_libraries(adios2_hello_bpReaderHeatMap2D adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReaderHeatMap2D RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_bpReaderHeatMap3D bpReaderHeatMap3D.cpp) + target_link_libraries(adios2_hello_bpReaderHeatMap3D adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpReaderHeatMap3D RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +if(ADIOS2_HAVE_Fortran) + add_executable(adios2_hello_bpReaderHeatMap3D_f bpReaderHeatMap3D.F90) + target_link_libraries(adios2_hello_bpReaderHeatMap3D_f adios2::fortran) + install(TARGETS adios2_hello_bpReaderHeatMap3D_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_bpReaderHeatMap3D_f_mpi bpReaderHeatMap3D.F90) + target_link_libraries(adios2_hello_bpReaderHeatMap3D_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_bpReaderHeatMap3D_f_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endif() diff --git a/examples/hello/bpReader/helloBPReader.cpp b/examples/hello/bpReader/bpReader.cpp similarity index 88% rename from examples/hello/bpReader/helloBPReader.cpp rename to examples/hello/bpReader/bpReader.cpp index c786b1df2f..1b57561fd0 100644 --- a/examples/hello/bpReader/helloBPReader.cpp +++ b/examples/hello/bpReader/bpReader.cpp @@ -2,8 +2,8 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReader.cpp: Simple self-descriptive example of how to read a variable - * to a BP File. + * bpReader.cpp: Simple self-descriptive example of how to read a variable + * from a BP File. * * Try running like this from the build directory: * mpirun -np 3 ./bin/hello_bpReader @@ -41,8 +41,8 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine bpReader = bpIO.Open(filename, adios2::Mode::Read); - const std::map variables = - bpIO.AvailableVariables(); + bpReader.BeginStep(); + const std::map variables = bpIO.AvailableVariables(); for (const auto &variablePair : variables) { @@ -50,14 +50,12 @@ int main(int argc, char *argv[]) for (const auto ¶meter : variablePair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; } } /** Write variable for buffering */ - adios2::Variable bpFloats = - bpIO.InquireVariable("bpFloats"); + adios2::Variable bpFloats = bpIO.InquireVariable("bpFloats"); adios2::Variable bpInts = bpIO.InquireVariable("bpInts"); const std::size_t Nx = 10; @@ -99,6 +97,7 @@ int main(int argc, char *argv[]) std::cout << "\n"; } } + bpReader.EndStep(); /** Close bp file, engine becomes unreachable after this*/ bpReader.Close(); @@ -107,9 +106,7 @@ int main(int argc, char *argv[]) { if (rank == 0) { - std::cerr - << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cerr << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cerr << e.what() << "\n"; } MPI_Abort(MPI_COMM_WORLD, 1); @@ -133,8 +130,7 @@ int main(int argc, char *argv[]) { if (rank == 0) { - std::cerr << "Exception, STOPPING PROGRAM from rank " << rank - << "\n"; + std::cerr << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cerr << e.what() << "\n"; } MPI_Abort(MPI_COMM_WORLD, 1); diff --git a/examples/hello/bpReader/helloBPReaderHeatMap2D.cpp b/examples/hello/bpReader/bpReaderHeatMap2D.cpp similarity index 84% rename from examples/hello/bpReader/helloBPReaderHeatMap2D.cpp rename to examples/hello/bpReader/bpReaderHeatMap2D.cpp index 0eacb2f641..17a5ecbc08 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap2D.cpp +++ b/examples/hello/bpReader/bpReaderHeatMap2D.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReaderHeatMap.cpp : Writes a heat map in a regular 2D mesh, + * bpReaderHeatMap2D.cpp : Writes a heat map in a regular 2D mesh, * values grow from 0 in increments of 1 * * temperature[gNx, Ny] @@ -54,8 +54,7 @@ int main(int argc, char *argv[]) for (unsigned int j = 0; j < Ny; ++j) { - const unsigned int value = - static_cast(iGlobal * shape[1] + j); + const unsigned int value = static_cast(iGlobal * shape[1] + j); temperatures[i * Ny + j] = value; } } @@ -70,24 +69,25 @@ int main(int argc, char *argv[]) * Parameters, Transports, and Execution: Engines */ adios2::IO putHeatMap = adios.DeclareIO("HeatMapWriter"); - adios2::Variable outTemperature = - putHeatMap.DefineVariable( - "temperature", shape, start, count, adios2::ConstantDims); + adios2::Variable outTemperature = putHeatMap.DefineVariable( + "temperature", shape, start, count, adios2::ConstantDims); /** Will create HeatMap.bp */ - adios2::Engine bpWriter = - putHeatMap.Open("HeatMap2D.bp", adios2::Mode::Write); + adios2::Engine bpWriter = putHeatMap.Open("HeatMap2D.bp", adios2::Mode::Write); + bpWriter.BeginStep(); bpWriter.Put(outTemperature, temperatures.data()); + bpWriter.EndStep(); bpWriter.Close(); // ************************** READ if (rank == 0) { adios2::IO getHeatMap = adios.DeclareIO("HeatMapReader"); - adios2::Engine bpReader = getHeatMap.Open( - "HeatMap2D.bp", adios2::Mode::Read, MPI_COMM_SELF); + adios2::Engine bpReader = + getHeatMap.Open("HeatMap2D.bp", adios2::Mode::Read, MPI_COMM_SELF); + bpReader.BeginStep(); // this just discovers in the metadata file that the variable exists adios2::Variable inTemperature = getHeatMap.InquireVariable("temperature"); @@ -100,8 +100,7 @@ int main(int argc, char *argv[]) std::cout << "Pre-allocated " << elementsSize << " elements, " << elementsSize * sizeof(unsigned int) << " bytes\n"; - bpReader.Get(inTemperature, inTemperatures.data(), - adios2::Mode::Sync); + bpReader.Get(inTemperature, inTemperatures.data(), adios2::Mode::Sync); std::cout << "Incoming temperature map:\n"; @@ -115,14 +114,14 @@ int main(int argc, char *argv[]) } std::cout << "\n"; } + bpReader.EndStep(); bpReader.Close(); } } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/bpReader/helloBPReaderHeatMap2D.py b/examples/hello/bpReader/bpReaderHeatMap2D.py similarity index 73% rename from examples/hello/bpReader/helloBPReaderHeatMap2D.py rename to examples/hello/bpReader/bpReaderHeatMap2D.py index 9aa8925a39..7400b65e10 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap2D.py +++ b/examples/hello/bpReader/bpReaderHeatMap2D.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPReaderHeatMap2D.py +# bpReaderHeatMap2D.py # # # Created on: Dec 5th, 2017 @@ -41,18 +41,23 @@ adios = adios2.ADIOS(comm) ioWrite = adios.DeclareIO("ioWriter") -varTemperature = ioWrite.DefineVariable("temperature2D", temperatures, shape, - start, count, adios2.ConstantDims) +varTemperature = ioWrite.DefineVariable( + "temperature2D", temperatures, shape, start, count, adios2.ConstantDims +) -obpStream = ioWrite.Open('HeatMap2D_py.bp', adios2.Mode.Write) +obpStream = ioWrite.Open("HeatMap2D_py.bp", adios2.Mode.Write) +obpStream.BeginStep() obpStream.Put(varTemperature, temperatures) +obpStream.EndStep() obpStream.Close() if rank == 0: ioRead = adios.DeclareIO("ioReader") - ibpStream = ioRead.Open('HeatMap2D_py.bp', adios2.Mode.Read, MPI.COMM_SELF) + ibpStream = ioRead.Open("HeatMap2D_py.bp", adios2.Mode.Read, MPI.COMM_SELF) + + ibpStream.BeginStep() var_inTemperature = ioRead.InquireVariable("temperature2D") @@ -60,17 +65,18 @@ var_inTemperature.SetSelection([[2, 2], [4, 4]]) inSize = var_inTemperature.SelectionSize() - print('Incoming size ' + str(inSize)) + print("Incoming size " + str(inSize)) inTemperatures = numpy.zeros(inSize, dtype=numpy.int) ibpStream.Get(var_inTemperature, inTemperatures, adios2.Mode.Sync) - print('Incoming temperature map') + print("Incoming temperature map") for i in range(0, inTemperatures.size): - print(str(inTemperatures[i]) + ' ') + print(str(inTemperatures[i]) + " ") if (i + 1) % 4 == 0: print() + ibpStream.EndStep() ibpStream.Close() diff --git a/examples/hello/bpReader/helloBPReaderHeatMap3D.F90 b/examples/hello/bpReader/bpReaderHeatMap3D.F90 similarity index 98% rename from examples/hello/bpReader/helloBPReaderHeatMap3D.F90 rename to examples/hello/bpReader/bpReaderHeatMap3D.F90 index e44d9c53bf..3bd7251e89 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap3D.F90 +++ b/examples/hello/bpReader/bpReaderHeatMap3D.F90 @@ -1,4 +1,4 @@ -program helloBPReaderHeatMap3D +program bpReaderHeatMap3D #if ADIOS2_USE_MPI use mpi #endif @@ -130,4 +130,4 @@ program helloBPReaderHeatMap3D call MPI_Finalize(ierr) #endif -end program helloBPReaderHeatMap3D +end program bpReaderHeatMap3D diff --git a/examples/hello/bpReader/helloBPReaderHeatMap3D.cpp b/examples/hello/bpReader/bpReaderHeatMap3D.cpp similarity index 84% rename from examples/hello/bpReader/helloBPReaderHeatMap3D.cpp rename to examples/hello/bpReader/bpReaderHeatMap3D.cpp index 40d57dad9b..a4f98fb5b8 100644 --- a/examples/hello/bpReader/helloBPReaderHeatMap3D.cpp +++ b/examples/hello/bpReader/bpReaderHeatMap3D.cpp @@ -61,11 +61,10 @@ int main(int argc, char *argv[]) { for (unsigned int k = 0; k < count[2]; ++k) { - const unsigned int value = static_cast( - iGlobal * shape[1] * shape[2] + j * shape[2] + k); + const unsigned int value = + static_cast(iGlobal * shape[1] * shape[2] + j * shape[2] + k); - const std::size_t linearIndex = - i * count[1] * count[2] + j * count[2] + k; + const std::size_t linearIndex = i * count[1] * count[2] + j * count[2] + k; temperatures[linearIndex] = value; } @@ -82,24 +81,25 @@ int main(int argc, char *argv[]) * Parameters, Transports, and Execution: Engines */ adios2::IO putHeatMap = adios.DeclareIO("HeatMapWrite"); - adios2::Variable outTemperature = - putHeatMap.DefineVariable( - "temperature", shape, start, count, adios2::ConstantDims); + adios2::Variable outTemperature = putHeatMap.DefineVariable( + "temperature", shape, start, count, adios2::ConstantDims); /** Will create HeatMap3D.bp */ - adios2::Engine bpWriter = - putHeatMap.Open("HeatMap3D.bp", adios2::Mode::Write); + adios2::Engine bpWriter = putHeatMap.Open("HeatMap3D.bp", adios2::Mode::Write); + bpWriter.BeginStep(); bpWriter.Put(outTemperature, temperatures.data()); + bpWriter.EndStep(); bpWriter.Close(); // ************************** READ if (rank == 0) { adios2::IO getHeatMap = adios.DeclareIO("HeatMapRead"); - adios2::Engine bpReader = getHeatMap.Open( - "HeatMap3D.bp", adios2::Mode::Read, MPI_COMM_SELF); + adios2::Engine bpReader = + getHeatMap.Open("HeatMap3D.bp", adios2::Mode::Read, MPI_COMM_SELF); + bpReader.BeginStep(); // this just discovers in the metadata file that the variable exists adios2::Variable inTemperature = getHeatMap.InquireVariable("temperature"); @@ -112,8 +112,7 @@ int main(int argc, char *argv[]) std::cout << "Pre-allocated " << elementsSize << " elements, " << elementsSize * sizeof(unsigned int) << " bytes\n"; - bpReader.Get(inTemperature, inTemperatures.data(), - adios2::Mode::Sync); + bpReader.Get(inTemperature, inTemperatures.data(), adios2::Mode::Sync); std::cout << "Temperature map selection: "; std::cout << "{ start = [2,2,2], count = [4,4,4] }\n"; @@ -128,14 +127,14 @@ int main(int argc, char *argv[]) } std::cout << "\n"; } + bpReader.EndStep(); bpReader.Close(); } } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/bpReader/helloBPReader_nompi.cpp b/examples/hello/bpReader/bpReader_nompi.cpp similarity index 88% rename from examples/hello/bpReader/helloBPReader_nompi.cpp rename to examples/hello/bpReader/bpReader_nompi.cpp index f8161897d0..6f36aa3c63 100644 --- a/examples/hello/bpReader/helloBPReader_nompi.cpp +++ b/examples/hello/bpReader/bpReader_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPReader.cpp: Simple self-descriptive example of how to read a variable + * bpReader_nompi.cpp: Simple self-descriptive example of how to read a variable * from a BP File. * * Created on: Feb 16, 2017 @@ -31,9 +31,9 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine bpReader = bpIO.Open(filename, adios2::Mode::Read); + bpReader.BeginStep(); - const std::map variables = - bpIO.AvailableVariables(true); + const std::map variables = bpIO.AvailableVariables(true); std::cout << "List of variables:"; for (const auto &variablePair : variables) @@ -43,8 +43,7 @@ int main(int argc, char *argv[]) std::cout << std::endl; /** Write variable for buffering */ - adios2::Variable bpFloats = - bpIO.InquireVariable("bpFloats"); + adios2::Variable bpFloats = bpIO.InquireVariable("bpFloats"); adios2::Variable bpInts = bpIO.InquireVariable("bpInts"); @@ -67,9 +66,9 @@ int main(int argc, char *argv[]) } else { - std::cout << "There are no integer datasets in " << filename - << ".\n"; + std::cout << "There are no integer datasets in " << filename << ".\n"; } + bpReader.EndStep(); /** Close bp file, engine becomes unreachable after this*/ bpReader.Close(); diff --git a/examples/hello/bpThreadWrite/CMakeLists.txt b/examples/hello/bpThreadWrite/CMakeLists.txt new file mode 100644 index 0000000000..bc7fd8fb1b --- /dev/null +++ b/examples/hello/bpThreadWrite/CMakeLists.txt @@ -0,0 +1,21 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloThreadWriteExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Threads QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(Threads_FOUND) + add_executable(adios2_hello_bpThreadWrite bpThreadWrite.cpp) + target_link_libraries(adios2_hello_bpThreadWrite adios2::cxx11 ${CMAKE_THREAD_LIBS_INIT}) + install(TARGETS adios2_hello_bpThreadWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpThreadWrite/bpThreadWrite.cpp b/examples/hello/bpThreadWrite/bpThreadWrite.cpp new file mode 100644 index 0000000000..4badac3239 --- /dev/null +++ b/examples/hello/bpThreadWrite/bpThreadWrite.cpp @@ -0,0 +1,124 @@ + +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * bpThreadWrite.cpp : adios2 low-level API example to write in a threaded + * application using C++11 thread and having adios2 calls + * inside mutex regions adios2 API are not thread-safe: + * 1. launching MPI from a thread is not possible on many + * supercomputers + * 2. I/O is highly serialized (buffering and low-level I/O + * calls), therefore users must be aware that adios2 might introduce + * bottlenecks. To run: Do not use MPI, just run the executable + * ./adios2_hello_bpThreadWrite + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include + +#include //std::size_t +#include +#include +#include +#include +#include + +namespace +{ + +std::mutex mutex; + +// tasks that runs on thread, each section of the vector is covered +template +void ThreadTask(const std::size_t threadID, std::vector &data, const std::size_t startIndex, + const std::size_t localSize, const std::string &variableName, adios2::IO io, + adios2::Engine engine) +{ + (void)threadID; // unused variable + // populate vector data, but simply adding step to index + for (std::size_t i = 0; i < localSize; ++i) + { + const std::size_t index = startIndex + i; + data[index] = static_cast(index); + } + + // I/O write region in a locked mutex + { + mutex.lock(); + + adios2::Variable variable = io.InquireVariable(variableName); + variable.SetSelection({{startIndex}, {localSize}}); + + engine.Put(variable, &data[startIndex]); + // PerformPuts must be called to collect memory per buffer + engine.PerformPuts(); + + mutex.unlock(); + } +} + +} // end namespace + +int main(int argc, char *argv[]) +{ + try + { + constexpr std::size_t nx = 100; + // data to be populated and written per thread + std::vector data(nx); + + // initialize adios2 objects serially + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("thread-write"); + // populate shape, leave start and count empty as + // they will come from each thread SetSelection + const std::string variableName = "data"; + io.DefineVariable(variableName, adios2::Dims{nx}, adios2::Dims(), adios2::Dims()); + + adios2::Engine engine = io.Open("thread-writes.bp", adios2::Mode::Write); + + // set up thread tasks + // just grab maximum number of threads to simplify things + const auto nthreads = static_cast(std::thread::hardware_concurrency()); + std::vector threadTasks; + threadTasks.reserve(nthreads); + + // launch threaded tasks (this is what OpenMP would simplify) + // elements per thread + const std::size_t stride = nx / nthreads; + // elements for last thread, add remainder + const std::size_t last = stride + nx % nthreads; + + engine.BeginStep(); + // launch threads + for (std::size_t t = 0; t < nthreads; ++t) + { + const std::size_t startIndex = stride * t; + // non-inclusive endIndex + const std::size_t localSize = (t == nthreads - 1) ? last : stride; + + // use std::ref to pass things by reference + // adios2 objects can be passed by value + + threadTasks.emplace_back(ThreadTask, t, std::ref(data), startIndex, localSize, + std::ref(variableName), io, engine); + } + + for (auto &threadTask : threadTasks) + { + threadTask.join(); + } + engine.EndStep(); + + engine.Close(); + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; + } + + return 0; +} diff --git a/examples/hello/bpTimeWriter/CMakeLists.txt b/examples/hello/bpTimeWriter/CMakeLists.txt index 5306bbd375..30a9f1d361 100644 --- a/examples/hello/bpTimeWriter/CMakeLists.txt +++ b/examples/hello/bpTimeWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpTimeWriter helloBPTimeWriter_nompi.cpp) -target_link_libraries(hello_bpTimeWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPTimeWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpTimeWriter bpTimeWriter_nompi.cpp) +target_link_libraries(adios2_hello_bpTimeWriter adios2::cxx11) +install(TARGETS adios2_hello_bpTimeWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_bpTimeWriter_mpi helloBPTimeWriter.cpp) - target_link_libraries(hello_bpTimeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpTimeWriter_mpi bpTimeWriter.cpp) + target_link_libraries(adios2_hello_bpTimeWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpTimeWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter.cpp b/examples/hello/bpTimeWriter/bpTimeWriter.cpp similarity index 83% rename from examples/hello/bpTimeWriter/helloBPTimeWriter.cpp rename to examples/hello/bpTimeWriter/bpTimeWriter.cpp index 3ca86093f7..77e37389cc 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter.cpp +++ b/examples/hello/bpTimeWriter/bpTimeWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPTimeWriter.cpp example for writing a variable using the Advance + * bpTimeWriter.cpp example for writing a variable using the Advance * function for time aggregation. Time step is saved as an additional (global) * single value variable, just for tracking purposes. * @@ -51,8 +51,7 @@ int main(int argc, char *argv[]) const unsigned int variablesSize = 10; std::vector> bpFloats(variablesSize); - adios2::Variable bpString = - bpIO.DefineVariable("bpString"); + adios2::Variable bpString = bpIO.DefineVariable("bpString"); for (unsigned int v = 0; v < variablesSize; ++v) { @@ -67,9 +66,8 @@ int main(int argc, char *argv[]) } namev += std::to_string(v); - bpFloats[v] = - bpIO.DefineVariable(namev, {size * Nx}, {rank * Nx}, - {Nx}, adios2::ConstantDims); + bpFloats[v] = bpIO.DefineVariable(namev, {size * Nx}, {rank * Nx}, {Nx}, + adios2::ConstantDims); } /** global single value variable: name */ @@ -77,8 +75,7 @@ int main(int argc, char *argv[]) bpIO.DefineVariable("timeStep"); /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpWriter = - bpIO.Open("myVector.bp", adios2::Mode::Write); + adios2::Engine bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); for (unsigned int timeStep = 0; timeStep < 3; ++timeStep) { @@ -96,9 +93,8 @@ int main(int argc, char *argv[]) // and myFloats[0] == 9, 10, or 11 bpWriter.Put(bpFloats[v], myFloats.data()); } - const std::string myString( - "Hello from rank: " + std::to_string(rank) + - " and timestep: " + std::to_string(timeStep)); + const std::string myString("Hello from rank: " + std::to_string(rank) + + " and timestep: " + std::to_string(timeStep)); if (rank == 0) { @@ -118,11 +114,9 @@ int main(int argc, char *argv[]) // { adios2::IO ioReader = adios.DeclareIO("bpReader"); - adios2::Engine bpReader = - ioReader.Open("myVector.bp", adios2::Mode::Read); + adios2::Engine bpReader = ioReader.Open("myVector.bp", adios2::Mode::Read); - adios2::Variable bpFloats000 = - ioReader.InquireVariable("bpFloats000"); + adios2::Variable bpFloats000 = ioReader.InquireVariable("bpFloats000"); adios2::Variable bpString = ioReader.InquireVariable("bpString"); @@ -135,8 +129,8 @@ int main(int argc, char *argv[]) std::vector data(bpFloats000.SelectionSize()); bpReader.Get(bpFloats000, data.data(), adios2::Mode::Sync); - std::cout << "Data timestep " << bpFloats000.StepsStart() - << " from rank " << rank << ": "; + std::cout << "Data timestep " << bpFloats000.StepsStart() << " from rank " << rank + << ": "; for (const auto datum : data) { std::cout << datum << " "; @@ -162,8 +156,7 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter.py b/examples/hello/bpTimeWriter/bpTimeWriter.py similarity index 87% rename from examples/hello/bpTimeWriter/helloBPTimeWriter.py rename to examples/hello/bpTimeWriter/bpTimeWriter.py index 4ddff5a1aa..87afc7f1c1 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter.py +++ b/examples/hello/bpTimeWriter/bpTimeWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# test_hello.py +# bpTimeWriter.py # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov @@ -28,8 +28,9 @@ bpIO = adios.DeclareIO("BPN2N") # Variables -bpArray = bpIO.DefineVariable("bpArray", myArray, [size * nx], [rank * nx], - [nx], adios2.ConstantDims) +bpArray = bpIO.DefineVariable( + "bpArray", myArray, [size * nx], [rank * nx], [nx], adios2.ConstantDims +) bpTimeStep = bpIO.DefineVariable("bpTimeStep", time) # Engine diff --git a/examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp b/examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp similarity index 86% rename from examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp rename to examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp index cbefe40c24..ddfd113fa4 100644 --- a/examples/hello/bpTimeWriter/helloBPTimeWriter_nompi.cpp +++ b/examples/hello/bpTimeWriter/bpTimeWriter_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPTimeWriter_nompi.cpp no mpi version of helloBPTimeWriter.cpp + * bpTimeWriter_nompi.cpp no mpi version of bpTimeWriter.cpp * * Created on: Feb 16, 2017 * Author: William F Godoy godoywf@ornl.gov @@ -32,11 +32,10 @@ int main(int argc, char *argv[]) /** name, { shape (total dimensions) }, { start (local) }, { count * {local} } */ - adios2::Variable bpFloats = bpIO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable bpFloats = + bpIO.DefineVariable("bpFloats", {}, {}, {Nx}, adios2::ConstantDims); - adios2::Variable bpTimeStep = - bpIO.DefineVariable("timeStep"); + adios2::Variable bpTimeStep = bpIO.DefineVariable("timeStep"); /** Engine derived class, spawned to start IO operations */ adios2::Engine bpWriter = bpIO.Open("myVector.bp", adios2::Mode::Write); diff --git a/examples/hello/bpWriteReadCuda/CMakeLists.txt b/examples/hello/bpWriteReadCuda/CMakeLists.txt new file mode 100644 index 0000000000..453867f0b4 --- /dev/null +++ b/examples/hello/bpWriteReadCuda/CMakeLists.txt @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadCudaExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(CUDAToolkit REQUIRED) + if(CUDAToolkit_FOUND) + enable_language(CUDA) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_CUDA OR ADIOS2_HAVE_Kokkos_CUDA) + add_executable(adios2_hello_bpWriteReadCuda bpWriteReadCuda.cu) + target_link_libraries(adios2_hello_bpWriteReadCuda PUBLIC adios2::cxx11 CUDA::cudart) + set_target_properties(adios2_hello_bpWriteReadCuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + install(TARGETS adios2_hello_bpWriteReadCuda RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/cuda/cudaBPWriteRead.cu b/examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu similarity index 91% rename from examples/cuda/cudaBPWriteRead.cu rename to examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu index 735486a799..5db837c79d 100644 --- a/examples/cuda/cudaBPWriteRead.cu +++ b/examples/hello/bpWriteReadCuda/bpWriteReadCuda.cu @@ -1,4 +1,7 @@ /* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * * Simple example of writing and reading data * through ADIOS2 BP engine with multiple simulations steps * for every IO step. @@ -15,10 +18,9 @@ __global__ void update_array(float *vect, int val) { vect[blockIdx.x] += val; } -std::string engine("BP5"); +std::string engine("BPFile"); -int BPWrite(const std::string fname, const size_t N, int nSteps, - const std::string engine) +int BPWrite(const std::string fname, const size_t N, int nSteps, const std::string engine) { // Initialize the simulation data float *gpuSimData; @@ -60,8 +62,7 @@ int BPWrite(const std::string fname, const size_t N, int nSteps, return 0; } -int BPRead(const std::string fname, const size_t N, int nSteps, - const std::string engine) +int BPRead(const std::string fname, const size_t N, int nSteps, const std::string engine) { // Create ADIOS structures adios2::ADIOS adios; @@ -86,8 +87,7 @@ int BPRead(const std::string fname, const size_t N, int nSteps, data.SetMemorySpace(adios2::MemorySpace::GPU); bpReader.Get(data, gpuSimData); //, adios2::Mode::Deferred); bpReader.EndStep(); - cudaMemcpy(simData.data(), gpuSimData, N * sizeof(float), - cudaMemcpyDeviceToHost); + cudaMemcpy(simData.data(), gpuSimData, N * sizeof(float), cudaMemcpyDeviceToHost); std::cout << "Simualation step " << step << " : "; std::cout << simData.size() << " elements: " << simData[1] << std::endl; } diff --git a/examples/hello/bpWriteReadHip/CMakeLists.txt b/examples/hello/bpWriteReadHip/CMakeLists.txt new file mode 100644 index 0000000000..bb1b6d3acf --- /dev/null +++ b/examples/hello/bpWriteReadHip/CMakeLists.txt @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadHipExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(hip QUIET) + if(hip_FOUND) + enable_language(HIP) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Kokkos_HIP OR hip_FOUND) + add_executable(adios2_hello_bpWriteReadHip bpWriteReadHip.cpp) + target_link_libraries(adios2_hello_bpWriteReadHip adios2::cxx11 hip::device) + set_source_files_properties(bpWriteReadHip.cpp PROPERTIES LANGUAGE HIP) + install(TARGETS adios2_hello_bpWriteReadHip RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp b/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp new file mode 100644 index 0000000000..755bb3f735 --- /dev/null +++ b/examples/hello/bpWriteReadHip/bpWriteReadHip.cpp @@ -0,0 +1,135 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ +#include +#include +#include +#include + +#include + +#include + +__global__ void hip_initialize(float *vec) { vec[hipBlockIdx_x] = hipBlockIdx_x; } + +__global__ void hip_increment(float *vec, float val) { vec[hipBlockIdx_x] += val; } + +int BPWrite(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + hipError_t hipExit; + float *gpuSimData; + hipExit = hipMalloc((void **)&gpuSimData, N * sizeof(float)); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + hipLaunchKernelGGL(hip_initialize, dim3(N), dim3(1), 0, 0, gpuSimData); + hipExit = hipDeviceSynchronize(); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("WriteIO"); + io.SetEngine(engine); + + const adios2::Dims shape{static_cast(N)}; + const adios2::Dims start{static_cast(0)}; + const adios2::Dims count{N}; + auto data = io.DefineVariable("data", shape, start, count); + + adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write); + + for (size_t step = 0; step < nSteps; ++step) + { + adios2::Box sel({0}, {N}); + data.SetSelection(sel); + + bpWriter.BeginStep(); + bpWriter.Put(data, gpuSimData); + bpWriter.EndStep(); + + hipLaunchKernelGGL(hip_increment, dim3(N), dim3(1), 0, 0, gpuSimData, 10); + hipExit = hipDeviceSynchronize(); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + } + + bpWriter.Close(); + return 0; +} + +int BPRead(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + hipError_t hipExit; + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("ReadIO"); + io.SetEngine(engine); + + adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read); + + unsigned int step = 0; + float *gpuSimData; + hipExit = hipMalloc((void **)&gpuSimData, N * sizeof(float)); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + for (; bpReader.BeginStep() == adios2::StepStatus::OK; ++step) + { + auto data = io.InquireVariable("data"); + const adios2::Dims start{0}; + const adios2::Dims count{N}; + const adios2::Box sel(start, count); + data.SetSelection(sel); + + bpReader.Get(data, gpuSimData); + bpReader.EndStep(); + + std::vector cpuData(N); + hipExit = hipMemcpy(cpuData.data(), gpuSimData, N * sizeof(float), hipMemcpyDeviceToHost); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + std::cout << "Simualation step " << step << " : "; + std::cout << cpuData.size() << " elements: " << cpuData[0]; + std::cout << " " << cpuData[1] << " ... "; + std::cout << cpuData[cpuData.size() - 1] << std::endl; + } + bpReader.Close(); + return 0; +} + +int main(int argc, char **argv) +{ + hipError_t hipExit; + const int device_id = 0; + hipExit = hipSetDevice(device_id); + if (hipExit != hipSuccess) + { + std::cout << "[BPWrite] error: " << hipGetErrorString(hipExit) << std::endl; + return 1; + } + const std::vector list_of_engines = {"BPFile"}; + const size_t N = 6000; + int nSteps = 2, ret = 0; + + for (auto engine : list_of_engines) + { + std::cout << "Using engine " << engine << std::endl; + const std::string fname(engine + "_HIP_WR.bp"); + ret += BPWrite(fname, N, nSteps, engine); + ret += BPRead(fname, N, nSteps, engine); + } + return ret; +} diff --git a/examples/hello/bpWriteReadKokkos/CMakeLists.txt b/examples/hello/bpWriteReadKokkos/CMakeLists.txt new file mode 100644 index 0000000000..a8e810b734 --- /dev/null +++ b/examples/hello/bpWriteReadKokkos/CMakeLists.txt @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriteReadKokkosExample) + +# CXX Compiler settings only in for this example +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Kokkos 3.7 QUIET) + if(Kokkos_FOUND AND DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +else() + if(DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() +endif() + +if(ADIOS2_HAVE_Kokkos) + add_executable(adios2_hello_bpWriteReadKokkos bpWriteReadKokkos.cpp) + kokkos_compilation(SOURCE bpWriteReadKokkos.cpp) + target_link_libraries(adios2_hello_bpWriteReadKokkos adios2::cxx11 Kokkos::kokkos) + install(TARGETS adios2_hello_bpWriteReadKokkos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp b/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp new file mode 100644 index 0000000000..fd972ed9b0 --- /dev/null +++ b/examples/hello/bpWriteReadKokkos/bpWriteReadKokkos.cpp @@ -0,0 +1,117 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ +#include +#include +#include + +#include + +#include + +int BPWrite(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + // Initialize the simulation data with the default memory space + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View gpuSimData("simBuffer", N); + Kokkos::parallel_for( + "initBuffer", Kokkos::RangePolicy(0, N), + KOKKOS_LAMBDA(int i) { gpuSimData(i) = static_cast(i); }); + Kokkos::fence(); + + // Set up the ADIOS structures + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("WriteIO"); + io.SetEngine(engine); + + const adios2::Dims shape{static_cast(N)}; + const adios2::Dims start{static_cast(0)}; + const adios2::Dims count{N}; + auto data = io.DefineVariable("data", shape, start, count); + + adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write); + + // Simulation steps + for (int step = 0; step < nSteps; ++step) + { + // Make a 1D selection to describe the local dimensions of the + // variable we write and its offsets in the global spaces + adios2::Box sel({0}, {N}); + data.SetSelection(sel); + + // Start IO step every write step + bpWriter.BeginStep(); + bpWriter.Put(data, gpuSimData.data()); + bpWriter.EndStep(); + + // Update values in the simulation data using the default + // execution space + Kokkos::parallel_for( + "updateBuffer", Kokkos::RangePolicy(0, N), + KOKKOS_LAMBDA(int i) { gpuSimData(i) += 10; }); + Kokkos::fence(); + } + + bpWriter.Close(); + Kokkos::DefaultExecutionSpace exe_space; + std::cout << "Done writing on memory space: " << exe_space.name() << std::endl; + return 0; +} + +int BPRead(const std::string fname, const size_t N, int nSteps, const std::string engine) +{ + // Create ADIOS structures + adios2::ADIOS adios; + adios2::IO io = adios.DeclareIO("ReadIO"); + io.SetEngine(engine); + + Kokkos::DefaultExecutionSpace exe_space; + std::cout << "Read on memory space: " << exe_space.name() << std::endl; + + adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read); + + unsigned int step = 0; + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View gpuSimData("simBuffer", N); + for (; bpReader.BeginStep() == adios2::StepStatus::OK; ++step) + { + auto data = io.InquireVariable("data"); + const adios2::Dims start{0}; + const adios2::Dims count{N}; + const adios2::Box sel(start, count); + data.SetSelection(sel); + + bpReader.Get(data, gpuSimData.data()); + bpReader.EndStep(); + + auto cpuData = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, gpuSimData); + std::cout << "Simualation step " << step << " : "; + std::cout << cpuData.size() << " elements: " << cpuData[0]; + std::cout << " " << cpuData[1] << " ... "; + std::cout << cpuData[cpuData.size() - 1] << std::endl; + } + + bpReader.Close(); + return 0; +} + +int main(int argc, char **argv) +{ + const std::vector list_of_engines = {"BPFile"}; + const size_t N = 6000; + int nSteps = 2, ret = 0; + + Kokkos::initialize(argc, argv); + { + for (auto engine : list_of_engines) + { + std::cout << "Using engine " << engine << std::endl; + const std::string fname(engine + "_Kokkos_WR.bp"); + ret += BPWrite(fname, N, nSteps, engine); + ret += BPRead(fname, N, nSteps, engine); + } + } + Kokkos::finalize(); + return ret; +} diff --git a/examples/hello/bpWriter/CMakeLists.txt b/examples/hello/bpWriter/CMakeLists.txt index aad594f556..0e48312f8c 100644 --- a/examples/hello/bpWriter/CMakeLists.txt +++ b/examples/hello/bpWriter/CMakeLists.txt @@ -3,50 +3,89 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_bpWriter helloBPWriter.cpp) -target_link_libraries(hello_bpWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloBPWriterExample) -add_executable(hello_bpWriter_c helloBPWriter.c) -target_link_libraries(hello_bpWriter_c adios2::c) +if(NOT TARGET adios2_core) + set(_components C) -add_executable(hello_bpPutDeferred helloBPPutDeferred.cpp) -target_link_libraries(hello_bpPutDeferred adios2::cxx11) + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(MPI COMPONENTS ${_components}) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + list(APPEND _components CXX) + + find_package(SZ QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_bpWriter bpWriter.cpp) +target_link_libraries(adios2_hello_bpWriter adios2::cxx11) +install(TARGETS adios2_hello_bpWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_bpWriter_c bpWriter.c) +target_link_libraries(adios2_hello_bpWriter_c adios2::c) +install(TARGETS adios2_hello_bpWriter_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_bpPutDeferred bpPutDeferred.cpp) +target_link_libraries(adios2_hello_bpPutDeferred adios2::cxx11) +install(TARGETS adios2_hello_bpPutDeferred RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(hello_bpSubStreams helloBPSubStreams.cpp) -target_link_libraries(hello_bpSubStreams adios2::cxx11) +add_executable(adios2_hello_bpSubStreams bpSubStreams.cpp) +target_link_libraries(adios2_hello_bpSubStreams adios2::cxx11) +install(TARGETS adios2_hello_bpSubStreams RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_SZ) - add_executable(hello_bpSZ helloBPSZ.cpp) - target_link_libraries(hello_bpSZ adios2::cxx11) + add_executable(adios2_hello_bpSZ bpSZ.cpp) + target_link_libraries(adios2_hello_bpSZ adios2::cxx11) + install(TARGETS adios2_hello_bpSZ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f helloBPWriter.F90) - set_property(TARGET hello_bpWriter_f PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpWriter_f adios2::fortran) + add_executable(adios2_hello_bpWriter_f bpWriter.F90) + target_link_libraries(adios2_hello_bpWriter_f adios2::fortran) + install(TARGETS adios2_hello_bpWriter_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_MPI) - add_executable(hello_bpWriter_mpi helloBPWriter.cpp) - target_link_libraries(hello_bpWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpWriter_mpi bpWriter.cpp) + target_link_libraries(adios2_hello_bpWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpWriter_c_mpi helloBPWriter.c) - target_link_libraries(hello_bpWriter_c_mpi adios2::c_mpi MPI::MPI_C) + add_executable(adios2_hello_bpWriter_c_mpi bpWriter.c) + target_link_libraries(adios2_hello_bpWriter_c_mpi adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpWriter_c_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpPutDeferred_mpi helloBPPutDeferred.cpp) - target_link_libraries(hello_bpPutDeferred_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpPutDeferred_mpi bpPutDeferred.cpp) + target_link_libraries(adios2_hello_bpPutDeferred_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpPutDeferred_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_bpSubStreams_mpi helloBPSubStreams.cpp) - target_link_libraries(hello_bpSubStreams_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpSubStreams_mpi bpSubStreams.cpp) + target_link_libraries(adios2_hello_bpSubStreams_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpSubStreams_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_SZ) - add_executable(hello_bpSZ_mpi helloBPSZ.cpp) - target_link_libraries(hello_bpSZ_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_bpSZ_mpi bpSZ.cpp) + target_link_libraries(adios2_hello_bpSZ_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_bpSZ_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() if(ADIOS2_HAVE_Fortran) - add_executable(hello_bpWriter_f_mpi helloBPWriter.F90) - set_property(TARGET hello_bpWriter_f_mpi PROPERTY LINKER_LANGUAGE Fortran) - target_link_libraries(hello_bpWriter_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + add_executable(adios2_hello_bpWriter_f_mpi bpWriter.F90) + target_link_libraries(adios2_hello_bpWriter_f_mpi adios2::fortran_mpi MPI::MPI_Fortran) + install(TARGETS adios2_hello_bpWriter_f_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() endif() diff --git a/examples/hello/bpWriter/helloBPPutDeferred.cpp b/examples/hello/bpWriter/bpPutDeferred.cpp similarity index 85% rename from examples/hello/bpWriter/helloBPPutDeferred.cpp rename to examples/hello/bpWriter/bpPutDeferred.cpp index 9165919a00..2c0371209e 100644 --- a/examples/hello/bpWriter/helloBPPutDeferred.cpp +++ b/examples/hello/bpWriter/bpPutDeferred.cpp @@ -2,17 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPPutDeferred.cpp - * - * Created on: Oct 23, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * helloBPPutDeferred.cpp: Simple self-descriptive example of how to write a + * bpPutDeferred.cpp: Simple self-descriptive example of how to write a * variable * to a BP File that lives in several MPI processes. * @@ -71,16 +61,17 @@ int main(int argc, char *argv[]) adios2::Variable bpFloats = bpIO.DefineVariable( "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); - adios2::Variable bpInts = bpIO.DefineVariable( - "bpInts", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); + adios2::Variable bpInts = bpIO.DefineVariable("bpInts", {size * Nx}, {rank * Nx}, + {Nx}, adios2::ConstantDims); /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpFileWriter = - bpIO.Open("myVectorDeferred.bp", adios2::Mode::Write); + adios2::Engine bpFileWriter = bpIO.Open("myVectorDeferred.bp", adios2::Mode::Write); + bpFileWriter.BeginStep(); /** Put variables for buffering, template type is optional */ bpFileWriter.Put(bpFloats, myFloats.data()); bpFileWriter.Put(bpInts, myInts.data()); + bpFileWriter.EndStep(); /** Create bp file, engine becomes unreachable after this*/ bpFileWriter.Close(); diff --git a/examples/hello/bpWriter/helloBPSZ.cpp b/examples/hello/bpWriter/bpSZ.cpp similarity index 85% rename from examples/hello/bpWriter/helloBPSZ.cpp rename to examples/hello/bpWriter/bpSZ.cpp index 1818c6d656..357f42f829 100644 --- a/examples/hello/bpWriter/helloBPSZ.cpp +++ b/examples/hello/bpWriter/bpSZ.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPSZ.cpp : example passing runtime compression arguments + * bpSZ.cpp : example passing runtime compression arguments * * Created on: Aug 3, 2018 * Author: William F Godoy godoywf@ornl.gov @@ -49,9 +49,8 @@ int main(int argc, char *argv[]) { if (argc != 3) { - throw std::invalid_argument( - "ERROR: need sz accuracy e.g. 0.01, 0.1 as " - "2nd parameter in argv\n"); + throw std::invalid_argument("ERROR: need sz accuracy e.g. 0.01, 0.1 as " + "2nd parameter in argv\n"); } const std::size_t Nx = static_cast(std::stoull(argv[1])); @@ -83,21 +82,17 @@ int main(int argc, char *argv[]) if (accuracy > 1E-16) { adios2::Operator op = adios.DefineOperator("SZCompressor", "sz"); - varFloats.AddOperation(op, - {{"accuracy", std::to_string(accuracy)}}); - varDoubles.AddOperation(op, - {{"accuracy", std::to_string(accuracy)}}); + varFloats.AddOperation(op, {{"accuracy", std::to_string(accuracy)}}); + varDoubles.AddOperation(op, {{"accuracy", std::to_string(accuracy)}}); } - adios2::Attribute attribute = - bpIO.DefineAttribute("SZ_accuracy", accuracy); + adios2::Attribute attribute = bpIO.DefineAttribute("SZ_accuracy", accuracy); // To avoid compiling warnings (void)attribute; /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpFileWriter = - bpIO.Open("SZexample.bp", adios2::Mode::Write); + adios2::Engine bpFileWriter = bpIO.Open("SZexample.bp", adios2::Mode::Write); for (unsigned int t = 0; t < 3; ++t) { diff --git a/examples/hello/bpWriter/helloBPSubStreams.cpp b/examples/hello/bpWriter/bpSubStreams.cpp similarity index 92% rename from examples/hello/bpWriter/helloBPSubStreams.cpp rename to examples/hello/bpWriter/bpSubStreams.cpp index 596e8f574a..dad04e82b7 100644 --- a/examples/hello/bpWriter/helloBPSubStreams.cpp +++ b/examples/hello/bpWriter/bpSubStreams.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPSubStreams.cpp + * bpSubStreams.cpp * * Created on: Feb 21, 2018 * Author: William F Godoy godoywf@ornl.gov @@ -38,8 +38,7 @@ int main(int argc, char *argv[]) std::vector myInts = {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}; const std::size_t Nx = myFloats.size(); - const std::string myString("Hello Variable String from rank " + - std::to_string(rank)); + const std::string myString("Hello Variable String from rank " + std::to_string(rank)); try { @@ -68,14 +67,12 @@ int main(int argc, char *argv[]) // adios2::Variable &bpString = // bpIO.DefineVariable("bpString"); - adios2::Attribute attribute = - bpIO.DefineAttribute("attrINT", -1); + adios2::Attribute attribute = bpIO.DefineAttribute("attrINT", -1); (void)attribute; // For the sake of the example we create an unused // variable /** Engine derived class, spawned to start IO operations */ - adios2::Engine bpFileWriter = - bpIO.Open("myVector_cpp.bp", adios2::Mode::Write); + adios2::Engine bpFileWriter = bpIO.Open("myVector_cpp.bp", adios2::Mode::Write); for (unsigned int t = 0; t < 2; ++t) { diff --git a/examples/hello/bpWriter/helloBPWriter.F90 b/examples/hello/bpWriter/bpWriter.F90 similarity index 97% rename from examples/hello/bpWriter/helloBPWriter.F90 rename to examples/hello/bpWriter/bpWriter.F90 index d1cea302ae..296cb290a1 100644 --- a/examples/hello/bpWriter/helloBPWriter.F90 +++ b/examples/hello/bpWriter/bpWriter.F90 @@ -1,4 +1,4 @@ -program helloBPWriter +program bpWriter #if ADIOS2_USE_MPI use mpi #endif @@ -72,4 +72,4 @@ program helloBPWriter call MPI_Finalize(ierr) #endif -end program helloBPWriter +end program bpWriter diff --git a/examples/hello/bpWriter/helloBPWriter.c b/examples/hello/bpWriter/bpWriter.c similarity index 85% rename from examples/hello/bpWriter/helloBPWriter.c rename to examples/hello/bpWriter/bpWriter.c index 715e0ed9a3..c304510493 100644 --- a/examples/hello/bpWriter/helloBPWriter.c +++ b/examples/hello/bpWriter/bpWriter.c @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.c : C bindings version of helloBPWriter.cpp + * bpWriter.c : C bindings version of bpWriter.cpp * * Created on: Aug 8, 2017 * Author: William F Godoy godoywf@ornl.gov @@ -68,6 +68,7 @@ int main(int argc, char *argv[]) adios2_adios *adios = adios2_init_serial(); #endif + adios2_step_status err; check_handler(adios, "adios"); adios2_io *io = adios2_declare_io(adios, "BPFile_Write"); @@ -83,17 +84,20 @@ int main(int argc, char *argv[]) size_t count[1]; count[0] = Nx; - adios2_variable *variable = - adios2_define_variable(io, "bpFloats", adios2_type_float, 1, shape, - start, count, adios2_constant_dims_true); + adios2_variable *variable = adios2_define_variable(io, "bpFloats", adios2_type_float, 1, shape, + start, count, adios2_constant_dims_true); check_handler(variable, "variable"); adios2_engine *engine = adios2_open(io, "myVector_c.bp", adios2_mode_write); check_handler(engine, "engine"); + adios2_begin_step(engine, adios2_step_mode_append, 0.0f, &err); + errio = adios2_put(engine, variable, myFloats, adios2_mode_deferred); check_error(errio); + adios2_end_step(engine); + errio = adios2_close(engine); check_error(errio); diff --git a/examples/hello/bpWriter/helloBPWriter.cpp b/examples/hello/bpWriter/bpWriter.cpp similarity index 89% rename from examples/hello/bpWriter/helloBPWriter.cpp rename to examples/hello/bpWriter/bpWriter.cpp index 39043656bd..6afd440791 100644 --- a/examples/hello/bpWriter/helloBPWriter.cpp +++ b/examples/hello/bpWriter/bpWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloBPWriter.cpp: Simple self-descriptive example of how to write a variable + * bpWriter.cpp: Simple self-descriptive example of how to write a variable * to a BP File that lives in several MPI processes. * * Created on: Feb 16, 2017 @@ -39,8 +39,7 @@ int main(int argc, char *argv[]) std::vector myInts = {0, -1, -2, -3, -4, -5, -6, -7, -8, -9}; const std::size_t Nx = myFloats.size(); - const std::string myString("Hello Variable String from rank " + - std::to_string(rank)); + const std::string myString("Hello Variable String from rank " + std::to_string(rank)); try { @@ -61,11 +60,10 @@ int main(int argc, char *argv[]) adios2::Variable bpFloats = bpIO.DefineVariable( "bpFloats", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); - adios2::Variable bpInts = bpIO.DefineVariable( - "bpInts", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); + adios2::Variable bpInts = bpIO.DefineVariable("bpInts", {size * Nx}, {rank * Nx}, + {Nx}, adios2::ConstantDims); - adios2::Variable bpString = - bpIO.DefineVariable("bpString"); + adios2::Variable bpString = bpIO.DefineVariable("bpString"); (void)bpString; // For the sake of the example we create an unused // variable @@ -73,10 +71,12 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine bpFileWriter = bpIO.Open(filename, adios2::Mode::Write); + bpFileWriter.BeginStep(); /** Put variables for buffering, template type is optional */ bpFileWriter.Put(bpFloats, myFloats.data()); bpFileWriter.Put(bpInts, myInts.data()); // bpFileWriter.Put(bpString, myString); + bpFileWriter.EndStep(); /** Create bp file, engine becomes unreachable after this*/ bpFileWriter.Close(); diff --git a/examples/hello/bpWriter/helloBPWriter.py b/examples/hello/bpWriter/bpWriter.py similarity index 70% rename from examples/hello/bpWriter/helloBPWriter.py rename to examples/hello/bpWriter/bpWriter.py index ce29de2f0e..fe2272112b 100644 --- a/examples/hello/bpWriter/helloBPWriter.py +++ b/examples/hello/bpWriter/bpWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPWriter_nompi.py : only works with non MPI version +# bpWriter.py : only works with MPI version # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov from mpi4py import MPI @@ -15,7 +15,7 @@ size = comm.Get_size() # User data -myArray = numpy.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.]) +myArray = numpy.array([0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) Nx = myArray.size # ADIOS MPI Communicator @@ -23,22 +23,25 @@ # ADIOS IO bpIO = adios.DeclareIO("BPFile_N2N") -bpIO.SetEngine('bp3') +bpIO.SetEngine("BPFile") # bpIO.SetParameters( {"Threads" : "2", "ProfileUnits" : "Microseconds", # "InitialBufferSize" : "17Kb"} ) bpIOParams = {} -bpIOParams['Threads'] = '2' -bpIOParams['ProfileUnits'] = 'Microseconds' -bpIOParams['InitialBufferSize'] = '17Kb' +bpIOParams["Threads"] = "2" +bpIOParams["ProfileUnits"] = "Microseconds" +bpIOParams["InitialBufferSize"] = "17Kb" bpIO.SetParameters(bpIOParams) -fileID = bpIO.AddTransport('File', {'Library': 'fstream'}) +fileID = bpIO.AddTransport("File", {"Library": "fstream"}) # ADIOS Variable name, shape, start, offset, constant dims ioArray = bpIO.DefineVariable( - "bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims) + "bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims +) # ADIOS Engine bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write) +bpFileWriter.BeginStep() bpFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) +bpFileWriter.EndStep() bpFileWriter.Close() diff --git a/examples/hello/bpWriter/helloBPWriter_nompi.py b/examples/hello/bpWriter/bpWriter_nompi.py similarity index 67% rename from examples/hello/bpWriter/helloBPWriter_nompi.py rename to examples/hello/bpWriter/bpWriter_nompi.py index 9428808fa0..1de8ce4dd6 100644 --- a/examples/hello/bpWriter/helloBPWriter_nompi.py +++ b/examples/hello/bpWriter/bpWriter_nompi.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloBPWriter.py : only works with MPI version +# bpWriter_nonmpi.py : only works with non MPI version # Created on: Feb 2, 2017 # Author: William F Godoy godoywf@ornl.gov @@ -10,7 +10,7 @@ import adios2 # User data -myArray = numpy.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.]) +myArray = numpy.array([0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) Nx = myArray.size # adios @@ -20,10 +20,11 @@ bpIO = adios.DeclareIO("BPFile_N2N") # ADIOS Variable name, shape, start, offset, constant dims -ioArray = bpIO.DefineVariable( - "bpArray", myArray, [], [], [Nx], adios2.ConstantDims) +ioArray = bpIO.DefineVariable("bpArray", myArray, [], [], [Nx], adios2.ConstantDims) # ADIOS Engine bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write) +bpFileWriter.BeginStep() bpFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) +bpFileWriter.EndStep() bpFileWriter.Close() diff --git a/examples/hello/datamanReader/CMakeLists.txt b/examples/hello/datamanReader/CMakeLists.txt index 56a6139009..656bacefac 100644 --- a/examples/hello/datamanReader/CMakeLists.txt +++ b/examples/hello/datamanReader/CMakeLists.txt @@ -3,8 +3,28 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -if(ADIOS2_HAVE_MPI) - add_executable(hello_datamanReader helloDataManReader.cpp) - target_link_libraries(hello_datamanReader adios2::cxx11_mpi MPI::MPI_C) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataManReaderExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ZeroMQ 4.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) + add_executable(adios2_hello_datamanReader dataManReader.cpp) + target_link_libraries(adios2_hello_datamanReader adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_datamanReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/datamanReader/helloDataManReader.cpp b/examples/hello/datamanReader/dataManReader.cpp similarity index 85% rename from examples/hello/datamanReader/helloDataManReader.cpp rename to examples/hello/datamanReader/dataManReader.cpp index cbf4716cd6..2bc58495b2 100644 --- a/examples/hello/datamanReader/helloDataManReader.cpp +++ b/examples/hello/datamanReader/dataManReader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataManReader.cpp + * dataManReader.cpp * * Created on: Jan 9, 2017 * Author: Jason Wang @@ -43,8 +43,7 @@ int main(int argc, char *argv[]) adios2::ADIOS adios(MPI_COMM_WORLD); adios2::IO io = adios.DeclareIO("whatever"); io.SetEngine("DataMan"); - io.SetParameters( - {{"IPAddress", "127.0.0.1"}, {"Port", "12306"}, {"Timeout", "5"}}); + io.SetParameters({{"IPAddress", "127.0.0.1"}, {"Port", "12306"}, {"Timeout", "5"}}); // open stream adios2::Engine engine = io.Open("HelloDataMan", adios2::Mode::Read); @@ -61,11 +60,10 @@ int main(int argc, char *argv[]) { floatArrayVar = io.InquireVariable("FloatArray"); auto shape = floatArrayVar.Shape(); - size_t datasize = std::accumulate(shape.begin(), shape.end(), 1, - std::multiplies()); + size_t datasize = + std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); floatVector.resize(datasize); - engine.Get(floatArrayVar, floatVector.data(), - adios2::Mode::Sync); + engine.Get(floatArrayVar, floatVector.data(), adios2::Mode::Sync); engine.EndStep(); PrintData(floatVector, engine.CurrentStep()); } diff --git a/examples/hello/datamanReader/helloDataManReader.py b/examples/hello/datamanReader/dataManReader.py similarity index 92% rename from examples/hello/datamanReader/helloDataManReader.py rename to examples/hello/datamanReader/dataManReader.py index 87248b6a64..c773e84fb8 100644 --- a/examples/hello/datamanReader/helloDataManReader.py +++ b/examples/hello/datamanReader/dataManReader.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloDataManReader.py +# dataManReader.py # # Created on: Sept 5, 2019 # Author: Jason Wang @@ -21,7 +21,7 @@ io.SetEngine("DataMan") io.SetParameters({"IPAddress": "127.0.0.1", "Port": "12306", "Timeout": "5"}) -engine = io.Open('HelloDataMan', adios2.Mode.Read, comm) +engine = io.Open("HelloDataMan", adios2.Mode.Read, comm) while True: stepStatus = engine.BeginStep() diff --git a/examples/hello/datamanWriter/CMakeLists.txt b/examples/hello/datamanWriter/CMakeLists.txt index 7c500d6e12..0bc0789ac6 100644 --- a/examples/hello/datamanWriter/CMakeLists.txt +++ b/examples/hello/datamanWriter/CMakeLists.txt @@ -3,7 +3,27 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -if(ADIOS2_HAVE_MPI) - add_executable(hello_datamanWriter helloDataManWriter.cpp) - target_link_libraries(hello_datamanWriter adios2::cxx11_mpi MPI::MPI_C) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataManWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ZeroMQ 4.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_DataMan) + add_executable(adios2_hello_datamanWriter dataManWriter.cpp) + target_link_libraries(adios2_hello_datamanWriter adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_datamanWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/datamanWriter/helloDataManWriter.cpp b/examples/hello/datamanWriter/dataManWriter.cpp similarity index 92% rename from examples/hello/datamanWriter/helloDataManWriter.cpp rename to examples/hello/datamanWriter/dataManWriter.cpp index b5115601b0..fc106c2bb3 100644 --- a/examples/hello/datamanWriter/helloDataManWriter.cpp +++ b/examples/hello/datamanWriter/dataManWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataManWriter.cpp + * dataManWriter.cpp * * Created on: Feb 16, 2017 * Author: Jason Wang @@ -38,8 +38,7 @@ void PrintData(std::vector &data, const size_t step) template std::vector GenerateData(const size_t step) { - size_t datasize = std::accumulate(count.begin(), count.end(), 1, - std::multiplies()); + size_t datasize = std::accumulate(count.begin(), count.end(), 1, std::multiplies()); std::vector myVec(datasize); for (size_t i = 0; i < datasize; ++i) { @@ -76,8 +75,7 @@ int main(int argc, char *argv[]) adios2::Engine engine = io.Open("HelloDataMan", adios2::Mode::Write); // define variable - auto floatArrayVar = - io.DefineVariable("FloatArray", shape, start, count); + auto floatArrayVar = io.DefineVariable("FloatArray", shape, start, count); // write data for (size_t i = 0; i < steps; ++i) diff --git a/examples/hello/datamanWriter/helloDataManWriter.py b/examples/hello/datamanWriter/dataManWriter.py similarity index 92% rename from examples/hello/datamanWriter/helloDataManWriter.py rename to examples/hello/datamanWriter/dataManWriter.py index e23774cb38..9035d0f42a 100644 --- a/examples/hello/datamanWriter/helloDataManWriter.py +++ b/examples/hello/datamanWriter/dataManWriter.py @@ -2,7 +2,7 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. # -# helloDataManWriter.py +# dataManWriter.py # # Created on: Sept 5, 2019 # Author: Jason Wang @@ -36,9 +36,10 @@ io.SetParameters({"IPAddress": "127.0.0.1", "Port": "12306", "Timeout": "5"}) var = io.DefineVariable( - "FloatArray", floatArray, shape, start, count, adios2.ConstantDims) + "FloatArray", floatArray, shape, start, count, adios2.ConstantDims +) -engine = io.Open('HelloDataMan', adios2.Mode.Write) +engine = io.Open("HelloDataMan", adios2.Mode.Write) for i in range(steps): floatArray = floatArray + 1 diff --git a/examples/hello/dataspacesReader/CMakeLists.txt b/examples/hello/dataspacesReader/CMakeLists.txt index 7136868362..11e8e3ff13 100644 --- a/examples/hello/dataspacesReader/CMakeLists.txt +++ b/examples/hello/dataspacesReader/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_dataSpacesReader helloDataSpacesReader.cpp) -target_link_libraries(hello_dataSpacesReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataSpacesReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_dataSpacesReader_mpi helloDataSpacesReader.cpp) - target_link_libraries(hello_dataSpacesReader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(DataSpaces 2.1.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_DataSpaces) + add_executable(adios2_hello_dataSpacesReader dataSpacesReader.cpp) + target_link_libraries(adios2_hello_dataSpacesReader adios2::cxx11) + install(TARGETS adios2_hello_dataSpacesReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_dataSpacesReader_mpi dataSpacesReader.cpp) + target_link_libraries(adios2_hello_dataSpacesReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_dataSpacesReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/dataspacesReader/helloDataSpacesReader.cpp b/examples/hello/dataspacesReader/dataSpacesReader.cpp similarity index 88% rename from examples/hello/dataspacesReader/helloDataSpacesReader.cpp rename to examples/hello/dataspacesReader/dataSpacesReader.cpp index d2650f0c01..c6f6731432 100644 --- a/examples/hello/dataspacesReader/helloDataSpacesReader.cpp +++ b/examples/hello/dataspacesReader/dataSpacesReader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataSpacesReader.cpp + * dataSpacesReader.cpp * * Created on: Feb 06, 2019 * Author: Pradeep Subedi @@ -52,13 +52,10 @@ int main(int argc, char *argv[]) adios2::IO dataSpacesIO = adios.DeclareIO("myIO"); dataSpacesIO.SetEngine("DATASPACES"); - adios2::Engine dataSpacesReader = - dataSpacesIO.Open("helloDataSpaces", adios2::Mode::Read); + adios2::Engine dataSpacesReader = dataSpacesIO.Open("helloDataSpaces", adios2::Mode::Read); dataSpacesReader.BeginStep(); - adios2::Variable bpFloats = - dataSpacesIO.InquireVariable("bpFloats"); - std::cout << "Incoming variable is of size " << bpFloats.Shape()[0] - << "\n"; + adios2::Variable bpFloats = dataSpacesIO.InquireVariable("bpFloats"); + std::cout << "Incoming variable is of size " << bpFloats.Shape()[0] << "\n"; const std::size_t total_size = bpFloats.Shape()[0]; const std::size_t my_start = (total_size / size) * rank; const std::size_t my_count = (total_size / size); @@ -81,8 +78,7 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/dataspacesWriter/CMakeLists.txt b/examples/hello/dataspacesWriter/CMakeLists.txt index 6518c8c24b..32a1bb4673 100644 --- a/examples/hello/dataspacesWriter/CMakeLists.txt +++ b/examples/hello/dataspacesWriter/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_dataSpacesWriter helloDataSpacesWriter.cpp) -target_link_libraries(hello_dataSpacesWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloDataSpacesWriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_dataSpacesWriter_mpi helloDataSpacesWriter.cpp) - target_link_libraries(hello_dataSpacesWriter_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(DataSpaces 2.1.1 QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_DataSpaces) + add_executable(adios2_hello_dataSpacesWriter dataSpacesWriter.cpp) + target_link_libraries(adios2_hello_dataSpacesWriter adios2::cxx11) + install(TARGETS adios2_hello_dataSpacesWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_dataSpacesWriter_mpi dataSpacesWriter.cpp) + target_link_libraries(adios2_hello_dataSpacesWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_dataSpacesWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp b/examples/hello/dataspacesWriter/dataSpacesWriter.cpp similarity index 69% rename from examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp rename to examples/hello/dataspacesWriter/dataSpacesWriter.cpp index 888ab7016d..9c9e23b466 100644 --- a/examples/hello/dataspacesWriter/helloDataSpacesWriter.cpp +++ b/examples/hello/dataspacesWriter/dataSpacesWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloDataSpacesWriter.cpp + * dataSpacesWriter.cpp * * Created on: Feb 06, 2019 * Author: Pradeep Subedi @@ -36,11 +36,11 @@ int main(int argc, char *argv[]) size = 1; #endif - std::vector myFloats = { - (float)10.0 * rank + 0, (float)10.0 * rank + 1, (float)10.0 * rank + 2, - (float)10.0 * rank + 3, (float)10.0 * rank + 4, (float)10.0 * rank + 5, - (float)10.0 * rank + 6, (float)10.0 * rank + 7, (float)10.0 * rank + 8, - (float)10.0 * rank + 9}; + std::vector myFloats = {(float)10.0 * rank + 0, (float)10.0 * rank + 1, + (float)10.0 * rank + 2, (float)10.0 * rank + 3, + (float)10.0 * rank + 4, (float)10.0 * rank + 5, + (float)10.0 * rank + 6, (float)10.0 * rank + 7, + (float)10.0 * rank + 8, (float)10.0 * rank + 9}; const std::size_t Nx = myFloats.size(); try @@ -54,13 +54,12 @@ int main(int argc, char *argv[]) dataSpacesIO.SetEngine("DATASPACES"); // Define variable and local size - auto bpFloats = dataSpacesIO.DefineVariable( - "bpFloats", {size * Nx}, {rank * Nx}, {Nx}); + auto bpFloats = + dataSpacesIO.DefineVariable("bpFloats", {size * Nx}, {rank * Nx}, {Nx}); // Create engine smart pointer to Sst Engine due to polymorphism, // Open returns a smart pointer to Engine containing the Derived class - adios2::Engine dataSpacesWriter = - dataSpacesIO.Open("helloDataSpaces", adios2::Mode::Write); + adios2::Engine dataSpacesWriter = dataSpacesIO.Open("helloDataSpaces", adios2::Mode::Write); dataSpacesWriter.BeginStep(); dataSpacesWriter.Put(bpFloats, myFloats.data()); @@ -69,15 +68,13 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/hdf5Reader/CMakeLists.txt b/examples/hello/hdf5Reader/CMakeLists.txt index 2dd4227cf9..ebfcb9ad7b 100644 --- a/examples/hello/hdf5Reader/CMakeLists.txt +++ b/examples/hello/hdf5Reader/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_hdf5Reader helloHDF5Reader_nompi.cpp) -target_link_libraries(hello_hdf5Reader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHDF5ReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_hdf5Reader_mpi helloHDF5Reader.cpp) - target_link_libraries(hello_hdf5Reader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_HDF5) + add_executable(adios2_hello_hdf5Reader hdf5Reader_nompi.cpp) + target_link_libraries(adios2_hello_hdf5Reader adios2::cxx11) + install(TARGETS adios2_hello_hdf5Reader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_hdf5Reader_mpi hdf5Reader.cpp) + target_link_libraries(adios2_hello_hdf5Reader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Reader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/hdf5Reader/helloHDF5Reader.cpp b/examples/hello/hdf5Reader/hdf5Reader.cpp similarity index 91% rename from examples/hello/hdf5Reader/helloHDF5Reader.cpp rename to examples/hello/hdf5Reader/hdf5Reader.cpp index bc3b827f8d..fd15a3d631 100644 --- a/examples/hello/hdf5Reader/helloHDF5Reader.cpp +++ b/examples/hello/hdf5Reader/hdf5Reader.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Reader.cpp + * hdf5Reader.cpp * * Created on: Jan 24, 2018 * Author: Junmin Gu @@ -17,16 +17,15 @@ #include template -void ReadData(adios2::IO h5IO, adios2::Engine &h5Reader, - const std::string &name) +void ReadData(adios2::IO h5IO, adios2::Engine &h5Reader, const std::string &name) { adios2::Variable var = h5IO.InquireVariable(name); if (var) { - int nDims = var.Shape().size(); + size_t nDims = var.Shape().size(); size_t totalSize = 1; - for (int i = 0; i < nDims; i++) + for (size_t i = 0; i < nDims; i++) { totalSize *= var.Shape()[i]; } @@ -100,8 +99,9 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine h5Reader = h5IO.Open(filename, adios2::Mode::Read); - const std::map variables = - h5IO.AvailableVariables(); + h5Reader.BeginStep(); + + const std::map variables = h5IO.AvailableVariables(); for (const auto &variablePair : variables) { @@ -110,8 +110,7 @@ int main(int argc, char *argv[]) for (const auto ¶meter : variablePair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; if (parameter.second == "double") { ReadData(h5IO, h5Reader, variablePair.first); @@ -132,8 +131,7 @@ int main(int argc, char *argv[]) } } - const std::map attributes = - h5IO.AvailableAttributes(); + const std::map attributes = h5IO.AvailableAttributes(); for (const auto &attrPair : attributes) { @@ -142,8 +140,7 @@ int main(int argc, char *argv[]) for (const auto ¶meter : attrPair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; if (parameter.second == "double") { // ReadData(h5IO, h5Reader, variablePair.first); @@ -164,13 +161,13 @@ int main(int argc, char *argv[]) //... add more types if needed } } + h5Reader.EndStep(); h5Reader.Close(); } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp b/examples/hello/hdf5Reader/hdf5Reader_nompi.cpp similarity index 93% rename from examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp rename to examples/hello/hdf5Reader/hdf5Reader_nompi.cpp index 9aab7f8b5f..967039a750 100644 --- a/examples/hello/hdf5Reader/helloHDF5Reader_nompi.cpp +++ b/examples/hello/hdf5Reader/hdf5Reader_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Reader.cpp + * hdf5Reader.cpp * * Created on: Jan 24, 2018 * Author: Junmin Gu @@ -22,9 +22,9 @@ void ReadData(adios2::IO h5IO, adios2::Engine h5Reader, const std::string &name) if (var) { - int nDims = var.Shape().size(); + size_t nDims = var.Shape().size(); size_t totalSize = 1; - for (int i = 0; i < nDims; i++) + for (size_t i = 0; i < nDims; i++) { totalSize *= var.Shape()[i]; } @@ -90,8 +90,9 @@ int main(int argc, char *argv[]) /** Engine derived class, spawned to start IO operations */ adios2::Engine h5Reader = h5IO.Open(filename, adios2::Mode::Read); - const std::map variables = - h5IO.AvailableVariables(); + h5Reader.BeginStep(); + + const std::map variables = h5IO.AvailableVariables(); for (const auto &variablePair : variables) { @@ -100,8 +101,7 @@ int main(int argc, char *argv[]) for (const auto ¶meter : variablePair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; if (parameter.second == "double") { ReadData(h5IO, h5Reader, variablePair.first); @@ -125,6 +125,8 @@ int main(int argc, char *argv[]) // ReadData(h5IO, h5Reader, "h5Floats"); // ReadData(h5IO, h5Reader, "h5Ints"); + h5Reader.EndStep(); + /** Close h5 file, engine becomes unreachable after this*/ h5Reader.Close(); } diff --git a/examples/hello/hdf5SubFile/CMakeLists.txt b/examples/hello/hdf5SubFile/CMakeLists.txt new file mode 100644 index 0000000000..81e494fa1b --- /dev/null +++ b/examples/hello/hdf5SubFile/CMakeLists.txt @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(HelloHDF5SubFileExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_HDF5 AND HDF5_VERSION VERSION_GREATER_EQUAL 1.14) + add_executable(adios2_hello_hdf5Subfile hdf5SubFile.cpp) + target_link_libraries(adios2_hello_hdf5Subfile adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Subfile RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + diff --git a/examples/h5subfile/h5_subfile.cpp b/examples/hello/hdf5SubFile/hdf5SubFile.cpp similarity index 86% rename from examples/h5subfile/h5_subfile.cpp rename to examples/hello/hdf5SubFile/hdf5SubFile.cpp index a980f0dbc8..a018267b1a 100644 --- a/examples/h5subfile/h5_subfile.cpp +++ b/examples/hello/hdf5SubFile/hdf5SubFile.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer.cpp: Simple self-descriptive example of how to write a + * hdf5SubFile.cpp: Simple self-descriptive example of how to write a * variable to a parallel HDF5 File using MPI processes. * * Created on: March 6, 2023 @@ -41,12 +41,10 @@ void writeMe(adios2::IO &hdf5IO, int rank, int size, const char *testFileName) "true"); // set this if not all ranks are writting adios2::Variable h5Floats = hdf5IO.DefineVariable( - "h5Floats", {size * Nx, Ny}, {rank * Nx, 0}, {Nx, Ny}, - adios2::ConstantDims); + "h5Floats", {size * Nx, Ny}, {rank * Nx, 0}, {Nx, Ny}, adios2::ConstantDims); - adios2::Variable h5Ints = - hdf5IO.DefineVariable("h5Ints", {size * Nx, Ny}, {rank * Nx, 0}, - {Nx, Ny}, adios2::ConstantDims); + adios2::Variable h5Ints = hdf5IO.DefineVariable( + "h5Ints", {size * Nx, Ny}, {rank * Nx, 0}, {Nx, Ny}, adios2::ConstantDims); /** Engine derived class, spawned to start IO operations */ adios2::Engine hdf5Writer = hdf5IO.Open(testFileName, adios2::Mode::Write); @@ -87,23 +85,17 @@ void writeMe(adios2::IO &hdf5IO, int rank, int size, const char *testFileName) hdf5IO.DefineAttribute("adios2_schema/version_minor", std::to_string(ADIOS2_VERSION_MINOR)); hdf5IO.DefineAttribute("/adios2_schema/mesh/type", "explicit"); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension0", - m_globalDims[0]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension1", - m_globalDims[1]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension2", - m_globalDims[2]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension3", - m_globalDims[3]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension-num", - m_globalDims.size()); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension0", m_globalDims[0]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension1", m_globalDims[1]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension2", m_globalDims[2]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension3", m_globalDims[3]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension-num", m_globalDims.size()); hdf5Writer.Close(); } template -void ReadVarData(adios2::IO h5IO, adios2::Engine &h5Reader, - const std::string &name) +void ReadVarData(adios2::IO h5IO, adios2::Engine &h5Reader, const std::string &name) { adios2::Variable var = h5IO.InquireVariable(name); @@ -154,8 +146,7 @@ void readMe(adios2::IO &h5IO, int rank, int size, const char *fileName) /** Engine derived class, spawned to start IO operations */ adios2::Engine h5Reader = h5IO.Open(fileName, adios2::Mode::Read); - const std::map variables = - h5IO.AvailableVariables(); + const std::map variables = h5IO.AvailableVariables(); if (0 == rank) std::cout << " Num Vars: " << variables.size() << std::endl; @@ -167,8 +158,7 @@ void readMe(adios2::IO &h5IO, int rank, int size, const char *fileName) for (const auto ¶meter : variablePair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; if (parameter.second == "double") { ReadVarData(h5IO, h5Reader, variablePair.first); @@ -188,8 +178,7 @@ void readMe(adios2::IO &h5IO, int rank, int size, const char *fileName) } } // variables - const std::map attributes = - h5IO.AvailableAttributes(); + const std::map attributes = h5IO.AvailableAttributes(); if (0 == rank) std::cout << "Num Attrs:" << attributes.size() << std::endl; @@ -201,8 +190,7 @@ void readMe(adios2::IO &h5IO, int rank, int size, const char *fileName) for (const auto ¶meter : attrPair.second) { - std::cout << "\t" << parameter.first << ": " << parameter.second - << "\n"; + std::cout << "\t" << parameter.first << ": " << parameter.second << "\n"; if (parameter.second == "double") { @@ -277,15 +265,13 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/hdf5Writer/CMakeLists.txt b/examples/hello/hdf5Writer/CMakeLists.txt index 934fbb4cfb..b1fd2bcdcf 100644 --- a/examples/hello/hdf5Writer/CMakeLists.txt +++ b/examples/hello/hdf5Writer/CMakeLists.txt @@ -3,10 +3,33 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_hdf5Writer helloHDF5Writer_nompi.cpp) -target_link_libraries(hello_hdf5Writer adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHDF5WriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_hdf5Writer_mpi helloHDF5Writer.cpp) - target_link_libraries(hello_hdf5Writer_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(HDF5 QUIET COMPONENTS C) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_HDF5) + add_executable(adios2_hello_hdf5Writer hdf5Writer_nompi.cpp) + target_link_libraries(adios2_hello_hdf5Writer adios2::cxx11) + install(TARGETS adios2_hello_hdf5Writer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_hdf5Writer_mpi hdf5Writer.cpp) + target_link_libraries(adios2_hello_hdf5Writer_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_hdf5Writer_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/hdf5Writer.cpp similarity index 76% rename from examples/hello/hdf5Writer/helloHDF5Writer.cpp rename to examples/hello/hdf5Writer/hdf5Writer.cpp index 1035195ccf..3e09334593 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/hdf5Writer.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer.cpp: Simple self-descriptive example of how to write a + * hdf5Writer.cpp: Simple self-descriptive example of how to write a * variable to a parallel HDF5 File using MPI processes. * * Created on: March 20, 2017 @@ -53,11 +53,9 @@ int main(int argc, char *argv[]) adios2::Variable h5Ints = hdf5IO.DefineVariable( "h5Ints", {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); - adios2::Variable h5ScalarDouble = - hdf5IO.DefineVariable("h5ScalarDouble"); + adios2::Variable h5ScalarDouble = hdf5IO.DefineVariable("h5ScalarDouble"); /** Engine derived class, spawned to start IO operations */ - adios2::Engine hdf5Writer = - hdf5IO.Open("myVector.h5", adios2::Mode::Write); + adios2::Engine hdf5Writer = hdf5IO.Open("myVector.h5", adios2::Mode::Write); #ifdef ALL_RANKS_WRITE // all Ranks must call Put /** Write variable for buffering */ @@ -78,22 +76,15 @@ int main(int argc, char *argv[]) hdf5Writer.EndStep(); #endif std::vector m_globalDims = {10, 20, 30, 40}; - hdf5IO.DefineAttribute( - "adios2_schema/version_major", - std::to_string(ADIOS2_VERSION_MAJOR)); - hdf5IO.DefineAttribute( - "adios2_schema/version_minor", - std::to_string(ADIOS2_VERSION_MINOR)); - hdf5IO.DefineAttribute("/adios2_schema/mesh/type", - "explicit"); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension0", - m_globalDims[0]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension1", - m_globalDims[1]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension2", - m_globalDims[2]); - hdf5IO.DefineAttribute("adios2_schema/mesh/dimension3", - m_globalDims[3]); + hdf5IO.DefineAttribute("adios2_schema/version_major", + std::to_string(ADIOS2_VERSION_MAJOR)); + hdf5IO.DefineAttribute("adios2_schema/version_minor", + std::to_string(ADIOS2_VERSION_MINOR)); + hdf5IO.DefineAttribute("/adios2_schema/mesh/type", "explicit"); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension0", m_globalDims[0]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension1", m_globalDims[1]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension2", m_globalDims[2]); + hdf5IO.DefineAttribute("adios2_schema/mesh/dimension3", m_globalDims[3]); hdf5IO.DefineAttribute("adios2_schema/mesh/dimension-num", m_globalDims.size()); @@ -101,15 +92,13 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp b/examples/hello/hdf5Writer/hdf5Writer_nompi.cpp similarity index 83% rename from examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp rename to examples/hello/hdf5Writer/hdf5Writer_nompi.cpp index e435648293..a1fa27ef18 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp +++ b/examples/hello/hdf5Writer/hdf5Writer_nompi.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloHDF5Writer_nompi.cpp no mpi version of helloHDF5Writer.cpp + * hdf5Writer_nompi.cpp no mpi version of helloHDF5Writer.cpp * * Created on: March 20, 2017 * Author: Junmin @@ -33,16 +33,19 @@ int main(int argc, char *argv[]) /** global array : name, { shape (total) }, { start (local) }, { count * (local) }, all are constant dimensions */ - adios2::Variable bpFloats = hdf5IO.DefineVariable( - "bpFloats", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable bpFloats = + hdf5IO.DefineVariable("bpFloats", {}, {}, {Nx}, adios2::ConstantDims); /** Engine derived class, spawned to start IO operations */ - adios2::Engine hdf5Writer = - hdf5IO.Open("myVector.h5", adios2::Mode::Write); + adios2::Engine hdf5Writer = hdf5IO.Open("myVector.h5", adios2::Mode::Write); + + hdf5Writer.BeginStep(); /** Write variable for buffering */ hdf5Writer.Put(bpFloats, myFloats.data()); + hdf5Writer.EndStep(); + /** Create bp file, engine becomes unreachable after this*/ hdf5Writer.Close(); } diff --git a/examples/hello/helloWorld/CMakeLists.txt b/examples/hello/helloWorld/CMakeLists.txt new file mode 100644 index 0000000000..416d0d5b26 --- /dev/null +++ b/examples/hello/helloWorld/CMakeLists.txt @@ -0,0 +1,47 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloHelloWorldExample) + +if(NOT TARGET adios2_core) + set(_components C CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_helloWorld_c hello-world.c) +target_link_libraries(adios2_hello_helloWorld_c adios2::c) +install(TARGETS adios2_hello_helloWorld_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_helloWorld hello-world.cpp) +target_link_libraries(adios2_hello_helloWorld adios2::cxx11) +install(TARGETS adios2_hello_helloWorld RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_helloWorld_hl hello-world-hl.cpp) +target_link_libraries(adios2_hello_helloWorld_hl adios2::cxx11) +install(TARGETS adios2_hello_helloWorld_hl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_helloWorld_c_mpi hello-world.c) + target_link_libraries(adios2_hello_helloWorld_c_mpi adios2::c_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_c_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_helloWorld_mpi hello-world.cpp) + target_link_libraries(adios2_hello_helloWorld_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_helloWorld_hl_mpi hello-world-hl.cpp) + target_link_libraries(adios2_hello_helloWorld_hl_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_helloWorld_hl_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/helloWorld/hello-world-hl.cpp b/examples/hello/helloWorld/hello-world-hl.cpp new file mode 100644 index 0000000000..d1a4f2c05f --- /dev/null +++ b/examples/hello/helloWorld/hello-world-hl.cpp @@ -0,0 +1,75 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world-hl.cpp : adios2 high-level API example to write and read a + * std::string Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include +#include + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(const std::string &greeting) +{ +#if ADIOS2_USE_MPI + adios2::fstream out("hello-world-hl-cpp.bp", adios2::fstream::out, MPI_COMM_WORLD); +#else + adios2::fstream out("hello-world-hl-cpp.bp", adios2::fstream::out); +#endif + + out.write("Greeting", greeting); + out.close(); +} + +std::string reader() +{ +#if ADIOS2_USE_MPI + adios2::fstream in("hello-world-hl-cpp.bp", adios2::fstream::in, MPI_COMM_WORLD); +#else + adios2::fstream in("hello-world-hl-cpp.bp", adios2::fstream::in); +#endif + + for (adios2::fstep iStep; adios2::getstep(in, iStep);) + { + const std::vector greetings = in.read("Greeting"); + return greetings.front(); + } + return ""; +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + try + { + const std::string greeting = "Hello World from ADIOS2"; + writer(greeting); + + const std::string message = reader(); + std::cout << message << "\n"; + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world-hl.py b/examples/hello/helloWorld/hello-world-hl.py new file mode 100644 index 0000000000..825fb5282e --- /dev/null +++ b/examples/hello/helloWorld/hello-world-hl.py @@ -0,0 +1,47 @@ +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# hello-world.py : adios2 high-level API example to write and read a +# string Variable with a greeting +# +# Created on: 2/2/2021 +# Author: Dmitry Ganyushin ganyushindi@ornl.gov +# +import sys +from mpi4py import MPI +import adios2 + +DATA_FILENAME = "hello-world-hl-py.bp" +# MPI +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + + +def writer(greeting): + """write a string to a bp file""" + with adios2.open(DATA_FILENAME, "w", comm) as fh: + fh.write("Greeting", greeting, end_step=True) + return 0 + + +def reader(): + """read a string from to a bp file""" + with adios2.open(DATA_FILENAME, "r", comm) as fh: + for fstep in fh: + message = fstep.read_string("Greeting") + return message + + +def main(): + """driver function""" + greeting = "Hello World from ADIOS2" + writer(greeting) + message = reader() + print("{}".format(message)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/hello/helloWorld/hello-world.c b/examples/hello/helloWorld/hello-world.c new file mode 100644 index 0000000000..d1ea152e5e --- /dev/null +++ b/examples/hello/helloWorld/hello-world.c @@ -0,0 +1,74 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world.c : adios2 C API example to write and read a + * char* Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include //printf +#include //malloc, free + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2_adios *adios, const char *greeting) +{ + adios2_step_status status; + adios2_io *io = adios2_declare_io(adios, "hello-world-writer"); + adios2_variable *var_greeting = adios2_define_variable( + io, "Greeting", adios2_type_string, 0, NULL, NULL, NULL, adios2_constant_dims_true); + + adios2_engine *engine = adios2_open(io, "hello-world-c.bp", adios2_mode_write); + adios2_begin_step(engine, adios2_step_mode_append, -1., &status); + adios2_put(engine, var_greeting, greeting, adios2_mode_deferred); + adios2_end_step(engine); + adios2_close(engine); +} + +void reader(adios2_adios *adios, char *greeting) +{ + adios2_step_status status; + adios2_io *io = adios2_declare_io(adios, "hello-world-reader"); + adios2_engine *engine = adios2_open(io, "hello-world-c.bp", adios2_mode_read); + adios2_variable *var_greeting = adios2_inquire_variable(io, "Greeting"); + adios2_begin_step(engine, adios2_step_mode_read, -1., &status); + adios2_get(engine, var_greeting, greeting, adios2_mode_deferred); + adios2_end_step(engine); + adios2_close(engine); +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + { +#if ADIOS2_USE_MPI + adios2_adios *adios = adios2_init_mpi(MPI_COMM_WORLD); +#else + adios2_adios *adios = adios2_init(); +#endif + + const char greeting[] = "Hello World from ADIOS2"; + writer(adios, greeting); + + char *message = (char *)malloc(24); + reader(adios, message); + printf("%s\n", message); + + free(message); + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world.cpp b/examples/hello/helloWorld/hello-world.cpp new file mode 100644 index 0000000000..722f70a868 --- /dev/null +++ b/examples/hello/helloWorld/hello-world.cpp @@ -0,0 +1,78 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * hello-world.cpp : adios2 low-level API example to write and read a + * std::string Variable with a greeting + * + * Created on: Nov 14, 2019 + * Author: William F Godoy godoywf@ornl.gov + */ + +#include +#include + +#include +#if ADIOS2_USE_MPI +#include +#endif + +void writer(adios2::ADIOS &adios, const std::string &greeting) +{ + adios2::IO io = adios.DeclareIO("hello-world-writer"); + adios2::Variable varGreeting = io.DefineVariable("Greeting"); + + adios2::Engine writer = io.Open("hello-world-cpp.bp", adios2::Mode::Write); + writer.BeginStep(); + writer.Put(varGreeting, greeting); + writer.EndStep(); + writer.Close(); +} + +std::string reader(adios2::ADIOS &adios) +{ + adios2::IO io = adios.DeclareIO("hello-world-reader"); + adios2::Engine reader = io.Open("hello-world-cpp.bp", adios2::Mode::Read); + reader.BeginStep(); + adios2::Variable varGreeting = io.InquireVariable("Greeting"); + std::string greeting; + reader.Get(varGreeting, greeting); + reader.EndStep(); + reader.Close(); + return greeting; +} + +int main(int argc, char *argv[]) +{ +#if ADIOS2_USE_MPI + MPI_Init(&argc, &argv); +#endif + + try + { +#if ADIOS2_USE_MPI + adios2::ADIOS adios(MPI_COMM_WORLD); +#else + adios2::ADIOS adios; +#endif + + const std::string greeting = "Hello World from ADIOS2"; + writer(adios, greeting); + + const std::string message = reader(adios); + std::cout << message << "\n"; + } + catch (std::exception &e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; +#if ADIOS2_USE_MPI + MPI_Abort(MPI_COMM_WORLD, -1); +#endif + } + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return 0; +} diff --git a/examples/hello/helloWorld/hello-world.py b/examples/hello/helloWorld/hello-world.py new file mode 100644 index 0000000000..e2b3bd7f8d --- /dev/null +++ b/examples/hello/helloWorld/hello-world.py @@ -0,0 +1,56 @@ +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# hello-world.py : adios2 low-level API example to write and read a +# string Variable with a greeting +# +# Created on: 2/2/2021 +# Author: Dmitry Ganyushin ganyushindi@ornl.gov +# +import sys +from mpi4py import MPI +import adios2 + +DATA_FILENAME = "hello-world-py.bp" +# MPI +comm = MPI.COMM_WORLD +rank = comm.Get_rank() +size = comm.Get_size() + + +def writer(ad, greeting): + """write a string to a bp file""" + io = ad.DeclareIO("hello-world-writer") + var_greeting = io.DefineVariable("Greeting") + w = io.Open(DATA_FILENAME, adios2.Mode.Write) + w.BeginStep() + w.Put(var_greeting, greeting) + w.EndStep() + w.Close() + return 0 + + +def reader(ad): + """read a string from to a bp file""" + io = ad.DeclareIO("hello-world-reader") + r = io.Open(DATA_FILENAME, adios2.Mode.Read) + r.BeginStep() + var_greeting = io.InquireVariable("Greeting") + message = r.Get(var_greeting) + r.EndStep() + return message + + +def main(): + """driver function""" + ad = adios2.ADIOS(comm) + greeting = "Hello World from ADIOS2" + writer(ad, greeting) + message = reader(ad) + print("{}".format(message)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/hello/inlineFWriteCppRead/CMakeLists.txt b/examples/hello/inlineFWriteCppRead/CMakeLists.txt index 64b99b539d..ad5cfbd537 100644 --- a/examples/hello/inlineFWriteCppRead/CMakeLists.txt +++ b/examples/hello/inlineFWriteCppRead/CMakeLists.txt @@ -3,17 +3,36 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -include(FortranCInterface) -FortranCInterface_HEADER(InlineExampleFC.h MACRO_NAMESPACE "FC_") -FortranCInterface_VERIFY(CXX QUIET) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloFWriteCppReadExample) -add_library(InlineMixedLangCPP inlineMixedLang.cpp) -target_link_libraries(InlineMixedLangCPP adios2::cxx11) -target_include_directories(InlineMixedLangCPP - PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - ) +if(NOT TARGET adios2_core) + set(_components CXX) -add_executable(InlineMixedLangF inlineMixedLang.f90) -target_link_libraries(InlineMixedLangF adios2::fortran InlineMixedLangCPP) -set_target_properties(InlineMixedLangF PROPERTIES LINKER_LANGUAGE Fortran) + include(CheckLanguage) + check_language(Fortran) + if(CMAKE_Fortran_COMPILER) + enable_language(Fortran) + endif() + if(CMAKE_Fortran_COMPILER_LOADED) + list(APPEND _components Fortran) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Fortran) + include(FortranCInterface) + FortranCInterface_HEADER(InlineExampleFC.h MACRO_NAMESPACE "FC_") + FortranCInterface_VERIFY(CXX QUIET) + + add_library(adios2_hello_inlineMixedLang inlineMixedLang.cpp) + target_link_libraries(adios2_hello_inlineMixedLang adios2::cxx11) + target_include_directories(adios2_hello_inlineMixedLang PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + install(TARGETS adios2_hello_inlineMixedLang RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_hello_inlineMixedLang_f inlineMixedLang.f90) + target_link_libraries(adios2_hello_inlineMixedLang_f adios2_hello_inlineMixedLang adios2::fortran) + set_target_properties(adios2_hello_inlineMixedLang_f PROPERTIES LINKER_LANGUAGE Fortran) + install(TARGETS adios2_hello_inlineMixedLang_f RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/hello/inlineFWriteCppRead/inlineMixedLang.cpp b/examples/hello/inlineFWriteCppRead/inlineMixedLang.cpp index 45765a1503..c7dc5f75b5 100644 --- a/examples/hello/inlineFWriteCppRead/inlineMixedLang.cpp +++ b/examples/hello/inlineFWriteCppRead/inlineMixedLang.cpp @@ -28,6 +28,9 @@ void FC_GLOBAL(open_reader, OPEN_READER)(adios2::IO *io) void FC_GLOBAL(analyze_data, ANALYZE_DATA)() { + // begin step on the reader + reader.BeginStep(); + // grab the desired variable auto u = adiosIO->InquireVariable("data2D"); if (!u) @@ -37,9 +40,6 @@ void FC_GLOBAL(analyze_data, ANALYZE_DATA)() } auto shape = u.Shape(); - // begin step on the reader - reader.BeginStep(); - // get the data pointer and do some stuff with it float *data = nullptr; reader.Get(u, &data); diff --git a/examples/hello/inlineMWE/CMakeLists.txt b/examples/hello/inlineMWE/CMakeLists.txt new file mode 100644 index 0000000000..98ac7fcc70 --- /dev/null +++ b/examples/hello/inlineMWE/CMakeLists.txt @@ -0,0 +1,17 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloInlineMWEExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_inlineMWE inlineMWE.cpp) +target_link_libraries(adios2_hello_inlineMWE adios2::cxx11) +install(TARGETS adios2_hello_inlineMWE RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/inlineMWE/inlineMWE.cpp b/examples/hello/inlineMWE/inlineMWE.cpp similarity index 69% rename from examples/inlineMWE/inlineMWE.cpp rename to examples/hello/inlineMWE/inlineMWE.cpp index 9024e5bd08..cb12a3642b 100644 --- a/examples/inlineMWE/inlineMWE.cpp +++ b/examples/hello/inlineMWE/inlineMWE.cpp @@ -1,3 +1,8 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + #include #include @@ -16,17 +21,17 @@ int main(int argc, char *argv[]) { writer.BeginStep(); std::vector v(N, 3.2); - std::cout << "Putting data at address " << v.data() - << " into inline writer.\n"; + std::cout << "Putting data at address " << v.data() << " into inline writer.\n"; writer.Put(u, v.data()); writer.EndStep(); reader.BeginStep(); double *data = nullptr; reader.Get(u, &data); - std::cout << "Getting data from address " << data - << " via inline reader\n"; + std::cout << "Getting data from address " << data << " via inline reader\n"; reader.EndStep(); } + writer.Close(); + reader.Close(); return 0; } diff --git a/examples/hello/inlineReaderWriter/CMakeLists.txt b/examples/hello/inlineReaderWriter/CMakeLists.txt index 25a8334140..cf76d4d0e6 100644 --- a/examples/hello/inlineReaderWriter/CMakeLists.txt +++ b/examples/hello/inlineReaderWriter/CMakeLists.txt @@ -3,10 +3,29 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_inlineReaderWriter helloInlineReaderWriter.cpp) -target_link_libraries(hello_inlineReaderWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloInlineReaderWriterExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_inlineReaderWriter inlineReaderWriter.cpp) +target_link_libraries(adios2_hello_inlineReaderWriter adios2::cxx11) +install(TARGETS adios2_hello_inlineReaderWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_inlineReaderWriter_mpi helloInlineReaderWriter.cpp) - target_link_libraries(hello_inlineReaderWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_inlineReaderWriter_mpi inlineReaderWriter.cpp) + target_link_libraries(adios2_hello_inlineReaderWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_inlineReaderWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp b/examples/hello/inlineReaderWriter/inlineReaderWriter.cpp similarity index 85% rename from examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp rename to examples/hello/inlineReaderWriter/inlineReaderWriter.cpp index d77679a81d..f7ca536bfc 100644 --- a/examples/hello/inlineReaderWriter/helloInlineReaderWriter.cpp +++ b/examples/hello/inlineReaderWriter/inlineReaderWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloInlineReaderWriter.cpp example borrowed from helloBPTimeWriter, using + * inlineReaderWriter.cpp example borrowed from bpTimeWriter, using * the inline engine. Writes a variable using the Advance function for time * aggregation. Time step is saved as an additional (global) single value * variable, just for tracking purposes. @@ -19,13 +19,11 @@ #include -void DoAnalysis(adios2::IO &inlineIO, adios2::Engine &inlineReader, int rank, - unsigned int step) +void DoAnalysis(adios2::IO &inlineIO, adios2::Engine &inlineReader, int rank, unsigned int step) { inlineReader.BeginStep(); /////////////////////READ - adios2::Variable inlineFloats000 = - inlineIO.InquireVariable("inlineFloats000"); + adios2::Variable inlineFloats000 = inlineIO.InquireVariable("inlineFloats000"); adios2::Variable inlineString = inlineIO.InquireVariable("inlineString"); @@ -34,8 +32,8 @@ void DoAnalysis(adios2::IO &inlineIO, adios2::Engine &inlineReader, int rank, { auto blocksInfo = inlineReader.BlocksInfo(inlineFloats000, step); - std::cout << "Data StepsStart " << inlineFloats000.StepsStart() - << " from rank " << rank << ": "; + std::cout << "Data StepsStart " << inlineFloats000.StepsStart() << " from rank " << rank + << ": "; for (auto &info : blocksInfo) { // bp file reader would see all blocks, inline only sees local @@ -46,8 +44,7 @@ void DoAnalysis(adios2::IO &inlineIO, adios2::Engine &inlineReader, int rank, // info passed by reference // engine must remember data pointer (or info) to fill it out at // PerformGets() - inlineReader.Get(inlineFloats000, info, - adios2::Mode::Deferred); + inlineReader.Get(inlineFloats000, info, adios2::Mode::Deferred); } inlineReader.PerformGets(); @@ -128,19 +125,17 @@ int main(int argc, char *argv[]) } namev += std::to_string(v); - inlineFloats[v] = inlineIO.DefineVariable( - namev, {size * Nx}, {rank * Nx}, {Nx}, adios2::ConstantDims); + inlineFloats[v] = inlineIO.DefineVariable(namev, {size * Nx}, {rank * Nx}, {Nx}, + adios2::ConstantDims); } /** global single value variable: name */ adios2::Variable inlineTimeStep = inlineIO.DefineVariable("timeStep"); - adios2::Engine inlineWriter = - inlineIO.Open("myWriteID", adios2::Mode::Write); + adios2::Engine inlineWriter = inlineIO.Open("myWriteID", adios2::Mode::Write); - adios2::Engine inlineReader = - inlineIO.Open("myReadID", adios2::Mode::Read); + adios2::Engine inlineReader = inlineIO.Open("myReadID", adios2::Mode::Read); for (unsigned int timeStep = 0; timeStep < 3; ++timeStep) { @@ -159,9 +154,8 @@ int main(int argc, char *argv[]) inlineWriter.Put(inlineFloats[v], myFloats.data()); } - const std::string myString( - "Hello from rank: " + std::to_string(rank) + - " and timestep: " + std::to_string(timeStep)); + const std::string myString("Hello from rank: " + std::to_string(rank) + + " and timestep: " + std::to_string(timeStep)); if (rank == 0) { diff --git a/examples/hello/skeleton/CMakeLists.txt b/examples/hello/skeleton/CMakeLists.txt index 5e5a35007c..4c6ead50ab 100644 --- a/examples/hello/skeleton/CMakeLists.txt +++ b/examples/hello/skeleton/CMakeLists.txt @@ -3,16 +3,37 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_skeletonWriter helloSkeletonWriter.cpp HelloSkeletonArgs.cpp) -target_link_libraries(hello_skeletonWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSkeletonExample) -add_executable(hello_skeletonReader helloSkeletonReader.cpp HelloSkeletonArgs.cpp) -target_link_libraries(hello_skeletonReader adios2::cxx11) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +add_executable(adios2_hello_skeletonWriter skeletonWriter.cpp SkeletonArgs.cpp) +target_link_libraries(adios2_hello_skeletonWriter adios2::cxx11) +install(TARGETS adios2_hello_skeletonWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable(adios2_hello_skeletonReader skeletonReader.cpp SkeletonArgs.cpp) +target_link_libraries(adios2_hello_skeletonReader adios2::cxx11) +install(TARGETS adios2_hello_skeletonReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ADIOS2_HAVE_MPI) - add_executable(hello_skeletonWriter_mpi helloSkeletonWriter.cpp HelloSkeletonArgs.cpp) - target_link_libraries(hello_skeletonWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_skeletonWriter_mpi skeletonWriter.cpp SkeletonArgs.cpp) + target_link_libraries(adios2_hello_skeletonWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_skeletonWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - add_executable(hello_skeletonReader_mpi helloSkeletonReader.cpp HelloSkeletonArgs.cpp) - target_link_libraries(hello_skeletonReader_mpi adios2::cxx11_mpi MPI::MPI_C) + add_executable(adios2_hello_skeletonReader_mpi skeletonReader.cpp SkeletonArgs.cpp) + target_link_libraries(adios2_hello_skeletonReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_skeletonReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/hello/skeleton/HelloSkeletonArgs.cpp b/examples/hello/skeleton/SkeletonArgs.cpp similarity index 72% rename from examples/hello/skeleton/HelloSkeletonArgs.cpp rename to examples/hello/skeleton/SkeletonArgs.cpp index c35c1c16b8..109ca5388d 100644 --- a/examples/hello/skeleton/HelloSkeletonArgs.cpp +++ b/examples/hello/skeleton/SkeletonArgs.cpp @@ -6,7 +6,7 @@ * Author: Norbert Podhorszki */ -#include "HelloSkeletonArgs.h" +#include "SkeletonArgs.h" #include @@ -19,9 +19,8 @@ static void printUsage(bool isWriter) { if (isWriter) { - std::cout - << "Usage: Usage: helloSkeletonWriter config N M nx ny " - "steps sleeptime\n"; + std::cout << "Usage: Usage: helloSkeletonWriter config N M nx ny " + "steps sleeptime\n"; } else { @@ -32,30 +31,26 @@ static void printUsage(bool isWriter) << " M: number of processes in Y dimension\n"; if (isWriter) { - std::cout - << " nx: local array size in X dimension per processor\n" - << " ny: local array size in Y dimension per processor\n" - << " steps: the total number of steps to output\n" - << " sleeptime: wait this many milliseconds between output " - "steps\n\n"; + std::cout << " nx: local array size in X dimension per processor\n" + << " ny: local array size in Y dimension per processor\n" + << " steps: the total number of steps to output\n" + << " sleeptime: wait this many milliseconds between output " + "steps\n\n"; } } static unsigned int convertToUint(std::string varName, char *arg) { char *end; - unsigned int retval = std::strtoul(arg, &end, 10); + const auto retval = static_cast(std::strtoul(arg, &end, 10)); if (end[0] || errno == ERANGE) { - throw std::invalid_argument("Invalid value given for " + varName + - ": " + std::string(arg)); + throw std::invalid_argument("Invalid value given for " + varName + ": " + std::string(arg)); } return retval; } -HelloSkeletonArgs::HelloSkeletonArgs(bool isWriter, int argc, char *argv[], - int rank, int nproc) -: rank{rank} +SkeletonArgs::SkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc) : rank{rank} { npx = npy = ndx = ndy = steps = sleeptime = 0; gndx = gndy = posx = posy = offsx = offsy = 0; @@ -92,8 +87,7 @@ HelloSkeletonArgs::HelloSkeletonArgs(bool isWriter, int argc, char *argv[], if (npx * npy != static_cast(nproc)) { - throw std::invalid_argument( - "N*M must equal the number of processes"); + throw std::invalid_argument("N*M must equal the number of processes"); } } catch (std::invalid_argument &e) @@ -103,7 +97,7 @@ HelloSkeletonArgs::HelloSkeletonArgs(bool isWriter, int argc, char *argv[], } } -void HelloSkeletonArgs::DecomposeArray(size_t NX, size_t NY) +void SkeletonArgs::DecomposeArray(size_t NX, size_t NY) { gndx = static_cast(NX); gndy = static_cast(NY); @@ -127,6 +121,6 @@ void HelloSkeletonArgs::DecomposeArray(size_t NX, size_t NY) ndy = gndy - ndy * (npy - 1); } - std::cout << "rank " << rank << " reads 2D slice " << ndx << " x " << ndy - << " from offset (" << offsx << "," << offsy << ")" << std::endl; + std::cout << "rank " << rank << " reads 2D slice " << ndx << " x " << ndy << " from offset (" + << offsx << "," << offsy << ")" << std::endl; } diff --git a/examples/hello/skeleton/HelloSkeletonArgs.h b/examples/hello/skeleton/SkeletonArgs.h similarity index 92% rename from examples/hello/skeleton/HelloSkeletonArgs.h rename to examples/hello/skeleton/SkeletonArgs.h index 1cfeb2e776..0433e83950 100644 --- a/examples/hello/skeleton/HelloSkeletonArgs.h +++ b/examples/hello/skeleton/SkeletonArgs.h @@ -11,7 +11,7 @@ #include -class HelloSkeletonArgs +class SkeletonArgs { public: @@ -41,8 +41,7 @@ class HelloSkeletonArgs int rank; // MPI rank unsigned int nproc; // number of processors - HelloSkeletonArgs(bool isWriter, int argc, char *argv[], int rank, - int nproc); + SkeletonArgs(bool isWriter, int argc, char *argv[], int rank, int nproc); void DecomposeArray(size_t NX, size_t NY); }; diff --git a/examples/hello/skeleton/HelloSkeletonPrint.h b/examples/hello/skeleton/SkeletonPrint.h similarity index 73% rename from examples/hello/skeleton/HelloSkeletonPrint.h rename to examples/hello/skeleton/SkeletonPrint.h index 9c6a893f90..f8da9a98f8 100644 --- a/examples/hello/skeleton/HelloSkeletonPrint.h +++ b/examples/hello/skeleton/SkeletonPrint.h @@ -17,8 +17,8 @@ #include -void printDataStep(const float *data, const adios2::Dims &size, - const adios2::Dims &offset, const int rank, const int step) +void printDataStep(const float *data, const adios2::Dims &size, const adios2::Dims &offset, + const int rank, const int step) { std::ofstream myfile; std::string filename = "data." + std::to_string(rank); @@ -32,12 +32,11 @@ void printDataStep(const float *data, const adios2::Dims &size, } uint64_t nelems = size[0] * size[1]; - myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1] - << " offsets=" << offset[0] << ":" << offset[1] << " step=" << step - << std::endl; + myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1] << " offsets=" << offset[0] + << ":" << offset[1] << " step=" << step << std::endl; - myfile << " step row columns " << offset[1] << "..." - << offset[1] + size[1] - 1 << std::endl; + myfile << " step row columns " << offset[1] << "..." << offset[1] + size[1] - 1 + << std::endl; myfile << " "; for (size_t j = 0; j < size[1]; j++) { @@ -51,8 +50,7 @@ void printDataStep(const float *data, const adios2::Dims &size, myfile << std::setw(5) << step << std::setw(5) << offset[0] + i; for (size_t j = 0; j < size[1]; j++) { - myfile << std::setw(9) << std::setprecision(4) - << data[i * size[1] + j]; + myfile << std::setw(9) << std::setprecision(4) << data[i * size[1] + j]; } myfile << std::endl; } diff --git a/examples/hello/skeleton/hello_bpfile.xml b/examples/hello/skeleton/bpfile.xml similarity index 97% rename from examples/hello/skeleton/hello_bpfile.xml rename to examples/hello/skeleton/bpfile.xml index aeb255fd93..f46b17d38b 100644 --- a/examples/hello/skeleton/hello_bpfile.xml +++ b/examples/hello/skeleton/bpfile.xml @@ -1,6 +1,6 @@ diff --git a/examples/hello/skeleton/hello_skeleton.xml b/examples/hello/skeleton/skeleton.xml similarity index 96% rename from examples/hello/skeleton/hello_skeleton.xml rename to examples/hello/skeleton/skeleton.xml index bbca561454..ed9ad58b9c 100644 --- a/examples/hello/skeleton/hello_skeleton.xml +++ b/examples/hello/skeleton/skeleton.xml @@ -1,6 +1,6 @@ diff --git a/examples/hello/skeleton/helloSkeletonReader.cpp b/examples/hello/skeleton/skeletonReader.cpp similarity index 76% rename from examples/hello/skeleton/helloSkeletonReader.cpp rename to examples/hello/skeleton/skeletonReader.cpp index 882ddf1407..84ad636345 100644 --- a/examples/hello/skeleton/helloSkeletonReader.cpp +++ b/examples/hello/skeleton/skeletonReader.cpp @@ -1,3 +1,8 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + #include #include //std::ios_base::failure #include //std::cout @@ -6,8 +11,8 @@ #include -#include "HelloSkeletonArgs.h" -#include "HelloSkeletonPrint.h" +#include "SkeletonArgs.h" +#include "SkeletonPrint.h" int main(int argc, char *argv[]) { @@ -32,7 +37,7 @@ int main(int argc, char *argv[]) try { - HelloSkeletonArgs settings(false, argc, argv, rank, nproc); + SkeletonArgs settings(false, argc, argv, rank, nproc); /** ADIOS class factory of IO class objects, Debug is ON by default */ #if ADIOS2_USE_MPI @@ -41,23 +46,15 @@ int main(int argc, char *argv[]) adios2::ADIOS adios(settings.configfile); #endif adios2::IO io = adios.DeclareIO("reader"); - adios2::Engine reader = - io.Open(settings.streamname, adios2::Mode::Read); + adios2::Engine reader = io.Open(settings.streamname, adios2::Mode::Read); int step = 0; adios2::Variable vMyArray; adios2::Dims count, start; std::vector myArray; - while (true) + while (reader.BeginStep(adios2::StepMode::Read, 60.0f) == adios2::StepStatus::OK) { - adios2::StepStatus status = - reader.BeginStep(adios2::StepMode::Read, 60.0f); - if (status != adios2::StepStatus::OK) - { - break; - } - if (step == 0) { // this just discovers in the metadata file that the variable @@ -65,11 +62,10 @@ int main(int argc, char *argv[]) vMyArray = io.InquireVariable("myArray"); if (!vMyArray) { - std::cout - << "Missing 'myArray' variable. The Skeleton reader " - "engine must retrieve variables from the writer and " - "create Variable objects before they can be " - "inquired\n"; + std::cout << "Missing 'myArray' variable. The Skeleton reader " + "engine must retrieve variables from the writer and " + "create Variable objects before they can be " + "inquired\n"; count.push_back(0); count.push_back(0); start.push_back(0); @@ -79,15 +75,14 @@ int main(int argc, char *argv[]) { // now read the variable // Get the read decomposition - settings.DecomposeArray(vMyArray.Shape()[0], - vMyArray.Shape()[1]); + settings.DecomposeArray(vMyArray.Shape()[0], vMyArray.Shape()[1]); count.push_back(settings.ndx); count.push_back(settings.ndy); start.push_back(settings.offsx); start.push_back(settings.offsy); vMyArray.SetSelection({start, count}); - size_t elementsSize = count[0] * count[1]; + const size_t elementsSize = count[0] * count[1]; myArray.resize(elementsSize); } } @@ -106,8 +101,7 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/skeleton/helloSkeletonWriter.cpp b/examples/hello/skeleton/skeletonWriter.cpp similarity index 80% rename from examples/hello/skeleton/helloSkeletonWriter.cpp rename to examples/hello/skeleton/skeletonWriter.cpp index 3d4a9699d8..0eb1d43638 100644 --- a/examples/hello/skeleton/helloSkeletonWriter.cpp +++ b/examples/hello/skeleton/skeletonWriter.cpp @@ -13,7 +13,7 @@ #include #include -#include "HelloSkeletonArgs.h" +#include "SkeletonArgs.h" #include @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) try { - HelloSkeletonArgs settings(true, argc, argv, rank, nproc); + SkeletonArgs settings(true, argc, argv, rank, nproc); std::vector myArray(settings.ndx * settings.ndy); @@ -53,12 +53,10 @@ int main(int argc, char *argv[]) adios2::IO io = adios.DeclareIO("writer"); adios2::Variable varArray = io.DefineVariable( - "myArray", {settings.gndx, settings.gndy}, - {settings.offsx, settings.offsy}, {settings.ndx, settings.ndy}, - adios2::ConstantDims); + "myArray", {settings.gndx, settings.gndy}, {settings.offsx, settings.offsy}, + {settings.ndx, settings.ndy}, adios2::ConstantDims); - adios2::Engine writer = - io.Open(settings.streamname, adios2::Mode::Write); + adios2::Engine writer = io.Open(settings.streamname, adios2::Mode::Write); for (size_t step = 0; step < settings.steps; ++step) { @@ -67,23 +65,21 @@ int main(int argc, char *argv[]) { for (size_t i = 0; i < settings.ndx; ++i) { - myArray[idx] = rank + (step / 100.0f); + myArray[idx] = static_cast(rank) + (static_cast(step) / 100.0f); ++idx; } } writer.BeginStep(adios2::StepMode::Append); writer.Put(varArray, myArray.data()); writer.EndStep(); - std::this_thread::sleep_for( - std::chrono::milliseconds(settings.sleeptime)); + std::this_thread::sleep_for(std::chrono::milliseconds(settings.sleeptime)); } writer.Close(); } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/sstReader/CMakeLists.txt b/examples/hello/sstReader/CMakeLists.txt index eff30267d5..39a0b615c0 100644 --- a/examples/hello/sstReader/CMakeLists.txt +++ b/examples/hello/sstReader/CMakeLists.txt @@ -3,10 +3,35 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_sstReader helloSstReader.cpp) -target_link_libraries(hello_sstReader adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSstReaderExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_sstReader_mpi helloSstReader.cpp) - target_link_libraries(hello_sstReader_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + if(NOT WIN32) + find_package(LIBFABRIC 1.6 QUIET) + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_SST) + add_executable(adios2_hello_sstReader sstReader.cpp) + target_link_libraries(adios2_hello_sstReader adios2::cxx11) + install(TARGETS adios2_hello_sstReader RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_sstReader_mpi sstReader.cpp) + target_link_libraries(adios2_hello_sstReader_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_sstReader_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/sstReader/helloSstReader.cpp b/examples/hello/sstReader/sstReader.cpp similarity index 90% rename from examples/hello/sstReader/helloSstReader.cpp rename to examples/hello/sstReader/sstReader.cpp index 8b8df3f8dc..56630b3eea 100644 --- a/examples/hello/sstReader/helloSstReader.cpp +++ b/examples/hello/sstReader/sstReader.cpp @@ -2,10 +2,10 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloSstReader.cpp + * sstReader.cpp * * Created on: Aug 17, 2017 -v * Author: Greg Eisenhauer + * Author: Greg Eisenhauer */ #include @@ -54,10 +54,8 @@ int main(int argc, char *argv[]) adios2::Engine sstReader = sstIO.Open("helloSst", adios2::Mode::Read); sstReader.BeginStep(); - adios2::Variable bpFloats = - sstIO.InquireVariable("bpFloats"); - std::cout << "Incoming variable is of size " << bpFloats.Shape()[0] - << "\n"; + adios2::Variable bpFloats = sstIO.InquireVariable("bpFloats"); + std::cout << "Incoming variable is of size " << bpFloats.Shape()[0] << "\n"; const std::size_t total_size = bpFloats.Shape()[0]; const std::size_t my_start = (total_size / size) * rank; const std::size_t my_count = (total_size / size); @@ -80,8 +78,7 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) diff --git a/examples/hello/sstWriter/CMakeLists.txt b/examples/hello/sstWriter/CMakeLists.txt index 637e00bfd4..f5adca3e58 100644 --- a/examples/hello/sstWriter/CMakeLists.txt +++ b/examples/hello/sstWriter/CMakeLists.txt @@ -3,10 +3,35 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(hello_sstWriter helloSstWriter.cpp) -target_link_libraries(hello_sstWriter adios2::cxx11) +cmake_minimum_required(VERSION 3.12) +project(ADIOS2HelloSstWriterExample) -if(ADIOS2_HAVE_MPI) - add_executable(hello_sstWriter_mpi helloSstWriter.cpp) - target_link_libraries(hello_sstWriter_mpi adios2::cxx11_mpi MPI::MPI_C) +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + if (NOT WIN32) + find_package(LIBFABRIC 1.6 QUIET) + endif () + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_SST) + add_executable(adios2_hello_sstWriter sstWriter.cpp) + target_link_libraries(adios2_hello_sstWriter adios2::cxx11) + install(TARGETS adios2_hello_sstWriter RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(ADIOS2_HAVE_MPI) + add_executable(adios2_hello_sstWriter_mpi sstWriter.cpp) + target_link_libraries(adios2_hello_sstWriter_mpi adios2::cxx11_mpi MPI::MPI_C) + install(TARGETS adios2_hello_sstWriter_mpi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() endif() diff --git a/examples/hello/sstWriter/helloSstWriter.cpp b/examples/hello/sstWriter/sstWriter.cpp similarity index 75% rename from examples/hello/sstWriter/helloSstWriter.cpp rename to examples/hello/sstWriter/sstWriter.cpp index 27641cd9a3..02d4981171 100644 --- a/examples/hello/sstWriter/helloSstWriter.cpp +++ b/examples/hello/sstWriter/sstWriter.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * helloSstWriter.cpp + * sstWriter.cpp * * Created on: Aug 17, 2017 * Author: Greg Eisenhauer @@ -36,10 +36,11 @@ int main(int argc, char *argv[]) #endif std::vector myFloats = { - (float)10.0 * rank + 0, (float)10.0 * rank + 1, (float)10.0 * rank + 2, - (float)10.0 * rank + 3, (float)10.0 * rank + 4, (float)10.0 * rank + 5, - (float)10.0 * rank + 6, (float)10.0 * rank + 7, (float)10.0 * rank + 8, - (float)10.0 * rank + 9}; + static_cast(10.0 * rank + 0), static_cast(10.0 * rank + 1), + static_cast(10.0 * rank + 2), static_cast(10.0 * rank + 3), + static_cast(10.0 * rank + 4), static_cast(10.0 * rank + 5), + static_cast(10.0 * rank + 6), static_cast(10.0 * rank + 7), + static_cast(10.0 * rank + 8), static_cast(10.0 * rank + 9)}; const std::size_t Nx = myFloats.size(); try @@ -53,8 +54,7 @@ int main(int argc, char *argv[]) sstIO.SetEngine("Sst"); // Define variable and local size - auto bpFloats = sstIO.DefineVariable("bpFloats", {size * Nx}, - {rank * Nx}, {Nx}); + auto bpFloats = sstIO.DefineVariable("bpFloats", {size * Nx}, {rank * Nx}, {Nx}); // Create engine smart pointer to Sst Engine due to polymorphism, // Open returns a smart pointer to Engine containing the Derived class @@ -67,15 +67,13 @@ int main(int argc, char *argv[]) } catch (std::invalid_argument &e) { - std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "Invalid argument exception, STOPPING PROGRAM from rank " << rank << "\n"; std::cout << e.what() << "\n"; } catch (std::ios_base::failure &e) { - std::cout - << "IO System base failure exception, STOPPING PROGRAM from rank " - << rank << "\n"; + std::cout << "IO System base failure exception, STOPPING PROGRAM from rank " << rank + << "\n"; std::cout << e.what() << "\n"; } catch (std::exception &e) diff --git a/examples/hello/sstWriter/helloSstWriter.py b/examples/hello/sstWriter/sstWriter.py similarity index 72% rename from examples/hello/sstWriter/helloSstWriter.py rename to examples/hello/sstWriter/sstWriter.py index 99508627ad..08a7a8270a 100644 --- a/examples/hello/sstWriter/helloSstWriter.py +++ b/examples/hello/sstWriter/sstWriter.py @@ -12,13 +12,13 @@ # ADIOS IO sstIO = adios.DeclareIO("myIO") -sstIO.SetEngine('Sst') -myArray = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], - dtype='f') +sstIO.SetEngine("Sst") +myArray = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype="f") myArray = 10.0 * rank + myArray nx = len(myArray) -ioArray = sstIO.DefineVariable("bpFloats", myArray, [size * nx], - [rank * nx], [nx], adios2.ConstantDims) +ioArray = sstIO.DefineVariable( + "bpFloats", myArray, [size * nx], [rank * nx], [nx], adios2.ConstantDims +) sstFileWriter = sstIO.Open("helloSst", adios2.Mode.Write) sstFileWriter.BeginStep() sstFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) diff --git a/examples/inlineMWE/CMakeLists.txt b/examples/inlineMWE/CMakeLists.txt deleted file mode 100644 index 3773d2d3f7..0000000000 --- a/examples/inlineMWE/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -add_executable(inlineMWE inlineMWE.cpp) -target_link_libraries(inlineMWE adios2::cxx11) diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 5fed9662d6..013d696b17 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -4,4 +4,6 @@ #------------------------------------------------------------------------------# add_subdirectory(engine) -add_subdirectory(operator) +if(ADIOS2_HAVE_Sodium) + add_subdirectory(operator) +endif() diff --git a/examples/plugins/ReadMe.md b/examples/plugins/ReadMe.md new file mode 100644 index 0000000000..3fbfdaa0c6 --- /dev/null +++ b/examples/plugins/ReadMe.md @@ -0,0 +1,13 @@ +## ADIOS2 plugins examples + +The _plugins_ examples are meant to introduce you to the plugin capabilities of ADIOS2, such as +how to develop your own engine or operators. + +They can be found in the following subdirectories, and they should be explored in the order that they are listed: + +1. [engine](engine): The _engine_ example demonstrates how to develop the read/write capabilities of your ADIOS2 engine + and use it to read and write variables. + * Languages: C++ +2. [operator](operator): The _operator_ example demonstrates how to read and write variables using the + ADIOS2/plugins/operators/EncryptionOperator and ADIOS2's BP engine. + * Languages: C++ diff --git a/examples/plugins/engine/CMakeLists.txt b/examples/plugins/engine/CMakeLists.txt index a611c0b8b7..d902043a83 100644 --- a/examples/plugins/engine/CMakeLists.txt +++ b/examples/plugins/engine/CMakeLists.txt @@ -3,33 +3,39 @@ # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# +cmake_minimum_required(VERSION 3.12) +project(ADIOS2PluginsEngineExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + include(GenerateExportHeader) -add_library(PluginEngineWrite - ExampleWritePlugin.cpp -) -target_link_libraries(PluginEngineWrite adios2::cxx11 adios2_core) -generate_export_header(PluginEngineWrite BASE_NAME plugin_engine_write) -target_include_directories(PluginEngineWrite PUBLIC + +add_library(adios2_plugins_exampleWritePlugin ExampleWritePlugin.cpp) +target_link_libraries(adios2_plugins_exampleWritePlugin adios2::cxx11 adios2_core) +generate_export_header(adios2_plugins_exampleWritePlugin BASE_NAME plugin_engine_write) +target_include_directories(adios2_plugins_exampleWritePlugin PUBLIC $ $ ) +install(TARGETS adios2_plugins_exampleWritePlugin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_library(PluginEngineRead - ExampleReadPlugin.cpp -) -target_link_libraries(PluginEngineRead adios2::cxx11 adios2_core) -generate_export_header(PluginEngineRead BASE_NAME plugin_engine_read) -target_include_directories(PluginEngineRead PUBLIC +add_library(adios2_plugins_exampleReadPlugin ExampleReadPlugin.cpp) +target_link_libraries(adios2_plugins_exampleReadPlugin adios2::cxx11 adios2_core) +generate_export_header(adios2_plugins_exampleReadPlugin BASE_NAME plugin_engine_read) +target_include_directories(adios2_plugins_exampleReadPlugin PUBLIC $ $ ) +install(TARGETS adios2_plugins_exampleReadPlugin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(examplePluginEngine_write - examplePluginEngine_write.cpp -) -target_link_libraries(examplePluginEngine_write adios2::cxx11) +add_executable(adios2_plugins_examplePluginEngineWrite examplePluginEngineWrite.cpp) +target_link_libraries(adios2_plugins_examplePluginEngineWrite adios2::cxx11) +install(TARGETS adios2_plugins_examplePluginEngineWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_executable(examplePluginEngine_read - examplePluginEngine_read.cpp -) -target_link_libraries(examplePluginEngine_read adios2::cxx11) +add_executable(adios2_plugins_examplePluginEngineRead examplePluginEngineRead.cpp) +target_link_libraries(adios2_plugins_examplePluginEngineRead adios2::cxx11) +install(TARGETS adios2_plugins_examplePluginEngineRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/plugins/engine/ExampleReadPlugin.cpp b/examples/plugins/engine/ExampleReadPlugin.cpp index 29ac7daeea..b896f9104f 100644 --- a/examples/plugins/engine/ExampleReadPlugin.cpp +++ b/examples/plugins/engine/ExampleReadPlugin.cpp @@ -18,8 +18,8 @@ namespace adios2 namespace plugin { -ExampleReadPlugin::ExampleReadPlugin(core::IO &io, const std::string &name, - const Mode mode, helper::Comm comm) +ExampleReadPlugin::ExampleReadPlugin(core::IO &io, const std::string &name, const Mode mode, + helper::Comm comm) : PluginEngineInterface(io, name, mode, comm.Duplicate()) { Init(); @@ -61,16 +61,15 @@ void ExampleReadPlugin::Init() m_DataFile.open(fileName, std::ofstream::in); if (!m_DataFile) { - throw std::ios_base::failure("ExampleReadPlugin: Failed to open file " + - fileName); + throw std::ios_base::failure("ExampleReadPlugin: Failed to open file " + fileName); } std::string varfName = dir + "/vars.txt"; m_VarFile.open(varfName, std::ofstream::in); if (!m_VarFile) { - throw std::ios_base::failure("ExampleReadPlugin: Failed to open file " + - varfName + ".vars"); + throw std::ios_base::failure("ExampleReadPlugin: Failed to open file " + varfName + + ".vars"); } // get var info @@ -92,31 +91,29 @@ void ExampleReadPlugin::Init() { // not supported } -#define declare_template_instantiation(T) \ - else if (type == helper::GetDataType()) \ - { \ - AddVariable(name, shape, start, count); \ +#define declare_template_instantiation(T) \ + else if (type == helper::GetDataType()) \ + { \ + AddVariable(name, shape, start, count); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation } } -#define declare(T) \ - void ExampleReadPlugin::DoGetSync(core::Variable &variable, T *values) \ - { \ - ReadVariable(variable, values); \ - } \ - void ExampleReadPlugin::DoGetDeferred(core::Variable &variable, \ - T *values) \ - { \ - ReadVariable(variable, values); \ +#define declare(T) \ + void ExampleReadPlugin::DoGetSync(core::Variable &variable, T *values) \ + { \ + ReadVariable(variable, values); \ + } \ + void ExampleReadPlugin::DoGetDeferred(core::Variable &variable, T *values) \ + { \ + ReadVariable(variable, values); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare) #undef declare -StepStatus ExampleReadPlugin::BeginStep(StepMode mode, - const float timeoutSeconds) +StepStatus ExampleReadPlugin::BeginStep(StepMode mode, const float timeoutSeconds) { return StepStatus::OK; } @@ -134,13 +131,10 @@ void ExampleReadPlugin::DoClose(const int transportIndex) {} extern "C" { -adios2::plugin::ExampleReadPlugin *EngineCreate(adios2::core::IO &io, - const std::string &name, - const adios2::Mode mode, - adios2::helper::Comm comm) +adios2::plugin::ExampleReadPlugin *EngineCreate(adios2::core::IO &io, const std::string &name, + const adios2::Mode mode, adios2::helper::Comm comm) { - return new adios2::plugin::ExampleReadPlugin(io, name, mode, - comm.Duplicate()); + return new adios2::plugin::ExampleReadPlugin(io, name, mode, comm.Duplicate()); } void EngineDestroy(adios2::plugin::ExampleReadPlugin *obj) { delete obj; } diff --git a/examples/plugins/engine/ExampleReadPlugin.h b/examples/plugins/engine/ExampleReadPlugin.h index 9fff0ae316..a6126a4032 100644 --- a/examples/plugins/engine/ExampleReadPlugin.h +++ b/examples/plugins/engine/ExampleReadPlugin.h @@ -36,8 +36,8 @@ namespace plugin class ExampleReadPlugin : public PluginEngineInterface { public: - ExampleReadPlugin(core::IO &io, const std::string &name, - const Mode openMode, helper::Comm comm); + ExampleReadPlugin(core::IO &io, const std::string &name, const Mode openMode, + helper::Comm comm); virtual ~ExampleReadPlugin(); /** Indicates beginning of a step **/ @@ -56,8 +56,8 @@ class ExampleReadPlugin : public PluginEngineInterface protected: void Init() override; -#define declare(T) \ - void DoGetSync(core::Variable &variable, T *values) override; \ +#define declare(T) \ + void DoGetSync(core::Variable &variable, T *values) override; \ void DoGetDeferred(core::Variable &variable, T *values) override; ADIOS2_FOREACH_STDTYPE_1ARG(declare) #undef declare @@ -70,8 +70,7 @@ class ExampleReadPlugin : public PluginEngineInterface size_t m_CurrentStep = 0; template - void AddVariable(const std::string &name, Dims shape, Dims start, - Dims count); + void AddVariable(const std::string &name, Dims shape, Dims start, Dims count); template void ReadVariable(core::Variable &variable, T *values); @@ -83,10 +82,9 @@ class ExampleReadPlugin : public PluginEngineInterface extern "C" { PLUGIN_ENGINE_READ_EXPORT adios2::plugin::ExampleReadPlugin * -EngineCreate(adios2::core::IO &io, const std::string &name, - const adios2::Mode mode, adios2::helper::Comm comm); -PLUGIN_ENGINE_READ_EXPORT void -EngineDestroy(adios2::plugin::ExampleReadPlugin *obj); +EngineCreate(adios2::core::IO &io, const std::string &name, const adios2::Mode mode, + adios2::helper::Comm comm); +PLUGIN_ENGINE_READ_EXPORT void EngineDestroy(adios2::plugin::ExampleReadPlugin *obj); } #endif /* EXAMPLEREADPLUGIN_H_ */ diff --git a/examples/plugins/engine/ExampleReadPlugin.tcc b/examples/plugins/engine/ExampleReadPlugin.tcc index eef62f09d5..bf1195549b 100644 --- a/examples/plugins/engine/ExampleReadPlugin.tcc +++ b/examples/plugins/engine/ExampleReadPlugin.tcc @@ -19,8 +19,7 @@ namespace plugin { template -void ExampleReadPlugin::AddVariable(const std::string &name, Dims shape, - Dims start, Dims count) +void ExampleReadPlugin::AddVariable(const std::string &name, Dims shape, Dims start, Dims count) { core::Variable *v = m_IO.InquireVariable(name); if (!v) @@ -30,8 +29,7 @@ void ExampleReadPlugin::AddVariable(const std::string &name, Dims shape, } template -inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, - T *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, T *values) { while (m_DataFile.good()) { @@ -65,9 +63,8 @@ inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable &variable, - std::string *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, + std::string *values) { while (m_DataFile.good()) { @@ -82,8 +79,7 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, - char *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, char *values) { while (m_DataFile.good()) { @@ -101,9 +97,8 @@ inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable &variable, - unsigned char *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, + unsigned char *values) { while (m_DataFile.good()) { @@ -123,9 +118,8 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable &variable, - signed char *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, + signed char *values) { while (m_DataFile.good()) { @@ -145,8 +139,7 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, - short *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, short *values) { while (m_DataFile.good()) { @@ -166,9 +159,8 @@ inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable &variable, - unsigned short *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, + unsigned short *values) { while (m_DataFile.good()) { @@ -188,9 +180,8 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable &variable, - long double *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable &variable, + long double *values) { while (m_DataFile.good()) { @@ -208,8 +199,8 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } catch (...) { - std::throw_with_nested(std::invalid_argument( - "ERROR: could not cast " + val + " to long double ")); + std::throw_with_nested( + std::invalid_argument("ERROR: could not cast " + val + " to long double ")); } } break; @@ -218,21 +209,17 @@ ExampleReadPlugin::ReadVariable(core::Variable &variable, } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable> &variable, - std::complex *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable> &variable, + std::complex *values) { - throw std::invalid_argument( - "ERROR: std::complex not supported in this engine"); + throw std::invalid_argument("ERROR: std::complex not supported in this engine"); } template <> -inline void -ExampleReadPlugin::ReadVariable(core::Variable> &variable, - std::complex *values) +inline void ExampleReadPlugin::ReadVariable(core::Variable> &variable, + std::complex *values) { - throw std::invalid_argument( - "ERROR: std::complex not supported in this engine"); + throw std::invalid_argument("ERROR: std::complex not supported in this engine"); } } // end namespace plugin } // end namespace adios2 diff --git a/examples/plugins/engine/ExampleWritePlugin.cpp b/examples/plugins/engine/ExampleWritePlugin.cpp index 9a969b3f3a..083de1693b 100644 --- a/examples/plugins/engine/ExampleWritePlugin.cpp +++ b/examples/plugins/engine/ExampleWritePlugin.cpp @@ -19,8 +19,8 @@ namespace adios2 namespace plugin { -ExampleWritePlugin::ExampleWritePlugin(core::IO &io, const std::string &name, - const Mode mode, helper::Comm comm) +ExampleWritePlugin::ExampleWritePlugin(core::IO &io, const std::string &name, const Mode mode, + helper::Comm comm) : PluginEngineInterface(io, name, mode, comm.Duplicate()) { Init(); @@ -46,21 +46,18 @@ void ExampleWritePlugin::Init() m_DataFile.open(fileName); if (!m_DataFile) { - throw std::ios_base::failure( - "ExampleWritePlugin: Failed to open file " + fileName); + throw std::ios_base::failure("ExampleWritePlugin: Failed to open file " + fileName); } std::string varfName = dir + "/vars.txt"; m_VarFile.open(varfName); if (!m_VarFile) { - throw std::ios_base::failure( - "ExampleWritePlugin: Failed to open file " + varfName); + throw std::ios_base::failure("ExampleWritePlugin: Failed to open file " + varfName); } } -StepStatus ExampleWritePlugin::BeginStep(StepMode mode, - const float timeoutSeconds) +StepStatus ExampleWritePlugin::BeginStep(StepMode mode, const float timeoutSeconds) { WriteVarsFromIO(); return StepStatus::OK; @@ -70,16 +67,14 @@ size_t ExampleWritePlugin::CurrentStep() const { return m_CurrentStep; } void ExampleWritePlugin::EndStep() { m_CurrentStep++; } -#define declare(T) \ - void ExampleWritePlugin::DoPutSync(core::Variable &variable, \ - const T *values) \ - { \ - WriteArray(variable, values); \ - } \ - void ExampleWritePlugin::DoPutDeferred(core::Variable &variable, \ - const T *values) \ - { \ - WriteArray(variable, values); \ +#define declare(T) \ + void ExampleWritePlugin::DoPutSync(core::Variable &variable, const T *values) \ + { \ + WriteArray(variable, values); \ + } \ + void ExampleWritePlugin::DoPutDeferred(core::Variable &variable, const T *values) \ + { \ + WriteArray(variable, values); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare) #undef declare @@ -95,13 +90,13 @@ void ExampleWritePlugin::WriteVarsFromIO() { const std::string &varName = vpair.first; const DataType varType = vpair.second->m_Type; -#define declare_template_instantiation(T) \ - if (varType == helper::GetDataType()) \ - { \ - core::Variable *v = m_IO.InquireVariable(varName); \ - if (!v) \ - return; \ - WriteVariableInfo(*v); \ +#define declare_template_instantiation(T) \ + if (varType == helper::GetDataType()) \ + { \ + core::Variable *v = m_IO.InquireVariable(varName); \ + if (!v) \ + return; \ + WriteVariableInfo(*v); \ } ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation @@ -113,13 +108,10 @@ void ExampleWritePlugin::WriteVarsFromIO() extern "C" { -adios2::plugin::ExampleWritePlugin *EngineCreate(adios2::core::IO &io, - const std::string &name, - const adios2::Mode mode, - adios2::helper::Comm comm) +adios2::plugin::ExampleWritePlugin *EngineCreate(adios2::core::IO &io, const std::string &name, + const adios2::Mode mode, adios2::helper::Comm comm) { - return new adios2::plugin::ExampleWritePlugin(io, name, mode, - comm.Duplicate()); + return new adios2::plugin::ExampleWritePlugin(io, name, mode, comm.Duplicate()); } void EngineDestroy(adios2::plugin::ExampleWritePlugin *obj) { delete obj; } diff --git a/examples/plugins/engine/ExampleWritePlugin.h b/examples/plugins/engine/ExampleWritePlugin.h index bfdd3fa338..b95b1f56da 100644 --- a/examples/plugins/engine/ExampleWritePlugin.h +++ b/examples/plugins/engine/ExampleWritePlugin.h @@ -36,13 +36,12 @@ namespace plugin class ExampleWritePlugin : public PluginEngineInterface { public: - ExampleWritePlugin(core::IO &io, const std::string &name, - const Mode openMode, helper::Comm comm); + ExampleWritePlugin(core::IO &io, const std::string &name, const Mode openMode, + helper::Comm comm); virtual ~ExampleWritePlugin(); /** Indicates beginning of a step **/ - StepStatus BeginStep(StepMode mode, - const float timeoutSeconds = -1.0) override; + StepStatus BeginStep(StepMode mode, const float timeoutSeconds = -1.0) override; /** Indicates end of a step **/ void EndStep() override; @@ -56,8 +55,8 @@ class ExampleWritePlugin : public PluginEngineInterface protected: void Init() override; -#define declare(T) \ - void DoPutSync(core::Variable &variable, const T *values) override; \ +#define declare(T) \ + void DoPutSync(core::Variable &variable, const T *values) override; \ void DoPutDeferred(core::Variable &variable, const T *values) override; ADIOS2_FOREACH_STDTYPE_1ARG(declare) #undef declare @@ -84,10 +83,9 @@ class ExampleWritePlugin : public PluginEngineInterface extern "C" { PLUGIN_ENGINE_WRITE_EXPORT adios2::plugin::ExampleWritePlugin * -EngineCreate(adios2::core::IO &io, const std::string &name, - const adios2::Mode mode, adios2::helper::Comm comm); -PLUGIN_ENGINE_WRITE_EXPORT void -EngineDestroy(adios2::plugin::ExampleWritePlugin *obj); +EngineCreate(adios2::core::IO &io, const std::string &name, const adios2::Mode mode, + adios2::helper::Comm comm); +PLUGIN_ENGINE_WRITE_EXPORT void EngineDestroy(adios2::plugin::ExampleWritePlugin *obj); } #endif /* EXAMPLEWRITEPLUGIN_H_ */ diff --git a/examples/plugins/engine/ExampleWritePlugin.tcc b/examples/plugins/engine/ExampleWritePlugin.tcc index 4a6fdc737f..e820392f36 100644 --- a/examples/plugins/engine/ExampleWritePlugin.tcc +++ b/examples/plugins/engine/ExampleWritePlugin.tcc @@ -23,14 +23,12 @@ template void ExampleWritePlugin::WriteVariableInfo(core::Variable &variable) { /** write basic variable info to file **/ - m_VarFile << variable.m_Name << ";" << variable.m_Type << ";" - << variable.m_Shape << ";" << variable.m_Start << ";" - << variable.m_Count << std::endl; + m_VarFile << variable.m_Name << ";" << variable.m_Type << ";" << variable.m_Shape << ";" + << variable.m_Start << ";" << variable.m_Count << std::endl; } template -void ExampleWritePlugin::WriteArray(core::Variable &variable, - const T *values) +void ExampleWritePlugin::WriteArray(core::Variable &variable, const T *values) { /** Write variable name and step to file, followed by the actual data on the * next line **/ diff --git a/examples/plugins/engine/examplePluginEngine_read.cpp b/examples/plugins/engine/examplePluginEngineRead.cpp similarity index 60% rename from examples/plugins/engine/examplePluginEngine_read.cpp rename to examples/plugins/engine/examplePluginEngineRead.cpp index 17042868dc..02241e4291 100644 --- a/examples/plugins/engine/examplePluginEngine_read.cpp +++ b/examples/plugins/engine/examplePluginEngineRead.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginEngine_read.cpp example showing how to use ExampleReadPlugin + * examplePluginEngineRead.cpp example showing how to use ExampleReadPlugin * engine * * Created on: July 5, 2021 @@ -16,35 +16,6 @@ #include "adios2.h" -void testStreaming(adios2::Engine &reader, std::vector &myFloats, - adios2::Variable &var) -{ - for (int i = 0; i < 2; i++) - { - if (i == 1) - { - for (auto &num : myFloats) - { - num *= 2; - } - } - - reader.BeginStep(); - std::vector readFloats; - reader.Get(var, readFloats); - reader.EndStep(); - - if (readFloats == myFloats) - { - std::cout << "data was read correctly!" << std::endl; - } - else - { - std::cout << "data was not read correctly!" << std::endl; - } - } -} - int main(int argc, char *argv[]) { std::string config; @@ -53,12 +24,6 @@ int main(int argc, char *argv[]) config = std::string(argv[1]); } - bool streaming = false; - if (argc > 2) - { - streaming = std::atoi(argv[2]) == 1; - } - std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; bool success = false; @@ -82,30 +47,38 @@ int main(int argc, char *argv[]) } adios2::Engine reader = io.Open("TestPlugin", adios2::Mode::Read); - auto var = io.InquireVariable("data"); - if (!var) - { - std::cout << "variable does not exist" << std::endl; - } - - if (streaming) - { - testStreaming(reader, myFloats, var); - } - else + // test streaming + for (int i = 0; i < 2; i++) { - std::vector readFloats; - reader.Get(var, readFloats); - reader.PerformGets(); + if (i == 1) + { + for (auto &num : myFloats) + { + num *= 2; + } + } - if (readFloats == myFloats) + reader.BeginStep(); + auto var = io.InquireVariable("data"); + if (!var) { - std::cout << "data was read correctly!" << std::endl; + std::cout << "variable does not exist" << std::endl; } else { - std::cout << "data was not read correctly!" << std::endl; + std::vector readFloats; + reader.Get(var, readFloats); + + if (readFloats == myFloats) + { + std::cout << "data was read correctly!" << std::endl; + } + else + { + std::cout << "data was not read correctly!" << std::endl; + } } + reader.EndStep(); } /** Engine becomes unreachable after this*/ diff --git a/examples/plugins/engine/examplePluginEngine_write.cpp b/examples/plugins/engine/examplePluginEngineWrite.cpp similarity index 73% rename from examples/plugins/engine/examplePluginEngine_write.cpp rename to examples/plugins/engine/examplePluginEngineWrite.cpp index d9aad21a32..75b51c660d 100644 --- a/examples/plugins/engine/examplePluginEngine_write.cpp +++ b/examples/plugins/engine/examplePluginEngineWrite.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginEngine_write.cpp example showing how to use ExampleWritePlugin + * examplePluginEngineWrite.cpp example showing how to use ExampleWritePlugin * engine * * Created on: July 5, 2021 @@ -16,24 +16,6 @@ #include "adios2.h" -void testStreaming(adios2::Engine &writer, std::vector &myFloats, - adios2::Variable &var) -{ - for (int i = 0; i < 2; i++) - { - if (i == 1) - { - for (auto &num : myFloats) - { - num *= 2; - } - } - writer.BeginStep(); - writer.Put(var, myFloats.data()); - writer.EndStep(); - } -} - int main(int argc, char *argv[]) { std::string config; @@ -42,12 +24,6 @@ int main(int argc, char *argv[]) config = std::string(argv[1]); } - bool streaming = false; - if (argc > 2) - { - streaming = std::atoi(argv[2]) == 1; - } - /** Application variable */ std::vector myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const std::size_t Nx = myFloats.size(); @@ -64,8 +40,8 @@ int main(int argc, char *argv[]) /** global array: name, { shape (total dimensions) }, { start (local) }, * { count (local) }, all are constant dimensions */ - adios2::Variable var = io.DefineVariable( - "data", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable var = + io.DefineVariable("data", {}, {}, {Nx}, adios2::ConstantDims); if (config.empty()) { @@ -78,14 +54,19 @@ int main(int argc, char *argv[]) } adios2::Engine writer = io.Open("TestPlugin", adios2::Mode::Write); - if (streaming) - { - testStreaming(writer, myFloats, var); - } - else + // test streaming + for (int i = 0; i < 2; i++) { + if (i == 1) + { + for (auto &num : myFloats) + { + num *= 2; + } + } + writer.BeginStep(); writer.Put(var, myFloats.data()); - writer.PerformPuts(); + writer.EndStep(); } /** Engine becomes unreachable after this*/ diff --git a/examples/plugins/engine/example_engine.xml b/examples/plugins/engine/example_engine.xml index 412c1a9684..46393a70d7 100644 --- a/examples/plugins/engine/example_engine.xml +++ b/examples/plugins/engine/example_engine.xml @@ -10,7 +10,7 @@ - + @@ -22,7 +22,7 @@ - + diff --git a/examples/plugins/operator/CMakeLists.txt b/examples/plugins/operator/CMakeLists.txt index 8881bb8f16..f71e6dca20 100644 --- a/examples/plugins/operator/CMakeLists.txt +++ b/examples/plugins/operator/CMakeLists.txt @@ -2,12 +2,24 @@ # Distributed under the OSI-approved Apache License, Version 2.0. See # accompanying file Copyright.txt for details. #------------------------------------------------------------------------------# -add_executable(exampleOperatorPlugin_write - examplePluginOperator_write.cpp -) -target_link_libraries(exampleOperatorPlugin_write adios2::cxx11) - -add_executable(exampleOperatorPlugin_read - examplePluginOperator_read.cpp -) -target_link_libraries(exampleOperatorPlugin_read adios2::cxx11) + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2PluginsOperatorExample) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(Sodium QUIET) + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +endif() + +if(ADIOS2_HAVE_Sodium) + add_executable(adios2_plugins_exampleOperatorPluginWrite examplePluginOperatorWrite.cpp) + target_link_libraries(adios2_plugins_exampleOperatorPluginWrite adios2::cxx11) + install(TARGETS adios2_plugins_exampleOperatorPluginWrite RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(adios2_plugins_exampleOperatorPluginRead examplePluginOperatorRead.cpp) + target_link_libraries(adios2_plugins_exampleOperatorPluginRead adios2::cxx11) + install(TARGETS adios2_plugins_exampleOperatorPluginRead RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() \ No newline at end of file diff --git a/examples/plugins/operator/examplePluginOperator_read.cpp b/examples/plugins/operator/examplePluginOperatorRead.cpp similarity index 75% rename from examples/plugins/operator/examplePluginOperator_read.cpp rename to examples/plugins/operator/examplePluginOperatorRead.cpp index fd6d0a927f..1430b7cd96 100644 --- a/examples/plugins/operator/examplePluginOperator_read.cpp +++ b/examples/plugins/operator/examplePluginOperatorRead.cpp @@ -2,7 +2,7 @@ * Distributed under the OSI-approved Apache License, Version 2.0. See * accompanying file Copyright.txt for details. * - * examplePluginOperator_read.cpp example showing how to use EncryptionOperator + * examplePluginOperatorRead.cpp example showing how to use EncryptionOperator * plugin * * Created on: July 5, 2021 @@ -26,18 +26,16 @@ int main(int argc, char *argv[]) /** Application variable */ std::vector myDoubles = { - 0.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, - 0.0001, + 0.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, + 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, + 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, + 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, + 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, + 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, + 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, + 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, + 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, + 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, 0.0001, }; bool success = false; @@ -53,6 +51,7 @@ int main(int argc, char *argv[]) /** global array: name, { shape (total dimensions) }, { start (local) }, * { count (local) }, all are constant dimensions */ adios2::Engine reader = io.Open("testOperator.bp", adios2::Mode::Read); + reader.BeginStep(); auto var = io.InquireVariable("data"); if (!var) { @@ -61,7 +60,7 @@ int main(int argc, char *argv[]) if (config.empty()) { - io.SetEngine("BP4"); + io.SetEngine("BPFile"); /* PluginName -> is required. If your operator needs * other parameters, they can be passed in here as well. */ adios2::Params params; @@ -83,6 +82,7 @@ int main(int argc, char *argv[]) { std::cout << "data was not read correctly!" << std::endl; } + reader.EndStep(); /** Engine becomes unreachable after this*/ reader.Close(); diff --git a/examples/plugins/operator/examplePluginOperator_write.cpp b/examples/plugins/operator/examplePluginOperatorWrite.cpp similarity index 72% rename from examples/plugins/operator/examplePluginOperator_write.cpp rename to examples/plugins/operator/examplePluginOperatorWrite.cpp index e8cc86d3c6..2909b28bf7 100644 --- a/examples/plugins/operator/examplePluginOperator_write.cpp +++ b/examples/plugins/operator/examplePluginOperatorWrite.cpp @@ -26,18 +26,16 @@ int main(int argc, char *argv[]) /** Application variable */ std::vector myDoubles = { - 0.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 5.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 6.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 7.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 8.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, - 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, - 0.0001, + 0.0001, 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, + 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, + 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, + 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, + 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, + 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, + 6.0001, 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, + 7.0001, 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, + 8.0001, 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, + 9.0001, 8.0001, 7.0001, 6.0001, 5.0001, 4.0001, 3.0001, 2.0001, 1.0001, 0.0001, }; const std::size_t Nx = myDoubles.size(); @@ -53,12 +51,12 @@ int main(int argc, char *argv[]) /** global array: name, { shape (total dimensions) }, { start (local) }, * { count (local) }, all are constant dimensions */ - adios2::Variable var = io.DefineVariable( - "data", {}, {}, {Nx}, adios2::ConstantDims); + adios2::Variable var = + io.DefineVariable("data", {}, {}, {Nx}, adios2::ConstantDims); if (config.empty()) { - io.SetEngine("BP4"); + io.SetEngine("BPFile"); /* PluginName -> is required. If your operator needs * other parameters, they can be passed in here as well. */ adios2::Params params; @@ -70,7 +68,9 @@ int main(int argc, char *argv[]) adios2::Engine writer = io.Open("testOperator.bp", adios2::Mode::Write); + writer.BeginStep(); writer.Put(var, myDoubles.data()); + writer.EndStep(); /** Engine becomes unreachable after this*/ writer.Close(); diff --git a/examples/query/CMakeLists.txt b/examples/query/CMakeLists.txt deleted file mode 100644 index 444dda6fef..0000000000 --- a/examples/query/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -#------------------------------------------------------------------------------# -# Distributed under the OSI-approved Apache License, Version 2.0. See -# accompanying file Copyright.txt for details. -#------------------------------------------------------------------------------# - -if(ADIOS2_HAVE_MPI) - add_executable(queryTest test.cpp) - target_link_libraries(queryTest adios2::cxx11_mpi MPI::MPI_C) -endif() - diff --git a/examples/query/READ.ME b/examples/query/READ.ME deleted file mode 100644 index 65b8042d3e..0000000000 --- a/examples/query/READ.ME +++ /dev/null @@ -1,8 +0,0 @@ -q1.json is a json query file for one var - -q2.json is a composite query - -The bp*xml are the from heat transfer example with bp4 engine. -and tag is added at the end for xml query spec - -JSON query file option should be used with ADIOS2_HAVE_DATAMAN \ No newline at end of file diff --git a/examples/query/test.cpp b/examples/query/test.cpp deleted file mode 100644 index 49bb4bd139..0000000000 --- a/examples/query/test.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "adios2.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -//#include "adios2/toolkit/query/Worker.h" - -int main(int argc, char *argv[]) -{ - int provided; - - // MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP - MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - try - { - std::string configFileName = "query.xml"; - std::string dataFileName = "/tmp/heatbp4.bp"; - if (argc <= 2) - { - std::cout << "Usage: " << argv[0] - << " configFileName dataFilePath (queryFile)" - << std::endl; - std::cout << " e.g. " << argv[0] << " bp4io.xml heat_bp4.bp/ " - << std::endl; - std::cout << " or " << argv[0] - << " bp4io.xml heat_bp4.bp/ q1.json" << std::endl; - return 0; - } - - configFileName = argv[1]; - dataFileName = argv[2]; - - if (rank == 0) - { - std::cout << " using config file = " << configFileName << std::endl; - std::cout << " data file = " << dataFileName << std::endl; - } - - adios2::ADIOS ad = adios2::ADIOS(configFileName, MPI_COMM_WORLD); - - adios2::IO queryIO = ad.DeclareIO("query"); - adios2::Engine reader = - queryIO.Open(dataFileName, adios2::Mode::Read, MPI_COMM_WORLD); -#ifdef NEVER - adios2::QueryWorker w = adios2::QueryWorker(configFileName, reader); -#else - std::string queryFile = configFileName; - if (argc > 3) - { - queryFile = argv[3]; - } - std::cout << "Testing query file ..." << queryFile << std::endl; - adios2::QueryWorker w = adios2::QueryWorker(queryFile, reader); -#endif - std::vector> touched_blocks; - - while (reader.BeginStep() == adios2::StepStatus::OK) - { - adios2::Box empty; - w.GetResultCoverage(empty, touched_blocks); - // adios2::Box tt({10,10}, {12,12}); - // w.GetResultCoverage(tt, touched_blocks); - std::cout << " ... now can read out touched blocks ... size=" - << touched_blocks.size() << std::endl; - for (auto n : touched_blocks) - { - std::ostringstream startStr; - std::ostringstream countStr; - for (size_t k = 0; k < n.first.size(); k++) - { - startStr << n.first[k] << " "; - countStr << n.second[k] << " "; - } - std::cout << "\t[" << startStr.str() << "] [" << countStr.str() - << "]" << std::endl; - } - reader.EndStep(); - } - reader.Close(); - return 0; - } - catch (std::exception &e) - { - std::cout << "Exception, STOPPING PROGRAM from rank " << rank << "\n"; - std::cout << e.what() << "\n"; - } - - MPI_Finalize(); - - return 0; -} - -bool testMe(std::string &queryConfigFile, std::string const &doubleVarName, - MPI_Comm comm) -{ - adios2::ADIOS ad(queryConfigFile, comm); - std::string dataFileName = "test.file"; - - // adios2::query::Worker w(queryConfigFile, comm); - - // w.SetSource(inIO, reader); - - { - // the config file should have info on idx method to use - - /* - // if wanting to build customized minmax idx - // instead of using the existing block stats or bp4 minmax arrays - bool overwrite = false; - size_t recommendedSize = 20000; - - if (!w.PrepareIdx(overwrite, recommendedSize, doubleVarName)) - return false; - */ - } - - adios2::IO inIO = ad.DeclareIO("query"); - adios2::Engine reader = inIO.Open(dataFileName, adios2::Mode::Read, comm); - - // to be continued - if (!reader) - return false; - // std::vector dataOutput; - // std::vector coordinateOutput; - - return true; -} - -/* - */ diff --git a/examples/simulations/CMakeLists.txt b/examples/simulations/CMakeLists.txt new file mode 100644 index 0000000000..d6b6434beb --- /dev/null +++ b/examples/simulations/CMakeLists.txt @@ -0,0 +1,13 @@ +if(ADIOS2_HAVE_MPI) + add_subdirectory(gray-scott) + add_subdirectory(gray-scott-struct) + + if(ADIOS2_HAVE_Kokkos) + add_subdirectory(gray-scott-kokkos) + endif() + + add_subdirectory(heatTransfer) +endif() + +add_subdirectory(korteweg-de-vries) +add_subdirectory(lorenz_ode) diff --git a/examples/simulations/GrayScott.jl/.JuliaFormatter.toml b/examples/simulations/GrayScott.jl/.JuliaFormatter.toml new file mode 100644 index 0000000000..00db94693b --- /dev/null +++ b/examples/simulations/GrayScott.jl/.JuliaFormatter.toml @@ -0,0 +1,4 @@ +margin = 80 +join_lines_based_on_source = true +style = "sciml" +format_doctrings = true diff --git a/examples/simulations/GrayScott.jl/Project.toml b/examples/simulations/GrayScott.jl/Project.toml new file mode 100644 index 0000000000..a295ba3546 --- /dev/null +++ b/examples/simulations/GrayScott.jl/Project.toml @@ -0,0 +1,19 @@ +name = "GrayScott" +uuid = "089a57ea-382b-4fd7-9f05-24902db6ec52" +authors = ["William F Godoy "] +version = "0.1.0" + +[deps] +ADIOS2 = "e0ce9d3b-0dbd-416f-8264-ccca772f60ec" +AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" +ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267" +PProf = "e4faabce-9ead-11e9-39d9-4379958e3056" +Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[compat] +julia = "1.8" diff --git a/examples/simulations/GrayScott.jl/ReadMe.md b/examples/simulations/GrayScott.jl/ReadMe.md new file mode 100644 index 0000000000..2e12adb5d8 --- /dev/null +++ b/examples/simulations/GrayScott.jl/ReadMe.md @@ -0,0 +1,154 @@ +### ADIOS2 GrayScott.jl example + +Julia version +of [the gray-scott C++ and Python](https://github.com/ornladios/ADIOS2/blob/master/examples/simulations/gray-scott/) +example. + +This is a 3D 7-point stencil code to simulate the following [Gray-Scott +reaction diffusion model](https://doi.org/10.1126/science.261.5118.189): + +``` +u_t = Du * (u_xx + u_yy + u_zz) - u * v^2 + F * (1 - u) + noise * randn(-1,1) +v_t = Dv * (v_xx + v_yy + v_zz) + u * v^2 - (F + k) * v +``` + +This version contains: + +- CPU threaded solver using Julia's [multithreading]](https://docs.julialang.org/en/v1/manual/multi-threading/) +- GPU solvers using [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl), [AMDGPU.jl](https://github.com/JuliaGPU/AMDGPU.jl) +- Parallel I/O using the [ADIOS2.jl](https://github.com/eschnett/ADIOS2.jl) Julia bindings + to [ADIOS2](https://github.com/ornladios/ADIOS2) +- Message passing interface (MPI) using [MPI.jl](https://github.com/JuliaParallel/MPI.jl) Julia bindings to MPI +- Easily switch between float- (Float32) and double- (Float64) precision in the configuration file + +#### How to run + +Currently only the simulation part is ported from C++, the data analysis is work-in-progress. + +Pre-requisites: + +- A recent Julia version: v1.8.5 or v1.9.0-beta3 as of January 2023 + from [julialang.org/downloads](https://julialang.org/downloads/) + +##### Run locally + +1. **Set up dependencies** + +From the `GrayScott.jl` directory instantiate and use MPI artifact jll (preferred method). +To use a system provided MPI, see [here](https://juliaparallel.org/MPI.jl/latest/configuration/#using_system_mpi) + +```julia + +$ julia --project + +Julia REPL + +julia> ] + +(GrayScott.jl)> instantiate +... +(GrayScott.jl)> <- +julia> using MPIPreferences +julia> MPIPreferences.use_jll_binary() +julia> exit() +``` + +Julia manages its own packages using [Pkg.jl](https://pkgdocs.julialang.org/v1/), the above would create +platform-specific `LocalPreferences.toml` and `Manifest.toml` files. + +2. **Set up the examples/settings-files.json configuration file** + +``` +{ + "L": 64, + "Du": 0.2, + "Dv": 0.1, + "F": 0.02, + "k": 0.048, + "dt": 1.0, + "plotgap": 10, + "steps": 10000, + "noise": 0.1, + "output": "gs-julia-1MPI-64L-F32.bp", + "checkpoint": false, + "checkpoint_freq": 700, + "checkpoint_output": "ckpt.bp", + "restart": false, + "restart_input": "ckpt.bp", + "adios_config": "adios2.xml", + "adios_span": false, + "adios_memory_selection": false, + "mesh_type": "image", + "precision": "Float32", + "backend": "CPU" +} + +``` + +The file is nearly identical to the C++ original example. +Not all options are currently supported, but two Julia-only options are added: + + - "precision": either Float32 or Float64 in the array simulation (including GPUs) + - "backend": "CPU", "CUDA" or "AMDGPU" + +3. **Running the simulation** + +- `CPU threads`: launch julia assigning a number of threads (e.g. -t 8): + + ``` + $ julia --project -t 8 gray-scott.jl examples/settings-files.json + ``` + +- `CUDA/AMDGPU`: set the "backend" option in examples/settings-files.json to either "CUDA" or "AMDGPU" + + ``` + $ julia --project gray-scott.jl examples/settings-files.json + ``` + +This would generate an adios2 file from the output entry in the configuration file (e.g. `gs-julia-1MPI-64L-F32.bp`) +that can be visualized with ParaView with either the VTX or the FIDES readers. +**Important**: the AMDGPU.jl implementation of `randn` is currently work in progress. +See related issue [here](https://github.com/JuliaGPU/AMDGPU.jl/issues/378) + +4. **Running on OLCF Summit and Crusher systems** + The code was tested on the Oak Ridge National Laboratory Leadership Computing Facilities ( + OLCF): [Summit](https://docs.olcf.ornl.gov/systems/summit_user_guide.html) + and [Crusher](https://docs.olcf.ornl.gov/systems/crusher_quick_start_guide.html). Both are used testing a recent + version of Julia [v1.9.0-beta3](https://julialang.org/downloads/#upcoming_release) and a `JULIA_DEPOT_PATH` is + required to install packages and artifacts. **DO NOT USE your home directory**. We are providing configuration + scripts in `scripts/config_XXX.sh` showing the plumming required for these systems. They need to be executed only + once per session from the login nodes. + +To reuse these file the first 3 entries must be modified and run on login-nodes and the PATH poiting at a downloaded +Julia binary for the corresponding PowerPC (Summit) and x86-64 (Crusher) architectures. Only "CPU" and "CUDA" backends +are supported on Summit, while "CPU" and "AMDGPU" backends are supported on Crusher. + + ``` + ### Replace these 3 entries + PROJ_DIR=/gpfs/alpine/proj-shared/csc383 + export JULIA_DEPOT_PATH=$PROJ_DIR/etc/summit/julia_depot + GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + ... + ### and the path + export PATH=$PROJ_DIR/opt/summit/julia-1.9.0-beta3/bin:$PATH + ``` + +#### To-do list + +1. Add support including random number on device kernel code on `AMDGPU.jl` +2. Set the domain size `L` in the configuration file as a multiple of 6 for Summit, and a multiple of 4 on Crusher +3. Add data analysis: PDF for u and v and Julia 2D plotting capabilities: Plots.jl, Makie.jl +4. Add interactive computing with Pluto.jl notebooks + +#### Acknowledgements + +This research was supported by the Exascale Computing Project (17-SC-20-SC), a joint project of the U.S. Department of +Energy’s Office of Science and National Nuclear Security Administration, responsible for delivering a capable exascale +ecosystem, including software, applications, and hardware technology, to support the nation’s exascale computing +imperative. + +This research used resources of the Oak Ridge Leadership Computing Facility at the Oak Ridge National Laboratory, which +is supported by the Office of Science of the U.S. Department of Energy under Contract No. DE-AC05-00OR22725. + +Thanks to the Exascale Computing Project PROTEAS-TUNE and ADIOS subprojects, and the ASCR Bluestone. +Thanks to all the Julia community members, packages developers and maintainers for their great work. \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/examples/settings-files.json b/examples/simulations/GrayScott.jl/examples/settings-files.json new file mode 100644 index 0000000000..ab6b9cc9d4 --- /dev/null +++ b/examples/simulations/GrayScott.jl/examples/settings-files.json @@ -0,0 +1,23 @@ +{ + "L": 64, + "Du": 0.2, + "Dv": 0.1, + "F": 0.02, + "k": 0.048, + "dt": 1.0, + "plotgap": 10, + "steps": 10000, + "noise": 0.1, + "output": "gs-julia-1MPI-64L-F32.bp", + "checkpoint": false, + "checkpoint_freq": 700, + "checkpoint_output": "ckpt.bp", + "restart": false, + "restart_input": "ckpt.bp", + "adios_config": "adios2.xml", + "adios_span": false, + "adios_memory_selection": false, + "mesh_type": "image", + "precision": "Float32", + "backend": "CPU" +} \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/gray-scott.jl b/examples/simulations/GrayScott.jl/gray-scott.jl new file mode 100644 index 0000000000..2c1196beb9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/gray-scott.jl @@ -0,0 +1,15 @@ +import GrayScott + +# using Profile +# using PProf + +function julia_main()::Cint + GrayScott.main(ARGS) + return 0 +end + +if !isdefined(Base, :active_repl) + @time julia_main() + # @profile julia_main() + # pprof() +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/scripts/config_crusher.sh b/examples/simulations/GrayScott.jl/scripts/config_crusher.sh new file mode 100644 index 0000000000..3820dd297b --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/config_crusher.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +PROJ_DIR=/gpfs/alpine/proj-shared/csc383 +export JULIA_DEPOT_PATH=$PROJ_DIR/etc/crusher/julia_depot +GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + +# remove existing generated Manifest.toml +rm -f $GS_DIR/Manifest.toml +rm -f $GS_DIR/LocalPreferences.toml + +# good practice to avoid conflicts with existing default modules +module purge + +# load required modules +module load PrgEnv-cray/8.3.3 # has required gcc +module load cray-mpich +module load rocm/5.4.0 +module load adios2 # only works with PrgEnv-cray + +# existing julia 1.6 module is outdated +export PATH=$PROJ_DIR/opt/crusher/julia-1.9.0-beta3/bin:$PATH + +# Required to point at underlying modules above +export JULIA_AMDGPU_DISABLE_ARTIFACTS=1 +# Required to enable underlying ADIOS2 library from loaded module +export JULIA_ADIOS2_PATH=$OLCF_ADIOS2_ROOT + +# MPIPreferences to use spectrum-mpi +julia --project=$GS_DIR -e 'using Pkg; Pkg.add("MPIPreferences")' +julia --project=$GS_DIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(; library_names=["libmpi_cray"], mpiexec="srun")' + +# Regression being fixed with CUDA v4.0.0. CUDA.jl does lazy loading for portability to systems without NVIDIA GPUs +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(name="CUDA", version="v3.13.1")' + +# Instantiate the project by installing packages in Project.toml +julia --project=$GS_DIR -e 'using Pkg; Pkg.instantiate()' + +# Adds a custom branch in case the development version is needed (for devs to test new features) +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(url="https://github.com/eschnett/ADIOS2.jl.git", rev="main")' + +# Build the new ADIOS2 +julia --project=$GS_DIR -e 'using Pkg; Pkg.build()' +julia --project=$GS_DIR -e 'using Pkg; Pkg.precompile()' diff --git a/examples/simulations/GrayScott.jl/scripts/config_summit.sh b/examples/simulations/GrayScott.jl/scripts/config_summit.sh new file mode 100644 index 0000000000..d5f616ee31 --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/config_summit.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Replace these 3 entries +PROJ_DIR=/gpfs/alpine/proj-shared/csc383 +export JULIA_DEPOT_PATH=$PROJ_DIR/etc/summit/julia_depot +GS_DIR=$PROJ_DIR/wgodoy/ADIOS2/examples/simulations/GrayScott.jl + +# remove existing generated Manifest.toml +rm -f $GS_DIR/Manifest.toml +rm -f $GS_DIR/LocalPreferences.toml + +# good practice to avoid conflicts with existing default modules +# needed to avoid seg fault with MPI +module purge + +# load required modules +module load spectrum-mpi +module load gcc/12.1.0 # needed by julia libraries +module load cuda/11.0.3 # failure with 11.5.2 +module load adios2/2.8.1 +# module load julia/1.8.2 not working with CUDA.jl as it's missing libLLVM-13jl.so +export PATH=$PROJ_DIR/opt/summit/julia-1.9.0-beta3/bin:$PATH + +# Required to enable underlying ADIOS2 library from loaded module +export JULIA_ADIOS2_PATH=$OLCF_ADIOS2_ROOT + +# MPIPreferences to use spectrum-mpi +julia --project=$GS_DIR -e 'using Pkg; Pkg.add("MPIPreferences")' +julia --project=$GS_DIR -e 'using MPIPreferences; MPIPreferences.use_system_binary(; library_names=["libmpi_ibm"], mpiexec="jsrun")' + +# Instantiate the project by installing packages in Project.toml +julia --project=$GS_DIR -e 'using Pkg; Pkg.instantiate()' + +# Adds to LocalPreferences.toml to use underlying system CUDA since CUDA.jl v4.0.0 +# https://cuda.juliagpu.org/stable/installation/overview/#Using-a-local-CUDA +julia --project=$GS_DIR -e 'using CUDA; CUDA.set_runtime_version!("local")' + +# Adds a custom branch in case the development version is needed (for devs to test new features) +julia --project=$GS_DIR -e 'using Pkg; Pkg.add(url="https://github.com/eschnett/ADIOS2.jl.git", rev="main")' + +# Build the new ADIOS2 +julia --project=$GS_DIR -e 'using Pkg; Pkg.build()' +julia --project=$GS_DIR -e 'using Pkg; Pkg.precompile()' diff --git a/examples/simulations/GrayScott.jl/scripts/job_crusher.sh b/examples/simulations/GrayScott.jl/scripts/job_crusher.sh new file mode 100644 index 0000000000..ee4953f6d1 --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/job_crusher.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#SBATCH -A CSC383_crusher +#SBATCH -J gs-julia-1MPI-1GPU +#SBATCH -o %x-%j.out +#SBATCH -e %x-%j.err +#SBATCH -t 0:02:00 +#SBATCH -p batch +#SBATCH -N 1 + +date + +GS_DIR=/gpfs/alpine/proj-shared/csc383/wgodoy/ADIOS2/examples/simulations/GrayScott.jl +GS_EXE=$GS_DIR/gray-scott.jl + +srun -n 1 --gpus=1 julia --project=$GS_DIR $GS_EXE settings-files.json + +# launch this file with sbatch `$ sbatch job_crusher.sh` diff --git a/examples/simulations/GrayScott.jl/scripts/job_summit.sh b/examples/simulations/GrayScott.jl/scripts/job_summit.sh new file mode 100644 index 0000000000..9beffc157f --- /dev/null +++ b/examples/simulations/GrayScott.jl/scripts/job_summit.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Begin LSF directives +#BSUB -P csc383 +#BSUB -W 00:02 +#BSUB -nnodes 1 +#BSUB -J gs-julia +#BSUB -o output.%J +#BSUB -e output.%J +#BSUB -N godoywf@ornl.gov +# End BSUB directives and begin shell commands + +date +GS_DIR=/gpfs/alpine/proj-shared/csc383/wgodoy/ADIOS2/examples/simulations/GrayScott.jl +GS_EXE=$GS_DIR/gray-scott.jl + +jsrun -n 1 -g 1 julia --project=$GS_DIR $GS_EXE settings-files.json + +# launch this file with bsub `$ bsub job_summit.sh` diff --git a/examples/simulations/GrayScott.jl/src/GrayScott.jl b/examples/simulations/GrayScott.jl/src/GrayScott.jl new file mode 100644 index 0000000000..d50c1abb09 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/GrayScott.jl @@ -0,0 +1,91 @@ +""" +GrayScott.jl is a Simulation and Analysis parallel framework for solving the +Gray-Scott 3D diffusion reaction system of equations of two variables U and V on +a regular Cartesian mesh. + +The bp output files can be visualized with ParaView. +""" +module GrayScott + +import MPI, ADIOS2 + +# contains relevant data containers "structs" for Input, Domain and Fields +include(joinpath("simulation", "Structs.jl")) + +# contains helper functions for general use +include(joinpath("helper", "Helper.jl")) +import .Helper + +# initializes inputs from configuration file +include(joinpath("simulation", "Inputs.jl")) +import .Inputs + +# manages the simulation computation +include(joinpath("simulation", "Simulation.jl")) +import .Simulation + +# manages the I/O +include(joinpath("simulation", "IO.jl")) +import .IO + +function julia_main()::Cint + try + main(ARGS) + catch + Base.invokelatest(Base.display_error, Base.catch_stack()) + return 1 + end + return 0 +end + +function main(args::Vector{String})::Int32 + MPI.Init() + comm = MPI.COMM_WORLD + rank = MPI.Comm_rank(comm) + size = MPI.Comm_size(comm) + + # a data struct that holds settings data from config_file in args + # example config file: ../examples/settings-files.json + settings = Inputs.get_settings(args, comm) + + # initialize MPI Cartesian Domain and Communicator + mpi_cart_domain = Simulation.init_domain(settings, comm) + + # initialize fields + fields = Simulation.init_fields(settings, + mpi_cart_domain, + Helper.get_type(settings.precision)) + + # initialize IOStream struct holding ADIOS-2 components for parallel I/O + stream = IO.init(settings, mpi_cart_domain, fields) + + restart_step::Int32 = 0 + # @TODO: checkpoint-restart + step::Int32 = restart_step + + while step < settings.steps + Simulation.iterate!(fields, settings, mpi_cart_domain) + step += 1 + + if step % settings.plotgap == 0 + if rank == 0 + println("Simulation at step ", step, " writing output step ", + step / settings.plotgap) + end + + IO.write_step!(stream, step, fields) + end + end + + IO.close!(stream) + + # Debugging session or Julia REPL session, not needed overall as it would be + # called when the program ends + if !isinteractive() + MPI.Finalize() + end + + return 0 +end + +end # module GrayScott diff --git a/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl b/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl new file mode 100644 index 0000000000..f7fb0bb33f --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/analysis/pdfcalc.jl @@ -0,0 +1,160 @@ + +import MPI +import ArgParse +import ADIOS2 + +function _epsilon(d::T)::Bool where {T <: Number} + return (d < 1.0e-20) +end + +""" +Return 2 arrays pdf and bins of a 2D slice +""" +function _compute_pdf(data::Array{T, 3}, shape, count, nbins, min::T, + max::T) where {T} + pdf = Array{T, 2}(undef, nbins, count) + bins = Array{T, 1}(undef, nbins) + bin_width = (max - min) / nbins + + for i in 1:nbins + bins[i] = min + (i - 1) * bin_width + end + + slice_size = shape[2] * shape[3] + # special case: only one bin or small window + if nbins == 1 || _epsilon(max - min) || _epsilon(bin_width) + fill!(pdf, slice_size) + return pdf, bins + end + + # Calculate a PDF for 'nbins' bins for values between 'min' and 'max' + + for c in 1:count + for j in 1:shape[2] + for k in 1:shape[3] + value = data[k, j, c] + + if value > max || value < min + @show value, " is outside [", min, max "]" + end + bin = floor((value - min) / bin_width) + + if bin == nbins + bin = nbins - 1 + end + pdf[bin, c] += 1 + end + end + end +end + +function _parse_arguments(args) + s = ArgParse.ArgParseSettings(description = "gray-scott workflow pdf generator, Julia version") + + # @add_arg_table! s begin + # "--opt1" # an option (will take an argument) + # "--opt2", "-o" # another option, with short form + # "arg1" # a positional argument + # end + + ArgParse.@add_arg_table! s begin + "input" + help = "Name of the input file handle for reading data" + arg_type = String + required = true + "output" + help = "Name of the output file to which data must be written" + arg_type = String + required = true + "N" + help = "Number of bins for the PDF calculation, default = 1000" + arg_type = Int64 + required = false + default = 1000 + "output_inputdata" + help = "YES will write the original variables besides the analysis results" + arg_type = Bool + required = false + default = false + end + + # parse_args return a dictionary with key/value for arguments + parsed_arguments = ArgParse.parse_args(args, s) + return parsed_arguments +end + +function _read_data_write_pdf(inputs, comm) + in_filename = inputs["input"] + out_filename = inputs["output"] + nbins = inputs["N"] + write_inputvars = inputs["output_inputdata"] + + adios = ADIOS2.adios_init_mpi("adios2.xml", comm) + + reader_io = ADIOS2.declare_io(adios, "SimulationOutput") + writer_io = ADIOS2.declare_io(adios, "PDFAnalysisOutput") + + rank = MPI.Comm_rank(comm) + size = MPI.Comm_size(comm) + + if rank == 0 + println("PDF analysis reads from Simulation using engine type: ", + ADIOS2.engine_type(reader_io)) + println("PDF analysis writes using engine type: ", + ADIOS2.engine_type(writer_io)) + end + + # Engines for reading and writing + reader = ADIOS2.open(reader_io, inputs["input"], ADIOS2.mode_read) + writer = ADIOS2.open(writer_io, inputs["output"], ADIOS2.mode_write) + + # break inside if needed + while true + + # timeout is 10 seconds + read_status = ADIOS2.begin_step(reader, ADIOS2.step_mode_read, 10) + + if read_status == ADIOS2.step_status_not_ready + # sleep in seconds, minimum is one milisecond = 0.001 + sleep(1) + continue + else if read_status != ADIOS2.step_status_ok + break + end + + step_sim_out = ADIOS2.current_step(reader) + var_U = ADIOS2.inquire_variable(reader_io, "U") + var_V = ADIOS2.inquire_variable(reader_io, "V") + var_step = ADIOS2.inquire_variable(reader_io, "step") + + shape = ADIOS2.shape(var_U) + + # Split in the slowest dimension + count_z = shape[3] / size + start_z = count_z * rank + + # Last process needs to read all the rest + if rank == size-1 + count_z = shape[3] - count_z * (size-1) + end + + # missing set_selection + start = ( 0,0,start_z) + count = (shape[1], shape[2], count_z) + ADIOS2.set_selection(var_U, start, count) + ADIOS2.set_selection(var_V, start, count) + + # Calculate + + end +end + +function main(args) + MPI.Init() + + inputs = _parse_arguments(args) + comm = MPI.COMM_WORLD + _read_data_write_pdf(inputs, comm) + + MPI.Finalize() +end diff --git a/examples/simulations/GrayScott.jl/src/helper/Helper.jl b/examples/simulations/GrayScott.jl/src/helper/Helper.jl new file mode 100644 index 0000000000..757c571714 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/Helper.jl @@ -0,0 +1,7 @@ + +module Helper + +include("helperMPI.jl") +include("helperString.jl") + +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl b/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl new file mode 100644 index 0000000000..529d7e0420 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/helperMPI.jl @@ -0,0 +1,15 @@ + +import MPI + +export bcase_file + +function bcast_file_contents(file_name::String, comm, root = 0)::String + size::UInt32 = 0 + data::Vector{UInt8} = [] + if MPI.Comm_rank(comm) == root + data = read(open(file_name, "r")) + end + + data = MPI.bcast(data, comm) + return String(data) +end diff --git a/examples/simulations/GrayScott.jl/src/helper/helperString.jl b/examples/simulations/GrayScott.jl/src/helper/helperString.jl new file mode 100644 index 0000000000..596a2f0b94 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/helper/helperString.jl @@ -0,0 +1,14 @@ + +export get_type + +function get_type(input::String) + if input == "Float64" + return Float64 + elseif input == "Float32" + return Float32 + elseif input == "Float16" + return Float16 + end + + return nothing +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/simulation/IO.jl b/examples/simulations/GrayScott.jl/src/simulation/IO.jl new file mode 100644 index 0000000000..deb3a24ae8 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/IO.jl @@ -0,0 +1,106 @@ +module IO + +export init, write_step! + +# import external module +import ADIOS2 + +# internal submodule +import ..Simulation +# types from parent module types in Structs.jl +import ..Settings, ..MPICartDomain, ..Fields, ..IOStream + +function init(settings::Settings, mcd::MPICartDomain, + fields::Fields{T}) where {T} + + # initialize adios MPI using the cartesian communicator + adios = ADIOS2.adios_init_mpi(mcd.cart_comm) + io = ADIOS2.declare_io(adios, "SimulationOutput") + # @TODO: implement ADIOS2.set_engine in ADIOS2.jl + engine = ADIOS2.open(io, settings.output, ADIOS2.mode_write) + + # store simulation run provenance as attributes + ADIOS2.define_attribute(io, "F", settings.F) + ADIOS2.define_attribute(io, "k", settings.k) + ADIOS2.define_attribute(io, "dt", settings.dt) + ADIOS2.define_attribute(io, "Du", settings.Du) + ADIOS2.define_attribute(io, "Dv", settings.Dv) + ADIOS2.define_attribute(io, "noise", settings.noise) + + _add_visualization_schemas(io, settings.L) + + # ADIOS2 requires tuples for the dimensions + # define global variables u and v + shape = (settings.L, settings.L, settings.L) + start = Tuple(mcd.proc_offsets) + count = Tuple(mcd.proc_sizes) + + var_step = ADIOS2.define_variable(io, "step", Int32) + var_U = ADIOS2.define_variable(io, "U", T, shape, start, count) + var_V = ADIOS2.define_variable(io, "V", T, shape, start, count) + + return IOStream(adios, io, engine, var_step, var_U, var_V) +end + +function write_step!(stream::IOStream, step::Int32, fields::Fields{T}) where {T} + + # this creates temporaries similar to Fortran + u_no_ghost, v_no_ghost = Simulation.get_fields(fields) + + # writer engine + w = stream.engine + + ADIOS2.begin_step(w) + ADIOS2.put!(w, stream.var_step, step) + ADIOS2.put!(w, stream.var_U, u_no_ghost) + ADIOS2.put!(w, stream.var_V, v_no_ghost) + ADIOS2.end_step(w) +end + +function close!(stream::IOStream) + ADIOS2.close(stream.engine) + ADIOS2.adios_finalize(stream.adios) +end + +function _add_visualization_schemas(io, length) + + # Fides schema + ADIOS2.define_attribute(io, "Fides_Data_Model", "uniform") + ADIOS2.define_attribute_array(io, "Fides_Origin", [0.0, 0.0, 0.0]) + ADIOS2.define_attribute_array(io, "Fides_Spacing", [0.1, 0.1, 0.1]) + ADIOS2.define_attribute(io, "Fides_Dimension_Variable", "U") + ADIOS2.define_attribute_array(io, "Fides_Variable_List", ["U", "V"]) + ADIOS2.define_attribute_array(io, "Fides_Variable_Associations", + ["points", "points"]) + + # VTX schema + # string concatenation uses *, ^ is for repetition + # if length = 64 + # extent = "0 64 0 64 0 64 " + extent = ("0 " * string(length) * " ")^3 + extent = rstrip(extent) + + # deactive code formatting using JuliaFormatter.jl + # raw strings: " must be escaped with \" + #! format: off + vtx_schema = raw" + + + + + + + + + step + + + + + " + #! format: on + # reactive code formatting using JuliaFormatter.jl + ADIOS2.define_attribute(io, "vtk.xml", vtx_schema) +end + +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl b/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl new file mode 100644 index 0000000000..a4160ce1d8 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Inputs.jl @@ -0,0 +1,78 @@ + +""" +Submodule used by GrayScott to handle inputs +""" +module Inputs + +export get_settings + +import ArgParse +import JSON + +import ..Helper +# import directly from parent module (GrayScott) +import ..Settings, ..SettingsKeys + +# public facing function +function get_settings(args::Vector{String}, comm)::Settings + config_file = _parse_args(args) + + # check format extension + if !endswith(config_file, ".json") && + !(endswith(config_file, ".yaml") || endswith(config_file, ".yml")) + throw(ArgumentError("config file must be json, yaml format. Extension not recognized.\n")) + end + + config_file_contents::String = Helper.bcast_file_contents(config_file, comm) + + if endswith(config_file, ".json") + return _parse_settings_json(config_file_contents) + end + + return nothing +end + +# local scope functions +function _parse_args(args::Vector{String}; + error_handler = ArgParse.default_handler)::String + s = ArgParse.ArgParseSettings(description = "gray-scott workflow simulation example configuration file, Julia version, GrayScott.jl", + exc_handler = error_handler) + + # @add_arg_table! s begin + # "--opt1" # an option (will take an argument) + # "--opt2", "-o" # another option, with short form + # "arg1" # a positional argument + # end + + ArgParse.@add_arg_table! s begin + "config_file" + help = "configuration file" + arg_type = String + required = true + end + + # parse_args return a dictionary with key/value for arguments + parsed_arguments = ArgParse.parse_args(args, s) + + # key is mandatory, so it's safe to retrieve + config_file::String = parsed_arguments["config_file"] + + return config_file +end + +function _parse_settings_json(json_contents::String)::Settings + json = JSON.parse(json_contents) + settings = Settings() + + # Iterate through dictionary pairs + for (key, value) in json + # Iterate through predefined keys, else ignore (no error if unrecognized) + if key in SettingsKeys + setproperty!(settings, Symbol(key), value) + end + end + + return settings +end + +end # module \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl new file mode 100644 index 0000000000..f3cbf3325c --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation.jl @@ -0,0 +1,281 @@ +""" +The present file contains runtime backend for using CPU Threads, and optionally +CUDA.jl and AMDGPU.jl +""" +module Simulation + +export init_domain, init_fields + +import MPI +import Distributions + +# from parent module +import ..Settings, ..MPICartDomain, ..Fields + +# include functions for NVIDIA GPUs using CUDA.jl +include("Simulation_CUDA.jl") +# include functions for AMD GPUs using AMDGPU.jl +include("Simulation_AMDGPU.jl") + +function init_domain(settings::Settings, comm::MPI.Comm)::MPICartDomain + mcd = MPICartDomain() + + # set dims and Cartesian communicator + mcd.dims = MPI.Dims_create(MPI.Comm_size(comm), mcd.dims) + mcd.cart_comm = MPI.Cart_create(comm, mcd.dims) + + # set proc local coordinates in Cartesian communicator + rank = MPI.Comm_rank(comm) + mcd.coords = MPI.Cart_coords(mcd.cart_comm, rank) + + # set proc local mesh sizes + mcd.proc_sizes = settings.L ./ mcd.dims + + for (i, coord) in enumerate(mcd.coords) + if coord < settings.L % mcd.dims[i] + mcd.proc_sizes[i] += 1 + end + end + + # set proc local offsets + for i in 1:3 + mcd.proc_offsets[i] = settings.L / mcd.dims[i] * + mcd.coords[i] + +min(settings.L % mcd.dims[i], mcd.coords[i]) + end + + # get neighbors ranks + mcd.proc_neighbors["west"], + mcd.proc_neighbors["east"] = MPI.Cart_shift(mcd.cart_comm, 0, 1) + mcd.proc_neighbors["down"], + mcd.proc_neighbors["up"] = MPI.Cart_shift(mcd.cart_comm, 1, 1) + mcd.proc_neighbors["south"], + mcd.proc_neighbors["north"] = MPI.Cart_shift(mcd.cart_comm, 2, 1) + + return mcd +end + +""" +Create and Initialize fields for either CPU, CUDA.jl, AMDGPU.jl backends +Multiple dispatch would direct to the appropriate overleaded function +""" +function init_fields(settings::Settings, + mcd::MPICartDomain, T)::Fields{T} + lowercase_backend = lowercase(settings.backend) + if lowercase_backend == "cuda" + return _init_fields_cuda(settings, mcd, T) + elseif lowercase_backend == "amdgpu" + return _init_fields_amdgpu(settings, mcd, T) + end + # everything else would trigger the CPU threads backend + return _init_fields_cpu(settings, mcd, T) +end + +function _init_fields_cpu(settings::Settings, + mcd::MPICartDomain, T)::Fields{T} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = ones(T, size_x + 2, size_y + 2, size_z + 2) + v = zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = zeros(T, size_x + 2, size_y + 2, size_z + 2) + + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + d::Int64 = 6 + + # global locations + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + xoff = mcd.proc_offsets[1] + yoff = mcd.proc_offsets[2] + zoff = mcd.proc_offsets[3] + + Threads.@threads for z in minL:maxL + for y in minL:maxL + for x in minL:maxL + if !is_inside(x, y, z, mcd.proc_offsets, mcd.proc_sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, y - yoff + 2, z - zoff + 2] = 0.25 + v[x - xoff + 2, y - yoff + 2, z - zoff + 2] = 0.33 + end + end + end + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, Array{T, N}}, settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _get_mpi_faces(size_x, size_y, size_z, T) + + ## create a new type taking: count, block length, stride + ## to interoperate with MPI for ghost cell exchange + xy_face_t = MPI.Types.create_vector(size_y + 2, size_x, size_x + 2, + MPI.Datatype(T)) + xz_face_t = MPI.Types.create_vector(size_z, size_x, + (size_x + 2) * (size_y + 2), + MPI.Datatype(T)) + yz_face_t = MPI.Types.create_vector((size_y + 2) * (size_z + 2), 1, + size_x + 2, MPI.Datatype(T)) + MPI.Types.commit!(xy_face_t) + MPI.Types.commit!(xz_face_t) + MPI.Types.commit!(yz_face_t) + + return xy_face_t, xz_face_t, yz_face_t +end + +function _exchange!(fields, mcd) + """ + Send XY face z=size_z+1 to north and receive z=1 from south + """ + function _exchange_xy!(var, size_z, data_type, rank1, rank2, comm) + # to north + send_buf = MPI.Buffer(@view(var[2, 1, size_z + 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to south + send_buf = MPI.Buffer(@view(var[2, 1, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, size_z + 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + """ + Send XZ face y=size_y+1 to up and receive y=1 from down + """ + function _exchange_xz!(var, size_y, data_type, rank1, rank2, comm) + # to up + send_buf = MPI.Buffer(@view(var[2, size_y + 1, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, 1, 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to down + send_buf = MPI.Buffer(@view(var[2, 2, 2]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[2, size_y + 2, 2]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + """ + Send YZ face x=size_x+2 to east and receive x=2 from west + """ + function _exchange_yz!(var, size_x, data_type, rank1, rank2, comm) + # to east + send_buf = MPI.Buffer(@view(var[size_x + 1, 1, 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[1, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank1, source = rank2) + + # to west + send_buf = MPI.Buffer(@view(var[2, 1, 1]), 1, data_type) + recv_buf = MPI.Buffer(@view(var[size_x + 2, 1, 1]), 1, data_type) + MPI.Sendrecv!(send_buf, recv_buf, comm, dest = rank2, source = rank1) + end + + # if already a CPU array, no need to copy, + # otherwise (device) copy to host. + u = typeof(fields.u) <: Array ? fields.u : Array(fields.u) + v = typeof(fields.v) <: Array ? fields.v : Array(fields.v) + + for var in [u, v] + _exchange_xy!(var, mcd.proc_sizes[3], fields.xy_face_t, + mcd.proc_neighbors["north"], mcd.proc_neighbors["south"], + mcd.cart_comm) + + _exchange_xz!(var, mcd.proc_sizes[2], fields.xz_face_t, + mcd.proc_neighbors["up"], mcd.proc_neighbors["down"], + mcd.cart_comm) + + _exchange_yz!(var, mcd.proc_sizes[1], fields.yz_face_t, + mcd.proc_neighbors["east"], mcd.proc_neighbors["west"], + mcd.cart_comm) + end +end + +function _calculate!(fields::Fields{T, N, Array{T, N}}, settings::Settings, + mcd::MPICartDomain) where {T, N} + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + # loop through non-ghost cells, bounds are inclusive + # @TODO: load balancing? option: a big linear loop + # use @inbounds at the right for-loop level, avoid putting it at the top level + Threads.@threads for k in 2:(mcd.proc_sizes[3] + 1) + for j in 2:(mcd.proc_sizes[2] + 1) + @inbounds for i in 2:(mcd.proc_sizes[1] + 1) + u = fields.u[i, j, k] + v = fields.v[i, j, k] + + # introduce a random disturbance on du + du = Du * _laplacian(i, j, k, fields.u) - u * v^2 + + F * (1.0 - u) + + noise * rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, fields.v) + u * v^2 - + (F + K) * v + + # advance the next step + fields.u_temp[i, j, k] = u + du * dt + fields.v_temp[i, j, k] = v + dv * dt + end + end + end +end + +""" + 7-point stencil around the cell, + this is equally a host and a device function! +""" +function _laplacian(i, j, k, var) + @inbounds l = var[i - 1, j, k] + var[i + 1, j, k] + var[i, j - 1, k] + + var[i, j + 1, k] + var[i, j, k - 1] + var[i, j, k + 1] - + 6.0 * var[i, j, k] + return l / 6.0 +end + +function get_fields(fields::Fields{T, N, Array{T, N}}) where {T, N} + @inbounds begin + u_no_ghost = fields.u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + v_no_ghost = fields.v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + end + return u_no_ghost, v_no_ghost +end + +end # module diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl new file mode 100644 index 0000000000..8920167779 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation_AMDGPU.jl @@ -0,0 +1,168 @@ + +import AMDGPU + +function _init_fields_amdgpu(settings::Settings, mcd::MPICartDomain, + T)::Fields{T, 3, <:AMDGPU.ROCArray{T, 3}} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = AMDGPU.ones(T, size_x + 2, size_y + 2, size_z + 2) + v = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = AMDGPU.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + roc_offsets = AMDGPU.ROCArray(mcd.proc_offsets) + roc_sizes = AMDGPU.ROCArray(mcd.proc_sizes) + + d::Int64 = 6 + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + # @TODO: get ideal grid size and threads + threads = (16, 16) + # grid size must be the total number of threads of each direction + grid = (settings.L, settings.L) + + AMDGPU.wait(AMDGPU.@roc groupsize=threads gridsize=grid _populate_amdgpu!(u, + v, + roc_offsets, + roc_sizes, + minL, + maxL)) + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _populate_amdgpu!(u, v, offsets, sizes, minL, maxL) + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + # local coordinates (this are 1-index already) + lz = (AMDGPU.workgroupIdx().x - Int32(1)) * AMDGPU.workgroupDim().x + + AMDGPU.workitemIdx().x + ly = (AMDGPU.workgroupIdx().y - Int32(1)) * AMDGPU.workgroupDim().y + + AMDGPU.workitemIdx().y + + # This check might not be needed + if lz <= size(u, 3) && ly <= size(u, 2) + + # get global coordinates + z = lz + offsets[3] - 1 + y = ly + offsets[2] - 1 + + if z >= minL && z <= maxL && y >= minL && y <= maxL + xoff = offsets[1] + + for x in minL:maxL + # check if global coordinates for initialization are inside the region + if !is_inside(x, y, z, offsets, sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, ly + 1, lz + 1] = 0.25 + v[x - xoff + 2, ly + 1, lz + 1] = 0.33 + end + end + end +end + +function _calculate!(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + roc_sizes = AMDGPU.ROCArray(mcd.proc_sizes) + + threads = (16, 16) + blocks = (settings.L, settings.L) + + AMDGPU.wait(AMDGPU.@roc groupsize=threads gridsize=grid _calculate_kernel_amdgpu!(fields.u, + fields.v, + fields.u_temp, + fields.v_temp, + roc_sizes, + Du, + Dv, + F, + K, + noise, + dt)) +end + +function _calculate_kernel_amdgpu!(u, v, u_temp, v_temp, sizes, Du, Dv, F, K, + noise, dt) + + # local coordinates (this are 1-index already) + k = (AMDGPU.workgroupIdx().x - Int32(1)) * AMDGPU.workgroupDim().x + + AMDGPU.workitemIdx().x + j = (AMDGPU.workgroupIdx().y - Int32(1)) * AMDGPU.workgroupDim().y + + AMDGPU.workitemIdx().y + + # loop through non-ghost cells + if k >= 2 && k <= sizes[3] + 1 && j >= 2 && j <= sizes[2] + 1 + # bounds are inclusive + for i in 2:(sizes[1] + 1) + u_ijk = u[i, j, k] + v_ijk = v[i, j, k] + + du = Du * _laplacian(i, j, k, u) - u_ijk * v_ijk^2 + + F * (1.0 - u_ijk) + # + noise * AMDGPU.rand(eltype(u)) + # WIP in AMDGPU.jl, works with CUDA.jl + # + rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, v) + u_ijk * v_ijk^2 - + (F + K) * v_ijk + + # advance the next step + u_temp[i, j, k] = u_ijk + du * dt + v_temp[i, j, k] = v_ijk + dv * dt + end + end +end + +function get_fields(fields::Fields{T, N, <:AMDGPU.ROCArray{T, N}}) where {T, N} + u = Array(fields.u) + u_no_ghost = u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + + v = Array(fields.v) + v_no_ghost = v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + return u_no_ghost, v_no_ghost +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl b/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl new file mode 100644 index 0000000000..ee470f00ec --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Simulation_CUDA.jl @@ -0,0 +1,160 @@ + +import CUDA + +function _init_fields_cuda(settings::Settings, mcd::MPICartDomain, + T)::Fields{T, 3, <:CUDA.CuArray{T, 3}} + size_x = mcd.proc_sizes[1] + size_y = mcd.proc_sizes[2] + size_z = mcd.proc_sizes[3] + + # should be ones + u = CUDA.ones(T, size_x + 2, size_y + 2, size_z + 2) + v = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + u_temp = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + v_temp = CUDA.zeros(T, size_x + 2, size_y + 2, size_z + 2) + + cu_offsets = CUDA.CuArray(mcd.proc_offsets) + cu_sizes = CUDA.CuArray(mcd.proc_sizes) + + d::Int64 = 6 + minL = Int64(settings.L / 2 - d) + maxL = Int64(settings.L / 2 + d) + + # @TODO: get ideal blocks and threads + threads = (16, 16) + blocks = (settings.L, settings.L) + + CUDA.@cuda threads=threads blocks=blocks _populate_cuda!(u, v, + cu_offsets, + cu_sizes, + minL, maxL) + CUDA.synchronize() + + xy_face_t, xz_face_t, yz_face_t = _get_mpi_faces(size_x, size_y, size_z, T) + + fields = Fields(u, v, u_temp, v_temp, xy_face_t, xz_face_t, yz_face_t) + return fields +end + +function iterate!(fields::Fields{T, N, <:CUDA.CuArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + _exchange!(fields, mcd) + # this function is the bottleneck + _calculate!(fields, settings, mcd) + + # swap the names + fields.u, fields.u_temp = fields.u_temp, fields.u + fields.v, fields.v_temp = fields.v_temp, fields.v +end + +function _populate_cuda!(u, v, offsets, sizes, minL, maxL) + function is_inside(x, y, z, offsets, sizes)::Bool + if x < offsets[1] || x >= offsets[1] + sizes[1] + return false + end + if y < offsets[2] || y >= offsets[2] + sizes[2] + return false + end + if z < offsets[3] || z >= offsets[3] + sizes[3] + return false + end + + return true + end + + # local coordinates (this are 1-index already) + lz = (CUDA.blockIdx().x - Int32(1)) * CUDA.blockDim().x + + CUDA.threadIdx().x + ly = (CUDA.blockIdx().y - Int32(1)) * CUDA.blockDim().y + + CUDA.threadIdx().y + + if lz <= size(u, 3) && ly <= size(u, 2) + + # get global coordinates + z = lz + offsets[3] - 1 + y = ly + offsets[2] - 1 + + if z >= minL && z <= maxL && y >= minL && y <= maxL + xoff = offsets[1] + + for x in minL:maxL + # check if global coordinates for initialization are inside the region + if !is_inside(x, y, z, offsets, sizes) + continue + end + + # Julia is 1-index, like Fortran :) + u[x - xoff + 2, ly + 1, lz + 1] = 0.25 + v[x - xoff + 2, ly + 1, lz + 1] = 0.33 + end + end + end +end + +function _calculate!(fields::Fields{T, N, <:CUDA.CuArray{T, N}}, + settings::Settings, + mcd::MPICartDomain) where {T, N} + function _calculate_kernel!(u, v, u_temp, v_temp, sizes, Du, Dv, F, K, + noise, dt) + + # local coordinates (this are 1-index already) + k = (CUDA.blockIdx().x - Int32(1)) * CUDA.blockDim().x + + CUDA.threadIdx().x + j = (CUDA.blockIdx().y - Int32(1)) * CUDA.blockDim().y + + CUDA.threadIdx().y + + # loop through non-ghost cells + if k >= 2 && k <= sizes[3] + 1 && j >= 2 && j <= sizes[2] + 1 + # bounds are inclusive + for i in 2:(sizes[1] + 1) + u_ijk = u[i, j, k] + v_ijk = v[i, j, k] + + du = Du * _laplacian(i, j, k, u) - u_ijk * v_ijk^2 + + F * (1.0 - u_ijk) + + noise * rand(Distributions.Uniform(-1, 1)) + + dv = Dv * _laplacian(i, j, k, v) + u_ijk * v_ijk^2 - + (F + K) * v_ijk + + # advance the next step + u_temp[i, j, k] = u_ijk + du * dt + v_temp[i, j, k] = v_ijk + dv * dt + end + end + end + + Du = convert(T, settings.Du) + Dv = convert(T, settings.Dv) + F = convert(T, settings.F) + K = convert(T, settings.k) + noise = convert(T, settings.noise) + dt = convert(T, settings.dt) + + cu_sizes = CUDA.CuArray(mcd.proc_sizes) + + threads = (16, 16) + blocks = (settings.L, settings.L) + + CUDA.@cuda threads=threads blocks=blocks _calculate_kernel!(fields.u, + fields.v, + fields.u_temp, + fields.v_temp, + cu_sizes, + Du, Dv, F, K, + noise, dt) + CUDA.synchronize() +end + +function get_fields(fields::Fields{T, N, <:CUDA.CuArray{T, N}}) where {T, N} + u = Array(fields.u) + u_no_ghost = u[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + + v = Array(fields.v) + v_no_ghost = v[(begin + 1):(end - 1), (begin + 1):(end - 1), + (begin + 1):(end - 1)] + return u_no_ghost, v_no_ghost +end diff --git a/examples/simulations/GrayScott.jl/src/simulation/Structs.jl b/examples/simulations/GrayScott.jl/src/simulation/Structs.jl new file mode 100644 index 0000000000..ca35fb5611 --- /dev/null +++ b/examples/simulations/GrayScott.jl/src/simulation/Structs.jl @@ -0,0 +1,102 @@ + +""" +Settings carry the settings from the simulation config file (json or yaml formats) + +Using Base.@kwdef macro for easy defaults and enable keyword arguments +Settings(Du = 0.2, noise = 0.2) +See: +https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408/24?u=williamfgc +""" +Base.@kwdef mutable struct Settings + L::Int64 = 128 + steps::Int32 = 20000 + plotgap::Int32 = 200 + F::Float64 = 0.04 + k::Float64 = 0 + dt::Float64 = 0.2 + Du::Float64 = 0.05 + Dv::Float64 = 0.1 + noise::Float64 = 0.0 + output::String = "foo.bp" + checkpoint::Bool = false + checkpoint_freq::Int32 = 2000 + checkpoint_output::String = "ckpt.bp" + restart::Bool = false + restart_input::String = "ckpt.bp" + adios_config::String = "adios2.yaml" + adios_span::Bool = false + adios_memory_selection::Bool = false + mesh_type::String = "image" + precision::String = "Float64" + backend::String = "CPU" +end + +SettingsKeys = Set{String}([ + "L", + "steps", + "plotgap", + "F", + "k", + "dt", + "Du", + "Dv", + "noise", + "output", + "checkpoint", + "checkpoint_freq", + "checkpoint_output", + "restart", + "restart_input", + "adios_config", + "adios_span", + "adios_memory_selection", + "mesh_type", + "precision", + "backend", + ]) + +Base.@kwdef mutable struct MPICartDomain + cart_comm::MPI.Comm = MPI.COMM_NULL + + # Cartesian communicator info + # Could used StaticArrays.jl? + # start dims with zeros + dims::Vector{Int32} = zeros(Int32, 3) + coords::Vector{Int32} = zeros(Int32, 3) + + # local process mesh sizes and offsets in Cartesian domain info, using defaults + proc_sizes::Vector{Int64} = [128, 128, 128] + proc_offsets::Vector{Int64} = [1, 1, 1] + + # couldn't use NamedTuples as struct is mutable + proc_neighbors = Dict{String, Int32}("west" => -1, "east" => -1, "up" => -1, + "down" => -1, "north" => -1, + "south" => -1) +end + +""" +Carry the physical field outputs: u and v +Using AbstractArray to allow for Array, CuArray and ROCArray +""" +mutable struct Fields{T, N, A <: AbstractArray{T, N}} + u::A + v::A + u_temp::A + v_temp::A + # MPI Datatypes for halo exchange MPI.Datatype(T) + xy_face_t::MPI.Datatype + xz_face_t::MPI.Datatype + yz_face_t::MPI.Datatype +end + +""" +Carry the I/O information for outputs +""" +struct IOStream + adios::ADIOS2.Adios + io::ADIOS2.AIO + engine::ADIOS2.Engine + var_step::ADIOS2.Variable + var_U::ADIOS2.Variable + var_V::ADIOS2.Variable +end diff --git a/examples/simulations/GrayScott.jl/test/Project.toml b/examples/simulations/GrayScott.jl/test/Project.toml new file mode 100644 index 0000000000..c60df76b67 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/Project.toml @@ -0,0 +1,3 @@ +[deps] +MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl b/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl new file mode 100644 index 0000000000..46a844a037 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/functional/functional-GrayScott.jl @@ -0,0 +1,12 @@ + +import GrayScott +import Test: @testset, @test + +@testset "GrayScott" begin MPI.mpiexec() do runcmd + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + + juliacmd = `julia --project gray-scott.jl $config_file` + + @test run(`mpirun -n 4 $juliacmd`).exitcode == 0 +end end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/test/runtests.jl b/examples/simulations/GrayScott.jl/test/runtests.jl new file mode 100644 index 0000000000..e795c94ca9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/runtests.jl @@ -0,0 +1,26 @@ + +import MPI + +# Run all lightweight unit tests within a single MPI session +MPI.Init() + +verbose = false + +# unit tests for module GrayScott +include(joinpath("unit", "helper", "unit-helperMPI.jl")) + +include(joinpath("unit", "simulation", "unit-Inputs.jl")) +include(joinpath("unit", "simulation", "unit-Simulation.jl")) +include(joinpath("unit", "simulation", "unit-Simulation_CUDA.jl")) +include(joinpath("unit", "simulation", "unit-IO.jl")) + +# unit tests for analysis scripts +include(joinpath("unit", "analysis", "unit-pdfcalc.jl")) + +MPI.Finalize() + +# Command line tests. These are heavier tests launched as separate processes. +# The downside is that only global success can be tested and not internal states. + +# functional tests +# include(joinpath("functional", "functional-GrayScott.jl")) diff --git a/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl b/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl new file mode 100644 index 0000000000..87ea9b8478 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/analysis/unit-pdfcalc.jl @@ -0,0 +1,19 @@ + +import Test: @testset, @test, @test_throws + +include(joinpath(dirname(Base.active_project()), "src", "analysis", + "pdfcalc.jl")) + +@testset "unit-analysis.pdfcalc._parse_args" begin + inputs = _parse_arguments(["foo.bp", "bar.bp", "1500"]) + @test inputs["input"] == "foo.bp" + @test inputs["output"] == "bar.bp" + @test inputs["N"] == 1500 + @test inputs["output_inputdata"] == false + + inputs = _parse_arguments(["input.bp", "output.bp", "1000", "true"]) + @test inputs["input"] == "input.bp" + @test inputs["output"] == "output.bp" + @test inputs["N"] == 1000 + @test inputs["output_inputdata"] == true +end diff --git a/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl b/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl new file mode 100644 index 0000000000..33d9f2202f --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/helper/unit-helperMPI.jl @@ -0,0 +1,12 @@ + +import Test: @testset, @test, @test_throws +import GrayScott: Helper + +@testset "unit-Helper.bcast_file_contents" begin + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + + file_contents = Helper.bcast_file_contents(config_file, MPI.COMM_WORLD) + file_contents_expected = String(read(open(config_file, "r"))) + @test file_contents == file_contents_expected +end \ No newline at end of file diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl new file mode 100644 index 0000000000..5a33f90ed9 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-IO.jl @@ -0,0 +1,36 @@ + +import Test: @testset, @test, @test_throws + +import ADIOS2 + +# import submodule +import GrayScott: IO +# import types +import GrayScott: Settings, MPICartDomain, Fields + +@testset "unit-IO.init" begin + settings = Settings() + mpi_cart_domain = MPICartDomain() + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test eltype(fields.u) == Float32 + @test eltype(fields.v) == Float32 + + stream = IO.init(settings, mpi_cart_domain, fields) + + @test ADIOS2.name(stream.engine) == "foo.bp" + IO.close!(stream) + + # @TODO: needs to be done from rank==0 only + # Base.Filesystem.rm("foo.bp", force = true, recursive = true) +end + +@testset "unit-IO.write" begin + settings = Settings() + settings.L = 6 + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + stream = IO.init(settings, mpi_cart_domain, fields) + IO.write_step!(stream, Int32(0), fields) + IO.close!(stream) +end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl new file mode 100644 index 0000000000..fb77325de5 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Inputs.jl @@ -0,0 +1,15 @@ + +import Test: @testset, @test, @test_throws +import GrayScott: Inputs + +# Unfortunately due to MPI being a Singleton, single MPI.Init() +# these unit tests don't run as independent files + +@testset "unit-Inputs.get_settings" begin + config_file = joinpath(dirname(Base.active_project()), "examples", + "settings-files.json") + Inputs.get_settings([config_file], MPI.COMM_WORLD) + + @test_throws(ArgumentError, + Inputs.get_settings(["hello.nojson"], MPI.COMM_WORLD)) +end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl new file mode 100644 index 0000000000..ad43a8b49f --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation.jl @@ -0,0 +1,34 @@ + +import Test: @testset, @test, @test_throws +# import submodule +import GrayScott: Simulation +# import types +import GrayScott: Settings, MPICartDomain, Fields + +# Unfortunately due to MPI being a Singleton, single MPI.Init() +# these unit tests don't run as independent files + +@testset "unit-Simulation.init" begin + settings = Settings() + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test typeof(fields) == Fields{Float32, 3, Array{Float32, 3}} +end + +@testset "unit-Simulation.iterate" begin + settings = Settings() + settings.L = 2 + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + Simulation.iterate!(fields, settings, mpi_cart_domain) + + if verbose + sleep(0.01) + rank = MPI.Comm_rank(MPI.COMM_WORLD) + @show rank, fields.v + end +end + +#end diff --git a/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl new file mode 100644 index 0000000000..e3c3a6fc07 --- /dev/null +++ b/examples/simulations/GrayScott.jl/test/unit/simulation/unit-Simulation_CUDA.jl @@ -0,0 +1,28 @@ + +import Test: @testset, @test, @test_throws +# import submodule +import GrayScott: Simulation +# import types +import GrayScott: Settings, MPICartDomain, Fields + +@testset "unit-Simulation.init_fields-cuda" begin + function test_init_cuda(L) + settings = Settings() + settings.L = L + mpi_cart_domain = Simulation.init_domain(settings, MPI.COMM_WORLD) + + fields = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + settings.backend = "CUDA" + fields_cuda = Simulation.init_fields(settings, mpi_cart_domain, Float32) + + @test fields.u ≈ Array(fields_cuda.u) + @test fields.v ≈ Array(fields_cuda.v) + end + + test_init_cuda(8) + test_init_cuda(16) + test_init_cuda(32) + test_init_cuda(64) + test_init_cuda(128) +end \ No newline at end of file diff --git a/examples/simulations/ReadMe.md b/examples/simulations/ReadMe.md new file mode 100644 index 0000000000..d3b72b36a6 --- /dev/null +++ b/examples/simulations/ReadMe.md @@ -0,0 +1,30 @@ +## ADIOS2 simulations examples + +The _simulations_ examples are meant to demonstrate how to integrate ADIOS2 within your +simulation code to read, write and/or stream your simulation data. + +They can be found in the following subdirectories, and they should be explored in the order that they are listed: + +1. [korteweg-de-vries](korteweg-de-vries): The _korteweg-de-vries_ example demonstrates how to solve the initial value + problem for the Korteweg de-Vries equation via the Zabusky and Krustal scheme and integrate ADIOS2 for its IO + capabilities. + * Languages: C++, Python +2. [lorenz_ode](lorenz_ode): The _lorenz_ode_ example demonstrates how to solve the Lorenz system of ordinary + differential equations and integrate ADIOS2 for its IO capabilities. + * Languages: C++ +3. [gray-scott](gray-scott): The _gray-scott_ example demonstrates how to perform simulation with the Gray-Scott + reaction diffusion model and integrate ADIOS2 for its IO capabilities. + * Languages: C++ +4. [gray-scott-struct](gray-scott-struct): The _gray-scott-struct_ example demonstrates how to perform a simulation with + the Gray-Scott reaction diffusion model using a struct that defines user defined data types and integrate ADIOS2 for + its IO capabilities. + * Languages: C++ +5. [gray-scott-kokkos](gray-scott-kokkos): The _gray-scott-kokkos_ example demonstrates how to perform a simulation with + the Gray-Scott reaction diffusion model using Kokkos and integrate ADIOS2 for its IO capabilities. + * Languages: C++ +6. [GrayScott.jl](GrayScott.jl): The _GrayScott.jl_ example demonstrates how to perform a simulation with the Gray-Scott + reaction diffusion model and integrate ADIOS2 for its IO capabilities. + * Languages: Julia +7. [heatTransfer](heatTransfer): The _heatTransfer_ example demonstrates how to solve a 2D Poisson equation for + temperature in homogeneous media using finite differences and integrate ADIOS2 for its IO capabilities. + * Languages: C++ diff --git a/examples/simulations/gray-scott-kokkos/CMakeLists.txt b/examples/simulations/gray-scott-kokkos/CMakeLists.txt new file mode 100644 index 0000000000..b43362cf3f --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/CMakeLists.txt @@ -0,0 +1,47 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +cmake_minimum_required(VERSION 3.12) +project(ADIOS2SimulationsGrayScottKokkosExample) + +# CXX Compiler settings only in for this example +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT TARGET adios2_core) + set(_components CXX) + + find_package(MPI COMPONENTS C) + if(MPI_FOUND) + # Workaround for various MPI implementations forcing the link of C++ bindings + add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) + + list(APPEND _components MPI) + endif() + + find_package(Kokkos 3.7 QUIET) + if(Kokkos_FOUND AND DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() + + find_package(ADIOS2 REQUIRED COMPONENTS ${_components}) +else() + if(DEFINED Kokkos_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${Kokkos_CXX_COMPILER}") + endif() +endif() + +if(ADIOS2_HAVE_MPI AND ADIOS2_HAVE_Kokkos) + add_executable(adios2_simulations_gray-scott-kokkos + main.cpp + gray-scott.cpp + settings.cpp + writer.cpp + restart.cpp + ) + kokkos_compilation(SOURCE gray-scott.cpp) + target_link_libraries(adios2_simulations_gray-scott-kokkos adios2::cxx11_mpi MPI::MPI_C Kokkos::kokkos) + install(TARGETS adios2_simulations_gray-scott-kokkos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/simulations/gray-scott-kokkos/ReadMe.md b/examples/simulations/gray-scott-kokkos/ReadMe.md new file mode 100644 index 0000000000..86790505d0 --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/ReadMe.md @@ -0,0 +1,9 @@ +### ADIOS2 gray-scott-kokkos example + +This is a 3D 7-point stencil code to simulate the following [Gray-Scott +reaction diffusion model](https://doi.org/10.1126/science.261.5118.189): + +#### Differences from the gray-scott example + +It uses Kokkos to run the simulation on GPU. +Please use the installed Gray-Scott example directory but run adios2_simulations_gray-scott-kokkos binary. diff --git a/examples/simulations/gray-scott-kokkos/gray-scott.cpp b/examples/simulations/gray-scott-kokkos/gray-scott.cpp new file mode 100644 index 0000000000..b6f6cd4b7c --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/gray-scott.cpp @@ -0,0 +1,330 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * The solver is based on Hiroshi Watanabe's 2D Gray-Scott reaction diffusion + * code available at: https://github.com/kaityo256/sevendayshpc/tree/master/day5 + */ + +#include "gray-scott.h" + +#include +#include // runtime_error +#include + +GrayScott::GrayScott(const Settings &settings, MPI_Comm comm) +: settings(settings), comm(comm), rand_pool(5374857) +{ +} + +GrayScott::~GrayScott() {} + +void GrayScott::init() +{ + init_mpi(); + init_field(); +} + +void GrayScott::iterate() +{ + auto temp_u = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, u); + auto temp_v = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, v); + exchange(temp_u, temp_v); + Kokkos::deep_copy(u, temp_u); + Kokkos::deep_copy(v, temp_v); + + calc(); + + std::swap(u, u2); + std::swap(v, v2); +} + +void GrayScott::restart(Kokkos::View &u_in, + Kokkos::View &v_in) +{ + auto const expected_len = (size_x + 2) * (size_y + 2) * (size_z + 2); + if (u_in.size() == expected_len) + { + u = u_in; + v = v_in; + } + else + { + throw std::runtime_error("Restart with incompatible array size, expected " + + std::to_string(expected_len) + " got " + + std::to_string(u_in.size()) + " elements"); + } +} + +const Kokkos::View GrayScott::u_ghost() const { return u; } + +const Kokkos::View GrayScott::v_ghost() const { return v; } + +Kokkos::View GrayScott::u_noghost() const +{ + return data_noghost(u); +} + +Kokkos::View GrayScott::v_noghost() const +{ + return data_noghost(v); +} + +void GrayScott::u_noghost(Kokkos::View u_no_ghost) const +{ + data_noghost(u, u_no_ghost); +} + +void GrayScott::v_noghost(Kokkos::View v_no_ghost) const +{ + data_noghost(v, v_no_ghost); +} + +Kokkos::View +GrayScott::data_noghost(const Kokkos::View &data) const +{ + Kokkos::View buf("noghost_temp", size_x, size_y, size_z); + data_no_ghost_common(data, buf); + return buf; +} + +void GrayScott::data_noghost(const Kokkos::View &data, + Kokkos::View data_no_ghost) const +{ + data_no_ghost_common(data, data_no_ghost); +} + +void GrayScott::init_field() +{ + Kokkos::resize(u, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(u, 1.0); + Kokkos::resize(v, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(v, 0.0); + Kokkos::resize(u2, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(u2, 0.0); + Kokkos::resize(v2, size_x + 2, size_y + 2, size_z + 2); + Kokkos::deep_copy(v2, 0.0); + + const int d = 6; + auto const L = settings.L; + auto const settingsL = static_cast(settings.L); + auto const temp_u = u; + auto const temp_v = v; + size_t const ox = offset_x, oy = offset_y, oz = offset_z; + size_t const sx = size_x, sy = size_y; + auto const min_z = std::max(L / 2 - d, offset_z); + auto const max_z = std::min(L / 2 + d, offset_z + size_z); + Kokkos::parallel_for( + "init_buffers", Kokkos::RangePolicy<>(min_z, max_z), KOKKOS_LAMBDA(int z) { + for (int y = settingsL / 2 - d; y < settingsL / 2 + d; y++) + { + if (y < static_cast(oy)) + continue; + if (y >= static_cast(oy + sy)) + continue; + for (int x = settingsL / 2 - d; x < settingsL / 2 + d; x++) + { + if (x < static_cast(ox)) + continue; + if (x >= static_cast(ox + sx)) + continue; + temp_u(x - ox + 1, y - oy + 1, z - oz + 1) = 0.25; + temp_v(x - ox + 1, y - oy + 1, z - oz + 1) = 0.33; + } + } + }); +} + +void GrayScott::calc() +{ + auto const temp_u = u; + auto const temp_v = v; + auto const temp_u2 = u2; + auto const temp_v2 = v2; + auto const Du = settings.Du; + auto const Dv = settings.Dv; + auto const dt = settings.dt; + auto const F = settings.F; + auto const k = settings.k; + auto const noise = settings.noise; + size_t const sx = size_x, sy = size_y, sz = size_z; + auto const random_pool = rand_pool; + Kokkos::parallel_for( + "calc_gray_scott", Kokkos::RangePolicy<>(1, sz + 1), KOKKOS_LAMBDA(int z) { + RandomPool::generator_type generator = random_pool.get_state(); + double ts; + for (int y = 1; y < static_cast(sy) + 1; y++) + { + for (int x = 1; x < static_cast(sx) + 1; x++) + { + double du, dv; + // laplacian for u + ts = 0; + ts += temp_u(x - 1, y, z); + ts += temp_u(x + 1, y, z); + ts += temp_u(x, y - 1, z); + ts += temp_u(x, y + 1, z); + ts += temp_u(x, y, z - 1); + ts += temp_u(x, y, z + 1); + ts += -6.0 * temp_u(x, y, z); + ts /= 6.0; + du = Du * ts; + + // laplacian for v + ts = 0; + ts += temp_v(x - 1, y, z); + ts += temp_v(x + 1, y, z); + ts += temp_v(x, y - 1, z); + ts += temp_v(x, y + 1, z); + ts += temp_v(x, y, z - 1); + ts += temp_v(x, y, z + 1); + ts += -6.0 * temp_v(x, y, z); + ts /= 6.0; + dv = Dv * ts; + + du += (-temp_u(x, y, z) * temp_v(x, y, z) * temp_v(x, y, z) + + F * (1.0 - temp_u(x, y, z))); + dv += (temp_u(x, y, z) * temp_v(x, y, z) * temp_v(x, y, z) - + (F + k) * temp_v(x, y, z)); + du += noise * generator.frand(-1.f, 1.f); + temp_u2(x, y, z) = temp_u(x, y, z) + du * dt; + temp_v2(x, y, z) = temp_v(x, y, z) + dv * dt; + } + } + random_pool.free_state(generator); + }); +} + +void GrayScott::init_mpi() +{ + int dims[3] = {}; + const int periods[3] = {1, 1, 1}; + int coords[3] = {}; + + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &procs); + + MPI_Dims_create(procs, 3, dims); + npx = dims[0]; + npy = dims[1]; + npz = dims[2]; + + MPI_Cart_create(comm, 3, dims, periods, 0, &cart_comm); + MPI_Cart_coords(cart_comm, rank, 3, coords); + px = coords[0]; + py = coords[1]; + pz = coords[2]; + + size_x = settings.L / npx; + size_y = settings.L / npy; + size_z = settings.L / npz; + + if (px < settings.L % npx) + { + size_x++; + } + if (py < settings.L % npy) + { + size_y++; + } + if (pz < settings.L % npz) + { + size_z++; + } + + offset_x = (settings.L / npx * px) + std::min(settings.L % npx, px); + offset_y = (settings.L / npy * py) + std::min(settings.L % npy, py); + offset_z = (settings.L / npz * pz) + std::min(settings.L % npz, pz); + + MPI_Cart_shift(cart_comm, 0, 1, &west, &east); + MPI_Cart_shift(cart_comm, 1, 1, &down, &up); + MPI_Cart_shift(cart_comm, 2, 1, &south, &north); + + // XY faces: size_x * (size_y + 2) + MPI_Type_vector(static_cast(size_y + 2), static_cast(size_x), + static_cast(size_x + 2), MPI_DOUBLE, &xy_face_type); + MPI_Type_commit(&xy_face_type); + + // XZ faces: size_x * size_z + MPI_Type_vector(static_cast(size_z), static_cast(size_x), + static_cast((size_x + 2) * (size_y + 2)), MPI_DOUBLE, &xz_face_type); + MPI_Type_commit(&xz_face_type); + + // YZ faces: (size_y + 2) * (size_z + 2) + MPI_Type_vector(static_cast((size_y + 2) * (size_z + 2)), 1, static_cast(size_x + 2), + MPI_DOUBLE, &yz_face_type); + MPI_Type_commit(&yz_face_type); +} + +void GrayScott::exchange_xy( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send XY face z=size_z to north and receive z=0 from south + MPI_Sendrecv(&local_data.data()[l2i(1, 0, static_cast(size_z))], 1, xy_face_type, north, 1, + &local_data.data()[l2i(1, 0, 0)], 1, xy_face_type, south, 1, cart_comm, &st); + // Send XY face z=1 to south and receive z=size_z+1 from north + MPI_Sendrecv(&local_data.data()[l2i(1, 0, 1)], 1, xy_face_type, south, 1, + &local_data.data()[l2i(1, 0, static_cast(size_z + 1))], 1, xy_face_type, + north, 1, cart_comm, &st); +} + +void GrayScott::exchange_xz( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send XZ face y=size_y to up and receive y=0 from down + MPI_Sendrecv(&local_data.data()[l2i(1, static_cast(size_y), 1)], 1, xz_face_type, up, 2, + &local_data.data()[l2i(1, 0, 1)], 1, xz_face_type, down, 2, cart_comm, &st); + // Send XZ face y=1 to down and receive y=size_y+1 from up + MPI_Sendrecv(&local_data.data()[l2i(1, 1, 1)], 1, xz_face_type, down, 2, + &local_data.data()[l2i(1, static_cast(size_y + 1), 1)], 1, xz_face_type, up, + 2, cart_comm, &st); +} + +void GrayScott::exchange_yz( + Kokkos::View local_data) const +{ + MPI_Status st; + + // Send YZ face x=size_x to east and receive x=0 from west + MPI_Sendrecv(&local_data.data()[l2i(static_cast(size_x), 0, 0)], 1, yz_face_type, east, 3, + &local_data.data()[l2i(0, 0, 0)], 1, yz_face_type, west, 3, cart_comm, &st); + // Send YZ face x=1 to west and receive x=size_x+1 from east + MPI_Sendrecv(&local_data.data()[l2i(1, 0, 0)], 1, yz_face_type, west, 3, + &local_data.data()[l2i(static_cast(size_x + 1), 0, 0)], 1, yz_face_type, east, + 3, cart_comm, &st); +} + +void GrayScott::exchange(Kokkos::View u, + Kokkos::View v) const +{ + exchange_xy(u); + exchange_xz(u); + exchange_yz(u); + + exchange_xy(v); + exchange_xz(v); + exchange_yz(v); +} + +void GrayScott::data_no_ghost_common( + const Kokkos::View &data, + Kokkos::View data_no_ghost) const +{ + auto const sx = size_x; + auto const sy = size_y; + auto const sz = size_z; + Kokkos::parallel_for( + "updateBuffer", Kokkos::RangePolicy<>(1, sz + 1), KOKKOS_LAMBDA(int z) { + for (int y = 1; y < static_cast(sy) + 1; y++) + { + for (int x = 1; x < static_cast(sx) + 1; x++) + { + data_no_ghost(x - 1, y - 1, z - 1) = data(x, y, z); + } + } + }); +} diff --git a/examples/simulations/gray-scott-kokkos/gray-scott.h b/examples/simulations/gray-scott-kokkos/gray-scott.h new file mode 100644 index 0000000000..26553c8c07 --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/gray-scott.h @@ -0,0 +1,102 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ + +#ifndef __GRAY_SCOTT_H__ +#define __GRAY_SCOTT_H__ + +#include + +#include +#include +#include + +#include "settings.h" + +class GrayScott +{ +public: + // Dimension of process grid + size_t npx, npy, npz; + // Coordinate of this rank in process grid + size_t px, py, pz; + // Dimension of local array + size_t size_x, size_y, size_z; + // Offset of local array in the global array + size_t offset_x, offset_y, offset_z; + + GrayScott(const Settings &settings, MPI_Comm comm); + ~GrayScott(); + + void init(); + void iterate(); + void restart(Kokkos::View &u, + Kokkos::View &v); + + const Kokkos::View u_ghost() const; + const Kokkos::View v_ghost() const; + + Kokkos::View u_noghost() const; + Kokkos::View v_noghost() const; + + void u_noghost(Kokkos::View u_no_ghost) const; + void v_noghost(Kokkos::View v_no_ghost) const; + + Settings settings; + + Kokkos::View u, v, u2, v2; + + int rank, procs; + int west, east, up, down, north, south; + MPI_Comm comm; + MPI_Comm cart_comm; + + // MPI datatypes for halo exchange + MPI_Datatype xy_face_type; + MPI_Datatype xz_face_type; + MPI_Datatype yz_face_type; + + using RandomPool = Kokkos::Random_XorShift64_Pool; + RandomPool rand_pool; + + // Setup cartesian communicator data types + void init_mpi(); + // Setup initial conditions + void init_field(); + + // Process simulation for one timestep + void calc(); + + // Exchange faces with neighbors + void exchange(Kokkos::View u, + Kokkos::View v) const; + // Exchange XY faces with north/south + void + exchange_xy(Kokkos::View local_data) const; + // Exchange XZ faces with up/down + void + exchange_xz(Kokkos::View local_data) const; + // Exchange YZ faces with west/east + void + exchange_yz(Kokkos::View local_data) const; + + // Return a copy of data with ghosts removed + Kokkos::View + data_noghost(const Kokkos::View &data) const; + + // pointer version + void data_noghost(const Kokkos::View &data, + Kokkos::View no_ghost) const; + + // Convert local coordinate to local index + KOKKOS_FUNCTION int l2i(int x, int y, int z) const + { + return static_cast(x + y * (size_x + 2) + z * (size_x + 2) * (size_y + 2)); + } + + void data_no_ghost_common(const Kokkos::View &data, + Kokkos::View data_no_ghost) const; +}; + +#endif diff --git a/examples/simulations/gray-scott-kokkos/json.hpp b/examples/simulations/gray-scott-kokkos/json.hpp new file mode 100644 index 0000000000..1e7cf51e0a --- /dev/null +++ b/examples/simulations/gray-scott-kokkos/json.hpp @@ -0,0 +1,20274 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.4.0 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2018 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef NLOHMANN_JSON_HPP +#define NLOHMANN_JSON_HPP + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 4 +#define NLOHMANN_JSON_VERSION_PATCH 0 + +#include // all_of, find, for_each +#include // assert +#include // and, not, or +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#include // istream, ostream +#include // iterator_traits, random_access_iterator_tag +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap + +// #include +#ifndef NLOHMANN_JSON_FWD_HPP +#define NLOHMANN_JSON_FWD_HPP + +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +namespace nlohmann +{ +/*! +@brief default JSONSerializer template argument + +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer; + +template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer> +class basic_json; + +/*! +@brief JSON Pointer + +A JSON pointer defines a string syntax for identifying a specific value +within a JSON document. It can be used with functions `at` and +`operator[]`. Furthermore, JSON pointers are the base for JSON patches. + +@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + +@since version 2.0.0 +*/ +template +class json_pointer; + +/*! +@brief default JSON class + +This type is the default specialization of the @ref basic_json class which +uses the standard template types. + +@since version 1.0.0 +*/ +using json = basic_json<>; +} // namespace nlohmann + +#endif + +// #include + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// disable float-equal warnings on GCC/clang +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +// allow for portable deprecation warnings +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) + #define JSON_DEPRECATED __declspec(deprecated) +#else + #define JSON_DEPRECATED +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// manual branch prediction +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #define JSON_LIKELY(x) __builtin_expect(!!(x), 1) + #define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else + #define JSON_LIKELY(x) x + #define JSON_UNLIKELY(x) x +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// #include + + +#include // not +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type + +namespace nlohmann +{ +namespace detail +{ +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +template +using uncvref_t = typename std::remove_cv::type>::type; + +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // not +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include + +// #include + +// #include + + +#include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + + +// http://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template