From 8a654f55ebaa4ac3a5ec2b70597a08f8a8563d6b Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 13:59:02 -0500 Subject: [PATCH 01/43] STYLE: Moving unused types to legacy --- {src/include => legacy/src}/Tpetra_LRMultiVector_decl.hpp | 0 {src/include => legacy/src}/Tpetra_LRMultiVector_def.hpp | 0 {src/include => legacy/src}/Tpetra_LR_WrappedDualView.hpp | 0 {src/include => legacy/src}/communication_plan_old.h | 0 {src/include => legacy/src}/mapped_mpi_types.h | 0 {src/include => legacy/src}/mpi_types_old.h | 0 {src/include => legacy/src}/partition_map.h | 0 {src/include => legacy/src}/tpetra_wrapper_types.h | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename {src/include => legacy/src}/Tpetra_LRMultiVector_decl.hpp (100%) rename {src/include => legacy/src}/Tpetra_LRMultiVector_def.hpp (100%) rename {src/include => legacy/src}/Tpetra_LR_WrappedDualView.hpp (100%) rename {src/include => legacy/src}/communication_plan_old.h (100%) rename {src/include => legacy/src}/mapped_mpi_types.h (100%) rename {src/include => legacy/src}/mpi_types_old.h (100%) rename {src/include => legacy/src}/partition_map.h (100%) rename {src/include => legacy/src}/tpetra_wrapper_types.h (100%) diff --git a/src/include/Tpetra_LRMultiVector_decl.hpp b/legacy/src/Tpetra_LRMultiVector_decl.hpp similarity index 100% rename from src/include/Tpetra_LRMultiVector_decl.hpp rename to legacy/src/Tpetra_LRMultiVector_decl.hpp diff --git a/src/include/Tpetra_LRMultiVector_def.hpp b/legacy/src/Tpetra_LRMultiVector_def.hpp similarity index 100% rename from src/include/Tpetra_LRMultiVector_def.hpp rename to legacy/src/Tpetra_LRMultiVector_def.hpp diff --git a/src/include/Tpetra_LR_WrappedDualView.hpp b/legacy/src/Tpetra_LR_WrappedDualView.hpp similarity index 100% rename from src/include/Tpetra_LR_WrappedDualView.hpp rename to legacy/src/Tpetra_LR_WrappedDualView.hpp diff --git a/src/include/communication_plan_old.h b/legacy/src/communication_plan_old.h similarity index 100% rename from src/include/communication_plan_old.h rename to legacy/src/communication_plan_old.h diff --git a/src/include/mapped_mpi_types.h b/legacy/src/mapped_mpi_types.h similarity index 100% rename from src/include/mapped_mpi_types.h rename to legacy/src/mapped_mpi_types.h diff --git a/src/include/mpi_types_old.h b/legacy/src/mpi_types_old.h similarity index 100% rename from src/include/mpi_types_old.h rename to legacy/src/mpi_types_old.h diff --git a/src/include/partition_map.h b/legacy/src/partition_map.h similarity index 100% rename from src/include/partition_map.h rename to legacy/src/partition_map.h diff --git a/src/include/tpetra_wrapper_types.h b/legacy/src/tpetra_wrapper_types.h similarity index 100% rename from src/include/tpetra_wrapper_types.h rename to legacy/src/tpetra_wrapper_types.h From afbd5e72486d9f9ab3245d93930f03598a4ab6ce Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 14:36:54 -0500 Subject: [PATCH 02/43] STYLE: Tidying up, prep for build system refactor --- index.md | 5 - CMakeLists.txt => legacy/CMakeLists.txt | 0 {results => legacy/results}/results_cpu.csv | 0 {results => legacy/results}/results_cpu1.csv | 0 {results => legacy/results}/results_cpu8.csv | 0 .../results}/results_ser_vP.csv | 0 .../results}/strong_scaling.csv | 0 lib/.gitignore | 1 - src/include/matar.h | 5 - v1_todo.md | 613 ------------------ 10 files changed, 624 deletions(-) delete mode 100644 index.md rename CMakeLists.txt => legacy/CMakeLists.txt (100%) rename {results => legacy/results}/results_cpu.csv (100%) rename {results => legacy/results}/results_cpu1.csv (100%) rename {results => legacy/results}/results_cpu8.csv (100%) rename {results => legacy/results}/results_ser_vP.csv (100%) rename {results => legacy/results}/strong_scaling.csv (100%) delete mode 100644 lib/.gitignore delete mode 100644 v1_todo.md diff --git a/index.md b/index.md deleted file mode 100644 index 6d7b184b..00000000 --- a/index.md +++ /dev/null @@ -1,5 +0,0 @@ -## Hello - -dfhefad fad fdsaf dsaf - -## test diff --git a/CMakeLists.txt b/legacy/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to legacy/CMakeLists.txt diff --git a/results/results_cpu.csv b/legacy/results/results_cpu.csv similarity index 100% rename from results/results_cpu.csv rename to legacy/results/results_cpu.csv diff --git a/results/results_cpu1.csv b/legacy/results/results_cpu1.csv similarity index 100% rename from results/results_cpu1.csv rename to legacy/results/results_cpu1.csv diff --git a/results/results_cpu8.csv b/legacy/results/results_cpu8.csv similarity index 100% rename from results/results_cpu8.csv rename to legacy/results/results_cpu8.csv diff --git a/results/results_ser_vP.csv b/legacy/results/results_ser_vP.csv similarity index 100% rename from results/results_ser_vP.csv rename to legacy/results/results_ser_vP.csv diff --git a/results/strong_scaling.csv b/legacy/results/strong_scaling.csv similarity index 100% rename from results/strong_scaling.csv rename to legacy/results/strong_scaling.csv diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index 059e58d8..00000000 --- a/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -Trilinos diff --git a/src/include/matar.h b/src/include/matar.h index 8640f798..484d87a6 100644 --- a/src/include/matar.h +++ b/src/include/matar.h @@ -83,9 +83,4 @@ #include "aliases.h" #include "mpi_types.h" -#ifdef TRILINOS_INTERFACE -#include "mapped_mpi_types.h" -#include "tpetra_wrapper_types.h" -#endif - #endif // MATAR_H diff --git a/v1_todo.md b/v1_todo.md deleted file mode 100644 index 561ca55d..00000000 --- a/v1_todo.md +++ /dev/null @@ -1,613 +0,0 @@ -# MATAR v1 Release — To-Do List - -> Prepared: June 2026 -> Branch: `MPI_Updates` -> Scope: Low-hanging-fruit improvements targeting a fall 2026 v1 release. -> Categories: Build System · OS Robustness · CPU-GPU Portability · Documentation · Performance - -> **Note on ordering:** Section 5 (Build System Refactor) is the primary v1 goal and is listed last only because many items in Sections 1–4 reference it. Read Section 5 first to understand the overall direction, then read Sections 1–4 for the code-level work that runs in parallel. - ---- - -## 1. OS Robustness - -### 1.1 `matar.h` unconditionally includes `mpi_types.h` and `tpetra_wrapper_types.h` -- **File:** `src/include/matar.h:84-86` -- **Problem:** All three optional headers (`mpi_types.h`, `mapped_mpi_types.h`, `tpetra_wrapper_types.h`) are included without preprocessor guards. Even though each file guards its content with `#ifdef HAVE_MPI` / `#ifdef TRILINOS_INTERFACE`, the files are still found and opened by the preprocessor on every build. If a downstream project installs only the serial subset of MATAR, compilation fails because the files are absent. Additionally, `mapped_mpi_types.h` uses an angle-bracket include `` (line 46) instead of `"mpi_types.h"` — this only resolves if the MATAR include directory is on the system path, which is fragile. -- **Fix:** Wrap with preprocessor guards: - ```cpp - #ifdef HAVE_MPI - #include "mpi_types.h" - #include "mapped_mpi_types.h" - #endif - #ifdef TRILINOS_INTERFACE - #include "tpetra_wrapper_types.h" - #endif - ``` - Also fix the angle-bracket include in `mapped_mpi_types.h:46` to `#include "mpi_types.h"`. The `HAVE_MPI` and `TRILINOS_INTERFACE` macros will be set correctly via `CMakePresets.json` (see §5.1) and propagated through the installed `MatarTargets.cmake` (see §5.1 / §1.3). -- **Priority:** High — breaks clean non-MPI installs today. - -### 1.2 Backend detection macros (`HAVE_CUDA`, `HAVE_OPENMP`, `HAVE_HIP`) not propagated by CMake install -- **File:** `src/include/kokkos_types.h:49-70`, `CMakeLists.txt:76` -- **Problem:** The root `CMakeLists.txt` only calls `add_definitions(-DHAVE_KOKKOS=1)`. It never sets `HAVE_CUDA`, `HAVE_OPENMP`, `HAVE_HIP`, or `HAVE_THREADS`. Downstream consumers who link MATAR via `find_package(Matar)` receive no backend macros; `kokkos_types.h` silently falls through to the `#else` branch, using `LayoutLeft` even for OpenMP builds (which should use `LayoutRight` for C-order cache locality). -- **Fix:** In `CMakeLists.txt`, after `find_package(Kokkos REQUIRED)`, query Kokkos's own config variables and propagate them as interface definitions: - ```cmake - foreach(_backend CUDA HIP OPENMP SYCL THREADS) - if(Kokkos_ENABLE_${_backend}) - target_compile_definitions(matar INTERFACE HAVE_${_backend}=1) - endif() - endforeach() - ``` - The `CMakePresets.json` (§5.1) will pass the right Kokkos enable flags, so the backend macros flow end-to-end without manual `-DHAVE_CUDA=1` arguments. -- **Priority:** High — wrong layout silently chosen for OpenMP builds. - -### 1.3 HIP backend uses deprecated `Kokkos::Experimental` namespace -- **File:** `src/include/kokkos_types.h:63-64` -- **Problem:** - ```cpp - using DefaultMemSpace = Kokkos::Experimental::HIPSpace; - using DefaultExecSpace = Kokkos::Experimental::HIP; - ``` - These were promoted out of `Experimental` in Kokkos 3.7/4.x. Builds against modern Kokkos on Frontier and Crusher produce compilation errors or deprecation warnings today. -- **Fix:** Drop the `Experimental::` prefix unconditionally — all Kokkos versions targeted for MATAR v1 are ≥3.7: - ```cpp - using DefaultMemSpace = Kokkos::HIPSpace; - using DefaultExecSpace = Kokkos::HIP; - ``` - If compatibility with Kokkos < 3.7 must be preserved, guard with `#if KOKKOS_VERSION >= 30700`. -- **Priority:** High — breaks on current Frontier/Crusher toolchains. - -### 1.4 `_old` files installed alongside live headers -- **File:** `CMakeLists.txt:110` -- **Problem:** `install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/include/ ...)` installs `communication_plan_old.h` and `mpi_types_old.h`. Users and IDEs auto-complete from these, and they add ~50 KB of dead code to the installed package. -- **Fix:** Confirm no active file includes them (`grep -r "mpi_types_old\|communication_plan_old" src/`), then either delete them or exclude them from the install: - ```cmake - install(DIRECTORY src/include/ DESTINATION include - PATTERN "*_old.h" EXCLUDE) - ``` -- **Priority:** Low. - -### 1.5 No `MATAR_VERSION` macro exposed to C++ consumers -- **File:** `CMakeLists.txt:9, 86` -- **Problem:** `project(MATAR)` has no `VERSION` field. `MatarConfigVersion.cmake` hardcodes `VERSION 1.0`. Downstream projects cannot do compile-time version checks (`#if MATAR_VERSION_MAJOR >= 1`). -- **Fix:** Change to `project(MATAR VERSION 1.0.0)` and derive the config-version file from `${PROJECT_VERSION}`. Add a `configure_file` step to generate `matar_version.h`: - ```cmake - configure_file(cmake/matar_version.h.in include/matar_version.h) - install(FILES ${CMAKE_BINARY_DIR}/include/matar_version.h DESTINATION include) - ``` - where `matar_version.h.in` exposes `MATAR_VERSION_MAJOR`, `MATAR_VERSION_MINOR`, `MATAR_VERSION_PATCH`. -- **Priority:** Medium. - -### 1.6 CI: macOS runners use `--machine=linux` and CI doesn't run `ctest` -- **Files:** `.github/workflows/test.yml:63`, `.github/workflows/cmake.yml:82-86` -- **Problem:** Two separate CI issues that are both resolved by the build system refactor (§5.3): - 1. All `TEST_MAC_*` jobs call `build-matar.sh --machine=linux`, bypassing macOS-specific compiler selection and the core-count guard. - 2. `cmake.yml` has `ctest` commented out, so it only validates compilation, not correctness. -- **Fix:** Both are addressed by §5.3 (replace CI with `cmake --preset` invocations). Once the preset-based CI is in place: the macOS jobs use a `macos` preset (no machine flag needed) and `ctest --preset` runs tests correctly. The dead `cmake.yml` can be either deleted or merged into `test.yml` as a build-only job with no script dependency. -- **Priority:** High (resolved by §5.3; flag here for tracking). - -### 1.7 `test/CMakeLists.txt` uses non-standard `-DCUDA=ON` backend variables -- **File:** `test/CMakeLists.txt:29-51` -- **Problem:** The test CMakeLists checks `if(CUDA)`, `if(HIP)`, `if(OPENMP)` — ad-hoc cache variables that must be passed by the caller. Any user who runs `cmake` directly (without the wrapper script) gets no backend definitions emitted, so the test binaries compile for the wrong target. -- **Fix:** This is resolved by §5.4 (fold tests into root CMakeLists). With §1.2 (backend macros propagated via `MatarTargets.cmake`), the test CMakeLists can simply link `matar` and receive all backend macros transitively. Remove the `if(CUDA)/if(HIP)` block entirely. -- **Priority:** Medium (resolved by §5.4 + §1.2; flag here for tracking). - -### 1.8 No macOS MPI CI coverage -- **File:** `.github/workflows/test.yml` -- **Problem:** The macOS matrix only tests serial Kokkos. MPI availability on macOS runners (`brew install open-mpi`) is not verified. -- **Fix:** After §5.3 lands, add a `serial-mpi` preset entry in the macOS CI matrix. Gate it with a `brew install open-mpi` step matching the Ubuntu `apt-get` step. -- **Priority:** Low — good-to-have, not a v1 blocker. - ---- - -## 2. CPU-GPU Portability - -### 2.1 `FOR_FIRST` / `DO_FIRST` hardcode GPU warp size to 32 -- **File:** `src/include/macros.h:847-881` -- **Problem:** `Kokkos::TeamPolicy<>((x1)-(x0), Kokkos::AUTO, 32)` hardcodes vector length to 32. CUDA warps are 32-wide, but AMD HIP wavefronts are 64-wide and CPU SIMD varies. The hardcoded `32` is silently suboptimal or wrong on non-NVIDIA targets. -- **Fix:** Replace `32` with `Kokkos::AUTO`: - ```cpp - Kokkos::TeamPolicy<>((x1)-(x0), Kokkos::AUTO, Kokkos::AUTO) - ``` -- **Priority:** High — direct performance/correctness impact on HIP/CPU builds. - -### 2.2 `F_LOOP_ORDER` is `Kokkos::Iterate::Right` — wrong for Fortran column-major layout on GPU -- **File:** `src/include/macros.h:127-129` -- **Problem:** - ```cpp - #define LOOP_ORDER Kokkos::Iterate::Right // C arrays: last index fastest — correct - #define F_LOOP_ORDER Kokkos::Iterate::Right // F arrays: WRONG — should be Left - ``` - `DO_ALL` macros for FArray/FMatrix types use `F_LOOP_ORDER`. `Iterate::Right` makes the *last* dimension contiguous in the GPU thread mapping, which is correct for C-order arrays but wrong for Fortran arrays where the *first* index varies fastest. This causes non-coalesced memory access on GPU for all F-type arrays. -- **Fix:** `#define F_LOOP_ORDER Kokkos::Iterate::Left` -- **Priority:** High — GPU memory access pattern is wrong for all F-type arrays. - -### 2.3 `policy2D`, `policy3D`, `policy4D` don't bind to `DefaultExecSpace` -- **File:** `src/include/kokkos_types.h:82-84` -- **Problem:** - ```cpp - using policy2D = Kokkos::MDRangePolicy< Kokkos::Rank<2> >; - ``` - Without an explicit execution space, these resolve to the Kokkos global default, which may differ from MATAR's configured `DefaultExecSpace`. Mixing `policy2D` with a `CArrayKokkos` can cause Kokkos to complain or silently dispatch to the wrong device. -- **Fix:** - ```cpp - using policy2D = Kokkos::MDRangePolicy, DefaultExecSpace>; - using policy3D = Kokkos::MDRangePolicy, DefaultExecSpace>; - using policy4D = Kokkos::MDRangePolicy, DefaultExecSpace>; - ``` -- **Priority:** Medium. - -### 2.4 `real_t` and `u_int` in the global namespace — POSIX collision on Linux -- **File:** `src/include/aliases.h:44-45` -- **Problem:** - ```cpp - using real_t = double; - using u_int = unsigned int; // conflicts with POSIX u_int from - ``` - Both declarations are at global scope, outside `namespace mtr`. `u_int` is a POSIX typedef on Linux; any translation unit that includes both `` and `matar.h` gets a redefinition error. -- **Fix:** Move both into `namespace mtr`: - ```cpp - namespace mtr { - using real_t = double; - using u_int = unsigned int; - } - ``` - Audit downstream code (Fierro, ELEMENTS) for unqualified uses of `real_t` and `u_int` — they will need `mtr::real_t` or a `using namespace mtr` after this change. Document as a v1 breaking change in `MIGRATION.md` (see §3.7). -- **Priority:** High — actual compile failure with common system headers on Linux. - -### 2.5 `FArrayKokkos` 6D and 7D constructors have a parameter name typo (`sone_dim2`) -- **File:** `src/include/kokkos_types.h:178-183` -- **Problem:** - ```cpp - FArrayKokkos(size_t dim0, size_t sone_dim2, size_t dim2, ...); - ``` - The second parameter is named `sone_dim2` (should be `dim1`). The name leak into generated Doxygen and IDE tooltips for every 6D and 7D constructor across all Kokkos array/matrix types. -- **Fix:** Rename `sone_dim2` → `dim1` in all 6D and 7D declarations and definitions throughout `kokkos_types.h`. Verify with `grep -n sone_dim2 src/include/kokkos_types.h`. -- **Priority:** Medium — cosmetic but pollutes all generated documentation. - -### 2.6 FOR_ALL macro loop indices use `const int` — limits to ~2B elements -- **File:** `src/include/macros.h:167-168` -- **Problem:** `KOKKOS_LAMBDA(const int (i))` caps the loop index at `INT_MAX` (~2.1B). On GPU with HBM (32–80 GB), arrays with >2^31 elements are common (e.g., 8 GB of floats = 2^31 elements). The Kokkos `RangePolicy<>` itself supports 64-bit ranges, but the lambda signature overrides the index type. The serial fallback functions (`for_all`, lines 931–968) also use `int`. -- **Fix:** Change all Kokkos macro lambda signatures from `const int` to `const int64_t` (or `Kokkos::RangePolicy<>::index_type`). Change the serial `for_all` function signatures from `int` to `ptrdiff_t` or `int64_t`. -- **Priority:** Medium — silent data corruption for large GPU problems. - -### 2.7 `DefaultLayout` for CArrayKokkos is `LayoutLeft` on CUDA, contradicting C-order semantics -- **File:** `src/include/kokkos_types.h:51-53` -- **Problem:** The CUDA branch sets `DefaultLayout = Kokkos::LayoutLeft` (column-major). `CArrayKokkos` is documented as C-order (last index fastest = row-major = `LayoutRight`). Using `LayoutLeft` for a C-named type confuses users porting CPU `CArray` code to GPU, because `CArray` uses `LayoutRight`. The mismatch also means C-order 2D access (`A(i,j)` with j varying fastest in the loop) is non-coalesced on the GPU with the current default. -- **Fix:** Decouple `DefaultLayout` from the execution backend. Instead, define layout on a per-type basis: `CArrayKokkos` should default to `LayoutRight` and `FArrayKokkos` to `LayoutLeft` regardless of backend. The template parameter already allows overriding; change only the defaults. Document the tradeoff in the type-selection guide (§3.10). -- **Priority:** Medium — affects all 2D+ CArrayKokkos uses on CUDA. - -### 2.8 No SYCL backend path in `kokkos_types.h` -- **File:** `src/include/kokkos_types.h:49-70` -- **Problem:** The backend dispatch chain handles CUDA, OpenMP, Threads, and HIP, then falls back to `Kokkos::DefaultExecutionSpace`. There is no `#elif HAVE_SYCL` branch. Intel GPU clusters (Aurora at Argonne) use the Kokkos SYCL backend; MATAR builds targeting those machines fall through to the generic branch with no explicit memory space selection. -- **Fix:** Add a SYCL branch (after §1.2 propagates `HAVE_SYCL` via CMake): - ```cpp - #elif HAVE_SYCL - using DefaultMemSpace = Kokkos::Experimental::SYCLDeviceUSMSpace; - using DefaultExecSpace = Kokkos::Experimental::SYCL; - using DefaultLayout = Kokkos::LayoutLeft; - ``` - Add a `sycl` preset to `CMakePresets.json` (§5.1) that enables `Kokkos_ENABLE_SYCL` and passes `-DHAVE_SYCL=1` via `target_compile_definitions`. -- **Priority:** Low — Intel Aurora is a near-term target for DOE codes but not a v1 blocker. - -### 2.9 No CMake assertion that Kokkos was built with the requested backend -- **File:** `CMakeLists.txt:63-64` -- **Problem:** `find_package(Kokkos REQUIRED)` succeeds even when the installed Kokkos was built without CUDA. The mismatch is discovered at runtime (or not at all — kernels silently run on the host). The `CMakePresets.json` approach (§5.1) will use `FetchContent` to build the right Kokkos from scratch, making this less likely for new users. But users who point to a pre-installed Kokkos via `Kokkos_DIR` still hit this. -- **Fix:** After `find_package(Kokkos)`, assert the expected backend is enabled: - ```cmake - if(Matar_CUDA_BUILD) - kokkos_check(DEVICES CUDA) # fatal error if CUDA not in this Kokkos install - elseif(Matar_HIP_BUILD) - kokkos_check(DEVICES HIP) - endif() - ``` -- **Priority:** Medium. - ---- - -## 3. Documentation - -### 3.1 `host_types.h` has zero Doxygen comments across 5400+ lines -- **File:** `src/include/host_types.h` -- **Problem:** There are no `/*!`, `///`, or `/** */` Doxygen comments anywhere in `host_types.h`. The full serial type hierarchy — FArray, CArray, FMatrix, CMatrix, ViewFArray, ViewCArray, RaggedRightArray, RaggedDownArray, CSRArray, CSCArray (~14 types) — has zero per-method documentation. `kokkos_types.h` has Doxygen for the first type only (FArrayKokkos 1D–3D constructors); the remaining ~11,000 lines across the other Kokkos types are also bare. The Doxygen config (`docs_doxygen/Doxyfile`) exists but generates minimal output. -- **Fix:** Add `@brief`, `@param`, `@return` blocks to the constructors, `operator()`, `size()`, `dims()`, `pointer()`, and `set_values()` for all types. Start with `host_types.h` (CPU-only users' entry point), then `DCArrayKokkos`/`DCMatrixKokkos` (most common GPU types). The comment pattern is uniform across all types — a script can generate stubs in a few hours. -- **Priority:** High — most-used types in the library have zero generated docs. - -### 3.2 MPI types (`mpi_types.h`, `mapped_mpi_types.h`, `communication_plan.h`) have no Doxygen -- **Files:** `src/include/mpi_types.h`, `src/include/mapped_mpi_types.h`, `src/include/communication_plan.h` -- **Problem:** `MPICArrayKokkos`, `MPICMatrixKokkos`, `CommunicationPlan`, `PartitionMap`, and all related classes have no class-level `\brief` comments or method-level documentation. These are the most complex types in the library and the least documented. -- **Fix:** Add at minimum a class-level `\brief` and method documentation for the key public API: constructors, `communicate()`, `get_comm_plan()`, `update_host()`, `update_device()`. Add code examples (see §3.5). -- **Priority:** High — new API, no documentation = unusable for newcomers. - -### 3.3 Doxygen comments absent for 4D–7D constructors in all Kokkos types -- **File:** `src/include/kokkos_types.h` -- **Problem:** Only 1D–3D constructors have `\brief` / `\param` Doxygen. All 4D, 5D, 6D, 7D constructors are undocumented. The pattern repeats across all 16 Kokkos array/matrix types (~100 constructor overloads). -- **Fix:** Add `\brief` and `\param` entries for 4D–7D constructors. The pattern is uniform; a templated sed/awk script can generate stubs from the existing 1D–3D docs in an hour. -- **Priority:** Medium — affects all generated API docs. - -### 3.4 README typos and broken code examples -- **File:** `README.md:23, 31, 45` -- **Problems:** - - Lines 23, 31: "convection" → "convention" (appears twice in array access descriptions) - - Line 45: "idetical" → "identical" - - Lines 25, 34: for-loop syntax uses commas (`for (i=0,i` replaces `source scripts/build-matar.sh` - - `mtr::real_t` and `mtr::u_int` (namespaced — breaking if §2.4 is fixed) - - Minimum Kokkos version (≥3.7 for non-`Experimental` HIP) - - Removed `_old` headers -- **Priority:** Medium — important for downstream projects, especially given the build system change. - -### 3.9 No type-selection guide (when to use which MATAR type) -- **Problem:** The distinction between `CArrayKokkos` (device-only), `DCArrayKokkos` (dual host+device), `DViewCArrayKokkos` (wraps existing pointer), and `MPICArrayKokkos` (distributed) is non-obvious. New users regularly pick the wrong type, discover the issue at runtime, and must resort to reading source code. -- **Fix:** Add a decision-tree or table to the README or a `docs/choosing_a_type.md`: - - CPU-only data → `CArray` / `FArray` - - GPU-only data (no host access after init) → `CArrayKokkos` - - Data that moves between CPU and GPU → `DCArrayKokkos` - - Wrapping an existing host pointer for GPU use → `DViewCArrayKokkos` - - Distributed data across MPI ranks → `MPICArrayKokkos` - - Data that grows or shrinks at runtime on device → `DynamicArrayKokkos` (pre-allocate a capacity at construction; use `push_back`/`pop_back` within that capacity; use `resize()` — once §4.4 is implemented — to grow the backing buffer) -- **Priority:** Medium. - -### 3.10 `macros.h` header comment shows wrong macro names -- **File:** `src/include/macros.h:73-96` -- **Problem:** The header comment says "The syntax to use the FOR_REDUCE is as follows:" and shows `REDUCE_SUM(...)`. The actual macro is `FOR_REDUCE_SUM(...)`. Users who copy the example get a compile error. -- **Fix:** Update the comment block to use the actual macro names: `FOR_REDUCE_SUM`, `FOR_REDUCE_MAX`, `FOR_REDUCE_MIN`. -- **Priority:** Low. - -### 3.11 Sphinx / Doxygen docs are not built in CI -- **Files:** `docs_doxygen/`, `docs_sphinx/`, `.github/workflows/` -- **Problem:** Both a Doxygen config and a Sphinx `conf.py` exist, but neither is run in CI. Broken `\param` entries and broken rST go undetected. There is no Breathe/Exhale integration to pull Doxygen XML into Sphinx. -- **Fix:** Add a `docs.yml` GitHub Actions job: `doxygen docs_doxygen/Doxyfile && make -C docs_sphinx html`. Once `host_types.h` and `kokkos_types.h` have Doxygen coverage (§3.1), add Breathe to `docs_sphinx/conf.py` to pull the API docs into Sphinx. -- **Priority:** Low — implement after §3.1 adds Doxygen coverage. - ---- - -## 4. Performance - -### 4.1 `set_values()` launches a parallel kernel instead of `Kokkos::deep_copy` -- **File:** `src/include/kokkos_types.h` (all Kokkos types, e.g., line ~545 for FArrayKokkos) -- **Problem:** All `set_values` implementations do: - ```cpp - Kokkos::parallel_for("SetValues", length_, - KOKKOS_CLASS_LAMBDA(const int i){ this_array_(i) = val; }); - ``` - `Kokkos::deep_copy(view, scalar)` is the correct API: it uses `cudaMemset` for trivially-copyable types on CUDA, avoids kernel-scheduling overhead for small arrays, and is recognized by Kokkos profiling tools as a memory operation rather than a user kernel. The current approach also inherits the `const int` index overflow bug (§2.6). -- **Fix:** Replace all `set_values` bodies with: - ```cpp - Kokkos::deep_copy(this_array_, val); - ``` - For dual-view types (`DCArrayKokkos` etc.), call `Kokkos::deep_copy` on the device view, then `update_host()`. -- **Priority:** Medium. - -### 4.2 `CommunicationPlan` displacement setup is O(n²) — should use a prefix sum -- **File:** `src/include/communication_plan.h` (~line 359) -- **Problem:** `send_displs_` and `recv_displs_` are computed with a nested loop: - ```cpp - for(int i=0; i new_capacity) - dims_actual_size_[0] = new_capacity; - } - ``` - 2. Add a `void push_back_host(T value)` overload that writes directly from host memory (via a `Kokkos::View` mirror copy or by operating only when the execution space is a host space), and document that the `push_back(T value)` GPU path is only appropriate for device-side lambdas. - 3. Uncomment the 2D–7D constructors and `operator()` bodies, then extend `resize()` to the multi-dimensional case — `Kokkos::resize` accepts up to 8 extents for multi-rank views and the flat 1D backing `View` makes this straightforward. -- **Priority:** Medium — item 1 (resize) is a clear gap; items 2–3 improve usability before v1. - -### 4.5 `DViewCArrayKokkos` and related types do not warn on missing sync in debug builds -- **File:** `src/include/kokkos_types.h` (DView types) -- **Problem:** MATAR's DView wrappers expose `update_host()` and `update_device()` but there is no assertion or warning if a user accesses host data after modifying the device copy without calling `update_host()`. Silent stale-data reads are the most common MATAR user bug. -- **Fix:** In debug builds (`NDEBUG` not defined), add assertions in `operator()` checking the DualView's modification flags. Kokkos `DualView` already tracks these via `modified_host()` and `modified_device()`; MATAR should expose them in `assert()` calls on the host-side accessors. -- **Priority:** Medium. - -### 4.6 Benchmark suite is not in CI -- **File:** `benchmark/`, `.github/workflows/` -- **Problem:** A benchmark suite exists (`benchmark/src/CArray_benchmark.cpp`, `CArrayDevice_benchmark.cpp`) but is never run in CI. Performance regressions will not be caught before v1. -- **Fix:** After §5.4 adds `Matar_BUILD_BENCHMARKS` as a root CMake option, add a `benchmark.yml` CI job that uses the `serial` preset and runs with `--benchmark_min_time=0` to validate compilation and execution without timing comparisons. -- **Priority:** Medium (depends on §5.4). - -### 4.7 Unqualified `deep_copy` calls in DView types rely on ADL -- **File:** `src/include/kokkos_types.h` (~lines 2532, 3426, 5809, 6699) -- **Problem:** `DViewFArrayKokkos::update_host()` and `update_device()` call `deep_copy(...)` without `Kokkos::` qualification. ADL finds `Kokkos::deep_copy` through the Kokkos namespace, but if any header upstream defines a `deep_copy` in an associated namespace, the wrong one is silently called. -- **Fix:** Qualify all calls as `Kokkos::deep_copy(...)`. -- **Priority:** Low. - -### 4.8 Serial `reduce_sum` / `reduce_min` / `reduce_max` pass the accumulator by value -- **File:** `src/include/macros.h:1104-1242` -- **Problem:** The serial fallback functions take `T var` by value and reset it internally (`var = 0`). The original variable at the call site is never written. This pattern is surprising for readers and wastes a copy for non-trivial `T`. -- **Fix:** Remove the `var` parameter and declare the accumulator locally: - ```cpp - template - void reduce_sum(int i_start, int i_end, const F &lambda_fcn, T &result) { - T var = T{0}; - for(int i=i_start; i= 8, "MATAR requires 64-bit size_t")` at the top of `host_types.h` to catch 32-bit platform builds early. -- **Priority:** Medium. - -### 4.11 `MATAR_KOKKOS_INIT` / `MATAR_KOKKOS_FINALIZE` are exception-unsafe -- **File:** `src/include/macros.h:908-915` -- **Problem:** The manual `Kokkos::initialize` / `Kokkos::finalize` pair leaves Kokkos un-finalized if application code throws between them, potentially leaking GPU contexts. -- **Fix:** Add a recommended `MATAR_KOKKOS_SCOPE_GUARD` macro alongside the existing ones: - ```cpp - #define MATAR_KOKKOS_SCOPE_GUARD Kokkos::ScopeGuard _kokkos_sg(argc, argv); - ``` - Keep the old macros for backward compatibility. Reference `MATAR_KOKKOS_SCOPE_GUARD` in the GPU quick-start added to README (§3.5). -- **Priority:** Low. - ---- - -## 5. Build System Refactor (Primary v1 Goal) - -> **Goal:** Replace the `scripts/build-matar.sh` bash wrapper system entirely with a pure CMake build. The target workflow is: -> ``` -> cmake --preset cuda-mpi # configure -> cmake --build --preset cuda-mpi # build -> ctest --preset cuda-mpi # test -> ``` -> This is a prerequisite for: Windows portability, IDE integration (VS Code CMake Tools, CLion), removing the machine/bash dependency, and fixing the CI issues listed in §1.6. Items 5.1–5.4 are ordered as a dependency chain; complete them in sequence. - -### 5.1 Add `CMakePresets.json` — the new top-level build interface -- **Files (new):** `CMakePresets.json` at repo root -- **Replaces:** `scripts/build-matar.sh`, `scripts/cmake_build_test.sh`, `scripts/cmake_build_examples.sh`, `scripts/setup-env.sh` -- **Design:** One base preset (`base`) with shared defaults; all other presets `inherit` from it. Each backend gets a configure preset; build and test presets inherit the configure preset: - ```json - { - "version": 6, - "configurePresets": [ - { - "name": "base", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build-${presetName}", - "cacheVariables": { - "CMAKE_CXX_STANDARD": "17", - "Matar_ENABLE_KOKKOS": "ON" - } - }, - { "name": "serial", "inherits": "base", "displayName": "Serial CPU" }, - { "name": "serial-debug", "inherits": "serial", - "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "Matar_BUILD_TESTS": "ON" }}, - { "name": "openmp", "inherits": "base", - "cacheVariables": { "Kokkos_ENABLE_OPENMP": "ON" }}, - { "name": "cuda", "inherits": "base", - "cacheVariables": { "Kokkos_ENABLE_CUDA": "ON", "CMAKE_CUDA_ARCHITECTURES": "80" }}, - { "name": "hip", "inherits": "base", - "cacheVariables": { "Kokkos_ENABLE_HIP": "ON" }}, - { "name": "serial-mpi", "inherits": "serial", - "cacheVariables": { "Matar_ENABLE_MPI": "ON" }}, - { "name": "openmp-mpi", "inherits": "openmp", - "cacheVariables": { "Matar_ENABLE_MPI": "ON" }}, - { "name": "cuda-mpi", "inherits": "cuda", - "cacheVariables": { "Matar_ENABLE_MPI": "ON" }} - ], - "buildPresets": [ - { "name": "serial", "configurePreset": "serial" }, - { "name": "serial-debug", "configurePreset": "serial-debug" }, - { "name": "cuda", "configurePreset": "cuda" } - ], - "testPresets": [ - { "name": "serial", "configurePreset": "serial-debug", "output": { "outputOnFailure": true } }, - { "name": "serial-mpi", "configurePreset": "serial-mpi", "output": { "outputOnFailure": true } } - ] - } - ``` - Note: machine-specific paths (GPU architecture, MPI install prefix) belong in a `CMakeUserPresets.json` (gitignored) that inherits from the shared presets. -- **Priority:** High — all other build system items depend on this. - -### 5.2 Fold Kokkos dependency into root CMakeLists via `FetchContent` -- **Files:** `CMakeLists.txt`, `src/Kokkos/kokkos/` (existing submodule) -- **Replaces:** `scripts/kokkos-install.sh`, `scripts/trilinos-install.sh` (Trilinos path remains manual for now — Trilinos is too large for FetchContent) -- **Design:** Use a find-then-fetch pattern so power users with an existing Kokkos install are not forced to rebuild it: - ```cmake - find_package(Kokkos QUIET) - if(NOT Kokkos_FOUND) - message(STATUS "Kokkos not found — building from submodule src/Kokkos/kokkos") - set(FETCHCONTENT_SOURCE_DIR_KOKKOS ${CMAKE_SOURCE_DIR}/src/Kokkos/kokkos) - include(FetchContent) - FetchContent_Declare(kokkos SOURCE_DIR ${FETCHCONTENT_SOURCE_DIR_KOKKOS}) - FetchContent_MakeAvailable(kokkos) - endif() - ``` - The existing `src/Kokkos/kokkos` git submodule remains the version-pinned source. Delete `scripts/kokkos-install.sh` once this is verified. -- **Priority:** High (depends on §5.1). - -### 5.3 Update CI workflows to use `cmake --preset` -- **Files:** `.github/workflows/cmake.yml`, `.github/workflows/test.yml` -- **Replaces:** All `source build-matar.sh ...` steps in CI -- **Design:** Replace the multi-step bash script invocation with standard CMake preset calls: - ```yaml - - name: Configure - run: cmake --preset ${{ matrix.preset }} - - name: Build - run: cmake --build --preset ${{ matrix.preset }} - - name: Test - run: ctest --preset ${{ matrix.preset }} --output-on-failure - ``` - Matrix entries become `preset: [serial, serial-debug, openmp, serial-mpi]`. The macOS matrix uses the same presets (no `--machine` flag). Delete `cmake.yml` and consolidate into a single `test.yml`. This resolves §1.6 (macOS CI misconfiguration) and §1.6 (commented-out ctest) automatically. -- **Priority:** High (depends on §5.1 and §5.2). - -### 5.4 Fold test, example, and benchmark builds into root CMakeLists as optional subdirs -- **Files:** `CMakeLists.txt`, `test/CMakeLists.txt`, `examples/CMakeLists.txt`, `benchmark/CMakeLists.txt` -- **Replaces:** The standalone project structure that requires installing MATAR before building tests -- **Design:** Add to root `CMakeLists.txt`: - ```cmake - option(Matar_BUILD_TESTS "Build unit tests" OFF) - option(Matar_BUILD_EXAMPLES "Build examples" OFF) - option(Matar_BUILD_BENCHMARKS "Build benchmarks" OFF) - if(Matar_BUILD_TESTS) add_subdirectory(test) endif() - if(Matar_BUILD_EXAMPLES) add_subdirectory(examples) endif() - if(Matar_BUILD_BENCHMARKS) add_subdirectory(benchmark) endif() - ``` - Update each subdirectory's `CMakeLists.txt` to support both standalone and in-tree use: - ```cmake - if(NOT TARGET matar) - find_package(Matar REQUIRED) - endif() - ``` - Remove the non-standard `-DCUDA=ON` / `-DKOKKOS=ON` variables from `test/CMakeLists.txt` (resolved by §1.2 — backend macros flow from the `matar` target transitively). Enable `Matar_BUILD_TESTS=ON` in the `serial-debug` preset. -- **Priority:** High (depends on §5.1; also resolves §1.7 and §4.6). - -### 5.5 Replace `scripts/machines/` compiler paths with CMake toolchain files -- **Files:** `scripts/machines/mac-env.sh`, `scripts/machines/linux-env.sh`, `scripts/machines/darwin-env.sh` (new: `cmake/toolchains/`) -- **Replaces:** Hardcoded `/opt/homebrew/opt/llvm/bin/clang` and `/usr/bin/gcc` paths in shell env scripts -- **Design:** Create `cmake/toolchains/` with one file per target environment (e.g., `darwin-cluster.cmake`, `mac-homebrew-llvm.cmake`). Users pass `-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/darwin-cluster.cmake` or set `toolchainFile` in a `CMakeUserPresets.json`. This is the standard CMake pattern for cross-compilation and environment-specific compilers. -- **Priority:** Medium (depends on §5.1). - -### 5.6 Archive `scripts/` as legacy — do not delete immediately -- **Files:** `scripts/` -- **Plan:** After §5.1–§5.4 are complete and the CI is green on the new system, rename `scripts/` to `scripts/legacy/`. Add `scripts/legacy/README.md` explaining that these scripts are archived for reference and pointing to `CMakePresets.json`. Leave the files intact — they are useful for reproducing HPC environment-specific edge cases. Delete in v1.1 once no downstream users report dependency on them. -- **Priority:** Low (final step after §5.1–§5.4). - ---- - -## Summary Table - -| # | Category | Item | Priority | -|---|---|---|---| -| **5.1** | **Build** | **Add `CMakePresets.json` — new top-level build interface** | **High** | -| **5.2** | **Build** | **Fold Kokkos into root CMake via `FetchContent`** | **High** | -| **5.3** | **Build** | **Update CI to `cmake --preset` (resolves §1.6)** | **High** | -| **5.4** | **Build** | **Fold test/example/benchmark into root CMakeLists (resolves §1.7)** | **High** | -| 5.5 | Build | Replace machine env scripts with CMake toolchain files | Medium | -| 5.6 | Build | Archive `scripts/` as legacy after §5.1–§5.4 | Low | -| 1.1 | OS | `matar.h` unconditional MPI/Tpetra includes + angle-bracket include | High | -| 1.2 | OS | Backend macros not propagated by CMake install | High | -| 1.3 | OS | HIP uses deprecated `Kokkos::Experimental` namespace | High | -| 1.4 | OS | `_old` files installed alongside live headers | Low | -| 1.5 | OS | No `MATAR_VERSION` macro | Medium | -| 1.6 | OS | CI macOS `--machine=linux` + ctest not run (resolved by §5.3) | High | -| 1.7 | OS | `test/CMakeLists.txt` non-standard backend variables (resolved by §5.4 + §1.2) | Medium | -| 1.8 | OS | No macOS MPI CI | Low | -| 2.1 | GPU | `FOR_FIRST`/`DO_FIRST` hardcode warp size 32 | High | -| 2.2 | GPU | `F_LOOP_ORDER` wrong direction for GPU F-array traversal | High | -| 2.3 | GPU | `policy2D/3D/4D` don't bind `DefaultExecSpace` | Medium | -| 2.4 | GPU | `real_t`/`u_int` in global namespace — POSIX collision | High | -| 2.5 | GPU | `sone_dim2` typo in FArrayKokkos 6D/7D constructors | Medium | -| 2.6 | GPU | FOR_ALL loop indices use `const int` — limits to 2^31 elements | Medium | -| 2.7 | GPU | CArrayKokkos default `LayoutLeft` on CUDA contradicts C-order semantics | Medium | -| 2.8 | GPU | No SYCL backend path | Low | -| 2.9 | GPU | No CMake assertion that Kokkos has the requested backend | Medium | -| 3.1 | Docs | `host_types.h` zero Doxygen across 5400+ lines | High | -| 3.2 | Docs | MPI types have no class/method documentation | High | -| 3.3 | Docs | No Doxygen for 4D–7D constructors in Kokkos types | Medium | -| 3.4 | Docs | README typos and broken pseudocode | Medium | -| 3.5 | Docs | README has no GPU or MPI quick-start | Medium | -| 3.6 | Docs | No `PartitionMap`/`CommunicationPlan` usage example | High | -| 3.7 | Docs | No CHANGELOG | High | -| 3.8 | Docs | No v1 migration guide (especially for build system change) | Medium | -| 3.9 | Docs | No type-selection guide | Medium | -| 3.10 | Docs | `macros.h` header shows wrong macro names | Low | -| 3.11 | Docs | Sphinx/Doxygen not built in CI | Low | -| 4.1 | Perf | `set_values()` uses kernel launch instead of `Kokkos::deep_copy` | Medium | -| 4.2 | Perf | `CommunicationPlan` displacement setup is O(n²) | Medium | -| 4.3 | Perf | Redundant GPU fences in `CommunicationPlan` init | Low | -| 4.4 | Perf | `DynamicArrayKokkos`: no `resize()`, costly `push_back`, 2D–7D commented out | Medium | -| 4.5 | Perf | DView types have no sync-state assertions in debug builds | Medium | -| 4.6 | Perf | Benchmark suite not in CI (depends on §5.4) | Medium | -| 4.7 | Perf | Unqualified `deep_copy` calls in DView types | Low | -| 4.8 | Perf | Serial reduce accumulator passed by value | Low | -| 4.9 | Perf | `reduce_prod` has wrong `// MIN` comment | Low | -| 4.10 | Perf | Audit host-type index arithmetic for `int` overflow | Medium | -| 4.11 | Perf | `MATAR_KOKKOS_INIT` is exception-unsafe | Low | - ---- - -## v1 Blocking Items - -Items that must be complete before tagging 1.0, grouped by theme. - -### Build System (do first — everything else depends on it) -1. **5.1** Add `CMakePresets.json` -2. **5.2** Fold Kokkos into CMake via `FetchContent` -3. **5.3** Update CI to `cmake --preset` (also fixes §1.6) -4. **5.4** Fold test/example/benchmark into root CMakeLists (also fixes §1.7) - -### Correctness / Portability (parallel with build work) -5. **1.3** HIP deprecated `Kokkos::Experimental` — breaks Frontier builds today -6. **2.1** `FOR_FIRST` hardcoded warp size 32 — wrong on AMD HIP -7. **2.2** `F_LOOP_ORDER` wrong direction — non-coalesced GPU access for all FArray types -8. **2.4** `real_t`/`u_int` global namespace — compile failure with POSIX headers on Linux -9. **1.1** `matar.h` unconditional MPI/Tpetra includes — breaks clean installs -10. **1.2** Backend macros not propagated — wrong layout for OpenMP - -### Documentation (required for a usable v1 release) -11. **3.1** `host_types.h` zero Doxygen — most-used types in the library -12. **3.2** MPI types have no documentation — new API, cannot be used without docs -13. **3.6** No `PartitionMap`/`CommunicationPlan` usage example -14. **3.7** No CHANGELOG From e87882e9c05d56a473f753cd3bedae984bbab95a Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:13:20 -0500 Subject: [PATCH 03/43] BUG: Fix compiler warning --- examples/matar_mpi.cpp | 8 +++-- examples/mesh_decomp/install_ptscotch.sh | 36 ------------------- .../examples}/ann_distributed.cpp | 0 .../examples}/ann_distributed_crs.cpp | 0 .../examples}/test_tpetra_carray.cpp | 0 .../examples}/test_tpetra_crs.cpp | 0 .../examples}/test_tpetra_farray.cpp | 0 .../examples}/test_tpetra_mesh.cpp | 0 {scripts => legacy/scripts}/README.md | 0 {scripts => legacy/scripts}/build-matar.sh | 0 .../scripts}/cmake_build_benchmark.sh | 0 .../scripts}/cmake_build_examples.sh | 0 .../scripts}/cmake_build_test.sh | 0 {scripts => legacy/scripts}/kokkos-install.sh | 0 .../scripts}/legacy/cmake_build.sh | 0 .../scripts}/legacy/kokkos-install.sh | 0 .../scripts}/legacy/matar-install.sh | 0 .../scripts}/legacy/setup-env.sh | 0 .../scripts}/machines/darwin-env.sh | 0 .../scripts}/machines/linux-env.sh | 0 .../scripts}/machines/mac-env.sh | 0 {scripts => legacy/scripts}/matar-install.sh | 0 {scripts => legacy/scripts}/setup-env.sh | 0 .../scripts}/trilinos-install.sh | 0 24 files changed, 5 insertions(+), 39 deletions(-) delete mode 100755 examples/mesh_decomp/install_ptscotch.sh rename {examples => legacy/examples}/ann_distributed.cpp (100%) rename {examples => legacy/examples}/ann_distributed_crs.cpp (100%) rename {examples => legacy/examples}/test_tpetra_carray.cpp (100%) rename {examples => legacy/examples}/test_tpetra_crs.cpp (100%) rename {examples => legacy/examples}/test_tpetra_farray.cpp (100%) rename {examples => legacy/examples}/test_tpetra_mesh.cpp (100%) rename {scripts => legacy/scripts}/README.md (100%) rename {scripts => legacy/scripts}/build-matar.sh (100%) rename {scripts => legacy/scripts}/cmake_build_benchmark.sh (100%) rename {scripts => legacy/scripts}/cmake_build_examples.sh (100%) rename {scripts => legacy/scripts}/cmake_build_test.sh (100%) rename {scripts => legacy/scripts}/kokkos-install.sh (100%) rename {scripts => legacy/scripts}/legacy/cmake_build.sh (100%) rename {scripts => legacy/scripts}/legacy/kokkos-install.sh (100%) rename {scripts => legacy/scripts}/legacy/matar-install.sh (100%) rename {scripts => legacy/scripts}/legacy/setup-env.sh (100%) rename {scripts => legacy/scripts}/machines/darwin-env.sh (100%) rename {scripts => legacy/scripts}/machines/linux-env.sh (100%) rename {scripts => legacy/scripts}/machines/mac-env.sh (100%) rename {scripts => legacy/scripts}/matar-install.sh (100%) rename {scripts => legacy/scripts}/setup-env.sh (100%) rename {scripts => legacy/scripts}/trilinos-install.sh (100%) diff --git a/examples/matar_mpi.cpp b/examples/matar_mpi.cpp index 8f616fbf..e22bbe48 100644 --- a/examples/matar_mpi.cpp +++ b/examples/matar_mpi.cpp @@ -125,13 +125,15 @@ MATAR_INITIALIZE(argc, argv); // ------------------------------------------------------------------------- // all_reduce with fixed trailing indices (multi-dimensional arrays). // ------------------------------------------------------------------------- - const size_t n_elem = size * 10; + // Signed: FOR_ALL's multi-dim forms brace-initialize a signed MDRangePolicy, + // so unsigned bounds trigger -Wnarrowing. + const int n_elem = size * 10; // Rank-2: element centroid coordinates — elem_centroids(elem_id, elem_position) // with elem_position ∈ {0,1,2} as x, y, z. Reduce over elem_id for each axis. { - size_t n_elem = 3; - size_t num_coords = 3; + int n_elem = 3; + int num_coords = 3; MPICArrayKokkos elem_centroids(n_elem, num_coords,"elem_centroids"); elem_centroids.initialize_comm_plan(comm_plan); FOR_ALL(elem_id, 0, n_elem, diff --git a/examples/mesh_decomp/install_ptscotch.sh b/examples/mesh_decomp/install_ptscotch.sh deleted file mode 100755 index 29d3f853..00000000 --- a/examples/mesh_decomp/install_ptscotch.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Install script for Scotch and PT-Scotch -set -e - -# Configuration -LIB_DIR="lib" -# SCOTCH_VERSION="7.0.4" -# PTSCOTCH_VERSION="7.0.4" -# INSTALL_PREFIX="$(pwd)/${LIB_DIR}" - -# echo "Installing Scotch and PT-Scotch to ${INSTALL_PREFIX}" - -# Create lib directory if it doesn't exist -if [ ! -d "${LIB_DIR}" ]; then - mkdir -p "${LIB_DIR}" -fi -cd ${LIB_DIR} -# Clone and build Scotch -echo "Cloning Scotch..." -if [ -d "scotch" ]; then - rm -rf scotch -fi -git clone https://gitlab.inria.fr/scotch/scotch.git -cd scotch - -echo "Building Scotch..." -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release \ - -DSCOTCH_MPI=ON \ - -DMPI_C_COMPILER=mpicc \ - -DMPI_Fortran_COMPILER=mpifort -make - -echo "Installation complete! Libraries installed in: ${INSTALL_PREFIX}" \ No newline at end of file diff --git a/examples/ann_distributed.cpp b/legacy/examples/ann_distributed.cpp similarity index 100% rename from examples/ann_distributed.cpp rename to legacy/examples/ann_distributed.cpp diff --git a/examples/ann_distributed_crs.cpp b/legacy/examples/ann_distributed_crs.cpp similarity index 100% rename from examples/ann_distributed_crs.cpp rename to legacy/examples/ann_distributed_crs.cpp diff --git a/examples/test_tpetra_carray.cpp b/legacy/examples/test_tpetra_carray.cpp similarity index 100% rename from examples/test_tpetra_carray.cpp rename to legacy/examples/test_tpetra_carray.cpp diff --git a/examples/test_tpetra_crs.cpp b/legacy/examples/test_tpetra_crs.cpp similarity index 100% rename from examples/test_tpetra_crs.cpp rename to legacy/examples/test_tpetra_crs.cpp diff --git a/examples/test_tpetra_farray.cpp b/legacy/examples/test_tpetra_farray.cpp similarity index 100% rename from examples/test_tpetra_farray.cpp rename to legacy/examples/test_tpetra_farray.cpp diff --git a/examples/test_tpetra_mesh.cpp b/legacy/examples/test_tpetra_mesh.cpp similarity index 100% rename from examples/test_tpetra_mesh.cpp rename to legacy/examples/test_tpetra_mesh.cpp diff --git a/scripts/README.md b/legacy/scripts/README.md similarity index 100% rename from scripts/README.md rename to legacy/scripts/README.md diff --git a/scripts/build-matar.sh b/legacy/scripts/build-matar.sh similarity index 100% rename from scripts/build-matar.sh rename to legacy/scripts/build-matar.sh diff --git a/scripts/cmake_build_benchmark.sh b/legacy/scripts/cmake_build_benchmark.sh similarity index 100% rename from scripts/cmake_build_benchmark.sh rename to legacy/scripts/cmake_build_benchmark.sh diff --git a/scripts/cmake_build_examples.sh b/legacy/scripts/cmake_build_examples.sh similarity index 100% rename from scripts/cmake_build_examples.sh rename to legacy/scripts/cmake_build_examples.sh diff --git a/scripts/cmake_build_test.sh b/legacy/scripts/cmake_build_test.sh similarity index 100% rename from scripts/cmake_build_test.sh rename to legacy/scripts/cmake_build_test.sh diff --git a/scripts/kokkos-install.sh b/legacy/scripts/kokkos-install.sh similarity index 100% rename from scripts/kokkos-install.sh rename to legacy/scripts/kokkos-install.sh diff --git a/scripts/legacy/cmake_build.sh b/legacy/scripts/legacy/cmake_build.sh similarity index 100% rename from scripts/legacy/cmake_build.sh rename to legacy/scripts/legacy/cmake_build.sh diff --git a/scripts/legacy/kokkos-install.sh b/legacy/scripts/legacy/kokkos-install.sh similarity index 100% rename from scripts/legacy/kokkos-install.sh rename to legacy/scripts/legacy/kokkos-install.sh diff --git a/scripts/legacy/matar-install.sh b/legacy/scripts/legacy/matar-install.sh similarity index 100% rename from scripts/legacy/matar-install.sh rename to legacy/scripts/legacy/matar-install.sh diff --git a/scripts/legacy/setup-env.sh b/legacy/scripts/legacy/setup-env.sh similarity index 100% rename from scripts/legacy/setup-env.sh rename to legacy/scripts/legacy/setup-env.sh diff --git a/scripts/machines/darwin-env.sh b/legacy/scripts/machines/darwin-env.sh similarity index 100% rename from scripts/machines/darwin-env.sh rename to legacy/scripts/machines/darwin-env.sh diff --git a/scripts/machines/linux-env.sh b/legacy/scripts/machines/linux-env.sh similarity index 100% rename from scripts/machines/linux-env.sh rename to legacy/scripts/machines/linux-env.sh diff --git a/scripts/machines/mac-env.sh b/legacy/scripts/machines/mac-env.sh similarity index 100% rename from scripts/machines/mac-env.sh rename to legacy/scripts/machines/mac-env.sh diff --git a/scripts/matar-install.sh b/legacy/scripts/matar-install.sh similarity index 100% rename from scripts/matar-install.sh rename to legacy/scripts/matar-install.sh diff --git a/scripts/setup-env.sh b/legacy/scripts/setup-env.sh similarity index 100% rename from scripts/setup-env.sh rename to legacy/scripts/setup-env.sh diff --git a/scripts/trilinos-install.sh b/legacy/scripts/trilinos-install.sh similarity index 100% rename from scripts/trilinos-install.sh rename to legacy/scripts/trilinos-install.sh From 0ccd5b9a65d0dc4ac65718f8e449edf250c92d61 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:16:09 -0500 Subject: [PATCH 04/43] BUG: Fix assert in DynamicRaggedDownArrayKokkos --- src/include/kokkos_types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 8531ade1..2c993502 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -10002,9 +10002,9 @@ size_t DynamicRaggedDownArrayKokkos::size() con template KOKKOS_INLINE_FUNCTION size_t DynamicRaggedDownArrayKokkos::dims(size_t i) const { - assert(i < 3 && "DynamicRaggedDownArrayKokkos dims only supports dims(0) or dims(1)!"); + assert(i < 2 && "DynamicRaggedDownArrayKokkos dims only supports dims(0) or dims(1)!"); if(i == 0) return dim1_; - if(i == 1) return dim2_; + return dim2_; } // overload operator () to access data as an array(i,j) From 661c97925d79bec7abbe3f4294967e01b8140ae1 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:16:52 -0500 Subject: [PATCH 05/43] ENH: Add misssing reduce_prod for serial macros --- src/include/macros.h | 77 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/src/include/macros.h b/src/include/macros.h index a6648574..4bcabc13 100644 --- a/src/include/macros.h +++ b/src/include/macros.h @@ -1244,7 +1244,7 @@ void reduce_max (int i_start, int i_end, -// MIN +// PRODUCT template void reduce_prod (int i_start, int i_end, T var, @@ -1257,6 +1257,39 @@ void reduce_prod (int i_start, int i_end, }; // end for_reduce +template +void reduce_prod (int i_start, int i_end, + int j_start, int j_end, + T var, + const F &lambda_fcn, T &result){ + var = 1.0; + for (int i=i_start; i +void reduce_prod (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + T var, + const F &lambda_fcn, T &result){ + var = 1.0; + for (int i=i_start; i Date: Tue, 25 Aug 2026 17:17:29 -0500 Subject: [PATCH 06/43] ENH: Adding MPI header guards for mpi_types --- src/include/matar.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/matar.h b/src/include/matar.h index 484d87a6..09b25329 100644 --- a/src/include/matar.h +++ b/src/include/matar.h @@ -81,6 +81,9 @@ #include "host_types.h" #include "kokkos_types.h" #include "aliases.h" + +#ifdef HAVE_MPI #include "mpi_types.h" +#endif #endif // MATAR_H From 919e2acdbf02c903a064fbdd33bb63f522e6ba1c Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:18:37 -0500 Subject: [PATCH 07/43] ENH: Swapping to CMake build system, WIP --- CMakeLists.txt | 180 ++++++++++++++++++++++ CMakePresets.json | 111 +++++++++++++ benchmark/CMakeLists.txt | 71 +++------ benchmark/src/CArrayDevice_benchmark.cpp | 2 +- cmake/MatarConfig.cmake.in | 17 +- examples/CMakeLists.txt | 147 ++---------------- examples/halfspace_cooling/CMakeLists.txt | 11 +- examples/laplace/CMakeLists.txt | 12 +- examples/laplaceMPI/CMakeLists.txt | 27 +--- examples/mesh_decomp/CMakeLists.txt | 59 +++---- examples/pointcloud/CMakeLists.txt | 21 +-- examples/sparsetests/CMakeLists.txt | 22 +-- examples/test_rocm/CMakeLists.txt | 26 +--- examples/virtualFcnKokkos/CMakeLists.txt | 15 +- examples/virtualFcnMATAR/CMakeLists.txt | 21 +-- examples/watt-graph/CMakeLists.txt | 23 +-- test/CMakeLists.txt | 64 +++----- test/test_cases/CMakeLists.txt | 42 +++-- 18 files changed, 421 insertions(+), 450 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..469f502b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,180 @@ +cmake_minimum_required(VERSION 3.21) + +project(Matar VERSION 1.0.0 LANGUAGES CXX) + +# ----------------------------------------------------------------------------- +# Options +# ----------------------------------------------------------------------------- +option(MATAR_ENABLE_KOKKOS "Enable the Kokkos-backed device/dual MATAR types" ON) +option(MATAR_ENABLE_MPI "Enable the MPI-aware MATAR types (MPICArrayKokkos, CommunicationPlan)" OFF) +option(MATAR_ENABLE_GPU_AWARE_MPI "Assume the MPI implementation is GPU-aware (device buffers passed to MPI)" OFF) +option(MATAR_USE_EXTERNAL_KOKKOS "Use an already-installed Kokkos (find_package) instead of building the bundled submodule" OFF) +option(MATAR_BUILD_EXAMPLES "Build the MATAR example programs" OFF) +option(MATAR_BUILD_TESTS "Build the MATAR unit tests" OFF) +option(MATAR_BUILD_BENCHMARKS "Build the MATAR benchmarks" OFF) +option(MATAR_INSTALL "Generate install/export rules" ${PROJECT_IS_TOP_LEVEL}) + +# Trilinos support has been removed; the old Trilinos-based build lives in legacy/. +if(DEFINED Matar_ENABLE_TRILINOS OR DEFINED Matar_KOKKOS_PACKAGE) + message(FATAL_ERROR + "Trilinos support has been removed from MATAR. " + "See legacy/CMakeLists.txt for the retired Trilinos build.") +endif() + +# Map the old option names used by existing consumers (ELEMENTS, Fierro). +if(DEFINED Matar_ENABLE_KOKKOS) + message(DEPRECATION "Matar_ENABLE_KOKKOS is deprecated; use MATAR_ENABLE_KOKKOS") + set(MATAR_ENABLE_KOKKOS ${Matar_ENABLE_KOKKOS}) +endif() +if(DEFINED Matar_ENABLE_MPI) + message(DEPRECATION "Matar_ENABLE_MPI is deprecated; use MATAR_ENABLE_MPI") + set(MATAR_ENABLE_MPI ${Matar_ENABLE_MPI}) +endif() + +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) + endif() +endif() + +# ----------------------------------------------------------------------------- +# Vectorization flags (cmake/Modules/FindVector.cmake) +# +# Detects per-compiler auto-vectorization flags and appends them to the Release +# flags for everything compiled in this tree (examples, tests, benchmarks, and +# the bundled Kokkos). Toggles: +# -DCMAKE_VECTOR_NOVEC=ON same flags but with vectorization disabled +# -DCMAKE_VECTOR_VERBOSE=ON compiler vectorization reports +# ----------------------------------------------------------------------------- +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") +find_package(Vector) +if(CMAKE_VECTOR_NOVEC) + set(VECTOR_C_FLAGS "${VECTOR_NOVEC_C_FLAGS}") + set(VECTOR_CXX_FLAGS "${VECTOR_NOVEC_CXX_FLAGS}") +endif() +if(CMAKE_VECTOR_VERBOSE) + set(VECTOR_C_FLAGS "${VECTOR_C_FLAGS} ${VECTOR_C_VERBOSE}") + set(VECTOR_CXX_FLAGS "${VECTOR_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") +endif() +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${VECTOR_C_FLAGS}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") + +# ----------------------------------------------------------------------------- +# The matar target (header-only) +# ----------------------------------------------------------------------------- +add_library(matar INTERFACE) +add_library(matar::matar ALIAS matar) + +target_compile_features(matar INTERFACE cxx_std_17) +target_include_directories(matar INTERFACE + $ + $ +) + +# ----------------------------------------------------------------------------- +# Kokkos +# +# Backend selection is done with the standard Kokkos cache variables +# (Kokkos_ENABLE_OPENMP, Kokkos_ENABLE_CUDA, Kokkos_ARCH_*, ...), which the +# bundled submodule build consumes directly. An external Kokkos is used only +# when explicitly requested, so higher-level projects get a Kokkos built to +# match the backend they asked for. +# ----------------------------------------------------------------------------- +if(MATAR_ENABLE_KOKKOS) + if(TARGET Kokkos::kokkos) + # A parent project already provides Kokkos; adding the submodule again + # would define duplicate targets. + set(MATAR_KOKKOS_PROVIDER "parent") + elseif(MATAR_USE_EXTERNAL_KOKKOS) + find_package(Kokkos CONFIG REQUIRED) + set(MATAR_KOKKOS_PROVIDER "external") + else() + if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/Kokkos/kokkos/CMakeLists.txt) + message(FATAL_ERROR + "The bundled Kokkos submodule is missing. Run:\n" + " git submodule update --init --recursive\n" + "or point at an installed Kokkos with " + "-DMATAR_USE_EXTERNAL_KOKKOS=ON -DKokkos_ROOT=") + endif() + add_subdirectory(src/Kokkos/kokkos) + set(MATAR_KOKKOS_PROVIDER "bundled") + endif() + + target_link_libraries(matar INTERFACE Kokkos::kokkos) + target_compile_definitions(matar INTERFACE HAVE_KOKKOS=1) + + if(Kokkos_ENABLE_CUDA) + target_compile_definitions(matar INTERFACE HAVE_CUDA=1) + elseif(Kokkos_ENABLE_HIP) + target_compile_definitions(matar INTERFACE HAVE_HIP=1) + elseif(Kokkos_ENABLE_OPENMP) + target_compile_definitions(matar INTERFACE HAVE_OPENMP=1) + elseif(Kokkos_ENABLE_THREADS) + target_compile_definitions(matar INTERFACE HAVE_THREADS=1) + endif() +endif() + +# ----------------------------------------------------------------------------- +# MPI +# ----------------------------------------------------------------------------- +if(MATAR_ENABLE_MPI) + find_package(MPI REQUIRED COMPONENTS CXX) + target_link_libraries(matar INTERFACE MPI::MPI_CXX) + target_compile_definitions(matar INTERFACE HAVE_MPI=1) + if(MATAR_ENABLE_GPU_AWARE_MPI) + target_compile_definitions(matar INTERFACE HAVE_GPU_AWARE_MPI) + endif() +endif() + +# ----------------------------------------------------------------------------- +# Install / export +# +# When the bundled Kokkos is used, its own install rules run too, so Kokkos is +# installed into the same prefix and MatarConfig's find_dependency(Kokkos) +# resolves against the sibling KokkosConfig.cmake. +# ----------------------------------------------------------------------------- +if(MATAR_INSTALL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + install(TARGETS matar EXPORT MatarTargets) + install(DIRECTORY src/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h") + + install(EXPORT MatarTargets + NAMESPACE matar:: + FILE MatarTargets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matar) + + configure_package_config_file( + cmake/MatarConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/MatarConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matar) + + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/MatarConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT) + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/MatarConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/MatarConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matar) +endif() + +# ----------------------------------------------------------------------------- +# Examples / tests / benchmarks +# ----------------------------------------------------------------------------- +if(MATAR_BUILD_TESTS) + enable_testing() + add_subdirectory(test) +endif() +if(MATAR_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() +if(MATAR_BUILD_BENCHMARKS) + add_subdirectory(benchmark) +endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..d2553098 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,111 @@ +{ + "version": 3, + "cmakeMinimumRequired": { "major": 3, "minor": 21, "patch": 0 }, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "MATAR_BUILD_TESTS": "ON", + "MATAR_BUILD_EXAMPLES": "ON" + } + }, + { + "name": "kokkos", + "hidden": true, + "inherits": "base", + "cacheVariables": { + "MATAR_ENABLE_KOKKOS": "ON", + "Kokkos_ENABLE_SERIAL": "ON", + "Kokkos_ARCH_NATIVE": "ON" + } + }, + { + "name": "mpi", + "hidden": true, + "cacheVariables": { "MATAR_ENABLE_MPI": "ON" } + }, + { + "name": "debug", + "hidden": true, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } + }, + + { "name": "serial", "displayName": "Kokkos serial backend", "inherits": "kokkos" }, + { + "name": "openmp", + "displayName": "Kokkos OpenMP backend", + "inherits": "kokkos", + "cacheVariables": { "Kokkos_ENABLE_OPENMP": "ON" } + }, + { + "name": "pthreads", + "displayName": "Kokkos std::threads backend", + "inherits": "kokkos", + "cacheVariables": { "Kokkos_ENABLE_THREADS": "ON" } + }, + { + "name": "cuda", + "displayName": "Kokkos CUDA backend", + "inherits": "kokkos", + "cacheVariables": { + "Kokkos_ENABLE_CUDA": "ON", + "Kokkos_ENABLE_CUDA_CONSTEXPR": "ON", + "Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE": "ON" + } + }, + { + "name": "hip", + "displayName": "Kokkos HIP backend", + "inherits": "kokkos", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "hipcc", + "Kokkos_ENABLE_HIP": "ON", + "Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE": "ON" + } + }, + + { "name": "serial-mpi", "displayName": "Kokkos serial backend + MPI", "inherits": ["serial", "mpi"] }, + { "name": "openmp-mpi", "displayName": "Kokkos OpenMP backend + MPI", "inherits": ["openmp", "mpi"] }, + { "name": "cuda-mpi", "displayName": "Kokkos CUDA backend + MPI", "inherits": ["cuda", "mpi"] }, + { "name": "hip-mpi", "displayName": "Kokkos HIP backend + MPI", "inherits": ["hip", "mpi"] }, + + { "name": "serial-debug", "inherits": ["serial", "debug"] }, + { "name": "openmp-debug", "inherits": ["openmp", "debug"] }, + { "name": "cuda-debug", "inherits": ["cuda", "debug"] }, + { "name": "hip-debug", "inherits": ["hip", "debug"] }, + { "name": "serial-mpi-debug", "inherits": ["serial-mpi", "debug"] } + ], + "buildPresets": [ + { "name": "serial", "configurePreset": "serial" }, + { "name": "openmp", "configurePreset": "openmp" }, + { "name": "pthreads", "configurePreset": "pthreads" }, + { "name": "cuda", "configurePreset": "cuda" }, + { "name": "hip", "configurePreset": "hip" }, + { "name": "serial-mpi", "configurePreset": "serial-mpi" }, + { "name": "openmp-mpi", "configurePreset": "openmp-mpi" }, + { "name": "cuda-mpi", "configurePreset": "cuda-mpi" }, + { "name": "hip-mpi", "configurePreset": "hip-mpi" }, + { "name": "serial-debug", "configurePreset": "serial-debug" }, + { "name": "openmp-debug", "configurePreset": "openmp-debug" }, + { "name": "cuda-debug", "configurePreset": "cuda-debug" }, + { "name": "hip-debug", "configurePreset": "hip-debug" }, + { "name": "serial-mpi-debug", "configurePreset": "serial-mpi-debug" } + ], + "testPresets": [ + { "name": "serial", "configurePreset": "serial", "output": { "outputOnFailure": true } }, + { "name": "openmp", "configurePreset": "openmp", "output": { "outputOnFailure": true } }, + { "name": "pthreads", "configurePreset": "pthreads", "output": { "outputOnFailure": true } }, + { "name": "cuda", "configurePreset": "cuda", "output": { "outputOnFailure": true } }, + { "name": "hip", "configurePreset": "hip", "output": { "outputOnFailure": true } }, + { "name": "serial-mpi", "configurePreset": "serial-mpi", "output": { "outputOnFailure": true } }, + { "name": "openmp-mpi", "configurePreset": "openmp-mpi", "output": { "outputOnFailure": true } }, + { "name": "cuda-mpi", "configurePreset": "cuda-mpi", "output": { "outputOnFailure": true } }, + { "name": "hip-mpi", "configurePreset": "hip-mpi", "output": { "outputOnFailure": true } }, + { "name": "serial-debug", "configurePreset": "serial-debug", "output": { "outputOnFailure": true } }, + { "name": "openmp-debug", "configurePreset": "openmp-debug", "output": { "outputOnFailure": true } }, + { "name": "serial-mpi-debug", "configurePreset": "serial-mpi-debug", "output": { "outputOnFailure": true } } + ] +} diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 0a548973..81ffd0d6 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,54 +1,19 @@ -cmake_minimum_required(VERSION 3.5) - -project (matarbenchmark) - -set(benchmark_DIR "benchmark/build") - -find_package(benchmark REQUIRED) -find_package(Matar REQUIRED) - - - - - -if (NOT KOKKOS) - add_executable(BM_Carray src/CArray_benchmark.cpp) - target_link_libraries(BM_Carray matar benchmark::benchmark) +include(FetchContent) + +FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.8.3 +) +set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) +set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE) +set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(benchmark) + +add_executable(BM_CArray src/CArray_benchmark.cpp) +target_link_libraries(BM_CArray matar::matar benchmark::benchmark) + +if(MATAR_ENABLE_KOKKOS) + add_executable(BM_CArrayDevice src/CArrayDevice_benchmark.cpp) + target_link_libraries(BM_CArrayDevice matar::matar benchmark::benchmark) endif() - -if (KOKKOS) - find_package(Kokkos REQUIRED) #new - - add_definitions(-DHAVE_KOKKOS=1) - - add_executable(BM_CArray src/CArray_benchmark.cpp) - target_link_libraries(BM_CArray matar Kokkos::kokkos benchmark::benchmark) - - add_executable(BM_CArrayDevice src/CArrayDevice_benchmark.cpp) - target_link_libraries(BM_CArrayDevice matar Kokkos::kokkos benchmark::benchmark) - - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() -endif() - -# find_package(Kokkos REQUIRED) #new - -# set(This matar_benchmark) - -# set(Sources -# src/serial_types_benchmark.cpp -# ) - - - - -# if (KOKKOKS) -# target_link_libraries(${This} matar Kokkos::kokkos benchmark::benchmark) -# endif () diff --git a/benchmark/src/CArrayDevice_benchmark.cpp b/benchmark/src/CArrayDevice_benchmark.cpp index 71462125..313e1546 100644 --- a/benchmark/src/CArrayDevice_benchmark.cpp +++ b/benchmark/src/CArrayDevice_benchmark.cpp @@ -57,7 +57,7 @@ static void BM_CArrayDevice_vec_vec_dot(benchmark::State& state) double loc_sum = 0; double C = 0; - REDUCE_SUM(i, 0, size, + FOR_REDUCE_SUM(i, 0, size, loc_sum, { loc_sum += A(i)*B(i); }, C); diff --git a/cmake/MatarConfig.cmake.in b/cmake/MatarConfig.cmake.in index a673ed41..688359c5 100644 --- a/cmake/MatarConfig.cmake.in +++ b/cmake/MatarConfig.cmake.in @@ -1,4 +1,19 @@ @PACKAGE_INIT@ +include(CMakeFindDependencyMacro) + +if(@MATAR_ENABLE_KOKKOS@) + find_dependency(Kokkos) +endif() +if(@MATAR_ENABLE_MPI@) + find_dependency(MPI COMPONENTS CXX) +endif() + include("${CMAKE_CURRENT_LIST_DIR}/MatarTargets.cmake") -check_required_components("@Matar@") + +# Older consumers link against plain `matar` rather than matar::matar. +if(NOT TARGET matar) + add_library(matar ALIAS matar::matar) +endif() + +check_required_components(Matar) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index aecbe314..c5ea9b95 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,100 +1,25 @@ -cmake_minimum_required(VERSION 3.8) +set(LINKING_LIBRARIES matar::matar) -# --- custom targets: --- +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../solvers) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -if (NOT TARGET distclean) - # Only include distclean if it has not already been defined (by any - # other package that defines distclean and uses MATAR as a submodule) - INCLUDE(../cmake/Modules/TargetDistclean.cmake OPTIONAL) -endif (NOT TARGET distclean) - -find_package(Matar REQUIRED) -set(LINKING_LIBRARIES matar) - -include_directories(../solvers) - -if (MPI) - find_package(MPI REQUIRED) - add_definitions(-DHAVE_MPI=1) - list(APPEND LINKING_LIBRARIES MPI::MPI_CXX) - if (GPU_AWARE_MPI) - add_definitions(-DHAVE_GPU_AWARE_MPI) -# elseif (GPU_SHARED_MEM) -# add_definitions(-DHAVE_GPU_SHARED_MEM) - endif() -endif() - -if (NOT KOKKOS) +if (NOT MATAR_ENABLE_KOKKOS) add_executable(mtest main.cpp) target_link_libraries(mtest ${LINKING_LIBRARIES}) - add_executable(test_for test_for.cpp) - target_link_libraries(test_for ${LINKING_LIBRARIES}) + add_executable(test_for test_for.cpp) + target_link_libraries(test_for ${LINKING_LIBRARIES}) - add_executable(test_shared_ptr test_shared_ptr.cpp) - target_link_libraries(test_shared_ptr ${LINKING_LIBRARIES}) + add_executable(test_shared_ptr test_shared_ptr.cpp) + target_link_libraries(test_shared_ptr ${LINKING_LIBRARIES}) endif() -if (KOKKOS) - if (Matar_ENABLE_TRILINOS) - find_package(Trilinos REQUIRED) #new - # Assume if the CXX compiler exists, the rest do too. - if (EXISTS ${Trilinos_CXX_COMPILER}) - set(CMAKE_CXX_COMPILER ${Trilinos_CXX_COMPILER}) - set(CMAKE_C_COMPILER ${Trilinos_C_COMPILER}) - set(CMAKE_Fortran_COMPILER ${Trilinos_Fortran_COMPILER}) - endif() - if(NOT DISTRIBUTION) - # Make sure to use same compilers and flags as Trilinos - set(CMAKE_CXX_FLAGS "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") - set(CMAKE_Fortran_FLAGS "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}") - endif() - - message("\nFound Trilinos! Here are the details: ") - message(" Trilinos_DIR = ${Trilinos_DIR}") - message(" Trilinos_VERSION = ${Trilinos_VERSION}") - message(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}") - message(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES}") - message(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS}") - message(" Trilinos_LIBRARY_DIRS = ${Trilinos_LIBRARY_DIRS}") - message(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}") - message(" Trilinos_TPL_INCLUDE_DIRS = ${Trilinos_TPL_INCLUDE_DIRS}") - message(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}") - message(" Trilinos_TPL_LIBRARY_DIRS = ${Trilinos_TPL_LIBRARY_DIRS}") - message(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}") - message("End of Trilinos details\n") - - include_directories(${Trilinos_INCLUDE_DIRS} ${Trilinos_TPL_INCLUDE_DIRS}) - list(APPEND LINKING_LIBRARIES Trilinos::all_selected_libs) - add_definitions(-DTRILINOS_INTERFACE=1) - else() - find_package(Kokkos REQUIRED) #new - list(APPEND LINKING_LIBRARIES Kokkos::kokkos) - endif() - - - add_definitions(-DHAVE_KOKKOS=1) - - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - +if (MATAR_ENABLE_KOKKOS) add_executable(testsetval test_set_values.cpp) target_link_libraries(testsetval ${LINKING_LIBRARIES}) add_executable(mtestkokkos main_kokkos.cpp) target_link_libraries(mtestkokkos ${LINKING_LIBRARIES}) - add_executable(drrak_test test_drrak.cpp) target_link_libraries(drrak_test ${LINKING_LIBRARIES}) @@ -119,9 +44,6 @@ if (KOKKOS) add_executable(annkokkos_compare ann_kokkos_compare.cpp) target_link_libraries(annkokkos_compare ${LINKING_LIBRARIES}) - #add_executable(ompperftest ompperftest.cpp) - #target_link_libraries(ompperftest ${LINKING_LIBRARIES}) - add_executable(lu_test test_lu_solve.cpp) target_link_libraries(lu_test ${LINKING_LIBRARIES}) @@ -131,85 +53,38 @@ if (KOKKOS) add_executable(cramers_rule_test test_cramers_rule.cpp) target_link_libraries(cramers_rule_test ${LINKING_LIBRARIES}) - include_directories(pointcloud) add_subdirectory(pointcloud) - - if (Matar_ENABLE_TRILINOS) - add_executable(anndistributed ann_distributed.cpp) - target_link_libraries(anndistributed ${LINKING_LIBRARIES}) - - add_executable(anndistributed_crs ann_distributed_crs.cpp) - target_link_libraries(anndistributed_crs ${LINKING_LIBRARIES}) - - add_executable(test_tpetra_farray test_tpetra_farray.cpp) - target_link_libraries(test_tpetra_farray ${LINKING_LIBRARIES}) - - add_executable(test_tpetra_carray test_tpetra_carray.cpp) - target_link_libraries(test_tpetra_carray ${LINKING_LIBRARIES}) - - add_executable(test_tpetra_crs test_tpetra_crs.cpp) - target_link_libraries(test_tpetra_crs ${LINKING_LIBRARIES}) - - add_executable(test_tpetra_mesh test_tpetra_mesh.cpp) - target_link_libraries(test_tpetra_mesh ${LINKING_LIBRARIES}) - endif() - - if (OPENMP) + if (Kokkos_ENABLE_OPENMP) add_executable(parallel_hello_world parallel_hello_world.cpp) target_link_libraries(parallel_hello_world ${LINKING_LIBRARIES}) endif() - if (MPI) - include_directories(laplaceMPI) + if (MATAR_ENABLE_MPI) add_subdirectory(laplaceMPI) - - include_directories(mesh_decomp) add_subdirectory(mesh_decomp) add_executable(matar_mpi matar_mpi.cpp) target_link_libraries(matar_mpi ${LINKING_LIBRARIES}) endif() - endif() ### HIP Linking error, will add back in after fixed -if (NOT HIP) - include_directories(virtualFcnKokkos) +if (NOT Kokkos_ENABLE_HIP) add_subdirectory(virtualFcnKokkos) endif() # In testing, not working -#include_directories(gArrayofgArrays) #add_subdirectory(gArrayofgArrays) -include_directories(virtualFcnMATAR) add_subdirectory(virtualFcnMATAR) - -include_directories(laplace) add_subdirectory(laplace) - -include_directories(halfspace_cooling) add_subdirectory(halfspace_cooling) - -include_directories(watt-graph) add_subdirectory(watt-graph) - -#include_directories(matar_fortran) #add_subdirectory(matar_fortran) - -include_directories(sparsetests) add_subdirectory(sparsetests) - -include_directories(test_rocm) add_subdirectory(test_rocm) - -# include_directories(phaseField/srcKokkosVerbose) # add_subdirectory(phaseField/srcKokkosVerbose) - -# include_directories(phaseField/srcMacros) # add_subdirectory(phaseField/srcMacros) - -# include_directories(phaseFieldMPI) # add_subdirectory(phaseFieldMPI) diff --git a/examples/halfspace_cooling/CMakeLists.txt b/examples/halfspace_cooling/CMakeLists.txt index 91bffb75..3e8526ee 100644 --- a/examples/halfspace_cooling/CMakeLists.txt +++ b/examples/halfspace_cooling/CMakeLists.txt @@ -1,13 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -find_package(Matar REQUIRED) - -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - +if (MATAR_ENABLE_KOKKOS) add_executable(halfspace_cooling halfspace_cooling.cpp) - - add_definitions(-DHAVE_KOKKOS=1) - target_link_libraries(halfspace_cooling ${LINKING_LIBRARIES}) endif() diff --git a/examples/laplace/CMakeLists.txt b/examples/laplace/CMakeLists.txt index b3122cd0..7dab9555 100644 --- a/examples/laplace/CMakeLists.txt +++ b/examples/laplace/CMakeLists.txt @@ -1,8 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -find_package(Matar REQUIRED) - -if (NOT KOKKOS) +if (NOT MATAR_ENABLE_KOKKOS) add_executable(carray_right main_carray_right.cpp) add_executable(carray_wrong main_carray_wrong.cpp) add_executable(farray_right main_farray_right.cpp) @@ -14,17 +10,13 @@ if (NOT KOKKOS) target_link_libraries(farray_wrong ${LINKING_LIBRARIES}) endif() -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - +if (MATAR_ENABLE_KOKKOS) add_executable(kokkosview main_kokkosview.cpp) add_executable(carraykokkos_default_indexing main_carraykokkos_default_indexing.cpp) add_executable(carraykokkos_c_indexing main_carraykokkos_c_indexing.cpp) add_executable(farraykokkos_default_indexing main_farraykokkos_default_indexing.cpp) add_executable(farraykokkos_f_indexing main_farraykokkos_f_indexing.cpp) - add_definitions(-DHAVE_KOKKOS=1) - target_link_libraries(kokkosview ${LINKING_LIBRARIES}) target_link_libraries(carraykokkos_default_indexing ${LINKING_LIBRARIES}) target_link_libraries(carraykokkos_c_indexing ${LINKING_LIBRARIES}) diff --git a/examples/laplaceMPI/CMakeLists.txt b/examples/laplaceMPI/CMakeLists.txt index d722fac9..67aad3da 100644 --- a/examples/laplaceMPI/CMakeLists.txt +++ b/examples/laplaceMPI/CMakeLists.txt @@ -1,29 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - find_package(MPI REQUIRED) - +if (MATAR_ENABLE_KOKKOS AND MATAR_ENABLE_MPI) add_executable(laplace_mpi laplace_mpi.cpp) - #add_executable(laplace_mpi simple_mpi.cpp) - #add_executable(laplace_mpi mpi_mesh_test.cpp) - #add_executable(laplace_mpi simple_halo.cpp) - add_definitions(-DHAVE_MPI=1) - - add_definitions(-DHAVE_KOKKOS=1) - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - - endif() - target_link_libraries(laplace_mpi ${LINKING_LIBRARIES}) endif() diff --git a/examples/mesh_decomp/CMakeLists.txt b/examples/mesh_decomp/CMakeLists.txt index 6c8901da..96284a33 100644 --- a/examples/mesh_decomp/CMakeLists.txt +++ b/examples/mesh_decomp/CMakeLists.txt @@ -1,42 +1,43 @@ -cmake_minimum_required(VERSION 3.5) - -# Find MPI -find_package(MPI REQUIRED) -add_definitions(-DHAVE_MPI=1) - -find_package(Matar REQUIRED) - -execute_process( - COMMAND ${CMAKE_CURRENT_LIST_DIR}/install_ptscotch.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - RESULT_VARIABLE INSTALL_PTSCOTCH_RESULT -) - -if(NOT INSTALL_PTSCOTCH_RESULT EQUAL 0) - message(FATAL_ERROR "Failed to install PT-Scotch by running install_ptscotch.sh") -endif() - +if (MATAR_ENABLE_KOKKOS AND MATAR_ENABLE_MPI) + include(ExternalProject) + + # Build PT-Scotch at build time (not configure time). The clone/configure/build + # only reruns when missing, so reconfigures are fast and offline. + set(SCOTCH_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/scotch/build) + ExternalProject_Add(ptscotch_external + GIT_REPOSITORY https://gitlab.inria.fr/scotch/scotch.git + GIT_SHALLOW TRUE + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/scotch/src + BINARY_DIR ${SCOTCH_BUILD_DIR} + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=Release + -DBUILD_PTSCOTCH=ON + -DMPI_C_COMPILER=mpicc + -DMPI_Fortran_COMPILER=mpifort + -DENABLE_TESTS=OFF + INSTALL_COMMAND "" + BUILD_BYPRODUCTS + ${SCOTCH_BUILD_DIR}/lib/libscotch.a + ${SCOTCH_BUILD_DIR}/lib/libptscotch.a + ${SCOTCH_BUILD_DIR}/lib/libptscotcherr.a + ) -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - add_executable(mesh_decomp mesh_decomp.cpp) + add_dependencies(mesh_decomp ptscotch_external) - add_definitions(-DHAVE_KOKKOS=1) + # Generated Scotch headers land in the external build tree + target_include_directories(mesh_decomp PRIVATE ${SCOTCH_BUILD_DIR}/src/include) - # Add include directories for MPI and Scotch/PT-Scotch - target_include_directories(mesh_decomp PRIVATE ${MPI_CXX_INCLUDE_PATH} ${CMAKE_CURRENT_LIST_DIR}/lib/scotch/build/src/include) - # Link libraries - order matters! libptscotch depends on libscotch # Use -Wl,--whole-archive to ensure all symbols are included from static libraries # Note: Only link libptscotcherr.a (not libscotcherr.a) to avoid multiple definitions - target_link_libraries(mesh_decomp ${LINKING_LIBRARIES} MPI::MPI_CXX + target_link_libraries(mesh_decomp ${LINKING_LIBRARIES} -Wl,--whole-archive - ${CMAKE_CURRENT_LIST_DIR}/lib/scotch/build/lib/libscotch.a + ${SCOTCH_BUILD_DIR}/lib/libscotch.a -Wl,--no-whole-archive -Wl,--whole-archive - ${CMAKE_CURRENT_LIST_DIR}/lib/scotch/build/lib/libptscotcherr.a - ${CMAKE_CURRENT_LIST_DIR}/lib/scotch/build/lib/libptscotch.a + ${SCOTCH_BUILD_DIR}/lib/libptscotcherr.a + ${SCOTCH_BUILD_DIR}/lib/libptscotch.a -Wl,--no-whole-archive -lz # zlib for gzip compression -lbz2 # bzip2 library diff --git a/examples/pointcloud/CMakeLists.txt b/examples/pointcloud/CMakeLists.txt index aafb20e9..b953bfff 100644 --- a/examples/pointcloud/CMakeLists.txt +++ b/examples/pointcloud/CMakeLists.txt @@ -1,24 +1,7 @@ -cmake_minimum_required(VERSION 3.18) - - -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - - add_definitions(-DHAVE_KOKKOS=1) - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - - +if (MATAR_ENABLE_KOKKOS) add_executable(pointcloud-gbl pointcloud-gbl.cpp) add_executable(pointcloud-rk pointcloud-rk.cpp) target_link_libraries(pointcloud-gbl ${LINKING_LIBRARIES}) target_link_libraries(pointcloud-rk ${LINKING_LIBRARIES}) -endif(KOKKOS) +endif() diff --git a/examples/sparsetests/CMakeLists.txt b/examples/sparsetests/CMakeLists.txt index a0f4c506..a2769b0d 100644 --- a/examples/sparsetests/CMakeLists.txt +++ b/examples/sparsetests/CMakeLists.txt @@ -1,27 +1,11 @@ -cmake_minimum_required(VERSION 3.5) - -if (KOKKOS) - #find_package(Kokkos REQUIRED) - add_definitions(-DHAVE_KOKKOS=1) - +if (MATAR_ENABLE_KOKKOS) add_executable(matVec matVec.cpp) add_executable(powerIter powerIter.cpp) add_executable(spPower sparsePowerIter.cpp) add_executable(spatVec sparseMatVec.cpp) + target_link_libraries(spatVec ${LINKING_LIBRARIES}) target_link_libraries(matVec ${LINKING_LIBRARIES}) target_link_libraries(powerIter ${LINKING_LIBRARIES}) target_link_libraries(spPower ${LINKING_LIBRARIES}) - - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - -endif () - +endif() diff --git a/examples/test_rocm/CMakeLists.txt b/examples/test_rocm/CMakeLists.txt index 564bb7e3..e3112beb 100644 --- a/examples/test_rocm/CMakeLists.txt +++ b/examples/test_rocm/CMakeLists.txt @@ -1,28 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -#project (test_rocm) - -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - +if (MATAR_ENABLE_KOKKOS) add_executable(test_rocm SomeClass.cpp main.cpp) - - add_definitions(-DHAVE_KOKKOS=1) - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - #enable_language(HIP) - #set_source_files_properties(SomeClass.cpp SomeClass.h PROPERTIES LANGUAGE HIP) - - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - - endif() - target_link_libraries(test_rocm ${LINKING_LIBRARIES}) endif() diff --git a/examples/virtualFcnKokkos/CMakeLists.txt b/examples/virtualFcnKokkos/CMakeLists.txt index 89f72fab..9fa37b11 100644 --- a/examples/virtualFcnKokkos/CMakeLists.txt +++ b/examples/virtualFcnKokkos/CMakeLists.txt @@ -1,15 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -#project (virttestkokkos) - -find_package(Matar REQUIRED) - -if (KOKKOS) - #find_package(Kokkos REQUIRED) #new - - add_executable(virttestkokkos child.cpp child.hpp inherited_inits.cpp inherited_inits.hpp kokkos_alias.h main_kokkos_vfcn.cpp parents.h) - - add_definitions(-DHAVE_KOKKOS=1) - +if (MATAR_ENABLE_KOKKOS) + add_executable(virttestkokkos child.cpp child.hpp inherited_inits.cpp inherited_inits.hpp kokkos_alias.h main_kokkos_vfcn.cpp parents.h) target_link_libraries(virttestkokkos ${LINKING_LIBRARIES}) endif() diff --git a/examples/virtualFcnMATAR/CMakeLists.txt b/examples/virtualFcnMATAR/CMakeLists.txt index 22873a82..59f8fce9 100644 --- a/examples/virtualFcnMATAR/CMakeLists.txt +++ b/examples/virtualFcnMATAR/CMakeLists.txt @@ -1,23 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - -find_package(Matar REQUIRED) - -if (KOKKOS) - add_definitions(-DHAVE_KOKKOS=1) - #find_package(Kokkos REQUIRED) - - add_definitions(-DHAVE_KOKKOS=1) - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - +if (MATAR_ENABLE_KOKKOS) add_executable(virtual_fcn_test main.cpp classes.cpp) target_link_libraries(virtual_fcn_test ${LINKING_LIBRARIES}) - endif() diff --git a/examples/watt-graph/CMakeLists.txt b/examples/watt-graph/CMakeLists.txt index 3061157a..b0b2d2f9 100644 --- a/examples/watt-graph/CMakeLists.txt +++ b/examples/watt-graph/CMakeLists.txt @@ -1,26 +1,9 @@ -cmake_minimum_required(VERSION 3.5) - - -if (NOT KOKKOS) +if (NOT MATAR_ENABLE_KOKKOS) add_executable(test_floyd floyd.cpp) target_link_libraries(test_floyd ${LINKING_LIBRARIES}) endif() -if (KOKKOS) - #find_package(Kokkos REQUIRED) - add_definitions(-DHAVE_KOKKOS=1) - +if (MATAR_ENABLE_KOKKOS) add_executable(test_kokkos_floyd kokkos_floyd.cpp) target_link_libraries(test_kokkos_floyd ${LINKING_LIBRARIES}) - - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - -endif () +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 55a0a7d4..72aa33ba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,51 +1,23 @@ -cmake_minimum_required(VERSION 3.5) +include(FetchContent) -project (matartest) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 +) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) +# On Windows: keep gtest from overriding the parent project's runtime settings. +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) -# Required at top level so CMake generates ${CMAKE_BINARY_DIR}/CTestTestfile.cmake. -# Without this, ctest from the build root finds no tests (enable_testing in a subdirectory is not enough). -enable_testing() +add_subdirectory(test_cases) -# MATAR built with MPI lists MPI::MPI_CXX on imported target `matar`; MatarConfig loads targets during -# find_package(Matar). Only pre-find MPI for those test builds (see cmake_build_test.sh). -option(MATAR_TEST_USE_MPI "Configure tests against MPI-enabled MATAR (requires MPI before find_package)" OFF) -if(MATAR_TEST_USE_MPI) - find_package(MPI REQUIRED COMPONENTS CXX) -endif() -find_package(Matar REQUIRED) +add_executable(test_csr CSRArray.cpp) +target_link_libraries(test_csr matar::matar gtest_main) -#------------------------------------------- -# Testing stuff -#------------------------------------------- -if (NOT KOKKOS) - add_subdirectory(googletest) - add_subdirectory(test_cases) - add_executable(test_csr CSRArray.cpp) - target_link_libraries(test_csr matar gtest_main) - add_executable(test_csc CSCArray.cpp) - target_link_libraries(test_csc matar gtest_main) -endif() +add_executable(test_csc CSCArray.cpp) +target_link_libraries(test_csc matar::matar gtest_main) -if (KOKKOS) - find_package(Kokkos REQUIRED) #new - add_definitions(-DHAVE_KOKKOS=1) - - if (CUDA) - add_definitions(-DHAVE_CUDA=1) - elseif (HIP) - add_definitions(-DHAVE_HIP=1) - elseif (OPENMP) - add_definitions(-DHAVE_OPENMP=1) - elseif (THREADS) - add_definitions(-DHAVE_THREADS=1) - endif() - - add_subdirectory(googletest) - add_subdirectory(test_cases) - add_executable(test_csr CSRArray.cpp) - target_link_libraries(test_csr matar gtest_main) - add_executable(test_csc CSCArray.cpp) - target_link_libraries(test_csc matar gtest_main) - - -endif() +include(GoogleTest) +gtest_discover_tests(test_csr DISCOVERY_MODE PRE_TEST) +gtest_discover_tests(test_csc DISCOVERY_MODE PRE_TEST) diff --git a/test/test_cases/CMakeLists.txt b/test/test_cases/CMakeLists.txt index b9a7ee07..87b100a7 100644 --- a/test/test_cases/CMakeLists.txt +++ b/test/test_cases/CMakeLists.txt @@ -1,30 +1,28 @@ -cmake_minimum_required(VERSION 3.5) - -# Optional MPI for matar_mpi_tests: loaded in ../CMakeLists.txt when MATAR_TEST_USE_MPI is set. - -# Find all test files in the current directory except test_main.cpp and MPI-only sources. -file(GLOB TEST_SOURCES "test_*.cpp") -list(REMOVE_ITEM TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test_mpi_types.cpp") - -# Create a single test executable that includes all test files -add_executable(matar_tests test_main.cpp ${TEST_SOURCES}) -target_link_libraries(matar_tests matar gtest_main) - -# Add Kokkos if available -if(KOKKOS) - target_link_libraries(matar_tests Kokkos::kokkos) -endif() - -# Add test discovery include(GoogleTest) -gtest_discover_tests(matar_tests) +if(MATAR_ENABLE_KOKKOS) + # Find all test files in the current directory except MPI-only sources. + file(GLOB TEST_SOURCES "test_*.cpp") + list(REMOVE_ITEM TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test_mpi_types.cpp") + + # Create a single test executable that includes all test files + add_executable(matar_tests test_main.cpp ${TEST_SOURCES}) + target_link_libraries(matar_tests matar::matar gtest_main) + # PRE_TEST: enumerate tests when ctest runs, not by executing the + # binary right after linking (avoids Kokkos initialization during builds). + gtest_discover_tests(matar_tests DISCOVERY_MODE PRE_TEST) +else() + # Without Kokkos, only the host-type tests apply (the other test + # sources, including test_macros.cpp, use Kokkos types/APIs directly). + add_executable(matar_tests test_nonkokkos_types.cpp) + target_link_libraries(matar_tests matar::matar gtest_main) + gtest_discover_tests(matar_tests DISCOVERY_MODE PRE_TEST) +endif() # --- MPI + Kokkos: MPICArrayKokkos / CommunicationPlan (run suite under mpirun) --- -if(KOKKOS AND TARGET MPI::MPI_CXX) +if(MATAR_ENABLE_KOKKOS AND MATAR_ENABLE_MPI) add_executable(matar_mpi_tests mpi_test_main.cpp test_mpi_types.cpp) - target_link_libraries(matar_mpi_tests PRIVATE matar gtest Kokkos::kokkos MPI::MPI_CXX) - target_compile_definitions(matar_mpi_tests PRIVATE HAVE_MPI=1 HAVE_KOKKOS=1) + target_link_libraries(matar_mpi_tests PRIVATE matar::matar gtest) # --oversubscribe: GitHub Actions / small VMs often expose fewer slots than ranks (Open MPI). add_test( From 86b45789bd4c33414d82ab1a09c20b60a298a287 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:19:00 -0500 Subject: [PATCH 08/43] ENH: Updating workflows --- .github/workflows/cmake.yml | 167 +++++++++++++++++++++--------------- .github/workflows/test.yml | 50 ++++------- .gitignore | 5 +- 3 files changed, 116 insertions(+), 106 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index a826c860..9fe50733 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -6,82 +6,107 @@ on: pull_request: branches: [ "main" ] -#env: -# # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) -# BUILD_TYPE: Debug - jobs: - # This workflow contains a single job called "build" - build: - # - name: ${{ matrix.config.name }} - runs-on: ${{ matrix.config.os }} - strategy: - fail-fast: false - matrix: - config: - - {name: "Ubuntu_Latest_GCC_SERIAL", os: ubuntu-latest, build_type: "Debug", cc: "gcc", cxx: "g++", matar_config_args: "", kokkos_config_args: ""} - - {name: "Ubuntu_Latest_GCC_KOKKOS_SERIAL", os: ubuntu-latest, build_type: "Debug", cc: "gcc", cxx: "g++", matar_config_args: "-DKOKKOS=ON", kokkos_config_args: "-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_SERIAL=ON -DKokkos_ENABLE_TESTS=OFF -DBUILD_TESTING=OFF"} + # MATAR without Kokkos: host-only header library. + build-no-kokkos: + name: Ubuntu_GCC_NO_KOKKOS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Configure + run: | + cmake -B build/no-kokkos \ + -DCMAKE_BUILD_TYPE=Debug \ + -DMATAR_ENABLE_KOKKOS=OFF \ + -DMATAR_BUILD_TESTS=ON \ + -DMATAR_BUILD_EXAMPLES=ON + + - name: Build + run: cmake --build build/no-kokkos -j2 + + - name: Test + run: ctest --test-dir build/no-kokkos --output-on-failure + # Bundled Kokkos submodule (the default path), plus an install round-trip + # verifying a downstream find_package(Matar) consumer. + build-bundled-kokkos: + name: Ubuntu_GCC_BUNDLED_KOKKOS + runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 - + - uses: actions/checkout@v3 + - name: Checkout submodules run: git submodule update --init --recursive - - # Kokkos configure, build, and install------------------------------------------ - - if: contains(matrix.config.name, 'KOKKOS') - name: Configure Kokkos CMake - shell: bash + + - name: Configure + run: cmake --preset serial + + - name: Build + run: cmake --build --preset serial -j2 + + - name: Test + run: ctest --preset serial + + - name: Install + run: cmake --install build/serial --prefix ${{ github.workspace }}/install + + - name: Downstream find_package(Matar) smoke test run: | - cmake \ - -S ${{ github.workspace }}/src/Kokkos/kokkos \ - -B ${{ github.workspace }}/build-kokkos-serial/kokkos \ - -D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/build-kokkos-serial/kokkos \ - ${{ matrix.config.kokkos_config_args }} - - - if: contains(matrix.config.name, 'KOKKOS') - name: Build Kokkos - shell: bash - run: cmake --build ${{ github.workspace }}/build-kokkos-serial/kokkos - - - if: contains(matrix.config.name, 'KOKKOS') - name: Install Kokkos - shell: bash - run: cmake --install ${{ github.workspace }}/build-kokkos-serial/kokkos - - # End Kokkos configure, build, and install------------------------------------------ - - - # MATAR configure and build------------------------------------------ - - if: false == contains(matrix.config.name, 'KOKKOS') - name: Configure MATAR CMake Without Kokkos - shell: bash + mkdir -p consumer + cat > consumer/main.cpp << 'EOF' + #include + int main(int argc, char* argv[]) { + MATAR_INITIALIZE(argc, argv); + { mtr::CArrayDevice a(3, 3); } + MATAR_FINALIZE(); + return 0; + } + EOF + cat > consumer/CMakeLists.txt << 'EOF' + cmake_minimum_required(VERSION 3.21) + project(MatarConsumer LANGUAGES CXX) + find_package(Matar REQUIRED) + add_executable(consumer main.cpp) + target_link_libraries(consumer matar::matar) + EOF + cmake -S consumer -B consumer/build -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install + cmake --build consumer/build -j2 + ./consumer/build/consumer + + # External (pre-installed) Kokkos via MATAR_USE_EXTERNAL_KOKKOS. + build-external-kokkos: + name: Ubuntu_GCC_EXTERNAL_KOKKOS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Checkout submodules + run: git submodule update --init --recursive + + - name: Install Kokkos standalone run: | - cmake \ - -B ${{ github.workspace }}/build-kokkos-serial/matar \ - -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ - ${{ matrix.config.matar_config_args }} - - - if: contains(matrix.config.name, 'KOKKOS') - name: Configure MATAR CMake With Kokkos - shell: bash + cmake -S src/Kokkos/kokkos -B build/kokkos \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_STANDARD=17 \ + -DKokkos_ENABLE_SERIAL=ON \ + -DKokkos_ENABLE_TESTS=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/kokkos-install + cmake --build build/kokkos -j2 + cmake --install build/kokkos + + - name: Configure MATAR against external Kokkos run: | - cmake \ - -B ${{ github.workspace }}/build-kokkos-serial/matar \ - -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ - ${{ matrix.config.matar_config_args }} \ - -DKokkos_DIR=${{ github.workspace }}/build-kokkos-serial/kokkos/lib/cmake/Kokkos - - - name: Build MATAR - shell: bash - run: cmake --build ${{github.workspace}}/build-kokkos-serial/matar - # End MATAR configure and build------------------------------------------ - - #- name: Test - # working-directory: ${{github.workspace}}/build - # # Execute tests defined by the CMake configuration. - # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - # run: ctest -C ${{env.BUILD_TYPE}} - + cmake -B build/external \ + -DCMAKE_BUILD_TYPE=Debug \ + -DMATAR_USE_EXTERNAL_KOKKOS=ON \ + -DKokkos_ROOT=${{ github.workspace }}/kokkos-install \ + -DMATAR_BUILD_TESTS=ON \ + -DMATAR_BUILD_EXAMPLES=ON + + - name: Build + run: cmake --build build/external -j2 + + - name: Test + run: ctest --test-dir build/external --output-on-failure diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 542c2a70..273d0cff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,38 +7,32 @@ on: pull_request: branches: [ "main" ] -#env: -# # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - - jobs: - # This workflow contains a single job called "build" build: - # name: ${{ matrix.config.name }} runs-on: ${{ matrix.config.os }} strategy: fail-fast: false matrix: config: - - {name: "TEST_UBUNTU_SERIAL_DEBUG", os: ubuntu-latest, debug: "enabled", cc: "gcc", cxx: "g++", kokkos_backend: "serial"} - - {name: "TEST_UBUNTU_OPENMP_DEBUG", os: ubuntu-latest, debug: "enabled", cc: "gcc", cxx: "g++", kokkos_backend: "openmp"} - - {name: "TEST_UBUNTU_SERIAL_RELEASE", os: ubuntu-latest, debug: "disabled", cc: "gcc", cxx: "g++", kokkos_backend: "serial"} - - {name: "TEST_UBUNTU_OPENMP_RELEASE", os: ubuntu-latest, debug: "disabled", cc: "gcc", cxx: "g++", kokkos_backend: "openmp"} - # Kokkos + MPI: builds MATAR with MPI, registers MPICArrayKokkos_mpi_suite (mpirun from CTest). - - {name: "TEST_UBUNTU_SERIAL_MPI_DEBUG", os: ubuntu-latest, debug: "enabled", cc: "gcc", cxx: "g++", kokkos_backend: "serial_mpi"} - - {name: "TEST_MAC_SERIAL_DEBUG", os: macos-14, debug: "enabled", cc: "clang", cxx: "clang++", kokkos_backend: "serial"} - - {name: "TEST_MAC_SERIAL_RELEASE", os: macos-14, debug: "disabled", cc: "clang", cxx: "clang++", kokkos_backend: "serial"} + - {name: "TEST_UBUNTU_SERIAL_DEBUG", os: ubuntu-latest, preset: "serial-debug"} + - {name: "TEST_UBUNTU_OPENMP_DEBUG", os: ubuntu-latest, preset: "openmp-debug"} + - {name: "TEST_UBUNTU_SERIAL_RELEASE", os: ubuntu-latest, preset: "serial"} + - {name: "TEST_UBUNTU_OPENMP_RELEASE", os: ubuntu-latest, preset: "openmp"} + # Kokkos + MPI: registers MPICArrayKokkos_mpi_suite (mpirun from CTest). + - {name: "TEST_UBUNTU_SERIAL_MPI_DEBUG", os: ubuntu-latest, preset: "serial-mpi-debug"} + - {name: "TEST_MAC_SERIAL_DEBUG", os: macos-14, preset: "serial-debug"} + - {name: "TEST_MAC_SERIAL_RELEASE", os: macos-14, preset: "serial"} steps: - name: Checkout repository uses: actions/checkout@v3 - + - name: Checkout submodules run: git submodule update --init --recursive - name: Install Open MPI - if: contains(matrix.config.kokkos_backend, 'mpi') && matrix.config.os == 'ubuntu-latest' + if: contains(matrix.config.preset, 'mpi') && matrix.config.os == 'ubuntu-latest' env: DEBIAN_FRONTEND: noninteractive run: | @@ -49,23 +43,11 @@ jobs: mpi-default-bin \ mpi-default-dev - # Build MATAR tests using the build-matar.sh script - - name: Build MATAR Tests - shell: bash - run: | - cd ${{ github.workspace }}/scripts - source build-matar.sh \ - --execution=test \ - --kokkos_build_type=${{ matrix.config.kokkos_backend }} \ - --build_action=full-app \ - --machine=linux \ - --debug=${{ matrix.config.debug }} \ - --build_cores=1 + - name: Configure + run: cmake --preset ${{ matrix.config.preset }} - # Run the tests - - name: Run Tests - shell: bash - run: | - cd ${{ github.workspace }}/build-matar-${{ matrix.config.kokkos_backend }} - ctest --output-on-failure + - name: Build + run: cmake --build --preset ${{ matrix.config.preset }} -j2 + - name: Run Tests + run: ctest --preset ${{ matrix.config.preset }} diff --git a/.gitignore b/.gitignore index 87400105..70c98184 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build/ +CMakeUserPresets.json install-* benchmark/benchmark* build-matar-* @@ -7,4 +9,5 @@ docs_doxygen/ docs_sphinx/ tutorial/getting_started/Example0/build_* tutorial/getting_started/Example0/install* -examples/mesh_decomp/lib/* \ No newline at end of file +examples/mesh_decomp/lib/* +test/googletest/ From b4ca6fd3ec9e89016f23aa56c9eb373bbb838bb2 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:24:01 -0500 Subject: [PATCH 09/43] DOC: Updating documentation --- README.md | 118 +++++++++++++++++++++--------------------------------- 1 file changed, 45 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index afaff73e..a068c9bd 100644 --- a/README.md +++ b/README.md @@ -102,89 +102,61 @@ The code can also be cloned using git clone --recursive https://github.com/lanl/MATAR.git ``` -## Basic build -The basic build is for users only interested in the serial CPU only MATAR data types. For this build, we recommend making a folder perhaps called build then go into the build folder and type -``` -cmake .. -make -``` -The compiled code will be in the build folder. +## Building MATAR +MATAR is built entirely with CMake. Kokkos is bundled as a git submodule (`src/Kokkos/kokkos`) and is built automatically with the backend you select, so no separate Kokkos install is needed. -## Debug basic build - -To build serial CPU only MATAR data types in the debug mode, please use +The provided CMake presets configure, build, and test MATAR with a given Kokkos backend: ``` -cmake -DCMAKE_BUILD_TYPE=Debug .. -make +cmake --preset serial # also: openmp, pthreads, cuda, hip, +cmake --build --preset serial # serial-mpi, openmp-mpi, cuda-mpi, hip-mpi, +ctest --preset serial # plus -debug variants (e.g. serial-debug) ``` -The debug flag includes checks on array and matrix dimensions and index bounds. - +The unit tests are built with the presets but only execute when `ctest` is invoked. +Each preset builds into `build/`, with example executables in `build//bin`. Debug presets include checks on array and matrix dimensions and index bounds. On HPC machines, load your compiler/MPI/CUDA modules first, then run the preset; site-specific toolchains can be layered with a `CMakeUserPresets.json`. -## Building MATAR with Kokkos -A building script is provided to build the MATAR examples and tests, with or without Kokkos. The simplest build with all defaults can be run with +Configuring manually instead of with presets works the same way: ``` -source {path-to-repo}/scripts/build-matar.sh +cmake -B build -DMATAR_BUILD_EXAMPLES=ON -DKokkos_ENABLE_OPENMP=ON +cmake --build build -j ``` -Running with the argument ```--help``` will give a full list of all possible arguments. -If an argument is not changed, it will be set to the default action, which can all be found from the help command -If the scripts fail to build, then carefully review the modules used and the computer architecture settings. -## Building MATAR with Anaconda -The recommended way to build **MATAR** is inside an Anaconda environment. As a starting place, follow the steps for your platform to install [anaconda](https://docs.anaconda.com/free/anaconda/install/index.html)/[miniconda](https://docs.conda.io/en/latest/miniconda.html)/[mamba](https://mamba.readthedocs.io/en/latest/installation.html). +The CMake options are: -Open a terminal on your machine and go to a folder where you want to run the **MATAR** code. Activate a bash terminal by typing: -``` -bash -``` -Then create and activate an Anaconda environment by typing: -``` -conda create -n MATAR -conda activate MATAR -``` -In this example, the enviroment is called MATAR, but any name can be used. In some cases, the text to activate an enviroment is `source activate MATAR`. Likewise, if an enviroment already exists, then just activate the desired environment. - -Now install a compiler and cmake, which are needed to build the MATAR library. -``` -conda install -c conda-forge "cxx-compiler=1.5.2" -conda install -c conda-forge "fortran-compiler=1.5.2" -conda install cmake -``` -By using cxx-compiler=1.5.2., it install gcc 11. Omit the version number and gcc 12 will be installed (at this time). If building for a GPU, it is recommended to use an older gcc version. For example, we have success using gcc 11 with CUDA 12. +| Option | Default | Description | +|---|---|---| +| `MATAR_ENABLE_KOKKOS` | ON | Build the Kokkos-backed device/dual types (builds the bundled Kokkos submodule) | +| `MATAR_ENABLE_MPI` | OFF | Enable the MPI-aware types (`MPICArrayKokkos`, `CommunicationPlan`) | +| `MATAR_ENABLE_GPU_AWARE_MPI` | OFF | Assume the MPI implementation is GPU-aware | +| `MATAR_USE_EXTERNAL_KOKKOS` | OFF | Use an installed Kokkos (`-DKokkos_ROOT=`) instead of the submodule | +| `MATAR_BUILD_EXAMPLES` | OFF | Build the example programs | +| `MATAR_BUILD_TESTS` | OFF | Build the unit tests (`ctest` to run) | +| `MATAR_BUILD_BENCHMARKS` | OFF | Build the benchmarks | -If running on an Nvidia GPU, install cudatoolkit by typing: -``` -conda install -c conda-forge cudatoolkit -conda install -c conda-forge cudatoolkit-dev -``` -This installs CUDA 12 (at this time). +The Kokkos backend is selected with the standard Kokkos CMake variables (`Kokkos_ENABLE_OPENMP`, `Kokkos_ENABLE_CUDA`, `Kokkos_ENABLE_HIP`, `Kokkos_ARCH_*`, ...), which are passed through to the bundled Kokkos build. With `MATAR_ENABLE_KOKKOS=OFF`, MATAR is a dependency-free serial header-only library. -The build script is located at -``` -source {path-to-repo}/scripts/build-matar.sh -``` - -To build the MATAR library and examples with CUDA, type: -``` -source build-matar.sh --kokkos_build_type=cuda --build_cores=16 -``` -The executables for the examples that run in parallel Nvidia GPUs using CUDA are located in: -``` -MATAR/build-matar-cuda/bin -``` - -To build the MATAR library and examples with OpenMP, type: -``` -source build-matar.sh --kokkos_build_type=openmp --build_cores=16 -``` - -The executables for the examples that run in parallel on multi-core CPUs using OpenMP are located in: -``` -MATAR/build-matar-openmp/bin +## Using MATAR in your CMake project +MATAR and Kokkos can be pulled into another CMake project with FetchContent: +```cmake +include(FetchContent) +FetchContent_Declare( + matar + GIT_REPOSITORY https://github.com/lanl/MATAR + GIT_TAG +) +FetchContent_MakeAvailable(matar) # builds bundled Kokkos with your Kokkos_ENABLE_* settings +target_link_libraries(myapp PRIVATE matar::matar) ``` -Using the main_kokkos.cpp executable as an example, it can be run by typing: +or by adding the repository as a git submodule: +```cmake +add_subdirectory(path/to/MATAR) +target_link_libraries(myapp PRIVATE matar::matar) ``` -./mtestkokkos +or against an installed MATAR (`cmake --install build/ --prefix `): +```cmake +find_package(Matar REQUIRED) # -DCMAKE_PREFIX_PATH= +target_link_libraries(myapp PRIVATE matar::matar) ``` +Linking `matar::matar` carries the include paths, `HAVE_KOKKOS`/`HAVE_MPI` definitions, and the Kokkos/MPI link dependencies automatically. If your project provides its own Kokkos (via `add_subdirectory` or `find_package` before MATAR), MATAR uses that Kokkos rather than the submodule. ## Running codes in parallel The openMP and pthread Kokkos backends require the user to specify the number of threads used to run the code in parallel. @@ -196,15 +168,15 @@ in otherwords, ``` ./mycode --kokkos-threads=4 ``` -The above command runs the code with fine grained parallelism using 4 threads. In your code, ensure you pass the command line argument variables to Kokkos::initialize function as shown below here. +The above command runs the code with fine grained parallelism using 4 threads. In your code, ensure you pass the command line argument variables to the MATAR_INITIALIZE macro (which wraps Kokkos::initialize) as shown below here. ``` int main(int argc, char* argv[]) { - Kokkos::initialize(argc, argv); + MATAR_INITIALIZE(argc, argv); // coding goes here - Kokkos::finalize(); + MATAR_FINALIZE(); return 0; } From 7cf59a6fe3fdcd0077421199ca0c933de4c21306 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:41:22 -0500 Subject: [PATCH 10/43] ENH: Updating tutorials --- .../getting_started/Example0/CMakeLists.txt | 109 ++---------- tutorial/getting_started/Example0/build.sh | 94 +++++------ .../getting_started/Example1/CMakeLists.txt | 109 ++---------- tutorial/getting_started/Example1/build.sh | 94 +++++------ .../getting_started/Example2/CMakeLists.txt | 109 ++---------- tutorial/getting_started/Example2/build.sh | 94 +++++------ .../getting_started/Example3/CMakeLists.txt | 109 ++---------- tutorial/getting_started/Example3/build.sh | 94 +++++------ .../getting_started/Example4/CMakeLists.txt | 111 ++----------- tutorial/getting_started/Example4/build.sh | 94 +++++------ .../getting_started/Example5/CMakeLists.txt | 109 ++---------- tutorial/getting_started/Example5/build.sh | 94 +++++------ tutorial/getting_started/kokkos-install.sh | 156 ------------------ 13 files changed, 325 insertions(+), 1051 deletions(-) delete mode 100644 tutorial/getting_started/kokkos-install.sh diff --git a/tutorial/getting_started/Example0/CMakeLists.txt b/tutorial/getting_started/Example0/CMakeLists.txt index 6f84a77a..f989f27a 100644 --- a/tutorial/getting_started/Example0/CMakeLists.txt +++ b/tutorial/getting_started/Example0/CMakeLists.txt @@ -1,103 +1,26 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample1 CXX) +cmake_minimum_required(VERSION 3.21) +project(MATARExample0 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Try to find the FindVector module, but don't fail if not found -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector OPTIONAL) -message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") - -if(NOT VECTOR_CXX_FLAGS) - # Define empty flags if not found - set(VECTOR_CXX_FLAGS "") - set(VECTOR_CXX_VERBOSE "") - message(STATUS "FindVector.cmake not found, continuing without vectorization flags") -endif() - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags for vectorization -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} ") #-O3 -fstrict-aliasing -march=native -mtune=native -ftree-vectorize -mprefer-vector-width=512 -fno-trapping-math -fno-math-errno -fopenmp-simd - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") if(VECTOR_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(MATAR_data MATAR_data.cpp) -target_link_libraries(MATAR_data Kokkos::kokkos) \ No newline at end of file +target_link_libraries(MATAR_data matar::matar) diff --git a/tutorial/getting_started/Example0/build.sh b/tutorial/getting_started/Example0/build.sh index d16277b0..70e1222d 100755 --- a/tutorial/getting_started/Example0/build.sh +++ b/tutorial/getting_started/Example0/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/matmul" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./MATAR_data" \ No newline at end of file diff --git a/tutorial/getting_started/Example1/CMakeLists.txt b/tutorial/getting_started/Example1/CMakeLists.txt index d3b4f670..f38f001c 100644 --- a/tutorial/getting_started/Example1/CMakeLists.txt +++ b/tutorial/getting_started/Example1/CMakeLists.txt @@ -1,103 +1,26 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample1 CXX) +cmake_minimum_required(VERSION 3.21) +project(MATARExample1 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Try to find the FindVector module, but don't fail if not found -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector OPTIONAL) -message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") - -if(NOT VECTOR_CXX_FLAGS) - # Define empty flags if not found - set(VECTOR_CXX_FLAGS "") - set(VECTOR_CXX_VERBOSE "") - message(STATUS "FindVector.cmake not found, continuing without vectorization flags") -endif() - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags for vectorization -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} -O3 -fstrict-aliasing -march=native -mtune=native -ftree-vectorize -mprefer-vector-width=512 -fno-trapping-math -fno-math-errno -fopenmp-simd") - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") if(VECTOR_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(matmul matmul.cpp) -target_link_libraries(matmul Kokkos::kokkos) \ No newline at end of file +target_link_libraries(matmul matar::matar) diff --git a/tutorial/getting_started/Example1/build.sh b/tutorial/getting_started/Example1/build.sh index 002f6c7a..70e1222d 100755 --- a/tutorial/getting_started/Example1/build.sh +++ b/tutorial/getting_started/Example1/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/matmul" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./matmul" \ No newline at end of file diff --git a/tutorial/getting_started/Example2/CMakeLists.txt b/tutorial/getting_started/Example2/CMakeLists.txt index 95454d5c..6071766a 100644 --- a/tutorial/getting_started/Example2/CMakeLists.txt +++ b/tutorial/getting_started/Example2/CMakeLists.txt @@ -1,103 +1,26 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample2 CXX) +cmake_minimum_required(VERSION 3.21) +project(MATARExample2 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Set the module path and include FindVector -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector) - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags using FindVector -if(VECTOR_CXX_FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} -O3") - message(STATUS "Using vectorization flags from FindVector: ${VECTOR_CXX_FLAGS}") -else() - message(WARNING "Vectorization flags not found, using default optimization flags") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") -endif() - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") if(VECTOR_VERBOSE) - if(VECTOR_CXX_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output: ${VECTOR_CXX_VERBOSE}") - else() - message(WARNING "Vectorization verbose flags not found") - endif() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(heat heat.cpp) -target_link_libraries(heat Kokkos::kokkos) \ No newline at end of file +target_link_libraries(heat matar::matar) diff --git a/tutorial/getting_started/Example2/build.sh b/tutorial/getting_started/Example2/build.sh index b2118c81..70e1222d 100755 --- a/tutorial/getting_started/Example2/build.sh +++ b/tutorial/getting_started/Example2/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/heat" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./heat" \ No newline at end of file diff --git a/tutorial/getting_started/Example3/CMakeLists.txt b/tutorial/getting_started/Example3/CMakeLists.txt index ec83c0b6..ef3c574b 100644 --- a/tutorial/getting_started/Example3/CMakeLists.txt +++ b/tutorial/getting_started/Example3/CMakeLists.txt @@ -1,103 +1,26 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample1 CXX) +cmake_minimum_required(VERSION 3.21) +project(MATARExample3 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Try to find the FindVector module, but don't fail if not found -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector OPTIONAL) -message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") - -if(NOT VECTOR_CXX_FLAGS) - # Define empty flags if not found - set(VECTOR_CXX_FLAGS "") - set(VECTOR_CXX_VERBOSE "") - message(STATUS "FindVector.cmake not found, continuing without vectorization flags") -endif() - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags for vectorization -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} -O3 -fstrict-aliasing -march=native -mtune=native -ftree-vectorize -mprefer-vector-width=512 -fno-trapping-math -fno-math-errno -fopenmp-simd") - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") if(VECTOR_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(health_data health_data.cpp) -target_link_libraries(health_data Kokkos::kokkos) \ No newline at end of file +target_link_libraries(health_data matar::matar) diff --git a/tutorial/getting_started/Example3/build.sh b/tutorial/getting_started/Example3/build.sh index 8906486c..70e1222d 100755 --- a/tutorial/getting_started/Example3/build.sh +++ b/tutorial/getting_started/Example3/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/matmul" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./health_data" \ No newline at end of file diff --git a/tutorial/getting_started/Example4/CMakeLists.txt b/tutorial/getting_started/Example4/CMakeLists.txt index 78347dd8..71c8db10 100644 --- a/tutorial/getting_started/Example4/CMakeLists.txt +++ b/tutorial/getting_started/Example4/CMakeLists.txt @@ -1,104 +1,27 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample4 CXX Fortran) +cmake_minimum_required(VERSION 3.21) +project(MATARExample4 LANGUAGES CXX Fortran) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Try to find the FindVector module, but don't fail if not found -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector OPTIONAL) -message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") - -if(NOT VECTOR_CXX_FLAGS) - # Define empty flags if not found - set(VECTOR_CXX_FLAGS "") - set(VECTOR_CXX_VERBOSE "") - message(STATUS "FindVector.cmake not found, continuing without vectorization flags") -endif() - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags for vectorization -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} -O3 -fstrict-aliasing -march=native -mtune=native -ftree-vectorize -mprefer-vector-width=512 -fno-trapping-math -fno-math-errno -fopenmp-simd") - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") +set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${VECTOR_Fortran_FLAGS}") if(VECTOR_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(matar-fortran main.f90 matar_function.cpp) -target_link_libraries(matar-fortran Kokkos::kokkos) \ No newline at end of file +target_link_libraries(matar-fortran matar::matar) diff --git a/tutorial/getting_started/Example4/build.sh b/tutorial/getting_started/Example4/build.sh index c566a1ec..70e1222d 100755 --- a/tutorial/getting_started/Example4/build.sh +++ b/tutorial/getting_started/Example4/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/heat" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./matar-fortran" \ No newline at end of file diff --git a/tutorial/getting_started/Example5/CMakeLists.txt b/tutorial/getting_started/Example5/CMakeLists.txt index 1f8323aa..e5589381 100644 --- a/tutorial/getting_started/Example5/CMakeLists.txt +++ b/tutorial/getting_started/Example5/CMakeLists.txt @@ -1,103 +1,26 @@ -cmake_minimum_required(VERSION 3.16) -project(MATARExample1 CXX) +cmake_minimum_required(VERSION 3.21) +project(MATARExample5 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Add FetchContent functionality to download Kokkos -include(FetchContent) - -# Try to find the FindVector module, but don't fail if not found -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../cmake/Modules) -include(FindVector OPTIONAL) -message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") - -if(NOT VECTOR_CXX_FLAGS) - # Define empty flags if not found - set(VECTOR_CXX_FLAGS "") - set(VECTOR_CXX_VERBOSE "") - message(STATUS "FindVector.cmake not found, continuing without vectorization flags") -endif() - -# Set backend options (same as in kokkos-install.sh) -set(Kokkos_BACKEND "cuda" CACHE STRING "Kokkos backend (serial, openmp, pthreads, cuda, hip)") -set_property(CACHE Kokkos_BACKEND PROPERTY STRINGS serial openmp pthreads cuda hip) - -message(STATUS "Building with Kokkos backend: ${Kokkos_BACKEND}") - -# Basic Kokkos options (always enabled) -set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Serial backend") -set(Kokkos_ARCH_NATIVE ON CACHE BOOL "Enable native architecture optimizations") -set(Kokkos_ENABLE_TESTS OFF CACHE BOOL "Build Kokkos tests") -set(BUILD_TESTING OFF CACHE BOOL "Build tests") - -# Backend-specific options -if(Kokkos_BACKEND STREQUAL "cuda") - # Find CUDA - find_package(CUDAToolkit REQUIRED) - set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable CUDA backend") - set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Enable CUDA Lambda support") - set(Kokkos_ENABLE_CUDA_CONSTEXPR ON CACHE BOOL "Enable CUDA Constexpr support") - set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable CUDA RDC") -elseif(Kokkos_BACKEND STREQUAL "hip") - set(Kokkos_ENABLE_HIP ON CACHE BOOL "Enable HIP backend") - set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE ON CACHE BOOL "Enable HIP RDC") - set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "C++ compiler" FORCE) -elseif(Kokkos_BACKEND STREQUAL "openmp") - set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable OpenMP backend") -elseif(Kokkos_BACKEND STREQUAL "pthreads") - set(Kokkos_ENABLE_THREADS ON CACHE BOOL "Enable Threads backend") -elseif(Kokkos_BACKEND STREQUAL "serial") - # Serial is already enabled by default - message(STATUS "Using Serial backend only") -else() - message(FATAL_ERROR "Invalid Kokkos_BACKEND value: ${Kokkos_BACKEND}") -endif() - -# Additional debug build option -option(DEBUG_BUILD "Enable debug build" OFF) -if(DEBUG_BUILD) - set(CMAKE_BUILD_TYPE Debug) - message(STATUS "Debug build enabled") -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -# Download and configure Kokkos -FetchContent_Declare( - kokkos - GIT_REPOSITORY https://github.com/kokkos/kokkos.git - GIT_TAG master # You can specify a specific tag/release here -) - -# Make Kokkos available -FetchContent_MakeAvailable(kokkos) - -# Define that we're using Kokkos -add_definitions(-DHAVE_KOKKOS=1) - - -set(MATAR_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../src/include) -include_directories(${MATAR_INCLUDE_DIR}) - - -message(STATUS "CMAKE_SOURCE_DIR absolute path: ${CMAKE_SOURCE_DIR}") -message(STATUS "SCRIPT_DIR absolute path: ${SCRIPT_DIR}") -message(STATUS "Primary MATAR include path: ${SCRIPT_DIR}/../MATAR") - -# Set compiler flags for vectorization -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_FLAGS} -O3 ") #-O3 -fstrict-aliasing -march=native -mtune=native -ftree-vectorize -mprefer-vector-width=512 -fno-trapping-math -fno-math-errno -fopenmp-simd - -# Option for verbose vectorization output +# Vectorization flags from the MATAR repository (optional performance boost). +# -DVECTOR_VERBOSE=ON adds the compiler's vectorization reports. option(VECTOR_VERBOSE "Enable verbose vectorization output" OFF) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/Modules) +find_package(Vector) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_FLAGS}") if(VECTOR_VERBOSE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VECTOR_CXX_VERBOSE}") - message(STATUS "Enabling vectorization verbose output") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${VECTOR_CXX_VERBOSE}") endif() -# Display final compiler flags -message(STATUS "Final CXX compiler flags: ${CMAKE_CXX_FLAGS}") +# Pull in MATAR from the repository root. This builds the bundled Kokkos +# submodule with whatever standard Kokkos flags are passed at configure time +# (e.g. -DKokkos_ENABLE_OPENMP=ON, -DKokkos_ENABLE_CUDA=ON, ...). +# Linking matar::matar provides the headers, HAVE_KOKKOS/HAVE_* definitions, +# and the Kokkos link dependency automatically. +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../.. matar) -# Create the executable add_executable(hydro hydro.cpp) -target_link_libraries(hydro Kokkos::kokkos) \ No newline at end of file +target_link_libraries(hydro matar::matar) diff --git a/tutorial/getting_started/Example5/build.sh b/tutorial/getting_started/Example5/build.sh index 440145ea..70e1222d 100755 --- a/tutorial/getting_started/Example5/build.sh +++ b/tutorial/getting_started/Example5/build.sh @@ -1,16 +1,16 @@ #!/bin/bash +# Build this MATAR tutorial example with a chosen Kokkos backend. +# MATAR and its bundled Kokkos submodule are built automatically by CMake; +# backends are selected with the standard Kokkos_ENABLE_* CMake flags. + # Guard against sourcing -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - # Script is being executed - : # continue with script -else +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then echo "This script should be executed, not sourced" echo "Please run: ./build.sh -t " return 1 fi -# Function to display usage usage() { echo "Usage: $0 [-t build_type] [-d] [-v]" echo "build_type options: all, serial, openmp, pthreads, cuda, hip" @@ -20,102 +20,84 @@ usage() { exit 1 } -# Parse command line arguments while getopts "t:dv" opt; do case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - v ) - vector_verbose=true - ;; - \? ) - usage - ;; + t ) build_type=$OPTARG ;; + d ) debug=true ;; + v ) vector_verbose=true ;; + \? ) usage ;; esac done -# Validate build type if [ -z "$build_type" ]; then echo "Error: Build type (-t) is required" usage fi -# Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# Function to build a specific backend build_backend() { local backend=$1 local build_dir="${SCRIPT_DIR}/build_${backend}" - + echo "====================================================" echo "Building MATAR example with ${backend} backend" echo "====================================================" - - # Create build directory - mkdir -p "${build_dir}" - cd "${build_dir}" - - # Set CMake options based on flags - CMAKE_OPTIONS="-DKokkos_BACKEND=${backend}" - + + # Map the backend name to standard Kokkos CMake flags + CMAKE_OPTIONS="-DKokkos_ARCH_NATIVE=ON" + case ${backend} in + serial ) + ;; # Kokkos enables the Serial backend by default + openmp ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_OPENMP=ON" ;; + pthreads ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_THREADS=ON" ;; + cuda ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKokkos_ENABLE_CUDA=ON -DKokkos_ENABLE_CUDA_CONSTEXPR=ON -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON" ;; + hip ) + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CXX_COMPILER=hipcc -DKokkos_ENABLE_HIP=ON -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON" ;; + * ) + echo "Invalid backend: ${backend}"; usage ;; + esac + if [ "$debug" = "true" ]; then - CMAKE_OPTIONS="${CMAKE_OPTIONS} -DDEBUG_BUILD=ON" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_BUILD_TYPE=Debug" echo "Debug build enabled" fi - + if [ "$vector_verbose" = "true" ]; then CMAKE_OPTIONS="${CMAKE_OPTIONS} -DVECTOR_VERBOSE=ON" echo "Vectorization verbose output enabled" fi - - # Configure with CMake + echo "Running CMake with options: ${CMAKE_OPTIONS}" - cmake ${CMAKE_OPTIONS} .. - - # Build - echo "Building with make..." - make -j$(nproc) - + cmake -S "${SCRIPT_DIR}" -B "${build_dir}" ${CMAKE_OPTIONS} + cmake --build "${build_dir}" -j"$(nproc)" + echo "Build for ${backend} completed!" - echo "Executable: ${build_dir}/heat" + echo "Executable is in: ${build_dir}" echo "" } -# Build based on the selected option if [ "${build_type}" = "all" ]; then - # Build all available backends BACKENDS=("serial" "openmp" "pthreads") - - # Add CUDA if available + if command -v nvcc &> /dev/null; then BACKENDS+=("cuda") else echo "CUDA not found, skipping CUDA backend build" fi - - # Add HIP if available + if command -v hipcc &> /dev/null; then BACKENDS+=("hip") else echo "HIP not found, skipping HIP backend build" fi - - # Build each backend + for backend in "${BACKENDS[@]}"; do build_backend "${backend}" done - - echo "All builds completed!" else - # Build a single backend build_backend "${build_type}" fi - -echo "To run an example:" -echo "cd build_" -echo "./hydro" \ No newline at end of file diff --git a/tutorial/getting_started/kokkos-install.sh b/tutorial/getting_started/kokkos-install.sh deleted file mode 100644 index 3c7f7de5..00000000 --- a/tutorial/getting_started/kokkos-install.sh +++ /dev/null @@ -1,156 +0,0 @@ -#!/bin/bash - -# Function to display usage -usage() { - echo "Usage: $0 [-t build_type] [-d] [-p install_prefix]" - echo "build_type options: serial, openmp, pthreads, cuda, hip" - echo " -t Specify build type (required)" - echo " -d Enable debug build (optional)" - echo " -p Installation prefix path (optional)" - exit 1 -} - -# Parse command line arguments -while getopts "t:dp:" opt; do - case ${opt} in - t ) - build_type=$OPTARG - ;; - d ) - debug=true - ;; - p ) - INSTALL_PREFIX=$OPTARG - ;; - \? ) - usage - ;; - esac -done - -# Validate build type -if [ -z "$build_type" ]; then - echo "Error: Build type (-t) is required" - usage -fi - -# Validate build type value -valid_types=("serial" "openmp" "pthreads" "cuda" "hip") -if [[ ! " ${valid_types[@]} " =~ " ${build_type} " ]]; then - echo "Error: Invalid build type. Must be one of: ${valid_types[*]}" - usage -fi - -# Exit on error -#set -e - -# Get the directory where the script is called from -CURRENT_DIR=$(pwd) -INSTALL_PREFIX="${INSTALL_PREFIX:-${CURRENT_DIR}/install}" -INSTALL_DIR="${CURRENT_DIR}/build_tmp" -BUILD_DIR="${INSTALL_DIR}/build" -KOKKOS_SOURCE_DIR="${INSTALL_DIR}/kokkos" -KOKKOS_BUILD_DIR="${BUILD_DIR}" -KOKKOS_INSTALL_DIR="${INSTALL_PREFIX}" - -# Create directories -mkdir -p $INSTALL_DIR -mkdir -p $BUILD_DIR -mkdir -p $INSTALL_PREFIX -cd $INSTALL_DIR - -echo "Cloning Kokkos repository..." -git clone https://github.com/kokkos/kokkos.git -cd kokkos - -echo "Creating build directory..." -cd $BUILD_DIR - -# Kokkos flags for Cuda -CUDA_ADDITIONS=( --D Kokkos_ENABLE_CUDA=ON --D Kokkos_ENABLE_CUDA_CONSTEXPR=ON --D Kokkos_ENABLE_CUDA_LAMBDA=ON --D Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=ON -) - -# Kokkos flags for Hip -HIP_ADDITIONS=( --D Kokkos_ENABLE_HIP=ON --D CMAKE_CXX_COMPILER=hipcc --D Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON -) - -# Kokkos flags for OpenMP -OPENMP_ADDITIONS=( --D Kokkos_ENABLE_OPENMP=ON -) - -# Kokkos flags for PThreads -PTHREADS_ADDITIONS=( --D Kokkos_ENABLE_THREADS=ON -) - -# Configure kokkos using CMake -cmake_options=( - -D CMAKE_BUILD_TYPE=Release - -D CMAKE_INSTALL_PREFIX="${KOKKOS_INSTALL_DIR}" - -D CMAKE_CXX_STANDARD=17 - -D Kokkos_ENABLE_SERIAL=ON - -D Kokkos_ARCH_NATIVE=ON - -D Kokkos_ENABLE_TESTS=OFF - -D BUILD_TESTING=OFF -) - -if [ "$build_type" = "openmp" ]; then - cmake_options+=( - ${OPENMP_ADDITIONS[@]} - ) -elif [ "$build_type" = "pthreads" ]; then - cmake_options+=( - ${PTHREADS_ADDITIONS[@]} - ) -elif [ "$build_type" = "cuda" ]; then - cmake_options+=( - ${CUDA_ADDITIONS[@]} - ) -elif [ "$build_type" = "hip" ]; then - cmake_options+=( - ${HIP_ADDITIONS[@]} - ) -fi - -if [ "$debug" = "true" ]; then - echo "Setting debug to true for CMAKE build type" - cmake_options+=( - -DCMAKE_BUILD_TYPE=Debug - ) -fi - -echo "Configuring Kokkos..." -# Configure kokkos -cmake "${cmake_options[@]}" -B "${KOKKOS_BUILD_DIR}" -S "${KOKKOS_SOURCE_DIR}" - -echo "Building Kokkos..." -make -j$(nproc) - -echo "Installing Kokkos..." -make install - -echo "Cleaning up..." -cd $CURRENT_DIR -rm -rf $INSTALL_DIR - -echo "Setting up environment..." -# Create a setup script instead of modifying .bashrc -cat > ${INSTALL_PREFIX}/setup_env.sh << EOF -#!/bin/bash -export CMAKE_PREFIX_PATH=\${CMAKE_PREFIX_PATH}:${INSTALL_PREFIX} -export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:${INSTALL_PREFIX}/lib64 -EOF -chmod +x ${INSTALL_PREFIX}/setup_env.sh - -echo "Kokkos installation completed!" -echo "Installation location: ${INSTALL_PREFIX}" -echo "To set up the environment variables, run:" -echo "source ${INSTALL_PREFIX}/setup_env.sh" \ No newline at end of file From b166e971e7a29c6c48af355a7cd105edd96b4d6e Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:42:00 -0500 Subject: [PATCH 11/43] ENH: Updating gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 70c98184..1cad4d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ install/* heffte/ docs_doxygen/ docs_sphinx/ -tutorial/getting_started/Example0/build_* -tutorial/getting_started/Example0/install* +tutorial/getting_started/Example*/build_* +tutorial/getting_started/Example*/install* examples/mesh_decomp/lib/* test/googletest/ From 17671a78a4b741458059183bdf10677d52ac7dd6 Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 17:55:21 -0500 Subject: [PATCH 12/43] ENH: Adding formatting scripts --- .clang-format | 38 +++++++++ formatting/README.md | 38 +++++++++ formatting/matar-format.py | 167 +++++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 .clang-format create mode 100644 formatting/README.md create mode 100755 formatting/matar-format.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..247a18a2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,38 @@ +# MATAR style: Google base with adjustments for MATAR/Kokkos idioms +BasedOnStyle: Google + +# --- deviations from stock Google, matching existing MATAR code --- +IndentWidth: 4 +ColumnLimit: 100 +AccessModifierOffset: -4 + +# --- MATAR / Kokkos macro handling --- +# Complete-statement macros: prevents mis-indentation of following lines +StatementMacros: + - MATAR_INITIALIZE + - MATAR_FINALIZE + - MATAR_FENCE + - MATAR_MPI_INIT + - MATAR_MPI_FINALIZE + - MATAR_MPI_BARRIER + +# Declaration decorators +AttributeMacros: + - KOKKOS_INLINE_FUNCTION + - KOKKOS_FUNCTION + - KOKKOS_LAMBDA + - KOKKOS_CLASS_LAMBDA + +# Keep the braced loop-body argument of parallel macros formatted as a block: +# penalize packing so each index triple stays on its own line in multi-dim loops +AlignAfterOpenBracket: Align +AllowAllArgumentsOnNextLine: false +BinPackArguments: false + +# Don't let clang-format merge short loop bodies onto one line inside macros +AllowShortBlocksOnASingleLine: Never +AllowShortLambdasOnASingleLine: None + + +# MATAR convention: aligned consecutive assignments (deviation from Google) +AlignConsecutiveAssignments: Consecutive diff --git a/formatting/README.md b/formatting/README.md new file mode 100644 index 00000000..9aa5c548 --- /dev/null +++ b/formatting/README.md @@ -0,0 +1,38 @@ +# MATAR code formatting + +Formatting is a two-stage pipeline: + +1. **clang-format** (config: `.clang-format` at the repo root) — Google style with + MATAR conventions: 4-space indents, 100-column limit, aligned consecutive + assignments, and macro-awareness for `MATAR_*` statement macros and + `KOKKOS_*` attribute macros. +2. **`matar-format.py`** — post-processor that rewrites MATAR parallel-macro + calls (`FOR_ALL`, `DO_ALL`, `FOR_REDUCE_*`, `DO_REDUCE_*`, and their `_CLASS` + variants) into the canonical layout clang-format cannot produce + (it has no notion of argument groups): + + ```c++ + DO_REDUCE_MAX(k, 0, 10, + j, 0, 10, + i, 0, 10, + loc_max, { + if (loc_max < arr3D(i, j, k)) { + loc_max = arr3D(i, j, k); + } + }, result); + ``` + + One index triple per line aligned under the first argument, reduction + variables on their own line, body at macro indent + 4, trailing arguments + joined onto the closing line. Bodies keep clang-format's internal + formatting; only their indentation is shifted. The pass is idempotent and + skips any call it cannot parse confidently. + +## Usage + +Always run both stages, clang-format first: + +```bash +clang-format -i src/include/*.h solvers/*.hpp +python3 formatting/matar-format.py src/include/*.h solvers/*.hpp +``` diff --git a/formatting/matar-format.py b/formatting/matar-format.py new file mode 100755 index 00000000..51d374c8 --- /dev/null +++ b/formatting/matar-format.py @@ -0,0 +1,167 @@ +#!/usr/bin/env python3 +"""Post-processor for clang-format: canonical layout for MATAR parallel macros. + +clang-format treats FOR_ALL(k, 0, n, j, 0, n, i, 0, n, {...}) as a call with +nine scalar arguments and packs or splits them arbitrarily. This pass rewrites +each call into MATAR's canonical layout: + + DO_REDUCE_MAX(k, 0, 10, + j, 0, 10, + i, 0, 10, + loc_max, { + + }, result); + +Bodies keep clang-format's internal formatting; only their indentation shifts. +Usage: matar-format.py [ ...] (edits in place, idempotent) +""" +import re +import sys + +MACROS = ( + "FOR_ALL_CLASS", "DO_ALL_CLASS", + "FOR_ALL", "DO_ALL", + "FOR_REDUCE_SUM_CLASS", "FOR_REDUCE_MAX_CLASS", "FOR_REDUCE_MIN_CLASS", + "FOR_REDUCE_PRODUCT_CLASS", + "FOR_REDUCE_SUM", "FOR_REDUCE_MAX", "FOR_REDUCE_MIN", "FOR_REDUCE_PRODUCT", + "DO_REDUCE_SUM", "DO_REDUCE_MAX", "DO_REDUCE_MIN", +) +MACRO_RE = re.compile(r"(? Date: Tue, 25 Aug 2026 18:13:29 -0500 Subject: [PATCH 13/43] STYLE: Formatting --- .clang-format | 5 +- .clang-format-ignore | 5 + solvers/cramers_rule.hpp | 268 +- solvers/lu_solver.hpp | 646 +-- solvers/qr_solver.hpp | 244 +- src/include/aliases.h | 236 +- src/include/communication_plan.h | 302 +- src/include/host_types.h | 4568 ++++++--------- src/include/kokkos_types.h | 8951 +++++++++++++----------------- src/include/macros.h | 3157 +++++------ src/include/matar.h | 14 +- src/include/mpi_types.h | 731 ++- 12 files changed, 8227 insertions(+), 10900 deletions(-) create mode 100644 .clang-format-ignore diff --git a/.clang-format b/.clang-format index 247a18a2..c9124643 100644 --- a/.clang-format +++ b/.clang-format @@ -3,9 +3,12 @@ BasedOnStyle: Google # --- deviations from stock Google, matching existing MATAR code --- IndentWidth: 4 -ColumnLimit: 100 +ColumnLimit: 150 AccessModifierOffset: -4 +# Never reorder #includes: preserves author-intended ordering +SortIncludes: Never + # --- MATAR / Kokkos macro handling --- # Complete-statement macros: prevents mis-indentation of following lines StatementMacros: diff --git a/.clang-format-ignore b/.clang-format-ignore new file mode 100644 index 00000000..9d583016 --- /dev/null +++ b/.clang-format-ignore @@ -0,0 +1,5 @@ +# Files clang-format must not touch (gitignore-style globs, clang-format >= 18) + +# Heavy preprocessor code: #define continuations and variadic macro dispatch +# tables that clang-format mangles badly. Format by hand. +src/include/macros.h diff --git a/solvers/cramers_rule.hpp b/solvers/cramers_rule.hpp index 78fd34d4..bb2b455b 100644 --- a/solvers/cramers_rule.hpp +++ b/solvers/cramers_rule.hpp @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -38,7 +38,7 @@ **********************************************************************************************/ #include "matar.h" -using namespace mtr; +using namespace mtr; ///////////////////////////////////////////////////////////////////////////// /// @@ -50,11 +50,9 @@ using namespace mtr; /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -double det_2x2(const T &A){ - return A(0, 0)*A(1, 1) - A(0, 1)*A(1, 0); -} // end of det_2d function - +KOKKOS_INLINE_FUNCTION double det_2x2(const T& A) { + return A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0); +} // end of det_2d function ///////////////////////////////////////////////////////////////////////////// /// @@ -68,14 +66,10 @@ double det_2x2(const T &A){ /// \param a11 The 11 component of the array /// ///////////////////////////////////////////////////////////////////////////// -KOKKOS_INLINE_FUNCTION -double det_2x2( - const double a00, const double a01, - const double a10, const double a11) { - +KOKKOS_INLINE_FUNCTION double det_2x2(const double a00, const double a01, const double a10, const double a11) { const double det = (a00 * a11 - a01 * a10); return det; -} // end function +} // end function ///////////////////////////////////////////////////////////////////////////// /// @@ -87,16 +81,12 @@ double det_2x2( /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -double det_3x3(const T &A){ +KOKKOS_INLINE_FUNCTION double det_3x3(const T& A) { + const double det = A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) - A(0, 1) * (A(1, 0) * A(2, 2) - A(2, 0) * A(1, 2)) + + A(0, 2) * (A(1, 0) * A(2, 1) - A(2, 0) * A(1, 1)); - const double det = A(0, 0) * (A(1, 1)*A(2, 2) - A(2, 1)*A(1, 2)) - - A(0, 1) * (A(1, 0)*A(2, 2) - A(2, 0)*A(1, 2)) - + A(0, 2) * (A(1, 0)*A(2, 1) - A(2, 0)*A(1, 1)); - return det; -} // end of det_3d function - +} // end of det_3d function ///////////////////////////////////////////////////////////////////////////// /// @@ -110,19 +100,12 @@ double det_3x3(const T &A){ /// \param a22 The 22 component of the array /// ///////////////////////////////////////////////////////////////////////////// -KOKKOS_INLINE_FUNCTION -double det_3x3( - const double a00, const double a01, const double a02, - const double a10, const double a11, const double a12, - const double a20, const double a21, const double a22) { - - const double det = a00 * (a11 * a22 - a12 * a21) - - a01 * (a10 * a22 - a12 * a20) - + a02 * (a10 * a21 - a11 * a20); +KOKKOS_INLINE_FUNCTION double det_3x3(const double a00, const double a01, const double a02, const double a10, const double a11, const double a12, + const double a20, const double a21, const double a22) { + const double det = a00 * (a11 * a22 - a12 * a21) - a01 * (a10 * a22 - a12 * a20) + a02 * (a10 * a21 - a11 * a20); return det; -} // end function - +} // end function ///////////////////////////////////////////////////////////////////////////// /// @@ -134,43 +117,23 @@ double det_3x3( /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -double det_4x4(const T &A){ - - const double det = A(0, 3) * A(1, 2) * A(2, 1) * A(3, 0) - - A(0, 2) * A(1, 3) * A(2, 1) * A(3, 0) - - A(0, 3) * A(1, 1) * A(2, 2) * A(3, 0) - + A(0, 1) * A(1, 3) * A(2, 2) * A(3, 0) - + A(0, 2) * A(1, 1) * A(2, 3) * A(3, 0) - - A(0, 1) * A(1, 2) * A(2, 3) * A(3, 0) - - A(0, 3) * A(1, 2) * A(2, 0) * A(3, 1) - + A(0, 2) * A(1, 3) * A(2, 0) * A(3, 1) - + A(0, 3) * A(1, 0) * A(2, 2) * A(3, 1) - - A(0, 0) * A(1, 3) * A(2, 2) * A(3, 1) - - A(0, 2) * A(1, 0) * A(2, 3) * A(3, 1) - + A(0, 0) * A(1, 2) * A(2, 3) * A(3, 1) - + A(0, 3) * A(1, 1) * A(2, 0) * A(3, 2) - - A(0, 1) * A(1, 3) * A(2, 0) * A(3, 2) - - A(0, 3) * A(1, 0) * A(2, 1) * A(3, 2) - + A(0, 0) * A(1, 3) * A(2, 1) * A(3, 2) - + A(0, 1) * A(1, 0) * A(2, 3) * A(3, 2) - - A(0, 0) * A(1, 1) * A(2, 3) * A(3, 2) - - A(0, 2) * A(1, 1) * A(2, 0) * A(3, 3) - + A(0, 1) * A(1, 2) * A(2, 0) * A(3, 3) - + A(0, 2) * A(1, 0) * A(2, 1) * A(3, 3) - - A(0, 0) * A(1, 2) * A(2, 1) * A(3, 3) - - A(0, 1) * A(1, 0) * A(2, 2) * A(3, 3) - + A(0, 0) * A(1, 1) * A(2, 2) * A(3, 3); - - return det; -} // end of det_4x4 function +KOKKOS_INLINE_FUNCTION double det_4x4(const T& A) { + const double det = A(0, 3) * A(1, 2) * A(2, 1) * A(3, 0) - A(0, 2) * A(1, 3) * A(2, 1) * A(3, 0) - A(0, 3) * A(1, 1) * A(2, 2) * A(3, 0) + + A(0, 1) * A(1, 3) * A(2, 2) * A(3, 0) + A(0, 2) * A(1, 1) * A(2, 3) * A(3, 0) - A(0, 1) * A(1, 2) * A(2, 3) * A(3, 0) - + A(0, 3) * A(1, 2) * A(2, 0) * A(3, 1) + A(0, 2) * A(1, 3) * A(2, 0) * A(3, 1) + A(0, 3) * A(1, 0) * A(2, 2) * A(3, 1) - + A(0, 0) * A(1, 3) * A(2, 2) * A(3, 1) - A(0, 2) * A(1, 0) * A(2, 3) * A(3, 1) + A(0, 0) * A(1, 2) * A(2, 3) * A(3, 1) + + A(0, 3) * A(1, 1) * A(2, 0) * A(3, 2) - A(0, 1) * A(1, 3) * A(2, 0) * A(3, 2) - A(0, 3) * A(1, 0) * A(2, 1) * A(3, 2) + + A(0, 0) * A(1, 3) * A(2, 1) * A(3, 2) + A(0, 1) * A(1, 0) * A(2, 3) * A(3, 2) - A(0, 0) * A(1, 1) * A(2, 3) * A(3, 2) - + A(0, 2) * A(1, 1) * A(2, 0) * A(3, 3) + A(0, 1) * A(1, 2) * A(2, 0) * A(3, 3) + A(0, 2) * A(1, 0) * A(2, 1) * A(3, 3) - + A(0, 0) * A(1, 2) * A(2, 1) * A(3, 3) - A(0, 1) * A(1, 0) * A(2, 2) * A(3, 3) + A(0, 0) * A(1, 1) * A(2, 2) * A(3, 3); + return det; +} // end of det_4x4 function -// ============================================ +// ============================================ // Array Inversion routines using Cramers Rule // ============================================ - ///////////////////////////////////////////////////////////////////////////// /// /// \fn invert_2x2 @@ -183,18 +146,12 @@ double det_4x4(const T &A){ /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -void invert_2x2( - const T &A, - const T &inv, - const double det){ - - inv(0, 0) = A(1, 1)/(det+1.e-16); - inv(0, 1) = -A(0, 1)/(det+1.e-16); - inv(1, 0) = -A(1, 0)/(det+1.e-16); - inv(1, 1) = A(0, 0)/(det+1.e-16); -} // end of 2D jacobin inverse - +KOKKOS_INLINE_FUNCTION void invert_2x2(const T& A, const T& inv, const double det) { + inv(0, 0) = A(1, 1) / (det + 1.e-16); + inv(0, 1) = -A(0, 1) / (det + 1.e-16); + inv(1, 0) = -A(1, 0) / (det + 1.e-16); + inv(1, 1) = A(0, 0) / (det + 1.e-16); +} // end of 2D jacobin inverse ///////////////////////////////////////////////////////////////////////////// /// @@ -208,27 +165,21 @@ void invert_2x2( /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -void invert_3x3( - const T &A, - const T &inv, - const double det){ +KOKKOS_INLINE_FUNCTION void invert_3x3(const T& A, const T& inv, const double det) { + inv(0, 0) = +(A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)) / (det + 1e-16); + inv(0, 1) = -(A(0, 1) * A(2, 2) - A(0, 2) * A(2, 1)) / (det + 1e-16); + inv(0, 2) = +(A(0, 1) * A(1, 2) - A(0, 2) * A(1, 1)) / (det + 1e-16); - inv(0,0) = +(A(1,1)*A(2,2) - A(1,2)*A(2,1)) / (det+1e-16); - inv(0,1) = -(A(0,1)*A(2,2) - A(0,2)*A(2,1)) / (det+1e-16); - inv(0,2) = +(A(0,1)*A(1,2) - A(0,2)*A(1,1)) / (det+1e-16); + inv(1, 0) = -(A(1, 0) * A(2, 2) - A(1, 2) * A(2, 0)) / (det + 1e-16); + inv(1, 1) = +(A(0, 0) * A(2, 2) - A(0, 2) * A(2, 0)) / (det + 1e-16); + inv(1, 2) = -(A(0, 0) * A(1, 2) - A(0, 2) * A(1, 0)) / (det + 1e-16); - inv(1,0) = -(A(1,0)*A(2,2) - A(1,2)*A(2,0)) / (det+1e-16); - inv(1,1) = +(A(0,0)*A(2,2) - A(0,2)*A(2,0)) / (det+1e-16); - inv(1,2) = -(A(0,0)*A(1,2) - A(0,2)*A(1,0)) / (det+1e-16); - - inv(2,0) = +(A(1,0)*A(2,1) - A(1,1)*A(2,0)) / (det+1e-16); - inv(2,1) = -(A(0,0)*A(2,1) - A(0,1)*A(2,0)) / (det+1e-16); - inv(2,2) = +(A(0,0)*A(1,1) - A(0,1)*A(1,0)) / (det+1e-16); + inv(2, 0) = +(A(1, 0) * A(2, 1) - A(1, 1) * A(2, 0)) / (det + 1e-16); + inv(2, 1) = -(A(0, 0) * A(2, 1) - A(0, 1) * A(2, 0)) / (det + 1e-16); + inv(2, 2) = +(A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0)) / (det + 1e-16); return; -} // end of inverse matrix - +} // end of inverse matrix ///////////////////////////////////////////////////////////////////////////// /// @@ -242,33 +193,25 @@ void invert_3x3( /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -double invert_3x3( - const T &A, - const T &inv){ - - double det = - A(0,0)*(A(1,1)*A(2,2) - A(1,2)*A(2,1)) - - A(0,1)*(A(1,0)*A(2,2) - A(1,2)*A(2,0)) + - A(0,2)*(A(1,0)*A(2,1) - A(1,1)*A(2,0)); +KOKKOS_INLINE_FUNCTION double invert_3x3(const T& A, const T& inv) { + double det = A(0, 0) * (A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)) - A(0, 1) * (A(1, 0) * A(2, 2) - A(1, 2) * A(2, 0)) + + A(0, 2) * (A(1, 0) * A(2, 1) - A(1, 1) * A(2, 0)); + inv(0, 0) = +(A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)) / (det + 1e-16); + inv(0, 1) = -(A(0, 1) * A(2, 2) - A(0, 2) * A(2, 1)) / (det + 1e-16); + inv(0, 2) = +(A(0, 1) * A(1, 2) - A(0, 2) * A(1, 1)) / (det + 1e-16); - inv(0,0) = +(A(1,1)*A(2,2) - A(1,2)*A(2,1)) / (det+1e-16); - inv(0,1) = -(A(0,1)*A(2,2) - A(0,2)*A(2,1)) / (det+1e-16); - inv(0,2) = +(A(0,1)*A(1,2) - A(0,2)*A(1,1)) / (det+1e-16); + inv(1, 0) = -(A(1, 0) * A(2, 2) - A(1, 2) * A(2, 0)) / (det + 1e-16); + inv(1, 1) = +(A(0, 0) * A(2, 2) - A(0, 2) * A(2, 0)) / (det + 1e-16); + inv(1, 2) = -(A(0, 0) * A(1, 2) - A(0, 2) * A(1, 0)) / (det + 1e-16); - inv(1,0) = -(A(1,0)*A(2,2) - A(1,2)*A(2,0)) / (det+1e-16); - inv(1,1) = +(A(0,0)*A(2,2) - A(0,2)*A(2,0)) / (det+1e-16); - inv(1,2) = -(A(0,0)*A(1,2) - A(0,2)*A(1,0)) / (det+1e-16); - - inv(2,0) = +(A(1,0)*A(2,1) - A(1,1)*A(2,0)) / (det+1e-16); - inv(2,1) = -(A(0,0)*A(2,1) - A(0,1)*A(2,0)) / (det+1e-16); - inv(2,2) = +(A(0,0)*A(1,1) - A(0,1)*A(1,0)) / (det+1e-16); + inv(2, 0) = +(A(1, 0) * A(2, 1) - A(1, 1) * A(2, 0)) / (det + 1e-16); + inv(2, 1) = -(A(0, 0) * A(2, 1) - A(0, 1) * A(2, 0)) / (det + 1e-16); + inv(2, 2) = +(A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0)) / (det + 1e-16); return det; -} // end of inverse matrix - +} // end of inverse matrix ///////////////////////////////////////////////////////////////////////////// /// @@ -282,10 +225,7 @@ double invert_3x3( /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -double invert_4x4(const T &A, - const T &inv) { - +KOKKOS_INLINE_FUNCTION double invert_4x4(const T& A, const T& inv) { // helper array double cof[4][4]; @@ -300,38 +240,40 @@ double invert_4x4(const T &A, size_t mj = 0; for (size_t jj = 0; jj < 4; ++jj) { if (jj == j) continue; - minor[mi][mj] = A(ii,jj); + minor[mi][mj] = A(ii, jj); ++mj; - } // end jj + } // end jj ++mi; - } // end ii + } // end ii - cof[i][j] = ((i + j) % 2 == 0 ? 1 : -1) * det_3x3( - minor[0][0], minor[0][1], minor[0][2], - minor[1][0], minor[1][1], minor[1][2], - minor[2][0], minor[2][1], minor[2][2] - ); // function + cof[i][j] = ((i + j) % 2 == 0 ? 1 : -1) * det_3x3(minor[0][0], + minor[0][1], + minor[0][2], + minor[1][0], + minor[1][1], + minor[1][2], + minor[2][0], + minor[2][1], + minor[2][2]); // function - } // end j - }// end i + } // end j + } // end i // Compute determinant from first row and cofactors double det = 0.0; - for (size_t j = 0; j < 4; ++j){ - det += A(0,j) * cof[0][j]; - } // end for j - + for (size_t j = 0; j < 4; ++j) { + det += A(0, j) * cof[0][j]; + } // end for j // Transpose cofactors to get adjugate, then divide by determinant - for (size_t i = 0; i < 4; ++i){ - for (size_t j = 0; j < 4; ++j){ - inv(i,j) = cof[j][i] / (det+1.e-16); - } // end j - } // end i + for (size_t i = 0; i < 4; ++i) { + for (size_t j = 0; j < 4; ++j) { + inv(i, j) = cof[j][i] / (det + 1.e-16); + } // end j + } // end i return det; -} // end function - +} // end function ///////////////////////////////////////////////////////////////////////////// /// @@ -345,11 +287,7 @@ double invert_4x4(const T &A, /// ///////////////////////////////////////////////////////////////////////////// template -KOKKOS_INLINE_FUNCTION -void invert_4x4(const T &A, - const T &inv, - const double det) { - +KOKKOS_INLINE_FUNCTION void invert_4x4(const T& A, const T& inv, const double det) { // helper array double cof[4][4]; @@ -364,29 +302,33 @@ void invert_4x4(const T &A, size_t mj = 0; for (size_t jj = 0; jj < 4; ++jj) { if (jj == j) continue; - minor[mi][mj] = A(ii,jj); + minor[mi][mj] = A(ii, jj); ++mj; - } // end jj + } // end jj ++mi; - } // end ii + } // end ii - cof[i][j] = ((i + j) % 2 == 0 ? 1 : -1) * det_3x3( - minor[0][0], minor[0][1], minor[0][2], - minor[1][0], minor[1][1], minor[1][2], - minor[2][0], minor[2][1], minor[2][2] - ); // function + cof[i][j] = ((i + j) % 2 == 0 ? 1 : -1) * det_3x3(minor[0][0], + minor[0][1], + minor[0][2], + minor[1][0], + minor[1][1], + minor[1][2], + minor[2][0], + minor[2][1], + minor[2][2]); // function - } // end j - }// end i + } // end j + } // end i // Transpose cofactors to get adjugate, then divide by determinant - for (size_t i = 0; i < 4; ++i){ - for (size_t j = 0; j < 4; ++j){ - inv(i,j) = cof[j][i] / (det+1.e-16); - } // end j - } // end i + for (size_t i = 0; i < 4; ++i) { + for (size_t j = 0; j < 4; ++j) { + inv(i, j) = cof[j][i] / (det + 1.e-16); + } // end j + } // end i return; -} // end function +} // end function -#endif // CRAMERS \ No newline at end of file +#endif // CRAMERS \ No newline at end of file diff --git a/solvers/lu_solver.hpp b/solvers/lu_solver.hpp index 15a841c1..0c6fbe20 100644 --- a/solvers/lu_solver.hpp +++ b/solvers/lu_solver.hpp @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -36,570 +36,481 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************************************/ -#include #include -#include +#include +#include #include "matar.h" using namespace mtr; - const double TINY = 1e-15; // --------------------------- // LU decomposition functions // --------------------------- - // the function is run on the GPU template -KOKKOS_FUNCTION -int LU_decompose( - const T1 &A, // device array A (e.g., DCArrayKokkos ) passed in and is sent out in LU decomp format - const T2 &perm, // permutations (e.g., DCArrayKokkos ) - const T3 &vv, // helper array (e.g., CArrayKokkos ) - int &parity) { // parity (+1 or -1) - - const int n = A.dims(0); // size of array +KOKKOS_FUNCTION int LU_decompose(const T1& A, // device array A (e.g., DCArrayKokkos ) + // passed in and is sent out in LU decomp format + const T2& perm, // permutations (e.g., DCArrayKokkos ) + const T3& vv, // helper array (e.g., CArrayKokkos ) + int& parity) { // parity (+1 or -1) + + const int n = A.dims(0); // size of array parity = 1; // helper variables double temp; - - // search for the largest element in each row; save the scaling in the - // temporary array vv and return zero if the array is singular - for(size_t i = 0; i < n; i++) { - + + // search for the largest element in each row; save the scaling in the + // temporary array vv and return zero if the array is singular + for (size_t i = 0; i < n; i++) { double big = 0.; - for(size_t j = 0; j < n; j++){ - if((temp=fabs(A(i,j))) > big){ - big=temp; + for (size_t j = 0; j < n; j++) { + if ((temp = fabs(A(i, j))) > big) { + big = temp; } } - - if(big == 0.0) return(0); - + + if (big == 0.0) return (0); + vv(i) = big; } // the main loop for the Crout's algorithm - for(size_t j = 0; j < n; j++) { - - // this is the part a) of the algorithm except for i==j - for(size_t i=0;ij + pivot search - for(size_t i = j; i < n; i++) { - - double sum = A(i,j); - - for(size_t k=0; kj + pivot search + for (size_t i = j; i < n; i++) { + double sum = A(i, j); + + for (size_t k = 0; k < j; k++) { + sum -= A(i, k) * A(k, j); } - - A(i,j) = sum; - + + A(i, j) = sum; + // is the figure of merit for the pivot better than the best so far? - if((temp = vv(i)*fabs(sum)) >= big){ - big = temp; + if ((temp = vv(i) * fabs(sum)) >= big) { + big = temp; imax = i; } - } // end for i + } // end for i // interchange rows, if needed, change parity and the scale factor - if(imax != j) { - - for(size_t k = 0; k < n; k++){ - temp = A(imax,k); - A(imax,k) = A(j,k); - A(j,k) = temp; + if (imax != j) { + for (size_t k = 0; k < n; k++) { + temp = A(imax, k); + A(imax, k) = A(j, k); + A(j, k) = temp; } - - parity = -(parity); + + parity = -(parity); vv(imax) = vv(j); } - + // store the index perm(j) = imax; - // if the pivot element is zero, the array is singular but for some - // applications a tiny number is desirable instead - - if(A(j,j) == 0.0){ - A(j,j) = TINY; + // if the pivot element is zero, the array is singular but for some + // applications a tiny number is desirable instead + + if (A(j, j) == 0.0) { + A(j, j) = TINY; } // finally, divide by the pivot element - - if(j -KOKKOS_FUNCTION -void LU_backsub( - const T1 &A, // input array A (e.g., DCArrayKokkos ) in LU decomp format - const T2 &perm, // permutations (e.g., DCArrayKokkos ) - const T3 &b){ // RHS and is answer x to Ax=B (e.g., DCArrayKokkos ) - - const int n = A.dims(0); // size of array - - int ii = -1; - - - // First step of backsubstitution; the only wrinkle is to unscramble - // the permutation order. Note: the algorithm is optimized for a - // possibility of large amount of zeroes in b - - for(size_t i = 0; i < n; i++) { - - size_t ip = perm(i); - - double sum = b(ip); - b(ip) = b(i); - - if(ii >= 0){ - for(size_t j = ii; j0){ - ii=i; // a nonzero element encounted +KOKKOS_FUNCTION void LU_backsub(const T1& A, // input array A (e.g., DCArrayKokkos ) in LU decomp format + const T2& perm, // permutations (e.g., DCArrayKokkos ) + const T3& b) { // RHS and is answer x to Ax=B (e.g., DCArrayKokkos ) + + const int n = A.dims(0); // size of array + + int ii = -1; + + // First step of backsubstitution; the only wrinkle is to unscramble + // the permutation order. Note: the algorithm is optimized for a + // possibility of large amount of zeroes in b + + for (size_t i = 0; i < n; i++) { + size_t ip = perm(i); + + double sum = b(ip); + b(ip) = b(i); + + if (ii >= 0) { + for (size_t j = ii; j < i; j++) { + sum -= A(i, j) * b(j); } - - b(i) = sum; - } // end loop i - - // the second step - for(int i=n-1; i>=0; i--) { - - double sum = b(i); - for(size_t j=i+1; j -KOKKOS_INLINE_FUNCTION -void LU_invert( - T1 &A, // input array, e.g., DCArrayKokkos - T2 &perm, // permutations, e.g., DCArrayKokkos - T3 &inv_mat, // inverse array, e.g., DCArrayKokkos - T4 &col) { // tmp array, e.g., DCArrayKokkos + } else if (sum > 0) { + ii = i; // a nonzero element encounted + } + + b(i) = sum; + } // end loop i + + // the second step + for (int i = n - 1; i >= 0; i--) { + double sum = b(i); + for (size_t j = i + 1; j < n; j++) { + sum -= A(i, j) * b(j); + } // end j + + b(i) = sum / A(i, i); + } // end loop i - const size_t n = A.dims(0); // size of array +} // end if +// ------------------ +// LU invert function +// ------------------ +template +KOKKOS_INLINE_FUNCTION void LU_invert(T1& A, // input array, e.g., DCArrayKokkos + T2& perm, // permutations, e.g., DCArrayKokkos + T3& inv_mat, // inverse array, e.g., DCArrayKokkos + T4& col) { // tmp array, e.g., DCArrayKokkos - for(size_t j = 0; j < n; j++){ + const size_t n = A.dims(0); // size of array - for(size_t i = 0; i < n; i++){ + for (size_t j = 0; j < n; j++) { + for (size_t i = 0; i < n; i++) { col(i) = 0.0; - } // end for i - + } // end for i + col(j) = 1.0; LU_backsub(A, perm, col); - - for(size_t i = 0; i < n; i++){ - inv_mat(i,j) = col(i); - } // end for i - } // end for j + for (size_t i = 0; i < n; i++) { + inv_mat(i, j) = col(i); + } // end for i + + } // end for j return; -} // end function +} // end function // ----------------------- -// LU determinant function +// LU determinant function // Input: A filled in LUPDecompose; N - dimension. // Output: determinate of original A array -// ----------------------- +// ----------------------- template -KOKKOS_INLINE_FUNCTION -double LU_determinant( - T &A, // input array, e.g., DCArrayKokkos - const int parity){ // parity (+1 0r -1) +KOKKOS_INLINE_FUNCTION double LU_determinant(T& A, // input array, e.g., DCArrayKokkos + const int parity) { // parity (+1 0r -1) - const int n = A.dims(0); // size of array + const int n = A.dims(0); // size of array double res = (double)(parity); - - for(size_t j=0; j -int LU_decompose_host( - T1 &A, // device array A (e.g., DCArrayKokkos ) passed in and is sent out in LU decomp format - T2 &perm, // permutations (e.g., DCArrayKokkos ) - T3 &vv, // helper array (e.g., CArrayKokkos ) - int &parity) { // parity (+1 or -1) - - const int n = A.dims(0); // size of array +int LU_decompose_host(T1& A, // device array A (e.g., DCArrayKokkos ) passed in and is sent + // out in LU decomp format + T2& perm, // permutations (e.g., DCArrayKokkos ) + T3& vv, // helper array (e.g., CArrayKokkos ) + int& parity) { // parity (+1 or -1) + + const int n = A.dims(0); // size of array - CArrayKokkos temp_scalar(1); // persistant scalar on device + CArrayKokkos temp_scalar(1); // persistant scalar on device parity = 1; - + // STEP 1: - // search for the largest element in each row; save the scaling in the + // search for the largest element in each row; save the scaling in the // temporary array vv and return zero if the array is singular FOR_FIRST(i, 0, n, { - - double max_val = 0.0; + double max_val = 0.0; double max_val_lcl = 0.0; - FOR_REDUCE_MAX_SECOND(j, 0, n, - max_val_lcl, { - - max_val_lcl = fmax(max_val_lcl, fabs(A(i,j)) ); - - }, max_val); // end parallel j - - vv(i) = max_val; + FOR_REDUCE_MAX_SECOND(j, 0, n, max_val_lcl, { max_val_lcl = fmax(max_val_lcl, fabs(A(i, j))); }, + max_val); // end parallel j - }); // end for + vv(i) = max_val; + }); // end for // if the largest value in the array row is 0, then exit - double min_val = 0.0; - double min_val_lcl = 0.0; - FOR_REDUCE_MIN(i, 0, n, + double min_val = 0.0; + double min_val_lcl = 0.0; + FOR_REDUCE_MIN(i, 0, n, min_val_lcl, { - min_val_lcl = fmin(vv(i), min_val_lcl); - }, min_val); - if(min_val < TINY) return(0); // singular array as all row values are 0 - + if (min_val < TINY) return (0); // singular array as all row values are 0 // STEP 2: // the main loop for the Crout's algorithm - for(size_t j = 0; j < n; j++) { - - // this is the part a) of the algorithm except for i==j - for(size_t i=0; ij - // loop is from i=j to i= max_val_lcl) { - max_val_lcl = vv(i)*fabs(A(i,j)); - } // end if - - }, max_val); // end for i + // is the figure of merit for the pivot better than the best so far? + if (vv(i) * fabs(A(i, j)) >= max_val_lcl) { + max_val_lcl = vv(i) * fabs(A(i, j)); + } // end if + }, max_val); // end for i Kokkos::fence(); - size_t imax = j; + size_t imax = j; size_t imax_lcl = j; // loop is from i=j to i= max_val ) { + // is the figure of merit for the pivot better than the best so far? + if (vv(i) * fabs(A(i, j)) >= max_val) { imax_lcl = i; - } // end if - - }, imax); // end for i + } // end if + }, imax); // end for i Kokkos::fence(); // interchange rows, if needed, change parity and the scale factor - if(imax != j) { - + if (imax != j) { FOR_ALL(k, 0, n, { - double temp = A(imax,k); - A(imax,k) = A(j,k); - A(j,k) = temp; + double temp = A(imax, k); + A(imax, k) = A(j, k); + A(j, k) = temp; }); - + parity = -parity; - RUN({ - vv(imax) = vv(j); - }); + RUN({ vv(imax) = vv(j); }); - } // end if - - // store the index - RUN({ - perm(j) = imax; - }); + } // end if + // store the index + RUN({ perm(j) = imax; }); - // if the pivot element is zero, the array is singular but for some - // applications a tiny number is desirable instead + // if the pivot element is zero, the array is singular but for some + // applications a tiny number is desirable instead RUN({ - if(A(j,j) == 0.0){ - A(j,j) = TINY; + if (A(j, j) == 0.0) { + A(j, j) = TINY; } }); - - - // finally, divide by the pivot element - if(j -void LU_backsub_host( - const T1 &A, // input array A (e.g., DCArrayKokkos ) in LU decomp format - const T2 &perm, // permutations (e.g., DCArrayKokkos ) - T3 &b){ // RHS and is answer x to Ax=B (e.g., DCArrayKokkos ) +void LU_backsub_host(const T1& A, // input array A (e.g., DCArrayKokkos ) in LU decomp format + const T2& perm, // permutations (e.g., DCArrayKokkos ) + T3& b) { // RHS and is answer x to Ax=B (e.g., DCArrayKokkos ) - const int n = A.dims(0); // size of array + const int n = A.dims(0); // size of array - CArrayKokkos val(1); // a helper variable that carries a scalar + CArrayKokkos val(1); // a helper variable that carries a scalar - // First step of backsubstitution; the only wrinkle is to unscramble - // the permutation order. Note, the algorithm is optimized for a - // possibility of large amount of zeroes in b + // First step of backsubstitution; the only wrinkle is to unscramble + // the permutation order. Note, the algorithm is optimized for a + // possibility of large amount of zeroes in b // Forward substitution: solve L x = P b - for(size_t i = 0; i < n; i++) { - + for (size_t i = 0; i < n; i++) { size_t ip = perm.host(i); - - RUN({ - val(0) = b(ip); - b(ip) = b(i); + + RUN({ + val(0) = b(ip); + b(ip) = b(i); }); - double sum = 0.0; - double sum_lcl = 0.0; + double sum = 0.0; + double sum_lcl = 0.0; // j=0 to j=0; i--){ - - double sum = 0.0; + for (int i = n - 1; i >= 0; i--) { + double sum = 0.0; double sum_lcl = 0.0; // for j=i+1 to j -double LU_determinant_host( - T &A, // input array (e.g., DCArrayKokkos ) - const int parity){ // parity (+1 0r -1) +double LU_determinant_host(T& A, // input array (e.g., DCArrayKokkos ) + const int parity) { // parity (+1 0r -1) - const int n = A.dims(0); // size of array + const int n = A.dims(0); // size of array double res = (double)(parity); double prod_tally; double prod_lcl = 1.0; - - FOR_REDUCE_PRODUCT(j, 0, n, - prod_lcl, { - prod_lcl *= A(j,j); - }, prod_tally); // end j - res *= prod_tally; + FOR_REDUCE_PRODUCT(j, 0, n, + prod_lcl, { + prod_lcl *= A(j, j); + }, prod_tally); // end j - return(res); + res *= prod_tally; -} // end function + return (res); +} // end function -// ------------------ -// LU invert function -// ------------------ +// ------------------ +// LU invert function +// ------------------ template -void LU_invert_host( - T1 &A, // input array (e.g., DCArrayKokkos ) - T2 &perm, // permutations (e.g., DCArrayKokkos ) - T3 &inv_mat, // inverse array (e.g., DCArrayKokkos ) - T4 &col) { // tmp array (e.g., DCArrayKokkos ) +void LU_invert_host(T1& A, // input array (e.g., DCArrayKokkos ) + T2& perm, // permutations (e.g., DCArrayKokkos ) + T3& inv_mat, // inverse array (e.g., DCArrayKokkos ) + T4& col) { // tmp array (e.g., DCArrayKokkos ) - const size_t n = A.dims(0); // size of array + const size_t n = A.dims(0); // size of array + for (size_t j = 0; j < n; j++) { + col.set_values(0.0); - for(size_t j = 0; j < n; j++){ + RUN({ col(j) = 1.0; }); - col.set_values(0.0); - - RUN({ - col(j) = 1.0; - }); - LU_backsub_host(A, perm, col); - + FOR_ALL(i, 0, n, { - inv_mat(i,j) = col(i); - }); // end for i + inv_mat(i, j) = col(i); + }); // end for i - } // end for j + } // end for j return; -} // end function - - +} // end function // Solve for x in Ax = b using LU // A[n,n] // b[n], note answer, x, is returned in b template -int LU_solver_host(T1 &A, // e.g., DCArrayKokkos - T2 &b, // e.g., DCArrayKokkos - T3 &perm, // permutations (e.g., DCArrayKokkos ) - T4 &vv, // e.g., CArrayKokkos - int &parity) { - - - int singular = 0; - parity = 0; - singular = LU_decompose_host(A, perm, vv, parity); // A is returned as the LU array - - if(singular==0){ +int LU_solver_host(T1& A, // e.g., DCArrayKokkos + T2& b, // e.g., DCArrayKokkos + T3& perm, // permutations (e.g., DCArrayKokkos ) + T4& vv, // e.g., CArrayKokkos + int& parity) { + int singular = 0; + parity = 0; + singular = LU_decompose_host(A, perm, vv, parity); // A is returned as the LU array + + if (singular == 0) { printf("ERROR: array is singluar \n"); return 0; } @@ -609,5 +520,4 @@ int LU_solver_host(T1 &A, // e.g., DCArrayKokkos return singular; } - -#endif // LUSOLVER +#endif // LUSOLVER diff --git a/solvers/qr_solver.hpp b/solvers/qr_solver.hpp index 2108f16e..fdb919e7 100644 --- a/solvers/qr_solver.hpp +++ b/solvers/qr_solver.hpp @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -37,74 +37,68 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **********************************************************************************************/ - ////////////////////////// +////////////////////////// -#include #include -#include +#include +#include #include "matar.h" using namespace mtr; - // Transpose matrix template -void transpose_host(const T1 &A, // e.g., DCArrayKokkos - T2 &At) { // e.g., DCArrayKokkos +void transpose_host(const T1& A, // e.g., DCArrayKokkos + T2& At) { // e.g., DCArrayKokkos size_t m = A.dims(0); size_t n = A.dims(1); FOR_ALL(i, 0, m, j, 0, n, { - At(j, i) = A(i,j); + At(j, i) = A(i, j); }); return; -} // end function - +} // end function // Back substitution to solve Rx = y template -void QR_backsub_host(const T1 &R, // e.g., DCArrayKokkos - const T2 &y, // e.g., DCArrayKokkos - T3 &x) { // e.g., DCArrayKokkos - +void QR_backsub_host(const T1& R, // e.g., DCArrayKokkos + const T2& y, // e.g., DCArrayKokkos + T3& x) { // e.g., DCArrayKokkos + size_t n = R.dims(0); - + for (int i = n - 1; i >= 0; --i) { - - RUN({ - x(i) = y(i); - }); + RUN({ x(i) = y(i); }); - double sum = 0.0; + double sum = 0.0; double sum_lcl = 0.0; - FOR_REDUCE_SUM(j, i + 1, n, + FOR_REDUCE_SUM(j, i + 1, n, sum_lcl, { - sum_lcl -= R(i,j) * x(j); + sum_lcl -= R(i, j) * x(j); }, sum); RUN({ x(i) += sum; - x(i) /= R(i,i); + x(i) /= R(i, i); }); - } // end for i + } // end for i return; -} // end function +} // end function // QR Decomposition using Modified Gram-Schmidt template -void QR_decompose_host(const T1 &A, // e.g., DCArrayKokkos - T2 &Q, // e.g., DFArrayKokkos - T3 &R) { // e.g., DCArrayKokkos - +void QR_decompose_host(const T1& A, // e.g., DCArrayKokkos + T2& Q, // e.g., DFArrayKokkos + T3& R) { // e.g., DCArrayKokkos const size_t m = A.dims(0); const size_t n = A.dims(1); @@ -112,103 +106,91 @@ void QR_decompose_host(const T1 &A, // e.g., DCArrayKokkos Q.set_values(0.0); R.set_values(0.0); - DCArrayKokkos v(n,m,"v"); + DCArrayKokkos v(n, m, "v"); // Copy columns of A to v, and taking transpose FOR_ALL(i, 0, m, j, 0, n, { - v(j, i) = A(i,j); + v(j, i) = A(i, j); }); Kokkos::fence(); - for (size_t i = 0; i < n; ++i) { - // find the norm of a column in matrix v for row i - double tally = 0.0; + double tally = 0.0; double tally_lcl = 0.0; - - FOR_REDUCE_SUM(j, 0, m, + FOR_REDUCE_SUM(j, 0, m, tally_lcl, { - tally_lcl += v(i,j) * v(i,j); + tally_lcl += v(i, j) * v(i, j); }, tally); Kokkos::fence(); RUN({ - R(i,i) = sqrt(tally); // row i norm + R(i, i) = sqrt(tally); // row i norm }); // done with norm calc FOR_ALL(j, 0, m, { - Q(j,i) = v(i,j)/R(i,i); + Q(j, i) = v(i, j) / R(i, i); }); Kokkos::fence(); -// single parallelism -/* - FOR_ALL(jj, i+1, n, { - - R(i,jj) = 0.0; + // single parallelism + /* + FOR_ALL(jj, i+1, n, { - double sum=0; + R(i,jj) = 0.0; - for(size_t k=0; k -double QR_determinant_host(const T1 &Q, // e.g., DFArrayKokkos - const T2 &R) // e.g., DCArrayKokkos +double QR_determinant_host(const T1& Q, // e.g., DFArrayKokkos + const T2& R) // e.g., DCArrayKokkos { - //const size_t m = Q.dims(0); + // const size_t m = Q.dims(0); const size_t n = Q.dims(1); // Q(m,n,"Q"); // R(n,n,"R"); double detR = 1.0; - int signQ = 1; + int signQ = 1; // Accumulate det(R) and track sign adjustments // for (size_t i = 0; i < n; ++i) { @@ -222,33 +204,33 @@ double QR_determinant_host(const T1 &Q, // e.g., DFArrayKokkos double prod_tally; double prod_lcl = 1.0; - FOR_REDUCE_PRODUCT(i, 0, n, - prod_lcl, { - - if (R(i,i) < 0.0) { - prod_lcl *= -R(i,i); // store magnitude in detR + FOR_REDUCE_PRODUCT(i, 0, n, + prod_lcl, { + if (R(i, i) < 0.0) { + prod_lcl *= -R(i, i); // store magnitude in detR } else { - prod_lcl *= R(i,i); + prod_lcl *= R(i, i); } - }, prod_tally); // end j + }, prod_tally); // end j Kokkos::fence(); - detR = prod_tally; - - prod_lcl = 1.0; - FOR_REDUCE_PRODUCT(i, 0, n, - prod_lcl, { - - if (R(i,i) < 0.0) { - prod_lcl *= -1; // negative diagonal flips Q's sign - } - }, prod_tally); // end j + FOR_REDUCE_PRODUCT( + i, + 0, + n, + prod_lcl, + { + if (R(i, i) < 0.0) { + prod_lcl *= -1; // negative diagonal flips Q's sign + } + }, + prod_tally); // end j + + signQ = prod_tally; - signQ = prod_tally; - Kokkos::fence(); // Compute sign of det(Q) directly from Q if needed @@ -257,40 +239,33 @@ double QR_determinant_host(const T1 &Q, // e.g., DFArrayKokkos return detA; } - // Solve for x in Ax = b using QR // A[m,n] // x[n] // b[m] template -void QR_solver_host(const T1 &A, // e.g., DCArrayKokkos - const T2 &b, // e.g., DCArrayKokkos - T3 &x) { // e.g., DCArrayKokkos - +void QR_solver_host(const T1& A, // e.g., DCArrayKokkos + const T2& b, // e.g., DCArrayKokkos + T3& x) { // e.g., DCArrayKokkos + const size_t m = A.dims(0); const size_t n = A.dims(1); - DFArrayKokkos Q(m,n,"Q"); - DCArrayKokkos R(n,n,"R"); - DCArrayKokkos y(n,"y"); + DFArrayKokkos Q(m, n, "Q"); + DCArrayKokkos R(n, n, "R"); + DCArrayKokkos y(n, "y"); QR_decompose_host(A, Q, R); - // Compute Q^t * b FOR_FIRST(i, 0, n, { - - double sum = 0.0; + double sum = 0.0; double sum_lcl = 0.0; // Q[m,n] so Q^t[n,m] b[m] - FOR_REDUCE_SUM_SECOND(j, 0, m, - sum_lcl, { - sum_lcl += Q(j,i) * b(j); - }, sum); + FOR_REDUCE_SUM_SECOND(j, 0, m, sum_lcl, { sum_lcl += Q(j, i) * b(j); }, sum); y(i) = sum; - - }); // end parallel i + }); // end parallel i Kokkos::fence(); @@ -303,42 +278,33 @@ void QR_solver_host(const T1 &A, // e.g., DCArrayKokkos // dimensions: Q(m,n,"Q"); // dimenions: R(n,n,"R"); template -void QR_solver_host(const T1 &Q, // e.g., DFArrayKokkos - const T2 &R, // e.g., DCArrayKokkos - const T3 &b, // e.g., DCArrayKokkos - T4 &x) { // e.g., DCArrayKokkos - +void QR_solver_host(const T1& Q, // e.g., DFArrayKokkos + const T2& R, // e.g., DCArrayKokkos + const T3& b, // e.g., DCArrayKokkos + T4& x) { // e.g., DCArrayKokkos + const size_t m = Q.dims(0); const size_t n = Q.dims(1); - DCArrayKokkos y(n,"y"); + DCArrayKokkos y(n, "y"); // Compute Q^t * b FOR_FIRST(i, 0, n, { - - double sum = 0.0; + double sum = 0.0; double sum_lcl = 0.0; // Q[m,n] so Q^t[n,m] b[m] - FOR_REDUCE_SUM_SECOND(j, 0, m, - sum_lcl, { - sum_lcl += Q(j,i) * b(j); - }, sum); + FOR_REDUCE_SUM_SECOND(j, 0, m, sum_lcl, { sum_lcl += Q(j, i) * b(j); }, sum); y(i) = sum; - - }); // end parallel i + }); // end parallel i // Solve R x = y QR_backsub_host(R, y, x); } - - - ////////////////////////// - -#endif // QR +#endif // QR /* #include @@ -449,20 +415,18 @@ int main() { } */ - ////////////////////////////////// - /* // Dot product double dot_host( const DCArrayKokkos &a, const DCArrayKokkos &b) { - + double result = 0.0; double sum_lcl = 0.0; - FOR_REDUCE_SUM(i, 0, a.size(), + FOR_REDUCE_SUM(i, 0, a.size(), sum_lcl, { sum_lcl += a(i) * b(i); }, result); @@ -482,10 +446,10 @@ double norm_vec_host(const DCArrayKokkos &v) { // Multiply matrix and vector void mat_vec_multiply_host( - const DCArrayKokkos &A, + const DCArrayKokkos &A, const DCArrayKokkos &x, DCArrayKokkos &result) { - + size_t m = A.dims(0), n = x.size(); FOR_FIRST(i, 0, m, { diff --git a/src/include/aliases.h b/src/include/aliases.h index ba372d3c..65fd2c39 100644 --- a/src/include/aliases.h +++ b/src/include/aliases.h @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -40,147 +40,137 @@ #include "host_types.h" #include "kokkos_types.h" - using real_t = double; using u_int = unsigned int; - // simple data type names -namespace mtr -{ - // dense host (only cpu) types - template - using CArrayHost = CArray ; +namespace mtr { +// dense host (only cpu) types +template +using CArrayHost = CArray; + +template +using CMatrixHost = CMatrix; - template - using CMatrixHost = CMatrix ; +template +using FArrayHost = FArray; - template - using FArrayHost = FArray ; - - template - using FMatrixHost = FMatrix ; +template +using FMatrixHost = FMatrix; - template - using ViewCArrayHost = ViewCArray ; - - template - using ViewCMatrixHost = ViewCMatrix ; - - template - using ViewFArrayHost = ViewFArray ; - - template - using ViewFMatrixHost = ViewFMatrix ; +template +using ViewCArrayHost = ViewCArray; +template +using ViewCMatrixHost = ViewCMatrix; - // ragged and sparse host (only cpu) types - template - using RaggedCArrayHost = RaggedRightArray ; +template +using ViewFArrayHost = ViewFArray; - template - using RaggedFArrayHost = RaggedDownArray ; +template +using ViewFMatrixHost = ViewFMatrix; - template - using DynamicRaggedCArrayHost = DynamicRaggedRightArray ; +// ragged and sparse host (only cpu) types +template +using RaggedCArrayHost = RaggedRightArray; - template - using DynamicRaggedFArrayHost = DynamicRaggedDownArray ; +template +using RaggedFArrayHost = RaggedDownArray; - template - using CSRArrayHost = CSRArray ; +template +using DynamicRaggedCArrayHost = DynamicRaggedRightArray; - template - using CSCArrayHost = CSCArray ; +template +using DynamicRaggedFArrayHost = DynamicRaggedDownArray; +template +using CSRArrayHost = CSRArray; -} // end namespace +template +using CSCArrayHost = CSCArray; +} // namespace mtr #ifdef HAVE_KOKKOS -namespace mtr -{ - // dense device types - template - using CArrayDevice = CArrayKokkos ; - - template - using CMatrixDevice = CMatrixKokkos ; - - template - using FArrayDevice = FArrayKokkos ; - - template - using FMatrixDevice = FMatrixKokkos ; - - template - using ViewCArrayDevice = ViewCArrayKokkos ; - - template - using ViewCMatrixDevice = ViewCMatrixKokkos ; - - template - using ViewFArrayDevice = ViewFArrayKokkos ; - - template - using ViewFMatrixDevice = ViewFMatrixKokkos ; - - - // ragged and sparse device types - template - using RaggedCArrayDevice = RaggedRightArrayKokkos ; - - template - using RaggedCArrayDual = DRaggedRightArrayKokkos ; - - template - using RaggedFArrayDevice = RaggedDownArrayKokkos ; - - template - using DynamicRaggedCArrayDevice = DynamicRaggedRightArrayKokkos ; - - template - using DynamicRaggedFArrayDevice = DynamicRaggedDownArrayKokkos ; - - template - using CSRArrayDevice = CSRArrayKokkos ; - - template - using CSCArrayDevice = CSCArrayKokkos ; - - - // dual dense types - template - using CArrayDual = DCArrayKokkos ; - - template - using CMatrixDual = DCMatrixKokkos ; - - template - using FArrayDual = DFArrayKokkos ; - - template - using FMatrixDual = DFMatrixKokkos ; - - template - using ViewCArrayDual = DViewCArrayKokkos ; - - template - using ViewCMatrixDual = DViewCMatrixKokkos ; - - template - using ViewFArrayDual = DViewFArrayKokkos ; - - template - using ViewFMatrixDual = DViewFMatrixKokkos ; - - -} // end namespace -#endif // end if have Kokkos for simple data type names +namespace mtr { +// dense device types +template +using CArrayDevice = CArrayKokkos; + +template +using CMatrixDevice = CMatrixKokkos; + +template +using FArrayDevice = FArrayKokkos; + +template +using FMatrixDevice = FMatrixKokkos; + +template +using ViewCArrayDevice = ViewCArrayKokkos; + +template +using ViewCMatrixDevice = ViewCMatrixKokkos; + +template +using ViewFArrayDevice = ViewFArrayKokkos; + +template +using ViewFMatrixDevice = ViewFMatrixKokkos; + +// ragged and sparse device types +template +using RaggedCArrayDevice = RaggedRightArrayKokkos; + +template +using RaggedCArrayDual = DRaggedRightArrayKokkos; + +template +using RaggedFArrayDevice = RaggedDownArrayKokkos; + +template +using DynamicRaggedCArrayDevice = DynamicRaggedRightArrayKokkos; + +template +using DynamicRaggedFArrayDevice = DynamicRaggedDownArrayKokkos; + +template +using CSRArrayDevice = CSRArrayKokkos; + +template +using CSCArrayDevice = CSCArrayKokkos; + +// dual dense types +template +using CArrayDual = DCArrayKokkos; + +template +using CMatrixDual = DCMatrixKokkos; + +template +using FArrayDual = DFArrayKokkos; + +template +using FMatrixDual = DFMatrixKokkos; + +template +using ViewCArrayDual = DViewCArrayKokkos; + +template +using ViewCMatrixDual = DViewCMatrixKokkos; + +template +using ViewFArrayDual = DViewFArrayKokkos; + +template +using ViewFMatrixDual = DViewFMatrixKokkos; + +} // namespace mtr +#endif // end if have Kokkos for simple data type names #ifdef HAVE_KOKKOS #define MATAR_FENCE() Kokkos::fence() -#define MATAR_INITIALIZE(...) Kokkos::initialize(__VA_ARGS__) +#define MATAR_INITIALIZE(...) Kokkos::initialize(__VA_ARGS__) #define MATAR_FINALIZE() Kokkos::finalize(); #else #define MATAR_FENCE() @@ -188,4 +178,4 @@ namespace mtr #define MATAR_FINALIZE() #endif -#endif // ALIASES_H +#endif // ALIASES_H diff --git a/src/include/communication_plan.h b/src/include/communication_plan.h index 619ad158..7e75205a 100644 --- a/src/include/communication_plan.h +++ b/src/include/communication_plan.h @@ -3,47 +3,37 @@ #ifdef HAVE_MPI #include -#include "matar.h" #include -namespace mtr -{ +#include "matar.h" + +namespace mtr { -enum class communication_plan_type { - no_communication, - all_to_all_graph -}; +enum class communication_plan_type { no_communication, all_to_all_graph }; /// Reduction operation for @c MPICArrayKokkos::all_reduce (maps to @c MPI_Op for the MPI stage). -enum class operation { - sum, - product, - max, - min -}; +enum class operation { sum, product, max, min }; /// Map @ref operation to the corresponding @c MPI_Op (host-only; call after @c MPI_Init). inline MPI_Op mpi_op_for(operation op) { switch (op) { - case operation::sum: - return MPI_SUM; - case operation::product: - return MPI_PROD; - case operation::max: - return MPI_MAX; - case operation::min: - return MPI_MIN; - default: - return MPI_SUM; + case operation::sum: + return MPI_SUM; + case operation::product: + return MPI_PROD; + case operation::max: + return MPI_MAX; + case operation::min: + return MPI_MIN; + default: + return MPI_SUM; } } - struct CommunicationPlan { - // ======================================================================== - // Metadata for MPI neighbor graph communication + // Metadata for MPI neighbor graph communication // ======================================================================== communication_plan_type comm_type = communication_plan_type::no_communication; @@ -51,7 +41,7 @@ struct CommunicationPlan { // MPI world communicator MPI_Comm mpi_comm_world; bool has_comm_world = false; - int world_size = -1; + int world_size = -1; // MPI graph communicator MPI_Comm mpi_comm_graph; @@ -67,46 +57,48 @@ struct CommunicationPlan { // recv_weights: Weights on incoming edges (not used here, set to MPI_UNWEIGHTED) // Could be used to specify communication volume if needed for optimization - int* recv_weights = MPI_UNWEIGHTED; // [size: num_recv_ranks] Weights on incoming edges, set to MPI_UNWEIGHTED if not used - + int* recv_weights = MPI_UNWEIGHTED; // [size: num_recv_ranks] Weights on incoming edges, set to + // MPI_UNWEIGHTED if not used + // send_weights: Weights on outgoing edges (not used here, set to MPI_UNWEIGHTED) // Could be used to specify communication volume if needed for optimization - int* send_weights = MPI_UNWEIGHTED; // [size: num_send_ranks] Weights on outgoing edges, set to MPI_UNWEIGHTED if not used - + int* send_weights = MPI_UNWEIGHTED; // [size: num_send_ranks] Weights on outgoing edges, set to + // MPI_UNWEIGHTED if not used + // info: Hints for optimization (MPI_INFO_NULL means use defaults) MPI_Info info = MPI_INFO_NULL; - + // reorder: Whether to allow MPI to reorder ranks for optimization (0=no reordering) // Setting to 0 preserves original rank numbering - // Note: In the future, we may want to allow MPI to reorder ranks for optimization by setting to 1, - // this would allow MPI to reorder the ranks to make them physically closer on the hardware. - // This is a good optimization for large meshes, but will require maps from MPI_comm_world rank IDs to the new reordered rank IDs. - int reorder = 0; + // Note: In the future, we may want to allow MPI to reorder ranks for optimization by setting to + // 1, this would allow MPI to reorder the ranks to make them physically closer on the hardware. + // This is a good optimization for large meshes, but will require maps from MPI_comm_world rank + // IDs to the new reordered rank IDs. + int reorder = 0; + + DRaggedRightArrayKokkos send_indices_; // [size: num_send_ranks, num_items_to_send_per_rank] Indices of items to + // send to each rank + DRaggedRightArrayKokkos recv_indices_; // [size: num_recv_ranks, num_items_to_recv_per_rank] Indices of items to + // receive from each rank - DRaggedRightArrayKokkos send_indices_; // [size: num_send_ranks, num_items_to_send_per_rank] Indices of items to send to each rank - DRaggedRightArrayKokkos recv_indices_; // [size: num_recv_ranks, num_items_to_recv_per_rank] Indices of items to receive from each rank + DCArrayKokkos send_counts_; // [size: num_send_ranks] Number of items to send to each rank + DCArrayKokkos recv_counts_; // [size: num_recv_ranks] Number of items to receive from each rank - DCArrayKokkos send_counts_; // [size: num_send_ranks] Number of items to send to each rank - DCArrayKokkos recv_counts_; // [size: num_recv_ranks] Number of items to receive from each rank - - DCArrayKokkos send_displs_; // [size: num_send_ranks] Starting index of items to send to each rank - DCArrayKokkos recv_displs_; // [size: num_recv_ranks] Starting index of items to receive from each rank + DCArrayKokkos send_displs_; // [size: num_send_ranks] Starting index of items to send to each rank + DCArrayKokkos recv_displs_; // [size: num_recv_ranks] Starting index of items to receive from each rank - int total_send_count; // Total number of items to send - int total_recv_count; // Total number of items to receive + int total_send_count; // Total number of items to send + int total_recv_count; // Total number of items to receive // ======================================================================== // CONSTRUCTOR / INITIALIZATION // ======================================================================== - - CommunicationPlan() - : num_send_ranks(0), num_recv_ranks(0), - has_comm_graph(false) {} - - + + CommunicationPlan() : num_send_ranks(0), num_recv_ranks(0), has_comm_graph(false) {} + // Destructor to free MPI resources ~CommunicationPlan() { - int mpi_init = 0; + int mpi_init = 0; int mpi_finalized = 0; MPI_Initialized(&mpi_init); MPI_Finalized(&mpi_finalized); @@ -115,41 +107,45 @@ struct CommunicationPlan { } } - void initialize(MPI_Comm comm_world){ + void initialize(MPI_Comm comm_world) { int mpi_init = 0; MPI_Initialized(&mpi_init); if (!mpi_init) { return; } this->mpi_comm_world = comm_world; - has_comm_world = true; + has_comm_world = true; MPI_Comm_size(comm_world, &world_size); } - + /** * @brief Initialize an MPI distributed graph communicator for sparse neighbor communication. * * This function creates an MPI "dist graph communicator" tailored to the sparse data exchange * patterns typical in mesh-based parallel applications. It establishes direct knowledge for MPI - * about which processes (ranks) each process will communicate with. This improves the efficiency - * and clarity of later communication (for example, with MPI_Neighbor_alltoallv). + * about which processes (ranks) each process will communicate with. This improves the + * efficiency and clarity of later communication (for example, with MPI_Neighbor_alltoallv). * - * This function is especially useful when the communication pattern is not all-to-all, but rather - * a sparse subset: for instance, where each process only exchanges data with a few neighbors. + * This function is especially useful when the communication pattern is not all-to-all, but + * rather a sparse subset: for instance, where each process only exchanges data with a few + * neighbors. * * ==== Key Concepts ==== - * - MPI Communicator: An MPI object representing a group of processes that can communicate with each other. - * For context, "MPI_COMM_WORLD" is a communicator including all processes, but a graph communicator - * customizes direct process connections. + * - MPI Communicator: An MPI object representing a group of processes that can communicate + * with each other. For context, "MPI_COMM_WORLD" is a communicator including all processes, but + * a graph communicator customizes direct process connections. * - Rank: Integer ID identifying a process in a communicator. - * - Distributed Graph: MPI can represent communication as a directed sparse graph, with edges from - * this rank to those it needs to send to, and from those it will receive from. + * - Distributed Graph: MPI can represent communication as a directed sparse graph, with edges + * from this rank to those it needs to send to, and from those it will receive from. * * ==== Parameters ==== * @param num_send_ranks [in] Number of ranks this process will send data to (out-neighbors). - * @param send_rank_ids [in] Array of size num_send_ranks; each entry is the rank of a process to send to. - * @param num_recv_ranks [in] Number of ranks this process will receive data from (in-neighbors). - * @param recv_rank_ids [in] Array of size num_recv_ranks; each entry is the rank of a process to receive from. + * @param send_rank_ids [in] Array of size num_send_ranks; each entry is the rank of a + * process to send to. + * @param num_recv_ranks [in] Number of ranks this process will receive data from + * (in-neighbors). + * @param recv_rank_ids [in] Array of size num_recv_ranks; each entry is the rank of a + * process to receive from. * * ==== Steps ==== * @@ -171,10 +167,12 @@ struct CommunicationPlan { * - The 'reorder' argument (set to 0 in this class) disables rank reordering; * this ensures the assignment of process ranks is preserved, which is often needed * for mapping data or results back to physical entities. - * - On return, 'mpi_comm_graph' will allow use of "neighbor" collectives (MPI_Neighbor_alltoall[v], etc.), - * which automatically use the provided topology to send/receive to only neighbors efficiently. + * - On return, 'mpi_comm_graph' will allow use of "neighbor" collectives + * (MPI_Neighbor_alltoall[v], etc.), which automatically use the provided topology to + * send/receive to only neighbors efficiently. * - * 4. Marks the internal flag indicating that the graph communicator has been set up ("has_comm_graph"). + * 4. Marks the internal flag indicating that the graph communicator has been set up + * ("has_comm_graph"). * * ==== Example Usage ==== * Suppose rank 0 will send to ranks 1 and 2, and receive from rank 3 only: @@ -183,7 +181,7 @@ struct CommunicationPlan { * initialize_graph_communicator(2, send_ranks, 1, recv_ranks); * * ==== Why Use This? ==== - * - This avoids the need to do manual pairwise MPI_Send/MPI_Recv in your code, + * - This avoids the need to do manual pairwise MPI_Send/MPI_Recv in your code, * and enables the use of neighbor collectives -- concise, scalable, and hard-to-get-wrong. * - It explicitly tells MPI only about your neighbors, so it can optimize routes and memory. * - If you have a large number of processes or a mesh/network with only local coupling, @@ -191,21 +189,20 @@ struct CommunicationPlan { * * @throws std::runtime_error if the base communicator has not been initialized. */ - void initialize_graph_communicator(int num_send_ranks, int* send_rank_ids, int num_recv_ranks, int* recv_rank_ids){ - + void initialize_graph_communicator(int num_send_ranks, int* send_rank_ids, int num_recv_ranks, int* recv_rank_ids) { this->comm_type = communication_plan_type::all_to_all_graph; // Check if the MPI_COMM_WORLD communicator has been initialized. - if(!has_comm_world){ + if (!has_comm_world) { throw std::runtime_error("MPI communicator for the world has not been initialized"); } - + // Store the number of outbound and inbound neighbors this->num_send_ranks = num_send_ranks; this->num_recv_ranks = num_recv_ranks; - + // Copy and store send neighbor IDs (out-bound neighbors: where we will send data to) this->send_rank_ids = DCArrayKokkos(num_send_ranks, "send_rank_ids"); - for(int i = 0; i < num_send_ranks; i++){ + for (int i = 0; i < num_send_ranks; i++) { this->send_rank_ids.host(i) = send_rank_ids[i]; } this->send_rank_ids.update_device(); @@ -213,35 +210,36 @@ struct CommunicationPlan { // Copy and store receive neighbor IDs (in-bound neighbors: where we will receive data from) this->recv_rank_ids = DCArrayKokkos(num_recv_ranks, "recv_rank_ids"); - for(int i = 0; i < num_recv_ranks; i++){ + for (int i = 0; i < num_recv_ranks; i++) { this->recv_rank_ids.host(i) = recv_rank_ids[i]; } this->recv_rank_ids.update_device(); MATAR_FENCE(); - + // Create the distributed graph communicator. // This call links this process to its explicit send and receive neighbors. - // See https://www.open-mpi.org/doc/v4.0/man3/MPI_Dist_graph_create_adjacent.3.php for more details. - MPI_Dist_graph_create_adjacent( - mpi_comm_world, // Existing communicator (usually MPI_COMM_WORLD) - num_recv_ranks, // Number of in-neighbors (recv) - this->recv_rank_ids.host_pointer(), // Array of in-neighbor ranks (who we receive from) - recv_weights, // Edge weights (NULL = unweighted) - num_send_ranks, // Number of out-neighbors (send) - this->send_rank_ids.host_pointer(), // Array of out-neighbor ranks (who we send to) - send_weights, // Edge weights (NULL = unweighted) - info, // Additional info for MPI (not used, set to MPI_INFO_NULL) - reorder, // Allow MPI to reorder ranks for performance (0 disables) - &mpi_comm_graph // [out] New graph communicator + // See https://www.open-mpi.org/doc/v4.0/man3/MPI_Dist_graph_create_adjacent.3.php for more + // details. + MPI_Dist_graph_create_adjacent(mpi_comm_world, // Existing communicator (usually MPI_COMM_WORLD) + num_recv_ranks, // Number of in-neighbors (recv) + this->recv_rank_ids.host_pointer(), // Array of in-neighbor ranks (who we receive from) + recv_weights, // Edge weights (NULL = unweighted) + num_send_ranks, // Number of out-neighbors (send) + this->send_rank_ids.host_pointer(), // Array of out-neighbor ranks (who we send to) + send_weights, // Edge weights (NULL = unweighted) + info, // Additional info for MPI (not used, set to MPI_INFO_NULL) + reorder, // Allow MPI to reorder ranks for performance (0 disables) + &mpi_comm_graph // [out] New graph communicator ); - // Set the internal flag indicating that we have created the MPI distributed graph communicator. + // Set the internal flag indicating that we have created the MPI distributed graph + // communicator. has_comm_graph = true; } // Useful function for debugging, possibly remove - void verify_graph_communicator(){ - if(!has_comm_graph){ + void verify_graph_communicator() { + if (!has_comm_graph) { throw std::runtime_error("MPI graph communicator has not been initialized"); } @@ -251,24 +249,28 @@ struct CommunicationPlan { // Query the graph to verify it matches what we specified int indegree_out, outdegree_out, weighted; MPI_Dist_graph_neighbors_count(mpi_comm_graph, &indegree_out, &outdegree_out, &weighted); - + // Allocate arrays to receive neighbor information std::vector sources_out(indegree_out); std::vector sourceweights_out(indegree_out); std::vector destinations_out(outdegree_out); std::vector destweights_out(outdegree_out); - + // Retrieve the actual neighbors from the graph communicator - MPI_Dist_graph_neighbors(mpi_comm_graph, - indegree_out, sources_out.data(), sourceweights_out.data(), - outdegree_out, destinations_out.data(), destweights_out.data()); - + MPI_Dist_graph_neighbors(mpi_comm_graph, + indegree_out, + sources_out.data(), + sourceweights_out.data(), + outdegree_out, + destinations_out.data(), + destweights_out.data()); + int rank = -1; MPI_Comm_rank(mpi_comm_world, &rank); // Additional verification: Check if the queried values match our input bool verification_passed = true; - + // Print verification information for each rank sequentially for (int r = 0; r < world_size; ++r) { MPI_Barrier(mpi_comm_world); @@ -279,18 +281,18 @@ struct CommunicationPlan { std::cout << sources_out[i] << " "; } std::cout << std::endl; - + std::cout << " Outdegree (sends to " << outdegree_out << " ranks): "; for (int i = 0; i < outdegree_out; ++i) { std::cout << destinations_out[i] << " "; } std::cout << std::endl; - + std::cout << " Weighted: " << (weighted ? "yes" : "no") << std::endl; } MPI_Barrier(mpi_comm_world); } - + // Check if the counts match our stored values if (indegree_out != num_recv_ranks) { std::cerr << "[rank " << rank << "] ERROR: indegree mismatch! " @@ -302,7 +304,7 @@ struct CommunicationPlan { << "Expected " << num_send_ranks << ", got " << outdegree_out << std::endl; verification_passed = false; } - + // Check if source ranks match (build set from our stored recv_rank_ids) std::set sources_set_in; for (int i = 0; i < num_recv_ranks; ++i) { @@ -313,7 +315,7 @@ struct CommunicationPlan { std::cerr << "[rank " << rank << "] ERROR: source ranks mismatch!" << std::endl; verification_passed = false; } - + // Check if destination ranks match (build set from our stored send_rank_ids) std::set dests_set_in; for (int i = 0; i < num_send_ranks; ++i) { @@ -324,9 +326,9 @@ struct CommunicationPlan { std::cerr << "[rank " << rank << "] ERROR: destination ranks mismatch!" << std::endl; verification_passed = false; } - + // Global verification check - int local_passed = verification_passed ? 1 : 0; + int local_passed = verification_passed ? 1 : 0; int global_passed = 0; MPI_Allreduce(&local_passed, &global_passed, 1, MPI_INT, MPI_MIN, mpi_comm_world); MPI_Barrier(mpi_comm_world); @@ -341,42 +343,41 @@ struct CommunicationPlan { } // Setup send/receive metadata - void setup_send_recv(DRaggedRightArrayKokkos &rank_send_ids, DRaggedRightArrayKokkos &rank_recv_ids){ - - this->send_indices_ = rank_send_ids; // indices of element data to send to each rank - this->recv_indices_ = rank_recv_ids; // indices of element data to receive from each rank + void setup_send_recv(DRaggedRightArrayKokkos& rank_send_ids, DRaggedRightArrayKokkos& rank_recv_ids) { + this->send_indices_ = rank_send_ids; // indices of element data to send to each rank + this->recv_indices_ = rank_recv_ids; // indices of element data to receive from each rank // Setup send data - this->send_counts_ = DCArrayKokkos(num_send_ranks, "send_counts"); + this->send_counts_ = DCArrayKokkos(num_send_ranks, "send_counts"); this->total_send_count = 0; - for(int i = 0; i < num_send_ranks; i++){ + for (int i = 0; i < num_send_ranks; i++) { this->send_counts_.host(i) = rank_send_ids.stride_host(i); this->total_send_count += this->send_counts_.host(i); } this->send_counts_.update_device(); this->send_displs_ = DCArrayKokkos(num_send_ranks, "send_displs"); - for(int i = 0; i < num_send_ranks; i++){ + for (int i = 0; i < num_send_ranks; i++) { this->send_displs_.host(i) = 0; - for(int j = 0; j < i; j++){ + for (int j = 0; j < i; j++) { this->send_displs_.host(i) += this->send_counts_.host(j); } } this->send_displs_.update_device(); // Setup recv data - this->recv_counts_ = DCArrayKokkos(num_recv_ranks, "recv_counts"); + this->recv_counts_ = DCArrayKokkos(num_recv_ranks, "recv_counts"); this->total_recv_count = 0; - for(int i = 0; i < num_recv_ranks; i++){ + for (int i = 0; i < num_recv_ranks; i++) { this->recv_counts_.host(i) = rank_recv_ids.stride_host(i); this->total_recv_count += this->recv_counts_.host(i); } this->recv_counts_.update_device(); this->recv_displs_ = DCArrayKokkos(num_recv_ranks, "recv_displs"); - for(int i = 0; i < num_recv_ranks; i++){ + for (int i = 0; i < num_recv_ranks; i++) { this->recv_displs_.host(i) = 0; - for(int j = 0; j < i; j++){ + for (int j = 0; j < i; j++) { this->recv_displs_.host(i) += this->recv_counts_.host(j); } } @@ -385,9 +386,8 @@ struct CommunicationPlan { } // Useful function for debugging, possibly remove - void verify_send_recv(){ - - if(!has_comm_graph){ + void verify_send_recv() { + if (!has_comm_graph) { throw std::runtime_error("Graph communicator has not been initialized"); } @@ -402,15 +402,15 @@ struct CommunicationPlan { // Verify send counts and displacements int computed_total_send = 0; - for(int i = 0; i < num_send_ranks; i++){ + for (int i = 0; i < num_send_ranks; i++) { computed_total_send += send_counts_.host(i); - + // Verify displacements are consistent int expected_displs = 0; - for(int j = 0; j < i; j++){ + for (int j = 0; j < i; j++) { expected_displs += send_counts_.host(j); } - if(send_displs_.host(i) != expected_displs){ + if (send_displs_.host(i) != expected_displs) { std::cerr << "[rank " << rank << "] ERROR: send_displs[" << i << "] mismatch! " << "Expected " << expected_displs << ", got " << send_displs_.host(i) << std::endl; local_verification_passed = false; @@ -418,7 +418,7 @@ struct CommunicationPlan { } // Verify total send count - if(computed_total_send != total_send_count){ + if (computed_total_send != total_send_count) { std::cerr << "[rank " << rank << "] ERROR: total_send_count mismatch! " << "Expected " << computed_total_send << ", got " << total_send_count << std::endl; local_verification_passed = false; @@ -426,15 +426,15 @@ struct CommunicationPlan { // Verify recv counts and displacements int computed_total_recv = 0; - for(int i = 0; i < num_recv_ranks; i++){ + for (int i = 0; i < num_recv_ranks; i++) { computed_total_recv += recv_counts_.host(i); - + // Verify displacements are consistent int expected_displs = 0; - for(int j = 0; j < i; j++){ + for (int j = 0; j < i; j++) { expected_displs += recv_counts_.host(j); } - if(recv_displs_.host(i) != expected_displs){ + if (recv_displs_.host(i) != expected_displs) { std::cerr << "[rank " << rank << "] ERROR: recv_displs[" << i << "] mismatch! " << "Expected " << expected_displs << ", got " << recv_displs_.host(i) << std::endl; local_verification_passed = false; @@ -442,31 +442,29 @@ struct CommunicationPlan { } // Verify total recv count - if(computed_total_recv != total_recv_count){ + if (computed_total_recv != total_recv_count) { std::cerr << "[rank " << rank << "] ERROR: total_recv_count mismatch! " << "Expected " << computed_total_recv << ", got " << total_recv_count << std::endl; local_verification_passed = false; } // Verify send indices are within bounds (basic sanity check) - for(int i = 0; i < num_send_ranks; i++){ - for(int j = 0; j < send_indices_.stride_host(i); j++){ + for (int i = 0; i < num_send_ranks; i++) { + for (int j = 0; j < send_indices_.stride_host(i); j++) { int idx = send_indices_.host(i, j); - if(idx < 0){ - std::cerr << "[rank " << rank << "] ERROR: negative send index at rank " << i - << ", index " << j << ": " << idx << std::endl; + if (idx < 0) { + std::cerr << "[rank " << rank << "] ERROR: negative send index at rank " << i << ", index " << j << ": " << idx << std::endl; local_verification_passed = false; } } } // Verify recv indices are within bounds (basic sanity check) - for(int i = 0; i < num_recv_ranks; i++){ - for(int j = 0; j < recv_indices_.stride_host(i); j++){ + for (int i = 0; i < num_recv_ranks; i++) { + for (int j = 0; j < recv_indices_.stride_host(i); j++) { int idx = recv_indices_.host(i, j); - if(idx < 0){ - std::cerr << "[rank " << rank << "] ERROR: negative recv index at rank " << i - << ", index " << j << ": " << idx << std::endl; + if (idx < 0) { + std::cerr << "[rank " << rank << "] ERROR: negative recv index at rank " << i << ", index " << j << ": " << idx << std::endl; local_verification_passed = false; } } @@ -479,7 +477,7 @@ struct CommunicationPlan { MPI_Barrier(mpi_comm_world); if (rank == r) { std::cout << "\n[rank " << rank << "] Send/Recv Communication Plan Verification:" << std::endl; - + std::cout << " Send Configuration:" << std::endl; std::cout << " - Num send ranks: " << num_send_ranks << std::endl; std::cout << " - Total send count: " << total_send_count << std::endl; @@ -493,7 +491,7 @@ struct CommunicationPlan { std::cout << send_displs_.host(i) << " "; } std::cout << std::endl; - + std::cout << " Recv Configuration:" << std::endl; std::cout << " - Num recv ranks: " << num_recv_ranks << std::endl; std::cout << " - Total recv count: " << total_recv_count << std::endl; @@ -514,7 +512,7 @@ struct CommunicationPlan { // ============================================================================ // Global Verification: Use MPI to verify consistency across ranks // ============================================================================ - int local_passed = local_verification_passed ? 1 : 0; + int local_passed = local_verification_passed ? 1 : 0; int global_passed = 0; MPI_Allreduce(&local_passed, &global_passed, 1, MPI_INT, MPI_MIN, mpi_comm_world); MPI_Barrier(mpi_comm_world); @@ -528,15 +526,13 @@ struct CommunicationPlan { } MPI_Barrier(mpi_comm_world); - if(!global_passed){ + if (!global_passed) { throw std::runtime_error("Send/Recv communication plan verification failed"); } } -}; // End of CommunicationPlan - -} // end namespace mtr - -#endif // end if HAVE_MPI -#endif // end if COMMUNICATION_PLAN_H +}; // End of CommunicationPlan +} // end namespace mtr +#endif // end if HAVE_MPI +#endif // end if COMMUNICATION_PLAN_H diff --git a/src/include/host_types.h b/src/include/host_types.h index 9dac6416..d3a176e3 100644 --- a/src/include/host_types.h +++ b/src/include/host_types.h @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -38,245 +38,170 @@ **********************************************************************************************/ #include #include -#include -#include -#include // for shared_ptr - -//To disable asserts, uncomment the following line -//#define NDEBUG +#include +#include // for shared_ptr +#include -namespace mtr -{ +// To disable asserts, uncomment the following line +// #define NDEBUG +namespace mtr { //---Begin Standard Data Structures--- -//1. FArray -// indicies are [0:N-1] +// 1. FArray +// indicies are [0:N-1] template class FArray { - private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) - std::shared_ptr array_; - + std::shared_ptr array_; + public: - // default constructor - FArray (); - - //overload constructors from 1D to 7D - - FArray(size_t dim0); - - FArray(size_t dim0, - size_t dim1); - - FArray(size_t dim0, - size_t dim1, - size_t dim2); - - FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3); - - FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - FArray (const FArray& temp); - + FArray(); + + // overload constructors from 1D to 7D + + FArray(size_t dim0); + + FArray(size_t dim0, size_t dim1); + + FArray(size_t dim0, size_t dim1, size_t dim2); + + FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3); + + FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + FArray(const FArray& temp); + // overload operator() to access data as array(i,....,n); T& operator()(size_t i) const; - - T& operator()(size_t i, - size_t j) const; - - T& operator()(size_t i, - size_t j, - size_t k) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - - //overload = operator + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + // overload = operator FArray& operator=(const FArray& temp); - - //return array size + + // return array size size_t size() const; // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; - - //return pointer + + // return pointer T* pointer() const; // set values to input void set_values(T val); - + // deconstructor - ~FArray (); - -}; // end of f_array_t + ~FArray(); + +}; // end of f_array_t //---FArray class definnitions---- -//constructors +// constructors template -FArray::FArray(){ - array_ = NULL; +FArray::FArray() { + array_ = NULL; length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; } } -//1D +// 1D template -FArray::FArray(size_t dim0) -{ +FArray::FArray(size_t dim0) { dims_[0] = dim0; - length_ = dim0; - order_ = 1; - array_ = std::shared_ptr (new T[length_]); + length_ = dim0; + order_ = 1; + array_ = std::shared_ptr(new T[length_]); } template -FArray::FArray(size_t dim0, - size_t dim1) -{ +FArray::FArray(size_t dim0, size_t dim1) { dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = dim0*dim1; - array_ = std::shared_ptr (new T[length_]); + order_ = 2; + length_ = dim0 * dim1; + array_ = std::shared_ptr(new T[length_]); } -//3D +// 3D template -FArray::FArray(size_t dim0, - size_t dim1, - size_t dim2) -{ +FArray::FArray(size_t dim0, size_t dim1, size_t dim2) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = dim0*dim1*dim2; - array_ = std::shared_ptr (new T[length_]); + order_ = 3; + length_ = dim0 * dim1 * dim2; + array_ = std::shared_ptr(new T[length_]); } -//4D +// 4D template -FArray::FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3) -{ +FArray::FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = dim0*dim1*dim2*dim3; - array_ = std::shared_ptr (new T[length_]); + order_ = 4; + length_ = dim0 * dim1 * dim2 * dim3; + array_ = std::shared_ptr(new T[length_]); } -//5D +// 5D template -FArray::FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +FArray::FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = dim0*dim1*dim2*dim3*dim4; - array_ = std::shared_ptr (new T[length_]); + order_ = 5; + length_ = dim0 * dim1 * dim2 * dim3 * dim4; + array_ = std::shared_ptr(new T[length_]); } -//6D +// 6D template -FArray::FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +FArray::FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = dim0*dim1*dim2*dim3*dim4*dim5; - array_ = std::shared_ptr (new T[length_]); + order_ = 6; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; + array_ = std::shared_ptr(new T[length_]); } - -//7D +// 7D template -FArray::FArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +FArray::FArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -284,114 +209,85 @@ FArray::FArray(size_t dim0, dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = dim0*dim1*dim2*dim3*dim4*dim5*dim6; - array_ = std::shared_ptr (new T[length_]); - + order_ = 7; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + array_ = std::shared_ptr(new T[length_]); } -//Copy constructor +// Copy constructor template FArray::FArray(const FArray& temp) { - // Do nothing if the assignment is of the form x = x - + if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for - + } // end for + order_ = temp.order_; length_ = temp.length_; - array_ = temp.array_; - } // end if - -} // end constructor + array_ = temp.array_; + } // end if -//overload operator () for 1D to 7D -//indices are from [0:N-1] +} // end constructor -//1D +// overload operator () for 1D to 7D +// indices are from [0:N-1] + +// 1D template -T& FArray::operator()(size_t i) const -{ +T& FArray::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in FArray 1D!"); assert(i < dims_[0] && "i is out of bounds in FArray 1D!"); return array_[i]; } -//2D +// 2D template -T& FArray::operator()(size_t i, - size_t j) const -{ +T& FArray::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in FArray 2D!"); assert(i < dims_[0] && "i is out of bounds in FArray 2D!"); assert(j < dims_[1] && "j is out of bounds in FArray 2D!"); - return array_[i + j*dims_[0]]; + return array_[i + j * dims_[0]]; } -//3D +// 3D template -T& FArray::operator()(size_t i, - size_t j, - size_t k) const -{ +T& FArray::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in FArray 3D!"); assert(i < dims_[0] && "i is out of bounds in FArray 3D!"); assert(j < dims_[1] && "j is out of bounds in Farray 3D!"); assert(k < dims_[2] && "k is out of bounds in FArray 3D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1]]; } -//4D +// 4D template -T& FArray::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +T& FArray::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in FArray 4D!"); assert(i < dims_[0] && "i is out of bounds in FArray 4D!"); assert(j < dims_[1] && "j is out of bounds in FArray 4D!"); assert(k < dims_[2] && "k is out of bounds in FArray 4D!"); assert(l < dims_[3] && "l is out of bounds in FArray 4D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2]]; } -//5D +// 5D template -T& FArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +T& FArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in FArray 5D!"); assert(i < dims_[0] && "i is out of bounds in FArray 5D!"); assert(j < dims_[1] && "j is out of bounds in FArray 5D!"); assert(k < dims_[2] && "k is out of bounds in FArray 5D!"); assert(l < dims_[3] && "l is out of bounds in FArray 5D!"); assert(m < dims_[4] && "m is out of bounds in FArray 5D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3]]; } -//6D +// 6D template -T& FArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +T& FArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in FArray 6D!"); assert(i < dims_[0] && "i is out of bounds in FArray 6D!"); assert(j < dims_[1] && "j is out of bounds in FArray 6D!"); @@ -399,23 +295,13 @@ T& FArray::operator()(size_t i, assert(l < dims_[3] && "l is out of bounds in FArray 6D!"); assert(m < dims_[4] && "m is out of bounds in FArray 6D!"); assert(n < dims_[5] && "n is out of bounds in FArray 6D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3] - + n*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4]]; -} - -//7D -template -T& FArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3] + + n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]]; +} + +// 7D +template +T& FArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in FArray 7D!"); assert(i < dims_[0] && "i is out of bounds in FArray 7D!"); assert(j < dims_[1] && "j is out of bounds in FArray 7D!"); @@ -424,23 +310,18 @@ T& FArray::operator()(size_t i, assert(m < dims_[4] && "m is out of bounds in FArray 7D!"); assert(n < dims_[5] && "n is out of bounds in FArray 7D!"); assert(o < dims_[6] && "o is out of bounds in FArray 7D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3] - + n*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4] - + o*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4]*dims_[5]]; -} - + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3] + + n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] + o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5]]; +} + // = operator -//THIS = FArray <> TEMP(n,m,...) +// THIS = FArray <> TEMP(n,m,...) template -FArray& FArray::operator= (const FArray& temp) -{ - if(this != & temp) { - for (int iter = 0; iter < temp.order_; iter++){ +FArray& FArray::operator=(const FArray& temp) { + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for order_ = temp.order_; length_ = temp.length_; @@ -457,7 +338,7 @@ inline size_t FArray::size() const { template inline size_t FArray::dims(size_t i) const { assert(i < order_ && "FArray order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to FArray dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to FArray dims is out of bounds!"); return dims_[i]; } @@ -466,132 +347,77 @@ inline size_t FArray::order() const { return order_; } - template inline T* FArray::pointer() const { return array_.get(); } - template void FArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } - -//delete FArray +// delete FArray template -FArray::~FArray(){} +FArray::~FArray() {} //---end of FArray class definitions---- - -//2. ViewFArray -// indicies are [0:N-1] +// 2. ViewFArray +// indicies are [0:N-1] template class ViewFArray { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - T * array_; - + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + T* array_; + public: - // default constructor - ViewFArray (); + ViewFArray(); //---1D to 7D array --- - ViewFArray(T *array, - size_t dim0); - - ViewFArray (T *array, - size_t dim0, - size_t dim1); - - ViewFArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2); - - ViewFArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3); - - ViewFArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - ViewFArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - ViewFArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - + ViewFArray(T* array, size_t dim0); + + ViewFArray(T* array, size_t dim0, size_t dim1); + + ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2); + + ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3); + + ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + T& operator()(size_t i) const; - - T& operator()(size_t i, - size_t j) const; - - T& operator()(size_t i, - size_t j, - size_t k) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + // calculate C = math(A,B) template void operator=(M do_this_math); - - //return array size + + // return array size size_t size() const; - - //return array dims + + // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; @@ -600,130 +426,95 @@ class ViewFArray { // return pointer T* pointer() const; - -}; // end of viewFArray -//class definitions for viewFArray +}; // end of viewFArray + +// class definitions for viewFArray //~~~~constructors for viewFArray for 1D to 7D~~~~~~~ -//no dimension +// no dimension template -ViewFArray::ViewFArray(){ - array_ = NULL; - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - } +ViewFArray::ViewFArray() { + array_ = NULL; + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + } } -//1D +// 1D template -ViewFArray::ViewFArray(T *array, - size_t dim0) -{ +ViewFArray::ViewFArray(T* array, size_t dim0) { dims_[0] = dim0; - order_ = 1; - length_ = dim0; - array_ = array; + order_ = 1; + length_ = dim0; + array_ = array; } -//2D +// 2D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1) { dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = dim0*dim1; - array_ = array; + order_ = 2; + length_ = dim0 * dim1; + array_ = array; } -//3D +// 3D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = dim0*dim1*dim2; - array_ = array; + order_ = 3; + length_ = dim0 * dim1 * dim2; + array_ = array; } -//4D +// 4D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = dim0*dim1*dim2*dim3; - array_ = array; + order_ = 4; + length_ = dim0 * dim1 * dim2 * dim3; + array_ = array; } -//5D +// 5D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = dim0*dim1*dim2*dim3*dim4; - array_ = array; + order_ = 5; + length_ = dim0 * dim1 * dim2 * dim3 * dim4; + array_ = array; } -//6D +// 6D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = dim0*dim1*dim2*dim3*dim4*dim5; - array_ = array; + order_ = 6; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; + array_ = array; } -//7D +// 7D template -ViewFArray::ViewFArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +ViewFArray::ViewFArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -731,95 +522,68 @@ ViewFArray::ViewFArray(T *array, dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = dim0*dim1*dim2*dim3*dim4*dim5*dim6; - array_ = array; + order_ = 7; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + array_ = array; } //~~~~~~operator () overload -//for dimensions 1D to 7D -//indices for array are from 0...N-1 +// for dimensions 1D to 7D +// indices for array are from 0...N-1 -//1D +// 1D template -T& ViewFArray::operator()(size_t i) const -{ +T& ViewFArray::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewFArray 1D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 1D!"); return array_[i]; } -//2D +// 2D template -T& ViewFArray::operator()(size_t i, - size_t j) const -{ +T& ViewFArray::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewFArray 2D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 2D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 2D!"); - return array_[i + j*dims_[0]]; + return array_[i + j * dims_[0]]; } -//3D +// 3D template -T& ViewFArray::operator()(size_t i, - size_t j, - size_t k) const -{ +T& ViewFArray::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewFArray 3D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 3D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 3D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArray 3D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1]]; } -//4D +// 4D template -T& ViewFArray::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +T& ViewFArray::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewFArray 4D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 4D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 4D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArray 4D!"); assert(l < dims_[3] && "l is out of bounds in ViewFArray 4D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2]]; } -//5D +// 5D template -T& ViewFArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +T& ViewFArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewFArray 5D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 5D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 5D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArray 5D!"); assert(l < dims_[3] && "l is out of bounds in ViewFArray 5D!"); assert(m < dims_[4] && "m is out of bounds in ViewFArray 5D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3]]; } -//6D +// 6D template -T& ViewFArray:: operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +T& ViewFArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewFArray 6D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 6D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 6D!"); @@ -827,23 +591,13 @@ T& ViewFArray:: operator()(size_t i, assert(l < dims_[3] && "l is out of bounds in ViewFArray 6D!"); assert(m < dims_[4] && "m is out of bounds in ViewFArray 6D!"); assert(n < dims_[5] && "n is out of bounds in ViewFArray 6D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3] - + n*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4]]; -} - -//7D -template -T& ViewFArray:: operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3] + + n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]]; +} + +// 7D +template +T& ViewFArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewFArray 7D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArray 7D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArray 7D!"); @@ -852,25 +606,21 @@ T& ViewFArray:: operator()(size_t i, assert(m < dims_[4] && "m is out of bounds in ViewFArray 7D!"); assert(n < dims_[5] && "n is out of bounds in ViewFArray 7D!"); assert(o < dims_[6] && "n is out of bounds in ViewFArray 7D!"); - return array_[i + j*dims_[0] - + k*dims_[0]*dims_[1] - + l*dims_[0]*dims_[1]*dims_[2] - + m*dims_[0]*dims_[1]*dims_[2]*dims_[3] - + n*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4] - + o*dims_[0]*dims_[1]*dims_[2]*dims_[3]*dims_[4]*dims_[5]]; + return array_[i + j * dims_[0] + k * dims_[0] * dims_[1] + l * dims_[0] * dims_[1] * dims_[2] + m * dims_[0] * dims_[1] * dims_[2] * dims_[3] + + n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] + o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5]]; } // calculate this ViewFArray object = math(A,B) template template -void ViewFArray::operator=(M do_this_math){ - do_this_math(*this); // pass in this ViewFArray object -}// end of math opperation +void ViewFArray::operator=(M do_this_math) { + do_this_math(*this); // pass in this ViewFArray object +} // end of math opperation template inline size_t ViewFArray::dims(size_t i) const { assert(i < order_ && "ViewFArray order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewFArray dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewFArray dims is out of bounds!"); return dims_[i]; } @@ -891,102 +641,58 @@ inline T* ViewFArray::pointer() const { template void ViewFArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } //---end of ViewFArray class definitions--- - -//3. FMatrix -// indicies are [1:N] +// 3. FMatrix +// indicies are [1:N] template class FMatrix { private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - std::shared_ptr matrix_; + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + std::shared_ptr matrix_; public: // Default constructor - FMatrix (); + FMatrix(); //---1D to 7D matrix --- - FMatrix (size_t dim1); - - FMatrix (size_t dim1, - size_t dim2); - - FMatrix (size_t dim1, - size_t dim2, - size_t dim3); - - FMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - FMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - FMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - FMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7); - - FMatrix (const FMatrix& temp); - - T& operator() (size_t i) const; - - T& operator() (size_t i, - size_t j) const; - - T& operator() (size_t i, - size_t j, - size_t k) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - - + FMatrix(size_t dim1); + + FMatrix(size_t dim1, size_t dim2); + + FMatrix(size_t dim1, size_t dim2, size_t dim3); + + FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7); + + FMatrix(const FMatrix& temp); + + T& operator()(size_t i) const; + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + // Overload copy assignment operator FMatrix& operator=(const FMatrix& temp); @@ -995,26 +701,26 @@ class FMatrix { // matrix dims size_t dims(size_t i) const; - + // return matrix order (rank) size_t order() const; - - //return pointer + + // return pointer T* pointer() const; // set values to input void set_values(T val); // Deconstructor - ~FMatrix (); + ~FMatrix(); -}; // End of FMatrix +}; // End of FMatrix //---FMatrix class definitions--- -//constructors +// constructors template -FMatrix::FMatrix(){ +FMatrix::FMatrix() { matrix_ = NULL; length_ = order_ = 0; for (int i = 0; i < 7; i++) { @@ -1022,106 +728,77 @@ FMatrix::FMatrix(){ } } -//1D +// 1D template -FMatrix::FMatrix(size_t dim1) -{ +FMatrix::FMatrix(size_t dim1) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 1; + length_ = dim1; + matrix_ = std::shared_ptr(new T[length_]); } -//2D +// 2D template -FMatrix::FMatrix(size_t dim1, - size_t dim2) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = dim1 * dim2; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 2; + length_ = dim1 * dim2; + matrix_ = std::shared_ptr(new T[length_]); } -//3D +// 3D template -FMatrix::FMatrix(size_t dim1, - size_t dim2, - size_t dim3) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = dim1 * dim2 * dim3; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 3; + length_ = dim1 * dim2 * dim3; + matrix_ = std::shared_ptr(new T[length_]); } -//4D +// 4D template -FMatrix::FMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = dim1 * dim2 * dim3 * dim4; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 4; + length_ = dim1 * dim2 * dim3 * dim4; + matrix_ = std::shared_ptr(new T[length_]); } -//5D +// 5D template -FMatrix::FMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = dim1 * dim2 * dim3 * dim4 * dim5; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 5; + length_ = dim1 * dim2 * dim3 * dim4 * dim5; + matrix_ = std::shared_ptr(new T[length_]); } -//6D +// 6D template -FMatrix::FMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - matrix_ = std::shared_ptr (new T[length_]); - + order_ = 6; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + matrix_ = std::shared_ptr(new T[length_]); } template -FMatrix::FMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7) -{ +FMatrix::FMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -1129,112 +806,83 @@ FMatrix::FMatrix(size_t dim1, dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; - matrix_ = std::shared_ptr (new T[length_]); - + order_ = 7; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; + matrix_ = std::shared_ptr(new T[length_]); } template FMatrix::FMatrix(const FMatrix& temp) { - // Do nothing if the assignment is of the form x = x - + if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for - + } // end for + order_ = temp.order_; length_ = temp.length_; matrix_ = temp.matrix_; - } // end if - -} // end constructor + } // end if +} // end constructor -//overload operators +// overload operators -//1D +// 1D template -inline T& FMatrix::operator() (size_t i) const -{ +inline T& FMatrix::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in FMatrix 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 1D!"); return matrix_[i - 1]; } -//2D +// 2D template -inline T& FMatrix::operator() (size_t i, - size_t j) const -{ +inline T& FMatrix::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in FMatrix 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 2D!"); return matrix_[(i - 1) + ((j - 1) * dims_[0])]; } -//3D +// 3D template -inline T& FMatrix::operator() (size_t i, - size_t j, - size_t k) const -{ +inline T& FMatrix::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in FMatrix 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrix 3D!"); - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])]; + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])]; } -//4D +// 4D template -inline T& FMatrix::operator() (size_t i, - size_t j, - size_t k, - size_t l) const -{ +inline T& FMatrix::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in FMatrix 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrix 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrix 4D!"); - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; } -//5D +// 5D template -inline T& FMatrix::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +inline T& FMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in FMatrix 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrix 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrix 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrix 5D!"); - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; } -//6D +// 6D template -inline T& FMatrix::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +inline T& FMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in FMatrix 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 6D!"); @@ -1242,23 +890,13 @@ inline T& FMatrix::operator() (size_t i, assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrix 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrix 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in FMatrix 6D!"); - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; -} - -//7D -template -inline T& FMatrix::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; +} + +// 7D +template +inline T& FMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in FMatrix 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrix 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrix 7D!"); @@ -1267,29 +905,24 @@ inline T& FMatrix::operator() (size_t i, assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrix 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in FMatrix 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in FMatrix 7D!"); - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; } - template -inline FMatrix& FMatrix::operator= (const FMatrix& temp) -{ +inline FMatrix& FMatrix::operator=(const FMatrix& temp) { // Do nothing if assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for order_ = temp.order_; length_ = temp.length_; - matrix_ = temp.matrix_; + matrix_ = temp.matrix_; } - + return *this; } @@ -1300,9 +933,9 @@ inline size_t FMatrix::size() const { template inline size_t FMatrix::dims(size_t i) const { - i--; // i starts at 1 + i--; // i starts at 1 assert(i < order_ && "FMatrix order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to FMatrix dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to FMatrix dims is out of bounds!"); return dims_[i]; } @@ -1312,13 +945,13 @@ inline size_t FMatrix::order() const { } template -inline T* FMatrix::pointer() const{ +inline T* FMatrix::pointer() const { return matrix_.get(); } template void FMatrix::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { matrix_[i] = val; } } @@ -1328,112 +961,60 @@ FMatrix::~FMatrix() {} //----end of FMatrix class definitions---- - -//4. ViewFMatrix -// indices are [1:N] +// 4. ViewFMatrix +// indices are [1:N] template class ViewFMatrix { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - T * matrix_; - + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + T* matrix_; + public: - // Default constructor - ViewFMatrix (); - + ViewFMatrix(); + //--- 1D to 7D matrix --- - ViewFMatrix(T *matrix, - size_t dim1); - - ViewFMatrix(T *some_matrix, - size_t dim1, - size_t dim2); - - ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3); - - ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - ViewFMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - ViewFMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - ViewFMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7); - + ViewFMatrix(T* matrix, size_t dim1); + + ViewFMatrix(T* some_matrix, size_t dim1, size_t dim2); + + ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3); + + ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7); + T& operator()(size_t i) const; - - T& operator()(size_t i, - size_t j) const; - - T& operator()(size_t i, - size_t j, - size_t k) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + // calculate C = math(A,B) template void operator=(M do_this_math); - + // length of 1D array size_t size() const; - + // matrix dims size_t dims(size_t i) const; - + // return matrix order (rank) size_t order() const; @@ -1442,128 +1023,93 @@ class ViewFMatrix { // return pointer T* pointer() const; - -}; // end of ViewFMatrix -//constructors +}; // end of ViewFMatrix + +// constructors -//no dimension +// no dimension template ViewFMatrix::ViewFMatrix() { - matrix_ = NULL; - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - } + matrix_ = NULL; + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + } } -//1D +// 1D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; - matrix_ = matrix; + order_ = 1; + length_ = dim1; + matrix_ = matrix; } -//2D +// 2D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = dim1 * dim2; - matrix_ = matrix; + order_ = 2; + length_ = dim1 * dim2; + matrix_ = matrix; } -//3D +// 3D template -ViewFMatrix::ViewFMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = dim1 * dim2 * dim3; - matrix_ = matrix; + order_ = 3; + length_ = dim1 * dim2 * dim3; + matrix_ = matrix; } -//4D +// 4D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = dim1 * dim2 * dim3 * dim4; - matrix_ = matrix; + order_ = 4; + length_ = dim1 * dim2 * dim3 * dim4; + matrix_ = matrix; } -//5D +// 5D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = dim1 * dim2 * dim3 * dim4 * dim5; - matrix_ = matrix; + order_ = 5; + length_ = dim1 * dim2 * dim3 * dim4 * dim5; + matrix_ = matrix; } -//6D +// 6D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - matrix_ = matrix; + order_ = 6; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + matrix_ = matrix; } -//6D +// 6D template -ViewFMatrix::ViewFMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7) -{ +ViewFMatrix::ViewFMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -1571,99 +1117,72 @@ ViewFMatrix::ViewFMatrix(T *matrix, dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; - matrix_ = matrix; + order_ = 7; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; + matrix_ = matrix; } +// overload operator () -//overload operator () - -//1D +// 1D template -inline T& ViewFMatrix::operator()(size_t i) const -{ +inline T& ViewFMatrix::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewFMatrix 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 1D"); // die if >= dim1 - + return matrix_[(i - 1)]; } -//2D +// 2D template -inline T& ViewFMatrix::operator()(size_t i, - size_t j) const -{ +inline T& ViewFMatrix::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewFMatrix 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 2D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 2D"); // die if >= dim2 - + return matrix_[(i - 1) + ((j - 1) * dims_[0])]; } -//3D +// 3D template -inline T& ViewFMatrix::operator()(size_t i, - size_t j, - size_t k) const -{ +inline T& ViewFMatrix::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewFMatrix 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 3D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 3D"); // die if >= dim2 assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrix 3D"); // die if >= dim3 - - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])]; + + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])]; } -//4D +// 4D template -inline T& ViewFMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +inline T& ViewFMatrix::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewFMatrix 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 4D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 4D"); // die if >= dim2 assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrix 4D"); // die if >= dim3 assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrix 4D"); // die if >= dim4 - - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; + + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; } -//5D +// 5D template -inline T& ViewFMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +inline T& ViewFMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewFMatrix 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 5D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 5D"); // die if >= dim2 assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrix 5D"); // die if >= dim3 assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrix 5D"); // die if >= dim4 assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrix 5D"); // die if >= dim5 - - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; + + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; } -//6D +// 6D template -inline T& ViewFMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +inline T& ViewFMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewFMatrix 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 6D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 6D"); // die if >= dim2 @@ -1671,23 +1190,13 @@ inline T& ViewFMatrix::operator()(size_t i, assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrix 6D"); // die if >= dim4 assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrix 6D"); // die if >= dim5 assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewFMatrix 6D"); // die if >= dim6 - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; -} - -//6D -template -inline T& ViewFMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; +} + +// 6D +template +inline T& ViewFMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewFMatrix 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrix 7D"); // die if >= dim1 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrix 7D"); // die if >= dim2 @@ -1696,27 +1205,24 @@ inline T& ViewFMatrix::operator()(size_t i, assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrix 7D"); // die if >= dim5 assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewFMatrix 7D"); // die if >= dim6 assert(o >= 1 && o <= dims_[6] && "o is out of bounds in ViewFMatrix 7D"); // die if >= dim7 - - return matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; + + return matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; } // calculate this ViewFMatrix object = math(A,B) template template -void ViewFMatrix::operator=(M do_this_math){ - do_this_math(*this); // pass in this ViewFArray object -}// end of math opperation +void ViewFMatrix::operator=(M do_this_math) { + do_this_math(*this); // pass in this ViewFArray object +} // end of math opperation template inline size_t ViewFMatrix::dims(size_t i) const { - i--; // i starts at 1 + i--; // i starts at 1 assert(i < order_ && "ViewFMatrix order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewFMatrix dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewFMatrix dims is out of bounds!"); return dims_[i]; } @@ -1732,238 +1238,169 @@ inline T* ViewFMatrix::pointer() const { template void ViewFMatrix::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { matrix_[i] = val; } } //-----end ViewFMatrix----- - -//5. CArray -// indicies are [0:N-1] +// 5. CArray +// indicies are [0:N-1] template class CArray { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - std::shared_ptr array_; + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + std::shared_ptr array_; public: // Default constructor - CArray (); + CArray(); // --- 1D to 7D array --- - - CArray (size_t dim0); - - CArray (size_t dim0, - size_t dim1); - - CArray (size_t dim0, - size_t dim1, - size_t dim2); - - CArray (size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3); - - CArray (size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - CArray (size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - CArray (size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - CArray (const CArray& temp); - + + CArray(size_t dim0); + + CArray(size_t dim0, size_t dim1); + + CArray(size_t dim0, size_t dim1, size_t dim2); + + CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3); + + CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + CArray(const CArray& temp); + // Overload operator() - T& operator() (size_t i) const; - - T& operator() (size_t i, - size_t j) const; - - T& operator() (size_t i, - size_t j, - size_t k) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - + T& operator()(size_t i) const; + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + // Overload copy assignment operator - CArray& operator= (const CArray& temp); + CArray& operator=(const CArray& temp); - //return array size + // return array size size_t size() const; // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; - - //return pointer + + // return pointer T* pointer() const; // set values to input void set_values(T val); // Deconstructor - ~CArray (); + ~CArray(); -}; // End of CArray +}; // End of CArray //---carray class declarations--- -//constructors +// constructors -//no dim +// no dim template CArray::CArray() { - array_ = NULL; + array_ = NULL; length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; } } -//1D +// 1D template -CArray::CArray(size_t dim0) -{ +CArray::CArray(size_t dim0) { dims_[0] = dim0; - order_ = 1; - length_ = dim0; - array_ = std::shared_ptr (new T[length_]); + order_ = 1; + length_ = dim0; + array_ = std::shared_ptr(new T[length_]); } -//2D +// 2D template -CArray::CArray(size_t dim0, - size_t dim1) -{ +CArray::CArray(size_t dim0, size_t dim1) { dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = dim0 * dim1; - array_ = std::shared_ptr (new T[length_]); + order_ = 2; + length_ = dim0 * dim1; + array_ = std::shared_ptr(new T[length_]); } -//3D +// 3D template -CArray::CArray(size_t dim0, - size_t dim1, - size_t dim2) -{ +CArray::CArray(size_t dim0, size_t dim1, size_t dim2) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = dim0 * dim1 * dim2; - array_ = std::shared_ptr (new T[length_]); + order_ = 3; + length_ = dim0 * dim1 * dim2; + array_ = std::shared_ptr(new T[length_]); } -//4D +// 4D template -CArray::CArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3) -{ +CArray::CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = dim0 * dim1 * dim2 * dim3; - array_ = std::shared_ptr (new T[length_]); + order_ = 4; + length_ = dim0 * dim1 * dim2 * dim3; + array_ = std::shared_ptr(new T[length_]); } -//5D +// 5D template -CArray::CArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) { +CArray::CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = dim0 * dim1 * dim2 * dim3 * dim4; - array_ = std::shared_ptr (new T[length_]); + order_ = 5; + length_ = dim0 * dim1 * dim2 * dim3 * dim4; + array_ = std::shared_ptr(new T[length_]); } -//6D +// 6D template -CArray::CArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) { +CArray::CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; - array_ = std::shared_ptr (new T[length_]); + order_ = 6; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; + array_ = std::shared_ptr(new T[length_]); } -//7D +// 7D template -CArray::CArray(size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) { +CArray::CArray(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -1971,118 +1408,90 @@ CArray::CArray(size_t dim0, dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - array_ = std::shared_ptr (new T[length_]); + order_ = 7; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + array_ = std::shared_ptr(new T[length_]); } -//Copy constructor +// Copy constructor template CArray::CArray(const CArray& temp) { - // Do nothing if the assignment is of the form x = x - + if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for - + } // end for + order_ = temp.order_; length_ = temp.length_; - array_ = temp.array_; - } // end if - -} // end constructor + array_ = temp.array_; + } // end if +} // end constructor -//overload () operator +// overload () operator -//1D +// 1D template -inline T& CArray::operator() (size_t i) const -{ +inline T& CArray::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in CArray 1D!"); assert(i < dims_[0] && "i is out of bounds in CArray 1D!"); return array_[i]; } -//2D +// 2D template -inline T& CArray::operator() (size_t i, - size_t j) const -{ +inline T& CArray::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in CArray 2D!"); assert(i < dims_[0] && "i is out of bounds in CArray 2D!"); assert(j < dims_[1] && "j is out of bounds in CArray 2D!"); - - return array_[j + (i * dims_[1])]; + + return array_[j + (i * dims_[1])]; } -//3D +// 3D template -inline T& CArray::operator() (size_t i, - size_t j, - size_t k) const -{ +inline T& CArray::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in CArray 3D!"); assert(i < dims_[0] && "i is out of bounds in CArray 3D!"); assert(j < dims_[1] && "j is out of bounds in Carray 3D!"); assert(k < dims_[2] && "k is out of bounds in CArray 3D!"); - - return array_[k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])]; + + return array_[k + (j * dims_[2]) + (i * dims_[2] * dims_[1])]; } -//4D +// 4D template -inline T& CArray::operator() (size_t i, - size_t j, - size_t k, - size_t l) const -{ +inline T& CArray::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in CArray 4D!"); assert(i < dims_[0] && "i is out of bounds in CArray 4D"); // die if >= dim0 assert(j < dims_[1] && "j is out of bounds in CArray 4D"); // die if >= dim1 assert(k < dims_[2] && "k is out of bounds in CArray 4D"); // die if >= dim2 assert(l < dims_[3] && "l is out of bounds in CArray 4D"); // die if >= dim3 - return array_[l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])]; + return array_[l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])]; } -//5D +// 5D template -inline T& CArray::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +inline T& CArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in CArray 5D!"); assert(i < dims_[0] && "i is out of bounds in CArray 5D!"); assert(j < dims_[1] && "j is out of bounds in CArray 5D!"); assert(k < dims_[2] && "k is out of bounds in CArray 5D!"); assert(l < dims_[3] && "l is out of bounds in CArray 5D!"); assert(m < dims_[4] && "m is out of bounds in CArray 5D!"); - - return array_[m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + + return array_[m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } -//6D +// 6D template -inline T& CArray::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +inline T& CArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in CArray 6D!"); assert(i < dims_[0] && "i is out of bounds in CArray 6D!"); assert(j < dims_[1] && "j is out of bounds in CArray 6D!"); @@ -2090,24 +1499,14 @@ inline T& CArray::operator() (size_t i, assert(l < dims_[3] && "l is out of bounds in CArray 6D!"); assert(m < dims_[4] && "m is out of bounds in CArray 6D!"); assert(n < dims_[5] && "n is out of bounds in CArray 6D!"); - - return array_[n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; -} - -//7D -template -inline T& CArray::operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + + return array_[n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; +} + +// 7D +template +inline T& CArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in CArray 7D!"); assert(i < dims_[0] && "i is out of bounds in CArray 7D!"); assert(j < dims_[1] && "j is out of bounds in CArray 7D!"); @@ -2116,27 +1515,20 @@ inline T& CArray::operator() (size_t i, assert(m < dims_[4] && "m is out of bounds in CArray 7D!"); assert(n < dims_[5] && "n is out of bounds in CArray 7D!"); assert(o < dims_[6] && "o is out of bounds in CArray 7D!"); - - return array_[o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; - -} + return array_[o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; +} -//overload = operator +// overload = operator template -inline CArray& CArray::operator= (const CArray& temp) -{ - +inline CArray& CArray::operator=(const CArray& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for order_ = temp.order_; length_ = temp.length_; @@ -2145,9 +1537,7 @@ inline CArray& CArray::operator= (const CArray& temp) return *this; } - - -//return size +// return size template inline size_t CArray::size() const { return length_; @@ -2156,7 +1546,7 @@ inline size_t CArray::size() const { template inline size_t CArray::dims(size_t i) const { assert(i < order_ && "CArray order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to CArray dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to CArray dims is out of bounds!"); return dims_[i]; } @@ -2165,129 +1555,76 @@ inline size_t CArray::order() const { return order_; } - template -inline T* CArray::pointer() const{ +inline T* CArray::pointer() const { return array_.get(); } template void CArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } -//destructor +// destructor template CArray::~CArray() {} //----endof carray class definitions---- - -//6. ViewCArray -// indicies are [0:N-1] +// 6. ViewCArray +// indicies are [0:N-1] template class ViewCArray { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - T * array_; - + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + T* array_; + public: - // Default constructor - ViewCArray (); - + ViewCArray(); + //--- 1D to 7D array --- - ViewCArray(T *array, - size_t dim0); - - ViewCArray(T *array, - size_t dim0, - size_t dim1); - - ViewCArray(T *some_array, - size_t dim0, - size_t dim1, - size_t dim2); - - ViewCArray(T *some_array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3); - - ViewCArray (T *some_array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - ViewCArray (T *some_array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - ViewCArray (T *some_array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - + ViewCArray(T* array, size_t dim0); + + ViewCArray(T* array, size_t dim0, size_t dim1); + + ViewCArray(T* some_array, size_t dim0, size_t dim1, size_t dim2); + + ViewCArray(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3); + + ViewCArray(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + ViewCArray(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + ViewCArray(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + T& operator()(size_t i) const; - - T& operator()(size_t i, - size_t j) const; - - T& operator()(size_t i, - size_t j, - size_t k) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l) const; - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; // calculate C = math(A,B) template void operator=(M do_this_math); - - //return array size + + // return array size size_t size() const; - + // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; @@ -2296,130 +1633,95 @@ class ViewCArray { // return pointer T* pointer() const; - -}; // end of ViewCArray -//class definitions +}; // end of ViewCArray -//constructors +// class definitions -//no dim +// constructors + +// no dim template ViewCArray::ViewCArray() { - array_ = NULL; - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - } + array_ = NULL; + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + } } -//1D +// 1D template -ViewCArray::ViewCArray(T *array, - size_t dim0) -{ +ViewCArray::ViewCArray(T* array, size_t dim0) { dims_[0] = dim0; - order_ = 1; - length_ = dim0; - array_ = array; + order_ = 1; + length_ = dim0; + array_ = array; } -//2D +// 2D template -ViewCArray::ViewCArray(T *array, - size_t dim0, - size_t dim1) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1) { dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = dim0 * dim1; - array_ = array; + order_ = 2; + length_ = dim0 * dim1; + array_ = array; } -//3D +// 3D template -ViewCArray::ViewCArray (T *array, - size_t dim0, - size_t dim1, - size_t dim2) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1, size_t dim2) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = dim0 * dim1 * dim2; - array_ = array; + order_ = 3; + length_ = dim0 * dim1 * dim2; + array_ = array; } -//4D +// 4D template -ViewCArray::ViewCArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = dim0 * dim1 * dim2 * dim3; - array_ = array; + order_ = 4; + length_ = dim0 * dim1 * dim2 * dim3; + array_ = array; } -//5D +// 5D template -ViewCArray::ViewCArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = dim0 * dim1 * dim2 * dim3 * dim4; - array_ = array; + order_ = 5; + length_ = dim0 * dim1 * dim2 * dim3 * dim4; + array_ = array; } -//6D +// 6D template -ViewCArray::ViewCArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; - array_ = array; + order_ = 6; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5; + array_ = array; } -//7D +// 7D template -ViewCArray::ViewCArray(T *array, - size_t dim0, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +ViewCArray::ViewCArray(T* array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -2427,20 +1729,19 @@ ViewCArray::ViewCArray(T *array, dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - array_ = array; + order_ = 7; + length_ = dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + array_ = array; } -//overload () operator +// overload () operator -//1D +// 1D template -inline T& ViewCArray::operator()(size_t i) const -{ +inline T& ViewCArray::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewCArray 1D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 1D!"); - + return array_[i]; } @@ -2451,87 +1752,61 @@ template inline T& ViewCArray>::operator()(size_t i) const { assert(i < dim1_ && "i is out of bounds in c_array 1D"); // die if >= dim1 - + return (*this_array_)(i); } */ -//2D +// 2D template -inline T& ViewCArray::operator()(size_t i, - size_t j) const -{ - +inline T& ViewCArray::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewCArray 2D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 2D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArray 2D!"); - - return array_[j + (i * dims_[1])]; + + return array_[j + (i * dims_[1])]; } -//3D +// 3D template -inline T& ViewCArray::operator()(size_t i, - size_t j, - size_t k) const -{ +inline T& ViewCArray::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewCArray 3D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 3D!"); assert(j < dims_[1] && "j is out of bounds in ViewCarray 3D!"); assert(k < dims_[2] && "k is out of bounds in ViewCArray 3D!"); - - return array_[k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])]; + + return array_[k + (j * dims_[2]) + (i * dims_[2] * dims_[1])]; } -//4D +// 4D template -inline T& ViewCArray::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +inline T& ViewCArray::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewCArray 4D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 4D"); // die if >= dim0 assert(j < dims_[1] && "j is out of bounds in ViewCArray 4D"); // die if >= dim1 assert(k < dims_[2] && "k is out of bounds in ViewCArray 4D"); // die if >= dim2 assert(l < dims_[3] && "l is out of bounds in ViewCArray 4D"); // die if >= dim3 - - return array_[l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])]; + + return array_[l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])]; } -//5D +// 5D template -inline T& ViewCArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +inline T& ViewCArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewCArray 5D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 5D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArray 5D!"); assert(k < dims_[2] && "k is out of bounds in ViewCArray 5D!"); assert(l < dims_[3] && "l is out of bounds in ViewCArray 5D!"); assert(m < dims_[4] && "m is out of bounds in ViewCArray 5D!"); - - return array_[m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + + return array_[m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } -//6D +// 6D template -inline T& ViewCArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +inline T& ViewCArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewCArray 6D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 6D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArray 6D!"); @@ -2539,24 +1814,14 @@ inline T& ViewCArray::operator()(size_t i, assert(l < dims_[3] && "l is out of bounds in ViewCArray 6D!"); assert(m < dims_[4] && "m is out of bounds in ViewCArray 6D!"); assert(n < dims_[5] && "n is out of bounds in ViewCArray 6D!"); - - return array_[n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; -} - -//7D -template -inline T& ViewCArray::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + + return array_[n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; +} + +// 7D +template +inline T& ViewCArray::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewCArray 7D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArray 7D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArray 7D!"); @@ -2565,24 +1830,20 @@ inline T& ViewCArray::operator()(size_t i, assert(m < dims_[4] && "m is out of bounds in ViewCArray 7D!"); assert(n < dims_[5] && "n is out of bounds in ViewCArray 7D!"); assert(o < dims_[6] && "o is out of bounds in ViewCArray 7D!"); - - return array_[o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; -} + return array_[o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; +} // calculate this ViewFArray object = math(A,B) template template -void ViewCArray::operator=(M do_this_math){ - do_this_math(*this); // pass in this ViewFArray object -}// end of math opperation +void ViewCArray::operator=(M do_this_math) { + do_this_math(*this); // pass in this ViewFArray object +} // end of math opperation -//return size +// return size template inline size_t ViewCArray::size() const { return length_; @@ -2591,7 +1852,7 @@ inline size_t ViewCArray::size() const { template inline size_t ViewCArray::dims(size_t i) const { assert(i < order_ && "ViewCArray order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewCArray dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewCArray dims is out of bounds!"); return dims_[i]; } @@ -2607,132 +1868,87 @@ inline T* ViewCArray::pointer() const { template void ViewCArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } //---end of ViewCArray class definitions---- - -//7. CMatrix +// 7. CMatrix template class CMatrix { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - std::shared_ptr matrix_; - + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + std::shared_ptr matrix_; + public: - // default constructor CMatrix(); CMatrix(size_t dim1); - CMatrix(size_t dim1, - size_t dim2); - - CMatrix(size_t dim1, - size_t dim2, - size_t dim3); - - CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - CMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - CMatrix (size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7); + CMatrix(size_t dim1, size_t dim2); + + CMatrix(size_t dim1, size_t dim2, size_t dim3); + + CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7); CMatrix(const CMatrix& temp); - - //overload operators to access data + + // overload operators to access data T& operator()(size_t i) const; - T& operator()(size_t i, - size_t j) const; - - T& operator()(size_t i, - size_t j, - size_t k) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - - T& operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; - - //overload = operator - CMatrix& operator= (const CMatrix &temp); - - //return array size + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + // overload = operator + CMatrix& operator=(const CMatrix& temp); + + // return array size size_t size() const; - + // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; - //return pointer + // return pointer T* pointer() const; - + // set values to input void set_values(T val); // deconstructor - ~CMatrix( ); - -}; // end of CMatrix + ~CMatrix(); + +}; // end of CMatrix // CMatrix class definitions -//constructors +// constructors -//no dim +// no dim -//1D +// 1D template CMatrix::CMatrix() { matrix_ = NULL; @@ -2742,106 +1958,78 @@ CMatrix::CMatrix() { } } -//1D +// 1D template -CMatrix::CMatrix(size_t dim1) -{ +CMatrix::CMatrix(size_t dim1) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 1; + length_ = dim1; + matrix_ = std::shared_ptr(new T[length_]); } -//2D +// 2D template -CMatrix::CMatrix(size_t dim1, - size_t dim2) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = dim1 * dim2; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 2; + length_ = dim1 * dim2; + matrix_ = std::shared_ptr(new T[length_]); } -//3D +// 3D template -CMatrix::CMatrix(size_t dim1, - size_t dim2, - size_t dim3) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = dim1 * dim2 * dim3; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 3; + length_ = dim1 * dim2 * dim3; + matrix_ = std::shared_ptr(new T[length_]); } -//4D +// 4D template -CMatrix::CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = dim1 * dim2 * dim3 * dim4; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 4; + length_ = dim1 * dim2 * dim3 * dim4; + matrix_ = std::shared_ptr(new T[length_]); } -//5D +// 5D template -CMatrix::CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = dim1 * dim2 * dim3 * dim4 * dim5; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 5; + length_ = dim1 * dim2 * dim3 * dim4 * dim5; + matrix_ = std::shared_ptr(new T[length_]); } -//6D +// 6D template -CMatrix::CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 6; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + matrix_ = std::shared_ptr(new T[length_]); } -//7D +// 7D template -CMatrix::CMatrix(size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7) -{ +CMatrix::CMatrix(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -2849,115 +2037,88 @@ CMatrix::CMatrix(size_t dim1, dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; - matrix_ = std::shared_ptr (new T[length_]); + order_ = 7; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; + matrix_ = std::shared_ptr(new T[length_]); } template CMatrix::CMatrix(const CMatrix& temp) { - // Do nothing if the assignment is of the form x = x - + if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for - + } // end for + order_ = temp.order_; length_ = temp.length_; matrix_ = temp.matrix_; - } // end if - -} // end constructor + } // end if -//overload () operator +} // end constructor -//1D +// overload () operator + +// 1D template -T& CMatrix::operator()(size_t i) const -{ +T& CMatrix::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in CMatrix 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 1D!"); - - return matrix_[i-1]; + + return matrix_[i - 1]; } -//2D +// 2D template -T& CMatrix::operator()(size_t i, - size_t j) const -{ +T& CMatrix::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in CMatrix 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 2D!"); - - return matrix_[(j-1) + (i-1)*dims_[1]]; + + return matrix_[(j - 1) + (i - 1) * dims_[1]]; } -//3D +// 3D template -T& CMatrix::operator()(size_t i, - size_t j, - size_t k) const -{ +T& CMatrix::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in CMatrix 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrix 3D!"); - - return matrix_[(k-1) + (j-1)*dims_[2] - + (i-1)*dims_[2]*dims_[1]]; + + return matrix_[(k - 1) + (j - 1) * dims_[2] + (i - 1) * dims_[2] * dims_[1]]; } -//4D +// 4D template -T& CMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +T& CMatrix::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in CMatrix 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 4D"); // die if >= dim0 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 4D"); // die if >= dim1 assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrix 4D"); // die if >= dim2 assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrix 4D"); // die if >= dim3 - - return matrix_[(l-1) + (k-1)*dims_[3] - + (j-1)*dims_[3]*dims_[2] - + (i-1)*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(l - 1) + (k - 1) * dims_[3] + (j - 1) * dims_[3] * dims_[2] + (i - 1) * dims_[3] * dims_[2] * dims_[1]]; } -//5D +// 5D template -T& CMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +T& CMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in CMatrix 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrix 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrix 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrix 5D!"); - - return matrix_[(m-1) + (l-1)*dims_[4] - + (k-1)*dims_[4]*dims_[3] - + (j-1)*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(m - 1) + (l - 1) * dims_[4] + (k - 1) * dims_[4] * dims_[3] + (j - 1) * dims_[4] * dims_[3] * dims_[2] + + (i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; } -//6D +// 6D template -T& CMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +T& CMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in CMatrix 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 6D!"); @@ -2965,24 +2126,14 @@ T& CMatrix::operator()(size_t i, assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrix 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrix 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in CMatrix 6D!"); - - return matrix_[ (n-1) + (m-1)*dims_[5] - + (l-1)*dims_[5]*dims_[4] - + (k-1)*dims_[5]*dims_[4]*dims_[3] - + (j-1)*dims_[5]*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[5]*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; -} - -//7D -template -T& CMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + + return matrix_[(n - 1) + (m - 1) * dims_[5] + (l - 1) * dims_[5] * dims_[4] + (k - 1) * dims_[5] * dims_[4] * dims_[3] + + (j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] + (i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; +} + +// 7D +template +T& CMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in CMatrix 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrix 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrix 7D!"); @@ -2991,29 +2142,26 @@ T& CMatrix::operator()(size_t i, assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrix 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in CMatrix 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in CMatrix 7D!"); - - return matrix_[(o-1) + (n-1)*dims_[6] - + (m-1)*dims_[6]*dims_[5] - + (l-1)*dims_[6]*dims_[5]*dims_[4] - + (k-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3] - + (j-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(o - 1) + (n - 1) * dims_[6] + (m - 1) * dims_[6] * dims_[5] + (l - 1) * dims_[6] * dims_[5] * dims_[4] + + (k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] + (j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] + + (i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; } -//overload = operator -//THIS = CMatrix<> temp +// overload = operator +// THIS = CMatrix<> temp template -CMatrix &CMatrix::operator= (const CMatrix &temp) { - if(this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ +CMatrix& CMatrix::operator=(const CMatrix& temp) { + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for order_ = temp.order_; length_ = temp.length_; matrix_ = temp.matrix_; } - return *this; + return *this; } template @@ -3023,9 +2171,9 @@ inline size_t CMatrix::size() const { template inline size_t CMatrix::dims(size_t i) const { - i--; // i starts at 1 + i--; // i starts at 1 assert(i < order_ && "CMatrix order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to CMatrix dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to CMatrix dims is out of bounds!"); return dims_[i]; } @@ -3035,129 +2183,76 @@ inline size_t CMatrix::order() const { } template -inline T* CMatrix::pointer() const{ +inline T* CMatrix::pointer() const { return matrix_.get(); } template void CMatrix::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { matrix_[i] = val; } } // Destructor template -CMatrix::~CMatrix(){} +CMatrix::~CMatrix() {} //----end of CMatrix class definitions---- - -//8. ViewCMatrix -// indices [1:N] +// 8. ViewCMatrix +// indices [1:N] template class ViewCMatrix { - private: size_t dims_[7]; - size_t length_; // Length of 1D array - size_t order_; // tensor order (rank) - T * matrix_; - + size_t length_; // Length of 1D array + size_t order_; // tensor order (rank) + T* matrix_; + public: - // default constructor ViewCMatrix(); - - + //--- 1D array --- // overloaded constructor - ViewCMatrix (T *matrix, - size_t dim1); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6); - - ViewCMatrix (T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7); - - T& operator() (size_t i) const; - - T& operator() (size_t i, - size_t j) const; - - T& operator() (size_t i, - size_t j, - size_t k) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const; - - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const; - T& operator() (size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const; + ViewCMatrix(T* matrix, size_t dim1); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7); + + T& operator()(size_t i) const; + + T& operator()(size_t i, size_t j) const; + + T& operator()(size_t i, size_t j, size_t k) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; // calculate C = math(A,B) template void operator=(M do_this_math); - - //return array size + + // return array size size_t size() const; - + // return array dims size_t dims(size_t i) const; - + // return array order (rank) size_t order() const; @@ -3166,128 +2261,95 @@ class ViewCMatrix { // return pointer T* pointer() const; - -}; // end of ViewCMatrix -//class definitions +}; // end of ViewCMatrix + +// class definitions -//constructors +// constructors -//no dim +// no dim template -ViewCMatrix::ViewCMatrix(){ - matrix_ = NULL; - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - } +ViewCMatrix::ViewCMatrix() { + matrix_ = NULL; + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + } } -//1D +// 1D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1) -{ +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; - matrix_ = matrix; + order_ = 1; + length_ = dim1; + matrix_ = matrix; } -//2D +// 2D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2) -{ +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = dim1 * dim2; - matrix_ = matrix; + order_ = 2; + length_ = dim1 * dim2; + matrix_ = matrix; } -//3D +// 3D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3) -{ +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = dim1 * dim2 * dim3; - matrix_ = matrix; + order_ = 3; + length_ = dim1 * dim2 * dim3; + matrix_ = matrix; } -//4D +// 4D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4) -{ +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = dim1 * dim2 * dim3 * dim4; - matrix_ = matrix; + order_ = 4; + length_ = dim1 * dim2 * dim3 * dim4; + matrix_ = matrix; } -//5D +// 5D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5) -{ +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = dim1 * dim2 * dim3 * dim4 * dim5; - matrix_ = matrix; + order_ = 5; + length_ = dim1 * dim2 * dim3 * dim4 * dim5; + matrix_ = matrix; } -//6D +// 6D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6) { +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; - matrix_ = matrix; + order_ = 6; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6; + matrix_ = matrix; } -//7D +// 7D template -ViewCMatrix::ViewCMatrix(T *matrix, - size_t dim1, - size_t dim2, - size_t dim3, - size_t dim4, - size_t dim5, - size_t dim6, - size_t dim7) { +ViewCMatrix::ViewCMatrix(T* matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -3295,98 +2357,72 @@ ViewCMatrix::ViewCMatrix(T *matrix, dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; - matrix = matrix_; + order_ = 7; + length_ = dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7; + matrix = matrix_; } -//overload () operator +// overload () operator -//1D +// 1D template -T& ViewCMatrix:: operator() (size_t i) const -{ +T& ViewCMatrix::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewCMatrix 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 1D!"); - - return matrix_[i-1]; + + return matrix_[i - 1]; } -//2D +// 2D template -T& ViewCMatrix::operator() (size_t i, - size_t j) const -{ +T& ViewCMatrix::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewCMatrix 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 2D!"); - - return matrix_[(j-1) + (i-1)*dims_[1]]; + + return matrix_[(j - 1) + (i - 1) * dims_[1]]; } -//3D +// 3D template -T& ViewCMatrix::operator () (size_t i, - size_t j, - size_t k) const -{ +T& ViewCMatrix::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewCMatrix 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewCMatrix 3D!"); - - return matrix_[(k-1) + (j-1)*dims_[2] - + (i-1)*dims_[2]*dims_[1]]; + + return matrix_[(k - 1) + (j - 1) * dims_[2] + (i - 1) * dims_[2] * dims_[1]]; } -//4D +// 4D template -T& ViewCMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l) const -{ +T& ViewCMatrix::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewCMatrix 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 4D"); // die if >= dim0 assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 4D"); // die if >= dim1 assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewCMatrix 4D"); // die if >= dim2 assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewCMatrix 4D"); // die if >= dim3 - - return matrix_[(l-1) + (k-1)*dims_[3] - + (j-1)*dims_[3]*dims_[2] - + (i-1)*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(l - 1) + (k - 1) * dims_[3] + (j - 1) * dims_[3] * dims_[2] + (i - 1) * dims_[3] * dims_[2] * dims_[1]]; } -//5D +// 5D template -T& ViewCMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m) const -{ +T& ViewCMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewCMatrix 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewCMatrix 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewCMatrix 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewCMatrix 5D!"); - - return matrix_[(m-1) + (l-1)*dims_[4] - + (k-1)*dims_[4]*dims_[3] - + (j-1)*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(m - 1) + (l - 1) * dims_[4] + (k - 1) * dims_[4] * dims_[3] + (j - 1) * dims_[4] * dims_[3] * dims_[2] + + (i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; } -//6D +// 6D template -T& ViewCMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n) const -{ +T& ViewCMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewCMatrix 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 6D!"); @@ -3394,24 +2430,14 @@ T& ViewCMatrix::operator()(size_t i, assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewCMatrix 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewCMatrix 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewCMatrix 6D!"); - - return matrix_[(n-1) + (m-1)*dims_[5] - + (l-1)*dims_[5]*dims_[4] - + (k-1)*dims_[5]*dims_[4]*dims_[3] - + (j-1)*dims_[5]*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[5]*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; -} - -//7D -template -T& ViewCMatrix::operator()(size_t i, - size_t j, - size_t k, - size_t l, - size_t m, - size_t n, - size_t o) const -{ + + return matrix_[(n - 1) + (m - 1) * dims_[5] + (l - 1) * dims_[5] * dims_[4] + (k - 1) * dims_[5] * dims_[4] * dims_[3] + + (j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] + (i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; +} + +// 7D +template +T& ViewCMatrix::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewCMatrix 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrix 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrix 7D!"); @@ -3420,21 +2446,18 @@ T& ViewCMatrix::operator()(size_t i, assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewCMatrix 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewCMatrix 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in ViewCMatrix 7D!"); - - return matrix_[(o-1) + (n-1)*dims_[6] - + (m-1)*dims_[6]*dims_[5] - + (l-1)*dims_[6]*dims_[5]*dims_[4] - + (k-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3] - + (j-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3]*dims_[2] - + (i-1)*dims_[6]*dims_[5]*dims_[4]*dims_[3]*dims_[2]*dims_[1]]; + + return matrix_[(o - 1) + (n - 1) * dims_[6] + (m - 1) * dims_[6] * dims_[5] + (l - 1) * dims_[6] * dims_[5] * dims_[4] + + (k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] + (j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] + + (i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1]]; } // calculate this ViewFArray object = math(A,B) template template -void ViewCMatrix::operator=(M do_this_math){ - do_this_math(*this); // pass in this ViewFArray object -}// end of math opperation +void ViewCMatrix::operator=(M do_this_math) { + do_this_math(*this); // pass in this ViewFArray object +} // end of math opperation template inline size_t ViewCMatrix::size() const { @@ -3443,9 +2466,9 @@ inline size_t ViewCMatrix::size() const { template inline size_t ViewCMatrix::dims(size_t i) const { - i--; // i starts at 1 + i--; // i starts at 1 assert(i < order_ && "ViewCMatrix order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewCMatrix dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewCMatrix dims is out of bounds!"); return dims_[i]; } @@ -3461,55 +2484,54 @@ inline T* ViewCMatrix::pointer() const { template void ViewCMatrix::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { matrix_[i] = val; } } - //----end of ViewCMatrix class definitions---- -//9. RaggedRightArray +// 9. RaggedRightArray template class RaggedRightArray { private: - std::shared_ptr start_index_; - std::shared_ptr array_; - + std::shared_ptr start_index_; + std::shared_ptr array_; + size_t dim1_, length_; - size_t num_saved_; // the number saved in the 1D array - + size_t num_saved_; // the number saved in the 1D array + public: // Default constructor - RaggedRightArray (); - + RaggedRightArray(); + //--- 2D array access of a ragged right array --- - + // Overload constructor for a CArray - RaggedRightArray (CArray &strides_array); - + RaggedRightArray(CArray& strides_array); + // Overload constructor for a ViewCArray - RaggedRightArray (ViewCArray &strides_array); - + RaggedRightArray(ViewCArray& strides_array); + // Overloaded constructor for a traditional array - RaggedRightArray (size_t *strides_array, size_t some_dim1); - + RaggedRightArray(size_t* strides_array, size_t some_dim1); + // Overload constructor for a RaggedRightArray to // support a dynamically built stride_array - RaggedRightArray (size_t some_dim1, size_t buffer); + RaggedRightArray(size_t some_dim1, size_t buffer); // Copy constructor - RaggedRightArray (const RaggedRightArray& temp); - + RaggedRightArray(const RaggedRightArray& temp); + // A method to return the stride size size_t stride(size_t i) const; - + // A method to increase the number of column entries, i.e., // the stride size. Used with the constructor for building // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array void push_back(size_t i); - + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)] T& operator()(size_t i, size_t j) const; @@ -3517,128 +2539,125 @@ class RaggedRightArray { // method to return total size size_t size() const; - //return pointer + // return pointer T* pointer() const; - - //get row starts array + + // get row starts array size_t* get_starts() const; - RaggedRightArray& operator+= (const size_t i); + RaggedRightArray& operator+=(const size_t i); - RaggedRightArray& operator= (const RaggedRightArray &temp); + RaggedRightArray& operator=(const RaggedRightArray& temp); // set values to input void set_values(T val); // Destructor - ~RaggedRightArray ( ); -}; // End of RaggedRightArray + ~RaggedRightArray(); +}; // End of RaggedRightArray // Default constructor template -RaggedRightArray::RaggedRightArray () { - array_ = NULL; +RaggedRightArray::RaggedRightArray() { + array_ = NULL; start_index_ = NULL; length_ = dim1_ = num_saved_ = 0; } - // Overloaded constructor with CArray template -RaggedRightArray::RaggedRightArray (CArray &strides_array){ +RaggedRightArray::RaggedRightArray(CArray& strides_array) { // The length of the stride array is some_dim1; - dim1_ = strides_array.size(); - + dim1_ = strides_array.size(); + // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ + for (size_t i = 0; i < dim1_; i++) { count += strides_array(i); start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - - array_ = std::shared_ptr (new T[length_]); -} // End constructor + + array_ = std::shared_ptr(new T[length_]); +} // End constructor // Overloaded constructor with a view c array template -RaggedRightArray::RaggedRightArray (ViewCArray &strides_array) { +RaggedRightArray::RaggedRightArray(ViewCArray& strides_array) { // The length of the stride array is some_dim1; - dim1_ = strides_array.size(); - + dim1_ = strides_array.size(); + // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ + for (size_t i = 0; i < dim1_; i++) { count += strides_array(i); start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - array_ = std::shared_ptr (new T[length_]); -} // End constructor + array_ = std::shared_ptr(new T[length_]); +} // End constructor // Overloaded constructor with a regular cpp array template -RaggedRightArray::RaggedRightArray (size_t *strides_array, size_t dim1){ +RaggedRightArray::RaggedRightArray(size_t* strides_array, size_t dim1) { // The length of the stride array is some_dim1; dim1_ = dim1; - + // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ + for (size_t i = 0; i < dim1_; i++) { count += strides_array[i]; start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - array_ = std::shared_ptr (new T[length_]); -} // End constructor + array_ = std::shared_ptr(new T[length_]); +} // End constructor // overloaded constructor for a dynamically built strides_array. // buffer is the max number of columns needed template -RaggedRightArray::RaggedRightArray (size_t some_dim1, size_t buffer){ - +RaggedRightArray::RaggedRightArray(size_t some_dim1, size_t buffer) { dim1_ = some_dim1; - + // create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - //start_index_[0] = 0; // the 1D array starts at 0 + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + // start_index_[0] = 0; // the 1D array starts at 0 num_saved_ = 0; - - length_ = some_dim1*buffer; - array_ = std::shared_ptr (new T[length_]); - -} // end constructor + + length_ = some_dim1 * buffer; + array_ = std::shared_ptr(new T[length_]); + +} // end constructor // Copy constructor template -RaggedRightArray::RaggedRightArray (const RaggedRightArray& temp) { - +RaggedRightArray::RaggedRightArray(const RaggedRightArray& temp) { if (this != &temp) { - dim1_ = temp.dim1_; - length_ = temp.length_; + dim1_ = temp.dim1_; + length_ = temp.length_; num_saved_ = temp.num_saved_; // shared_ptr start_index_ = temp.start_index_; - array_ = temp.array_; + array_ = temp.array_; } } @@ -3655,9 +2674,9 @@ inline size_t RaggedRightArray::stride(size_t i) const { // this is used to build the stride array dynamically // DO NOT USE with constructors that are given a stride array template -void RaggedRightArray::push_back(size_t i){ - num_saved_ ++; - start_index_[i+1] = num_saved_; +void RaggedRightArray::push_back(size_t i) { + num_saved_++; + start_index_[i + 1] = num_saved_; } // Overload operator() to access data as array(i,j) @@ -3666,112 +2685,113 @@ template inline T& RaggedRightArray::operator()(size_t i, size_t j) const { // get the 1D array index size_t start = start_index_[i]; - + // asserts assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArray"); // die if >= dim1 - //assert(j < stride(i) && "j is out of stride bounds in RaggedRightArray"); // die if >= stride - assert(j+start < length_ && "j+start is out of bounds in RaggedRightArray"); // die if >= 1D array length) - + // assert(j < stride(i) && "j is out of stride bounds in RaggedRightArray"); // die if >= + // stride + assert(j + start < length_ && "j+start is out of bounds in RaggedRightArray"); // die if >= 1D array length) + return array_[j + start]; -} // End operator() +} // End operator() -//return size +// return size template size_t RaggedRightArray::size() const { return length_; } template -RaggedRightArray & RaggedRightArray::operator+= (const size_t i) { - this->num_saved_ ++; - this->start_index_[i+1] = num_saved_; +RaggedRightArray& RaggedRightArray::operator+=(const size_t i) { + this->num_saved_++; + this->start_index_[i + 1] = num_saved_; return *this; } -//overload = operator +// overload = operator template -RaggedRightArray & RaggedRightArray::operator= (const RaggedRightArray &temp) { - - if( this != &temp) { - dim1_ = temp.dim1_; - length_ = temp.length_; +RaggedRightArray& RaggedRightArray::operator=(const RaggedRightArray& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + length_ = temp.length_; num_saved_ = temp.num_saved_; // shared_ptr start_index_ = temp.start_index_; - array_ = temp.array_; + array_ = temp.array_; } - + return *this; } template -inline T* RaggedRightArray::pointer() const{ +inline T* RaggedRightArray::pointer() const { return array_.get(); } template -inline size_t* RaggedRightArray::get_starts() const{ +inline size_t* RaggedRightArray::get_starts() const { return start_index_.get(); } template void RaggedRightArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } // Destructor template -RaggedRightArray::~RaggedRightArray () {} +RaggedRightArray::~RaggedRightArray() {} //----end of RaggedRightArray class definitions---- -//9. RaggedRightArrayofVectors +// 9. RaggedRightArrayofVectors template class RaggedRightArrayofVectors { private: - std::shared_ptr start_index_; - std::shared_ptr array_; - + std::shared_ptr start_index_; + std::shared_ptr array_; + size_t dim1_, length_, vector_dim_; - size_t num_saved_; // the number saved in the 1D array - + size_t num_saved_; // the number saved in the 1D array + public: // Default constructor - RaggedRightArrayofVectors (); - - //--- 3D array access of a ragged right array storing a vector of size vector_dim_ at each (i,j)--- - + RaggedRightArrayofVectors(); + + //--- 3D array access of a ragged right array storing a vector of size vector_dim_ at each + //(i,j)--- + // Overload constructor for a CArray - RaggedRightArrayofVectors (CArray &strides_array, size_t vector_dim); - + RaggedRightArrayofVectors(CArray& strides_array, size_t vector_dim); + // Overload constructor for a ViewCArray - RaggedRightArrayofVectors (ViewCArray &strides_array, size_t vector_dim); - + RaggedRightArrayofVectors(ViewCArray& strides_array, size_t vector_dim); + // Overloaded constructor for a traditional array - RaggedRightArrayofVectors (size_t *strides_array, size_t some_dim1, size_t vector_dim); - + RaggedRightArrayofVectors(size_t* strides_array, size_t some_dim1, size_t vector_dim); + // Overload constructor for a RaggedRightArray to // support a dynamically built stride_array - RaggedRightArrayofVectors (size_t some_dim1, size_t buffer, size_t vector_dim); + RaggedRightArrayofVectors(size_t some_dim1, size_t buffer, size_t vector_dim); // Copy constructor - RaggedRightArrayofVectors (const RaggedRightArrayofVectors& temp); - + RaggedRightArrayofVectors(const RaggedRightArrayofVectors& temp); + // A method to return the stride size size_t stride(size_t i) const; // A method to return the vector dim size_t vector_dim() const; - + // A method to increase the number of column entries, i.e., // the stride size. Used with the constructor for building // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array void push_back(size_t i); - + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)], k=[0,vector_dim_] T& operator()(size_t i, size_t j, size_t k) const; @@ -3779,135 +2799,132 @@ class RaggedRightArrayofVectors { // method to return total size size_t size() const; - //return pointer + // return pointer T* pointer() const; - - //get row starts array + + // get row starts array size_t* get_starts() const; - RaggedRightArrayofVectors& operator+= (const size_t i); + RaggedRightArrayofVectors& operator+=(const size_t i); - RaggedRightArrayofVectors& operator= (const RaggedRightArrayofVectors &temp); + RaggedRightArrayofVectors& operator=(const RaggedRightArrayofVectors& temp); // set values to input void set_values(T val); // Destructor - ~RaggedRightArrayofVectors ( ); -}; // End of RaggedRightArray + ~RaggedRightArrayofVectors(); +}; // End of RaggedRightArray // Default constructor template -RaggedRightArrayofVectors::RaggedRightArrayofVectors () { - array_ = NULL; +RaggedRightArrayofVectors::RaggedRightArrayofVectors() { + array_ = NULL; start_index_ = NULL; length_ = dim1_ = vector_dim_ = num_saved_ = 0; } - // Overloaded constructor with CArray template -RaggedRightArrayofVectors::RaggedRightArrayofVectors (CArray &strides_array, size_t vector_dim){ +RaggedRightArrayofVectors::RaggedRightArrayofVectors(CArray& strides_array, size_t vector_dim) { // The length of the stride array is some_dim1; - dim1_ = strides_array.size(); + dim1_ = strides_array.size(); vector_dim_ = vector_dim; - + // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ - count += strides_array(i)*vector_dim_; + for (size_t i = 0; i < dim1_; i++) { + count += strides_array(i) * vector_dim_; start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - - array_ = std::shared_ptr (new T[length_]); -} // End constructor + + array_ = std::shared_ptr(new T[length_]); +} // End constructor // Overloaded constructor with a view c array template -RaggedRightArrayofVectors::RaggedRightArrayofVectors (ViewCArray &strides_array, size_t vector_dim) { +RaggedRightArrayofVectors::RaggedRightArrayofVectors(ViewCArray& strides_array, size_t vector_dim) { // The length of the stride array is some_dim1; - dim1_ = strides_array.size(); + dim1_ = strides_array.size(); vector_dim_ = vector_dim; - + // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ - count += strides_array(i)*vector_dim_; + for (size_t i = 0; i < dim1_; i++) { + count += strides_array(i) * vector_dim_; start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - array_ = std::shared_ptr (new T[length_]); -} // End constructor + array_ = std::shared_ptr(new T[length_]); +} // End constructor // Overloaded constructor with a regular cpp array template -RaggedRightArrayofVectors::RaggedRightArrayofVectors (size_t *strides_array, size_t dim1, size_t vector_dim){ +RaggedRightArrayofVectors::RaggedRightArrayofVectors(size_t* strides_array, size_t dim1, size_t vector_dim) { // The length of the stride array is some_dim1; - dim1_ = dim1; + dim1_ = dim1; vector_dim_ = vector_dim; // Create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + start_index_[0] = 0; // the 1D array starts at 0 + // Loop over to find the total length of the 1D array to // represent the ragged-right array of vectors and set the starting 1D index size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ - count += strides_array[i]*vector_dim_; + for (size_t i = 0; i < dim1_; i++) { + count += strides_array[i] * vector_dim_; start_index_[(i + 1)] = count; - } // end for i + } // end for i length_ = count; - - array_ = std::shared_ptr (new T[length_]); -} // End constructor + + array_ = std::shared_ptr(new T[length_]); +} // End constructor // overloaded constructor for a dynamically built strides_array. // buffer is the max number of columns needed template -RaggedRightArrayofVectors::RaggedRightArrayofVectors (size_t some_dim1, size_t buffer, size_t vector_dim){ - - dim1_ = some_dim1; +RaggedRightArrayofVectors::RaggedRightArrayofVectors(size_t some_dim1, size_t buffer, size_t vector_dim) { + dim1_ = some_dim1; vector_dim_ = vector_dim; // create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim1_ + 1)]); // note the dim1+1 - //start_index_[0] = 0; // the 1D array starts at 0 + start_index_ = std::shared_ptr(new size_t[(dim1_ + 1)]); // note the dim1+1 + // start_index_[0] = 0; // the 1D array starts at 0 num_saved_ = 0; - - length_ = some_dim1*buffer*vector_dim; - array_ = std::shared_ptr (new T[some_dim1*buffer]); - -} // end constructor + + length_ = some_dim1 * buffer * vector_dim; + array_ = std::shared_ptr(new T[some_dim1 * buffer]); + +} // end constructor // Copy constructor template -RaggedRightArrayofVectors::RaggedRightArrayofVectors (const RaggedRightArrayofVectors& temp) { - - if( this != &temp) { - dim1_ = temp.dim1_; +RaggedRightArrayofVectors::RaggedRightArrayofVectors(const RaggedRightArrayofVectors& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; vector_dim_ = temp.vector_dim_; - length_ = temp.length_; - num_saved_ = temp.num_saved_; - + length_ = temp.length_; + num_saved_ = temp.num_saved_; + // shared pointer start_index_ = temp.start_index_; - array_ = temp.start_index_; + array_ = temp.start_index_; } -} // end copy constructor +} // end copy constructor // A method to return the stride size template @@ -3915,16 +2932,16 @@ inline size_t RaggedRightArrayofVectors::stride(size_t i) const { // Ensure that i is within bounds assert(i < dim1_ && "i is greater than dim1_ in RaggedRightArray"); - return (start_index_[(i + 1)] - start_index_[i])/vector_dim_; + return (start_index_[(i + 1)] - start_index_[i]) / vector_dim_; } // A method to increase the stride size, in other words, // this is used to build the stride array dynamically // DO NOT USE with constructors that are given a stride array template -void RaggedRightArrayofVectors::push_back(size_t i){ +void RaggedRightArrayofVectors::push_back(size_t i) { num_saved_ += vector_dim_; - start_index_[i+1] = num_saved_; + start_index_[i + 1] = num_saved_; } // Overload operator() to access data as array(i,j,k) @@ -3933,102 +2950,102 @@ template inline T& RaggedRightArrayofVectors::operator()(size_t i, size_t j, size_t k) const { // get the 1D array index size_t start = start_index_[i]; - + // asserts assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArray"); // die if >= dim1 - //assert(j < stride(i) && "j is out of stride bounds in RaggedRightArray"); // die if >= stride - assert(j*vector_dim_+start + k < length_ && "j+start is out of bounds in RaggedRightArray"); // die if >= 1D array length) - - return array_[j*vector_dim_ + start + k]; -} // End operator() + // assert(j < stride(i) && "j is out of stride bounds in RaggedRightArray"); // die if >= + // stride + assert(j * vector_dim_ + start + k < length_ && "j+start is out of bounds in RaggedRightArray"); // die if >= 1D array length) + + return array_[j * vector_dim_ + start + k]; +} // End operator() -//return size +// return size template size_t RaggedRightArrayofVectors::size() const { return length_; } template -RaggedRightArrayofVectors & RaggedRightArrayofVectors::operator+= (const size_t i) { +RaggedRightArrayofVectors& RaggedRightArrayofVectors::operator+=(const size_t i) { this->num_saved_ += vector_dim_; - this->start_index_[i+1] = num_saved_; + this->start_index_[i + 1] = num_saved_; return *this; } -//overload = operator +// overload = operator template -RaggedRightArrayofVectors & RaggedRightArrayofVectors::operator= (const RaggedRightArrayofVectors &temp) { - - if( this != &temp) { - dim1_ = temp.dim1_; +RaggedRightArrayofVectors& RaggedRightArrayofVectors::operator=(const RaggedRightArrayofVectors& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; vector_dim_ = temp.vector_dim_; - length_ = temp.length_; - num_saved_ = temp.num_saved_; - + length_ = temp.length_; + num_saved_ = temp.num_saved_; + // shared pointer start_index_ = temp.start_index_; - array_ = temp.start_index_; + array_ = temp.start_index_; } - + return *this; } template -inline T* RaggedRightArrayofVectors::pointer() const{ +inline T* RaggedRightArrayofVectors::pointer() const { return array_.get(); } template -inline size_t* RaggedRightArrayofVectors::get_starts() const{ +inline size_t* RaggedRightArrayofVectors::get_starts() const { return start_index_.get(); } template void RaggedRightArrayofVectors::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } // Destructor template -RaggedRightArrayofVectors::~RaggedRightArrayofVectors () {} +RaggedRightArrayofVectors::~RaggedRightArrayofVectors() {} //----end of RaggedRightArrayofVectors class definitions---- -//10. RaggedDownArray +// 10. RaggedDownArray template class RaggedDownArray { private: - std::shared_ptr start_index_; - std::shared_ptr array_; + std::shared_ptr start_index_; + std::shared_ptr array_; size_t dim2_; size_t length_; - size_t num_saved_; // the number saved in the 1D array + size_t num_saved_; // the number saved in the 1D array public: - //default constructor - RaggedDownArray() ; + // default constructor + RaggedDownArray(); //~~~~2D`~~~~ - //overload constructor with CArray - RaggedDownArray(CArray &strides_array); + // overload constructor with CArray + RaggedDownArray(CArray& strides_array); - //overload with ViewCArray - RaggedDownArray(ViewCArray &strides_array); + // overload with ViewCArray + RaggedDownArray(ViewCArray& strides_array); - //overload with traditional array - RaggedDownArray(size_t *strides_array, size_t dome_dim1); + // overload with traditional array + RaggedDownArray(size_t* strides_array, size_t dome_dim1); // Overload constructor for a RaggedDownArray to // support a dynamically built stride_array - RaggedDownArray (size_t some_dim2, size_t buffer); + RaggedDownArray(size_t some_dim2, size_t buffer); // Copy constructor - RaggedDownArray (const RaggedDownArray& temp); - - //method to return stride size + RaggedDownArray(const RaggedDownArray& temp); + + // method to return stride size size_t stride(size_t j); // A method to increase the number of column entries, i.e., @@ -4036,157 +3053,155 @@ class RaggedDownArray { // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array void push_back(size_t j); - - //overload () operator to access data as array (i,j) + + // overload () operator to access data as array (i,j) T& operator()(size_t i, size_t j); // method to return total size size_t size(); - //return pointer + // return pointer T* pointer() const; - - //get row starts array + + // get row starts array size_t* get_starts() const; - //overload = operator - RaggedDownArray& operator= (const RaggedDownArray &temp); + // overload = operator + RaggedDownArray& operator=(const RaggedDownArray& temp); // set values to input void set_values(T val); - //destructor + // destructor ~RaggedDownArray(); -}; //~~~~~end of RaggedDownArray class declarations~~~~~~~~ +}; //~~~~~end of RaggedDownArray class declarations~~~~~~~~ -//no dims +// no dims template RaggedDownArray::RaggedDownArray() { - array_ = NULL; + array_ = NULL; start_index_ = NULL; length_ = dim2_ = num_saved_ = 0; } -//overload constructor with CArray +// overload constructor with CArray template -RaggedDownArray::RaggedDownArray( CArray &strides_array) { +RaggedDownArray::RaggedDownArray(CArray& strides_array) { // Length of stride array dim2_ = strides_array.size(); // Create and initialize startding indices - start_index_ = std::shared_ptr (new size_t[(dim2_ + 1)]); // note the dim2+1 - start_index_[0] = 0; //1D array starts at 0 + start_index_ = std::shared_ptr(new size_t[(dim2_ + 1)]); // note the dim2+1 + start_index_[0] = 0; // 1D array starts at 0 - - //length of strides + // length of strides dim2_ = strides_array.size(); // Loop to find total length of 1D array size_t count = 0; - for(size_t j = 0; j < dim2_ ; j++) { + for (size_t j = 0; j < dim2_; j++) { count += strides_array(j); - start_index_[j+1] = count; + start_index_[j + 1] = count; } length_ = count; - array_ = std::shared_ptr (new T[length_]); + array_ = std::shared_ptr(new T[length_]); -} // End constructor +} // End constructor // Overload constructor with ViewCArray template -RaggedDownArray::RaggedDownArray( ViewCArray &strides_array) { +RaggedDownArray::RaggedDownArray(ViewCArray& strides_array) { // Length of strides - //dim2_ = strides_array.size(); + // dim2_ = strides_array.size(); - //create array for holding start indices - start_index_ = std::shared_ptr (new size_t[(dim2_ + 1)]); // note the dim2+1 + // create array for holding start indices + start_index_ = std::shared_ptr(new size_t[(dim2_ + 1)]); // note the dim2+1 start_index_[0] = 0; size_t count = 0; // Loop over to get total length of 1D array - for(size_t j = 0; j < dim2_ ;j++ ) { + for (size_t j = 0; j < dim2_; j++) { count += strides_array(j); - start_index_[j+1] = count; + start_index_[j + 1] = count; } length_ = count; - array_ = std::shared_ptr (new T[length_]); + array_ = std::shared_ptr(new T[length_]); -} // End constructor +} // End constructor // Overload constructor with regualar array template -RaggedDownArray::RaggedDownArray( size_t *strides_array, size_t dim2){ +RaggedDownArray::RaggedDownArray(size_t* strides_array, size_t dim2) { // Length of stride array dim2_ = dim2; // Create and initialize starting index of entries - start_index_ = std::shared_ptr (new size_t[(dim2_ + 1)]); // note the dim2+1 + start_index_ = std::shared_ptr(new size_t[(dim2_ + 1)]); // note the dim2+1 start_index_[0] = 0; // Loop over to find length of 1D array // Represent ragged down array and set 1D index size_t count = 0; - for(size_t j = 0; j < dim2_; j++) { + for (size_t j = 0; j < dim2_; j++) { count += strides_array[j]; - start_index_[j+1] = count; + start_index_[j + 1] = count; } length_ = count; - array_ = std::shared_ptr (new T[length_]); + array_ = std::shared_ptr(new T[length_]); -} //end construnctor +} // end construnctor // overloaded constructor for a dynamically built strides_array. // buffer is the max number of columns needed template -RaggedDownArray::RaggedDownArray (size_t some_dim2, size_t buffer){ - +RaggedDownArray::RaggedDownArray(size_t some_dim2, size_t buffer) { dim2_ = some_dim2; - + // create and initialize the starting index of the entries in the 1D array - start_index_ = std::shared_ptr (new size_t[(dim2_ + 1)]); // note the dim2+1 - //start_index_[0] = 0; // the 1D array starts at 0 - + start_index_ = std::shared_ptr(new size_t[(dim2_ + 1)]); // note the dim2+1 + // start_index_[0] = 0; // the 1D array starts at 0 + num_saved_ = 0; - - length_ = some_dim2*buffer; - array_ = std::shared_ptr (new T[length_]); - -} // end constructor + + length_ = some_dim2 * buffer; + array_ = std::shared_ptr(new T[length_]); + +} // end constructor // Copy constructor template -RaggedDownArray::RaggedDownArray (const RaggedDownArray& temp) { - if( this != &temp) { - dim2_ = temp.dim2_; - length_ = temp.length_; +RaggedDownArray::RaggedDownArray(const RaggedDownArray& temp) { + if (this != &temp) { + dim2_ = temp.dim2_; + length_ = temp.length_; num_saved_ = temp.num_saved_; // shared pointer start_index_ = temp.start_index_; - array_ = temp.array_; + array_ = temp.array_; } -} // end copy constructor +} // end copy constructor // Check the stride size template size_t RaggedDownArray::stride(size_t j) { assert(j < dim2_ && "j is greater than dim2_ in RaggedDownArray"); - return start_index_[j+1] - start_index_[j]; + return start_index_[j + 1] - start_index_[j]; } // A method to increase the stride size, in other words, // this is used to build the stride array dynamically // DO NOT USE with constructors that are given a stride array template -void RaggedDownArray::push_back(size_t j){ - num_saved_ ++; - start_index_[j+1] = num_saved_; +void RaggedDownArray::push_back(size_t j) { + num_saved_++; + start_index_[j + 1] = num_saved_; } -//return size +// return size template size_t RaggedDownArray::size() { return length_; @@ -4203,43 +3218,41 @@ T& RaggedDownArray::operator()(size_t i, size_t j) { // Make sure we are within array bounds assert(i < stride(j) && "i is out of bounds in RaggedDownArray"); assert(j < dim2_ && "j is out of dim2_ bounds in RaggedDownArray"); - assert(i+start < length_ && "i+start is out of bounds in RaggedDownArray"); // die if >= 1D array length) - + assert(i + start < length_ && "i+start is out of bounds in RaggedDownArray"); // die if >= 1D array length) + return array_[i + start]; -} // End () operator +} // End () operator -//overload = operator +// overload = operator template -RaggedDownArray & RaggedDownArray::operator= (const RaggedDownArray &temp) { - - if( this != &temp) { - dim2_ = temp.dim2_; - length_ = temp.length_; +RaggedDownArray& RaggedDownArray::operator=(const RaggedDownArray& temp) { + if (this != &temp) { + dim2_ = temp.dim2_; + length_ = temp.length_; num_saved_ = temp.num_saved_; // shared pointer start_index_ = temp.start_index_; - array_ = temp.array_; + array_ = temp.array_; } - + return *this; } template -inline T* RaggedDownArray::pointer() const{ +inline T* RaggedDownArray::pointer() const { return array_.get(); } - template -inline size_t* RaggedDownArray::get_starts() const{ +inline size_t* RaggedDownArray::get_starts() const { return start_index_.get(); } template void RaggedDownArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } @@ -4249,50 +3262,48 @@ template RaggedDownArray::~RaggedDownArray() {} // End destructor - //----end of RaggedDownArray---- - -//11. DynamicRaggedRightArray +// 11. DynamicRaggedRightArray template class DynamicRaggedRightArray { private: - std::shared_ptr stride_; - std::shared_ptr array_; - + std::shared_ptr stride_; + std::shared_ptr array_; + size_t dim1_; size_t dim2_; size_t length_; - + public: // Default constructor - DynamicRaggedRightArray (); - + DynamicRaggedRightArray(); + //--- 2D array access of a ragged right array --- - + // overload constructor - DynamicRaggedRightArray (size_t dim1, size_t dim2); + DynamicRaggedRightArray(size_t dim1, size_t dim2); // Copy constructor - DynamicRaggedRightArray (const DynamicRaggedRightArray& temp); + DynamicRaggedRightArray(const DynamicRaggedRightArray& temp); // A method to return or set the stride size size_t& stride(size_t i) const; - + // A method to return the size size_t size() const; - //return pointer + // return pointer T* pointer() const; - + // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[stride(i)] T& operator()(size_t i, size_t j) const; - + // Overload copy assignment operator - DynamicRaggedRightArray& operator= (const DynamicRaggedRightArray &temp); - + DynamicRaggedRightArray& operator=(const DynamicRaggedRightArray& temp); + // set values of array indices void set_values(T val); @@ -4300,52 +3311,52 @@ class DynamicRaggedRightArray { void set_values_sparse(T val); // Destructor - ~DynamicRaggedRightArray (); + ~DynamicRaggedRightArray(); }; -//nothing +// nothing template -DynamicRaggedRightArray::DynamicRaggedRightArray () { - array_ = NULL; +DynamicRaggedRightArray::DynamicRaggedRightArray() { + array_ = NULL; stride_ = NULL; length_ = dim1_ = dim2_ = 0; } // Overloaded constructor template -DynamicRaggedRightArray::DynamicRaggedRightArray (size_t dim1, size_t dim2) { +DynamicRaggedRightArray::DynamicRaggedRightArray(size_t dim1, size_t dim2) { // The dimensions of the array; - dim1_ = dim1; - dim2_ = dim2; - length_ = dim1*dim2; - + dim1_ = dim1; + dim2_ = dim2; + length_ = dim1 * dim2; + // Create memory on the heap for the values - array_ = std::shared_ptr (new T[dim1*dim2]); - + array_ = std::shared_ptr(new T[dim1 * dim2]); + // Create memory for the stride size in each row - stride_ = std::shared_ptr (new size_t[dim1]); - + stride_ = std::shared_ptr(new size_t[dim1]); + // Initialize the stride - for (int i=0; i -DynamicRaggedRightArray::DynamicRaggedRightArray (const DynamicRaggedRightArray& temp) { - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +DynamicRaggedRightArray::DynamicRaggedRightArray(const DynamicRaggedRightArray& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; // shared pointer stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; } -} // end copy constructor +} // end copy constructor // A method to set the stride size for row i template @@ -4353,9 +3364,9 @@ size_t& DynamicRaggedRightArray::stride(size_t i) const { return stride_[i]; } -//return size +// return size template -size_t DynamicRaggedRightArray::size() const{ +size_t DynamicRaggedRightArray::size() const { return length_; } @@ -4364,48 +3375,46 @@ size_t DynamicRaggedRightArray::size() const{ template inline T& DynamicRaggedRightArray::operator()(size_t i, size_t j) const { // Asserts - assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedRight"); // die if >= dim1 - assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedRight"); // die if >= dim2 + assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedRight"); // die if >= dim1 + assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedRight"); // die if >= dim2 assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= stride - - return array_[j + i*dim2_]; + + return array_[j + i * dim2_]; } -//overload = operator +// overload = operator template -inline DynamicRaggedRightArray& DynamicRaggedRightArray::operator= (const DynamicRaggedRightArray &temp) -{ - - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +inline DynamicRaggedRightArray& DynamicRaggedRightArray::operator=(const DynamicRaggedRightArray& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; // shared pointer stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; } - + return *this; } template -inline T* DynamicRaggedRightArray::pointer() const{ +inline T* DynamicRaggedRightArray::pointer() const { return array_.get(); } template void DynamicRaggedRightArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } template void DynamicRaggedRightArray::set_values_sparse(T val) { - for(int i = 0; i < dim1_; i++) { - for(int j = 0; j < stride_[i]; j++) { - array_[dim2_*i+j] = val; + for (int i = 0; i < dim1_; i++) { + for (int j = 0; j < stride_[i]; j++) { + array_[dim2_ * i + j] = val; } } } @@ -4414,50 +3423,46 @@ void DynamicRaggedRightArray::set_values_sparse(T val) { template DynamicRaggedRightArray::~DynamicRaggedRightArray() {} - - - //----end DynamicRaggedRightArray class definitions---- - -//12. DynamicRaggedDownArray +// 12. DynamicRaggedDownArray template class DynamicRaggedDownArray { private: - std::shared_ptr stride_; - std::shared_ptr array_; - + std::shared_ptr stride_; + std::shared_ptr array_; + size_t dim1_; size_t dim2_; size_t length_; - + public: // Default constructor - DynamicRaggedDownArray (); - + DynamicRaggedDownArray(); + //--- 2D array access of a ragged right array --- - + // overload constructor - DynamicRaggedDownArray (size_t dim1, size_t dim2); - + DynamicRaggedDownArray(size_t dim1, size_t dim2); + // Copy constructor - DynamicRaggedDownArray (const DynamicRaggedDownArray& temp); - + DynamicRaggedDownArray(const DynamicRaggedDownArray& temp); + // A method to return or set the stride size size_t& stride(size_t j) const; - + // A method to return the size size_t size() const; - + // Overload operator() to access data as array(i,j), // where i=[stride(j)], j=[0:N-1] T& operator()(size_t i, size_t j) const; - + // Overload copy assignment operator - DynamicRaggedDownArray& operator= (const DynamicRaggedDownArray &temp); + DynamicRaggedDownArray& operator=(const DynamicRaggedDownArray& temp); - //return pointer + // return pointer T* pointer() const; // set values of indices @@ -4465,55 +3470,54 @@ class DynamicRaggedDownArray { // set values to input void set_values_sparse(T val); - + // Destructor - ~DynamicRaggedDownArray (); + ~DynamicRaggedDownArray(); }; -//nothing +// nothing template -DynamicRaggedDownArray::DynamicRaggedDownArray () { - array_ = NULL; +DynamicRaggedDownArray::DynamicRaggedDownArray() { + array_ = NULL; stride_ = NULL; length_ = dim1_ = dim2_ = 0; } // Overloaded constructor template -DynamicRaggedDownArray::DynamicRaggedDownArray (size_t dim1, size_t dim2) { +DynamicRaggedDownArray::DynamicRaggedDownArray(size_t dim1, size_t dim2) { // The dimensions of the array; - dim1_ = dim1; - dim2_ = dim2; - length_ = dim1*dim2; - + dim1_ = dim1; + dim2_ = dim2; + length_ = dim1 * dim2; + // Create memory on the heap for the values - array_ = std::shared_ptr (new T[dim1*dim2]); - + array_ = std::shared_ptr(new T[dim1 * dim2]); + // Create memory for the stride size in each row - stride_ = std::shared_ptr (new size_t[dim2]); - + stride_ = std::shared_ptr(new size_t[dim2]); + // Initialize the stride - for (int j=0; j -DynamicRaggedDownArray::DynamicRaggedDownArray (const DynamicRaggedDownArray& temp) { - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +DynamicRaggedDownArray::DynamicRaggedDownArray(const DynamicRaggedDownArray& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; // shared pointer stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; } -} // end copy constructor - +} // end copy constructor // A method to set the stride size for column j template @@ -4521,9 +3525,9 @@ size_t& DynamicRaggedDownArray::stride(size_t j) const { return stride_[j]; } -//return size +// return size template -size_t DynamicRaggedDownArray::size() const{ +size_t DynamicRaggedDownArray::size() const { return length_; } @@ -4533,48 +3537,46 @@ size_t DynamicRaggedDownArray::size() const{ template inline T& DynamicRaggedDownArray::operator()(size_t i, size_t j) const { // Asserts - assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedDownArray"); // die if >= dim1 - assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedDownArray"); // die if >= dim2 + assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedDownArray"); // die if >= dim1 + assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedDownArray"); // die if >= dim2 assert(i < stride_[j] && "i is out of stride bounds in DynamicRaggedDownArray"); // die if >= stride - - return array_[i + j*dim1_]; + + return array_[i + j * dim1_]; } -//overload = operator +// overload = operator template -inline DynamicRaggedDownArray& DynamicRaggedDownArray::operator= (const DynamicRaggedDownArray &temp) -{ - - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +inline DynamicRaggedDownArray& DynamicRaggedDownArray::operator=(const DynamicRaggedDownArray& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; // shared pointer stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; } - + return *this; } template -inline T* DynamicRaggedDownArray::pointer() const{ +inline T* DynamicRaggedDownArray::pointer() const { return array_.get(); } template void DynamicRaggedDownArray::set_values(T val) { - for(int i = 0; i < length_; i++) { + for (int i = 0; i < length_; i++) { array_[i] = val; } } template void DynamicRaggedDownArray::set_values_sparse(T val) { - for(int j = 0; j < dim2_; j++) { - for(int i = 0; i < stride_[j]; i++) { - array_[dim1_*j+i] = val; + for (int j = 0; j < dim2_; j++) { + for (int i = 0; i < stride_[j]; i++) { + array_[dim1_ * j + i] = val; } } } @@ -4585,26 +3587,23 @@ DynamicRaggedDownArray::~DynamicRaggedDownArray() {} //----end of DynamicRaggedDownArray class definitions----- - // 15CSRArrayy template class CSRArray { - private: // What ought to be private ? - size_t dim1_, dim2_; // dim1_ is number of rows dim2_ is number of columns +private: // What ought to be private ? + size_t dim1_, dim2_; // dim1_ is number of rows dim2_ is number of columns size_t nnz_; - std::shared_ptr array_; - std::shared_ptr column_index_; - std::shared_ptr start_index_; - - public: - + std::shared_ptr array_; + std::shared_ptr column_index_; + std::shared_ptr start_index_; + +public: /** * @brief Construct a new Sparse Row Array object * */ CSRArray(); - /** * @brief Construct a new Sparse Row Array object * @@ -4628,7 +3627,7 @@ class CSRArray { * * @param temp array to copy */ - CSRArray(const CSRArray &temp); + CSRArray(const CSRArray& temp); /** * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not alocated @@ -4638,7 +3637,7 @@ class CSRArray { * @return T& */ T& operator()(size_t i, size_t j) const; - + /** * @brief Same functionality as operator(). Used for compatibility with other matar types * @@ -4649,13 +3648,14 @@ class CSRArray { T& value(size_t i, size_t j) const; /** - * @brief Assignment operator. Uses shared pointers to the data of temp instead of making a fresh copy + * @brief Assignment operator. Uses shared pointers to the data of temp instead of making a + * fresh copy * * @param temp CSRArray to copy values of * @return CSRArray& */ - CSRArray& operator=(const CSRArray &temp); - + CSRArray& operator=(const CSRArray& temp); + /** * @brief get start of array_ data * @@ -4670,7 +3670,7 @@ class CSRArray { */ size_t* get_starts() const; - void printer(); //debugging tool + void printer(); // debugging tool /** * @brief Iterator notation to go through the non zero values of row i. @@ -4679,7 +3679,7 @@ class CSRArray { * @return T* pointer to first non zero element of row i */ T* begin(size_t i); - + /** * @brief Iterator notation to go through the non zeros values of row i * @@ -4689,7 +3689,8 @@ class CSRArray { T* end(size_t i); /** - * @brief Return number of non zero elements in row i. Included for compatibility with other matar types + * @brief Return number of non zero elements in row i. Included for compatibility with other + * matar types * * @param i row */ @@ -4720,274 +3721,264 @@ class CSRArray { size_t nnz(); // underscore stuff - // Use the index into the 1d array to get what value is stored there and what is the corresponding row + // Use the index into the 1d array to get what value is stored there and what is the + // corresponding row T& get_val_flat(size_t k); size_t get_col_flat(size_t k); // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to size_t flat_index(size_t i, size_t j); // Convertor - int toCSC(CArray &array, CArray &start_index, CArray &row_index); - + int toCSC(CArray& array, CArray& start_index, CArray& row_index); + void to_dense(CArray& A); // set values to input void set_values(T val); - //destructor - ~CSRArray(); - - + // destructor + ~CSRArray(); }; -template -CSRArray::CSRArray(){ +template +CSRArray::CSRArray() { dim1_ = dim2_ = nnz_ = 0; - array_ = NULL; + array_ = NULL; column_index_ = start_index_ = NULL; } template -CSRArray::CSRArray(CArray array, CArray column_index, CArray start_index, size_t dim1, size_t dim2 ){ - dim1_ = dim1; - dim2_ = dim2; - size_t nnz = array.size(); - start_index_ = std::shared_ptr (new size_t[dim1_ + 1]); - array_ = std::shared_ptr (new T[nnz+1]); - column_index_ = std::shared_ptr (new size_t[nnz]); - size_t i ; - for(i = 0; i < nnz; i++){ - array_[i] = array(i); +CSRArray::CSRArray(CArray array, CArray column_index, CArray start_index, size_t dim1, size_t dim2) { + dim1_ = dim1; + dim2_ = dim2; + size_t nnz = array.size(); + start_index_ = std::shared_ptr(new size_t[dim1_ + 1]); + array_ = std::shared_ptr(new T[nnz + 1]); + column_index_ = std::shared_ptr(new size_t[nnz]); + size_t i; + for (i = 0; i < nnz; i++) { + array_[i] = array(i); column_index_[i] = column_index(i); } - for(i = 0; i < dim1_ + 1; i++){ + for (i = 0; i < dim1_ + 1; i++) { start_index_[i] = start_index(i); } nnz_ = nnz; } -template -CSRArray::CSRArray(const CSRArray &temp){ - if(this != temp) { - nnz_ = temp.nnz_; +template +CSRArray::CSRArray(const CSRArray& temp) { + if (this != temp) { + nnz_ = temp.nnz_; dim1_ = temp.dim1_; dim2_ = temp.dim2_; - - start_index_ = temp.start_index_; + + start_index_ = temp.start_index_; column_index_ = temp.column_index_; - array_ = temp.array_; + array_ = temp.array_; } } -template -CSRArray::CSRArray(CArray dense){ - dim1_ = dense.dims(0); - dim2_ = dense.dims(1); - nnz_ = dense.size(); - start_index_ = std::shared_ptr (new size_t[dim1_ + 1]); - array_ = std::shared_ptr (new T[nnz_ + 1]); - column_index_ = std::shared_ptr (new size_t[nnz_]); - size_t i,j; +template +CSRArray::CSRArray(CArray dense) { + dim1_ = dense.dims(0); + dim2_ = dense.dims(1); + nnz_ = dense.size(); + start_index_ = std::shared_ptr(new size_t[dim1_ + 1]); + array_ = std::shared_ptr(new T[nnz_ + 1]); + column_index_ = std::shared_ptr(new size_t[nnz_]); + size_t i, j; size_t cur = 0; - for(i = 0; i < dim1_; i++){ - for(j = 0; i < dim2_; j++){ - if(j != 0){ - start_index_[i+1] += 1; - column_index_[cur] = j; - array_[cur] = dense(i,j); - cur++; + for (i = 0; i < dim1_; i++) { + for (j = 0; i < dim2_; j++) { + if (j != 0) { + start_index_[i + 1] += 1; + column_index_[cur] = j; + array_[cur] = dense(i, j); + cur++; } } } start_index_[0] = 0; - for(i = 1; i <= dim1_; i++){ - start_index_[i] = start_index_[i] + start_index_[i+1]; + for (i = 1; i <= dim1_; i++) { + start_index_[i] = start_index_[i] + start_index_[i + 1]; } - - } -template +template T& CSRArray::operator()(size_t i, size_t j) const { size_t row_start = start_index_[i]; - size_t row_end = start_index_[i+1]; + size_t row_end = start_index_[i + 1]; size_t k; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_[row_start + k] == j){ + for (k = 0; k < row_end - row_start; k++) { + if (column_index_[row_start + k] == j) { return array_[row_start + k]; } } - array_[nnz_] = (T) NULL; + array_[nnz_] = (T)NULL; return array_[nnz_]; } - -template +template T& CSRArray::value(size_t i, size_t j) const { size_t row_start = start_index_[i]; - size_t row_end = start_index_[i+1]; + size_t row_end = start_index_[i + 1]; size_t k; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_[row_start + k] == j){ + for (k = 0; k < row_end - row_start; k++) { + if (column_index_[row_start + k] == j) { return array_[row_start + k]; } } - array_[nnz_] = (T) NULL; + array_[nnz_] = (T)NULL; return array_[nnz_]; } -template -T* CSRArray::pointer() const{ +template +T* CSRArray::pointer() const { return array_.get(); } -template +template size_t* CSRArray::get_starts() const { return start_index_.get(); } -template -CSRArray& CSRArray::operator=(const CSRArray &temp){ - if(this != temp) { - nnz_ = temp.nnz_; +template +CSRArray& CSRArray::operator=(const CSRArray& temp) { + if (this != temp) { + nnz_ = temp.nnz_; dim1_ = temp.dim1_; dim2_ = temp.dim2_; - - start_index_ = temp.start_index_; + + start_index_ = temp.start_index_; column_index_ = temp.column_index_; - array_ = temp.array_; + array_ = temp.array_; } return *this; } -//debugging tool primarily +// debugging tool primarily template -void CSRArray::printer(){ - size_t i,j; - for(i = 0; i < dim1_; i++){ - for(j = 0; j < dim2_; j++){ - printf(" %d ", (*this)(i,j)); +void CSRArray::printer() { + size_t i, j; + for (i = 0; i < dim1_; i++) { + for (j = 0; j < dim2_; j++) { + printf(" %d ", (*this)(i, j)); } printf("\n"); } } -template -void CSRArray::to_dense(CArray& A){ - size_t i,j; - for(i = 0; i < dim1_; i++){ - for(j = 0; j < dim2_; j++){ - A(i,j) = (*this)(i,j); +template +void CSRArray::to_dense(CArray& A) { + size_t i, j; + for (i = 0; i < dim1_; i++) { + for (j = 0; j < dim2_; j++) { + A(i, j) = (*this)(i, j); } } - } -template +template size_t CSRArray::stride(size_t i) const { - assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); - return start_index_[i+i] - start_index_[i]; - + assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); + return start_index_[i + i] - start_index_[i]; } - -template +template size_t CSRArray::dim1() const { - return dim1_; + return dim1_; } -template +template size_t CSRArray::dim2() const { - return dim2_; + return dim2_; } - -template -T* CSRArray::begin(size_t i){ +template +T* CSRArray::begin(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin()"); size_t row_start = start_index_[i]; return &array_[row_start]; } -template -T* CSRArray::end(size_t i){ +template +T* CSRArray::end(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.end()"); - size_t row_start = start_index_[i+1]; + size_t row_start = start_index_[i + 1]; return &array_[row_start]; } -template -size_t CSRArray::begin_index(size_t i){ +template +size_t CSRArray::begin_index(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin_index()"); return start_index_[i]; } -template -size_t CSRArray::end_index(size_t i){ +template +size_t CSRArray::end_index(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin_index()"); - return start_index_[i+1]; + return start_index_[i + 1]; } -template -size_t CSRArray::nnz(){ +template +size_t CSRArray::nnz() { return nnz_; } -template -size_t CSRArray::nnz(size_t i){ +template +size_t CSRArray::nnz(size_t i) { assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); - return start_index_[i+1] - start_index_[i]; + return start_index_[i + 1] - start_index_[i]; } - -template -T& CSRArray::get_val_flat(size_t k){ - assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_val_flat()"); - return array_[k]; +template +T& CSRArray::get_val_flat(size_t k) { + assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_val_flat()"); + return array_[k]; } -template -size_t CSRArray::get_col_flat(size_t k){ +template +size_t CSRArray::get_col_flat(size_t k) { assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_col_lat()"); return column_index_[k]; } - -template -size_t CSRArray::flat_index(size_t i, size_t j){ +template +size_t CSRArray::flat_index(size_t i, size_t j) { size_t k; size_t row_start = start_index_[i]; - size_t row_end = start_index_[i+1]; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_[row_start+k] == j){ - return row_start+k; + size_t row_end = start_index_[i + 1]; + for (k = 0; k < row_end - row_start; k++) { + if (column_index_[row_start + k] == j) { + return row_start + k; } } - return nnz_; + return nnz_; } // Assumes that data, col_ptrs, and row_ptrs // have been allocated size already before this call // Returns the data in this csr format but as represented as the appropriatte vectors // for a csc format -template -int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray &row_ptrs ){ +template +int CSRArray::toCSC(CArray& data, CArray& col_ptrs, CArray& row_ptrs) { int nnz_cols[dim2_ + 1]; int col_counts[dim2_]; int i = 0; // How many elements are each column - for(i =0 ; i < dim2_; i++){ - nnz_cols[i] = 0; + for (i = 0; i < dim2_; i++) { + nnz_cols[i] = 0; col_counts[i] = 0; } nnz_cols[dim2_] = 0; - col_ptrs(0) = 0; - for(i =0; i < nnz_; i++){ + col_ptrs(0) = 0; + for (i = 0; i < nnz_; i++) { nnz_cols[column_index_[i] + 1] += 1; } // What we actually care about is how many elements are // in all the columns preceeding this column. - for(i = 1; i <= dim2_; i++){ - nnz_cols[i] = nnz_cols[i-1] + nnz_cols[i]; + for (i = 1; i <= dim2_; i++) { + nnz_cols[i] = nnz_cols[i - 1] + nnz_cols[i]; col_ptrs(i) = nnz_cols[i]; } size_t row = 1; @@ -4997,13 +3988,13 @@ int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray // we allocated for this column already // For row we simply keep track of what row we are currently in // as we scan through the 1d array of data. - for(i = 0; i < nnz_; i++){ - if(i >= start_index_[row]){ + for (i = 0; i < nnz_; i++) { + if (i >= start_index_[row]) { row++; } int idx = nnz_cols[column_index_[i]] + col_counts[column_index_[i]]; col_counts[column_index_[i]] += 1; - data(idx) = array_[i]; + data(idx) = array_[i]; row_ptrs(idx) = row - 1; } // I return an int because I thought I might need to return an error code @@ -5013,7 +4004,7 @@ int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray template void CSRArray::set_values(T val) { - for(int i = 0; i < nnz_; i++) { + for (int i = 0; i < nnz_; i++) { array_[i] = val; } } @@ -5025,334 +4016,329 @@ CSRArray::~CSRArray() {} // 16 CSCArray template -class CSCArray -{ -private: // What ought to be private ? +class CSCArray { +private: // What ought to be private ? size_t dim1_, dim2_; size_t nnz_; - std::shared_ptr array_; - std::shared_ptr start_index_; - std::shared_ptr row_index_; - - public: - - /** - * @brief Construct a new empty Sparse Col Array object - * - */ - CSCArray(); - - /** - * @brief Construct a new Sparse Col Array object - * - * @param array: 1d array of data values in order as read top to bottom, left to right - * @param row_index: 1d array that marks what row each element is in - * @param start_index: 1d array that marks where the first element of each column starts - * @param dim1: number of rows the matrix should have - * @param dim2: number of columns the matrix should have - */ - CSCArray(CArray array, CArray row_index, CArray start_index, size_t dim1, size_t dim2); - - /** - * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated - * - * @param i : row - * @param j : column - * @return T& : address of array_ that corresponds to A(i,j) - */ - T &operator()(size_t i, size_t j) const; - - /** - * @brief Overloaded copy operator - * - * @param temp : Array to copy - * @return CSCArray& - */ - CSCArray &operator=(const CSCArray &temp); - - T *pointer() const; - - /** - * @brief Same functionality as nnz(i) included for compatibility with the rest of matar - * - * @param i : row - * @return size_t - */ - size_t stride(size_t i) const; - - /** - * @brief Same functionality as operator() included for compatibility with the rest of matar - * - * @param i: row - * @param j: column - * @return T& - */ - T &value(size_t i, size_t j) const; - - /** - * @brief Get the start_index array - * - * @return size_t* : returns start_index_ - */ - size_t *get_starts() const; - - /** - * @brief Get number of rows - * - * @return size_t number of rows - */ - size_t dim1() const; - - /** - * @brief Get number of columns - * - * @return size_t number of columns - */ - size_t dim2() const; - - /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - T *begin(size_t i); - - /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - T *end(size_t i); - - // iterator for the raw data at row i - // i.e. return the index each element is the index in the 1 array - // This as the use of providing a reasonable way to get the column - // index and data value in the case you need both - size_t begin_index(size_t i); - size_t end_index (size_t i); - - /** - * @brief Get the number of non zero elements in row i - * - * @param i : row to get - * @return size_t : size of row - */ - size_t nnz(size_t i); - /** - * @brief Get number of non zero elements total in array - * - * @return size_t - */ - size_t nnz(); - - // Use the index into the 1d array to get what value is stored there and what is the corresponding row - T &get_val_flat(size_t k); - size_t get_row_flat(size_t k); - // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to - int flat_index(size_t i, size_t j); - // Convertor - int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); - void to_dense(FArray &A); - - // set values to input - void set_values(T val); - - // destructor - ~CSCArray(); + std::shared_ptr array_; + std::shared_ptr start_index_; + std::shared_ptr row_index_; + +public: + /** + * @brief Construct a new empty Sparse Col Array object + * + */ + CSCArray(); + + /** + * @brief Construct a new Sparse Col Array object + * + * @param array: 1d array of data values in order as read top to bottom, left to right + * @param row_index: 1d array that marks what row each element is in + * @param start_index: 1d array that marks where the first element of each column starts + * @param dim1: number of rows the matrix should have + * @param dim2: number of columns the matrix should have + */ + CSCArray(CArray array, CArray row_index, CArray start_index, size_t dim1, size_t dim2); + + /** + * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated + * + * @param i : row + * @param j : column + * @return T& : address of array_ that corresponds to A(i,j) + */ + T& operator()(size_t i, size_t j) const; + + /** + * @brief Overloaded copy operator + * + * @param temp : Array to copy + * @return CSCArray& + */ + CSCArray& operator=(const CSCArray& temp); + + T* pointer() const; + + /** + * @brief Same functionality as nnz(i) included for compatibility with the rest of matar + * + * @param i : row + * @return size_t + */ + size_t stride(size_t i) const; + + /** + * @brief Same functionality as operator() included for compatibility with the rest of matar + * + * @param i: row + * @param j: column + * @return T& + */ + T& value(size_t i, size_t j) const; + + /** + * @brief Get the start_index array + * + * @return size_t* : returns start_index_ + */ + size_t* get_starts() const; + + /** + * @brief Get number of rows + * + * @return size_t number of rows + */ + size_t dim1() const; + + /** + * @brief Get number of columns + * + * @return size_t number of columns + */ + size_t dim2() const; + + /** + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + T* begin(size_t i); + + /** + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + T* end(size_t i); + + // iterator for the raw data at row i + // i.e. return the index each element is the index in the 1 array + // This as the use of providing a reasonable way to get the column + // index and data value in the case you need both + size_t begin_index(size_t i); + size_t end_index(size_t i); + + /** + * @brief Get the number of non zero elements in row i + * + * @param i : row to get + * @return size_t : size of row + */ + size_t nnz(size_t i); + /** + * @brief Get number of non zero elements total in array + * + * @return size_t + */ + size_t nnz(); + + // Use the index into the 1d array to get what value is stored there and what is the + // corresponding row + T& get_val_flat(size_t k); + size_t get_row_flat(size_t k); + // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to + int flat_index(size_t i, size_t j); + // Convertor + int toCSR(CArray& data, CArray& row_ptrs, CArray& col_ptrs); + void to_dense(FArray& A); + + // set values to input + void set_values(T val); + + // destructor + ~CSCArray(); }; -template -CSCArray::CSCArray(){ +template +CSCArray::CSCArray() { dim1_ = dim2_ = nnz_ = 0; - array_ = NULL; + array_ = NULL; row_index_ = start_index_ = NULL; } template -CSCArray::CSCArray(CArray array, CArray row_index, CArray start_index, size_t dim1, size_t dim2 ){ - dim1_ = dim1; - dim2_ = dim2; - size_t nnz = array.size(); - start_index_ = std::shared_ptr (new size_t[dim2_ + 1]); - array_ = std::shared_ptr (new T[nnz+1]); - row_index_ = std::shared_ptr (new size_t[nnz]); - size_t i ; - for(i = 0; i < nnz; i++){ - array_[i] = array(i); +CSCArray::CSCArray(CArray array, CArray row_index, CArray start_index, size_t dim1, size_t dim2) { + dim1_ = dim1; + dim2_ = dim2; + size_t nnz = array.size(); + start_index_ = std::shared_ptr(new size_t[dim2_ + 1]); + array_ = std::shared_ptr(new T[nnz + 1]); + row_index_ = std::shared_ptr(new size_t[nnz]); + size_t i; + for (i = 0; i < nnz; i++) { + array_[i] = array(i); row_index_[i] = row_index(i); } - for(i = 0; i < dim2_ + 1; i++){ + for (i = 0; i < dim2_ + 1; i++) { start_index_[i] = start_index(i); } nnz_ = nnz; } - -template +template T& CSCArray::operator()(size_t i, size_t j) const { size_t col_start = start_index_[j]; - size_t col_end = start_index_[j + 1]; + size_t col_end = start_index_[j + 1]; size_t k; - for(k =0; k < col_end - col_start;k++){ - if(row_index_[col_start + k] == i){ - return array_[col_start + k]; + for (k = 0; k < col_end - col_start; k++) { + if (row_index_[col_start + k] == i) { + return array_[col_start + k]; } } - array_[nnz_] = (T) NULL; + array_[nnz_] = (T)NULL; return array_[nnz_]; } -template +template T* CSCArray::pointer() const { return array_.get(); } -template +template T& CSCArray::value(size_t i, size_t j) const { size_t col_start = start_index_[j]; - size_t col_end = start_index_[j + 1]; + size_t col_end = start_index_[j + 1]; size_t k; - for(k =0; k < col_end - col_start;k++){ - if(row_index_[col_start + k] == i){ - return array_[col_start + k]; + for (k = 0; k < col_end - col_start; k++) { + if (row_index_[col_start + k] == i) { + return array_[col_start + k]; } } - array_[nnz_] = (T) NULL; + array_[nnz_] = (T)NULL; return array_[nnz_]; } -template -size_t* CSCArray::get_starts() const{ +template +size_t* CSCArray::get_starts() const { return &start_index_[0]; } -template -CSCArray& CSCArray::operator=(const CSCArray &temp){ - if(this != temp) { - nnz_ = temp.nnz_; +template +CSCArray& CSCArray::operator=(const CSCArray& temp) { + if (this != temp) { + nnz_ = temp.nnz_; dim2_ = temp.dim2_; dim1_ = temp.dim1_; - + start_index_ = temp.start_index_; - row_index_ = temp.row_index_; - array_ = temp.array_; + row_index_ = temp.row_index_; + array_ = temp.array_; } return *this; } -template -size_t CSCArray::stride(size_t i) const{ +template +size_t CSCArray::stride(size_t i) const { assert(i < dim2_ && "i is out of bounds in CSCArray.stride()"); - return start_index_[i+1] - start_index_[i]; + return start_index_[i + 1] - start_index_[i]; } - -template -void CSCArray::to_dense(FArray& A){ - size_t i,j; - for (j = 0; j < dim2_; j++) - { - for(i = 0; i < dim1_; i++){ - A(i,j) = (*this)(i,j); +template +void CSCArray::to_dense(FArray& A) { + size_t i, j; + for (j = 0; j < dim2_; j++) { + for (i = 0; i < dim1_; i++) { + A(i, j) = (*this)(i, j); } } } -template +template size_t CSCArray::dim1() const { return dim1_; } -template -size_t CSCArray::dim2() const{ +template +size_t CSCArray::dim2() const { return dim2_; } -template -T* CSCArray::begin(size_t i){ +template +T* CSCArray::begin(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.begin()"); size_t col_start = start_index_[i]; return &array_[col_start]; } -template -T* CSCArray::end(size_t i){ +template +T* CSCArray::end(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.endt()"); - size_t col_start = start_index_[i+1]; + size_t col_start = start_index_[i + 1]; return &array_[col_start]; } -template -size_t CSCArray::begin_index(size_t i){ +template +size_t CSCArray::begin_index(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.begin_index()"); return start_index_[i]; } -template -size_t CSCArray::end_index(size_t i){ +template +size_t CSCArray::end_index(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.end_index()"); return start_index_[i + 1]; } -template -size_t CSCArray::nnz(){ +template +size_t CSCArray::nnz() { return nnz_; } -template -size_t CSCArray::nnz(size_t i){ - return start_index_[i+1] - start_index_[i]; +template +size_t CSCArray::nnz(size_t i) { + return start_index_[i + 1] - start_index_[i]; } -template -T& CSCArray::get_val_flat(size_t k){ +template +T& CSCArray::get_val_flat(size_t k) { return array_[k]; } -template -size_t CSCArray::get_row_flat(size_t k){ +template +size_t CSCArray::get_row_flat(size_t k) { return row_index_[k]; } -template -int CSCArray::flat_index(size_t i, size_t j){ +template +int CSCArray::flat_index(size_t i, size_t j) { size_t col_start = start_index_[j]; - size_t col_end = start_index_[j+1]; + size_t col_end = start_index_[j + 1]; size_t k; - for (k = 0; k < col_end - col_start; k++) - { - if(row_index_[col_start + k] == i){ - return col_start + k; + for (k = 0; k < col_end - col_start; k++) { + if (row_index_[col_start + k] == i) { + return col_start + k; } } - return -1; + return -1; } // Assumes that data, col_ptrs, and row_ptrs // have been allocated size already before this call // Returns the data in this csr format but as represented as the appropriatte vectors // for a csc format -template -int CSCArray::toCSR(CArray &data, CArray &col_ptrs, CArray &row_ptrs ){ +template +int CSCArray::toCSR(CArray& data, CArray& col_ptrs, CArray& row_ptrs) { int nnz_rows[dim1_ + 1]; int row_counts[dim1_]; int i = 0; // How many elements are each column - for(i =0 ; i < dim1_; i++){ - nnz_rows[i] = 0; + for (i = 0; i < dim1_; i++) { + nnz_rows[i] = 0; row_counts[i] = 0; } nnz_rows[dim1_] = 0; - row_ptrs(i) = 0 ; - for(i =0; i < nnz_; i++){ + row_ptrs(i) = 0; + for (i = 0; i < nnz_; i++) { nnz_rows[row_index_[i] + 1] += 1; } // What we actually care about is how many elements are // in all the columns preceeding this column. - for(i = 1; i < dim1_; i++){ - nnz_rows[i] = nnz_rows[i-1] + nnz_rows[i]; + for (i = 1; i < dim1_; i++) { + nnz_rows[i] = nnz_rows[i - 1] + nnz_rows[i]; row_ptrs(i) = nnz_rows[i]; } size_t col = 1; @@ -5362,13 +4348,13 @@ int CSCArray::toCSR(CArray &data, CArray &col_ptrs, CArray // we allocated for this column already // For row we simply keep track of what row we are currently in // as we scan through the 1d array of data. - for(i = 0; i < nnz_; i++){ - if(i >= start_index_[col]){ + for (i = 0; i < nnz_; i++) { + if (i >= start_index_[col]) { col++; } int idx = nnz_rows[row_index_[i]] + row_counts[row_index_[i]]; row_counts[row_index_[i]] += 1; - data(idx) = array_[i]; + data(idx) = array_[i]; col_ptrs(idx) = col - 1; } // I return an int because I thought I might need to return an error code @@ -5378,7 +4364,7 @@ int CSCArray::toCSR(CArray &data, CArray &col_ptrs, CArray template void CSCArray::set_values(T val) { - for(int i = 0; i < nnz_; i++) { + for (int i = 0; i < nnz_; i++) { array_[i] = val; } } @@ -5393,26 +4379,20 @@ CSCArray::~CSCArray() {} //////////////////////////////////////////////// class OperatorFunctor { - public: - - OperatorFunctor(){} + OperatorFunctor() {} // Method that update device view virtual void apply_function(void* Y) const {} // Deconstructor - ~OperatorFunctor (){} -}; // End of TpetraCRSMatrix - + ~OperatorFunctor() {} +}; // End of TpetraCRSMatrix //======================================================================= // end of standard MATAR data-types //======================================================================== +} // namespace mtr -} // end namespace - - - -#endif // HOST_TYPES_H +#endif // HOST_TYPES_H diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 2c993502..ab945eba 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -13,14 +13,14 @@ This program is open source under the BSD-3 License. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -43,11 +43,11 @@ #include #include -using HostSpace = Kokkos::HostSpace; +using HostSpace = Kokkos::HostSpace; using MemoryUnmanaged = Kokkos::MemoryUnmanaged; #ifdef HAVE_CUDA -//using UVMMemSpace = Kokkos::CudaUVMSpace; +// using UVMMemSpace = Kokkos::CudaUVMSpace; using DefaultMemSpace = Kokkos::CudaSpace; using DefaultExecSpace = Kokkos::Cuda; using DefaultLayout = Kokkos::LayoutLeft; @@ -69,52 +69,47 @@ using DefaultMemSpace = Kokkos::DefaultExecutionSpace::memory_space; using DefaultLayout = Kokkos::LayoutLeft; #endif - -//MACROS to make the code less scary -#define kmalloc(size) ( Kokkos::kokkos_malloc(size) ) -#define kfree(pnt) ( Kokkos::kokkos_free(pnt) ) -#define ProfileRegionStart ( Kokkos::Profiling::pushRegion ) -#define ProfileRegionEnd ( Kokkos::Profiling::popRegion ) +// MACROS to make the code less scary +#define kmalloc(size) (Kokkos::kokkos_malloc(size)) +#define kfree(pnt) (Kokkos::kokkos_free(pnt)) +#define ProfileRegionStart (Kokkos::Profiling::pushRegion) +#define ProfileRegionEnd (Kokkos::Profiling::popRegion) #define DEFAULTSTRINGARRAY "array_" #define DEFAULTSTRINGMATRIX "matrix_" using policy1D = Kokkos::RangePolicy; -using policy2D = Kokkos::MDRangePolicy< Kokkos::Rank<2> >; -using policy3D = Kokkos::MDRangePolicy< Kokkos::Rank<3> >; -using policy4D = Kokkos::MDRangePolicy< Kokkos::Rank<4> >; +using policy2D = Kokkos::MDRangePolicy >; +using policy3D = Kokkos::MDRangePolicy >; +using policy4D = Kokkos::MDRangePolicy >; using TeamPolicy = Kokkos::TeamPolicy; -//using mdrange_policy2 = Kokkos::MDRangePolicy>; -//using mdrange_policy3 = Kokkos::MDRangePolicy>; - -using RMatrix1D = Kokkos::View; -using RMatrix2D = Kokkos::View; -using RMatrix3D = Kokkos::View; -using RMatrix4D = Kokkos::View; -using RMatrix5D = Kokkos::View; -using IMatrix1D = Kokkos::View; -using IMatrix2D = Kokkos::View; -using IMatrix3D = Kokkos::View; -using IMatrix4D = Kokkos::View; -using IMatrix5D = Kokkos::View; -using SVar = Kokkos::View; -using SArray2D = Kokkos::View; -using SArray3D = Kokkos::View; -using SArray4D = Kokkos::View; -using SArray5D = Kokkos::View; - -using SHArray1D = Kokkos::View; +// using mdrange_policy2 = Kokkos::MDRangePolicy>; +// using mdrange_policy3 = Kokkos::MDRangePolicy>; + +using RMatrix1D = Kokkos::View; +using RMatrix2D = Kokkos::View; +using RMatrix3D = Kokkos::View; +using RMatrix4D = Kokkos::View; +using RMatrix5D = Kokkos::View; +using IMatrix1D = Kokkos::View; +using IMatrix2D = Kokkos::View; +using IMatrix3D = Kokkos::View; +using IMatrix4D = Kokkos::View; +using IMatrix5D = Kokkos::View; +using SVar = Kokkos::View; +using SArray2D = Kokkos::View; +using SArray3D = Kokkos::View; +using SArray4D = Kokkos::View; +using SArray5D = Kokkos::View; + +using SHArray1D = Kokkos::View; #endif -//To disable asserts, uncomment the following line -//#define NDEBUG - - - +// To disable asserts, uncomment the following line +// #define NDEBUG #ifdef HAVE_KOKKOS -namespace mtr -{ +namespace mtr { /*! \brief Kokkos version of the serial FArray class. * @@ -123,12 +118,10 @@ namespace mtr * used in Kokkos-specific code. */ - template class FArrayKokkos { + using TArray1D = Kokkos::View; - using TArray1D = Kokkos::View; - private: size_t dims_[7]; size_t order_; @@ -136,7 +129,6 @@ class FArrayKokkos { TArray1D this_array_; public: - /*! * \brief Default constructor */ @@ -169,85 +161,63 @@ class FArrayKokkos { */ FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - FArrayKokkos(size_t dim0, size_t sone_dim2, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + FArrayKokkos(size_t dim0, size_t sone_dim2, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string = DEFAULTSTRINGARRAY); + + FArrayKokkos(size_t dim0, size_t sone_dim2, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - FArrayKokkos(size_t dim0, size_t sone_dim2, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - // Overload operator() to acces data // from 1D to 6D - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k, - size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k, - size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n, size_t o) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; // Overload = operator - KOKKOS_INLINE_FUNCTION - FArrayKokkos& operator= (const FArrayKokkos &temp); + KOKKOS_INLINE_FUNCTION FArrayKokkos& operator=(const FArrayKokkos& temp); - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; - - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t size() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val); - - //return kokkos view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + + // return kokkos view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; // Destructor - KOKKOS_INLINE_FUNCTION - ~FArrayKokkos(); + KOKKOS_INLINE_FUNCTION ~FArrayKokkos(); -}; //end of FArrayKokkos declarations +}; // end of FArrayKokkos declarations // Default constructor template -FArrayKokkos::FArrayKokkos() { +FArrayKokkos::FArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -256,113 +226,101 @@ FArrayKokkos::FArrayKokkos() { // Overloaded 1D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, const std::string& tag_string){ +FArrayKokkos::FArrayKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; - dims_[0] = dim0; - order_ = 1; - length_ = dim0; - this_array_ = TArray1D(tag_string, length_); + dims_[0] = dim0; + order_ = 1; + length_ = dim0; + this_array_ = TArray1D(tag_string, length_); } // Overloaded 2D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); + + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = TArray1D(tag_string, length_); } // Overloaded 3D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = TArray1D(tag_string, length_); } // Overloaded 4D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = TArray1D(tag_string, length_); } // Overloaded 5D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = TArray1D(tag_string, length_); } // Overloaded 6D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = TArray1D(tag_string, length_); } // Overloaded 7D constructor template -FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - +FArrayKokkos::FArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); } @@ -372,8 +330,7 @@ FArrayKokkos::FArrayKokkos(size_t dim0, size_t // 1D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()( size_t i) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in FArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 1D!"); return this_array_(i); @@ -381,8 +338,7 @@ T& FArrayKokkos::operator()( size_t i) const { // 2D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in FArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 2D!"); @@ -391,52 +347,42 @@ T& FArrayKokkos::operator()(size_t i, size_t j) // 3D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in FArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in FArrayKokkos 3D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1])); } // 4D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in FArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in FArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in FArrayKokkos 4D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2])); } // 5D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in FArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in FArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in FArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in FArrayKokkos 5D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } // 6D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in FArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 6D!"); @@ -444,18 +390,14 @@ T& FArrayKokkos::operator()(size_t i, size_t j, assert(l < dims_[3] && "l is out of bounds in FArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in FArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in FArrayKokkos 6D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); } // 7D template -KOKKOS_INLINE_FUNCTION -T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& FArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in FArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in FArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in FArrayKokkos 7D!"); @@ -464,91 +406,78 @@ T& FArrayKokkos::operator()(size_t i, size_t j, assert(m < dims_[4] && "m is out of bounds in FArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in FArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in FArrayKokkos 7D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); } // Overload = operator // for object assingment THIS = FArrayKokkos<> TEMP(n,m,,,,) template -KOKKOS_INLINE_FUNCTION -FArrayKokkos& FArrayKokkos::operator= (const FArrayKokkos& temp) { +KOKKOS_INLINE_FUNCTION FArrayKokkos& FArrayKokkos::operator=( + const FArrayKokkos& temp) { using TArray1D = Kokkos::View; - + if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; } return *this; } template -KOKKOS_INLINE_FUNCTION -size_t FArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t FArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t FArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t FArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t FArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t FArrayKokkos::dims(size_t i) const { assert(i < order_ && "FArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to FArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to FArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t FArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t FArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* FArrayKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* FArrayKokkos::pointer() const { return this_array_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View FArrayKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View FArrayKokkos::get_kokkos_view() const { return this_array_; } // Get the name of the view template -const std::string FArrayKokkos::get_name() const{ +const std::string FArrayKokkos::get_name() const { return this_array_.label(); } - // set values of array template -void FArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_FArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); +void FArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_FArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } // Destructor template -KOKKOS_INLINE_FUNCTION -FArrayKokkos::~FArrayKokkos() {} +KOKKOS_INLINE_FUNCTION FArrayKokkos::~FArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of FArrayKokkos @@ -559,7 +488,6 @@ FArrayKokkos::~FArrayKokkos() {} */ template class ViewFArrayKokkos { - private: size_t dims_[7]; size_t order_; @@ -567,89 +495,58 @@ class ViewFArrayKokkos { T* this_array_; public: - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(); + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(); - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0); - - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1); + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0); - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2); - - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3); - - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4); - - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5); - - KOKKOS_INLINE_FUNCTION - ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, size_t dim6); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, - size_t l) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, - size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n) const; + KOKKOS_INLINE_FUNCTION ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n, size_t o) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION size_t size() const; + + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values on host to input void set_values(T val); - KOKKOS_INLINE_FUNCTION - ~ViewFArrayKokkos(); + KOKKOS_INLINE_FUNCTION ~ViewFArrayKokkos(); -}; // End of ViewFArrayKokkos declarations +}; // End of ViewFArrayKokkos declarations // Default constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos() { +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos() { length_ = order_ = 0; - this_array_ = nullptr; + this_array_ = nullptr; for (int i = 0; i < 7; i++) { dims_[i] = 0; } @@ -657,170 +554,144 @@ ViewFArrayKokkos::ViewFArrayKokkos() { // Overloaded 1D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0) { - dims_[0] = dim0; - order_ = 1; - length_ = dim0; +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0) { + dims_[0] = dim0; + order_ = 1; + length_ = dim0; this_array_ = some_array; } // Overloaded 2D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1) { - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1) { + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = some_array; } // Overloaded 3D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1, - size_t dim2) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = some_array; } // Overloaded 4D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = some_array; } // Overloaded 5D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = some_array; } // Overloaded 6D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4, - size_t dim5) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = some_array; } // Overloaded 7D constructor template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::ViewFArrayKokkos(T *some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4, - size_t dim5, size_t dim6) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::ViewFArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = some_array; } // Overloaded operator() for 1D array access template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 1D!"); return this_array_[i]; } -//2D +// 2D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 2D!"); return this_array_[i + (j * dims_[0])]; } -//3D +// 3D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArrayKokkos 3D!"); - return this_array_[i + (j * dims_[0]) - + (k * dims_[0] * dims_[1])]; + return this_array_[i + (j * dims_[0]) + (k * dims_[0] * dims_[1])]; } -//4D +// 4D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, - size_t l) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in ViewFArrayKokkos 4D!"); - return this_array_[i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] *dims_[2])]; + return this_array_[i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2])]; } -//5D +// 5D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, - size_t l, size_t m) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in ViewFArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in ViewFArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in ViewFArrayKokkos 5D!"); - return this_array_[i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; + return this_array_[i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; } -//6D +// 6D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 6D!"); @@ -828,19 +699,13 @@ T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, assert(l < dims_[3] && "l is out of bounds in ViewFArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in ViewFArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in ViewFArrayKokkos 6D!"); - return this_array_[i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; + return this_array_[i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; } -//7D +// 7D template -KOKKOS_INLINE_FUNCTION -T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, - size_t l, size_t m, size_t n, - size_t o) const { +KOKKOS_INLINE_FUNCTION T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewFArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in ViewFArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in ViewFArrayKokkos 7D!"); @@ -849,56 +714,45 @@ T& ViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, assert(m < dims_[4] && "m is out of bounds in ViewFArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in ViewFArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in ViewFArrayKokkos 7D!"); - return this_array_[i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; + return this_array_[i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t ViewFArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t ViewFArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t ViewFArrayKokkos::dims(size_t i) const { assert(i < order_ && "ViewFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewFArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewFArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t ViewFArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* ViewFArrayKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* ViewFArrayKokkos::pointer() const { return this_array_; } template void ViewFArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_[i] = val; - }); + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_[i] = val; }); } template -KOKKOS_INLINE_FUNCTION -ViewFArrayKokkos::~ViewFArrayKokkos() {} +KOKKOS_INLINE_FUNCTION ViewFArrayKokkos::~ViewFArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of ViewFArrayKokkos @@ -909,11 +763,9 @@ ViewFArrayKokkos::~ViewFArrayKokkos() {} */ template class FMatrixKokkos { - using TArray1D = Kokkos::View; - -private: +private: size_t dims_[7]; size_t order_; size_t length_; @@ -928,78 +780,57 @@ class FMatrixKokkos { FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); - FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); - FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - FMatrixKokkos& operator=(const FMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION FMatrixKokkos& operator=(const FMatrixKokkos& temp); + + KOKKOS_INLINE_FUNCTION size_t size() const; + + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val); - - //return kokkos view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + + // return kokkos view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; - KOKKOS_INLINE_FUNCTION - ~FMatrixKokkos(); + KOKKOS_INLINE_FUNCTION ~FMatrixKokkos(); -}; // End of FMatrixKokkos +}; // End of FMatrixKokkos // Default constructor template -FMatrixKokkos::FMatrixKokkos() { +FMatrixKokkos::FMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -1008,122 +839,114 @@ FMatrixKokkos::FMatrixKokkos() { // Overloaded 1D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - order_ = 1; - length_ = dim1; + + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 2D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); + + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 3D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 4D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 5D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 5D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 5D constructor template -FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { +FMatrixKokkos::FMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = TArray1D(tag_string, length_); } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in FMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 1D!"); return this_matrix_((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in FMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 2D!"); @@ -1131,49 +954,39 @@ T& FMatrixKokkos::operator()(size_t i, size_t j } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in FMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrixKokkos in 3D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in FMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrixKokkos in 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrixKokkos in 4D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in FMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in FMatrixKokkos in 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrixKokkos in 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrixKokkos in 5D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in FMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 6D!"); @@ -1181,17 +994,13 @@ T& FMatrixKokkos::operator()(size_t i, size_t j assert(l >= 1 && l <= dims_[3] && "l is out of bounds in FMatrixKokkos in 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrixKokkos in 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in FMatrixKokkos in 6D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; } template -KOKKOS_INLINE_FUNCTION -T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& FMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in FMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in FMatrixKokkos in 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in FMatrixKokkos in 7D!"); @@ -1200,90 +1009,75 @@ T& FMatrixKokkos::operator()(size_t i, size_t j assert(m >= 1 && m <= dims_[4] && "m is out of bounds in FMatrixKokkos in 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in FMatrixKokkos in 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in FMatrixKokkos in 7D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; } template -KOKKOS_INLINE_FUNCTION -FMatrixKokkos& FMatrixKokkos::operator=(const FMatrixKokkos& temp) { +KOKKOS_INLINE_FUNCTION FMatrixKokkos& FMatrixKokkos::operator=( + const FMatrixKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_matrix_ = temp.this_matrix_; } return *this; } - - template -KOKKOS_INLINE_FUNCTION -size_t FMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t FMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t FMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t FMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t FMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t FMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "FMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to FMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to FMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t FMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t FMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* FMatrixKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* FMatrixKokkos::pointer() const { return this_matrix_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View FMatrixKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View FMatrixKokkos::get_kokkos_view() const { return this_matrix_; } // Get the name of the view template -const std::string FMatrixKokkos::get_name() const{ +const std::string FMatrixKokkos::get_name() const { return this_matrix_.label(); } - // set values of array template void FMatrixKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_FMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_matrix_(i) = val; - }); + Kokkos::parallel_for("SetValues_FMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; }); } template -KOKKOS_INLINE_FUNCTION -FMatrixKokkos::~FMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION FMatrixKokkos::~FMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of FMatrixKokkos @@ -1294,97 +1088,64 @@ FMatrixKokkos::~FMatrixKokkos() {} */ template class ViewFMatrixKokkos { - private: - size_t dims_[7]; size_t order_; size_t length_; T* this_matrix_; - + public: + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(); - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6); - - KOKKOS_INLINE_FUNCTION - ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, size_t dim7); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3); - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4); - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); + + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + + KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7); + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION size_t size() const; + + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values on host to input void set_values(T val); - KOKKOS_INLINE_FUNCTION - ~ViewFMatrixKokkos(); - -}; // end of ViewFMatrixKokkos + KOKKOS_INLINE_FUNCTION ~ViewFMatrixKokkos(); + +}; // end of ViewFMatrixKokkos // Default constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos() { +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos() { this_matrix_ = nullptr; length_ = order_ = 0; for (int i = 0; i < 7; i++) { @@ -1394,119 +1155,99 @@ ViewFMatrixKokkos::ViewFMatrixKokkos() { // Overloaded 1D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1) { - dims_[0] = dim1; - order_ = 1; - length_ = dim1; +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1) { + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = some_matrix; } // Overloaded 2D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2) { - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2) { + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = some_matrix; } // Overloaded 3D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2, size_t dim3) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = some_matrix; } // Overloaded 4D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = some_matrix; } // Overloaded 5D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = some_matrix; } // Overloaded 6D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = some_matrix; } // Overloaded 6D constructor template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, size_t dim7) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::ViewFMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, size_t dim7) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = some_matrix; } - template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 1D!"); return this_matrix_[(i - 1)]; } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 2D!"); @@ -1514,53 +1255,39 @@ T& ViewFMatrixKokkos::operator()(size_t i, size_t j) const { } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const -{ +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrixKokkos 3D!"); - - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])]; + + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, - size_t l) const { +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrixKokkos 4D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewFMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrixKokkos 5D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const -{ +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 6D!"); @@ -1568,18 +1295,12 @@ T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewFMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewFMatrixKokkos 6D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const -{ +KOKKOS_INLINE_FUNCTION T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewFMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewFMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewFMatrixKokkos 7D!"); @@ -1588,153 +1309,120 @@ T& ViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(m >= 1 && m <= dims_[4] && "m is out of bounds in ViewFMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in ViewFMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in ViewFMatrixKokkos 7D!"); - return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; + return this_matrix_[(i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t ViewFMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t ViewFMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t ViewFMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "ViewFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewFMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewFMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewFMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t ViewFMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* ViewFMatrixKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* ViewFMatrixKokkos::pointer() const { return this_matrix_; } template void ViewFMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_[i] = val; - }); + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_[i] = val; }); } template -KOKKOS_INLINE_FUNCTION -ViewFMatrixKokkos::~ViewFMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION ViewFMatrixKokkos::~ViewFMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of ViewFMatrixKokkos //////////////////////////////////////////////////////////////////////////////// - ///////////////////////// // DFArrayKokkos: Dual type for managing data on both CPU and GPU. ///////////////////////// template class DFArrayKokkos { - // this is manage using TArray1D = Kokkos::DualView; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) - bool lock_ = false; + bool lock_ = false; TArray1D this_array_; public: // Data member to access host view - ViewFArray host; + ViewFArray host; DFArrayKokkos(); - + DFArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); DFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DFArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DFArrayKokkos& operator=(const DFArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DFArrayKokkos& operator=(const DFArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Method that update host view void update_host(); @@ -1748,23 +1436,20 @@ class DFArrayKokkos { // Method that unlocks updates void unlock_update(); - // set values on host to input void set_values(T val); // Get the name of the view const std::string get_name() const; - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DFArrayKokkos (); + KOKKOS_INLINE_FUNCTION ~DFArrayKokkos(); -}; // End of DFArrayKokkos declarations +}; // End of DFArrayKokkos declarations // Default constructor template -DFArrayKokkos::DFArrayKokkos() { +DFArrayKokkos::DFArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -1773,124 +1458,109 @@ DFArrayKokkos::DFArrayKokkos() { // Overloaded 1D constructor template -DFArrayKokkos::DFArrayKokkos(size_t dim0, const std::string& tag_string) { - - dims_[0] = dim0; - order_ = 1; - length_ = dim0; +DFArrayKokkos::DFArrayKokkos(size_t dim0, const std::string& tag_string) { + dims_[0] = dim0; + order_ = 1; + length_ = dim0; this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0); + host = ViewFArray(this_array_.view_host().data(), dim0); } // Overloaded 2D constructor template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1); } template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1, dim2); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1, dim2); } template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3); } template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4); } template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5); } template -DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +DFArrayKokkos::DFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); // Create host ViewFArray - host = ViewFArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewFArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DFArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 1D!"); return this_array_.view_device()(i); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DFArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 2D!"); @@ -1898,49 +1568,39 @@ T& DFArrayKokkos::operator()(size_t i, size_t j } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DFArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in DFArrayKokkos 3D!"); - return this_array_.view_device()(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1])); + return this_array_.view_device()(i + (j * dims_[0]) + (k * dims_[0] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DFArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DFArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DFArrayKokkos 4D!"); - return this_array_.view_device()(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2])); + return this_array_.view_device()(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2])); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DFArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DFArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DFArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in DFArrayKokkos 5D!"); - return this_array_.view_device()(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_array_.view_device()(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DFArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 6D!"); @@ -1948,17 +1608,13 @@ T& DFArrayKokkos::operator()(size_t i, size_t j assert(l < dims_[3] && "l is out of bounds in DFArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DFArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in DFArrayKokkos 6D!"); - return this_array_.view_device()(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); + return this_array_.view_device()(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); } template -KOKKOS_INLINE_FUNCTION -T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DFArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in DFArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DFArrayKokkos 7D!"); @@ -1967,75 +1623,65 @@ T& DFArrayKokkos::operator()(size_t i, size_t j assert(m < dims_[4] && "m is out of bounds in DFArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in DFArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in DFArrayKokkos 7D!"); - return this_array_.view_device()(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); + return this_array_.view_device()(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); } template -KOKKOS_INLINE_FUNCTION -DFArrayKokkos& DFArrayKokkos::operator= (const DFArrayKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DFArrayKokkos& DFArrayKokkos::operator=( + const DFArrayKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; - host = temp.host; - lock_ = temp.lock_; + host = temp.host; + lock_ = temp.lock_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DFArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DFArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DFArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DFArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DFArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DFArrayKokkos::dims(size_t i) const { assert(i < order_ && "DFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DFArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DFArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DFArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DFArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DFArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DFArrayKokkos::device_pointer() const { return this_array_.view_device().data(); } template -KOKKOS_INLINE_FUNCTION -T* DFArrayKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DFArrayKokkos::host_pointer() const { return this_array_.view_host().data(); } template -void DFArrayKokkos::update_host() { +void DFArrayKokkos::update_host() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_array_.template modify(); @@ -2043,7 +1689,7 @@ void DFArrayKokkos::update_host() { } template -void DFArrayKokkos::update_device() { +void DFArrayKokkos::update_device() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_array_.template modify(); @@ -2052,132 +1698,110 @@ void DFArrayKokkos::update_device() { // Get the name of the view template -const std::string DFArrayKokkos::get_name() const{ +const std::string DFArrayKokkos::get_name() const { return this_array_.view_device().label(); } template -void DFArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_.view_device()(i) = val; - }); +void DFArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_.view_device()(i) = val; }); } template -void DFArrayKokkos::lock_update() { +void DFArrayKokkos::lock_update() { lock_ = true; } template -void DFArrayKokkos::unlock_update() { +void DFArrayKokkos::unlock_update() { lock_ = false; } template -KOKKOS_INLINE_FUNCTION -DFArrayKokkos::~DFArrayKokkos() {} +KOKKOS_INLINE_FUNCTION DFArrayKokkos::~DFArrayKokkos() {} // End DFArrayKokkos - ///////////////////////// // DViewFArrayKokkos: The DView means dual view of the data, where data is on both CPU and GPU. // -// This MATAR type is for accepting a pointer to data on the CPU via the constructor and then it copies the data -// data to the GPU where the member functions and overloads access the data on the GPU. The corresponding -// FArrayKokkos type creates memory on the GPU; likewise, the viewFArrayKokkos accesses data already on the GPU. -// To emphasize, the data must be on the CPU prior to calling the constructor for the DView data type. +// This MATAR type is for accepting a pointer to data on the CPU via the constructor and then it +// copies the data data to the GPU where the member functions and overloads access the data on the +// GPU. The corresponding FArrayKokkos type creates memory on the GPU; likewise, the +// viewFArrayKokkos accesses data already on the GPU. To emphasize, the data must be on the CPU +// prior to calling the constructor for the DView data type. ///////////////////////// template class DViewFArrayKokkos { - // this is always unmanaged using TArray1DHost = Kokkos::View; // this is manage - using TArray1D = Kokkos::View; + using TArray1D = Kokkos::View; typename ExecSpace::memory_space memspace; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) TArray1D this_array_; TArray1DHost this_array_host_; - T * temp_inp_array_; + T* temp_inp_array_; public: DViewFArrayKokkos(); - - DViewFArrayKokkos(T * inp_array, size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewFArrayKokkos(T* inp_array, size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DViewFArrayKokkos& operator=(const DViewFArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DViewFArrayKokkos& operator=(const DViewFArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Data member to access host view - ViewFArray host; + ViewFArray host; // Method that update host view void update_host(); @@ -2185,25 +1809,21 @@ class DViewFArrayKokkos { // Method that update device view void update_device(); - // set values on host to input void set_values(T val); // Get the name of the view const std::string get_name() const; - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DViewFArrayKokkos (); -}; // End of DViewFArrayKokkos - + KOKKOS_INLINE_FUNCTION ~DViewFArrayKokkos(); +}; // End of DViewFArrayKokkos // Default constructor template -DViewFArrayKokkos::DViewFArrayKokkos() { +DViewFArrayKokkos::DViewFArrayKokkos() { length_ = order_ = 0; - temp_inp_array_ = NULL; + temp_inp_array_ = NULL; for (int i = 0; i < 7; i++) { dims_[i] = 0; } @@ -2211,13 +1831,13 @@ DViewFArrayKokkos::DViewFArrayKokkos() { // Overloaded 1D constructor template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, const std::string& tag_string) { - //using TArray1DHost = Kokkos::View; - //using TArray1D = Kokkos::View; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, const std::string& tag_string) { + // using TArray1DHost = Kokkos::View; + // using TArray1D = Kokkos::View; + dims_[0] = dim0; - order_ = 1; - length_ = dim0; + order_ = 1; + length_ = dim0; // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2225,20 +1845,20 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray. Note: inp_array and this_array_host_.data() are the same pointer - host = ViewFArray (inp_array, dim0); + host = ViewFArray(inp_array, dim0); } // Overloaded 2D constructor template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, const std::string& tag_string) { - //using TArray1DHost = Kokkos::View; - //using TArray1D = Kokkos::View; - //using TArray1Dtemp = TArray1D::HostMirror; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, const std::string& tag_string) { + // using TArray1DHost = Kokkos::View; + // using TArray1D = Kokkos::View; + // using TArray1Dtemp = TArray1D::HostMirror; + dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); + order_ = 2; + length_ = (dim0 * dim1); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2246,19 +1866,19 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1); + host = ViewFArray(inp_array, dim0, dim1); } template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, + const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); + order_ = 3; + length_ = (dim0 * dim1 * dim2); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2266,20 +1886,20 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1, dim2); + host = ViewFArray(inp_array, dim0, dim1, dim2); } template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2287,23 +1907,21 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1, dim2, dim3); + host = ViewFArray(inp_array, dim0, dim1, dim2, dim3); } template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + // using TArray1D = Kokkos::View; - //using TArray1D = Kokkos::View; - dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2311,23 +1929,22 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1, dim2, dim3, dim4); + host = ViewFArray(inp_array, dim0, dim1, dim2, dim3, dim4); } template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2335,16 +1952,14 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1, dim2, dim3, dim4, dim5); + host = ViewFArray(inp_array, dim0, dim1, dim2, dim3, dim4, dim5); } template -DViewFArrayKokkos::DViewFArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewFArrayKokkos::DViewFArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -2352,8 +1967,8 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in @@ -2361,20 +1976,18 @@ DViewFArrayKokkos::DViewFArrayKokkos(T * inp_ar // Create a device copy of that host view this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewFArray - host = ViewFArray (inp_array, dim0, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewFArray(inp_array, dim0, dim1, dim2, dim3, dim4, dim5, dim6); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 1D!"); return this_array_(i); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 2D!"); @@ -2382,49 +1995,39 @@ T& DViewFArrayKokkos::operator()(size_t i, size } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in DViewFArrayKokkos 3D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DViewFArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DViewFArrayKokkos 4D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DViewFArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DViewFArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in DViewFArrayKokkos 5D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 6D!"); @@ -2432,17 +2035,13 @@ T& DViewFArrayKokkos::operator()(size_t i, size assert(l < dims_[3] && "l is out of bounds in DViewFArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DViewFArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in DViewFArrayKokkos 6D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DViewFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DViewFArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in DViewFArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DViewFArrayKokkos 7D!"); @@ -2451,195 +2050,160 @@ T& DViewFArrayKokkos::operator()(size_t i, size assert(m < dims_[4] && "m is out of bounds in DViewFArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in DViewFArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in DViewFArrayKokkos 7D!"); - return this_array_(i + (j * dims_[0]) - + (k * dims_[0] * dims_[1]) - + (l * dims_[0] * dims_[1] * dims_[2]) - + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); + return this_array_(i + (j * dims_[0]) + (k * dims_[0] * dims_[1]) + (l * dims_[0] * dims_[1] * dims_[2]) + + (m * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + (n * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + (o * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); } template -KOKKOS_INLINE_FUNCTION -DViewFArrayKokkos& DViewFArrayKokkos::operator= (const DViewFArrayKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DViewFArrayKokkos& DViewFArrayKokkos::operator=( + const DViewFArrayKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; - temp_inp_array_ = temp.temp_inp_array_; + order_ = temp.order_; + length_ = temp.length_; + temp_inp_array_ = temp.temp_inp_array_; this_array_host_ = temp.this_array_host_; - this_array_ = temp.this_array_; - host = temp.host; + this_array_ = temp.this_array_; + host = temp.host; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DViewFArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DViewFArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DViewFArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DViewFArrayKokkos::dims(size_t i) const { assert(i < order_ && "DViewFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DViewFArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DViewFArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DViewFArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DViewFArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewFArrayKokkos::device_pointer() const { return this_array_.data(); } template -KOKKOS_INLINE_FUNCTION -T* DViewFArrayKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewFArrayKokkos::host_pointer() const { return this_array_host_.data(); } template -void DViewFArrayKokkos::update_host() { +void DViewFArrayKokkos::update_host() { // Deep copy of device view to host view deep_copy(this_array_host_, this_array_); } template -void DViewFArrayKokkos::update_device() { +void DViewFArrayKokkos::update_device() { // Deep copy of host view to device view deep_copy(this_array_, this_array_host_); } // Get the name of the view template -const std::string DViewFArrayKokkos::get_name() const{ +const std::string DViewFArrayKokkos::get_name() const { return this_array_.label(); } template -void DViewFArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_(i) = val; - }); +void DViewFArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template -KOKKOS_INLINE_FUNCTION -DViewFArrayKokkos::~DViewFArrayKokkos() {} +KOKKOS_INLINE_FUNCTION DViewFArrayKokkos::~DViewFArrayKokkos() {} // End DViewFArrayKokkos - ///////////////////////// // DFMatrixKokkos ///////////////////////// template class DFMatrixKokkos { - // this is manage using TArray1D = Kokkos::DualView; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) - bool lock_ = false; + bool lock_ = false; TArray1D this_matrix_; public: DFMatrixKokkos(); - + DFMatrixKokkos(size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); DFMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DFMatrixKokkos (size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DFMatrixKokkos& operator=(const DFMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DFMatrixKokkos& operator=(const DFMatrixKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Data member to access host view - ViewFMatrix host; + ViewFMatrix host; // Method that update host view void update_host(); @@ -2653,22 +2217,19 @@ class DFMatrixKokkos { // Method that unlocks updates void unlock_update(); - // set values on host to input void set_values(T val); // Get the name of the view const std::string get_name() const; - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DFMatrixKokkos (); -}; // End of DFMatrixKokkos declarations + KOKKOS_INLINE_FUNCTION ~DFMatrixKokkos(); +}; // End of DFMatrixKokkos declarations // Default constructor template -DFMatrixKokkos::DFMatrixKokkos() { +DFMatrixKokkos::DFMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -2677,124 +2238,110 @@ DFMatrixKokkos::DFMatrixKokkos() { // Overloaded 1D constructor template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, const std::string& tag_string) { - - dims_[0] = dim1; - order_ = 1; - length_ = dim1; +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, const std::string& tag_string) { + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1); } // Overloaded 2D constructor template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2); } template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3); } template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4); } template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5); } template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6); } template -DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); +DFMatrixKokkos::DFMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewFMatrix - host = ViewFMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6, dim7); + host = ViewFMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6, dim7); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 1D!"); return this_matrix_.view_device()((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 2D!"); @@ -2802,49 +2349,39 @@ T& DFMatrixKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DFMatrixKokkos 3D!"); - return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])); + return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DFMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DFMatrixKokkos 4D!"); - return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); + return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DFMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DFMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DFMatrixKokkos 5D!"); - return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 6D!"); @@ -2852,17 +2389,14 @@ T& DFMatrixKokkos::operator()(size_t i, size_t assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DFMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DFMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DFMatrixKokkos 6D!"); - return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); + return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); } template -KOKKOS_INLINE_FUNCTION -T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DFMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DFMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DFMatrixKokkos 7D!"); @@ -2871,76 +2405,67 @@ T& DFMatrixKokkos::operator()(size_t i, size_t assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DFMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DFMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in DFMatrixKokkos 7D!"); - return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); + return this_matrix_.view_device()((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); } template -KOKKOS_INLINE_FUNCTION -DFMatrixKokkos& DFMatrixKokkos::operator= (const DFMatrixKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DFMatrixKokkos& DFMatrixKokkos::operator=( + const DFMatrixKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_matrix_ = temp.this_matrix_; - host = temp.host; - lock_ = temp.lock_; + host = temp.host; + lock_ = temp.lock_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DFMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DFMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DFMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DFMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DFMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DFMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "DFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DFMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DFMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DFMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DFMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DFMatrixKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DFMatrixKokkos::device_pointer() const { return this_matrix_.view_device().data(); } template -KOKKOS_INLINE_FUNCTION -T* DFMatrixKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DFMatrixKokkos::host_pointer() const { return this_matrix_.view_host().data(); } template -void DFMatrixKokkos::update_host() { +void DFMatrixKokkos::update_host() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_matrix_.template modify(); @@ -2948,7 +2473,7 @@ void DFMatrixKokkos::update_host() { } template -void DFMatrixKokkos::update_device() { +void DFMatrixKokkos::update_device() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_matrix_.template modify(); @@ -2957,127 +2482,104 @@ void DFMatrixKokkos::update_device() { // Get the name of the view template -const std::string DFMatrixKokkos::get_name() const{ +const std::string DFMatrixKokkos::get_name() const { return this_matrix_.view_device().label(); } template -void DFMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_.view_device()(i) = val; - }); +void DFMatrixKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_.view_device()(i) = val; }); } template -void DFMatrixKokkos::lock_update() { +void DFMatrixKokkos::lock_update() { lock_ = true; } template -void DFMatrixKokkos::unlock_update() { +void DFMatrixKokkos::unlock_update() { lock_ = false; } template -KOKKOS_INLINE_FUNCTION -DFMatrixKokkos::~DFMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION DFMatrixKokkos::~DFMatrixKokkos() {} // End DFMatrixKokkos - ///////////////////////// // DViewFMatrixKokkos ///////////////////////// template class DViewFMatrixKokkos { - // this is always unmanaged using TArray1DHost = Kokkos::View; // this is manage - using TArray1D = Kokkos::View; + using TArray1D = Kokkos::View; typename ExecSpace::memory_space memspace; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) TArray1D this_matrix_; TArray1DHost this_matrix_host_; - T * temp_inp_matrix_; + T* temp_inp_matrix_; public: DViewFMatrixKokkos(); - - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DViewFMatrixKokkos& operator=(const DViewFMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DViewFMatrixKokkos& operator=(const DViewFMatrixKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Data member to access host view - ViewFMatrix host; + ViewFMatrix host; // Method that update host view void update_host(); @@ -3085,23 +2587,19 @@ class DViewFMatrixKokkos { // Method that update device view void update_device(); - // set values on host to input void set_values(T val); // Get the name of the view const std::string get_name() const; - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DViewFMatrixKokkos (); -}; // End of DViewFMatrixKokkos - + KOKKOS_INLINE_FUNCTION ~DViewFMatrixKokkos(); +}; // End of DViewFMatrixKokkos // Default constructor template -DViewFMatrixKokkos::DViewFMatrixKokkos() { +DViewFMatrixKokkos::DViewFMatrixKokkos() { length_ = order_ = 0; temp_inp_matrix_ = NULL; for (int i = 0; i < 7; i++) { @@ -3111,11 +2609,10 @@ DViewFMatrixKokkos::DViewFMatrixKokkos() { // Overloaded 1D constructor template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, const std::string& tag_string) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; + order_ = 1; + length_ = dim1; // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3123,17 +2620,16 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix. Note: inp_matrix and this_matrix_host_.data() are the same pointer - host = ViewFMatrix (inp_matrix, dim1); + host = ViewFMatrix(inp_matrix, dim1); } // Overloaded 2D constructor template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); + order_ = 2; + length_ = (dim1 * dim2); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3141,18 +2637,17 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2); + host = ViewFMatrix(inp_matrix, dim1, dim2); } template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, + const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); + order_ = 3; + length_ = (dim1 * dim2 * dim3); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3160,19 +2655,18 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2, dim3); + host = ViewFMatrix(inp_matrix, dim1, dim2, dim3); } template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3180,21 +2674,19 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2, dim3, dim4); + host = ViewFMatrix(inp_matrix, dim1, dim2, dim3, dim4); } template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3202,22 +2694,20 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5); + host = ViewFMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5); } template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3225,15 +2715,12 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewFMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6); } template -DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { - +DViewFMatrixKokkos::DViewFMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6, size_t dim7, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -3241,8 +2728,8 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -3250,20 +2737,18 @@ DViewFMatrixKokkos::DViewFMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewFMatrix - host = ViewFMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6, dim7); + host = ViewFMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6, dim7); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 1D!"); return this_matrix_((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 2D!"); @@ -3271,49 +2756,39 @@ T& DViewFMatrixKokkos::operator()(size_t i, siz } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewFMatrixKokkos 3D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewFMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewFMatrixKokkos 4D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewFMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewFMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewFMatrixKokkos 5D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 6D!"); @@ -3321,17 +2796,13 @@ T& DViewFMatrixKokkos::operator()(size_t i, siz assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewFMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewFMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DViewFMatrixKokkos 6D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4])); } template -KOKKOS_INLINE_FUNCTION -T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DViewFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DViewFMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewFMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewFMatrixKokkos 7D!"); @@ -3340,115 +2811,99 @@ T& DViewFMatrixKokkos::operator()(size_t i, siz assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewFMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DViewFMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in DViewFMatrixKokkos 7D!"); - return this_matrix_((i - 1) + ((j - 1) * dims_[0]) - + ((k - 1) * dims_[0] * dims_[1]) - + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) - + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) - + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) - + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); + return this_matrix_((i - 1) + ((j - 1) * dims_[0]) + ((k - 1) * dims_[0] * dims_[1]) + ((l - 1) * dims_[0] * dims_[1] * dims_[2]) + + ((m - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3]) + ((n - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4]) + + ((o - 1) * dims_[0] * dims_[1] * dims_[2] * dims_[3] * dims_[4] * dims_[5])); } template -KOKKOS_INLINE_FUNCTION -DViewFMatrixKokkos& DViewFMatrixKokkos::operator= (const DViewFMatrixKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DViewFMatrixKokkos& DViewFMatrixKokkos::operator=( + const DViewFMatrixKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; - temp_inp_matrix_ = temp.temp_inp_matrix_; + order_ = temp.order_; + length_ = temp.length_; + temp_inp_matrix_ = temp.temp_inp_matrix_; this_matrix_host_ = temp.this_matrix_host_; - this_matrix_ = temp.this_matrix_; - host = temp.host; + this_matrix_ = temp.this_matrix_; + host = temp.host; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DViewFMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DViewFMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DViewFMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DViewFMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "DViewFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DViewFMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DViewFMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DViewFMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DViewFMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DViewFMatrixKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewFMatrixKokkos::device_pointer() const { return this_matrix_.data(); } template -KOKKOS_INLINE_FUNCTION -T* DViewFMatrixKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewFMatrixKokkos::host_pointer() const { return this_matrix_host_.data(); } template -void DViewFMatrixKokkos::update_host() { +void DViewFMatrixKokkos::update_host() { // Deep copy of device view to host view deep_copy(this_matrix_host_, this_matrix_); } template -void DViewFMatrixKokkos::update_device() { +void DViewFMatrixKokkos::update_device() { // Deep copy of host view to device view deep_copy(this_matrix_, this_matrix_host_); } // Get the name of the view template -const std::string DViewFMatrixKokkos::get_name() const{ +const std::string DViewFMatrixKokkos::get_name() const { return this_matrix_.label(); } - template -void DViewFMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_(i) = val; - }); +void DViewFMatrixKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; }); } template -KOKKOS_INLINE_FUNCTION -DViewFMatrixKokkos::~DViewFMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION DViewFMatrixKokkos::~DViewFMatrixKokkos() {} // End DViewFMatrixKokkos - /*! \brief Kokkos version of the serial CArray class. * */ template class CArrayKokkos { - using TArray1D = Kokkos::View; - + private: size_t dims_[7]; size_t order_; @@ -3457,90 +2912,69 @@ class CArrayKokkos { public: CArrayKokkos(); - + CArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); CArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - CArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - CArrayKokkos& operator=(const CArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION CArrayKokkos& operator=(const CArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Methods returns the raw pointer (most likely GPU) of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~CArrayKokkos (); -}; // End of CArrayKokkos + KOKKOS_INLINE_FUNCTION ~CArrayKokkos(); +}; // End of CArrayKokkos // Default constructor template -CArrayKokkos::CArrayKokkos() { +CArrayKokkos::CArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -3549,118 +2983,109 @@ CArrayKokkos::CArrayKokkos() { // Overloaded 1D constructor template -CArrayKokkos::CArrayKokkos(size_t dim0, const std::string& tag_string) { +CArrayKokkos::CArrayKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - order_ = 1; - length_ = dim0; + + dims_[0] = dim0; + order_ = 1; + length_ = dim0; this_array_ = TArray1D(tag_string, length_); } // Overloaded 2D constructor template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); + + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = TArray1D(tag_string, length_); } template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = TArray1D(tag_string, length_); } template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = TArray1D(tag_string, length_); } template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { + using TArray1D = Kokkos::View; - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = TArray1D(tag_string, length_); } template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = TArray1D(tag_string, length_); } template -CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +CArrayKokkos::CArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in CArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 1D!"); return this_array_(i); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in CArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 2D!"); @@ -3668,49 +3093,39 @@ T& CArrayKokkos::operator()(size_t i, size_t j) } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in CArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in CArrayKokkos 3D!"); - return this_array_(k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])); + return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in CArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in CArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in CArrayKokkos 4D!"); - return this_array_(l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])); + return this_array_(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in CArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in CArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in CArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in CArrayKokkos 5D!"); - return this_array_(m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in CArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 6D!"); @@ -3718,17 +3133,13 @@ T& CArrayKokkos::operator()(size_t i, size_t j, assert(l < dims_[3] && "l is out of bounds in CArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in CArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in CArrayKokkos 6D!"); - return this_array_(n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& CArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in CArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in CArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in CArrayKokkos 7D!"); @@ -3737,90 +3148,78 @@ T& CArrayKokkos::operator()(size_t i, size_t j, assert(m < dims_[4] && "m is out of bounds in CArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in CArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in CArrayKokkos 7D!"); - return this_array_(o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -CArrayKokkos& CArrayKokkos::operator= (const CArrayKokkos& temp) { - using TArray1D = Kokkos::View; - +KOKKOS_INLINE_FUNCTION CArrayKokkos& CArrayKokkos::operator=( + const CArrayKokkos& temp) { + using TArray1D = Kokkos::View; + // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t CArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t CArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t CArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t CArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t CArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t CArrayKokkos::dims(size_t i) const { assert(i < order_ && "CArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to CArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to CArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t CArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t CArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* CArrayKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* CArrayKokkos::pointer() const { return this_array_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View CArrayKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View CArrayKokkos::get_kokkos_view() const { return this_array_; } // Get the name of the view template -const std::string CArrayKokkos::get_name() const{ +const std::string CArrayKokkos::get_name() const { return this_array_.label(); } // set values of array template -void CArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_CArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); +void CArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_CArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template -KOKKOS_INLINE_FUNCTION -CArrayKokkos::~CArrayKokkos() {} +KOKKOS_INLINE_FUNCTION CArrayKokkos::~CArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of CArrayKokkos @@ -3831,97 +3230,66 @@ CArrayKokkos::~CArrayKokkos() {} */ template class ViewCArrayKokkos { - private: size_t dims_[7]; size_t order_; size_t length_; // Length of 1D array T* this_array_; - + public: - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(); - - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0); + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(); - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1); + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0); - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, - size_t dim2); + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1); - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3); + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2); - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4); + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3); - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4, - size_t dim5); - - KOKKOS_INLINE_FUNCTION - ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, size_t dim4, - size_t dim5, size_t dim6);; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; - - KOKKOS_INLINE_FUNCTION - T& operator() (size_t i, size_t j, size_t k, size_t l, size_t m) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); + ; - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION size_t size() const; + + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values on host to input void set_values(T val); - KOKKOS_INLINE_FUNCTION - ~ViewCArrayKokkos(); - -}; // end of ViewCArrayKokkos + KOKKOS_INLINE_FUNCTION ~ViewCArrayKokkos(); + +}; // end of ViewCArrayKokkos // Default constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos() { +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos() { length_ = order_ = 0; - this_array_ = NULL; + this_array_ = NULL; for (int i = 0; i < 7; i++) { dims_[i] = 0; } @@ -3929,118 +3297,99 @@ ViewCArrayKokkos::ViewCArrayKokkos() { // Overloaded 1D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0) { - dims_[0] = dim0; - order_ = 1; - length_ = dim0; +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0) { + dims_[0] = dim0; + order_ = 1; + length_ = dim0; this_array_ = some_array; } // Overloaded 2D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1) { - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1) { + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = some_array; } // Overloaded 3D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1, size_t dim2) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = some_array; } // Overloaded 4D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1, size_t dim2, - size_t dim3) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = some_array; } // Overloaded 5D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1, size_t dim2, - size_t dim3, size_t dim4) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = some_array; } // Overloaded 6D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = some_array; } // Overloaded 7D constructor template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, - size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::ViewCArrayKokkos(T* some_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = some_array; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 1D!"); return this_array_[i]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 2D!"); @@ -4048,50 +3397,38 @@ T& ViewCArrayKokkos::operator()(size_t i, size_t j) const { } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in ViewCArrayKokkos 3D!"); - return this_array_[k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])]; + return this_array_[k + (j * dims_[2]) + (i * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, - size_t l) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in ViewCArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in ViewCArrayKokkos 4D!"); - return this_array_[l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])]; + return this_array_[l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in ViewCArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in ViewCArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in ViewCArrayKokkos 5D!"); - return this_array_[m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_array_[m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 6D!"); @@ -4099,17 +3436,12 @@ T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(l < dims_[3] && "l is out of bounds in ViewCArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in ViewCArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in ViewCArrayKokkos 6D!"); - return this_array_[n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_array_[n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewCArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in ViewCArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in ViewCArrayKokkos 7D!"); @@ -4118,56 +3450,45 @@ T& ViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(m < dims_[4] && "m is out of bounds in ViewCArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in ViewCArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in ViewCArrayKokkos 7D!"); - return this_array_[o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_array_[o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t ViewCArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t ViewCArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t ViewCArrayKokkos::dims(size_t i) const { assert(i < order_ && "ViewCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewCArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewCArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t ViewCArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* ViewCArrayKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* ViewCArrayKokkos::pointer() const { return this_array_; } template void ViewCArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_[i] = val; - }); + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_[i] = val; }); } template -KOKKOS_INLINE_FUNCTION -ViewCArrayKokkos::~ViewCArrayKokkos() {} +KOKKOS_INLINE_FUNCTION ViewCArrayKokkos::~ViewCArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of ViewCArrayKokkos @@ -4178,9 +3499,8 @@ ViewCArrayKokkos::~ViewCArrayKokkos() {} */ template class CMatrixKokkos { - using TArray1D = Kokkos::View; - + private: size_t dims_[7]; size_t order_; @@ -4196,78 +3516,57 @@ class CMatrixKokkos { CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); - CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); - CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - CMatrixKokkos& operator=(const CMatrixKokkos &temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; - KOKKOS_INLINE_FUNCTION - size_t size() const; - - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION CMatrixKokkos& operator=(const CMatrixKokkos& temp); + + KOKKOS_INLINE_FUNCTION size_t size() const; + + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val); - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; - KOKKOS_INLINE_FUNCTION - ~CMatrixKokkos(); + KOKKOS_INLINE_FUNCTION ~CMatrixKokkos(); -}; // End of CMatrixKokkos +}; // End of CMatrixKokkos // Default constructor template -CMatrixKokkos::CMatrixKokkos() { +CMatrixKokkos::CMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -4276,123 +3575,114 @@ CMatrixKokkos::CMatrixKokkos() { // Overloaded 1D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - order_ = 1; - length_ = dim1; + + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 2D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); + + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 3D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 4D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 5D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { - +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 6D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = TArray1D(tag_string, length_); } // Overloaded 7D constructor template -CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { +CMatrixKokkos::CMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7, const std::string& tag_string) { using TArray1D = Kokkos::View; - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); + + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = TArray1D(tag_string, length_); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in CMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 1D!"); return this_matrix_((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in CMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 2D!"); @@ -4400,49 +3690,39 @@ T& CMatrixKokkos::operator()(size_t i, size_t j } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in CMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrixKokkos 3D!"); - return this_matrix_((k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])); + return this_matrix_((k - 1) + ((j - 1) * dims_[2]) + ((i - 1) * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in CMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrixKokkos 4D!"); - return this_matrix_((l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((l - 1) + ((k - 1) * dims_[3]) + ((j - 1) * dims_[3] * dims_[2]) + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in CMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in CMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrixKokkos 5D!"); - return this_matrix_((m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((m - 1) + ((l - 1) * dims_[4]) + ((k - 1) * dims_[4] * dims_[3]) + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in CMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 6D!"); @@ -4450,17 +3730,13 @@ T& CMatrixKokkos::operator()(size_t i, size_t j assert(l >= 1 && l <= dims_[3] && "l is out of bounds in CMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in CMatrixKokkos 6D!"); - return this_matrix_((n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((n - 1) + ((m - 1) * dims_[5]) + ((l - 1) * dims_[5] * dims_[4]) + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& CMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in CMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in CMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in CMatrixKokkos 7D!"); @@ -4469,92 +3745,80 @@ T& CMatrixKokkos::operator()(size_t i, size_t j assert(m >= 1 && m <= dims_[4] && "m is out of bounds in CMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in CMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in CMatrixKokkos 7D!"); - return this_matrix_((o-1) + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((o - 1) + ((n - 1) * dims_[6]) + ((m - 1) * dims_[6] * dims_[5]) + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } // Overload = operator // for object assignment THIS = CMatrixKokkos <> temp template -KOKKOS_INLINE_FUNCTION -CMatrixKokkos & CMatrixKokkos::operator=(const CMatrixKokkos &temp) { +KOKKOS_INLINE_FUNCTION CMatrixKokkos& CMatrixKokkos::operator=( + const CMatrixKokkos& temp) { using TArray1D = Kokkos::View; - if( this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_matrix_ = temp.this_matrix_; } - + return *this; } template -KOKKOS_INLINE_FUNCTION -size_t CMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t CMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t CMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t CMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t CMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t CMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "CMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to CMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to CMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t CMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t CMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* CMatrixKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* CMatrixKokkos::pointer() const { return this_matrix_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View CMatrixKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View CMatrixKokkos::get_kokkos_view() const { return this_matrix_; } // Get the name of the view template -const std::string CMatrixKokkos::get_name() const{ +const std::string CMatrixKokkos::get_name() const { return this_matrix_.label(); } // set values of array template void CMatrixKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_CMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_matrix_(i) = val; - }); + Kokkos::parallel_for("SetValues_CMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; }); } // Deconstructor template -KOKKOS_INLINE_FUNCTION -CMatrixKokkos::~CMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION CMatrixKokkos::~CMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of CMatrixKokkos @@ -4565,7 +3829,6 @@ CMatrixKokkos::~CMatrixKokkos() {} */ template class ViewCMatrixKokkos { - private: size_t dims_[7]; size_t order_; @@ -4573,84 +3836,59 @@ class ViewCMatrixKokkos { T* this_matrix_; public: - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6); + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6); - KOKKOS_INLINE_FUNCTION - ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, size_t dim7); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j , size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k , size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t size() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; + + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values on host to input void set_values(T val); - KOKKOS_INLINE_FUNCTION - ~ViewCMatrixKokkos(); + KOKKOS_INLINE_FUNCTION ~ViewCMatrixKokkos(); -}; // End of ViewCMatrixKokkos +}; // End of ViewCMatrixKokkos // Default constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(){ +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos() { length_ = order_ = 0; - this_matrix_ = NULL; + this_matrix_ = NULL; for (int i = 0; i < 7; i++) { dims_[i] = 0; } @@ -4658,114 +3896,99 @@ ViewCMatrixKokkos::ViewCMatrixKokkos(){ // Overloaded 1D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1) { - dims_[0] = dim1; - order_ = 1; - length_ = dim1; +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1) { + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = some_matrix; } // Overloaded 2D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, - size_t dim2) { - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2) { + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = some_matrix; } // Overloaded 3D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = some_matrix; } // Overloaded 4D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = some_matrix; } // Overloaded 5D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = some_matrix; } // Overloaded 6D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = some_matrix; } // Overloaded 7D constructor template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, size_t dim7) { - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::ViewCMatrixKokkos(T* some_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, size_t dim7) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = some_matrix; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrixKokkos 1D!"); return this_matrix_[(i - 1)]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrixKokkos 2D!"); @@ -4773,49 +3996,38 @@ T& ViewCMatrixKokkos::operator()(size_t i, size_t j) const { } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewCMatrixKokkos 3D!"); - return this_matrix_[(k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])]; + return this_matrix_[(k - 1) + ((j - 1) * dims_[2]) + ((i - 1) * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j , size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in ViewCMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in ViewCMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in ViewCMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in ViewCMatrixKokkos 4D!"); - return this_matrix_[(l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])]; + return this_matrix_[(l - 1) + ((k - 1) * dims_[3]) + ((j - 1) * dims_[3] * dims_[2]) + ((i - 1) * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds for ViewCMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds for ViewCMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds for ViewCMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds for ViewCMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds for ViewCMatrixKokkos 5D!"); - return this_matrix_[(m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_matrix_[(m - 1) + ((l - 1) * dims_[4]) + ((k - 1) * dims_[4] * dims_[3]) + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds for ViewCMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds for ViewCMatrixKokkos 6D!"); @@ -4823,17 +4035,12 @@ T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(l >= 1 && l <= dims_[3] && "l is out of bounds for ViewCMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds for ViewCMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds for ViewCMatrixKokkos 6D!"); - return this_matrix_[(n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_matrix_[(n - 1) + ((m - 1) * dims_[5]) + ((l - 1) * dims_[5] * dims_[4]) + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } template -KOKKOS_INLINE_FUNCTION -T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in ViewCMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds for ViewCMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds for ViewCMatrixKokkos 7D!"); @@ -4842,58 +4049,46 @@ T& ViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, assert(m >= 1 && m <= dims_[4] && "m is out of bounds for ViewCMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds for ViewCMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds for ViewCMatrixKokkos 7D!"); - return this_matrix_[o + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; + return this_matrix_[o + ((n - 1) * dims_[6]) + ((m - 1) * dims_[6] * dims_[5]) + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])]; } - template -KOKKOS_INLINE_FUNCTION -size_t ViewCMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t ViewCMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t ViewCMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t ViewCMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "ViewCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to ViewCMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to ViewCMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t ViewCMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t ViewCMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* ViewCMatrixKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* ViewCMatrixKokkos::pointer() const { return this_matrix_; } template void ViewCMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_[i] = val; - }); + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_[i] = val; }); } template -KOKKOS_INLINE_FUNCTION -ViewCMatrixKokkos::~ViewCMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION ViewCMatrixKokkos::~ViewCMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of ViewCMatrixKokkos @@ -4904,95 +4099,73 @@ ViewCMatrixKokkos::~ViewCMatrixKokkos() {} ///////////////////////// template class DCArrayKokkos { - // this is manage - using TArray1D = Kokkos::DualView ; - + using TArray1D = Kokkos::DualView; + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) - bool lock_ = false; + bool lock_ = false; TArray1D this_array_; public: // Data member to access host view - ViewCArray host; + ViewCArray host; DCArrayKokkos(); - + DCArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); DCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DCArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DCArrayKokkos& operator=(const DCArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DCArrayKokkos& operator=(const DCArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Method returns kokkos dual view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_dual_view() const; + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_dual_view() const; // Get the name of the view const std::string get_name() const; @@ -5013,14 +4186,12 @@ class DCArrayKokkos { void set_values(T val); // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DCArrayKokkos (); -}; // End of DCArrayKokkos - + KOKKOS_INLINE_FUNCTION ~DCArrayKokkos(); +}; // End of DCArrayKokkos // Default constructor template -DCArrayKokkos::DCArrayKokkos() { +DCArrayKokkos::DCArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -5029,124 +4200,110 @@ DCArrayKokkos::DCArrayKokkos() { // Overloaded 1D constructor template -DCArrayKokkos::DCArrayKokkos(size_t dim0, const std::string& tag_string) { - dims_[0] = dim0; - order_ = 1; - length_ = dim0; +DCArrayKokkos::DCArrayKokkos(size_t dim0, const std::string& tag_string) { + dims_[0] = dim0; + order_ = 1; + length_ = dim0; this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0); + host = ViewCArray(this_array_.view_host().data(), dim0); } // Overloaded 2D constructor template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + order_ = 2; + length_ = (dim0 * dim1); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1); } template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + order_ = 3; + length_ = (dim0 * dim1 * dim2); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1, dim2); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1, dim2); } template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3); } template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4); } template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5); } template -DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +DCArrayKokkos::DCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); // Create host ViewCArray - host = ViewCArray (this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewCArray(this_array_.view_host().data(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DCArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 1D!"); return this_array_.view_device()(i); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DCArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 2D!"); @@ -5154,49 +4311,39 @@ T& DCArrayKokkos::operator()(size_t i, size_t j } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DCArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in DCArrayKokkos 3D!"); - return this_array_.view_device()(k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])); + return this_array_.view_device()(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DCArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DCArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DCArrayKokkos 4D!"); - return this_array_.view_device()(l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])); + return this_array_.view_device()(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DCArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DCArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DCArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in DCArrayKokkos 5D!"); - return this_array_.view_device()(m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_.view_device()(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DCArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 6D!"); @@ -5204,17 +4351,13 @@ T& DCArrayKokkos::operator()(size_t i, size_t j assert(l < dims_[3] && "l is out of bounds in DCArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DCArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in DCArrayKokkos 6D!"); - return this_array_.view_device()(n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_.view_device()(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DCArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in DCArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DCArrayKokkos 7D!"); @@ -5223,87 +4366,77 @@ T& DCArrayKokkos::operator()(size_t i, size_t j assert(m < dims_[4] && "m is out of bounds in DCArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in DCArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in DCArrayKokkos 7D!"); - return this_array_.view_device()(o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_.view_device()(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -DCArrayKokkos& DCArrayKokkos::operator= (const DCArrayKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DCArrayKokkos& DCArrayKokkos::operator=( + const DCArrayKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; - host = temp.host; - lock_ = temp.lock_; + host = temp.host; + lock_ = temp.lock_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DCArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DCArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DCArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DCArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DCArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DCArrayKokkos::dims(size_t i) const { assert(i < order_ && "DCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DCArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DCArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DCArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DCArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DCArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DCArrayKokkos::device_pointer() const { return this_array_.view_device().data(); } template -KOKKOS_INLINE_FUNCTION -T* DCArrayKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DCArrayKokkos::host_pointer() const { return this_array_.view_host().data(); } template -KOKKOS_INLINE_FUNCTION -Kokkos::DualView DCArrayKokkos::get_kokkos_dual_view() const { - return this_array_; +KOKKOS_INLINE_FUNCTION Kokkos::DualView DCArrayKokkos::get_kokkos_dual_view() + const { + return this_array_; } // Get the name of the view template -const std::string DCArrayKokkos::get_name() const{ +const std::string DCArrayKokkos::get_name() const { return this_array_.view_device().label(); } template -void DCArrayKokkos::update_host() { +void DCArrayKokkos::update_host() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_array_.template modify(); @@ -5311,7 +4444,7 @@ void DCArrayKokkos::update_host() { } template -void DCArrayKokkos::update_device() { +void DCArrayKokkos::update_device() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_array_.template modify(); @@ -5319,122 +4452,100 @@ void DCArrayKokkos::update_device() { } template -void DCArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_.view_device()(i) = val; - }); +void DCArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_.view_device()(i) = val; }); } template -void DCArrayKokkos::lock_update() { +void DCArrayKokkos::lock_update() { lock_ = true; } template -void DCArrayKokkos::unlock_update() { +void DCArrayKokkos::unlock_update() { lock_ = false; } template -DCArrayKokkos::~DCArrayKokkos() {} +DCArrayKokkos::~DCArrayKokkos() {} // End DCArrayKokkos - ///////////////////////// // DViewCArrayKokkos ///////////////////////// template class DViewCArrayKokkos { - // this is always unmanaged using TArray1DHost = Kokkos::View; // this is manage - using TArray1D = Kokkos::View; + using TArray1D = Kokkos::View; typename ExecSpace::memory_space memspace; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) TArray1D this_array_; TArray1DHost this_array_host_; - T * temp_inp_array_; - //typename Kokkos::View::HostMirror h_this_array_; + T* temp_inp_array_; + // typename Kokkos::View::HostMirror h_this_array_; public: DViewCArrayKokkos(); - - DViewCArrayKokkos(T * inp_array, size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewCArrayKokkos(T* inp_array, size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string = DEFAULTSTRINGARRAY); - DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DViewCArrayKokkos& operator=(const DViewCArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DViewCArrayKokkos& operator=(const DViewCArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Data member to access host view - ViewCArray host; + ViewCArray host; // Method that update host view void update_host(); @@ -5442,25 +4553,21 @@ class DViewCArrayKokkos { // Method that update device view void update_device(); - // set values on host to input void set_values(T val); // Get the name of the view const std::string get_name() const; - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DViewCArrayKokkos (); -}; // End of DViewCArrayKokkos - + KOKKOS_INLINE_FUNCTION ~DViewCArrayKokkos(); +}; // End of DViewCArrayKokkos // Default constructor template -DViewCArrayKokkos::DViewCArrayKokkos() { +DViewCArrayKokkos::DViewCArrayKokkos() { length_ = order_ = 0; - temp_inp_array_ = NULL; + temp_inp_array_ = NULL; for (int i = 0; i < 7; i++) { dims_[i] = 0; } @@ -5468,146 +4575,141 @@ DViewCArrayKokkos::DViewCArrayKokkos() { // Overloaded 1D constructor template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, const std::string& tag_string) { - //using TArray1DHost = Kokkos::View; - //using TArray1D = Kokkos::View; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, const std::string& tag_string) { + // using TArray1DHost = Kokkos::View; + // using TArray1D = Kokkos::View; + dims_[0] = dim0; - order_ = 1; - length_ = dim0; + order_ = 1; + length_ = dim0; // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; // Create a device copy of that host view - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); - // Create host ViewCArray. Note: inp_array and this_array_host_.data() are the same pointer - host = ViewCArray (inp_array, dim0); + // Create host ViewCArray. Note: inp_array and this_array_host_.data() are the same pointer + host = ViewCArray(inp_array, dim0); } // Overloaded 2D constructor template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, const std::string& tag_string) { - //using TArray1DHost = Kokkos::View; - //using TArray1D = Kokkos::View; - //using TArray1Dtemp = TArray1D::HostMirror; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, const std::string& tag_string) { + // using TArray1DHost = Kokkos::View; + // using TArray1D = Kokkos::View; + // using TArray1Dtemp = TArray1D::HostMirror; + dims_[0] = dim0; dims_[1] = dim1; - order_ = 2; - length_ = (dim0 * dim1); + order_ = 2; + length_ = (dim0 * dim1); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1); + host = ViewCArray(inp_array, dim0, dim1); } template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, + const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; - order_ = 3; - length_ = (dim0 * dim1 * dim2); + order_ = 3; + length_ = (dim0 * dim1 * dim2); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; // Create a device copy of that host view - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1, dim2); + host = ViewCArray(inp_array, dim0, dim1, dim2); } template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; // Create a device copy of that host view - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1, dim2, dim3); + host = ViewCArray(inp_array, dim0, dim1, dim2, dim3); } template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + // using TArray1D = Kokkos::View; - //using TArray1D = Kokkos::View; - dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; // Create a device copy of that host view - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1, dim2, dim3, dim4); + host = ViewCArray(inp_array, dim0, dim1, dim2, dim3, dim4); } template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; dims_[3] = dim3; dims_[4] = dim4; dims_[5] = dim5; - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; // Create a device copy of that host view - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1, dim2, dim3, dim4, dim5); + host = ViewCArray(inp_array, dim0, dim1, dim2, dim3, dim4, dim5); } template -DViewCArrayKokkos::DViewCArrayKokkos(T * inp_array, size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - //using TArray1D = Kokkos::View; - +DViewCArrayKokkos::DViewCArrayKokkos(T* inp_array, size_t dim0, size_t dim1, size_t dim2, size_t dim3, + size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { + // using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -5615,29 +4717,27 @@ DViewCArrayKokkos::DViewCArrayKokkos(T * inp_ar dims_[4] = dim4; dims_[5] = dim5; dims_[6] = dim6; - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); // Create a 1D host view of the external allocation this_array_host_ = TArray1DHost(inp_array, length_); // Assign temp point to inp_array pointer that is passed in temp_inp_array_ = inp_array; - //this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); + // this_array_ = create_mirror_view_and_copy(ExecSpace(), this_array_host_); this_array_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_array_host_); // Create host ViewCArray - host = ViewCArray (inp_array, dim0, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewCArray(inp_array, dim0, dim1, dim2, dim3, dim4, dim5, dim6); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 1D!"); return this_array_(i); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 2D!"); @@ -5645,49 +4745,39 @@ T& DViewCArrayKokkos::operator()(size_t i, size } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in DViewCArrayKokkos 3D!"); - return this_array_(k + (j * dims_[2]) - + (i * dims_[2] * dims_[1])); + return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DViewCArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DViewCArrayKokkos 4D!"); - return this_array_(l + (k * dims_[3]) - + (j * dims_[3] * dims_[2]) - + (i * dims_[3] * dims_[2] * dims_[1])); + return this_array_(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DViewCArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DViewCArrayKokkos 5D!"); assert(m < dims_[4] && "m is out of bounds in DViewCArrayKokkos 5D!"); - return this_array_(m + (l * dims_[4]) - + (k * dims_[4] * dims_[3]) - + (j * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 6D!"); @@ -5695,17 +4785,13 @@ T& DViewCArrayKokkos::operator()(size_t i, size assert(l < dims_[3] && "l is out of bounds in DViewCArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DViewCArrayKokkos 6D!"); assert(n < dims_[5] && "n is out of bounds in DViewCArrayKokkos 6D!"); - return this_array_(n + (m * dims_[5]) - + (l * dims_[5] * dims_[4]) - + (k * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DViewCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DViewCArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in DViewCArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DViewCArrayKokkos 7D!"); @@ -5714,195 +4800,161 @@ T& DViewCArrayKokkos::operator()(size_t i, size assert(m < dims_[4] && "m is out of bounds in DViewCArrayKokkos 7D!"); assert(n < dims_[5] && "n is out of bounds in DViewCArrayKokkos 7D!"); assert(o < dims_[6] && "o is out of bounds in DViewCArrayKokkos 7D!"); - return this_array_(o + (n * dims_[6]) - + (m * dims_[6] * dims_[5]) - + (l * dims_[6] * dims_[5] * dims_[4]) - + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_array_(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -DViewCArrayKokkos& DViewCArrayKokkos::operator= (const DViewCArrayKokkos& temp) { - //using TArray1D = Kokkos::View; - +KOKKOS_INLINE_FUNCTION DViewCArrayKokkos& DViewCArrayKokkos::operator=( + const DViewCArrayKokkos& temp) { + // using TArray1D = Kokkos::View; + // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; - temp_inp_array_ = temp.temp_inp_array_; + order_ = temp.order_; + length_ = temp.length_; + temp_inp_array_ = temp.temp_inp_array_; this_array_host_ = temp.this_array_host_; - this_array_ = temp.this_array_; - host = temp.host; + this_array_ = temp.this_array_; + host = temp.host; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DViewCArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DViewCArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DViewCArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DViewCArrayKokkos::dims(size_t i) const { assert(i < order_ && "DViewCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DViewCArrayKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DViewCArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DViewCArrayKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DViewCArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewCArrayKokkos::device_pointer() const { return this_array_.data(); } template -KOKKOS_INLINE_FUNCTION -T* DViewCArrayKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewCArrayKokkos::host_pointer() const { return this_array_host_.data(); } template -void DViewCArrayKokkos::update_host() { +void DViewCArrayKokkos::update_host() { // Deep copy of device view to host view deep_copy(this_array_host_, this_array_); } template -void DViewCArrayKokkos::update_device() { +void DViewCArrayKokkos::update_device() { // Deep copy of host view to device view deep_copy(this_array_, this_array_host_); } template -void DViewCArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_(i) = val; - }); +void DViewCArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template -const std::string DViewCArrayKokkos::get_name() const{ +const std::string DViewCArrayKokkos::get_name() const { return this_array_.label(); } template -KOKKOS_INLINE_FUNCTION -DViewCArrayKokkos::~DViewCArrayKokkos() {} +KOKKOS_INLINE_FUNCTION DViewCArrayKokkos::~DViewCArrayKokkos() {} // End DViewCArrayKokkos - ///////////////////////// // DCMatrixKokkos ///////////////////////// template class DCMatrixKokkos { - // this is manage using TArray1D = Kokkos::DualView; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) - bool lock_ = false; + bool lock_ = false; TArray1D this_matrix_; public: // Data member to access host view - ViewCMatrix host; + ViewCMatrix host; DCMatrixKokkos(); - + DCMatrixKokkos(size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); DCMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DCMatrixKokkos (size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DCMatrixKokkos& operator=(const DCMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DCMatrixKokkos& operator=(const DCMatrixKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Method that update host view void update_host(); @@ -5923,14 +4975,13 @@ class DCMatrixKokkos { const std::string get_name() const; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DCMatrixKokkos (); + KOKKOS_INLINE_FUNCTION ~DCMatrixKokkos(); -}; // End of DCMatrixKokkos declarations +}; // End of DCMatrixKokkos declarations // Default constructor template -DCMatrixKokkos::DCMatrixKokkos() { +DCMatrixKokkos::DCMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -5939,124 +4990,110 @@ DCMatrixKokkos::DCMatrixKokkos() { // Overloaded 1D constructor template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, const std::string& tag_string) { - - dims_[0] = dim1; - order_ = 1; - length_ = dim1; +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, const std::string& tag_string) { + dims_[0] = dim1; + order_ = 1; + length_ = dim1; this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1); } // Overloaded 2D constructor template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + order_ = 2; + length_ = (dim1 * dim2); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2); } template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + order_ = 3; + length_ = (dim1 * dim2 * dim3); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3); } template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4); } template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5); } template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6); } template -DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { - - dims_[0] = dim1; - dims_[1] = dim2; - dims_[2] = dim3; - dims_[3] = dim4; - dims_[4] = dim5; - dims_[5] = dim6; - dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); +DCMatrixKokkos::DCMatrixKokkos(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + size_t dim7, const std::string& tag_string) { + dims_[0] = dim1; + dims_[1] = dim2; + dims_[2] = dim3; + dims_[3] = dim4; + dims_[4] = dim5; + dims_[5] = dim6; + dims_[6] = dim7; + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); this_matrix_ = TArray1D(tag_string, length_); // Create host ViewCMatrix - host = ViewCMatrix (this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6, dim7); + host = ViewCMatrix(this_matrix_.view_host().data(), dim1, dim2, dim3, dim4, dim5, dim6, dim7); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 1D!"); return this_matrix_.view_device()((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 2D!"); @@ -6064,49 +5101,39 @@ T& DCMatrixKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DCMatrixKokkos 3D!"); - return this_matrix_.view_device()((k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])); + return this_matrix_.view_device()((k - 1) + ((j - 1) * dims_[2]) + ((i - 1) * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DCMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DCMatrixKokkos 4D!"); - return this_matrix_.view_device()((l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_.view_device()((l - 1) + ((k - 1) * dims_[3]) + ((j - 1) * dims_[3] * dims_[2]) + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DCMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DCMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DCMatrixKokkos 5D!"); - return this_matrix_.view_device()((m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_.view_device()((m - 1) + ((l - 1) * dims_[4]) + ((k - 1) * dims_[4] * dims_[3]) + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 6D!"); @@ -6114,17 +5141,14 @@ T& DCMatrixKokkos::operator()(size_t i, size_t assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DCMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DCMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DCMatrixKokkos 6D!"); - return this_matrix_.view_device()((n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_.view_device()((n - 1) + ((m - 1) * dims_[5]) + ((l - 1) * dims_[5] * dims_[4]) + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DCMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DCMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DCMatrixKokkos 7D!"); @@ -6133,76 +5157,67 @@ T& DCMatrixKokkos::operator()(size_t i, size_t assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DCMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DCMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in DCMatrixKokkos 7D!"); - return this_matrix_.view_device()((o-1) + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_.view_device()((o - 1) + ((n - 1) * dims_[6]) + ((m - 1) * dims_[6] * dims_[5]) + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -DCMatrixKokkos& DCMatrixKokkos::operator= (const DCMatrixKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DCMatrixKokkos& DCMatrixKokkos::operator=( + const DCMatrixKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_matrix_ = temp.this_matrix_; - host = temp.host; - lock_ = temp.lock_; + host = temp.host; + lock_ = temp.lock_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DCMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DCMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DCMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DCMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DCMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DCMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "DCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DCMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DCMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DCMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DCMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DCMatrixKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DCMatrixKokkos::device_pointer() const { return this_matrix_.view_device().data(); } template -KOKKOS_INLINE_FUNCTION -T* DCMatrixKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DCMatrixKokkos::host_pointer() const { return this_matrix_.view_host().data(); } template -void DCMatrixKokkos::update_host() { +void DCMatrixKokkos::update_host() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_matrix_.template modify(); @@ -6210,7 +5225,7 @@ void DCMatrixKokkos::update_host() { } template -void DCMatrixKokkos::update_device() { +void DCMatrixKokkos::update_device() { assert(!lock_ && "This data is locked, no copy will be done."); if (lock_) return; this_matrix_.template modify(); @@ -6219,127 +5234,104 @@ void DCMatrixKokkos::update_device() { // Get the name of the view template -const std::string DCMatrixKokkos::get_name() const{ +const std::string DCMatrixKokkos::get_name() const { return this_matrix_.view_device().label(); } template -void DCMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_.view_device()(i) = val; - }); +void DCMatrixKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_.view_device()(i) = val; }); } template -void DCMatrixKokkos::lock_update() { +void DCMatrixKokkos::lock_update() { lock_ = true; } template -void DCMatrixKokkos::unlock_update() { +void DCMatrixKokkos::unlock_update() { lock_ = false; } template -KOKKOS_INLINE_FUNCTION -DCMatrixKokkos::~DCMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION DCMatrixKokkos::~DCMatrixKokkos() {} // End DCMatrixKokkos - ///////////////////////// // DViewCMatrixKokkos ///////////////////////// template class DViewCMatrixKokkos { - // this is always unmanaged using TArray1DHost = Kokkos::View; // this is manage - using TArray1D = Kokkos::View; + using TArray1D = Kokkos::View; typename ExecSpace::memory_space memspace; - + private: size_t dims_[7]; size_t length_; size_t order_; // tensor order (rank) TArray1D this_matrix_; TArray1DHost this_matrix_host_; - T * temp_inp_matrix_; + T* temp_inp_matrix_; public: DViewCMatrixKokkos(); - - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGMATRIX); + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, size_t dim3, - size_t dim4, size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string = DEFAULTSTRINGMATRIX); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t dim7, + const std::string& tag_string = DEFAULTSTRINGMATRIX); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DViewCMatrixKokkos& operator=(const DViewCMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; + + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos& operator=(const DViewCMatrixKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Data member to access host view - ViewCMatrix host; + ViewCMatrix host; // Method that update host view void update_host(); @@ -6354,14 +5346,12 @@ class DViewCMatrixKokkos { const std::string get_name() const; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DViewCMatrixKokkos (); -}; // End of DViewCMatrixKokkos - + KOKKOS_INLINE_FUNCTION ~DViewCMatrixKokkos(); +}; // End of DViewCMatrixKokkos // Default constructor template -DViewCMatrixKokkos::DViewCMatrixKokkos() { +DViewCMatrixKokkos::DViewCMatrixKokkos() { length_ = order_ = 0; temp_inp_matrix_ = NULL; for (int i = 0; i < 7; i++) { @@ -6371,11 +5361,10 @@ DViewCMatrixKokkos::DViewCMatrixKokkos() { // Overloaded 1D constructor template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, const std::string& tag_string) { dims_[0] = dim1; - order_ = 1; - length_ = dim1; + order_ = 1; + length_ = dim1; // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6383,17 +5372,16 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix. Note: inp_matrix and this_matrix_host_.data() are the same pointer - host = ViewCMatrix (inp_matrix, dim1); + host = ViewCMatrix(inp_matrix, dim1); } // Overloaded 2D constructor template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; - order_ = 2; - length_ = (dim1 * dim2); + order_ = 2; + length_ = (dim1 * dim2); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6401,18 +5389,17 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2); + host = ViewCMatrix(inp_matrix, dim1, dim2); } template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, + const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; - order_ = 3; - length_ = (dim1 * dim2 * dim3); + order_ = 3; + length_ = (dim1 * dim2 * dim3); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6420,19 +5407,18 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2, dim3); + host = ViewCMatrix(inp_matrix, dim1, dim2, dim3); } template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; - order_ = 4; - length_ = (dim1 * dim2 * dim3 * dim4); + order_ = 4; + length_ = (dim1 * dim2 * dim3 * dim4); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6440,21 +5426,19 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2, dim3, dim4); + host = ViewCMatrix(inp_matrix, dim1, dim2, dim3, dim4); } template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; - order_ = 5; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5); + order_ = 5; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6462,22 +5446,20 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5); + host = ViewCMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5); } template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; dims_[3] = dim4; dims_[4] = dim5; dims_[5] = dim6; - order_ = 6; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + order_ = 6; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6485,15 +5467,12 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewCMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6); } template -DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_matrix, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, - size_t dim5, size_t dim6, - size_t dim7, const std::string& tag_string) { - +DViewCMatrixKokkos::DViewCMatrixKokkos(T* inp_matrix, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + size_t dim5, size_t dim6, size_t dim7, const std::string& tag_string) { dims_[0] = dim1; dims_[1] = dim2; dims_[2] = dim3; @@ -6501,8 +5480,8 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ dims_[4] = dim5; dims_[5] = dim6; dims_[6] = dim7; - order_ = 7; - length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); + order_ = 7; + length_ = (dim1 * dim2 * dim3 * dim4 * dim5 * dim6 * dim7); // Create a 1D host view of the external allocation this_matrix_host_ = TArray1DHost(inp_matrix, length_); // Assign temp point to inp_matrix pointer that is passed in @@ -6510,20 +5489,18 @@ DViewCMatrixKokkos::DViewCMatrixKokkos(T * inp_ // Create a device copy of that host view this_matrix_ = create_mirror_view_and_copy(Kokkos::view_alloc(memspace, tag_string), this_matrix_host_); // Create host ViewCMatrix - host = ViewCMatrix (inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6, dim7); + host = ViewCMatrix(inp_matrix, dim1, dim2, dim3, dim4, dim5, dim6, dim7); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 1D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 1D!"); return this_matrix_((i - 1)); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 2D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 2D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 2D!"); @@ -6531,49 +5508,39 @@ T& DViewCMatrixKokkos::operator()(size_t i, siz } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 3D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 3D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 3D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewCMatrixKokkos 3D!"); - return this_matrix_((k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])); + return this_matrix_((k - 1) + ((j - 1) * dims_[2]) + ((i - 1) * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 4D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 4D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 4D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewCMatrixKokkos 4D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewCMatrixKokkos 4D!"); - return this_matrix_((l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((l - 1) + ((k - 1) * dims_[3]) + ((j - 1) * dims_[3] * dims_[2]) + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 5D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 5D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 5D!"); assert(k >= 1 && k <= dims_[2] && "k is out of bounds in DViewCMatrixKokkos 5D!"); assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewCMatrixKokkos 5D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewCMatrixKokkos 5D!"); - return this_matrix_((m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((m - 1) + ((l - 1) * dims_[4]) + ((k - 1) * dims_[4] * dims_[3]) + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 6D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 6D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 6D!"); @@ -6581,17 +5548,13 @@ T& DViewCMatrixKokkos::operator()(size_t i, siz assert(l >= 1 && l <= dims_[3] && "l is out of bounds in DViewCMatrixKokkos 6D!"); assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewCMatrixKokkos 6D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DViewCMatrixKokkos 6D!"); - return this_matrix_((n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_((n - 1) + ((m - 1) * dims_[5]) + ((l - 1) * dims_[5] * dims_[4]) + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& DViewCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in DViewCMatrixKokkos 7D!"); assert(i >= 1 && i <= dims_[0] && "i is out of bounds in DViewCMatrixKokkos 7D!"); assert(j >= 1 && j <= dims_[1] && "j is out of bounds in DViewCMatrixKokkos 7D!"); @@ -6600,232 +5563,206 @@ T& DViewCMatrixKokkos::operator()(size_t i, siz assert(m >= 1 && m <= dims_[4] && "m is out of bounds in DViewCMatrixKokkos 7D!"); assert(n >= 1 && n <= dims_[5] && "n is out of bounds in DViewCMatrixKokkos 7D!"); assert(o >= 1 && o <= dims_[6] && "o is out of bounds in DViewCMatrixKokkos 7D!"); - return this_matrix_(o + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); + return this_matrix_(o + ((n - 1) * dims_[6]) + ((m - 1) * dims_[6] * dims_[5]) + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } template -KOKKOS_INLINE_FUNCTION -DViewCMatrixKokkos& DViewCMatrixKokkos::operator= (const DViewCMatrixKokkos& temp) { - +KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos& DViewCMatrixKokkos::operator=( + const DViewCMatrixKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; - temp_inp_matrix_ = temp.temp_inp_matrix_; + order_ = temp.order_; + length_ = temp.length_; + temp_inp_matrix_ = temp.temp_inp_matrix_; this_matrix_host_ = temp.this_matrix_host_; - this_matrix_ = temp.this_matrix_; - host = temp.host; + this_matrix_ = temp.this_matrix_; + host = temp.host; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DViewCMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DViewCMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DViewCMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DViewCMatrixKokkos::dims(size_t i) const { i--; assert(i < order_ && "DViewCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(dims_[i]>0 && "Access to DViewCMatrixKokkos dims is out of bounds!"); + assert(dims_[i] > 0 && "Access to DViewCMatrixKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DViewCMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DViewCMatrixKokkos::order() const { return order_; } template -KOKKOS_INLINE_FUNCTION -T* DViewCMatrixKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewCMatrixKokkos::device_pointer() const { return this_matrix_.data(); } template -KOKKOS_INLINE_FUNCTION -T* DViewCMatrixKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* DViewCMatrixKokkos::host_pointer() const { return this_matrix_host_.data(); } template -void DViewCMatrixKokkos::update_host() { +void DViewCMatrixKokkos::update_host() { // Deep copy of device view to host view deep_copy(this_matrix_host_, this_matrix_); } template -void DViewCMatrixKokkos::update_device() { +void DViewCMatrixKokkos::update_device() { // Deep copy of host view to device view deep_copy(this_matrix_, this_matrix_host_); } // Get the name of the view template -const std::string DViewCMatrixKokkos::get_name() const{ +const std::string DViewCMatrixKokkos::get_name() const { return this_matrix_.label(); } template -void DViewCMatrixKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_(i) = val; - }); +void DViewCMatrixKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; }); } template -KOKKOS_INLINE_FUNCTION -DViewCMatrixKokkos::~DViewCMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos::~DViewCMatrixKokkos() {} // End DViewCMatrixKokkos /*! \brief Dual Kokkos version of the serial RaggedRightArray class. * */ -template +template class DRaggedRightArrayKokkos { - // this is managed - using TArray1D = Kokkos::DualView ; - using StartArray = Kokkos::DualView; - using Strides1D = Kokkos::DualView; - + using TArray1D = Kokkos::DualView; + using StartArray = Kokkos::DualView; + using Strides1D = Kokkos::DualView; + // this is always unmanaged using TArray1DHost = Kokkos::View; typename ExecSpace::memory_space memspace; - - + private: - TArray1D this_array_; // 1D Array storing the data + TArray1D this_array_; // 1D Array storing the data typename TArray1D::t_dev this_array_dev_; typename TArray1D::t_host this_array_host_; - size_t dims_[3]; // Note: dims_[0] is always the stride length accounting for size of other dimensions - size_t length_; // Total length of 1D array storing the data - size_t block_length_; // Length of the contiguous block of data in the 1D array + size_t dims_[3]; // Note: dims_[0] is always the stride length accounting for size of other + // dimensions + size_t length_; // Total length of 1D array storing the data + size_t block_length_; // Length of the contiguous block of data in the 1D array - public: - // Kokkos views of strides and start indices Strides1D mystrides_; typename Strides1D::t_dev mystrides_dev_; typename Strides1D::t_host mystrides_host_; - + StartArray start_index_; typename StartArray::t_dev start_index_dev_; typename StartArray::t_host start_index_host_; - // ---- Constructors ---- // Default constructor DRaggedRightArrayKokkos(); - + // Overload constructor for a CArrayKokkos scalar, vector, and tensor - DRaggedRightArrayKokkos(CArrayKokkos &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - DRaggedRightArrayKokkos(CArrayKokkos &strides_array, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DRaggedRightArrayKokkos(CArrayKokkos &strides_array, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DRaggedRightArrayKokkos(CArrayKokkos& strides_array, + const std::string& tag_string = DEFAULTSTRINGARRAY); + DRaggedRightArrayKokkos(CArrayKokkos& strides_array, size_t dim2, + const std::string& tag_string = DEFAULTSTRINGARRAY); + DRaggedRightArrayKokkos(CArrayKokkos& strides_array, size_t dim2, size_t dim3, + const std::string& tag_string = DEFAULTSTRINGARRAY); // Overload constructor for a DCArrayKokkos scalar, vector, and tensor - DRaggedRightArrayKokkos(DCArrayKokkos &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - DRaggedRightArrayKokkos(DCArrayKokkos &strides_array, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DRaggedRightArrayKokkos(DCArrayKokkos &strides_array, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - - - // Overloaded constructor for a traditional array for scalar, vector, and tensor + DRaggedRightArrayKokkos(DCArrayKokkos& strides_array, + const std::string& tag_string = DEFAULTSTRINGARRAY); + DRaggedRightArrayKokkos(DCArrayKokkos& strides_array, size_t dim2, + const std::string& tag_string = DEFAULTSTRINGARRAY); + DRaggedRightArrayKokkos(DCArrayKokkos& strides_array, size_t dim2, size_t dim3, + const std::string& tag_string = DEFAULTSTRINGARRAY); + + // Overloaded constructor for a traditional array for scalar, vector, and tensor DRaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); DRaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, size_t some_dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DRaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, size_t some_dim2, size_t some_dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - + DRaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, size_t some_dim2, size_t some_dim3, + const std::string& tag_string = DEFAULTSTRINGARRAY); // A method to return the stride size - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t stride(size_t i) const; // Host method to return the stride size size_t stride_host(size_t i) const; - + // A method to increase the number of column entries, i.e., // the stride size. Used with the constructor for building // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array - KOKKOS_INLINE_FUNCTION - size_t& build_stride(const size_t i) const; - - KOKKOS_INLINE_FUNCTION - void stride_finalize() const; - + KOKKOS_INLINE_FUNCTION size_t& build_stride(const size_t i) const; + + KOKKOS_INLINE_FUNCTION void stride_finalize() const; + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; // Overload operator() to access data as array(i,j,k) // where i=[0:N-1], j=[stride(i)], k is contiguous in memory after j // accessed via pointer arithmetic from j's location - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; // Overload operator() to access data as array(i,j,k,l) // where i=[0:N-1], j=[stride(i)], k and l are contiguous in memory after j // accessed via pointer arithmetic from j's location - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; - + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; T& host(size_t i, size_t j) const; T& host(size_t i, size_t j, size_t k) const; T& host(size_t i, size_t j, size_t k, size_t l) const; // method to return total size - KOKKOS_INLINE_FUNCTION - size_t size() const{ - return length_; - } + KOKKOS_INLINE_FUNCTION size_t size() const { return length_; } // Method to return the dimensions of the array - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; - - //setup start indices + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; + + // setup start indices void data_setup(const std::string& tag_string); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_dual_view(); - - //return pointer + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_dual_view(); + + // return pointer T* host_pointer(); // Method returns the raw device pointer of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; - //print values - // void print() const; - - //set values to input + // print values + // void print() const; + + // set values to input void set_values(T val); // Get the name of the view @@ -6837,32 +5774,25 @@ class DRaggedRightArrayKokkos { // Method that update device view void update_device(); + KOKKOS_INLINE_FUNCTION DRaggedRightArrayKokkos& operator=(const DRaggedRightArrayKokkos& temp); - - KOKKOS_INLINE_FUNCTION - DRaggedRightArrayKokkos& operator=(const DRaggedRightArrayKokkos &temp); - - //initialize start indices view - class init_start_indices_functor{ - public: + // initialize start indices view + class init_start_indices_functor { + public: StartArray mystart_index_; - init_start_indices_functor(StartArray tempstart_index_){ - mystart_index_ = tempstart_index_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - mystart_index_.view_device()(index) = 0; - } + init_start_indices_functor(StartArray tempstart_index_) { mystart_index_ = tempstart_index_; } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { mystart_index_.view_device()(index) = 0; } }; - //setup start indices view - class setup_start_indices_functor{ - public: + // setup start indices view + class setup_start_indices_functor { + public: StartArray mystart_index_; Strides1D mytemp_strides_; - size_t tmp_block_length_; - setup_start_indices_functor(StartArray tempstart_index_, Strides1D temp_strides_, size_t block_length_){ - mystart_index_ = tempstart_index_; - mytemp_strides_ = temp_strides_; + size_t tmp_block_length_; + setup_start_indices_functor(StartArray tempstart_index_, Strides1D temp_strides_, size_t block_length_) { + mystart_index_ = tempstart_index_; + mytemp_strides_ = temp_strides_; tmp_block_length_ = block_length_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { @@ -6870,93 +5800,88 @@ class DRaggedRightArrayKokkos { const size_t count = mytemp_strides_.view_device()(index) * tmp_block_length_; update += count; if (final) { - mystart_index_.view_device()((index+1)) = update; + mystart_index_.view_device()((index + 1)) = update; } } }; - //setup length of view - class setup_length_functor{ - public: - //kokkos needs this typedef named + // setup length of view + class setup_length_functor { + public: + // kokkos needs this typedef named typedef size_t value_type; size_t tmp_block_length_; // This is helpful for determining the right index type, // especially if you expect to need a 64-bit index. - //typedef Kokkos::View::size_type size_type; + // typedef Kokkos::View::size_type size_type; Strides1D mytemp_strides_; - setup_length_functor(Strides1D temp_strides_, size_t block_length_){ - mytemp_strides_ = temp_strides_; + setup_length_functor(Strides1D temp_strides_, size_t block_length_) { + mytemp_strides_ = temp_strides_; tmp_block_length_ = block_length_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, size_t& update) const { - //const size_t count = mytemp_strides_(index); + // const size_t count = mytemp_strides_(index); update += mytemp_strides_.view_device()(index) * tmp_block_length_; } }; - //sets final 1D array size - class finalize_stride_functor{ - public: + // sets final 1D array size + class finalize_stride_functor { + public: StartArray mystart_index_; size_t tmp_block_length_; - finalize_stride_functor(StartArray tempstart_index_, size_t block_length_){ - mystart_index_ = tempstart_index_; + finalize_stride_functor(StartArray tempstart_index_, size_t block_length_) { + mystart_index_ = tempstart_index_; tmp_block_length_ = block_length_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { // Load old value in case we update it before accumulating - const size_t count = mystart_index_.view_device()(index+1) * tmp_block_length_; + const size_t count = mystart_index_.view_device()(index + 1) * tmp_block_length_; update += count; if (final) { - mystart_index_.view_device()((index+1)) = update; + mystart_index_.view_device()((index + 1)) = update; } } }; // Destructor - KOKKOS_INLINE_FUNCTION - ~DRaggedRightArrayKokkos ( ); -}; // End of DRaggedRightArray + KOKKOS_INLINE_FUNCTION ~DRaggedRightArrayKokkos(); +}; // End of DRaggedRightArray // Default constructor template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos() { - dims_[0] = 0; - dims_[1] = 0; - dims_[2] = 0; +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos() { + dims_[0] = 0; + dims_[1] = 0; + dims_[2] = 0; block_length_ = 0; - length_ = 0; + length_ = 0; } -// Overloaded constructor for CArrayKokkos for scalar +// Overloaded constructor for CArrayKokkos for scalar template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - CArrayKokkos &strides_array, - const std::string& tag_string) { - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + CArrayKokkos& strides_array, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = 0; dims_[2] = 0; - + block_length_ = 1; mystrides_host_ = typename Strides1D::t_host("host_strides", dims_[0]); - //requires host synchronization before building dual view wrapper + // requires host synchronization before building dual view wrapper Kokkos::deep_copy(mystrides_host_, strides_array.get_kokkos_view()); - mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); + mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); mystrides_dev_ = mystrides_.view_device(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for CArrayKokkos for vector template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - CArrayKokkos &strides_array, - size_t dim2, - const std::string& tag_string) { - - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + CArrayKokkos& strides_array, size_t dim2, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = dim2; dims_[2] = 0; @@ -6964,110 +5889,96 @@ DRaggedRightArrayKokkos::DRaggedRightAr block_length_ = dim2; mystrides_host_ = typename Strides1D::t_host("host_strides", dims_[0]); - //requires host synchronization before building dual view wrapper + // requires host synchronization before building dual view wrapper Kokkos::deep_copy(mystrides_host_, strides_array.get_kokkos_view()); - mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); + mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); mystrides_dev_ = mystrides_.view_device(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for CArrayKokkos for rank 2 tensor template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - CArrayKokkos &strides_array, - size_t dim2, - size_t dim3, - const std::string& tag_string) { - - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + CArrayKokkos& strides_array, size_t dim2, size_t dim3, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = dim2; dims_[2] = dim3; - block_length_ = dim2*dim3; - + block_length_ = dim2 * dim3; + mystrides_host_ = typename Strides1D::t_host("host_strides", dims_[0]); - //requires host synchronization before building dual view wrapper + // requires host synchronization before building dual view wrapper Kokkos::deep_copy(mystrides_host_, strides_array.get_kokkos_view()); - mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); + mystrides_ = Strides1D(strides_array.get_kokkos_view(), mystrides_host_); mystrides_dev_ = mystrides_.view_device(); data_setup(tag_string); -} // End constructor +} // End constructor -// Overloaded constructor for DCArrayKokkos for scalar +// Overloaded constructor for DCArrayKokkos for scalar template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - DCArrayKokkos &strides_array, - const std::string& tag_string) { - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + DCArrayKokkos& strides_array, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = 0; dims_[2] = 0; - + block_length_ = 1; - mystrides_ = strides_array.get_kokkos_dual_view(); - mystrides_dev_ = mystrides_.view_device(); + mystrides_ = strides_array.get_kokkos_dual_view(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); - + data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for DCArrayKokkos for vector template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - DCArrayKokkos &strides_array, - size_t dim2, - const std::string& tag_string) { - - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + DCArrayKokkos& strides_array, size_t dim2, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = dim2; dims_[2] = 0; block_length_ = dim2; - mystrides_ = strides_array.get_kokkos_dual_view(); - mystrides_dev_ = mystrides_.view_device(); + mystrides_ = strides_array.get_kokkos_dual_view(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for DCArrayKokkos for rank 2 tensor template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - DCArrayKokkos &strides_array, - size_t dim2, - size_t dim3, - const std::string& tag_string) { - - //construct strides dual view using device input +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( + DCArrayKokkos& strides_array, size_t dim2, size_t dim3, const std::string& tag_string) { + // construct strides dual view using device input dims_[0] = strides_array.size(); dims_[1] = dim2; dims_[2] = dim3; - block_length_ = dim2*dim3; - - mystrides_ = strides_array.get_kokkos_dual_view(); - mystrides_dev_ = mystrides_.view_device(); + block_length_ = dim2 * dim3; + + mystrides_ = strides_array.get_kokkos_dual_view(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for a raw array of scalar strides template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - size_t* strides_array, - size_t some_dim1, // size of strides_array - const std::string& tag_string) { - +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos(size_t* strides_array, + size_t some_dim1, // size of strides_array + const std::string& tag_string) { // Create a new DualView for mystrides_ with proper size mystrides_ = Strides1D("mystrides", some_dim1); - + // Get host view and copy data - for(size_t i = 0; i < some_dim1; i++) { + for (size_t i = 0; i < some_dim1; i++) { mystrides_.view_host()(i) = strides_array[i]; } @@ -7076,7 +5987,7 @@ DRaggedRightArrayKokkos::DRaggedRightAr mystrides_.template sync(); // Set device view - mystrides_dev_ = mystrides_.view_device(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); dims_[0] = some_dim1; @@ -7085,21 +5996,18 @@ DRaggedRightArrayKokkos::DRaggedRightAr block_length_ = 1; data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for a raw array of vector strides template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - size_t* strides_array, - size_t some_dim1, // size of strides_array - size_t some_dim2, - const std::string& tag_string) { - +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos(size_t* strides_array, + size_t some_dim1, // size of strides_array + size_t some_dim2, const std::string& tag_string) { // Create a new DualView for mystrides_ with proper size mystrides_ = Strides1D("mystrides", some_dim1); - + // Get host view and copy data - for(size_t i = 0; i < some_dim1; i++) { + for (size_t i = 0; i < some_dim1; i++) { mystrides_.view_host()(i) = strides_array[i]; } @@ -7108,7 +6016,7 @@ DRaggedRightArrayKokkos::DRaggedRightAr mystrides_.template sync(); // Set device view - mystrides_dev_ = mystrides_.view_device(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); dims_[0] = some_dim1; @@ -7116,24 +6024,21 @@ DRaggedRightArrayKokkos::DRaggedRightAr dims_[2] = 0; block_length_ = some_dim2; - + data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor for a raw array of tensor strides template -DRaggedRightArrayKokkos::DRaggedRightArrayKokkos( - size_t* strides_array, - size_t some_dim1, // size of strides_array - size_t some_dim2, - size_t some_dim3, - const std::string& tag_string) { - +DRaggedRightArrayKokkos::DRaggedRightArrayKokkos(size_t* strides_array, + size_t some_dim1, // size of strides_array + size_t some_dim2, size_t some_dim3, + const std::string& tag_string) { // Create a new DualView for mystrides_ with proper size mystrides_ = Strides1D("mystrides", some_dim1); - + // Get host view and copy data - for(size_t i = 0; i < some_dim1; i++) { + for (size_t i = 0; i < some_dim1; i++) { mystrides_.view_host()(i) = strides_array[i]; } @@ -7142,84 +6047,85 @@ DRaggedRightArrayKokkos::DRaggedRightAr mystrides_.template sync(); // Set device view - mystrides_dev_ = mystrides_.view_device(); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); dims_[0] = some_dim1; dims_[1] = some_dim2; dims_[2] = some_dim3; - block_length_ = some_dim2*some_dim3; - + block_length_ = some_dim2 * some_dim3; + data_setup(tag_string); -} // End constructor +} // End constructor -//setup start indices +// setup start indices template -void DRaggedRightArrayKokkos::data_setup(const std::string& tag_string) { - - //allocate start indices +void DRaggedRightArrayKokkos::data_setup(const std::string& tag_string) { + // allocate start indices std::string append_indices_string("start_indices"); std::string append_this_array_string("array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string start_index_tag_string = temp_copy_string.append(append_indices_string); - temp_copy_string = tag_string; - + temp_copy_string = tag_string; - start_index_ = StartArray(start_index_tag_string, dims_[0] + 1); - start_index_dev_ = start_index_.view_device(); + start_index_ = StartArray(start_index_tag_string, dims_[0] + 1); + start_index_dev_ = start_index_.view_device(); start_index_host_ = start_index_.view_host(); - - // Initialize the start indices to 0 - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartValuesInit", dims_[0] + 1, KOKKOS_CLASS_LAMBDA(const int i) { - start_index_dev_(i) = 0; - }); - #else + +// Initialize the start indices to 0 +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartValuesInit", dims_[0] + 1, KOKKOS_CLASS_LAMBDA(const int i) { start_index_dev_(i) = 0; }); +#else init_start_indices_functor execution_functor(start_index_); Kokkos::parallel_for("StartValuesInit", dims_[0] + 1, execution_functor); - #endif - // Setup the start indices - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValuesSetup", dims_[0], KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { - // Load old value in case we update it before accumulating - const size_t count = mystrides_dev_(i) * block_length_; - update += count; - if (final) { - start_index_dev_((i+1)) = update; - } - }); - #else +#endif +// Setup the start indices +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValuesSetup", + dims_[0], + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { + // Load old value in case we update it before accumulating + const size_t count = mystrides_dev_(i) * block_length_; + update += count; + if (final) { + start_index_dev_((i + 1)) = update; + } + }); +#else setup_start_indices_functor setup_execution_functor(start_index_, mystrides_, block_length_); Kokkos::parallel_scan("StartValuesSetup", dims_[0], setup_execution_functor); - #endif - //compute length of the storage - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_reduce("LengthSetup", dims_[0], KOKKOS_CLASS_LAMBDA(const int i, int& update) { - // Load old value in case we update it before accumulating - update += mystrides_dev_(i) * block_length_; - }, length_); - - #else +#endif +// compute length of the storage +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_reduce( + "LengthSetup", + dims_[0], + KOKKOS_CLASS_LAMBDA(const int i, int& update) { + // Load old value in case we update it before accumulating + update += mystrides_dev_(i) * block_length_; + }, + length_); + +#else setup_length_functor length_functor(mystrides_, block_length_); Kokkos::parallel_reduce("LengthSetup", dims_[0], length_functor, length_); - #endif - +#endif mystrides_.template modify(); mystrides_.template sync(); start_index_.template modify(); start_index_.template sync(); - //allocate view - this_array_ = TArray1D(tag_string, length_); - this_array_dev_ = this_array_.view_device(); + // allocate view + this_array_ = TArray1D(tag_string, length_); + this_array_dev_ = this_array_.view_device(); this_array_host_ = this_array_.view_host(); } // A method to return the stride size template -KOKKOS_INLINE_FUNCTION -size_t DRaggedRightArrayKokkos::stride(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DRaggedRightArrayKokkos::stride(size_t i) const { // Ensure that i is within bounds assert(i < (dims_[0]) && "i is greater than dims_[0] in DRaggedRightArray"); return mystrides_dev_(i); @@ -7227,8 +6133,7 @@ size_t DRaggedRightArrayKokkos::stride( // A method to return the size of each dimension template -KOKKOS_INLINE_FUNCTION -size_t DRaggedRightArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DRaggedRightArrayKokkos::dims(size_t i) const { // Ensure that i is within bounds assert(i >= 0 && "i is less than 0 in the DRaggedRightArrayKokkos class"); assert(i < 3 && "i is greater than 2 in the DRaggedRightArrayKokkos class"); @@ -7237,7 +6142,7 @@ size_t DRaggedRightArrayKokkos::dims(si // A method to return the stride size on the host space template -size_t DRaggedRightArrayKokkos::stride_host(size_t i) const { +size_t DRaggedRightArrayKokkos::stride_host(size_t i) const { // Ensure that i is within bounds assert(i < (dims_[0]) && "i is greater than dims_[0] in DRaggedRightArray"); return mystrides_host_(i); @@ -7245,174 +6150,164 @@ size_t DRaggedRightArrayKokkos::stride_ // Method to build the stride (non-Kokkos push back) template -KOKKOS_INLINE_FUNCTION -size_t& DRaggedRightArrayKokkos::build_stride(const size_t i) const { - return start_index_dev_(i+1); +KOKKOS_INLINE_FUNCTION size_t& DRaggedRightArrayKokkos::build_stride(const size_t i) const { + return start_index_dev_(i + 1); } // Method to finalize stride template -KOKKOS_INLINE_FUNCTION -void DRaggedRightArrayKokkos::stride_finalize() const { - - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValues", dims_[0], KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { - // Load old value in case we update it before accumulating - const size_t count = start_index_dev_(i+1); - update += count; - if (final) { - start_index_dev_((i+1)) = update; - } - - }); - #else +KOKKOS_INLINE_FUNCTION void DRaggedRightArrayKokkos::stride_finalize() const { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValues", + dims_[0], + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { + // Load old value in case we update it before accumulating + const size_t count = start_index_dev_(i + 1); + update += count; + if (final) { + start_index_dev_((i + 1)) = update; + } + }); +#else finalize_stride_functor execution_functor(start_index_, block_length_); - Kokkos::parallel_scan("StartValues", dims_[0],execution_functor); - #endif + Kokkos::parallel_scan("StartValues", dims_[0], execution_functor); +#endif Kokkos::fence(); - + start_index_.template modify(); start_index_.template sync(); } - // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { // Get the 1D array index size_t start = start_index_dev_(i); - + // asserts - assert(i < dims_[0] && "i is out of dim1 bounds in DRaggedRightArrayKokkos"); // die if >= dim1 + assert(i < dims_[0] && "i is out of dim1 bounds in DRaggedRightArrayKokkos"); // die if >= dim1 assert(j < stride(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= stride - - return this_array_dev_(j + start); -} // End operator() + return this_array_dev_(j + start); +} // End operator() // Overload operator() to access data as array(i,j,k) // where i=[0:N-1], j=[stride(i)], k is contiguous in memory after j // accessed via pointer arithmetic from j's location template -KOKKOS_INLINE_FUNCTION -T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j, size_t k) const { // Get the 1D array index size_t start = start_index_dev_(i); - + // asserts assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim0 - assert(j < stride(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= dim1 - assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dim2 - - size_t index_1D = start + k + dims_[1]*j; + assert(j < stride(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= dim1 + assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dim2 - return this_array_dev_(index_1D); -} // End operator() + size_t index_1D = start + k + dims_[1] * j; + return this_array_dev_(index_1D); +} // End operator() // Overload operator() to access data as array(i,j,k,l) // where i=[0:N-1], j=[stride(i)], k and l are contiguous in memory after j // accessed via pointer arithmetic from j's location template -KOKKOS_INLINE_FUNCTION -T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& DRaggedRightArrayKokkos::operator()(size_t i, size_t j, size_t k, + size_t l) const { // Get the 1D array index size_t start = start_index_dev_(i); - + // asserts assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim1 - assert(j < stride(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= stride - assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[1] - assert(l < dims_[2] && "l is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[2] - - size_t index_1D = start + l + dims_[2]*k + dims_[2]*dims_[1]*j; + assert(j < stride(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= stride + assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[1] + assert(l < dims_[2] && "l is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[2] + + size_t index_1D = start + l + dims_[2] * k + dims_[2] * dims_[1] * j; return this_array_dev_(index_1D); -} // End operator() +} // End operator() // Overload host operator() to access data as array(i,j) // where i=[0:N-1], j=[0:stride(i)] template -T& DRaggedRightArrayKokkos::host(size_t i, size_t j) const { +T& DRaggedRightArrayKokkos::host(size_t i, size_t j) const { // Get the 1D array index size_t start = start_index_host_(i); - + // asserts - assert(i < dims_[0] && "i is out of dim1 bounds in DRaggedRightArrayKokkos"); // die if >= dim1 + assert(i < dims_[0] && "i is out of dim1 bounds in DRaggedRightArrayKokkos"); // die if >= dim1 assert(j < stride_host(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= stride - + return this_array_host_(j + start); -} // End operator() +} // End operator() // Overload host operator() to access data as array(i,j,k) // where i=[0:N-1], j=[stride(i)], k is contiguous in memory after j // accessed via pointer arithmetic from j's location template -T& DRaggedRightArrayKokkos::host(size_t i, size_t j, size_t k) const { +T& DRaggedRightArrayKokkos::host(size_t i, size_t j, size_t k) const { // Get the 1D array index size_t start = start_index_host_(i); - + // asserts - assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim0 + assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim0 assert(j < stride_host(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= dim1 - assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dim2 + assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dim2 - size_t index_1D = start + k + dims_[1]*j; + size_t index_1D = start + k + dims_[1] * j; return this_array_host_(index_1D); -} // End operator() +} // End operator() // Overload host operator() to access data as array(i,j,k,l) // where i=[0:N-1], j=[stride(i)], k and l are contiguous in memory after j // accessed via pointer arithmetic from j's location template -T& DRaggedRightArrayKokkos::host(size_t i, size_t j, size_t k, size_t l) const { +T& DRaggedRightArrayKokkos::host(size_t i, size_t j, size_t k, size_t l) const { // Get the 1D array index size_t start = start_index_host_(i); - + // asserts - assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim1 + assert(i < dims_[0] && "i is out of dims_[0] bounds in DRaggedRightArrayKokkos"); // die if >= dim1 assert(j < stride_host(i) && "j is out of stride bounds in DRaggedRightArrayKokkos"); // die if >= stride - assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[1] - assert(l < dims_[2] && "l is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[2] - - size_t index_1D = start + l + dims_[2]*k + dims_[2]*dims_[1]*j; - + assert(k < dims_[1] && "k is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[1] + assert(l < dims_[2] && "l is out of vector bounds in DRaggedRightArrayKokkos"); // die if >= dims_[2] + + size_t index_1D = start + l + dims_[2] * k + dims_[2] * dims_[1] * j; + return this_array_host_(index_1D); -} // End operator() +} // End operator() template -KOKKOS_INLINE_FUNCTION -T* DRaggedRightArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* DRaggedRightArrayKokkos::device_pointer() const { return this_array_dev_.data(); } template -T* DRaggedRightArrayKokkos::host_pointer() { +T* DRaggedRightArrayKokkos::host_pointer() { return this_array_host_.data(); } template -void DRaggedRightArrayKokkos::update_host() { - +void DRaggedRightArrayKokkos::update_host() { this_array_.template modify(); this_array_.template sync(); } template -void DRaggedRightArrayKokkos::update_device() { - +void DRaggedRightArrayKokkos::update_device() { this_array_.template modify(); this_array_.template sync(); } template -KOKKOS_INLINE_FUNCTION -DRaggedRightArrayKokkos & DRaggedRightArrayKokkos:: - operator= (const DRaggedRightArrayKokkos &temp) { - +KOKKOS_INLINE_FUNCTION DRaggedRightArrayKokkos& +DRaggedRightArrayKokkos::operator=( + const DRaggedRightArrayKokkos& temp) { if (this != &temp) { /* StartArray tempdim = StartArray("tempdim", 1); @@ -7430,12 +6325,12 @@ DRaggedRightArrayKokkos & DRaggedRightA dims_[2] = temp.dims_[2]; block_length_ = temp.block_length_; - + // Create and initialize the starting index of the entries in the 1D array - start_index_ = temp.start_index_; - start_index_dev_ = temp.start_index_dev_; + start_index_ = temp.start_index_; + start_index_dev_ = temp.start_index_dev_; start_index_host_ = temp.start_index_host_; - //start_index_(0) = 0; // the 1D array starts at 0 + // start_index_(0) = 0; // the 1D array starts at 0 /* size_t * h_start_index = new size_t [dim1_+1]; @@ -7470,20 +6365,19 @@ DRaggedRightArrayKokkos & DRaggedRightA */ length_ = temp.length_; + // printf("Length %ld\n", length_); - //printf("Length %ld\n", length_); + // Kokkos::parallel_for("StartCheck", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { + // printf("%d) Start %ld\n", i, start_index_(i)); + // }); + // Kokkos::fence(); - //Kokkos::parallel_for("StartCheck", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { - // printf("%d) Start %ld\n", i, start_index_(i)); - // }); - //Kokkos::fence(); - - this_array_ = temp.this_array_; - this_array_dev_ = temp.this_array_dev_; + this_array_ = temp.this_array_; + this_array_dev_ = temp.this_array_dev_; this_array_host_ = temp.this_array_host_; - mystrides_ = temp.mystrides_; - mystrides_dev_ = temp.mystrides_dev_; - mystrides_host_ = temp.mystrides_host_; + mystrides_ = temp.mystrides_; + mystrides_dev_ = temp.mystrides_dev_; + mystrides_host_ = temp.mystrides_host_; /* dim1_ = temp.dim1_; @@ -7498,35 +6392,32 @@ DRaggedRightArrayKokkos & DRaggedRightA this_array_ = TArray1D("this_array_", length_); */ } - + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::DualView DRaggedRightArrayKokkos::get_kokkos_dual_view() { +KOKKOS_INLINE_FUNCTION Kokkos::DualView +DRaggedRightArrayKokkos::get_kokkos_dual_view() { return this_array_; } -//set values to input +// set values to input template -void DRaggedRightArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_array_dev_(i) = val; - }); +void DRaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_dev_(i) = val; }); } // Get the name of the view template -const std::string DRaggedRightArrayKokkos::get_name() const{ +const std::string DRaggedRightArrayKokkos::get_name() const { return this_array_.view_device().label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -DRaggedRightArrayKokkos::~DRaggedRightArrayKokkos() { } +KOKKOS_INLINE_FUNCTION DRaggedRightArrayKokkos::~DRaggedRightArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of DRaggedRightArrayKokkos @@ -7537,9 +6428,8 @@ DRaggedRightArrayKokkos::~DRaggedRightA */ template class DynamicArrayKokkos { - using TArray1D = Kokkos::View; - + private: size_t dims_[7]; size_t dims_actual_size_[7]; @@ -7549,126 +6439,119 @@ class DynamicArrayKokkos { public: DynamicArrayKokkos(); - + DynamicArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; -/* - DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + /* + DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; -*/ - - KOKKOS_INLINE_FUNCTION - DynamicArrayKokkos& operator=(const DynamicArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + */ + + KOKKOS_INLINE_FUNCTION DynamicArrayKokkos& operator=(const DynamicArrayKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; - KOKKOS_INLINE_FUNCTION - size_t dims_max(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - void push_back(T value); - + void pop_back(); - + // Methods returns the raw pointer (most likely GPU) of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val, int count = -1); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DynamicArrayKokkos (); -}; // End of DynamicArrayKokkos + KOKKOS_INLINE_FUNCTION ~DynamicArrayKokkos(); +}; // End of DynamicArrayKokkos // Default constructor template -DynamicArrayKokkos::DynamicArrayKokkos() { +DynamicArrayKokkos::DynamicArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { - dims_[i] = 0; + dims_[i] = 0; dims_actual_size_[i] = 0; } } // Overloaded 1D constructor template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, const std::string& tag_string) { +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; for (int i = 0; i < 1; i++) { dims_actual_size_[i] = 0; } - order_ = 1; - length_ = dim0; + order_ = 1; + length_ = dim0; this_array_ = TArray1D(tag_string, length_); } /* // Overloaded 2D constructor template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - using TArray1D = Kokkos::View; - +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +const std::string& tag_string) { using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; for (int i = 0; i < 2; i++) { @@ -7683,7 +6566,7 @@ template ::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -7699,7 +6582,7 @@ template ::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -7718,7 +6601,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d size_t dim4, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -7737,7 +6620,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -7758,7 +6641,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -7776,8 +6659,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d */ template -KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DynamicArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 1D!"); assert(i < dims_actual_size_[0] && "i is out of bounds in DynamicArrayKokkos 1D dims_actual_size!"); @@ -7788,28 +6670,26 @@ T& DynamicArrayKokkos::operator()(size_t i) con template KOKKOS_INLINE_FUNCTION T& DynamicArrayKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 2D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 2D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 2D!"); - return this_array_(j + (i * dims_[1])); + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos +2D!"); assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 2D!"); assert(j < dims_[1] +&& "j is out of bounds in DynamicArrayKokkos 2D!"); return this_array_(j + (i * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 3D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 3D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 3D!"); - assert(k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 3D!"); - return this_array_(k + (j * dims_[2]) +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k) +const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos +3D!"); assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 3D!"); assert(j < dims_[1] +&& "j is out of bounds in DynamicArrayKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in +DynamicArrayKokkos 3D!"); return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 4D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 4D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, +size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in +DynamicArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 4D!"); @@ -7820,10 +6700,9 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 5D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 5D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in +DynamicArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 5D!"); @@ -7836,11 +6715,10 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 6D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 6D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 6D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match +constructor in DynamicArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in +DynamicArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 6D!"); assert(k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 6D!"); assert(l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 6D!"); @@ -7854,11 +6732,10 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 7D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 7D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 7D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not +match constructor in DynamicArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in +DynamicArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 7D!"); assert(k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 7D!"); assert(l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 7D!"); assert(m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 7D!"); @@ -7874,114 +6751,100 @@ T& DynamicArrayKokkos::operator()(size_t i, siz */ template -KOKKOS_INLINE_FUNCTION -DynamicArrayKokkos& DynamicArrayKokkos::operator= (const DynamicArrayKokkos& temp) { - using TArray1D = Kokkos::View; - +KOKKOS_INLINE_FUNCTION DynamicArrayKokkos& DynamicArrayKokkos::operator=( + const DynamicArrayKokkos& temp) { + using TArray1D = Kokkos::View; + // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ - dims_[iter] = temp.dims_[iter]; + for (int iter = 0; iter < temp.order_; iter++) { + dims_[iter] = temp.dims_[iter]; dims_actual_size_[iter] = temp.dims_actual_size_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DynamicArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DynamicArrayKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DynamicArrayKokkos::dims(size_t i) const { assert(i <= order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); assert(dims_actual_size_[i] >= 0 && "Access to DynamicArrayKokkos dims is out of bounds!"); return dims_actual_size_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::dims_max(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DynamicArrayKokkos::dims_max(size_t i) const { assert(i <= order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); assert(dims_[i] >= 0 && "Access to DynamicArrayKokkos dims is out of bounds!"); return dims_[i]; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DynamicArrayKokkos::order() const { return order_; } template -void DynamicArrayKokkos::pop_back() { +void DynamicArrayKokkos::pop_back() { dims_actual_size_[0]--; } template -void DynamicArrayKokkos::push_back(T value) { +void DynamicArrayKokkos::push_back(T value) { size_t idx = dims_actual_size_[0]; - Kokkos::parallel_for("pushback_DynamicArrayKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(idx) = value; - }); + Kokkos::parallel_for("pushback_DynamicArrayKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(idx) = value; }); dims_actual_size_[0]++; } template -KOKKOS_INLINE_FUNCTION -T* DynamicArrayKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* DynamicArrayKokkos::pointer() const { return this_array_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicArrayKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View DynamicArrayKokkos::get_kokkos_view() + const { return this_array_; } // Get the name of the view template -const std::string DynamicArrayKokkos::get_name() const{ +const std::string DynamicArrayKokkos::get_name() const { return this_array_.label(); } // set values of array template -void DynamicArrayKokkos::set_values(T val, int count) { +void DynamicArrayKokkos::set_values(T val, int count) { assert(count <= dims_[0] && "count is out of bounds in DynamicArrayKokkos set_values!"); - if (count == -1) { // Only set values for the actual size of the array - Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); - } - else { // Set values for a specific number of elements - dims_actual_size_[0] = count; // Update the actual size of the array - Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); + if (count == -1) { // Only set values for the actual size of the array + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); + } else { // Set values for a specific number of elements + dims_actual_size_[0] = count; // Update the actual size of the array + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } } template -KOKKOS_INLINE_FUNCTION -DynamicArrayKokkos::~DynamicArrayKokkos() {} +KOKKOS_INLINE_FUNCTION DynamicArrayKokkos::~DynamicArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of DynamicArrayKokkos @@ -7992,9 +6855,8 @@ DynamicArrayKokkos::~DynamicArrayKokkos() {} */ template class DynamicMatrixKokkos { - using TArray1D = Kokkos::View; - + private: size_t dims_[7]; size_t dims_actual_size_[7]; @@ -8004,126 +6866,119 @@ class DynamicMatrixKokkos { public: DynamicMatrixKokkos(); - + DynamicMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; -/* - DynamicMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + /* + DynamicMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = + DEFAULTSTRINGARRAY); - DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; -*/ - - KOKKOS_INLINE_FUNCTION - DynamicMatrixKokkos& operator=(const DynamicMatrixKokkos& temp); + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + */ + + KOKKOS_INLINE_FUNCTION DynamicMatrixKokkos& operator=(const DynamicMatrixKokkos& temp); // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; - KOKKOS_INLINE_FUNCTION - size_t dims_max(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - void push_back(T value); - + void pop_back(); - + // Methods returns the raw pointer (most likely GPU) of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* pointer() const; + KOKKOS_INLINE_FUNCTION T* pointer() const; // set values void set_values(T val, int count = -1); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view() const; // Get the name of the view const std::string get_name() const; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DynamicMatrixKokkos (); -}; // End of DynamicMatrixKokkos + KOKKOS_INLINE_FUNCTION ~DynamicMatrixKokkos(); +}; // End of DynamicMatrixKokkos // Default constructor template -DynamicMatrixKokkos::DynamicMatrixKokkos() { +DynamicMatrixKokkos::DynamicMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { - dims_[i] = 0; + dims_[i] = 0; dims_actual_size_[i] = 0; } } // Overloaded 1D constructor template -DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, const std::string& tag_string) { +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; for (int i = 0; i < 1; i++) { dims_actual_size_[i] = 0; } - order_ = 1; - length_ = dim0; + order_ = 1; + length_ = dim0; this_array_ = TArray1D(tag_string, length_); } /* // Overloaded 2D constructor template -DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - using TArray1D = Kokkos::View; - +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, +const std::string& tag_string) { using TArray1D = Kokkos::View; + dims_[0] = dim0; dims_[1] = dim1; for (int i = 0; i < 2; i++) { @@ -8138,7 +6993,7 @@ template ::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -8154,7 +7009,7 @@ template ::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -8173,7 +7028,7 @@ DynamicMatrixKokkos::DynamicMatrixKokkos(size_t size_t dim4, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -8192,7 +7047,7 @@ DynamicMatrixKokkos::DynamicMatrixKokkos(size_t size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -8213,7 +7068,7 @@ DynamicMatrixKokkos::DynamicMatrixKokkos(size_t size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { using TArray1D = Kokkos::View; - + dims_[0] = dim0; dims_[1] = dim1; dims_[2] = dim2; @@ -8231,41 +7086,38 @@ DynamicMatrixKokkos::DynamicMatrixKokkos(size_t */ template -KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& DynamicMatrixKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 1D!"); assert(i <= dims_[0] && "i is out of bounds in DynamicMatrixKokkos 1D!"); assert(i > 0 && "i cannot be 0 in DynamicMatrixKokkos 1D!"); assert(i <= dims_actual_size_[0] && "i is out of bounds in DynamicArrayKokkos 1D dims_actual_size!"); - return this_array_((i-1)); + return this_array_((i - 1)); } /* template KOKKOS_INLINE_FUNCTION T& DynamicMatrixKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 2D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 2D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 2D!"); - return this_array_(j + (i * dims_[1])); + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos +2D!"); assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 2D!"); assert(j < dims_[1] +&& "j is out of bounds in DynamicMatrixKokkos 2D!"); return this_array_(j + (i * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 3D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 3D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 3D!"); - assert(k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 3D!"); - return this_array_(k + (j * dims_[2]) +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k) +const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos +3D!"); assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 3D!"); assert(j < dims_[1] +&& "j is out of bounds in DynamicMatrixKokkos 3D!"); assert(k < dims_[2] && "k is out of bounds in +DynamicMatrixKokkos 3D!"); return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 4D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 4D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, +size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in +DynamicMatrixKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 4D!"); assert(k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 4D!"); assert(l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 4D!"); @@ -8276,10 +7128,9 @@ T& DynamicMatrixKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 5D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 5D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in +DynamicMatrixKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 5D!"); assert(k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 5D!"); assert(l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 5D!"); @@ -8292,11 +7143,10 @@ T& DynamicMatrixKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 6D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 6D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 6D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m, size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match +constructor in DynamicMatrixKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in +DynamicMatrixKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 6D!"); assert(k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 6D!"); assert(l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 6D!"); assert(m < dims_[4] && "m is out of bounds in DynamicMatrixKokkos 6D!"); @@ -8310,11 +7160,10 @@ T& DynamicMatrixKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 7D!"); - assert(i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 7D!"); - assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 7D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, +size_t l, size_t m, size_t n, size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not +match constructor in DynamicMatrixKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in +DynamicMatrixKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 7D!"); assert(k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 7D!"); assert(l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 7D!"); assert(m < dims_[4] && "m is out of bounds in DynamicMatrixKokkos 7D!"); @@ -8330,41 +7179,38 @@ T& DynamicMatrixKokkos::operator()(size_t i, si */ template -KOKKOS_INLINE_FUNCTION -DynamicMatrixKokkos& DynamicMatrixKokkos::operator= (const DynamicMatrixKokkos& temp) { - using TArray1D = Kokkos::View; - +KOKKOS_INLINE_FUNCTION DynamicMatrixKokkos& DynamicMatrixKokkos::operator=( + const DynamicMatrixKokkos& temp) { + using TArray1D = Kokkos::View; + // Do nothing if the assignment is of the form x = x if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ - dims_[iter] = temp.dims_[iter]; + for (int iter = 0; iter < temp.order_; iter++) { + dims_[iter] = temp.dims_[iter]; dims_actual_size_[iter] = temp.dims_actual_size_[iter]; - } // end for + } // end for - order_ = temp.order_; - length_ = temp.length_; + order_ = temp.order_; + length_ = temp.length_; this_array_ = temp.this_array_; } - + return *this; } // Return size template -KOKKOS_INLINE_FUNCTION -size_t DynamicMatrixKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t DynamicMatrixKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicMatrixKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t DynamicMatrixKokkos::extent() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicMatrixKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DynamicMatrixKokkos::dims(size_t i) const { i--; assert(i <= order_ && "DynamicMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); assert(dims_actual_size_[i] >= 0 && "Access to DynamicMatrixKokkos dims is out of bounds!"); @@ -8372,8 +7218,7 @@ size_t DynamicMatrixKokkos::dims(size_t i) cons } template -KOKKOS_INLINE_FUNCTION -size_t DynamicMatrixKokkos::dims_max(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DynamicMatrixKokkos::dims_max(size_t i) const { i--; assert(i <= order_ && "DynamicMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); assert(dims_[i] >= 0 && "Access to DynamicMatrixKokkos dims is out of bounds!"); @@ -8381,154 +7226,132 @@ size_t DynamicMatrixKokkos::dims_max(size_t i) } template -KOKKOS_INLINE_FUNCTION -size_t DynamicMatrixKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t DynamicMatrixKokkos::order() const { return order_; } template -void DynamicMatrixKokkos::pop_back() { +void DynamicMatrixKokkos::pop_back() { dims_actual_size_[0]--; } template -void DynamicMatrixKokkos::push_back(T value) { +void DynamicMatrixKokkos::push_back(T value) { size_t idx = dims_actual_size_[0]; - Kokkos::parallel_for("pushback_DynamicMatrixKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(idx) = value; - }); + Kokkos::parallel_for("pushback_DynamicMatrixKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(idx) = value; }); dims_actual_size_[0]++; } template -KOKKOS_INLINE_FUNCTION -T* DynamicMatrixKokkos::pointer() const { +KOKKOS_INLINE_FUNCTION T* DynamicMatrixKokkos::pointer() const { return this_array_.data(); } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicMatrixKokkos::get_kokkos_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::View DynamicMatrixKokkos::get_kokkos_view() + const { return this_array_; } // Get the name of the view template -const std::string DynamicMatrixKokkos::get_name() const{ +const std::string DynamicMatrixKokkos::get_name() const { return this_array_.label(); } // set values of array template -void DynamicMatrixKokkos::set_values(T val, int count) { +void DynamicMatrixKokkos::set_values(T val, int count) { assert(count <= dims_[0] && "count is out of bounds in DynamicArrayKokkos set_values!"); - if (count == -1) { // Only set values for the actual size of the array - Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); - } - else { // Set values for a specific number of elements - + if (count == -1) { // Only set values for the actual size of the array + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); + } else { // Set values for a specific number of elements + dims_actual_size_[0] = count; - Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { - this_array_(i) = val; - }); + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", dims_actual_size_[0], KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } } template -KOKKOS_INLINE_FUNCTION -DynamicMatrixKokkos::~DynamicMatrixKokkos() {} +KOKKOS_INLINE_FUNCTION DynamicMatrixKokkos::~DynamicMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of DynamicMatrixKokkos //////////////////////////////////////////////////////////////////////////////// - /*! \brief Kokkos version of the serial RaggedRightArray class. * */ -template +template class RaggedRightArrayKokkos { + using TArray1D = Kokkos::View; + using SArray1D = Kokkos::View; + using Strides1D = Kokkos::View; - using TArray1D = Kokkos::View; - using SArray1D = Kokkos::View; - using Strides1D = Kokkos::View; - private: TArray1D array_; - + size_t dim1_; size_t length_; - + public: // Default constructor RaggedRightArrayKokkos(); - + //--- 2D array access of a ragged right array --- - + // Overload constructor for a CArrayKokkos - RaggedRightArrayKokkos(CArrayKokkos &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); + RaggedRightArrayKokkos(CArrayKokkos& strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); // Overload constructor for a DCArrayKokkos - RaggedRightArrayKokkos(DCArrayKokkos &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - + RaggedRightArrayKokkos(DCArrayKokkos& strides_array, + const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overload constructor for a ViewCArray - RaggedRightArrayKokkos(ViewCArray &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - + RaggedRightArrayKokkos(ViewCArray& strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overloaded constructor for a traditional array RaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - + // A method to return the stride size - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t stride(size_t i) const; // Host method to return the stride size size_t stride_host(size_t i) const; - + // A method to increase the number of column entries, i.e., // the stride size. Used with the constructor for building // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array - KOKKOS_INLINE_FUNCTION - size_t& build_stride(const size_t i) const; - - KOKKOS_INLINE_FUNCTION - void stride_finalize() const; - + KOKKOS_INLINE_FUNCTION size_t& build_stride(const size_t i) const; + + KOKKOS_INLINE_FUNCTION void stride_finalize() const; + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; // method to return total size - KOKKOS_INLINE_FUNCTION - size_t size(){ - return length_; - } - - //setup start indices + KOKKOS_INLINE_FUNCTION size_t size() { return length_; } + + // setup start indices void data_setup(const std::string& tag_string); - - //return pointer - KOKKOS_INLINE_FUNCTION - T* pointer(); - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view(); - - //print values - // void print() const; - - //set values to input + // return pointer + KOKKOS_INLINE_FUNCTION T* pointer(); + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + // print values + // void print() const; + + // set values to input void set_values(T val); - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; // Get the name of the view const std::string get_name() const; @@ -8536,178 +7359,167 @@ class RaggedRightArrayKokkos { // Kokkos views of strides and start indices Strides1D mystrides_; SArray1D start_index_; - - KOKKOS_INLINE_FUNCTION - RaggedRightArrayKokkos& operator= (const RaggedRightArrayKokkos &temp); - - //initialize start indices view - class init_start_indices_functor{ - public: - SArray1D mystart_index_; - init_start_indices_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - mystart_index_(index) = 0; - } + + KOKKOS_INLINE_FUNCTION RaggedRightArrayKokkos& operator=(const RaggedRightArrayKokkos& temp); + + // initialize start indices view + class init_start_indices_functor { + public: + SArray1D mystart_index_; + init_start_indices_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { mystart_index_(index) = 0; } }; - //setup start indices view - class setup_start_indices_functor{ - public: + // setup start indices view + class setup_start_indices_functor { + public: SArray1D mystart_index_; Strides1D mytemp_strides_; - setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_){ - mystart_index_ = tempstart_index_; - mytemp_strides_ = temp_strides_; + setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_) { + mystart_index_ = tempstart_index_; + mytemp_strides_ = temp_strides_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { - // Load old value in case we update it before accumulating + // Load old value in case we update it before accumulating const size_t count = mytemp_strides_(index); update += count; if (final) { - mystart_index_((index+1)) = update; + mystart_index_((index + 1)) = update; } } }; - //setup length of view - class setup_length_functor{ - public: - //kokkos needs this typedef named + // setup length of view + class setup_length_functor { + public: + // kokkos needs this typedef named typedef size_t value_type; // This is helpful for determining the right index type, // especially if you expect to need a 64-bit index. - //typedef Kokkos::View::size_type size_type; + // typedef Kokkos::View::size_type size_type; Strides1D mytemp_strides_; - setup_length_functor(Strides1D temp_strides_){ - mytemp_strides_ = temp_strides_; - } + setup_length_functor(Strides1D temp_strides_) { mytemp_strides_ = temp_strides_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, size_t& update) const { - //const size_t count = mytemp_strides_(index); + // const size_t count = mytemp_strides_(index); update += mytemp_strides_(index); } }; - //sets final 1D array size - class finalize_stride_functor{ - public: + // sets final 1D array size + class finalize_stride_functor { + public: SArray1D mystart_index_; - finalize_stride_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } + finalize_stride_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { - // Load old value in case we update it before accumulating - const size_t count = mystart_index_(index+1); + // Load old value in case we update it before accumulating + const size_t count = mystart_index_(index + 1); update += count; if (final) { - mystart_index_((index+1)) = update; + mystart_index_((index + 1)) = update; } } }; // Destructor - KOKKOS_INLINE_FUNCTION - ~RaggedRightArrayKokkos ( ); -}; // End of RaggedRightArray + KOKKOS_INLINE_FUNCTION ~RaggedRightArrayKokkos(); +}; // End of RaggedRightArray template -RaggedRightArrayKokkos::RaggedRightArrayKokkos() { +RaggedRightArrayKokkos::RaggedRightArrayKokkos() { dim1_ = length_ = 0; } - // Overloaded constructor template -RaggedRightArrayKokkos::RaggedRightArrayKokkos(CArrayKokkos &strides_array, - const std::string& tag_string) { +RaggedRightArrayKokkos::RaggedRightArrayKokkos( + CArrayKokkos& strides_array, const std::string& tag_string) { mystrides_ = strides_array.get_kokkos_view(); - dim1_ = strides_array.extent(); + dim1_ = strides_array.extent(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor template -RaggedRightArrayKokkos::RaggedRightArrayKokkos(DCArrayKokkos &strides_array, - const std::string& tag_string) { +RaggedRightArrayKokkos::RaggedRightArrayKokkos( + DCArrayKokkos& strides_array, const std::string& tag_string) { mystrides_ = strides_array.get_kokkos_dual_view().view_device(); - dim1_ = strides_array.extent(); + dim1_ = strides_array.extent(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor template -RaggedRightArrayKokkos::RaggedRightArrayKokkos(ViewCArray &strides_array, - const std::string& tag_string) { -} // End constructor +RaggedRightArrayKokkos::RaggedRightArrayKokkos(ViewCArray& strides_array, + const std::string& tag_string) {} // End constructor // Overloaded constructor template -RaggedRightArrayKokkos::RaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, - const std::string& tag_string) { - dim1_ = some_dim1; +RaggedRightArrayKokkos::RaggedRightArrayKokkos(size_t* strides_array, size_t some_dim1, + const std::string& tag_string) { + dim1_ = some_dim1; mystrides_ = Strides1D("mystrides_", dim1_); Kokkos::View host_strides(strides_array, dim1_); Kokkos::deep_copy(mystrides_, host_strides); data_setup(tag_string); -} // End constructor +} // End constructor - -//setup start indices +// setup start indices template -void RaggedRightArrayKokkos::data_setup(const std::string& tag_string) { - //allocate start indices +void RaggedRightArrayKokkos::data_setup(const std::string& tag_string) { + // allocate start indices std::string append_indices_string("_start_indices"); std::string append_array_string("_array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string start_index_tag_string = temp_copy_string.append(append_indices_string); - temp_copy_string = tag_string; - + temp_copy_string = tag_string; - start_index_ = SArray1D(start_index_tag_string,dim1_ + 1); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartValuesInit", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { - start_index_(i) = 0; - }); - #else + start_index_ = SArray1D(start_index_tag_string, dim1_ + 1); +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, KOKKOS_CLASS_LAMBDA(const int i) { start_index_(i) = 0; }); +#else init_start_indices_functor execution_functor(start_index_); - Kokkos::parallel_for("StartValuesInit", dim1_+1,execution_functor); - #endif + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, execution_functor); +#endif - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValuesSetup", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValuesSetup", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { // Load old value in case we update it before accumulating const size_t count = mystrides_(i); update += count; if (final) { - start_index_((i+1)) = update; + start_index_((i + 1)) = update; } - }); - #else +#else setup_start_indices_functor setup_execution_functor(start_index_, mystrides_); - Kokkos::parallel_scan("StartValuesSetup", dim1_,setup_execution_functor); - #endif + Kokkos::parallel_scan("StartValuesSetup", dim1_, setup_execution_functor); +#endif - //compute length of the storage - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_reduce("LengthSetup", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update) { +// compute length of the storage +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_reduce( + "LengthSetup", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update) { // Load old value in case we update it before accumulating update += mystrides_(i); - }, length_); - #else + }, + length_); +#else setup_length_functor length_functor(mystrides_); Kokkos::parallel_reduce("LengthSetup", dim1_, length_functor, length_); - #endif +#endif - //allocate view + // allocate view array_ = TArray1D(tag_string, length_); } // A method to return the stride size template -KOKKOS_INLINE_FUNCTION -size_t RaggedRightArrayKokkos::stride(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t RaggedRightArrayKokkos::stride(size_t i) const { // Ensure that i is within bounds assert(i < (dim1_) && "i is greater than dim1_ in RaggedRightArray"); return mystrides_(i); @@ -8715,182 +7527,169 @@ size_t RaggedRightArrayKokkos::stride(s // Host method to return the stride size template -size_t RaggedRightArrayKokkos::stride_host(size_t i) const { +size_t RaggedRightArrayKokkos::stride_host(size_t i) const { assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArray"); auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, mystrides_); return h(i); } template -KOKKOS_INLINE_FUNCTION -size_t RaggedRightArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t RaggedRightArrayKokkos::dims(size_t i) const { assert(i == 0 && "RaggedRightArrayKokkos dims only supports dims(0)!"); return dim1_; - } - // Method to build the stride (non-Kokkos push back) template -KOKKOS_INLINE_FUNCTION -size_t& RaggedRightArrayKokkos::build_stride(const size_t i) const { - return start_index_(i+1); +KOKKOS_INLINE_FUNCTION size_t& RaggedRightArrayKokkos::build_stride(const size_t i) const { + return start_index_(i + 1); } // Method to finalize stride template -KOKKOS_INLINE_FUNCTION -void RaggedRightArrayKokkos::stride_finalize() const { - - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValues", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { +KOKKOS_INLINE_FUNCTION void RaggedRightArrayKokkos::stride_finalize() const { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValues", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { // Load old value in case we update it before accumulating - const size_t count = start_index_(i+1); + const size_t count = start_index_(i + 1); update += count; if (final) { - start_index_((i+1)) = update; + start_index_((i + 1)) = update; } - }); - #else +#else finalize_stride_functor execution_functor(start_index_); - Kokkos::parallel_scan("StartValues", dim1_,execution_functor); - #endif + Kokkos::parallel_scan("StartValues", dim1_, execution_functor); +#endif Kokkos::fence(); } - // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& RaggedRightArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& RaggedRightArrayKokkos::operator()(size_t i, size_t j) const { // Get the 1D array index size_t start = start_index_(i); - + // asserts - assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArrayKokkos"); // die if >= dim1 + assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArrayKokkos"); // die if >= dim1 assert(j < stride(i) && "j is out of stride bounds in RaggedRightArrayKokkos"); // die if >= stride - + return array_(j + start); -} // End operator() +} // End operator() template -KOKKOS_INLINE_FUNCTION -T* RaggedRightArrayKokkos::pointer() { +KOKKOS_INLINE_FUNCTION T* RaggedRightArrayKokkos::pointer() { return array_.data(); } - template -KOKKOS_INLINE_FUNCTION -RaggedRightArrayKokkos & RaggedRightArrayKokkos:: - operator= (const RaggedRightArrayKokkos &temp) { - - if (this != &temp) { - /* - SArray1D tempdim = SArray1D("tempdim", 1); - auto h_tempdim = HostMirror(tempdim); - Kokkos::parallel_for("StrideDim", 1, KOKKOS_CLASS_LAMBDA(const int&) { - tempdim(0) = strides_array.size(); - //dim1_ = strides_array.size(); - }); - Kokkos::fence(); - deep_copy(h_tempdim, tempdim); - dim1_ = h_tempdim(0); - */ - dim1_ = temp.dim1_; - - // Create and initialize the starting index of the entries in the 1D array - start_index_ = temp.start_index_; - //start_index_(0) = 0; // the 1D array starts at 0 +KOKKOS_INLINE_FUNCTION RaggedRightArrayKokkos& +RaggedRightArrayKokkos::operator=( + const RaggedRightArrayKokkos& temp) { + if (this != &temp) { + /* + SArray1D tempdim = SArray1D("tempdim", 1); + auto h_tempdim = HostMirror(tempdim); + Kokkos::parallel_for("StrideDim", 1, KOKKOS_CLASS_LAMBDA(const int&) { + tempdim(0) = strides_array.size(); + //dim1_ = strides_array.size(); + }); + Kokkos::fence(); + deep_copy(h_tempdim, tempdim); + dim1_ = h_tempdim(0); + */ + dim1_ = temp.dim1_; - /* - size_t * h_start_index = new size_t [dim1_+1]; - h_start_index[0] = 0; - size_t * herenow = new size_t [2]; - herenow[0] = 1; - herenow[1] = 2; - size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ - count += herenow[i]; - h_start_index[(i + 1)] = count; - printf("%d) Start check %ld\n", i, h_start_index[i]); - } // end for i - */ - /* - SArray1D templen = SArray1D("templen", 1); - auto h_templen = Kokkos::create_mirror_view(templen); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("ArrayLength", 1, KOKKOS_CLASS_LAMBDA(const int&) { - templen(0) = start_index_(dim1_); - //length_ = start_index_(dim1_); - }); - #else - templen_functor templen_execution_functor(templen); - Kokkos::parallel_for("ArrayLength", 1, templen_execution_functor); - #endif - Kokkos::fence(); - Kokkos::deep_copy(h_templen, templen); - if (h_templen(0) != 0) - length_ = h_templen(0); - else - */ - length_ = temp.length_; + // Create and initialize the starting index of the entries in the 1D array + start_index_ = temp.start_index_; + // start_index_(0) = 0; // the 1D array starts at 0 + + /* + size_t * h_start_index = new size_t [dim1_+1]; + h_start_index[0] = 0; + size_t * herenow = new size_t [2]; + herenow[0] = 1; + herenow[1] = 2; + size_t count = 0; + for (size_t i = 0; i < dim1_; i++){ + count += herenow[i]; + h_start_index[(i + 1)] = count; + printf("%d) Start check %ld\n", i, h_start_index[i]); + } // end for i + */ + /* + SArray1D templen = SArray1D("templen", 1); + auto h_templen = Kokkos::create_mirror_view(templen); + #ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("ArrayLength", 1, KOKKOS_CLASS_LAMBDA(const int&) { + templen(0) = start_index_(dim1_); + //length_ = start_index_(dim1_); + }); + #else + templen_functor templen_execution_functor(templen); + Kokkos::parallel_for("ArrayLength", 1, templen_execution_functor); + #endif + Kokkos::fence(); + Kokkos::deep_copy(h_templen, templen); + if (h_templen(0) != 0) + length_ = h_templen(0); + else + */ + length_ = temp.length_; + // printf("Length %ld\n", length_); - //printf("Length %ld\n", length_); + // Kokkos::parallel_for("StartCheck", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { + // printf("%d) Start %ld\n", i, start_index_(i)); + // }); + // Kokkos::fence(); - //Kokkos::parallel_for("StartCheck", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { - // printf("%d) Start %ld\n", i, start_index_(i)); - // }); - //Kokkos::fence(); - - array_ = temp.array_; - mystrides_ = temp.mystrides_; + array_ = temp.array_; + mystrides_ = temp.mystrides_; + + /* + dim1_ = temp.dim1_; + length_ = temp.length_; + start_index_ = SArray1D("start_index_", dim1_ + 1); + Kokkos::parallel_for("EqualOperator", dim1_+1, KOKKOS_CLASS_LAMBDA(const int j) { + start_index_(j) = temp.start_index_(j); + }); + //for (int j = 0; j < dim1_; j++) { + // start_index_(j) = temp.start_index_(j); + //} + array_ = TArray1D("array_", length_); + */ + } - /* - dim1_ = temp.dim1_; - length_ = temp.length_; - start_index_ = SArray1D("start_index_", dim1_ + 1); - Kokkos::parallel_for("EqualOperator", dim1_+1, KOKKOS_CLASS_LAMBDA(const int j) { - start_index_(j) = temp.start_index_(j); - }); - //for (int j = 0; j < dim1_; j++) { - // start_index_(j) = temp.start_index_(j); - //} - array_ = TArray1D("array_", length_); - */ - } - return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View RaggedRightArrayKokkos::get_kokkos_view() { +KOKKOS_INLINE_FUNCTION Kokkos::View +RaggedRightArrayKokkos::get_kokkos_view() { return array_; } -//set values to input +// set values to input template -void RaggedRightArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_RaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); +void RaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_RaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Get the name of the view template -const std::string RaggedRightArrayKokkos::get_name() const{ +const std::string RaggedRightArrayKokkos::get_name() const { return array_.label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -RaggedRightArrayKokkos::~RaggedRightArrayKokkos() { } +KOKKOS_INLINE_FUNCTION RaggedRightArrayKokkos::~RaggedRightArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of RaggedRightArrayKokkos @@ -8901,67 +7700,57 @@ RaggedRightArrayKokkos::~RaggedRightArr */ template class RaggedRightArrayofVectorsKokkos { + using TArray1D = Kokkos::View; + using SArray1D = Kokkos::View; + using Strides1D = Kokkos::View; - using TArray1D = Kokkos::View; - using SArray1D = Kokkos::View; - using Strides1D = Kokkos::View; - private: TArray1D array_; - + size_t dim1_, vector_dim_; size_t length_; - + public: // Default constructor RaggedRightArrayofVectorsKokkos(); - + //--- 2D array access of a ragged right array --- - + // Overload constructor for a CArrayKokkos - RaggedRightArrayofVectorsKokkos(CArrayKokkos &strides_array, size_t vector_dim, - const std::string& tag_string = DEFAULTSTRINGARRAY ); - + RaggedRightArrayofVectorsKokkos(CArrayKokkos& strides_array, size_t vector_dim, + const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overload constructor for a ViewCArray - RaggedRightArrayofVectorsKokkos(ViewCArray &strides_array, size_t vector_dim, const std::string& tag_string = DEFAULTSTRINGARRAY); - + RaggedRightArrayofVectorsKokkos(ViewCArray& strides_array, size_t vector_dim, const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overloaded constructor for a traditional array RaggedRightArrayofVectorsKokkos(size_t* strides_array, size_t some_dim1, size_t vector_dim, const std::string& tag_string = DEFAULTSTRINGARRAY); - + // A method to return the stride size - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; - + KOKKOS_INLINE_FUNCTION size_t stride(size_t i) const; + // A method to increase the number of column entries, i.e., // the stride size. Used with the constructor for building // the stride_array dynamically. // DO NOT USE with the constructures with a strides_array - KOKKOS_INLINE_FUNCTION - size_t& build_stride(const size_t i) const; - - KOKKOS_INLINE_FUNCTION - void stride_finalize() const; - + KOKKOS_INLINE_FUNCTION size_t& build_stride(const size_t i) const; + + KOKKOS_INLINE_FUNCTION void stride_finalize() const; + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; // method to return total size - KOKKOS_INLINE_FUNCTION - size_t size() const{ - return length_; - } - - //setup start indices + KOKKOS_INLINE_FUNCTION size_t size() const { return length_; } + + // setup start indices void data_setup(const std::string& tag_string); - - KOKKOS_INLINE_FUNCTION - T* pointer(); - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view(); + KOKKOS_INLINE_FUNCTION T* pointer(); + + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); // Get the name of the view const std::string get_name() const; @@ -8969,79 +7758,73 @@ class RaggedRightArrayofVectorsKokkos { // Kokkos views of strides and start indices Strides1D mystrides_; SArray1D start_index_; - - KOKKOS_INLINE_FUNCTION - RaggedRightArrayofVectorsKokkos& operator= (const RaggedRightArrayofVectorsKokkos &temp); - //functors for kokkos execution policies - // initialize start indices view - class init_start_indices_functor{ - public: - SArray1D mystart_index_; - init_start_indices_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - mystart_index_(index) = 0; - } + KOKKOS_INLINE_FUNCTION RaggedRightArrayofVectorsKokkos& operator=(const RaggedRightArrayofVectorsKokkos& temp); + + // functors for kokkos execution policies + // initialize start indices view + class init_start_indices_functor { + public: + SArray1D mystart_index_; + init_start_indices_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { mystart_index_(index) = 0; } }; - //setup start indices view - class setup_start_indices_functor{ - public: + // setup start indices view + class setup_start_indices_functor { + public: SArray1D mystart_index_; Strides1D mytemp_strides_; size_t myvector_dim_; - setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_, size_t myvector_dim){ - mystart_index_ = tempstart_index_; - mytemp_strides_ = temp_strides_; - myvector_dim_ = myvector_dim; + setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_, size_t myvector_dim) { + mystart_index_ = tempstart_index_; + mytemp_strides_ = temp_strides_; + myvector_dim_ = myvector_dim; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { - // Load old value in case we update it before accumulating - const size_t count = mytemp_strides_(index)*myvector_dim_; + // Load old value in case we update it before accumulating + const size_t count = mytemp_strides_(index) * myvector_dim_; update += count; if (final) { - mystart_index_((index+1)) = update; + mystart_index_((index + 1)) = update; } } }; - //setup length of view - class setup_length_functor{ - public: - //kokkos needs this typedef named + // setup length of view + class setup_length_functor { + public: + // kokkos needs this typedef named typedef size_t value_type; // This is helpful for determining the right index type, // especially if you expect to need a 64-bit index. - //typedef Kokkos::View::size_type size_type; + // typedef Kokkos::View::size_type size_type; Strides1D mytemp_strides_; size_t myvector_dim_; - setup_length_functor(Strides1D temp_strides_, size_t myvector_dim){ - mytemp_strides_ = temp_strides_; - myvector_dim_ = myvector_dim; + setup_length_functor(Strides1D temp_strides_, size_t myvector_dim) { + mytemp_strides_ = temp_strides_; + myvector_dim_ = myvector_dim; } KOKKOS_INLINE_FUNCTION void operator()(const int index, size_t& update) const { - //const size_t count = mytemp_strides_(index)*myvector_dim_; - update += mytemp_strides_(index)*myvector_dim_;; + // const size_t count = mytemp_strides_(index)*myvector_dim_; + update += mytemp_strides_(index) * myvector_dim_; + ; } }; - //sets final 1D array size - class finalize_stride_functor{ - public: + // sets final 1D array size + class finalize_stride_functor { + public: SArray1D mystart_index_; - finalize_stride_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } + finalize_stride_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { - // Load old value in case we update it before accumulating - const size_t count = mystart_index_(index+1); + // Load old value in case we update it before accumulating + const size_t count = mystart_index_(index + 1); update += count; if (final) { - mystart_index_((index+1)) = update; + mystart_index_((index + 1)) = update; } } }; @@ -9050,31 +7833,30 @@ class RaggedRightArrayofVectorsKokkos { void set_values(T val); // Destructor - KOKKOS_INLINE_FUNCTION - ~RaggedRightArrayofVectorsKokkos ( ); -}; // End of RaggedRightArrayofVectorsKokkos + KOKKOS_INLINE_FUNCTION ~RaggedRightArrayofVectorsKokkos(); +}; // End of RaggedRightArrayofVectorsKokkos template -RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos() { +RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos() { dim1_ = length_ = vector_dim_ = 0; } // Overloaded constructor template -RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(CArrayKokkos - &strides_array, size_t vector_dim, - const std::string& tag_string) { - //mystrides_.assign_data(strides_array.pointer()); +RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos( + CArrayKokkos& strides_array, size_t vector_dim, const std::string& tag_string) { + // mystrides_.assign_data(strides_array.pointer()); vector_dim_ = vector_dim; - mystrides_ = strides_array.get_kokkos_view(); - dim1_ = strides_array.extent(); + mystrides_ = strides_array.get_kokkos_view(); + dim1_ = strides_array.extent(); data_setup(tag_string); -} // End constructor +} // End constructor /* template RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(CArrayKokkos - &strides_array, size_t vector_dim) { + &strides_array, +size_t vector_dim) { //mystrides_.assign_data(strides_array.pointer()); vector_dim_ = vector_dim; mystrides_ = strides_array; @@ -9084,75 +7866,79 @@ RaggedRightArrayofVectorsKokkos::RaggedRightArr // Overloaded constructor template -RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(ViewCArray &strides_array, size_t vector_dim, - const std::string& tag_string) { -} // End constructor +RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(ViewCArray& strides_array, + size_t vector_dim, + const std::string& tag_string) { +} // End constructor // Overloaded constructor template -RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(size_t* strides_array, size_t some_dim1, size_t vector_dim, - const std::string& tag_string) { +RaggedRightArrayofVectorsKokkos::RaggedRightArrayofVectorsKokkos(size_t* strides_array, size_t some_dim1, + size_t vector_dim, + const std::string& tag_string) { vector_dim_ = vector_dim; mystrides_.assign_data(strides_array); dim1_ = some_dim1; data_setup(tag_string); -} // End constructor +} // End constructor -//setup start indices +// setup start indices template -void RaggedRightArrayofVectorsKokkos::data_setup(const std::string& tag_string) { - - //allocate start indices +void RaggedRightArrayofVectorsKokkos::data_setup(const std::string& tag_string) { + // allocate start indices std::string append_indices_string("_start_indices"); std::string append_array_string("_array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string start_index_tag_string = temp_copy_string.append(append_indices_string); - temp_copy_string = tag_string; - - start_index_ = SArray1D(start_index_tag_string,dim1_ + 1); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartValuesInit", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { - start_index_(i) = 0; - }); - #else + temp_copy_string = tag_string; + + start_index_ = SArray1D(start_index_tag_string, dim1_ + 1); +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, KOKKOS_CLASS_LAMBDA(const int i) { start_index_(i) = 0; }); +#else init_start_indices_functor execution_functor(start_index_); - Kokkos::parallel_for("StartValuesInit", dim1_+1,execution_functor); - #endif + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, execution_functor); +#endif - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValuesSetup", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValuesSetup", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { // Load old value in case we update it before accumulating - const size_t count = mystrides_(i)*vector_dim_; + const size_t count = mystrides_(i) * vector_dim_; update += count; if (final) { - start_index_((i+1)) = update; + start_index_((i + 1)) = update; } - }); - #else +#else setup_start_indices_functor setup_execution_functor(start_index_, mystrides_, vector_dim_); - Kokkos::parallel_scan("StartValuesSetup", dim1_,setup_execution_functor); - #endif + Kokkos::parallel_scan("StartValuesSetup", dim1_, setup_execution_functor); +#endif - //compute length of the storage - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_reduce("LengthSetup", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update) { +// compute length of the storage +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_reduce( + "LengthSetup", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update) { // Load old value in case we update it before accumulating - update += mystrides_(i)*vector_dim_; - }, length_); - #else + update += mystrides_(i) * vector_dim_; + }, + length_); +#else setup_length_functor length_functor(mystrides_, vector_dim_); - Kokkos::parallel_reduce("LengthSetup", dim1_, length_functor,length_); - #endif + Kokkos::parallel_reduce("LengthSetup", dim1_, length_functor, length_); +#endif - //allocate view + // allocate view array_ = TArray1D(tag_string, length_); } // A method to return the stride size template -KOKKOS_INLINE_FUNCTION -size_t RaggedRightArrayofVectorsKokkos::stride(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t RaggedRightArrayofVectorsKokkos::stride(size_t i) const { // Ensure that i is within bounds assert(i < (dim1_) && "i is greater than dim1_ in RaggedRightArray"); return mystrides_(i); @@ -9160,102 +7946,93 @@ size_t RaggedRightArrayofVectorsKokkos: // Method to build the stride (non-Kokkos push back) template -KOKKOS_INLINE_FUNCTION -size_t& RaggedRightArrayofVectorsKokkos::build_stride(const size_t i) const { - return start_index_(i+1); +KOKKOS_INLINE_FUNCTION size_t& RaggedRightArrayofVectorsKokkos::build_stride(const size_t i) const { + return start_index_(i + 1); } // Method to finalize stride template -KOKKOS_INLINE_FUNCTION -void RaggedRightArrayofVectorsKokkos::stride_finalize() const { - - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValues", dim1_, KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { +KOKKOS_INLINE_FUNCTION void RaggedRightArrayofVectorsKokkos::stride_finalize() const { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValues", + dim1_, + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { // Load old value in case we update it before accumulating - const size_t count = start_index_(i+1); + const size_t count = start_index_(i + 1); update += count; if (final) { - start_index_((i+1)) = update; + start_index_((i + 1)) = update; } - }); - #else +#else finalize_stride_functor execution_functor(start_index_); Kokkos::parallel_scan("StartValues", dim1_, execution_functor); - #endif +#endif Kokkos::fence(); } - // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& RaggedRightArrayofVectorsKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& RaggedRightArrayofVectorsKokkos::operator()(size_t i, size_t j, + size_t k) const { // Get the 1D array index size_t start = start_index_(i); - + // asserts - assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArrayKokkos"); // die if >= dim1 - assert(j < stride(i) && "j is out of stride bounds in RaggedRightArrayKokkos"); // die if >= stride + assert(i < dim1_ && "i is out of dim1 bounds in RaggedRightArrayKokkos"); // die if >= dim1 + assert(j < stride(i) && "j is out of stride bounds in RaggedRightArrayKokkos"); // die if >= stride assert(k < vector_dim_ && "k is out of vector_dim bounds in RaggedRightArrayKokkos"); // die if >= vector_dim - - return array_(j*vector_dim_ + start + k); -} // End operator() + + return array_(j * vector_dim_ + start + k); +} // End operator() template -KOKKOS_INLINE_FUNCTION -T* RaggedRightArrayofVectorsKokkos::pointer() { +KOKKOS_INLINE_FUNCTION T* RaggedRightArrayofVectorsKokkos::pointer() { return array_.data(); } - template -KOKKOS_INLINE_FUNCTION -RaggedRightArrayofVectorsKokkos & RaggedRightArrayofVectorsKokkos:: - operator= (const RaggedRightArrayofVectorsKokkos &temp) { - - if (this != &temp) { - dim1_ = temp.dim1_; - vector_dim_ = temp.vector_dim_; - - // Create and initialize the starting index of the entries in the 1D array - start_index_ = temp.start_index_; - length_ = temp.length_; - - array_ = temp.array_; - mystrides_ = temp.mystrides_; - } - +KOKKOS_INLINE_FUNCTION RaggedRightArrayofVectorsKokkos& +RaggedRightArrayofVectorsKokkos::operator=( + const RaggedRightArrayofVectorsKokkos& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + vector_dim_ = temp.vector_dim_; + + // Create and initialize the starting index of the entries in the 1D array + start_index_ = temp.start_index_; + length_ = temp.length_; + + array_ = temp.array_; + mystrides_ = temp.mystrides_; + } + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View RaggedRightArrayofVectorsKokkos::get_kokkos_view() { +KOKKOS_INLINE_FUNCTION Kokkos::View +RaggedRightArrayofVectorsKokkos::get_kokkos_view() { return array_; } - template -void RaggedRightArrayofVectorsKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - array_(i) = val; - }); +void RaggedRightArrayofVectorsKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, length_), KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Get the name of the view template -const std::string RaggedRightArrayofVectorsKokkos::get_name() const{ +const std::string RaggedRightArrayofVectorsKokkos::get_name() const { return array_.label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -RaggedRightArrayofVectorsKokkos::~RaggedRightArrayofVectorsKokkos() { } +KOKKOS_INLINE_FUNCTION RaggedRightArrayofVectorsKokkos::~RaggedRightArrayofVectorsKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of RaggedRightArrayofVectorsKokkos @@ -9264,121 +8041,106 @@ RaggedRightArrayofVectorsKokkos::~Ragge /*! \brief Kokkos version of the serial RaggedDownArray class. * */ -template +template class RaggedDownArrayKokkos { + using TArray1D = Kokkos::View; + using SArray1D = Kokkos::View; + using Strides1D = Kokkos::View; - using TArray1D = Kokkos::View; - using SArray1D = Kokkos::View; - using Strides1D = Kokkos::View; - private: TArray1D array_; - + size_t dim2_; size_t length_; - + public: // Default constructor RaggedDownArrayKokkos(); - + //--- 2D array access of a ragged right array --- - + // Overload constructor for a CArray - RaggedDownArrayKokkos(CArrayKokkos &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - + RaggedDownArrayKokkos(CArrayKokkos& strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overload constructor for a ViewCArray - RaggedDownArrayKokkos(ViewCArray &strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); - + RaggedDownArrayKokkos(ViewCArray& strides_array, const std::string& tag_string = DEFAULTSTRINGARRAY); + // Overloaded constructor for a traditional array RaggedDownArrayKokkos(size_t* strides_array, size_t some_dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); // A method to return the stride size - KOKKOS_INLINE_FUNCTION - size_t stride(size_t j) const; + KOKKOS_INLINE_FUNCTION size_t stride(size_t j) const; // Host method to return the stride size size_t stride_host(size_t j) const; - //setup start indices + // setup start indices void data_setup(const std::string& tag_string); - + // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - - //return pointer - KOKKOS_INLINE_FUNCTION - T* pointer(); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view(); + // return pointer + KOKKOS_INLINE_FUNCTION T* pointer(); - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; // A method to return the total number of elements (sum of strides) - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Get the name of the view const std::string get_name() const; - - KOKKOS_INLINE_FUNCTION - RaggedDownArrayKokkos& operator= (const RaggedDownArrayKokkos &temp); - + + KOKKOS_INLINE_FUNCTION RaggedDownArrayKokkos& operator=(const RaggedDownArrayKokkos& temp); + // Kokkos views of strides and start indices Strides1D mystrides_; SArray1D start_index_; - - //functors for kokkos execution policies - //initialize start indices view - class init_start_indices_functor{ - public: - SArray1D mystart_index_; - init_start_indices_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - mystart_index_(index) = 0; - } + + // functors for kokkos execution policies + // initialize start indices view + class init_start_indices_functor { + public: + SArray1D mystart_index_; + init_start_indices_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { mystart_index_(index) = 0; } }; - //setup start indices view - class setup_start_indices_functor{ - public: + // setup start indices view + class setup_start_indices_functor { + public: SArray1D mystart_index_; Strides1D mytemp_strides_; - setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_){ - mystart_index_ = tempstart_index_; - mytemp_strides_ = temp_strides_; + setup_start_indices_functor(SArray1D tempstart_index_, Strides1D temp_strides_) { + mystart_index_ = tempstart_index_; + mytemp_strides_ = temp_strides_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, int& update, bool final) const { - // Load old value in case we update it before accumulating + // Load old value in case we update it before accumulating const size_t count = mytemp_strides_(index); update += count; if (final) { - mystart_index_((index+1)) = update; + mystart_index_((index + 1)) = update; } } }; - //setup length of view - class setup_length_functor{ - public: - //kokkos needs this typedef named + // setup length of view + class setup_length_functor { + public: + // kokkos needs this typedef named typedef size_t value_type; // This is helpful for determining the right index type, // especially if you expect to need a 64-bit index. - //typedef Kokkos::View::size_type size_type; + // typedef Kokkos::View::size_type size_type; Strides1D mytemp_strides_; - setup_length_functor(Strides1D temp_strides_){ - mytemp_strides_ = temp_strides_; - } + setup_length_functor(Strides1D temp_strides_) { mytemp_strides_ = temp_strides_; } KOKKOS_INLINE_FUNCTION void operator()(const int index, size_t& update) const { - //const size_t count = mytemp_strides_(index); + // const size_t count = mytemp_strides_(index); update += mytemp_strides_(index); } }; @@ -9387,92 +8149,94 @@ class RaggedDownArrayKokkos { void set_values(T val); // Destructor - KOKKOS_INLINE_FUNCTION - ~RaggedDownArrayKokkos ( ); -}; // End of RaggedDownArray + KOKKOS_INLINE_FUNCTION ~RaggedDownArrayKokkos(); +}; // End of RaggedDownArray template -RaggedDownArrayKokkos::RaggedDownArrayKokkos() { +RaggedDownArrayKokkos::RaggedDownArrayKokkos() { dim2_ = length_ = 0; } // Overloaded constructor template -RaggedDownArrayKokkos::RaggedDownArrayKokkos(CArrayKokkos &strides_array, - const std::string& tag_string) { +RaggedDownArrayKokkos::RaggedDownArrayKokkos( + CArrayKokkos& strides_array, const std::string& tag_string) { mystrides_ = strides_array.get_kokkos_view(); - dim2_ = strides_array.extent(); + dim2_ = strides_array.extent(); data_setup(tag_string); -} // End constructor +} // End constructor // Overloaded constructor template -RaggedDownArrayKokkos::RaggedDownArrayKokkos(ViewCArray &strides_array, const std::string& tag_string) { -} // End constructor +RaggedDownArrayKokkos::RaggedDownArrayKokkos(ViewCArray& strides_array, + const std::string& tag_string) {} // End constructor // Overloaded constructor template -RaggedDownArrayKokkos::RaggedDownArrayKokkos(size_t* strides_array, size_t some_dim2, - const std::string& tag_string) { +RaggedDownArrayKokkos::RaggedDownArrayKokkos(size_t* strides_array, size_t some_dim2, + const std::string& tag_string) { mystrides_.assign_data(strides_array); dim2_ = some_dim2; data_setup(tag_string); -} // End constructor +} // End constructor -//setup start indices +// setup start indices template -void RaggedDownArrayKokkos::data_setup(const std::string& tag_string) { - //allocate start indices +void RaggedDownArrayKokkos::data_setup(const std::string& tag_string) { + // allocate start indices std::string append_indices_string("_start_indices"); std::string append_array_string("_array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string start_index_tag_string = temp_copy_string.append(append_indices_string); - temp_copy_string = tag_string; - - start_index_ = SArray1D(start_index_tag_string,dim2_ + 1); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartValuesInit", dim2_+1, KOKKOS_CLASS_LAMBDA(const int i) { - start_index_(i) = 0; - }); - #else + temp_copy_string = tag_string; + + start_index_ = SArray1D(start_index_tag_string, dim2_ + 1); +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartValuesInit", dim2_ + 1, KOKKOS_CLASS_LAMBDA(const int i) { start_index_(i) = 0; }); +#else init_start_indices_functor execution_functor(start_index_); - Kokkos::parallel_for("StartValuesInit", dim2_+1,execution_functor); - #endif + Kokkos::parallel_for("StartValuesInit", dim2_ + 1, execution_functor); +#endif - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValuesSetup", dim2_, KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan( + "StartValuesSetup", + dim2_, + KOKKOS_CLASS_LAMBDA(const int i, int& update, const bool final) { // Load old value in case we update it before accumulating const size_t count = mystrides_(i); update += count; if (final) { - start_index_((i+1)) = update; + start_index_((i + 1)) = update; } - }); - #else +#else setup_start_indices_functor setup_execution_functor(start_index_, mystrides_); - Kokkos::parallel_scan("StartValuesSetup", dim2_,setup_execution_functor); - #endif + Kokkos::parallel_scan("StartValuesSetup", dim2_, setup_execution_functor); +#endif - //compute length of the storage - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_reduce("LengthSetup", dim2_, KOKKOS_CLASS_LAMBDA(const int i, int& update) { +// compute length of the storage +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_reduce( + "LengthSetup", + dim2_, + KOKKOS_CLASS_LAMBDA(const int i, int& update) { // Load old value in case we update it before accumulating update += mystrides_(i); - }, length_); - #else + }, + length_); +#else setup_length_functor length_functor(mystrides_); Kokkos::parallel_reduce("LengthSetup", dim2_, length_functor, length_); - #endif +#endif - //allocate view + // allocate view array_ = TArray1D(tag_string, length_); } // A method to return the stride size template -KOKKOS_INLINE_FUNCTION -size_t RaggedDownArrayKokkos::stride(size_t j) const { +KOKKOS_INLINE_FUNCTION size_t RaggedDownArrayKokkos::stride(size_t j) const { // Ensure that j is within bounds assert(j < (dim2_) && "j is greater than dim1_ in RaggedDownArray"); @@ -9481,7 +8245,7 @@ size_t RaggedDownArrayKokkos::stride(si // Host method to return the stride size template -size_t RaggedDownArrayKokkos::stride_host(size_t j) const { +size_t RaggedDownArrayKokkos::stride_host(size_t j) const { assert(j < dim2_ && "j is out of dim2 bounds in RaggedDownArray"); auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, mystrides_); return h(j); @@ -9489,242 +8253,228 @@ size_t RaggedDownArrayKokkos::stride_ho // A method to return the total number of elements (sum of strides) template -KOKKOS_INLINE_FUNCTION -size_t RaggedDownArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t RaggedDownArrayKokkos::size() const { return length_; } // Overload operator() to access data as array(i,j) // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& RaggedDownArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& RaggedDownArrayKokkos::operator()(size_t i, size_t j) const { // Get the 1D array index size_t start = start_index_(j); - + // asserts assert(i < stride(j) && "i is out of stride bounds in RaggedDownArrayKokkos"); // die if >= stride - assert(j < dim2_ && "j is out of dim1 bounds in RaggedDownArrayKokkos"); // die if >= dim1 - + assert(j < dim2_ && "j is out of dim1 bounds in RaggedDownArrayKokkos"); // die if >= dim1 + return array_(i + start); -} // End operator() +} // End operator() template -KOKKOS_INLINE_FUNCTION -RaggedDownArrayKokkos& RaggedDownArrayKokkos:: -operator= (const RaggedDownArrayKokkos &temp) { - - if (this != &temp) { - /* - SArray1D tempdim = SArray1D("tempdim", 1); - auto h_tempdim = HostMirror(tempdim); - Kokkos::parallel_for("StrideDim", 1, KOKKOS_CLASS_LAMBDA(const int&) { - tempdim(0) = strides_array.size(); - //dim1_ = strides_array.size(); - }); - Kokkos::fence(); - deep_copy(h_tempdim, tempdim); - dim1_ = h_tempdim(0); - */ - dim2_ = temp.dim2_; - - // Create and initialize the starting index of the entries in the 1D array - start_index_ = temp.start_index_; - /* - //start_index_(0) = 0; // the 1D array starts at 0 - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartFirst", 1, KOKKOS_CLASS_LAMBDA(const int&) { - start_index_(0) = 0; - }); - #else - assignment_init_functor init_execution_functor; - Kokkos::parallel_for("StartFirst", 1, init_execution_functor); - #endif - Kokkos::fence(); - - // Loop over to find the total length of the 1D array to - // represent the ragged-right array and set the starting 1D index - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_scan("StartValues", dim2_, KOKKOS_CLASS_LAMBDA(const int j, double& update, const bool final) { - // Load old value in case we update it before accumulating - const size_t count = temp.mystrides_[j]; - update += count; - if (final) { - start_index_((j+1)) = update; - } +KOKKOS_INLINE_FUNCTION RaggedDownArrayKokkos& +RaggedDownArrayKokkos::operator=( + const RaggedDownArrayKokkos& temp) { + if (this != &temp) { + /* + SArray1D tempdim = SArray1D("tempdim", 1); + auto h_tempdim = HostMirror(tempdim); + Kokkos::parallel_for("StrideDim", 1, KOKKOS_CLASS_LAMBDA(const int&) { + tempdim(0) = strides_array.size(); + //dim1_ = strides_array.size(); + }); + Kokkos::fence(); + deep_copy(h_tempdim, tempdim); + dim1_ = h_tempdim(0); + */ + dim2_ = temp.dim2_; - }); - #else - assignment_scan_functor scan_execution_functor(temp); - Kokkos::parallel_scan("StartValues", dim2_, scan_execution_functor); - #endif - Kokkos::fence(); - */ - /* - size_t * h_start_index = new size_t [dim1_+1]; - h_start_index[0] = 0; - size_t * herenow = new size_t [2]; - herenow[0] = 1; - herenow[1] = 2; - size_t count = 0; - for (size_t i = 0; i < dim1_; i++){ - count += herenow[i]; - h_start_index[(i + 1)] = count; - printf("%d) Start check %ld\n", i, h_start_index[i]); - } // end for i - */ - /* - SArray1D templen = SArray1D("templen", 1); - auto h_templen = Kokkos::create_mirror_view(templen); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("ArrayLength", 1, KOKKOS_CLASS_LAMBDA(const int&) { - templen(0) = start_index_(dim2_); - //length_ = start_index_(dim2_); - }); - #else - templen_functor templen_execution_functor(templen); - Kokkos::parallel_for("ArrayLength", 1, templen_execution_functor); - #endif - Kokkos::fence(); - deep_copy(h_templen, templen); - length_ = h_templen(0); - - printf("Length %ld\n", length_); - - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartCheck", dim2_+1, KOKKOS_CLASS_LAMBDA(const int j) { - printf("%d) Start %ld\n", j, start_index_(j)); - }); - #else - stride_check_functor check_execution_functor; - Kokkos::parallel_for("StartCheck", dim2_+1, check_execution_functor); - #endif - Kokkos::fence(); - */ - length_ = temp.length_; - array_ = temp.array_; - mystrides_ = temp.mystrides_; + // Create and initialize the starting index of the entries in the 1D array + start_index_ = temp.start_index_; + /* + //start_index_(0) = 0; // the 1D array starts at 0 + #ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartFirst", 1, KOKKOS_CLASS_LAMBDA(const int&) { + start_index_(0) = 0; + }); + #else + assignment_init_functor init_execution_functor; + Kokkos::parallel_for("StartFirst", 1, init_execution_functor); + #endif + Kokkos::fence(); + + // Loop over to find the total length of the 1D array to + // represent the ragged-right array and set the starting 1D index + #ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_scan("StartValues", dim2_, KOKKOS_CLASS_LAMBDA(const int j, double& update, + const bool final) { + // Load old value in case we update it before accumulating + const size_t count = temp.mystrides_[j]; + update += count; + if (final) { + start_index_((j+1)) = update; + } - /* - dim1_ = temp.dim1_; - length_ = temp.length_; - start_index_ = SArray1D("start_index_", dim1_ + 1); - Kokkos::parallel_for("EqualOperator", dim1_+1, KOKKOS_CLASS_LAMBDA(const int j) { - start_index_(j) = temp.start_index_(j); }); - //for (int j = 0; j < dim1_; j++) { - // start_index_(j) = temp.start_index_(j); - //} - array_ = TArray1D("array_", length_); - */ - } - + #else + assignment_scan_functor scan_execution_functor(temp); + Kokkos::parallel_scan("StartValues", dim2_, scan_execution_functor); + #endif + Kokkos::fence(); + */ + /* + size_t * h_start_index = new size_t [dim1_+1]; + h_start_index[0] = 0; + size_t * herenow = new size_t [2]; + herenow[0] = 1; + herenow[1] = 2; + size_t count = 0; + for (size_t i = 0; i < dim1_; i++){ + count += herenow[i]; + h_start_index[(i + 1)] = count; + printf("%d) Start check %ld\n", i, h_start_index[i]); + } // end for i + */ + /* + SArray1D templen = SArray1D("templen", 1); + auto h_templen = Kokkos::create_mirror_view(templen); + #ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("ArrayLength", 1, KOKKOS_CLASS_LAMBDA(const int&) { + templen(0) = start_index_(dim2_); + //length_ = start_index_(dim2_); + }); + #else + templen_functor templen_execution_functor(templen); + Kokkos::parallel_for("ArrayLength", 1, templen_execution_functor); + #endif + Kokkos::fence(); + deep_copy(h_templen, templen); + length_ = h_templen(0); + + printf("Length %ld\n", length_); + + #ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartCheck", dim2_+1, KOKKOS_CLASS_LAMBDA(const int j) { + printf("%d) Start %ld\n", j, start_index_(j)); + }); + #else + stride_check_functor check_execution_functor; + Kokkos::parallel_for("StartCheck", dim2_+1, check_execution_functor); + #endif + Kokkos::fence(); + */ + length_ = temp.length_; + array_ = temp.array_; + mystrides_ = temp.mystrides_; + + /* + dim1_ = temp.dim1_; + length_ = temp.length_; + start_index_ = SArray1D("start_index_", dim1_ + 1); + Kokkos::parallel_for("EqualOperator", dim1_+1, KOKKOS_CLASS_LAMBDA(const int j) { + start_index_(j) = temp.start_index_(j); + }); + //for (int j = 0; j < dim1_; j++) { + // start_index_(j) = temp.start_index_(j); + //} + array_ = TArray1D("array_", length_); + */ + } + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View RaggedDownArrayKokkos::get_kokkos_view() { +KOKKOS_INLINE_FUNCTION Kokkos::View +RaggedDownArrayKokkos::get_kokkos_view() { return array_; } -//set values to input +// set values to input template -void RaggedDownArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_RaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); +void RaggedDownArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_RaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Get the name of the view template -const std::string RaggedDownArrayKokkos::get_name() const{ +const std::string RaggedDownArrayKokkos::get_name() const { return array_.label(); } template -KOKKOS_INLINE_FUNCTION -size_t RaggedDownArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t RaggedDownArrayKokkos::dims(size_t i) const { assert(i == 0 && "RaggedDownArrayKokkos only supports dims(0) to get size of the strides"); return dim2_; } // Destructor template -KOKKOS_INLINE_FUNCTION -RaggedDownArrayKokkos::~RaggedDownArrayKokkos() { } +KOKKOS_INLINE_FUNCTION RaggedDownArrayKokkos::~RaggedDownArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// // End of RaggedDownArrayKokkos //////////////////////////////////////////////////////////////////////////////// -//11. DynamicRaggedRightArray +// 11. DynamicRaggedRightArray template class DynamicRaggedRightArrayKokkos { - using TArray1D = Kokkos::View; - using SArray1D = Kokkos::View; - + using SArray1D = Kokkos::View; + private: // THIS WILL BE A GPU POINTER! SArray1D stride_; TArray1D array_; - + size_t dim1_; size_t dim2_; size_t length_; - + public: // Default constructor - DynamicRaggedRightArrayKokkos (); - + DynamicRaggedRightArrayKokkos(); + //--- 2D array access of a ragged right array --- - + // overload constructor - DynamicRaggedRightArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - + DynamicRaggedRightArrayKokkos(size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + // A method to return or set the stride size - KOKKOS_INLINE_FUNCTION - size_t& stride(size_t i) const; - + KOKKOS_INLINE_FUNCTION size_t& stride(size_t i) const; + // A method to return the size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view(); + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); // Get the name of the view const std::string get_name() const; - + // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + // Overload copy assignment operator - KOKKOS_INLINE_FUNCTION - DynamicRaggedRightArrayKokkos& operator= (const DynamicRaggedRightArrayKokkos &temp); - - //kokkos policy functors - - //functors for kokkos execution policies - //set strides to a constant value - class set_strides_functor{ - public: - SArray1D functor_strides_; - size_t init_stride_; - set_strides_functor(size_t init_stride, SArray1D temp_strides_){ - init_stride_ = init_stride; - functor_strides_ = temp_strides_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - functor_strides_(index) = init_stride_; - } + KOKKOS_INLINE_FUNCTION DynamicRaggedRightArrayKokkos& operator=(const DynamicRaggedRightArrayKokkos& temp); + + // kokkos policy functors + + // functors for kokkos execution policies + // set strides to a constant value + class set_strides_functor { + public: + SArray1D functor_strides_; + size_t init_stride_; + set_strides_functor(size_t init_stride, SArray1D temp_strides_) { + init_stride_ = init_stride; + functor_strides_ = temp_strides_; + } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { functor_strides_(index) = init_stride_; } }; - + // set values on host to input void set_values(T val); @@ -9732,85 +8482,79 @@ class DynamicRaggedRightArrayKokkos { void set_values_sparse(T val); // Destructor - KOKKOS_INLINE_FUNCTION - ~DynamicRaggedRightArrayKokkos (); + KOKKOS_INLINE_FUNCTION ~DynamicRaggedRightArrayKokkos(); }; -//nothing +// nothing template -DynamicRaggedRightArrayKokkos::DynamicRaggedRightArrayKokkos () { +DynamicRaggedRightArrayKokkos::DynamicRaggedRightArrayKokkos() { dim1_ = dim2_ = length_ = 0; } // Overloaded constructor template -DynamicRaggedRightArrayKokkos::DynamicRaggedRightArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string) { +DynamicRaggedRightArrayKokkos::DynamicRaggedRightArrayKokkos(size_t dim1, size_t dim2, + const std::string& tag_string) { // The dimensions of the array; - dim1_ = dim1; - dim2_ = dim2; - length_ = dim1*dim2; - + dim1_ = dim1; + dim2_ = dim2; + length_ = dim1 * dim2; + std::string append_stride_string("strides"); std::string append_array_string("array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string strides_tag_string = temp_copy_string.append(append_stride_string); - temp_copy_string = tag_string; + temp_copy_string = tag_string; stride_ = SArray1D(strides_tag_string, dim1_); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StridesInit", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { - strides_(i) = 0; - }); - #else +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StridesInit", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { strides_(i) = 0; }); +#else set_strides_functor execution_functor(0, stride_); - Kokkos::parallel_for("StridesInit", dim1_,execution_functor); - #endif + Kokkos::parallel_for("StridesInit", dim1_, execution_functor); +#endif - //allocate view + // allocate view array_ = TArray1D(tag_string, length_); } // A method to set the stride size for row i template -KOKKOS_INLINE_FUNCTION -size_t& DynamicRaggedRightArrayKokkos::stride(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t& DynamicRaggedRightArrayKokkos::stride(size_t i) const { return stride_(i); } -//return size +// return size template -KOKKOS_INLINE_FUNCTION -size_t DynamicRaggedRightArrayKokkos::size() const{ +KOKKOS_INLINE_FUNCTION size_t DynamicRaggedRightArrayKokkos::size() const { return length_; } // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& DynamicRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DynamicRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { // Asserts - assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedRight"); // die if >= dim1 + assert(i < dim1_ && "i is out of dim1 bounds in DynamicRaggedRight"); // die if >= dim1 assert(j < stride_(i) && "j is out of stride bounds in DynamicRaggedRight"); // die if >= dim2 // Cannot assert on Kokkos View - //assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= stride - - return array_(j + i*dim2_); + // assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= + // stride + + return array_(j + i * dim2_); } -//overload = operator +// overload = operator template -KOKKOS_INLINE_FUNCTION -DynamicRaggedRightArrayKokkos& - DynamicRaggedRightArrayKokkos::operator= (const DynamicRaggedRightArrayKokkos &temp) -{ - - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +KOKKOS_INLINE_FUNCTION DynamicRaggedRightArrayKokkos& +DynamicRaggedRightArrayKokkos::operator=( + const DynamicRaggedRightArrayKokkos& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; /* #ifdef HAVE_CLASS_LAMBDA Kokkos::parallel_for("StrideZeroOut", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { @@ -9822,121 +8566,104 @@ DynamicRaggedRightArrayKokkos& #endif */ } - + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicRaggedRightArrayKokkos::get_kokkos_view() { +KOKKOS_INLINE_FUNCTION Kokkos::View +DynamicRaggedRightArrayKokkos::get_kokkos_view() { return array_; } -//set values to input +// set values to input template -void DynamicRaggedRightArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); +void DynamicRaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } template -void DynamicRaggedRightArrayKokkos::set_values_sparse(T val) { - // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { +void DynamicRaggedRightArrayKokkos::set_values_sparse(T val) { + // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( + // const Kokkos::TeamPolicy<>::member_type &teamMember ) { // const int i_i = teamMember.league_rank(); - // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(i_i) ), [&] ( const int (j_j) ) { - // array_(dim2_*i_i+j_j) = val; + // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(i_i) ), [&] ( const + // int (j_j) ) { + // array_(dim2_*i_i+j_j) = val; // }); // }); - Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); + Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Get the name of the view template -const std::string DynamicRaggedRightArrayKokkos::get_name() const{ +const std::string DynamicRaggedRightArrayKokkos::get_name() const { return array_.label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -DynamicRaggedRightArrayKokkos::~DynamicRaggedRightArrayKokkos() { -} - - - +KOKKOS_INLINE_FUNCTION DynamicRaggedRightArrayKokkos::~DynamicRaggedRightArrayKokkos() {} //----end DynamicRaggedRightArray class definitions---- - -//12. DynamicRaggedDownArray +// 12. DynamicRaggedDownArray template class DynamicRaggedDownArrayKokkos { - using TArray1D = Kokkos::View; - using SArray1D = Kokkos::View; + using SArray1D = Kokkos::View; private: SArray1D stride_; TArray1D array_; - + size_t dim1_; size_t dim2_; size_t length_; - + public: // Default constructor - DynamicRaggedDownArrayKokkos (); - + DynamicRaggedDownArrayKokkos(); + //--- 2D array access of a ragged right array --- - + // overload constructor - DynamicRaggedDownArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - + DynamicRaggedDownArrayKokkos(size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + // A method to return or set the stride size - KOKKOS_INLINE_FUNCTION - size_t& stride(size_t j) const; - + KOKKOS_INLINE_FUNCTION size_t& stride(size_t j) const; + // A method to return the size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view(); + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_view(); // Get the name of the view const std::string get_name() const; - + // Overload operator() to access data as array(i,j), // where i=[stride(j)], j=[0:N-1] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + // Overload copy assignment operator - KOKKOS_INLINE_FUNCTION - DynamicRaggedDownArrayKokkos& operator= (const DynamicRaggedDownArrayKokkos &temp); - - //kokkos policy functors - //set strides to 0 functor - //set strides to a constant value - class set_strides_functor{ - public: - SArray1D functor_strides_; - size_t init_stride_; - set_strides_functor(size_t init_stride, SArray1D temp_strides_){ - init_stride_ = init_stride; - functor_strides_ = temp_strides_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - functor_strides_(index) = init_stride_; - } + KOKKOS_INLINE_FUNCTION DynamicRaggedDownArrayKokkos& operator=(const DynamicRaggedDownArrayKokkos& temp); + + // kokkos policy functors + // set strides to 0 functor + // set strides to a constant value + class set_strides_functor { + public: + SArray1D functor_strides_; + size_t init_stride_; + set_strides_functor(size_t init_stride, SArray1D temp_strides_) { + init_stride_ = init_stride; + functor_strides_ = temp_strides_; + } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { functor_strides_(index) = init_stride_; } }; // set values on host to input @@ -9944,66 +8671,60 @@ class DynamicRaggedDownArrayKokkos { // set values to only previously non-empty indices based upon stride value void set_values_sparse(T val); - + // Destructor - KOKKOS_INLINE_FUNCTION - ~DynamicRaggedDownArrayKokkos (); + KOKKOS_INLINE_FUNCTION ~DynamicRaggedDownArrayKokkos(); }; -//nothing +// nothing template -DynamicRaggedDownArrayKokkos::DynamicRaggedDownArrayKokkos () { +DynamicRaggedDownArrayKokkos::DynamicRaggedDownArrayKokkos() { dim1_ = dim2_ = length_ = 0; } // Overloaded constructor template -DynamicRaggedDownArrayKokkos::DynamicRaggedDownArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string) { +DynamicRaggedDownArrayKokkos::DynamicRaggedDownArrayKokkos(size_t dim1, size_t dim2, + const std::string& tag_string) { // The dimensions of the array; - dim1_ = dim1; - dim2_ = dim2; - length_ = dim1*dim2; + dim1_ = dim1; + dim2_ = dim2; + length_ = dim1 * dim2; std::string append_stride_string("strides"); std::string append_array_string("array"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string strides_tag_string = temp_copy_string.append(append_stride_string); - temp_copy_string = tag_string; - + temp_copy_string = tag_string; stride_ = SArray1D(strides_tag_string, dim2_); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StridesInit", dim2_, KOKKOS_CLASS_LAMBDA(const int i) { - strides_(i) = 0; - }); - #else +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StridesInit", dim2_, KOKKOS_CLASS_LAMBDA(const int i) { strides_(i) = 0; }); +#else set_strides_functor execution_functor(0, stride_); - Kokkos::parallel_for("StridesInit", dim2_,execution_functor); - #endif + Kokkos::parallel_for("StridesInit", dim2_, execution_functor); +#endif - //allocate view + // allocate view array_ = TArray1D(tag_string, length_); } // A method to set the stride size for column j template -KOKKOS_INLINE_FUNCTION -size_t& DynamicRaggedDownArrayKokkos::stride(size_t j) const { +KOKKOS_INLINE_FUNCTION size_t& DynamicRaggedDownArrayKokkos::stride(size_t j) const { return stride_(j); } -//return size +// return size template -KOKKOS_INLINE_FUNCTION -size_t DynamicRaggedDownArrayKokkos::size() const{ +KOKKOS_INLINE_FUNCTION size_t DynamicRaggedDownArrayKokkos::size() const { return length_; } template -KOKKOS_INLINE_FUNCTION -size_t DynamicRaggedDownArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t DynamicRaggedDownArrayKokkos::dims(size_t i) const { assert(i < 2 && "DynamicRaggedDownArrayKokkos dims only supports dims(0) or dims(1)!"); - if(i == 0) return dim1_; + if (i == 0) return dim1_; return dim2_; } @@ -10011,30 +8732,28 @@ size_t DynamicRaggedDownArrayKokkos::dims(size_ // Note: i = 0:stride(j), j = 0:N-1 template -KOKKOS_INLINE_FUNCTION -T& DynamicRaggedDownArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DynamicRaggedDownArrayKokkos::operator()(size_t i, size_t j) const { // Asserts - assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedDownArrayKokkos"); // die if >= dim2 + assert(j < dim2_ && "j is out of dim2 bounds in DynamicRaggedDownArrayKokkos"); // die if >= dim2 assert(i < stride(j) && "i is out of stride bounds in DynamicRaggedDownArrayKokkos"); // die if >= stride(j) // Can't do this assert with a Kokkos View - //assert(i < stride_[j] && "i is out of stride bounds in DynamicRaggedDownArrayKokkos"); // die if >= stride - - return array_(i + j*dim1_); + // assert(i < stride_[j] && "i is out of stride bounds in DynamicRaggedDownArrayKokkos"); // + // die if >= stride + + return array_(i + j * dim1_); } -//overload = operator +// overload = operator template -KOKKOS_INLINE_FUNCTION -DynamicRaggedDownArrayKokkos& - DynamicRaggedDownArrayKokkos::operator= (const DynamicRaggedDownArrayKokkos &temp) -{ - - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; +KOKKOS_INLINE_FUNCTION DynamicRaggedDownArrayKokkos& +DynamicRaggedDownArrayKokkos::operator=( + const DynamicRaggedDownArrayKokkos& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; length_ = temp.length_; stride_ = temp.stride_; - array_ = temp.array_; + array_ = temp.array_; /* #ifdef HAVE_CLASS_LAMBDA Kokkos::parallel_for("StrideZeroOut", dim2_, KOKKOS_CLASS_LAMBDA(const int j) { @@ -10046,87 +8765,79 @@ DynamicRaggedDownArrayKokkos& #endif */ } - + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicRaggedDownArrayKokkos::get_kokkos_view() { +KOKKOS_INLINE_FUNCTION Kokkos::View +DynamicRaggedDownArrayKokkos::get_kokkos_view() { return array_; } -//set values to input +// set values to input template -void DynamicRaggedDownArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); +void DynamicRaggedDownArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } template -void DynamicRaggedDownArrayKokkos::set_values_sparse(T val) { - // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim2_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { +void DynamicRaggedDownArrayKokkos::set_values_sparse(T val) { + // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim2_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( + // const Kokkos::TeamPolicy<>::member_type &teamMember ) { // const int j_j = teamMember.league_rank(); - // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(j_j) ), [&] ( const int (i_i) ) { - // array_(dim1_*j_j+i_i) = val; + // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(j_j) ), [&] ( const + // int (i_i) ) { + // array_(dim1_*j_j+i_i) = val; // }); // }); - Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_(i) = val; - }); + Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Get the name of the view template -const std::string DynamicRaggedDownArrayKokkos::get_name() const{ +const std::string DynamicRaggedDownArrayKokkos::get_name() const { return array_.label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -DynamicRaggedDownArrayKokkos::~DynamicRaggedDownArrayKokkos() { -} +KOKKOS_INLINE_FUNCTION DynamicRaggedDownArrayKokkos::~DynamicRaggedDownArrayKokkos() {} ////// END DynamicRaggedDownArrayKokkos // KokkosCSRArray template class CSRArrayKokkos { - using TArray1D = Kokkos::View; using SArray1D = Kokkos::View; - private: // What ought to be private ? +private: // What ought to be private ? size_t dim1_, dim2_; size_t nnz_; TArray1D array_; SArray1D column_index_; SArray1D start_index_; TArray1D miss_; - public: +public: /** * @brief Construct a new Sparse Row Array Kokkos object * */ CSRArrayKokkos(); - //CSRArray(CArray data, CArray col_ptrs, CArray row_ptrs, size_t rows, size_t cols); - - CSRArrayKokkos( - CArrayKokkos &array, - CArrayKokkos &start_index, - CArrayKokkos &colum_index, - size_t dim1, size_t dim2, const std::string & tag_string = DEFAULTSTRINGARRAY); + // CSRArray(CArray data, CArray col_ptrs, CArray row_ptrs, size_t rows, size_t cols); + CSRArrayKokkos(CArrayKokkos& array, CArrayKokkos& start_index, + CArrayKokkos& colum_index, size_t dim1, size_t dim2, + const std::string& tag_string = DEFAULTSTRINGARRAY); /** * @brief Constructor takes in dense matrix */ - //KOKKOS_INLINE_FUNCTION - CSRArrayKokkos(const CArrayKokkos &dense, const size_t dim1, const size_t dim2); - + // KOKKOS_INLINE_FUNCTION + CSRArrayKokkos(const CArrayKokkos& dense, const size_t dim1, const size_t dim2); + void data_setup(const std::string& tag_string); /** * @brief Access method to A(i,j) returns a dummy value of 0 if value is not allocated @@ -10135,9 +8846,8 @@ class CSRArrayKokkos { * @param j column * @return KOKKOS_INLINE_FUNCTION& */ - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + /** * @brief Same functionality as operator. Included for compatibility with other matar types * @@ -10145,175 +8855,150 @@ class CSRArrayKokkos { * @param j * @return KOKKOS_INLINE_FUNCTION& */ - KOKKOS_INLINE_FUNCTION - T& value(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& value(size_t i, size_t j) const; /** * @brief Copy operator * * @param temp */ - KOKKOS_INLINE_FUNCTION - CSRArrayKokkos& operator=(const CSRArrayKokkos &temp); - - + KOKKOS_INLINE_FUNCTION CSRArrayKokkos& operator=(const CSRArrayKokkos& temp); + /** * @brief Pointer to start of array_ data * */ - KOKKOS_INLINE_FUNCTION - T* pointer() const; - + KOKKOS_INLINE_FUNCTION T* pointer() const; + /** * @brief Get the beginning of the start_index_ array * */ - KOKKOS_INLINE_FUNCTION - size_t* get_starts() const; + KOKKOS_INLINE_FUNCTION size_t* get_starts() const; - /** * @brief Number of columns * * @return KOKKOS_INLINE_FUNCTION */ - KOKKOS_INLINE_FUNCTION - size_t dim2() const ; - + KOKKOS_INLINE_FUNCTION size_t dim2() const; + /** * @brief Number of rows * * @return KOKKOS_INLINE_FUNCTION */ - KOKKOS_INLINE_FUNCTION - size_t dim1() const; - + KOKKOS_INLINE_FUNCTION size_t dim1() const; + /** - * @brief iterator notation to access the non zero elements of row i. Returns pointer to first element in row i + * @brief iterator notation to access the non zero elements of row i. Returns pointer to first + * element in row i * * @param i row * @return KOKKOS_INLINE_FUNCTION* */ - KOKKOS_INLINE_FUNCTION - T* begin(size_t i); - + KOKKOS_INLINE_FUNCTION T* begin(size_t i); + /** - * @brief Iteator notation to access the non zero elements of row i. Returns pointer first element of the next row + * @brief Iteator notation to access the non zero elements of row i. Returns pointer first + * element of the next row * * @param i * @return KOKKOS_INLINE_FUNCTION* */ - KOKKOS_INLINE_FUNCTION - T* end(size_t i); - + KOKKOS_INLINE_FUNCTION T* end(size_t i); + /** * @brief Get the size of row i. Same functionality as nnz(i) but included for compatiblity. * * @param i * @return KOKKOS_INLINE_FUNCTION */ - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; - + KOKKOS_INLINE_FUNCTION size_t stride(size_t i) const; /* * @brief get values from dense array */ - void from_dense(CArrayKokkos &starts, - CArrayKokkos &columns, - CArrayKokkos &array); + void from_dense(CArrayKokkos& starts, CArrayKokkos& columns, + CArrayKokkos& array); /* * iterator for the raw data at row i * i.e. return the index each element is the index in the 1 array * This as the use of providing a reasonable way to get the column * index and data value in the case you need both - */ - KOKKOS_INLINE_FUNCTION - size_t begin_index(size_t i) const; - KOKKOS_INLINE_FUNCTION - size_t end_index(size_t i) const; + */ + KOKKOS_INLINE_FUNCTION size_t begin_index(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t end_index(size_t i) const; /** * @brief get the number of non zero elements in row i */ - KOKKOS_INLINE_FUNCTION - size_t nnz(size_t i) const; - + KOKKOS_INLINE_FUNCTION size_t nnz(size_t i) const; + /** * @brief get the total number of non zero elements */ - KOKKOS_INLINE_FUNCTION - size_t nnz() const ; - - // Use the index into the 1d array to get what value is stored there and what is the corresponding row - KOKKOS_INLINE_FUNCTION - T& get_val_flat(size_t k) const; - KOKKOS_INLINE_FUNCTION - size_t get_col_flat(size_t k) const; + KOKKOS_INLINE_FUNCTION size_t nnz() const; + + // Use the index into the 1d array to get what value is stored there and what is the + // corresponding row + KOKKOS_INLINE_FUNCTION T& get_val_flat(size_t k) const; + KOKKOS_INLINE_FUNCTION size_t get_col_flat(size_t k) const; // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to int flat_index(size_t i, size_t j); // Convertor - + // int toCSC(CArray &data, CArray &col_ptrs, CArray &row_ptrs); - void to_dense(CArrayKokkos& A); + void to_dense(CArrayKokkos& A); // Get the name of the view // KOKKOS_INLINE_FUNCTION // const std::string get_name() const; - - class init_start_indices_functor{ - public: - SArray1D mystart_index_; - init_start_indices_functor(SArray1D tempstart_index_){ - mystart_index_ = tempstart_index_; - } - KOKKOS_INLINE_FUNCTION void operator()(const int index) const { - mystart_index_(index) = 0; - } + + class init_start_indices_functor { + public: + SArray1D mystart_index_; + init_start_indices_functor(SArray1D tempstart_index_) { mystart_index_ = tempstart_index_; } + KOKKOS_INLINE_FUNCTION void operator()(const int index) const { mystart_index_(index) = 0; } }; // set values on host to input void set_values(T val); - //destructor - KOKKOS_INLINE_FUNCTION - ~CSRArrayKokkos(); - - + // destructor + KOKKOS_INLINE_FUNCTION ~CSRArrayKokkos(); }; -template -CSRArrayKokkos::CSRArrayKokkos() { +template +CSRArrayKokkos::CSRArrayKokkos() { dim1_ = dim2_ = nnz_ = 0; } -template -CSRArrayKokkos::CSRArrayKokkos( - CArrayKokkos &array, - CArrayKokkos &start_index, - CArrayKokkos &colum_index, - size_t dim1, size_t dim2, const std::string & tag_string){ - dim1_ = dim1; - dim2_ = dim2; - start_index_ = start_index.get_kokkos_view(); - array_ = array.get_kokkos_view(); +template +CSRArrayKokkos::CSRArrayKokkos(CArrayKokkos& array, + CArrayKokkos& start_index, + CArrayKokkos& colum_index, size_t dim1, + size_t dim2, const std::string& tag_string) { + dim1_ = dim1; + dim2_ = dim2; + start_index_ = start_index.get_kokkos_view(); + array_ = array.get_kokkos_view(); column_index_ = colum_index.get_kokkos_view(); - nnz_ = colum_index.extent(); - miss_ = TArray1D("miss", 1); + nnz_ = colum_index.extent(); + miss_ = TArray1D("miss", 1); } /* template KOKKOS_INLINE_FUNCTION -CSRArrayKokkos::CSRArrayKokkos(const CArrayKokkos &dense, const size_t dim1, const size_t dim2){ - dim1_ = dim1; - dim2_ = dim2; +CSRArrayKokkos::CSRArrayKokkos(const CArrayKokkos &dense, const size_t dim1, const size_t dim2){ dim1_ = dim1; dim2_ = dim2; miss_ = TArray1D("miss",1); start_index_ = Kokkos::View("start indices", dim1 + 1); nnz_ = 0; - + start_index_(0) = 0; // TODO MAKE parallel @@ -10327,11 +9012,11 @@ CSRArrayKokkos::CSRArrayKokkos(const CArrayKok } } - + for(size_t i = 1; i < dim1_ + 1; i++){ start_index_(i) = start_index_[i] + start_index_[i-1]; } - + column_index_ = Kokkos::View("column Indices", nnz_); array_ = Kokkos::View("array elements", nnz_); size_t next = 0 ; @@ -10347,162 +9032,143 @@ CSRArrayKokkos::CSRArrayKokkos(const CArrayKok } */ -//setup start indices +// setup start indices template -void CSRArrayKokkos::data_setup(const std::string& tag_string) { - //allocate start indices +void CSRArrayKokkos::data_setup(const std::string& tag_string) { + // allocate start indices std::string append_indices_string("start_indices"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string start_index_tag_string = temp_copy_string.append(append_indices_string); - temp_copy_string = tag_string; + temp_copy_string = tag_string; start_index_ = SArray1D(start_index_tag_string, dim1_ + 1); - #ifdef HAVE_CLASS_LAMBDA - Kokkos::parallel_for("StartValuesInit", dim1_+1, KOKKOS_CLASS_LAMBDA(const int i) { - start_index_(i) = 0; - }); - #else +#ifdef HAVE_CLASS_LAMBDA + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, KOKKOS_CLASS_LAMBDA(const int i) { start_index_(i) = 0; }); +#else init_start_indices_functor execution_functor(start_index_); - Kokkos::parallel_for("StartValuesInit", dim1_+1,execution_functor); - #endif - + Kokkos::parallel_for("StartValuesInit", dim1_ + 1, execution_functor); +#endif } -template -KOKKOS_INLINE_FUNCTION -T& CSRArrayKokkos::operator()(size_t i, size_t j) const { +template +KOKKOS_INLINE_FUNCTION T& CSRArrayKokkos::operator()(size_t i, size_t j) const { size_t row_start = start_index_[i]; - size_t row_end = start_index_[i+1]; + size_t row_end = start_index_[i + 1]; size_t k; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_[row_start + k] == j){ + for (k = 0; k < row_end - row_start; k++) { + if (column_index_[row_start + k] == j) { return array_.data()[row_start + k]; } } - miss_[0] = (T) NULL; + miss_[0] = (T)NULL; return miss_[0]; } - -template -KOKKOS_INLINE_FUNCTION -T& CSRArrayKokkos::value(size_t i, size_t j) const { +template +KOKKOS_INLINE_FUNCTION T& CSRArrayKokkos::value(size_t i, size_t j) const { size_t row_start = start_index_[i]; - size_t row_end = start_index_[i+1]; + size_t row_end = start_index_[i + 1]; size_t k; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_[row_start + k] == j){ + for (k = 0; k < row_end - row_start; k++) { + if (column_index_[row_start + k] == j) { return array_.data()[row_start + k]; } } - miss_[0] = (T) NULL; + miss_[0] = (T)NULL; return miss_[0]; } -template -KOKKOS_INLINE_FUNCTION -T* CSRArrayKokkos::pointer() const{ +template +KOKKOS_INLINE_FUNCTION T* CSRArrayKokkos::pointer() const { return array_.data(); } -template -KOKKOS_INLINE_FUNCTION -size_t* CSRArrayKokkos::get_starts() const { +template +KOKKOS_INLINE_FUNCTION size_t* CSRArrayKokkos::get_starts() const { return start_index_.data(); } -template -KOKKOS_INLINE_FUNCTION -CSRArrayKokkos& CSRArrayKokkos::operator=(const CSRArrayKokkos &temp){ - if(this != temp) { - nnz_ = temp.nnz_; +template +KOKKOS_INLINE_FUNCTION CSRArrayKokkos& CSRArrayKokkos::operator=( + const CSRArrayKokkos& temp) { + if (this != temp) { + nnz_ = temp.nnz_; dim1_ = temp.dim1_; dim2_ = temp.dim2_; - - start_index_ = temp.start_index_; + + start_index_ = temp.start_index_; column_index_ = temp.column_index_; - array_ = temp.array_; + array_ = temp.array_; } return *this; } -template -void CSRArrayKokkos::to_dense(CArrayKokkos& A){ - size_t i,j; - for(i = 0; i < dim1_; i++){ - for(j = 0; j < dim2_; j++){ - A(i,j) = (*this)(i,j); +template +void CSRArrayKokkos::to_dense(CArrayKokkos& A) { + size_t i, j; + for (i = 0; i < dim1_; i++) { + for (j = 0; j < dim2_; j++) { + A(i, j) = (*this)(i, j); } } } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::stride(size_t i) const { - assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); - return start_index_.data()[i+i] - start_index_.data()[i]; +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::stride(size_t i) const { + assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); + return start_index_.data()[i + i] - start_index_.data()[i]; } - -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::dim2() const { +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::dim2() const { return dim2_; } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::dim1() const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::dim1() const { return dim1_; } -template -KOKKOS_INLINE_FUNCTION -T* CSRArrayKokkos::begin(size_t i){ +template +KOKKOS_INLINE_FUNCTION T* CSRArrayKokkos::begin(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin()"); size_t row_start = start_index_.data()[i]; return &array_.data()[row_start]; } -template -KOKKOS_INLINE_FUNCTION -T* CSRArrayKokkos::end(size_t i){ +template +KOKKOS_INLINE_FUNCTION T* CSRArrayKokkos::end(size_t i) { assert(i <= dim1_ && "i is out of bounds in CSRArray.end()"); - size_t row_start = start_index_.data()[i+1]; + size_t row_start = start_index_.data()[i + 1]; return &array_.data()[row_start]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::begin_index(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::begin_index(size_t i) const { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin_index()"); return start_index_.data()[i]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::end_index(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::end_index(size_t i) const { assert(i <= dim1_ && "i is out of bounds in CSRArray.begin_index()"); - return start_index_.data()[i+1]; + return start_index_.data()[i + 1]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::nnz() const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::nnz() const { return nnz_; } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::nnz(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::nnz(size_t i) const { assert(i <= dim1_ && "Index i out of bounds in CSRArray.stride()"); - return start_index_.data()[i+1] - start_index_.data()[i]; + return start_index_.data()[i + 1] - start_index_.data()[i]; } -template -KOKKOS_INLINE_FUNCTION -T& CSRArrayKokkos::get_val_flat(size_t k) const{ - assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_val_flat()"); - return array_.data()[k]; +template +KOKKOS_INLINE_FUNCTION T& CSRArrayKokkos::get_val_flat(size_t k) const { + assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_val_flat()"); + return array_.data()[k]; } // Get the name of the view @@ -10512,82 +9178,77 @@ T& CSRArrayKokkos::get_val_flat(size_t k) cons // return array_.label(); // } -template -KOKKOS_INLINE_FUNCTION -size_t CSRArrayKokkos::get_col_flat(size_t k) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSRArrayKokkos::get_col_flat(size_t k) const { assert(k < nnz_ && "Index k is out of bounds in CSRArray.get_col_lat()"); return column_index_.data()[k]; } - -template -int CSRArrayKokkos::flat_index(size_t i, size_t j){ +template +int CSRArrayKokkos::flat_index(size_t i, size_t j) { size_t k; size_t row_start = start_index_.data()[i]; - size_t row_end = start_index_.data()[i+1]; - for(k = 0; k < row_end - row_start; k++){ - if(column_index_.data()[row_start+k] == j){ - return row_start+k; + size_t row_end = start_index_.data()[i + 1]; + for (k = 0; k < row_end - row_start; k++) { + if (column_index_.data()[row_start + k] == j) { + return row_start + k; } } - return -1; + return -1; } +// template +// void CSRArrrayKokkos::from_dense(CArrayKokkos &starts, +// CArrayKokkos &columns, +// CArrayKokkos &array); - -//template -//void CSRArrrayKokkos::from_dense(CArrayKokkos &starts, -// CArrayKokkos &columns, -// CArrayKokkos &array); - - /* +/* int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray &row_ptrs ){ - int nnz_cols[ncols_ + 1]; - int col_counts[ncols_]; - int i = 0; - // How many elements are each column - for(i =0 ; i < ncols_; i++){ - nnz_cols[i] = 0; - col_counts[i] = 0; - } - nnz_cols[ncols_] = 0; - col_ptrs(0) = 0; - for(i =0; i < nnz_; i++){ - nnz_cols[column_index_[i] + 1] += 1; - } - // What we actually care about is how many elements are - // in all the columns preceeding this column. - for(i = 1; i <= ncols_; i++){ - nnz_cols[i] = nnz_cols[i-1] + nnz_cols[i]; - col_ptrs(i) = nnz_cols[i]; - } - size_t row = 1; - // if b is at A(i,j) stored in csr format - // it needs to go where the where the ith column starts - // + how many things we have put in the "window" - // we allocated for this column already - // For row we simply keep track of what row we are currently in - // as we scan through the 1d array of data. - for(i = 0; i < nnz_; i++){ - if(i >= start_index_[row]){ - row++; - } - int idx = nnz_cols[column_index_[i]] + col_counts[column_index_[i]]; - col_counts[column_index_[i]] += 1; - data(idx) = array_[i]; - row_ptrs(idx) = row - 1; - } - // I return an int because I thought I might need to return an error code - // Not sure that is true - return 0; +int nnz_cols[ncols_ + 1]; +int col_counts[ncols_]; +int i = 0; +// How many elements are each column +for(i =0 ; i < ncols_; i++){ +nnz_cols[i] = 0; +col_counts[i] = 0; +} +nnz_cols[ncols_] = 0; +col_ptrs(0) = 0; +for(i =0; i < nnz_; i++){ +nnz_cols[column_index_[i] + 1] += 1; +} +// What we actually care about is how many elements are +// in all the columns preceeding this column. +for(i = 1; i <= ncols_; i++){ +nnz_cols[i] = nnz_cols[i-1] + nnz_cols[i]; +col_ptrs(i) = nnz_cols[i]; +} +size_t row = 1; +// if b is at A(i,j) stored in csr format +// it needs to go where the where the ith column starts +// + how many things we have put in the "window" +// we allocated for this column already +// For row we simply keep track of what row we are currently in +// as we scan through the 1d array of data. +for(i = 0; i < nnz_; i++){ +if(i >= start_index_[row]){ +row++; +} +int idx = nnz_cols[column_index_[i]] + col_counts[column_index_[i]]; +col_counts[column_index_[i]] += 1; +data(idx) = array_[i]; +row_ptrs(idx) = row - 1; +} +// I return an int because I thought I might need to return an error code +// Not sure that is true +return 0; } */ template -void CSRArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ - array_[i] = val; - }); +void CSRArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, nnz_), KOKKOS_CLASS_LAMBDA(const int i) { array_[i] = val; }); } template @@ -10595,337 +9256,295 @@ CSRArrayKokkos::~CSRArrayKokkos() {} // 16 CSCArrayKokkos template -class CSCArrayKokkos -{ - +class CSCArrayKokkos { using TArray1D = Kokkos::View; using SArray1D = Kokkos::View; -private: // What ought to be private ? + +private: // What ought to be private ? size_t dim1_, dim2_; size_t nnz_; TArray1D array_; TArray1D miss_; SArray1D start_index_; SArray1D row_index_; - - public: +public: /** - * @brief Construct a new empty Sparse Col Array object - * - */ + * @brief Construct a new empty Sparse Col Array object + * + */ CSCArrayKokkos(); /** - * @brief Construct a new Sparse Col Array object - * - * @param array: 1d array of data values in order as read top to bottom, left to right - * @param row_index: 1d array that marks what row each element is in - * @param start_index: 1d array that marks where the first element of each column starts - * @param dim1: number of rows the matrix should have - * @param dim2: number of columns the matrix should have - */ - CSCArrayKokkos( - CArrayKokkos &array, - CArrayKokkos &start_index, - CArrayKokkos &row_index, - size_t dim1, size_t dim2, const std::string & tag_string = DEFAULTSTRINGARRAY); - + * @brief Construct a new Sparse Col Array object + * + * @param array: 1d array of data values in order as read top to bottom, left to right + * @param row_index: 1d array that marks what row each element is in + * @param start_index: 1d array that marks where the first element of each column starts + * @param dim1: number of rows the matrix should have + * @param dim2: number of columns the matrix should have + */ + CSCArrayKokkos(CArrayKokkos& array, CArrayKokkos& start_index, + CArrayKokkos& row_index, size_t dim1, size_t dim2, + const std::string& tag_string = DEFAULTSTRINGARRAY); /** - * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated - * - * @param i : row - * @param j : column - * @return T& : address of array_ that corresponds to A(i,j) - */ - KOKKOS_INLINE_FUNCTION - T &operator()(size_t i, size_t j) const; + * @brief Access A(i,j). Returns a dummy address with value 0 if A(i,j) is not allocated + * + * @param i : row + * @param j : column + * @return T& : address of array_ that corresponds to A(i,j) + */ + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; /** - * @brief Overloaded copy operator - * - * @param temp : Array to copy - * @return CSCArray& - */ - KOKKOS_INLINE_FUNCTION - CSCArrayKokkos &operator=(const CSCArrayKokkos &temp); + * @brief Overloaded copy operator + * + * @param temp : Array to copy + * @return CSCArray& + */ + KOKKOS_INLINE_FUNCTION CSCArrayKokkos& operator=(const CSCArrayKokkos& temp); /** - * @brief returns pointer to array_ - * - */ - KOKKOS_INLINE_FUNCTION - T *pointer() const; + * @brief returns pointer to array_ + * + */ + KOKKOS_INLINE_FUNCTION T* pointer() const; /** - * @brief Same functionality as nnz(i) included for compatibility with the rest of matar - * - * @param i : row - * @return size_t - */ - KOKKOS_INLINE_FUNCTION - size_t stride(size_t i) const; + * @brief Same functionality as nnz(i) included for compatibility with the rest of matar + * + * @param i : row + * @return size_t + */ + KOKKOS_INLINE_FUNCTION size_t stride(size_t i) const; /** - * @brief Same functionality as operator() included for compatibility with the rest of matar - * - * @param i: row - * @param j: column - * @return T& - */ - KOKKOS_INLINE_FUNCTION - T &value(size_t i, size_t j) const; + * @brief Same functionality as operator() included for compatibility with the rest of matar + * + * @param i: row + * @param j: column + * @return T& + */ + KOKKOS_INLINE_FUNCTION T& value(size_t i, size_t j) const; /** - * @brief Get the start_index array - * - * @return size_t* : returns start_index_ - */ - KOKKOS_INLINE_FUNCTION - size_t *get_starts() const; + * @brief Get the start_index array + * + * @return size_t* : returns start_index_ + */ + KOKKOS_INLINE_FUNCTION size_t* get_starts() const; /** - * @brief Get number of rows - * - * @return size_t number of rows - */ - KOKKOS_INLINE_FUNCTION - size_t dim1() const; + * @brief Get number of rows + * + * @return size_t number of rows + */ + KOKKOS_INLINE_FUNCTION size_t dim1() const; /** - * @brief Get number of columns - * - * @return size_t number of columns - */ - KOKKOS_INLINE_FUNCTION - size_t dim2() const; + * @brief Get number of columns + * + * @return size_t number of columns + */ + KOKKOS_INLINE_FUNCTION size_t dim2() const; /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - KOKKOS_INLINE_FUNCTION - T *begin(size_t i); + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + KOKKOS_INLINE_FUNCTION T* begin(size_t i); /** - * @brief iterator notation for iterating through the non zeros values of row i. - * - * @param i : row - * @return T* - */ - KOKKOS_INLINE_FUNCTION - T *end(size_t i); + * @brief iterator notation for iterating through the non zeros values of row i. + * + * @param i : row + * @return T* + */ + KOKKOS_INLINE_FUNCTION T* end(size_t i); // iterator for the raw data at row i // i.e. return the index each element is the index in the 1 array // This as the use of providing a reasonable way to get the column // index and data value in the case you need both - KOKKOS_INLINE_FUNCTION - size_t begin_index(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t begin_index(size_t i) const; - KOKKOS_INLINE_FUNCTION - size_t end_index(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t end_index(size_t i) const; /** - * @brief Get the number of non zero elements in row i - * - * @param i : row to get - * @return size_t : size of row - */ - KOKKOS_INLINE_FUNCTION - size_t nnz(size_t i) const; + * @brief Get the number of non zero elements in row i + * + * @param i : row to get + * @return size_t : size of row + */ + KOKKOS_INLINE_FUNCTION size_t nnz(size_t i) const; /** - * @brief Get number of non zero elements total in array - * - * @return size_t - */ - KOKKOS_INLINE_FUNCTION - size_t nnz() const; + * @brief Get number of non zero elements total in array + * + * @return size_t + */ + KOKKOS_INLINE_FUNCTION size_t nnz() const; - // Use the index into the 1d array to get what value is stored there and what is the corresponding row - KOKKOS_INLINE_FUNCTION - T &get_val_flat(size_t k); + // Use the index into the 1d array to get what value is stored there and what is the + // corresponding row + KOKKOS_INLINE_FUNCTION T& get_val_flat(size_t k); - KOKKOS_INLINE_FUNCTION - size_t get_row_flat(size_t k); + KOKKOS_INLINE_FUNCTION size_t get_row_flat(size_t k); // reverse map function from A(i,j) to what element of data/col_pt_ it corersponds to - KOKKOS_INLINE_FUNCTION - int flat_index(size_t i, size_t j); + KOKKOS_INLINE_FUNCTION int flat_index(size_t i, size_t j); // Get the name of the view // KOKKOS_INLINE_FUNCTION // const std::string get_name() const; // Convertor - //int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); - //void to_dense(FArray &A); + // int toCSR(CArray &data, CArray &row_ptrs, CArray &col_ptrs); + // void to_dense(FArray &A); // set values on host to input void set_values(T val); // destructor - KOKKOS_INLINE_FUNCTION - ~CSCArrayKokkos(); + KOKKOS_INLINE_FUNCTION ~CSCArrayKokkos(); }; -template +template CSCArrayKokkos::CSCArrayKokkos() { dim1_ = dim2_ = nnz_ = 0; } - -template -CSCArrayKokkos::CSCArrayKokkos( - CArrayKokkos &array, - CArrayKokkos &start_index, - CArrayKokkos &row_index, - size_t dim1, size_t dim2, const std::string & tag_string){ - - dim1_ = dim1; - dim2_ = dim2; +template +CSCArrayKokkos::CSCArrayKokkos(CArrayKokkos& array, + CArrayKokkos& start_index, + CArrayKokkos& row_index, size_t dim1, + size_t dim2, const std::string& tag_string) { + dim1_ = dim1; + dim2_ = dim2; start_index_ = start_index.get_kokkos_view(); - array_ = array.get_kokkos_view(); - + array_ = array.get_kokkos_view(); + row_index_ = row_index.get_kokkos_view(); - nnz_ = row_index.extent(); - miss_ = TArray1D("miss", 1); + nnz_ = row_index.extent(); + miss_ = TArray1D("miss", 1); } - -template -KOKKOS_INLINE_FUNCTION -T& CSCArrayKokkos::operator()(size_t i, size_t j) const { +template +KOKKOS_INLINE_FUNCTION T& CSCArrayKokkos::operator()(size_t i, size_t j) const { // Check if the indices are within bounds assert(i < dim1_ && "i is out of bounds in CSCArray.operator(i,j)"); assert(j < dim2_ && "j is out of bounds in CSCArray.operator(i,j)"); size_t col_start = start_index_.data()[j]; - size_t col_end = start_index_.data()[j + 1]; + size_t col_end = start_index_.data()[j + 1]; size_t k; - for(k = 0; k < col_end - col_start; k++){ - if(row_index_.data()[col_start + k] == i){ + for (k = 0; k < col_end - col_start; k++) { + if (row_index_.data()[col_start + k] == i) { return array_.data()[col_start + k]; } } - miss_[0] = (T) NULL; - return miss_[0]; + miss_[0] = (T)NULL; + return miss_[0]; } -template -KOKKOS_INLINE_FUNCTION -T* CSCArrayKokkos::pointer() const { +template +KOKKOS_INLINE_FUNCTION T* CSCArrayKokkos::pointer() const { return array_.data(); } - -template -KOKKOS_INLINE_FUNCTION -T& CSCArrayKokkos::value(size_t i, size_t j) const { +template +KOKKOS_INLINE_FUNCTION T& CSCArrayKokkos::value(size_t i, size_t j) const { size_t col_start = start_index_.data()[j]; - size_t col_end = start_index_.data()[j + 1]; + size_t col_end = start_index_.data()[j + 1]; size_t k; - for(k =0; k < col_end - col_start;k++){ - if(row_index_.data()[col_start + k] == i){ + for (k = 0; k < col_end - col_start; k++) { + if (row_index_.data()[col_start + k] == i) { return array_.data()[col_start + k]; } } - miss_[0] = (T) NULL; + miss_[0] = (T)NULL; return miss_[0]; } -template -KOKKOS_INLINE_FUNCTION -size_t* CSCArrayKokkos::get_starts() const{ +template +KOKKOS_INLINE_FUNCTION size_t* CSCArrayKokkos::get_starts() const { return &start_index_.data()[0]; } -template -KOKKOS_INLINE_FUNCTION -CSCArrayKokkos& CSCArrayKokkos::operator=(const CSCArrayKokkos &temp){ - if(this != &temp) { - nnz_ = temp.nnz_; +template +KOKKOS_INLINE_FUNCTION CSCArrayKokkos& CSCArrayKokkos::operator=( + const CSCArrayKokkos& temp) { + if (this != &temp) { + nnz_ = temp.nnz_; dim1_ = temp.dim1_; dim2_ = temp.dim2_; miss_ = temp.miss_; - + start_index_ = temp.start_index_; - row_index_ = temp.row_index_; - array_ = temp.array_; + row_index_ = temp.row_index_; + array_ = temp.array_; } return *this; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::stride(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::stride(size_t i) const { assert(i < dim2_ && "i is out of bounds in CSCArray.stride()"); - return start_index_.data()[i+1] - start_index_.data()[i]; + return start_index_.data()[i + 1] - start_index_.data()[i]; } - -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::dim1() const { +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::dim1() const { return dim1_; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::dim2() const{ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::dim2() const { return dim2_; } -template -KOKKOS_INLINE_FUNCTION -T* CSCArrayKokkos::begin(size_t i){ +template +KOKKOS_INLINE_FUNCTION T* CSCArrayKokkos::begin(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.begin()"); size_t col_start = start_index_.data()[i]; return &array_.data()[col_start]; } -template -KOKKOS_INLINE_FUNCTION -T* CSCArrayKokkos::end(size_t i){ +template +KOKKOS_INLINE_FUNCTION T* CSCArrayKokkos::end(size_t i) { assert(i <= dim2_ && "index i out of bounds at CSCArray.endt()"); - size_t col_start = start_index_.data()[i+1]; + size_t col_start = start_index_.data()[i + 1]; return &array_.data()[col_start]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::begin_index(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::begin_index(size_t i) const { assert(i <= dim2_ && "index i out of bounds at CSCArray.begin_index()"); return start_index_.data()[i]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::end_index(size_t i) const{ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::end_index(size_t i) const { assert(i <= dim2_ && "index i out of bounds at CSCArray.end_index()"); return start_index_.data()[i + 1]; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::nnz() const{ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::nnz() const { return nnz_; } -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::nnz(size_t i) const{ - return start_index_.data()[i+1] - start_index_.data()[i]; +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::nnz(size_t i) const { + return start_index_.data()[i + 1] - start_index_.data()[i]; } -template -KOKKOS_INLINE_FUNCTION -T& CSCArrayKokkos::get_val_flat(size_t k){ +template +KOKKOS_INLINE_FUNCTION T& CSCArrayKokkos::get_val_flat(size_t k) { return array_.data()[k]; } @@ -10935,33 +9554,27 @@ T& CSCArrayKokkos::get_val_flat(size_t k){ // return array_.label(); // } - -template -KOKKOS_INLINE_FUNCTION -size_t CSCArrayKokkos::get_row_flat(size_t k){ +template +KOKKOS_INLINE_FUNCTION size_t CSCArrayKokkos::get_row_flat(size_t k) { return row_index_.data()[k]; } -template -KOKKOS_INLINE_FUNCTION -int CSCArrayKokkos::flat_index(size_t i, size_t j){ +template +KOKKOS_INLINE_FUNCTION int CSCArrayKokkos::flat_index(size_t i, size_t j) { size_t col_start = start_index_.data()[j]; - size_t col_end = start_index_.data()[j+1]; + size_t col_end = start_index_.data()[j + 1]; size_t k; - for (k = 0; k < col_end - col_start; k++) - { - if(row_index_.data()[col_start + k] == i){ - return col_start + k; + for (k = 0; k < col_end - col_start; k++) { + if (row_index_.data()[col_start + k] == i) { + return col_start + k; } } - return -1; + return -1; } template -void CSCArrayKokkos::set_values(T val) { - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ - array_(i) = val; - }); +void CSCArrayKokkos::set_values(T val) { + Kokkos::parallel_for(Kokkos::RangePolicy<>(0, nnz_), KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; }); } // Assumes that data, col_ptrs, and row_ptrs @@ -11012,19 +9625,17 @@ int CSCArray::toCSR(CArray &data, CArray &col_ptrs, CArray */ template -CSCArrayKokkos::~CSCArrayKokkos() {} +CSCArrayKokkos::~CSCArrayKokkos() {} // Dual Dynamic Ragged Right Array template class DDynamicRaggedRightArrayKokkos { - - using TArray1D = Kokkos::DualView ; - using Strides1D = Kokkos::DualView; + using TArray1D = Kokkos::DualView; + using Strides1D = Kokkos::DualView; // this is always unmanaged using TArray1DHost = Kokkos::View; typename ExecSpace::memory_space memspace; - - + private: TArray1D array_; typename TArray1D::t_dev array_dev_; @@ -11032,37 +9643,33 @@ class DDynamicRaggedRightArrayKokkos { Strides1D mystrides_; typename Strides1D::t_dev mystrides_dev_; typename Strides1D::t_host mystrides_host_; - - + size_t dim1_; size_t dim2_; size_t length_; - + public: // Default constructor - DDynamicRaggedRightArrayKokkos (); - + DDynamicRaggedRightArrayKokkos(); + //--- 2D array access of a ragged right array --- - + // overload constructor - DDynamicRaggedRightArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DDynamicRaggedRightArrayKokkos(size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - //setup start indices + // setup start indices void data_setup(); - + // A method to return or set the stride size - KOKKOS_INLINE_FUNCTION - size_t& stride(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t& stride(size_t i) const; size_t& stride_host(size_t i) const; - + // A method to return the size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_dual_view(); + // return the view + KOKKOS_INLINE_FUNCTION TArray1D get_kokkos_dual_view(); // Get the name of the view const std::string get_name() const; @@ -11078,24 +9685,20 @@ class DDynamicRaggedRightArrayKokkos { // Method that update device view void update_strides_device(); - + // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[stride(i)] - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; + T& host(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - size_t dim1() const; + KOKKOS_INLINE_FUNCTION size_t dim1() const; + + KOKKOS_INLINE_FUNCTION size_t dim2() const; - KOKKOS_INLINE_FUNCTION - size_t dim2() const; - // Overload copy assignment operator - KOKKOS_INLINE_FUNCTION - DDynamicRaggedRightArrayKokkos& operator= (const DDynamicRaggedRightArrayKokkos& temp); - + KOKKOS_INLINE_FUNCTION DDynamicRaggedRightArrayKokkos& operator=(const DDynamicRaggedRightArrayKokkos& temp); + // set values on host to input void set_values(T val); @@ -11103,130 +9706,119 @@ class DDynamicRaggedRightArrayKokkos { void set_values_sparse(T val); // Destructor - KOKKOS_INLINE_FUNCTION - ~DDynamicRaggedRightArrayKokkos (); + KOKKOS_INLINE_FUNCTION ~DDynamicRaggedRightArrayKokkos(); }; -//nothing +// nothing template -DDynamicRaggedRightArrayKokkos::DDynamicRaggedRightArrayKokkos () { +DDynamicRaggedRightArrayKokkos::DDynamicRaggedRightArrayKokkos() { dim1_ = dim2_ = length_ = 0; } // Overloaded constructor template -DDynamicRaggedRightArrayKokkos::DDynamicRaggedRightArrayKokkos (size_t dim1, size_t dim2, const std::string& tag_string) { +DDynamicRaggedRightArrayKokkos::DDynamicRaggedRightArrayKokkos(size_t dim1, size_t dim2, + const std::string& tag_string) { // The dimensions of the array; - dim1_ = dim1; - dim2_ = dim2; - length_ = dim1*dim2; - + dim1_ = dim1; + dim2_ = dim2; + length_ = dim1 * dim2; + std::string append_stride_string("_strides"); - std::string temp_copy_string = tag_string; + std::string temp_copy_string = tag_string; std::string strides_tag_string = temp_copy_string.append(append_stride_string); - - mystrides_ = Strides1D(strides_tag_string, dim1_); - mystrides_dev_ = mystrides_.view_device(); + mystrides_ = Strides1D(strides_tag_string, dim1_); + mystrides_dev_ = mystrides_.view_device(); mystrides_host_ = mystrides_.view_host(); data_setup(); - //allocate view - array_ = TArray1D(tag_string, length_); + // allocate view + array_ = TArray1D(tag_string, length_); array_host_ = array_.view_host(); - array_dev_ = array_.view_device(); + array_dev_ = array_.view_device(); } -//setup start indices +// setup start indices template -void DDynamicRaggedRightArrayKokkos::data_setup() { +void DDynamicRaggedRightArrayKokkos::data_setup() { + Kokkos::parallel_for("StridesInit", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { mystrides_dev_(i) = 0; }); - Kokkos::parallel_for("StridesInit", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { - mystrides_dev_(i) = 0; - }); - - mystrides_.template modify(); - mystrides_.template sync(); - + mystrides_.template modify(); + mystrides_.template sync(); } // A method to set the stride size for row i template -KOKKOS_INLINE_FUNCTION -size_t& DDynamicRaggedRightArrayKokkos::stride(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t& DDynamicRaggedRightArrayKokkos::stride(size_t i) const { return mystrides_dev_(i); } // A method to set the stride size for row i template -size_t& DDynamicRaggedRightArrayKokkos::stride_host(size_t i) const { +size_t& DDynamicRaggedRightArrayKokkos::stride_host(size_t i) const { return mystrides_host_(i); } -//return size +// return size template -KOKKOS_INLINE_FUNCTION -size_t DDynamicRaggedRightArrayKokkos::size() const{ +KOKKOS_INLINE_FUNCTION size_t DDynamicRaggedRightArrayKokkos::size() const { return length_; } - template -KOKKOS_INLINE_FUNCTION -size_t DDynamicRaggedRightArrayKokkos::dim2() const { +KOKKOS_INLINE_FUNCTION size_t DDynamicRaggedRightArrayKokkos::dim2() const { return dim2_; } template -KOKKOS_INLINE_FUNCTION -size_t DDynamicRaggedRightArrayKokkos::dim1() const{ +KOKKOS_INLINE_FUNCTION size_t DDynamicRaggedRightArrayKokkos::dim1() const { return dim1_; } // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[0:stride(i)] template -KOKKOS_INLINE_FUNCTION -T& DDynamicRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& DDynamicRaggedRightArrayKokkos::operator()(size_t i, size_t j) const { // Asserts - assert(i < dim1_ && "i is out of dim1 bounds in DDynamicRaggedRightKokkos"); // die if >= dim1 + assert(i < dim1_ && "i is out of dim1 bounds in DDynamicRaggedRightKokkos"); // die if >= dim1 assert(j < mystrides_dev_(i) && "j is out of stride bounds in DDynamicRaggedRightKokkos"); // die if >= dim2 // Cannot assert on Kokkos View - //assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= stride - - return array_dev_(j + i*dim2_); + // assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= + // stride + + return array_dev_(j + i * dim2_); } // Overload operator() to access data as array(i,j), // where i=[0:N-1], j=[0:stride(i)] template -T& DDynamicRaggedRightArrayKokkos::host(size_t i, size_t j) const { +T& DDynamicRaggedRightArrayKokkos::host(size_t i, size_t j) const { // Asserts - assert(i < dim1_ && "i is out of dim1 bounds in DDynamicRaggedRightKokkos"); // die if >= dim1 + assert(i < dim1_ && "i is out of dim1 bounds in DDynamicRaggedRightKokkos"); // die if >= dim1 assert(j < mystrides_host_(i) && "j is out of stride bounds in DDynamicRaggedRightKokkos"); // die if >= dim2 // Cannot assert on Kokkos View - //assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= stride - - return array_host_(j + i*dim2_); + // assert(j < stride_[i] && "j is out of stride bounds in DynamicRaggedRight"); // die if >= + // stride + + return array_host_(j + i * dim2_); } -//overload = operator +// overload = operator template -KOKKOS_INLINE_FUNCTION -DDynamicRaggedRightArrayKokkos& - DDynamicRaggedRightArrayKokkos::operator= (const DDynamicRaggedRightArrayKokkos& temp) -{ - - if( this != &temp) { - dim1_ = temp.dim1_; - dim2_ = temp.dim2_; - length_ = temp.length_; - mystrides_ = temp.mystrides_; - mystrides_dev_ = temp.mystrides_dev_; +KOKKOS_INLINE_FUNCTION DDynamicRaggedRightArrayKokkos& +DDynamicRaggedRightArrayKokkos::operator=( + const DDynamicRaggedRightArrayKokkos& temp) { + if (this != &temp) { + dim1_ = temp.dim1_; + dim2_ = temp.dim2_; + length_ = temp.length_; + mystrides_ = temp.mystrides_; + mystrides_dev_ = temp.mystrides_dev_; mystrides_host_ = temp.mystrides_host_; - array_ = temp.array_; - array_dev_ = temp.array_dev_; - array_host_ = temp.array_host_; + array_ = temp.array_; + array_dev_ = temp.array_dev_; + array_host_ = temp.array_host_; /* #ifdef HAVE_CLASS_LAMBDA Kokkos::parallel_for("StrideZeroOut", dim1_, KOKKOS_CLASS_LAMBDA(const int i) { @@ -11238,76 +9830,68 @@ DDynamicRaggedRightArrayKokkos& #endif */ } - + return *this; } -//return the stored Kokkos view +// return the stored Kokkos view template -KOKKOS_INLINE_FUNCTION -Kokkos::DualView DDynamicRaggedRightArrayKokkos::get_kokkos_dual_view() { +KOKKOS_INLINE_FUNCTION Kokkos::DualView +DDynamicRaggedRightArrayKokkos::get_kokkos_dual_view() { return array_; } -//set values to input +// set values to input template -void DDynamicRaggedRightArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_dev_(i) = val; - }); +void DDynamicRaggedRightArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_dev_(i) = val; }); } template -void DDynamicRaggedRightArrayKokkos::update_host() { - +void DDynamicRaggedRightArrayKokkos::update_host() { array_.template modify(); array_.template sync(); } template -void DDynamicRaggedRightArrayKokkos::update_device() { - +void DDynamicRaggedRightArrayKokkos::update_device() { array_.template modify(); array_.template sync(); } template -void DDynamicRaggedRightArrayKokkos::update_strides_host() { - +void DDynamicRaggedRightArrayKokkos::update_strides_host() { mystrides_.template modify(); mystrides_.template sync(); } template -void DDynamicRaggedRightArrayKokkos::update_strides_device() { - +void DDynamicRaggedRightArrayKokkos::update_strides_device() { mystrides_.template modify(); mystrides_.template sync(); } template -void DDynamicRaggedRightArrayKokkos::set_values_sparse(T val) { - // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { +void DDynamicRaggedRightArrayKokkos::set_values_sparse(T val) { + // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( + // const Kokkos::TeamPolicy<>::member_type &teamMember ) { // const int i_i = teamMember.league_rank(); - // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(i_i) ), [&] ( const int (j_j) ) { - // array_(dim2_*i_i+j_j) = val; + // Kokkos::parallel_for( Kokkos::TeamThreadRange( teamMember, 0, stride_(i_i) ), [&] ( const + // int (j_j) ) { + // array_(dim2_*i_i+j_j) = val; // }); // }); - Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - array_dev_(i) = val; - }); + Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_dev_(i) = val; }); } // Get the name of the view template -const std::string DDynamicRaggedRightArrayKokkos::get_name() const{ +const std::string DDynamicRaggedRightArrayKokkos::get_name() const { return array_.view_device().label(); } // Destructor template -KOKKOS_INLINE_FUNCTION -DDynamicRaggedRightArrayKokkos::~DDynamicRaggedRightArrayKokkos() { -} +KOKKOS_INLINE_FUNCTION DDynamicRaggedRightArrayKokkos::~DDynamicRaggedRightArrayKokkos() {} ////////////////////////// // Inherited Class Array @@ -11328,7 +9912,7 @@ class InheritedArray2L { typename Kokkos::View::HostMirror h_this_array_; InheritedArray2L(); - + InheritedArray2L(size_t some_dim1); KOKKOS_INLINE_FUNCTION @@ -11372,7 +9956,7 @@ InheritedArray2L::InheritedArray2L() {} template InheritedArray2L::InheritedArray2L(size_t some_dim1) { using TArray1D = Kokkos::View; - + dim1_ = some_dim1; length_ = dim1_; this_array_ = TArray1D("this_array_", length_); @@ -11423,14 +10007,14 @@ void InheritedArray2L::ClearModels(U obj) { template InheritedArray2L& InheritedArray2L::operator= (const InheritedArray2L& temp) { using TArray1D = Kokkos::View; - + // Do nothing if the assignment is of the form x = x if (this != &temp) { dim1_ = temp.dim1_; length_ = temp.length_; this_array_ = TArray1D("this_array_", length_); } - + return *this; } @@ -11460,11 +10044,8 @@ InheritedArray2L::~InheritedArray2L() {} // End of InheritedArray2L //////////////////////////////////////////////////////////////////////////////// +} // namespace mtr -} // end namespace - -#endif // end if have Kokkos - - -#endif // KOKKOS_TYPES_H +#endif // end if have Kokkos +#endif // KOKKOS_TYPES_H diff --git a/src/include/macros.h b/src/include/macros.h index 4bcabc13..d194e72c 100644 --- a/src/include/macros.h +++ b/src/include/macros.h @@ -1,1577 +1,1580 @@ -#ifndef MACROS_H -#define MACROS_H -/********************************************************************************************** - © 2020. Triad National Security, LLC. All rights reserved. - This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos - National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. - Department of Energy/National Nuclear Security Administration. All rights in the program are - reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear - Security Administration. The Government is granted for itself and others acting on its behalf a - nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare - derivative works, distribute copies to the public, perform publicly and display publicly, and - to permit others to do so. - This program is open source under the BSD-3 License. - Redistribution and use in source and binary forms, with or without modification, are permitted - provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of - conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list of - conditions and the following disclaimer in the documentation and/or other materials - provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its contributors may be used - to endorse or promote products derived from this software without specific prior - written permission. - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - **********************************************************************************************/ - -/********************************************************************************************** - This file has suite of MACROS to build serial and parallel loops that are more readable and - are written with the same syntax. The parallel loops use kokkos (i.e., the MACROS hide the - complexity) and the serial loops are done using functions located in this file. The goal is to - help users add kokkos to their code projects for performance portability across architectures. - - The loop order with the MACRO enforces the inner loop varies the fastest and the outer most - loop varies the slowest. Optiminal performance will be achieved by ensureing the loop indices - align with the access pattern of the MATAR datatype. - - 1. The syntax to use the FOR_ALL MACRO is as follows: - - // parallelization over a single loop - FOR_ALL(k, 0, 10, - { loop contents is here }); - - // parallellization over two loops - FOR_ALL(m, 0, 3, - n, 0, 3, - { loop contents is here }); - - // parallellization over three loops - FOR_ALL(i, 0, 3, - j, 0, 3, - k, 0, 3, - { loop contents is here }); - - // optional kernel name for Kokkos profiling (trailing string literal) - FOR_ALL(i, 0, 10, - j, 0, 10, { - arr_2D(i, j) = j * 10 + i; - }, "FOR_ALL 2D"); - - 2. The syntax to use the FOR_REDUCE is as follows: - - // reduce over a single loop - REDUCE_SUM(i, 0, 100, - local_answer, - { loop contents is here }, answer); - - REDUCE_SUM(i, 0, 100, - j, 0, 100, - local_answer, - { loop contents is here }, answer); - - REDUCE_SUM(i, 0, 100, - j, 0, 100, - k, 0, 100, - local_answer, - { loop contents is here }, answer); - - // optional kernel name for Kokkos profiling (trailing string literal) - FOR_REDUCE_SUM(i, 0, 10, - local_answer, { - local_answer += arr(i) * arr(i); - }, result, "FOR_REDUCE_SUM 1D"); - - // other reduces are: FOR_REDUCE_MAX and FOR_REDUCE_MIN - **********************************************************************************************/ - - -#include -#include - - -// ----------------------------------------- -// MACRO for expanding argvs to make MSVC work -// ----------------------------------------- -#define EXPAND(x) x - - -// ----------------------------------------- -// MACROS used with both Kokkos and non-kokkos versions -// ----------------------------------------- -// a macro to select the name of a macro based on the number of inputs -#define \ - GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, NAME,...) NAME - - - -// ----------------------------------------- -// MACROS for kokkos -// ----------------------------------------- - -#ifdef HAVE_KOKKOS - -// CArray nested loop convention use Right, use Left for outermost loop first -#define LOOP_ORDER Kokkos::Iterate::Right - -// FArray nested loop convention use Right -#define F_LOOP_ORDER Kokkos::Iterate::Right - - -// run once on the device -#define \ - RUN1(fcn) \ - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, 1), \ - KOKKOS_LAMBDA(const int ijkabc){fcn} ) - -#define \ - RUN1_N(fcn, name) \ - Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( 0, 1), \ - KOKKOS_LAMBDA(const int ijkabc){fcn} ) - -#define \ - RUN(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, RUN1_N, RUN1)(__VA_ARGS__)) - -// run once on the device inside a class -#define \ - RUN_CLASS1(fcn) \ - Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, 1), \ - KOKKOS_CLASS_LAMBDA(const int ijkabc){fcn} ) - -#define \ - RUN_CLASS1_N(fcn, name) \ - Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( 0, 1), \ - KOKKOS_CLASS_LAMBDA(const int ijkabc){fcn} ) - -#define \ - RUN_CLASS(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, RUN_CLASS1_N, RUN_CLASS1)(__VA_ARGS__)) - - -// the FOR_ALL loop -#define \ - FOR1D(i, x0, x1,fcn) \ - Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)), \ - KOKKOS_LAMBDA( const int (i) ){fcn} ) - -#define \ - FOR1D_N(i, x0, x1, fcn, name) \ - Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)), \ - KOKKOS_LAMBDA( const int (i) ){fcn} ) - -#define \ - FOR2D(i, x0, x1, j, y0, y1,fcn) \ - Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ - FOR2D_N(i, x0, x1, j, y0, y1, fcn, name) \ - Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ - FOR3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ - Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ - FOR3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ - Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ - FOR_ALL(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, FOR3D_N, FOR3D, _11, FOR2D_N, FOR2D, _10, FOR1D_N, FOR1D)(__VA_ARGS__)) - - -// the DO_ALL loop -#define \ - DO1D(i, x0, x1,fcn) \ - Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)+1), \ - KOKKOS_LAMBDA( const int (i) ){fcn} ) - -#define \ - DO1D_N(i, x0, x1, fcn, name) \ - Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)+1), \ - KOKKOS_LAMBDA( const int (i) ){fcn} ) - -#define \ - DO2D(i, x0, x1, j, y0, y1,fcn) \ - Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER, F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ - DO2D_N(i, x0, x1, j, y0, y1, fcn, name) \ - Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER, F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ - DO3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ - Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ - DO3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ - Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ - DO_ALL(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, DO3D_N, DO3D, _11, DO2D_N, DO2D, _10, DO1D_N, DO1D)(__VA_ARGS__)) - - -// the REDUCE SUM loop -#define \ - RSUM1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ - RSUM1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ - RSUM2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - RSUM2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - RSUM3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - RSUM3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - FOR_REDUCE_SUM(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RSUM3D_N, RSUM3D, _13, RSUM2D_N, RSUM2D, _12, RSUM1D_N, RSUM1D, _11, _10)(__VA_ARGS__)) - - -// the REDUCE Product loop -#define \ - RPROD1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPROD1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPROD2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPROD2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPROD3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPROD3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - FOR_REDUCE_PRODUCT(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RPROD3D_N, RPROD3D, _13, RPROD2D_N, RPROD2D, _12, RPROD1D_N, RPROD1D, _11, _10)(__VA_ARGS__)) - - - - -// the REDUCE Product loop for a class -#define \ - RPRODCLASS1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPRODCLASS1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPRODCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPRODCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPRODCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - RPRODCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Prod< decltype(result) > ( (result) ) ) - -#define \ - FOR_REDUCE_PRODUCT_CLASS(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RPRODCLASS3D_N, RPRODCLASS3D, _13, RPRODCLASS2D_N, RPRODCLASS2D, _12, RPRODCLASS1D_N, RPRODCLASS1D, _11, _10)(__VA_ARGS__)) - - - - - - - - -// the DO_REDUCE_SUM loop -#define \ - DO_RSUM1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ - DO_RSUM1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ - DO_RSUM2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - DO_RSUM2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - DO_RSUM3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - DO_RSUM3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ - DO_REDUCE_SUM(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RSUM3D_N, DO_RSUM3D, _13, DO_RSUM2D_N, DO_RSUM2D, _12, DO_RSUM1D_N, DO_RSUM1D, _11, _10)(__VA_ARGS__)) - - - - -// the REDUCE MAX loop -#define \ - RMAX1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - RMAX1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - RMAX2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - RMAX2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - RMAX3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - RMAX3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - FOR_REDUCE_MAX(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMAX3D_N, RMAX3D, _13, RMAX2D_N, RMAX2D, _12, RMAX1D_N, RMAX1D, _11, _10)(__VA_ARGS__)) - - -// the DO_REDUCE_MAX loop -#define \ - DO_RMAX1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_RMAX1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_RMAX2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_RMAX2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_RMAX3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_RMAX3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - FOR_REDUCE_MAX_SECOND(j, y0, y1, lmax, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::TeamThreadRange( teamMember, y0, y1 ), [&] ( const int (j), decltype(lmax) &(lmax) ) \ - {fcn}, Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_REDUCE_MAX_THIRD(k, z0, z1, lmax, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::ThreadVectorRange( teamMember, z0, z1+1 ), [&] ( const int (k), decltype(lmax) &(lmax) ) \ - {fcn}, Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ - DO_REDUCE_MAX(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RMAX3D_N, DO_RMAX3D, _13, DO_RMAX2D_N, DO_RMAX2D, _12, DO_RMAX1D_N, DO_RMAX1D, _11, _10)(__VA_ARGS__)) - - - -// the REDUCE MIN loop -#define \ - RMIN1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ - RMIN1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ - RMIN2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - RMIN2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - RMIN3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - RMIN3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - FOR_REDUCE_MIN_SECOND(j, y0, y1, lmin, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::TeamThreadRange( teamMember, y0, y1 ), [&] ( const int (j), decltype(lmin) &(lmin) ) \ - {fcn}, Kokkos::Min< decltype(result) > ( (result) ) ) - -#define \ - DO_REDUCE_MIN_THIRD(k, z0, z1, lmin, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::ThreadVectorRange( teamMember, z0, z1+1 ), [&] ( const int (k), decltype(lmin) &(lmin) ) \ - {fcn}, Kokkos::Min< decltype(result) > ( (result) ) ) - -#define \ - FOR_REDUCE_MIN(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMIN3D_N, RMIN3D, _13, RMIN2D_N, RMIN2D, _12, RMIN1D_N, RMIN1D, _11, _10)(__VA_ARGS__)) - - -// the DO_REDUCE MIN loop -#define \ - DO_RMIN1D(i, x0, x1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ - DO_RMIN1D_N(i, x0, x1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ - KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ - DO_RMIN2D(i, x0, x1, j, y0, y1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - DO_RMIN2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ - KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - DO_RMIN3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ - Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - DO_RMIN3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ - Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ - KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ - DO_REDUCE_MIN(...) \ - EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RMIN3D_N, DO_RMIN3D, _13, DO_RMIN2D_N, DO_RMIN2D, _12, DO_RMIN1D_N, DO_RMIN1D, _11, _10)(__VA_ARGS__)) - - - -// the FOR_ALL loop with variables in a class -#define \ -FORCLASS1D(i, x0, x1,fcn) \ -Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)), \ - KOKKOS_CLASS_LAMBDA( const int (i) ){fcn} ) - -#define \ -FORCLASS1D_N(i, x0, x1, fcn, name) \ -Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)), \ - KOKKOS_CLASS_LAMBDA( const int (i) ){fcn} ) - -#define \ -FORCLASS2D(i, x0, x1, j, y0, y1,fcn) \ -Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ -FORCLASS2D_N(i, x0, x1, j, y0, y1, fcn, name) \ -Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j) ){fcn} ) - -#define \ -FORCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ -FORCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ -Kokkos::parallel_for( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) - -#define \ -FOR_ALL_CLASS(...) \ -EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, FORCLASS3D_N, FORCLASS3D, _11, FORCLASS2D_N, FORCLASS2D, _10, FORCLASS1D_N, FORCLASS1D)(__VA_ARGS__)) - - -// the REDUCE SUM loop -#define \ -RSUMCLASS1D(i, x0, x1, var, fcn, result) \ -Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ -RSUMCLASS1D_N(i, x0, x1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) - -#define \ -RSUMCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ -RSUMCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ -RSUMCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ -RSUMCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - (result) ) - -#define \ -FOR_REDUCE_SUM_CLASS(...) \ -EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RSUMCLASS3D_N, RSUMCLASS3D, _13, RSUMCLASS2D_N, RSUMCLASS2D, _12, RSUMCLASS1D_N, RSUMCLASS1D, _11, _10)(__VA_ARGS__)) - - - -// the REDUCE MAX loop with variables in a class - -#define \ -RMAXCLASS1D(i, x0, x1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -RMAXCLASS1D_N(i, x0, x1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -RMAXCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -RMAXCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -RMAXCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -RMAXCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Max< decltype(result) > ( (result) ) ) - -#define \ -FOR_REDUCE_MAX_CLASS(...) \ -EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMAXCLASS3D_N, RMAXCLASS3D, _13, RMAXCLASS2D_N, RMAXCLASS2D, _12, RMAXCLASS1D_N, RMAXCLASS1D, _11, _10)(__VA_ARGS__)) - - -// the REDUCE MIN loop with variables in a class -#define \ -RMINCLASS1D(i, x0, x1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ -RMINCLASS1D_N(i, x0, x1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::RangePolicy<> ( (x0), (x1) ), \ - KOKKOS_CLASS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result)) - -#define \ -RMINCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ -RMINCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ -RMINCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ -RMINCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ -Kokkos::parallel_reduce( name, \ - Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ - KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ - Kokkos::Min< decltype(result) >(result) ) - -#define \ -FOR_REDUCE_MIN_CLASS(...) \ -EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMINCLASS3D_N, RMINCLASS3D, _13, RMINCLASS2D_N, RMINCLASS2D, _12, RMINCLASS1D_N, RMINCLASS1D, _11, _10)(__VA_ARGS__)) - -#define \ -TEAM_ID \ -teamMember.league_rank() - -#define \ -THREAD_ID \ -teamMember.team_rank() - -#define \ -FOR_FIRST(i, x0, x1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::TeamPolicy<>( (x1)-(x0), Kokkos::AUTO, 32 ), \ - KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) \ - { const int (i) = TEAM_ID + (x0); fcn} ) - -#define \ -FOR_SECOND(j, y0, y1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::TeamThreadRange( teamMember,(y0), (y1) ), [&] ( const int (j) ) \ - {fcn} ) - -#define \ -FOR_REDUCE_SUM_SECOND(j, y0, y1, lsum, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::TeamThreadRange( teamMember, (y0), (y1) ), [&] ( const int (j), decltype(lsum) &(lsum) ) \ - {fcn}, (result) ) - -#define \ -FOR_THIRD(k, z0, z1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::ThreadVectorRange( teamMember, (z0), (z1) ), [&] ( const int (k) ) \ - {fcn} ) - -#define \ -FOR_REDUCE_SUM_THIRD(k, z0, z1, lsum, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::ThreadVectorRange( teamMember, (z0), (z1) ), [&] ( const int (k), decltype(lsum) &(lsum) ) \ - {fcn}, (result) ) - -#define \ -DO_FIRST(i, x0, x1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::TeamPolicy<>( (x1)-(x0)+1, Kokkos::AUTO, 32 ), \ - KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) \ - { const int (i) = TEAM_ID + (x0); fcn} ) - -#define \ -DO_SECOND(j, y0, y1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::TeamThreadRange( teamMember, (y0), (y1)+1 ), [&] ( const int (j) ) \ - {fcn} ) - -#define \ -DO_REDUCE_SUM_SECOND(j, y0, y1, lsum, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::TeamThreadRange( teamMember, (y0), (y1)+1 ), [&] ( const int (j), decltype(lsum) &(lsum) ) \ - {fcn}, (result) ) - -#define \ -DO_THIRD(k, z0, z1, fcn) \ -Kokkos::parallel_for( \ - Kokkos::ThreadVectorRange( teamMember, (z0), (z1)+1 ), [&] ( const int (k) ) \ - {fcn} ) - -#define \ -DO_REDUCE_SUM_THIRD(k, z0, z1, lsum, fcn, result) \ -Kokkos::parallel_reduce( \ - Kokkos::ThreadVectorRange( teamMember, (z0), (z1)+1 ), [&] ( const int (k), decltype(lsum) &(lsum) ) \ - {fcn}, (result) ) - -//Kokkos Initialize -#define \ - MATAR_KOKKOS_INIT \ - Kokkos::initialize(argc, argv); - -//Kokkos Finalize -#define \ - MATAR_KOKKOS_FINALIZE \ - Kokkos::finalize(); - -#endif - - -// end of KOKKOS routines - - - - -// ----------------------------------------- -// The for_all is used for serial loops and -// with the non-kokkos MACROS -// ----------------------------------------- - -template -void for_all (int i_start, int i_end, - const F &lambda_fcn){ - - for (int i=i_start; i -void for_all (int i_start, int i_end, - int j_start, int j_end, - const F &lambda_fcn){ - - for (int i=i_start; i -void for_all (int i_start, int i_end, - int j_start, int j_end, - int k_start, int k_end, - const F &lambda_fcn){ - - for (int i=i_start; i -void for_all_delta (int i_start, int i_end, int i_delta, - const F &lambda_fcn){ - - for (int i=i_start; i -void for_all_delta (int i_start, int i_end, int i_delta, - int j_start, int j_end, int j_delta, - const F &lambda_fcn){ - - for (int i=i_start; i -void for_all_delta (int i_start, int i_end, int i_delta, - int j_start, int j_end, int j_delta, - int k_start, int k_end, int k_delta, - const F &lambda_fcn){ - - for (int i=i_start; i // for the max and min values of a int, double, etc. - -// SUM -template -void reduce_sum (int i_start, int i_end, - T var, - const F &lambda_fcn, T &result){ - var = 0; - for (int i=i_start; i -void reduce_sum (int i_start, int i_end, - int j_start, int j_end, - T var, - const F &lambda_fcn, T &result){ - var = 0; - for (int i=i_start; i -void reduce_sum (int i_start, int i_end, - int j_start, int j_end, - int k_start, int k_end, - T var, - const F &lambda_fcn, T &result){ - var = 0; - for (int i=i_start; i -void reduce_min (int i_start, int i_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::max(); //2147483647; - for (int i=i_start; i -void reduce_min (int i_start, int i_end, - int j_start, int j_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::max(); //2147483647; - for (int i=i_start; i -void reduce_min (int i_start, int i_end, - int j_start, int j_end, - int k_start, int k_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::max(); //2147483647; - for (int i=i_start; i -void reduce_max (int i_start, int i_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::min(); // -2147483647 - 1; - for (int i=i_start; i -void reduce_max (int i_start, int i_end, - int j_start, int j_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::min(); //-2147483647 - 1; - for (int i=i_start; i -void reduce_max (int i_start, int i_end, - int j_start, int j_end, - int k_start, int k_end, - T var, - const F &lambda_fcn, T &result){ - var = std::numeric_limits::min(); // -2147483647 - 1; - for (int i=i_start; i -void reduce_prod (int i_start, int i_end, - T var, - const F &lambda_fcn, T &result){ - var = 1.0; - for (int i=i_start; i -void reduce_prod (int i_start, int i_end, - int j_start, int j_end, - T var, - const F &lambda_fcn, T &result){ - var = 1.0; - for (int i=i_start; i -void reduce_prod (int i_start, int i_end, - int j_start, int j_end, - int k_start, int k_end, - T var, - const F &lambda_fcn, T &result){ - var = 1.0; - for (int i=i_start; i +#include + + +// ----------------------------------------- +// MACRO for expanding argvs to make MSVC work +// ----------------------------------------- +#define EXPAND(x) x + + +// ----------------------------------------- +// MACROS used with both Kokkos and non-kokkos versions +// ----------------------------------------- +// a macro to select the name of a macro based on the number of inputs +#define \ + GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, NAME,...) NAME + + + +// ----------------------------------------- +// MACROS for kokkos +// ----------------------------------------- + +#ifdef HAVE_KOKKOS + +// CArray nested loop convention use Right, use Left for outermost loop first +#define LOOP_ORDER Kokkos::Iterate::Right + +// FArray nested loop convention use Right +#define F_LOOP_ORDER Kokkos::Iterate::Right + + +// run once on the device +#define \ + RUN1(fcn) \ + Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, 1), \ + KOKKOS_LAMBDA(const int ijkabc){fcn} ) + +#define \ + RUN1_N(fcn, name) \ + Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( 0, 1), \ + KOKKOS_LAMBDA(const int ijkabc){fcn} ) + +#define \ + RUN(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, RUN1_N, RUN1)(__VA_ARGS__)) + +// run once on the device inside a class +#define \ + RUN_CLASS1(fcn) \ + Kokkos::parallel_for( Kokkos::RangePolicy<> ( 0, 1), \ + KOKKOS_CLASS_LAMBDA(const int ijkabc){fcn} ) + +#define \ + RUN_CLASS1_N(fcn, name) \ + Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( 0, 1), \ + KOKKOS_CLASS_LAMBDA(const int ijkabc){fcn} ) + +#define \ + RUN_CLASS(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, RUN_CLASS1_N, RUN_CLASS1)(__VA_ARGS__)) + + +// the FOR_ALL loop +#define \ + FOR1D(i, x0, x1,fcn) \ + Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)), \ + KOKKOS_LAMBDA( const int (i) ){fcn} ) + +#define \ + FOR1D_N(i, x0, x1, fcn, name) \ + Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)), \ + KOKKOS_LAMBDA( const int (i) ){fcn} ) + +#define \ + FOR2D(i, x0, x1, j, y0, y1,fcn) \ + Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ + FOR2D_N(i, x0, x1, j, y0, y1, fcn, name) \ + Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ + FOR3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ + Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ + FOR3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ + Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ + FOR_ALL(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, FOR3D_N, FOR3D, _11, FOR2D_N, FOR2D, _10, FOR1D_N, FOR1D)(__VA_ARGS__)) + + +// the DO_ALL loop +#define \ + DO1D(i, x0, x1,fcn) \ + Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)+1), \ + KOKKOS_LAMBDA( const int (i) ){fcn} ) + +#define \ + DO1D_N(i, x0, x1, fcn, name) \ + Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)+1), \ + KOKKOS_LAMBDA( const int (i) ){fcn} ) + +#define \ + DO2D(i, x0, x1, j, y0, y1,fcn) \ + Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER, F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ + DO2D_N(i, x0, x1, j, y0, y1, fcn, name) \ + Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER, F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ + DO3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ + Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ + DO3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ + Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ + DO_ALL(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, DO3D_N, DO3D, _11, DO2D_N, DO2D, _10, DO1D_N, DO1D)(__VA_ARGS__)) + + +// the REDUCE SUM loop +#define \ + RSUM1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ + RSUM1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ + RSUM2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + RSUM2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + RSUM3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + RSUM3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + FOR_REDUCE_SUM(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RSUM3D_N, RSUM3D, _13, RSUM2D_N, RSUM2D, _12, RSUM1D_N, RSUM1D, _11, _10)(__VA_ARGS__)) + + +// the REDUCE Product loop +#define \ + RPROD1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPROD1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPROD2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPROD2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPROD3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPROD3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + FOR_REDUCE_PRODUCT(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RPROD3D_N, RPROD3D, _13, RPROD2D_N, RPROD2D, _12, RPROD1D_N, RPROD1D, _11, _10)(__VA_ARGS__)) + + + + +// the REDUCE Product loop for a class +#define \ + RPRODCLASS1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPRODCLASS1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPRODCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPRODCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPRODCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + RPRODCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Prod< decltype(result) > ( (result) ) ) + +#define \ + FOR_REDUCE_PRODUCT_CLASS(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RPRODCLASS3D_N, RPRODCLASS3D, _13, RPRODCLASS2D_N, RPRODCLASS2D, _12, RPRODCLASS1D_N, RPRODCLASS1D, _11, _10)(__VA_ARGS__)) + + + + + + + + +// the DO_REDUCE_SUM loop +#define \ + DO_RSUM1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ + DO_RSUM1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ + DO_RSUM2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + DO_RSUM2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + DO_RSUM3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + DO_RSUM3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ + DO_REDUCE_SUM(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RSUM3D_N, DO_RSUM3D, _13, DO_RSUM2D_N, DO_RSUM2D, _12, DO_RSUM1D_N, DO_RSUM1D, _11, _10)(__VA_ARGS__)) + + + + +// the REDUCE MAX loop +#define \ + RMAX1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + RMAX1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + RMAX2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + RMAX2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + RMAX3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + RMAX3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + FOR_REDUCE_MAX(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMAX3D_N, RMAX3D, _13, RMAX2D_N, RMAX2D, _12, RMAX1D_N, RMAX1D, _11, _10)(__VA_ARGS__)) + + +// the DO_REDUCE_MAX loop +#define \ + DO_RMAX1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_RMAX1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_RMAX2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_RMAX2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_RMAX3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_RMAX3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + FOR_REDUCE_MAX_SECOND(j, y0, y1, lmax, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::TeamThreadRange( teamMember, y0, y1 ), [&] ( const int (j), decltype(lmax) &(lmax) ) \ + {fcn}, Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_REDUCE_MAX_THIRD(k, z0, z1, lmax, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::ThreadVectorRange( teamMember, z0, z1+1 ), [&] ( const int (k), decltype(lmax) &(lmax) ) \ + {fcn}, Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ + DO_REDUCE_MAX(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RMAX3D_N, DO_RMAX3D, _13, DO_RMAX2D_N, DO_RMAX2D, _12, DO_RMAX1D_N, DO_RMAX1D, _11, _10)(__VA_ARGS__)) + + + +// the REDUCE MIN loop +#define \ + RMIN1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ + RMIN1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ + RMIN2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + RMIN2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + RMIN3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + RMIN3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + FOR_REDUCE_MIN_SECOND(j, y0, y1, lmin, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::TeamThreadRange( teamMember, y0, y1 ), [&] ( const int (j), decltype(lmin) &(lmin) ) \ + {fcn}, Kokkos::Min< decltype(result) > ( (result) ) ) + +#define \ + DO_REDUCE_MIN_THIRD(k, z0, z1, lmin, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::ThreadVectorRange( teamMember, z0, z1+1 ), [&] ( const int (k), decltype(lmin) &(lmin) ) \ + {fcn}, Kokkos::Min< decltype(result) > ( (result) ) ) + +#define \ + FOR_REDUCE_MIN(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMIN3D_N, RMIN3D, _13, RMIN2D_N, RMIN2D, _12, RMIN1D_N, RMIN1D, _11, _10)(__VA_ARGS__)) + + +// the DO_REDUCE MIN loop +#define \ + DO_RMIN1D(i, x0, x1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ + DO_RMIN1D_N(i, x0, x1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1)+1 ), \ + KOKKOS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ + DO_RMIN2D(i, x0, x1, j, y0, y1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + DO_RMIN2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0)}, {(x1)+1, (y1)+1} ), \ + KOKKOS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + DO_RMIN3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ + Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + DO_RMIN3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ + Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,F_LOOP_ORDER,F_LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1)+1, (y1)+1, (z1)+1} ), \ + KOKKOS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ + DO_REDUCE_MIN(...) \ + EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, DO_RMIN3D_N, DO_RMIN3D, _13, DO_RMIN2D_N, DO_RMIN2D, _12, DO_RMIN1D_N, DO_RMIN1D, _11, _10)(__VA_ARGS__)) + + + +// the FOR_ALL loop with variables in a class +#define \ +FORCLASS1D(i, x0, x1,fcn) \ +Kokkos::parallel_for( Kokkos::RangePolicy<> ( (x0), (x1)), \ + KOKKOS_CLASS_LAMBDA( const int (i) ){fcn} ) + +#define \ +FORCLASS1D_N(i, x0, x1, fcn, name) \ +Kokkos::parallel_for( name, Kokkos::RangePolicy<> ( (x0), (x1)), \ + KOKKOS_CLASS_LAMBDA( const int (i) ){fcn} ) + +#define \ +FORCLASS2D(i, x0, x1, j, y0, y1,fcn) \ +Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ +FORCLASS2D_N(i, x0, x1, j, y0, y1, fcn, name) \ +Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j) ){fcn} ) + +#define \ +FORCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ +FORCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, fcn, name) \ +Kokkos::parallel_for( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k) ) {fcn} ) + +#define \ +FOR_ALL_CLASS(...) \ +EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, _13, _12, FORCLASS3D_N, FORCLASS3D, _11, FORCLASS2D_N, FORCLASS2D, _10, FORCLASS1D_N, FORCLASS1D)(__VA_ARGS__)) + + +// the REDUCE SUM loop +#define \ +RSUMCLASS1D(i, x0, x1, var, fcn, result) \ +Kokkos::parallel_reduce( Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ +RSUMCLASS1D_N(i, x0, x1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, (result)) + +#define \ +RSUMCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ +RSUMCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ +RSUMCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ +RSUMCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + (result) ) + +#define \ +FOR_REDUCE_SUM_CLASS(...) \ +EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RSUMCLASS3D_N, RSUMCLASS3D, _13, RSUMCLASS2D_N, RSUMCLASS2D, _12, RSUMCLASS1D_N, RSUMCLASS1D, _11, _10)(__VA_ARGS__)) + + + +// the REDUCE MAX loop with variables in a class + +#define \ +RMAXCLASS1D(i, x0, x1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +RMAXCLASS1D_N(i, x0, x1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA(const int (i), decltype(var) &(var)){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +RMAXCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +RMAXCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +RMAXCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +RMAXCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Max< decltype(result) > ( (result) ) ) + +#define \ +FOR_REDUCE_MAX_CLASS(...) \ +EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMAXCLASS3D_N, RMAXCLASS3D, _13, RMAXCLASS2D_N, RMAXCLASS2D, _12, RMAXCLASS1D_N, RMAXCLASS1D, _11, _10)(__VA_ARGS__)) + + +// the REDUCE MIN loop with variables in a class +#define \ +RMINCLASS1D(i, x0, x1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ +RMINCLASS1D_N(i, x0, x1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::RangePolicy<> ( (x0), (x1) ), \ + KOKKOS_CLASS_LAMBDA( const int (i), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result)) + +#define \ +RMINCLASS2D(i, x0, x1, j, y0, y1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ +RMINCLASS2D_N(i, x0, x1, j, y0, y1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<2,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0)}, {(x1), (y1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i),const int (j), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ +RMINCLASS3D(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ +RMINCLASS3D_N(i, x0, x1, j, y0, y1, k, z0, z1, var, fcn, result, name) \ +Kokkos::parallel_reduce( name, \ + Kokkos::MDRangePolicy< Kokkos::Rank<3,LOOP_ORDER,LOOP_ORDER> > ( {(x0), (y0), (z0)}, {(x1), (y1), (z1)} ), \ + KOKKOS_CLASS_LAMBDA( const int (i), const int (j), const int (k), decltype(var) &(var) ){fcn}, \ + Kokkos::Min< decltype(result) >(result) ) + +#define \ +FOR_REDUCE_MIN_CLASS(...) \ +EXPAND(GET_MACRO(__VA_ARGS__, _16, _15, _14, RMINCLASS3D_N, RMINCLASS3D, _13, RMINCLASS2D_N, RMINCLASS2D, _12, RMINCLASS1D_N, RMINCLASS1D, _11, _10)(__VA_ARGS__)) + +#define \ +TEAM_ID \ +teamMember.league_rank() + +#define \ +THREAD_ID \ +teamMember.team_rank() + +#define \ +FOR_FIRST(i, x0, x1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::TeamPolicy<>( (x1)-(x0), Kokkos::AUTO, 32 ), \ + KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) \ + { const int (i) = TEAM_ID + (x0); fcn} ) + +#define \ +FOR_SECOND(j, y0, y1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::TeamThreadRange( teamMember,(y0), (y1) ), [&] ( const int (j) ) \ + {fcn} ) + +#define \ +FOR_REDUCE_SUM_SECOND(j, y0, y1, lsum, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::TeamThreadRange( teamMember, (y0), (y1) ), [&] ( const int (j), decltype(lsum) &(lsum) ) \ + {fcn}, (result) ) + +#define \ +FOR_THIRD(k, z0, z1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::ThreadVectorRange( teamMember, (z0), (z1) ), [&] ( const int (k) ) \ + {fcn} ) + +#define \ +FOR_REDUCE_SUM_THIRD(k, z0, z1, lsum, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::ThreadVectorRange( teamMember, (z0), (z1) ), [&] ( const int (k), decltype(lsum) &(lsum) ) \ + {fcn}, (result) ) + +#define \ +DO_FIRST(i, x0, x1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::TeamPolicy<>( (x1)-(x0)+1, Kokkos::AUTO, 32 ), \ + KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) \ + { const int (i) = TEAM_ID + (x0); fcn} ) + +#define \ +DO_SECOND(j, y0, y1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::TeamThreadRange( teamMember, (y0), (y1)+1 ), [&] ( const int (j) ) \ + {fcn} ) + +#define \ +DO_REDUCE_SUM_SECOND(j, y0, y1, lsum, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::TeamThreadRange( teamMember, (y0), (y1)+1 ), [&] ( const int (j), decltype(lsum) &(lsum) ) \ + {fcn}, (result) ) + +#define \ +DO_THIRD(k, z0, z1, fcn) \ +Kokkos::parallel_for( \ + Kokkos::ThreadVectorRange( teamMember, (z0), (z1)+1 ), [&] ( const int (k) ) \ + {fcn} ) + +#define \ +DO_REDUCE_SUM_THIRD(k, z0, z1, lsum, fcn, result) \ +Kokkos::parallel_reduce( \ + Kokkos::ThreadVectorRange( teamMember, (z0), (z1)+1 ), [&] ( const int (k), decltype(lsum) &(lsum) ) \ + {fcn}, (result) ) + +//Kokkos Initialize +#define \ + MATAR_KOKKOS_INIT \ + Kokkos::initialize(argc, argv); + +//Kokkos Finalize +#define \ + MATAR_KOKKOS_FINALIZE \ + Kokkos::finalize(); + +#endif + + +// end of KOKKOS routines + + + + +// ----------------------------------------- +// The for_all is used for serial loops and +// with the non-kokkos MACROS +// ----------------------------------------- + +template +void for_all (int i_start, int i_end, + const F &lambda_fcn){ + + for (int i=i_start; i +void for_all (int i_start, int i_end, + int j_start, int j_end, + const F &lambda_fcn){ + + for (int i=i_start; i +void for_all (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + const F &lambda_fcn){ + + for (int i=i_start; i +void for_all_delta (int i_start, int i_end, int i_delta, + const F &lambda_fcn){ + + for (int i=i_start; i +void for_all_delta (int i_start, int i_end, int i_delta, + int j_start, int j_end, int j_delta, + const F &lambda_fcn){ + + for (int i=i_start; i +void for_all_delta (int i_start, int i_end, int i_delta, + int j_start, int j_end, int j_delta, + int k_start, int k_end, int k_delta, + const F &lambda_fcn){ + + for (int i=i_start; i // for the max and min values of a int, double, etc. + +// SUM +template +void reduce_sum (int i_start, int i_end, + T var, + const F &lambda_fcn, T &result){ + var = 0; + for (int i=i_start; i +void reduce_sum (int i_start, int i_end, + int j_start, int j_end, + T var, + const F &lambda_fcn, T &result){ + var = 0; + for (int i=i_start; i +void reduce_sum (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + T var, + const F &lambda_fcn, T &result){ + var = 0; + for (int i=i_start; i +void reduce_min (int i_start, int i_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::max(); //2147483647; + for (int i=i_start; i +void reduce_min (int i_start, int i_end, + int j_start, int j_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::max(); //2147483647; + for (int i=i_start; i +void reduce_min (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::max(); //2147483647; + for (int i=i_start; i +void reduce_max (int i_start, int i_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::min(); // -2147483647 - 1; + for (int i=i_start; i +void reduce_max (int i_start, int i_end, + int j_start, int j_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::min(); //-2147483647 - 1; + for (int i=i_start; i +void reduce_max (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + T var, + const F &lambda_fcn, T &result){ + var = std::numeric_limits::min(); // -2147483647 - 1; + for (int i=i_start; i +void reduce_prod (int i_start, int i_end, + T var, + const F &lambda_fcn, T &result){ + var = 1.0; + for (int i=i_start; i +void reduce_prod (int i_start, int i_end, + int j_start, int j_end, + T var, + const F &lambda_fcn, T &result){ + var = 1.0; + for (int i=i_start; i +void reduce_prod (int i_start, int i_end, + int j_start, int j_end, + int k_start, int k_end, + T var, + const F &lambda_fcn, T &result){ + var = 1.0; + for (int i=i_start; i -#include "matar.h" + #include "communication_plan.h" +#include "matar.h" -namespace mtr -{ +namespace mtr { // Type trait to map C++ types to MPI_Datatype template @@ -69,30 +69,27 @@ struct mpi_type_map { static MPI_Datatype value() { return MPI_C_BOOL; } }; - template struct MPICArrayCommBuffers { - DCArrayKokkos send_buffer_; DCArrayKokkos recv_buffer_; - - DCArrayKokkos send_counts_; // [size: num_send_ranks] Number of items to send to each rank - DCArrayKokkos recv_counts_; // [size: num_recv_ranks] Number of items to receive from each rank - DCArrayKokkos send_displs_; // [size: num_send_ranks] Starting index of items to send to each rank - DCArrayKokkos recv_displs_; // [size: num_recv_ranks] Starting index of items to receive from each rank - - DRaggedRightArrayKokkos send_indices_; // [size: num_send_ranks, num_items_to_send_by_rank] Indices of items to send to each rank - DRaggedRightArrayKokkos recv_indices_; // [size: num_recv_ranks, num_items_to_recv_by_rank] Indices of items to receive from each rank -}; + DCArrayKokkos send_counts_; // [size: num_send_ranks] Number of items to send to each rank + DCArrayKokkos recv_counts_; // [size: num_recv_ranks] Number of items to receive from each rank + DCArrayKokkos send_displs_; // [size: num_send_ranks] Starting index of items to send to each rank + DCArrayKokkos recv_displs_; // [size: num_recv_ranks] Starting index of items to receive from each rank + DRaggedRightArrayKokkos send_indices_; // [size: num_send_ranks, num_items_to_send_by_rank] Indices of items to + // send to each rank + DRaggedRightArrayKokkos recv_indices_; // [size: num_recv_ranks, num_items_to_recv_by_rank] Indices of items to + // receive from each rank +}; ///////////////////////// // MPICArrayKokkos: Type for managing distributed data on both CPU and GPU. ///////////////////////// template class MPICArrayKokkos { - // Dual view for managing data on both CPU and GPU DCArrayKokkos this_array_; @@ -107,24 +104,22 @@ class MPICArrayKokkos { // DCArrayKokkos send_buffer_; // DCArrayKokkos recv_buffer_; - + protected: - size_t dims_[7] = {0,0,0,0,0,0,0}; - size_t length_ = 0; - size_t order_ = 0; // tensor order (rank) - size_t stride_ = 1; // [size: num_dims] Number of contiguous values per first index element + size_t dims_[7] = {0, 0, 0, 0, 0, 0, 0}; + size_t length_ = 0; + size_t order_ = 0; // tensor order (rank) + size_t stride_ = 1; // [size: num_dims] Number of contiguous values per first index element - size_t num_owned_ = 0; // Number of owned items (nodes/elements); optional override - size_t num_ghost_ = 0; // Number of ghost items (nodes/elements); informational when user-set + size_t num_owned_ = 0; // Number of owned items (nodes/elements); optional override + size_t num_ghost_ = 0; // Number of ghost items (nodes/elements); informational when user-set public: - // --- Ghost Communication Support --- - CommunicationPlan* comm_plan_ = NULL; // Pointer to shared communication plan + CommunicationPlan* comm_plan_ = NULL; // Pointer to shared communication plan // Data member to access host view (initialized as pointer to this_array_.host_pointer()) - ViewCArray host; - + ViewCArray host; // Note, consider this for sending blocks without dealing with stride_ // MPI_Datatype vector_type; @@ -132,64 +127,49 @@ class MPICArrayKokkos { // MPI_Type_commit(&vector_type); MPICArrayKokkos(); - + MPICArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); MPICArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + + MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, + const std::string& tag_string = DEFAULTSTRINGARRAY); - MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const; - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - MPICArrayKokkos& operator=(const MPICArrayKokkos& temp); + KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; + KOKKOS_INLINE_FUNCTION MPICArrayKokkos& operator=(const MPICArrayKokkos& temp); // Method to set comm plan for halo communication - void initialize_comm_plan(CommunicationPlan& comm_plan){ + void initialize_comm_plan(CommunicationPlan& comm_plan) { comm_plan_ = &comm_plan; - if(comm_plan_->comm_type == communication_plan_type::no_communication){ + if (comm_plan_->comm_type == communication_plan_type::no_communication) { return; } - + size_t send_size = comm_plan_->total_send_count * stride_; size_t recv_size = comm_plan_->total_recv_count * stride_; - + if (send_size > 0) { mpi_buffers_.send_buffer_ = DCArrayKokkos(send_size, "send_buffer"); } @@ -200,20 +180,20 @@ class MPICArrayKokkos { if (comm_plan_->num_send_ranks > 0) { mpi_buffers_.send_counts_ = DCArrayKokkos(comm_plan_->num_send_ranks, "send_counts"); mpi_buffers_.send_displs_ = DCArrayKokkos(comm_plan_->num_send_ranks, "send_displs"); - - for(int i = 0; i < comm_plan_->num_send_ranks; i++){ + + for (int i = 0; i < comm_plan_->num_send_ranks; i++) { mpi_buffers_.send_counts_.host(i) = comm_plan_->send_counts_.host(i) * stride_; mpi_buffers_.send_displs_.host(i) = comm_plan_->send_displs_.host(i) * stride_; } mpi_buffers_.send_counts_.update_device(); mpi_buffers_.send_displs_.update_device(); } - + if (comm_plan_->num_recv_ranks > 0) { mpi_buffers_.recv_counts_ = DCArrayKokkos(comm_plan_->num_recv_ranks, "recv_counts"); mpi_buffers_.recv_displs_ = DCArrayKokkos(comm_plan_->num_recv_ranks, "recv_displs"); - - for(int i = 0; i < comm_plan_->num_recv_ranks; i++){ + + for (int i = 0; i < comm_plan_->num_recv_ranks; i++) { mpi_buffers_.recv_counts_.host(i) = comm_plan_->recv_counts_.host(i) * stride_; mpi_buffers_.recv_displs_.host(i) = comm_plan_->recv_displs_.host(i) * stride_; } @@ -222,34 +202,26 @@ class MPICArrayKokkos { } }; - // GPU Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; + KOKKOS_INLINE_FUNCTION size_t size() const; // Host Method // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; + KOKKOS_INLINE_FUNCTION size_t extent() const; + + KOKKOS_INLINE_FUNCTION size_t dims(size_t i) const; - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; + KOKKOS_INLINE_FUNCTION size_t order() const; - KOKKOS_INLINE_FUNCTION - size_t order() const; - // Method returns the raw device pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* device_pointer() const; + KOKKOS_INLINE_FUNCTION T* device_pointer() const; // Method returns the raw host pointer of the Kokkos DualView - KOKKOS_INLINE_FUNCTION - T* host_pointer() const; + KOKKOS_INLINE_FUNCTION T* host_pointer() const; // Method returns kokkos dual view - KOKKOS_INLINE_FUNCTION - Kokkos::DualView get_kokkos_dual_view() const; + KOKKOS_INLINE_FUNCTION Kokkos::DualView get_kokkos_dual_view() const; // Method that update host view void update_host(); @@ -259,19 +231,18 @@ class MPICArrayKokkos { // Method that builds the send buffer, note, this has to be ordered // Such that all the boundary elements going to a given rank are contiguous in the send buffer. - void fill_send_buffer(){ - + void fill_send_buffer() { // Copy this_array_ to the host this_array_.update_host(); MATAR_FENCE(); size_t send_idx = 0; - for(int i = 0; i < comm_plan_->num_send_ranks; i++){ - for(int j = 0; j < comm_plan_->send_counts_.host(i); j++){ - size_t src_idx = comm_plan_->send_indices_.host(i, j); // index of the element to send - + for (int i = 0; i < comm_plan_->num_send_ranks; i++) { + for (int j = 0; j < comm_plan_->send_counts_.host(i); j++) { + size_t src_idx = comm_plan_->send_indices_.host(i, j); // index of the element to send + // Copy all values associated with this element (handles multi-dimensional arrays) - for(size_t k = 0; k < stride_; k++){ + for (size_t k = 0; k < stride_; k++) { mpi_buffers_.send_buffer_.host(send_idx + k) = this_array_.host_pointer()[src_idx * stride_ + k]; } send_idx += stride_; @@ -280,37 +251,37 @@ class MPICArrayKokkos { }; // Method that copies the recv buffer into the this_array - void copy_recv_buffer(){ - + void copy_recv_buffer() { size_t recv_idx = 0; - for(int i = 0; i < comm_plan_->num_recv_ranks; i++){ - for(int j = 0; j < comm_plan_->recv_counts_.host(i); j++){ + for (int i = 0; i < comm_plan_->num_recv_ranks; i++) { + for (int j = 0; j < comm_plan_->recv_counts_.host(i); j++) { size_t dest_idx = comm_plan_->recv_indices_.host(i, j); - + // Copy all values associated with this element (handles multi-dimensional arrays) - for(size_t k = 0; k < stride_; k++){ + for (size_t k = 0; k < stride_; k++) { this_array_.host_pointer()[dest_idx * stride_ + k] = mpi_buffers_.recv_buffer_.host(recv_idx + k); } - + recv_idx += stride_; } } }; - // Note: This "may" be needed, im not sure. Currently, it works.... - // Use nullptr for empty arrays to avoid accessing element 0 of 0-sized array (undefined behavior) - // T* send_buf_ptr = (send_buffer_.size() > 0) ? &send_buffer_.host(0) : nullptr; - // T* recv_buf_ptr = (recv_buffer_.size() > 0) ? &recv_buffer_.host(0) : nullptr; - // int* send_cnt_ptr = (comm_plan_->num_send_ranks > 0) ? &comm_plan_->send_counts_.host(0) : nullptr; - // int* send_dsp_ptr = (comm_plan_->num_send_ranks > 0) ? &comm_plan_->send_displs_.host(0) : nullptr; - // int* recv_cnt_ptr = (comm_plan_->num_recv_ranks > 0) ? &comm_plan_->recv_counts_.host(0) : nullptr; - // int* recv_dsp_ptr = (comm_plan_->num_recv_ranks > 0) ? &comm_plan_->recv_displs_.host(0) : nullptr; + // Use nullptr for empty arrays to avoid accessing element 0 of 0-sized array (undefined + // behavior) T* send_buf_ptr = (send_buffer_.size() > 0) ? &send_buffer_.host(0) : nullptr; T* + // recv_buf_ptr = (recv_buffer_.size() > 0) ? &recv_buffer_.host(0) : nullptr; int* send_cnt_ptr + // = (comm_plan_->num_send_ranks > 0) ? &comm_plan_->send_counts_.host(0) : nullptr; int* + // send_dsp_ptr = (comm_plan_->num_send_ranks > 0) ? &comm_plan_->send_displs_.host(0) : + // nullptr; int* recv_cnt_ptr = (comm_plan_->num_recv_ranks > 0) ? + // &comm_plan_->recv_counts_.host(0) : nullptr; int* recv_dsp_ptr = (comm_plan_->num_recv_ranks + // > 0) ? &comm_plan_->recv_displs_.host(0) : nullptr; // Method that communicates the data between the ranks - // NOTE: This is a blocking communication operation, - // if you want to use non-blocking communication, you can use the following: MPI_Ineighbor_alltoallv - + // NOTE: This is a blocking communication operation, + // if you want to use non-blocking communication, you can use the following: + // MPI_Ineighbor_alltoallv + // TODO: Consider replacing this with persistent communicator: // MPI_Request req; @@ -327,7 +298,7 @@ class MPICArrayKokkos { // // modify sendbuf in-place as needed // MPI_Wait(&req); - void communicate(){ + void communicate() { if (!comm_plan_) { return; } @@ -351,17 +322,16 @@ class MPICArrayKokkos { fill_send_buffer(); - MPI_Neighbor_alltoallv( - mpi_buffers_.send_buffer_.host_pointer(), - mpi_buffers_.send_counts_.host_pointer(), - mpi_buffers_.send_displs_.host_pointer(), - mpi_type_map::value(), - mpi_buffers_.recv_buffer_.host_pointer(), - mpi_buffers_.recv_counts_.host_pointer(), - mpi_buffers_.recv_displs_.host_pointer(), - mpi_type_map::value(), - comm_plan_->mpi_comm_graph); - + MPI_Neighbor_alltoallv(mpi_buffers_.send_buffer_.host_pointer(), + mpi_buffers_.send_counts_.host_pointer(), + mpi_buffers_.send_displs_.host_pointer(), + mpi_type_map::value(), + mpi_buffers_.recv_buffer_.host_pointer(), + mpi_buffers_.recv_counts_.host_pointer(), + mpi_buffers_.recv_displs_.host_pointer(), + mpi_type_map::value(), + comm_plan_->mpi_comm_graph); + copy_recv_buffer(); this_array_.update_device(); MATAR_FENCE(); @@ -381,121 +351,118 @@ class MPICArrayKokkos { /// stress(elem, gauss, i, j) → all_reduce(op, g, i, j) over owned elem. T all_reduce(operation op, size_t g, size_t ti, size_t tj); - void set_values(const T& value){ - this_array_.set_values(value); - }; + void set_values(const T& value) { this_array_.set_values(value); }; // Deconstructor - KOKKOS_INLINE_FUNCTION - ~MPICArrayKokkos (); -}; // End of MPIDArrayKokkos + KOKKOS_INLINE_FUNCTION ~MPICArrayKokkos(); +}; // End of MPIDArrayKokkos // Default constructor template -MPICArrayKokkos::MPICArrayKokkos() - : this_array_(), stride_(1), length_(0), order_(0) { - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - } +MPICArrayKokkos::MPICArrayKokkos() : this_array_(), stride_(1), length_(0), order_(0) { + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + } } // Overloaded 1D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, const std::string& tag_string) : stride_(1), length_(dim0), order_(1) { - dims_[0] = dim0; + dims_[0] = dim0; this_array_ = DCArrayKokkos(dim0, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0); + host = ViewCArray(this_array_.host_pointer(), dim0); } // Overloaded 2D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) : stride_(dim1), length_(dim0 * dim1), order_(2) { dims_[0] = dim0; dims_[1] = dim1; this_array_ = DCArrayKokkos(dim0, dim1, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1); } // Overloaded 3D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) : stride_(dim1 * dim2), length_(dim0 * dim1 * dim2), order_(3) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; this_array_ = DCArrayKokkos(dim0, dim1, dim2, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1, dim2); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1, dim2); } // Overloaded 4D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, + const std::string& tag_string) : stride_(dim1 * dim2 * dim3), length_(dim0 * dim1 * dim2 * dim3), order_(4) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; this_array_ = DCArrayKokkos(dim0, dim1, dim2, dim3, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1, dim2, dim3); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1, dim2, dim3); } // Overloaded 5D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, + const std::string& tag_string) : stride_(dim1 * dim2 * dim3 * dim4), length_(dim0 * dim1 * dim2 * dim3 * dim4), order_(5) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; this_array_ = DCArrayKokkos(dim0, dim1, dim2, dim3, dim4, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4); } // Overloaded 6D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + const std::string& tag_string) : stride_(dim1 * dim2 * dim3 * dim4 * dim5), length_(dim0 * dim1 * dim2 * dim3 * dim4 * dim5), order_(6) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; this_array_ = DCArrayKokkos(dim0, dim1, dim2, dim3, dim4, dim5, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4, dim5); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4, dim5); } // Overloaded 7D constructor template -MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) +MPICArrayKokkos::MPICArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) : stride_(dim1 * dim2 * dim3 * dim4 * dim5 * dim6), length_(dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6), order_(7) { - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; this_array_ = DCArrayKokkos(dim0, dim1, dim2, dim3, dim4, dim5, dim6, tag_string); - host = ViewCArray (this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); + host = ViewCArray(this_array_.host_pointer(), dim0, dim1, dim2, dim3, dim4, dim5, dim6); } - template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i) const { assert(order_ == 1 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 1D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 1D!"); return this_array_(i); } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j) const { assert(order_ == 2 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 2D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 2D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 2D!"); @@ -503,8 +470,7 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k) const { assert(order_ == 3 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 3D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 3D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 3D!"); @@ -513,8 +479,7 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { assert(order_ == 4 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 4D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 4D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 4D!"); @@ -524,8 +489,7 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { assert(order_ == 5 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 5D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 5D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 5D!"); @@ -536,8 +500,8 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const { assert(order_ == 6 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 6D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 6D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 6D!"); @@ -549,8 +513,8 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { +KOKKOS_INLINE_FUNCTION T& MPICArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, + size_t o) const { assert(order_ == 7 && "Tensor order (rank) does not match constructor in MPICArrayKokkos 7D!"); assert(i < dims_[0] && "i is out of bounds in MPICArrayKokkos 7D!"); assert(j < dims_[1] && "j is out of bounds in MPICArrayKokkos 7D!"); @@ -563,25 +527,23 @@ T& MPICArrayKokkos::operator()(size_t i, size_t } template -KOKKOS_INLINE_FUNCTION -MPICArrayKokkos& MPICArrayKokkos::operator=(const MPICArrayKokkos& temp) { - +KOKKOS_INLINE_FUNCTION MPICArrayKokkos& MPICArrayKokkos::operator=( + const MPICArrayKokkos& temp) { // Do nothing if the assignment is of the form x = x if (this != &temp) { - - this_array_ = temp.this_array_; + this_array_ = temp.this_array_; mpi_buffers_ = temp.mpi_buffers_; length_ = temp.length_; - for (int iter = 0; iter < temp.order_; iter++){ + for (int iter = 0; iter < temp.order_; iter++) { dims_[iter] = temp.dims_[iter]; - } // end for + } // end for - order_ = temp.order_; + order_ = temp.order_; comm_plan_ = temp.comm_plan_; comm_plan_ = temp.comm_plan_; - stride_ = temp.stride_; + stride_ = temp.stride_; num_owned_ = temp.num_owned_; num_ghost_ = temp.num_ghost_; @@ -592,68 +554,58 @@ MPICArrayKokkos& MPICArrayKokkos -KOKKOS_INLINE_FUNCTION -size_t MPICArrayKokkos::size() const { +KOKKOS_INLINE_FUNCTION size_t MPICArrayKokkos::size() const { return this_array_.size(); } template -KOKKOS_INLINE_FUNCTION -size_t MPICArrayKokkos::extent() const { +KOKKOS_INLINE_FUNCTION size_t MPICArrayKokkos::extent() const { return this_array_.extent(); } template -KOKKOS_INLINE_FUNCTION -size_t MPICArrayKokkos::dims(size_t i) const { +KOKKOS_INLINE_FUNCTION size_t MPICArrayKokkos::dims(size_t i) const { assert(i < order_ && "MPICArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); assert(dims_[i] > 0 && "Access to MPICArrayKokkos dims is out of bounds!"); return this_array_.dims(i); } template -KOKKOS_INLINE_FUNCTION -size_t MPICArrayKokkos::order() const { +KOKKOS_INLINE_FUNCTION size_t MPICArrayKokkos::order() const { return this_array_.order(); } template -KOKKOS_INLINE_FUNCTION -T* MPICArrayKokkos::device_pointer() const { +KOKKOS_INLINE_FUNCTION T* MPICArrayKokkos::device_pointer() const { return this_array_.device_pointer(); } template -KOKKOS_INLINE_FUNCTION -T* MPICArrayKokkos::host_pointer() const { +KOKKOS_INLINE_FUNCTION T* MPICArrayKokkos::host_pointer() const { return this_array_.host_pointer(); } template -KOKKOS_INLINE_FUNCTION -Kokkos::DualView MPICArrayKokkos::get_kokkos_dual_view() const { +KOKKOS_INLINE_FUNCTION Kokkos::DualView +MPICArrayKokkos::get_kokkos_dual_view() const { return this_array_.get_kokkos_dual_view(); } template -void MPICArrayKokkos::update_host() { +void MPICArrayKokkos::update_host() { this_array_.update_host(); } template -void MPICArrayKokkos::update_device() { +void MPICArrayKokkos::update_device() { this_array_.update_device(); } - - template T MPICArrayKokkos::all_reduce(operation op) { - - // assert(order_ == 1 && stride_ == 1 && "MPICArrayKokkos::all_reduce requires a 1D array (stride 1)."); - assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && - "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); - + // assert(order_ == 1 && stride_ == 1 && "MPICArrayKokkos::all_reduce requires a 1D array + // (stride 1)."); + assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); assert(num_owned_ <= dims_[0] && "MPICArrayKokkos::all_reduce: num_owned exceeds dim0."); const size_t owned_len = (num_owned_ > 0) ? num_owned_ : dims_[0]; @@ -663,53 +615,52 @@ T MPICArrayKokkos::all_reduce(operation op) T local; if (comm_plan_ == nullptr || comm_plan_->comm_type == communication_plan_type::no_communication) { - switch (op) { - case operation::sum: { - local = 0; - T loc_sum = 0; - FOR_REDUCE_SUM_CLASS(i, 0, owned_len, - loc_sum, { - loc_sum += this_array_(i); - }, local); - break; - } - case operation::product: { - local = T(1); - T loc_prod = 1; - FOR_REDUCE_PRODUCT_CLASS(i, 0, owned_len, - loc_prod, { - loc_prod *= this_array_(i); - }, local); - break; - } - case operation::max: { - T loc_max; - FOR_REDUCE_MAX_CLASS(i, 0, owned_len, - loc_max, { - loc_max = (this_array_(i) > loc_max) ? this_array_(i) : loc_max; - }, local); - break; - } - case operation::min: { - T loc_min; - FOR_REDUCE_MIN_CLASS(i, 0, owned_len, - loc_min, { - loc_min = (this_array_(i) < loc_min) ? this_array_(i) : loc_min; - }, local); - break; - } - default: - printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); - printf("Supported operations are: sum, product, max, min\n"); - Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); - break; + case operation::sum: { + local = 0; + T loc_sum = 0; + FOR_REDUCE_SUM_CLASS(i, 0, owned_len, + loc_sum, { + loc_sum += this_array_(i); + }, local); + break; + } + case operation::product: { + local = T(1); + T loc_prod = 1; + FOR_REDUCE_PRODUCT_CLASS(i, 0, owned_len, + loc_prod, { + loc_prod *= this_array_(i); + }, local); + break; + } + case operation::max: { + T loc_max; + FOR_REDUCE_MAX_CLASS(i, 0, owned_len, + loc_max, { + loc_max = (this_array_(i) > loc_max) ? this_array_(i) : loc_max; + }, local); + break; + } + case operation::min: { + T loc_min; + FOR_REDUCE_MIN_CLASS(i, 0, owned_len, + loc_min, { + loc_min = (this_array_(i) < loc_min) ? this_array_(i) : loc_min; + }, local); + break; + } + default: + printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); + printf("Supported operations are: sum, product, max, min\n"); + Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); + break; } } else { printf("MPICArrayKokkos::all_reduce: communication plan requires info on ghost vs owned\n"); } - T global = local; + T global = local; MPI_Comm comm = MPI_COMM_WORLD; if (comm_plan_ != nullptr && comm_plan_->has_comm_world) { comm = comm_plan_->mpi_comm_world; @@ -722,8 +673,7 @@ template ::all_reduce(operation op, size_t j) { assert(order_ == 2 && "MPICArrayKokkos::all_reduce(op,j) requires a rank-2 array."); assert(j < dims_[1] && "Fixed index j is out of bounds."); - assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && - "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); + assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); assert(num_owned_ <= dims_[0] && "MPICArrayKokkos::all_reduce: num_owned exceeds dim0."); const size_t owned_len = (num_owned_ > 0) ? num_owned_ : dims_[0]; assert(owned_len > 0 && "MPICArrayKokkos::all_reduce: empty reduction range."); @@ -731,49 +681,53 @@ T MPICArrayKokkos::all_reduce(operation op, T local; if (comm_plan_ == nullptr || comm_plan_->comm_type == communication_plan_type::no_communication) { switch (op) { - case operation::sum: { - local = 0; - T loc_sum = 0; - FOR_REDUCE_SUM_CLASS(e, 0, owned_len, loc_sum, { - loc_sum += this_array_(e, j); - }, local); - break; - } - case operation::product: { - local = T(1); - T loc_prod = 1; - FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, loc_prod, { - loc_prod *= this_array_(e, j); - }, local); - break; - } - case operation::max: { - T loc_max; - FOR_REDUCE_MAX_CLASS(e, 0, owned_len, loc_max, { - const T v = this_array_(e, j); - loc_max = (v > loc_max) ? v : loc_max; - }, local); - break; - } - case operation::min: { - T loc_min; - FOR_REDUCE_MIN_CLASS(e, 0, owned_len, loc_min, { - const T v = this_array_(e, j); - loc_min = (v < loc_min) ? v : loc_min; - }, local); - break; - } - default: - printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); - printf("Supported operations are: sum, product, max, min\n"); - Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); - break; + case operation::sum: { + local = 0; + T loc_sum = 0; + FOR_REDUCE_SUM_CLASS(e, 0, owned_len, + loc_sum, { + loc_sum += this_array_(e, j); + }, local); + break; + } + case operation::product: { + local = T(1); + T loc_prod = 1; + FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, + loc_prod, { + loc_prod *= this_array_(e, j); + }, local); + break; + } + case operation::max: { + T loc_max; + FOR_REDUCE_MAX_CLASS(e, 0, owned_len, + loc_max, { + const T v = this_array_(e, j); + loc_max = (v > loc_max) ? v : loc_max; + }, local); + break; + } + case operation::min: { + T loc_min; + FOR_REDUCE_MIN_CLASS(e, 0, owned_len, + loc_min, { + const T v = this_array_(e, j); + loc_min = (v < loc_min) ? v : loc_min; + }, local); + break; + } + default: + printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); + printf("Supported operations are: sum, product, max, min\n"); + Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); + break; } } else { printf("MPICArrayKokkos::all_reduce: communication plan requires info on ghost vs owned\n"); } - T global = local; + T global = local; MPI_Comm mpi_comm = MPI_COMM_WORLD; if (comm_plan_ != nullptr && comm_plan_->has_comm_world) { mpi_comm = comm_plan_->mpi_comm_world; @@ -786,8 +740,7 @@ template ::all_reduce(operation op, size_t j, size_t k) { assert(order_ == 3 && "MPICArrayKokkos::all_reduce(op,j,k) requires a rank-3 array."); assert(j < dims_[1] && k < dims_[2] && "Fixed tensor indices (j,k) are out of bounds."); - assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && - "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); + assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); assert(num_owned_ <= dims_[0] && "MPICArrayKokkos::all_reduce: num_owned exceeds dim0."); const size_t owned_len = (num_owned_ > 0) ? num_owned_ : dims_[0]; assert(owned_len > 0 && "MPICArrayKokkos::all_reduce: empty reduction range."); @@ -795,49 +748,53 @@ T MPICArrayKokkos::all_reduce(operation op, T local; if (comm_plan_ == nullptr || comm_plan_->comm_type == communication_plan_type::no_communication) { switch (op) { - case operation::sum: { - local = 0; - T loc_sum = 0; - FOR_REDUCE_SUM_CLASS(e, 0, owned_len, loc_sum, { - loc_sum += this_array_(e, j, k); - }, local); - break; - } - case operation::product: { - local = T(1); - T loc_prod = 1; - FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, loc_prod, { - loc_prod *= this_array_(e, j, k); - }, local); - break; - } - case operation::max: { - T loc_max; - FOR_REDUCE_MAX_CLASS(e, 0, owned_len, loc_max, { - const T v = this_array_(e, j, k); - loc_max = (v > loc_max) ? v : loc_max; - }, local); - break; - } - case operation::min: { - T loc_min; - FOR_REDUCE_MIN_CLASS(e, 0, owned_len, loc_min, { - const T v = this_array_(e, j, k); - loc_min = (v < loc_min) ? v : loc_min; - }, local); - break; - } - default: - printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); - printf("Supported operations are: sum, product, max, min\n"); - Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); - break; + case operation::sum: { + local = 0; + T loc_sum = 0; + FOR_REDUCE_SUM_CLASS(e, 0, owned_len, + loc_sum, { + loc_sum += this_array_(e, j, k); + }, local); + break; + } + case operation::product: { + local = T(1); + T loc_prod = 1; + FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, + loc_prod, { + loc_prod *= this_array_(e, j, k); + }, local); + break; + } + case operation::max: { + T loc_max; + FOR_REDUCE_MAX_CLASS(e, 0, owned_len, + loc_max, { + const T v = this_array_(e, j, k); + loc_max = (v > loc_max) ? v : loc_max; + }, local); + break; + } + case operation::min: { + T loc_min; + FOR_REDUCE_MIN_CLASS(e, 0, owned_len, + loc_min, { + const T v = this_array_(e, j, k); + loc_min = (v < loc_min) ? v : loc_min; + }, local); + break; + } + default: + printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); + printf("Supported operations are: sum, product, max, min\n"); + Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); + break; } } else { printf("MPICArrayKokkos::all_reduce: communication plan requires info on ghost vs owned\n"); } - T global = local; + T global = local; MPI_Comm mpi_comm = MPI_COMM_WORLD; if (comm_plan_ != nullptr && comm_plan_->has_comm_world) { mpi_comm = comm_plan_->mpi_comm_world; @@ -847,13 +804,10 @@ T MPICArrayKokkos::all_reduce(operation op, } template -T MPICArrayKokkos::all_reduce(operation op, size_t g, size_t ti, - size_t tj) { +T MPICArrayKokkos::all_reduce(operation op, size_t g, size_t ti, size_t tj) { assert(order_ == 4 && "MPICArrayKokkos::all_reduce(op,g,ti,tj) requires a rank-4 array."); - assert(g < dims_[1] && ti < dims_[2] && tj < dims_[3] && - "Fixed indices (Gauss, tensor i, j) are out of bounds."); - assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && - "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); + assert(g < dims_[1] && ti < dims_[2] && tj < dims_[3] && "Fixed indices (Gauss, tensor i, j) are out of bounds."); + assert(!(op == operation::product && sizeof(T) == sizeof(bool)) && "MPICArrayKokkos::all_reduce: product reduction is not supported for bool."); assert(num_owned_ <= dims_[0] && "MPICArrayKokkos::all_reduce: num_owned exceeds dim0."); const size_t owned_len = (num_owned_ > 0) ? num_owned_ : dims_[0]; assert(owned_len > 0 && "MPICArrayKokkos::all_reduce: empty reduction range."); @@ -861,49 +815,53 @@ T MPICArrayKokkos::all_reduce(operation op, T local; if (comm_plan_ == nullptr || comm_plan_->comm_type == communication_plan_type::no_communication) { switch (op) { - case operation::sum: { - local = 0; - T loc_sum = 0; - FOR_REDUCE_SUM_CLASS(e, 0, owned_len, loc_sum, { - loc_sum += this_array_(e, g, ti, tj); - }, local); - break; - } - case operation::product: { - local = T(1); - T loc_prod = 1; - FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, loc_prod, { - loc_prod *= this_array_(e, g, ti, tj); - }, local); - break; - } - case operation::max: { - T loc_max; - FOR_REDUCE_MAX_CLASS(e, 0, owned_len, loc_max, { - const T v = this_array_(e, g, ti, tj); - loc_max = (v > loc_max) ? v : loc_max; - }, local); - break; - } - case operation::min: { - T loc_min; - FOR_REDUCE_MIN_CLASS(e, 0, owned_len, loc_min, { - const T v = this_array_(e, g, ti, tj); - loc_min = (v < loc_min) ? v : loc_min; - }, local); - break; - } - default: - printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); - printf("Supported operations are: sum, product, max, min\n"); - Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); - break; + case operation::sum: { + local = 0; + T loc_sum = 0; + FOR_REDUCE_SUM_CLASS(e, 0, owned_len, + loc_sum, { + loc_sum += this_array_(e, g, ti, tj); + }, local); + break; + } + case operation::product: { + local = T(1); + T loc_prod = 1; + FOR_REDUCE_PRODUCT_CLASS(e, 0, owned_len, + loc_prod, { + loc_prod *= this_array_(e, g, ti, tj); + }, local); + break; + } + case operation::max: { + T loc_max; + FOR_REDUCE_MAX_CLASS(e, 0, owned_len, + loc_max, { + const T v = this_array_(e, g, ti, tj); + loc_max = (v > loc_max) ? v : loc_max; + }, local); + break; + } + case operation::min: { + T loc_min; + FOR_REDUCE_MIN_CLASS(e, 0, owned_len, + loc_min, { + const T v = this_array_(e, g, ti, tj); + loc_min = (v < loc_min) ? v : loc_min; + }, local); + break; + } + default: + printf("MPICArrayKokkos::all_reduce: unsupported operation %d\n", op); + printf("Supported operations are: sum, product, max, min\n"); + Kokkos::abort("MPICArrayKokkos::all_reduce: unsupported operation"); + break; } } else { printf("MPICArrayKokkos::all_reduce: communication plan requires info on ghost vs owned\n"); } - T global = local; + T global = local; MPI_Comm mpi_comm = MPI_COMM_WORLD; if (comm_plan_ != nullptr && comm_plan_->has_comm_world) { mpi_comm = comm_plan_->mpi_comm_world; @@ -912,13 +870,10 @@ T MPICArrayKokkos::all_reduce(operation op, return global; } - template -KOKKOS_INLINE_FUNCTION -MPICArrayKokkos::~MPICArrayKokkos() {} - -} // end namespace mtr +KOKKOS_INLINE_FUNCTION MPICArrayKokkos::~MPICArrayKokkos() {} +} // end namespace mtr -#endif // end if have MPI -#endif // end if MPICARRAYKOKKOS_H \ No newline at end of file +#endif // end if have MPI +#endif // end if MPICARRAYKOKKOS_H \ No newline at end of file From 25d70faa7add0d12844e58b8bd660cf4bb975abe Mon Sep 17 00:00:00 2001 From: Jacob Moore Date: Tue, 25 Aug 2026 18:26:22 -0500 Subject: [PATCH 14/43] ENH: Updating formatting scripts --- formatting/README.md | 22 +++++-- formatting/matar-format.py | 120 ++++++++++++++++++++++++------------- 2 files changed, 96 insertions(+), 46 deletions(-) diff --git a/formatting/README.md b/formatting/README.md index 9aa5c548..f0b49899 100644 --- a/formatting/README.md +++ b/formatting/README.md @@ -7,9 +7,10 @@ Formatting is a two-stage pipeline: assignments, and macro-awareness for `MATAR_*` statement macros and `KOKKOS_*` attribute macros. 2. **`matar-format.py`** — post-processor that rewrites MATAR parallel-macro - calls (`FOR_ALL`, `DO_ALL`, `FOR_REDUCE_*`, `DO_REDUCE_*`, and their `_CLASS` - variants) into the canonical layout clang-format cannot produce - (it has no notion of argument groups): + calls (`FOR_ALL`, `DO_ALL`, `FOR_REDUCE_*`, `DO_REDUCE_*`, their `_CLASS` + variants, and the hierarchical `FOR_FIRST`/`FOR_SECOND`/`FOR_THIRD`, + `DO_FIRST`/..., `*_REDUCE_*_SECOND`/`_THIRD` forms) into the canonical + layout clang-format cannot produce (it has no notion of argument groups): ```c++ DO_REDUCE_MAX(k, 0, 10, @@ -25,14 +26,23 @@ Formatting is a two-stage pipeline: One index triple per line aligned under the first argument, reduction variables on their own line, body at macro indent + 4, trailing arguments joined onto the closing line. Bodies keep clang-format's internal - formatting; only their indentation is shifted. The pass is idempotent and - skips any call it cannot parse confidently. + formatting; only their indentation is shifted. Macros nested inside another + macro's body (e.g. a `FOR_REDUCE_SUM_SECOND` inside a `FOR_FIRST`) are + reflowed recursively into the same expanded layout. + The pass skips any call it cannot parse confidently, and comments/strings + are masked so braces inside them cannot confuse the matcher. ## Usage -Always run both stages, clang-format first: +Always run both stages as a pair, clang-format first and the reflow second — +clang-format alone will re-pack the macro headers, and the reflow restores +them. Applied as a pair the result is stable (repeated runs are byte-identical). ```bash clang-format -i src/include/*.h solvers/*.hpp python3 formatting/matar-format.py src/include/*.h solvers/*.hpp ``` + +Files clang-format must never touch are listed in `.clang-format-ignore` +(currently `src/include/macros.h`, whose `#define \` continuation tables +clang-format mangles). diff --git a/formatting/matar-format.py b/formatting/matar-format.py index 51d374c8..ecff7196 100755 --- a/formatting/matar-format.py +++ b/formatting/matar-format.py @@ -13,38 +13,71 @@ }, result); Bodies keep clang-format's internal formatting; only their indentation shifts. -Usage: matar-format.py [ ...] (edits in place, idempotent) +Comments and string literals are masked out before any paren/brace matching, +so braces inside comments (including commented-out code) cannot confuse it. + +Usage: matar-format.py [ ...] (edits in place; the pipeline +clang-format-then-reflow is idempotent as a pair) """ import re import sys +# Longer names must precede their prefixes (regex alternation is first-match): +# e.g. FOR_REDUCE_SUM_SECOND before FOR_REDUCE_SUM. MACROS = ( "FOR_ALL_CLASS", "DO_ALL_CLASS", "FOR_ALL", "DO_ALL", "FOR_REDUCE_SUM_CLASS", "FOR_REDUCE_MAX_CLASS", "FOR_REDUCE_MIN_CLASS", "FOR_REDUCE_PRODUCT_CLASS", + "FOR_REDUCE_SUM_SECOND", "FOR_REDUCE_SUM_THIRD", + "FOR_REDUCE_MAX_SECOND", "FOR_REDUCE_MIN_SECOND", + "DO_REDUCE_SUM_SECOND", "DO_REDUCE_SUM_THIRD", + "DO_REDUCE_MAX_THIRD", "DO_REDUCE_MIN_THIRD", "FOR_REDUCE_SUM", "FOR_REDUCE_MAX", "FOR_REDUCE_MIN", "FOR_REDUCE_PRODUCT", "DO_REDUCE_SUM", "DO_REDUCE_MAX", "DO_REDUCE_MIN", + "FOR_FIRST", "FOR_SECOND", "FOR_THIRD", + "DO_FIRST", "DO_SECOND", "DO_THIRD", ) MACRO_RE = re.compile(r"(? Date: Tue, 25 Aug 2026 18:26:41 -0500 Subject: [PATCH 15/43] STYLE: Formatting examples --- examples/CSCKokkos.cpp | 33 +- examples/CSRKokkos.cpp | 15 +- examples/ann_kokkos.cpp | 250 +-- examples/ann_kokkos_compare.cpp | 252 +-- examples/gArrayofgArrays/main.cpp | 98 +- .../halfspace_cooling/halfspace_cooling.cpp | 15 +- examples/kokkos_for.cpp | 986 +++++----- examples/laplace/main_carray_right.cpp | 37 +- examples/laplace/main_carray_wrong.cpp | 37 +- .../laplace/main_carraykokkos_c_indexing.cpp | 70 +- .../main_carraykokkos_default_indexing.cpp | 70 +- examples/laplace/main_cpp.cpp | 35 +- examples/laplace/main_farray_right.cpp | 37 +- examples/laplace/main_farray_wrong.cpp | 37 +- .../main_farraykokkos_default_indexing.cpp | 70 +- .../laplace/main_farraykokkos_f_indexing.cpp | 70 +- examples/laplace/main_kokkosview.cpp | 80 +- examples/laplaceMPI/laplace_mpi.cpp | 161 +- examples/laplaceMPI/mpi_mesh_test.cpp | 365 ++-- examples/laplaceMPI/simple_halo.cpp | 160 +- examples/laplaceMPI/simple_mpi.cpp | 168 +- examples/main.cpp | 5 +- examples/main_kokkos.cpp | 561 +++--- examples/matar_fortran/matar_functions.cpp | 18 +- examples/matar_mpi.cpp | 486 +++-- examples/mesh_decomp/decomp_utils.h | 926 +++++---- examples/mesh_decomp/mesh.h | 704 ++++--- examples/mesh_decomp/mesh_decomp.cpp | 143 +- examples/mesh_decomp/mesh_inputs.h | 114 +- examples/mesh_decomp/mesh_io.h | 774 ++++---- examples/mesh_decomp/state.h | 103 +- examples/mtr-kokkos-simple.cpp | 367 ++-- examples/parallel_hello_world.cpp | 7 +- .../CH_fourier_spectral_solver.cpp | 52 +- .../CH_fourier_spectral_solver.h | 27 +- .../srcKokkosVerbose/fft_manager_in_place.cpp | 61 +- .../srcKokkosVerbose/fft_manager_in_place.h | 15 +- .../fft_manager_out_of_place.cpp | 29 +- .../fft_manager_out_of_place.h | 17 +- .../srcKokkosVerbose/fftc_cufft_in_place.cpp | 40 +- .../fftc_cufft_out_of_place.cpp | 38 +- .../srcKokkosVerbose/fftc_fftw_in_place.cpp | 31 +- .../fftc_fftw_out_of_place.cpp | 31 +- .../srcKokkosVerbose/fourier_space.cpp | 29 +- .../srcKokkosVerbose/fourier_space.h | 19 +- .../srcKokkosVerbose/global_arrays.cpp | 3 +- .../srcKokkosVerbose/global_arrays.h | 5 +- .../srcKokkosVerbose/initialize_comp.cpp | 13 +- .../srcKokkosVerbose/initialize_comp.h | 2 +- .../srcKokkosVerbose/local_free_energy.cpp | 39 +- .../srcKokkosVerbose/local_free_energy.h | 2 +- examples/phaseField/srcKokkosVerbose/main.cpp | 7 +- .../phaseField/srcKokkosVerbose/outputs.cpp | 37 +- .../phaseField/srcKokkosVerbose/outputs.h | 5 +- .../srcKokkosVerbose/sim_parameters.cpp | 37 +- .../srcKokkosVerbose/sim_parameters.h | 3 +- .../srcMacros/CH_fourier_spectral_solver.cpp | 34 +- .../srcMacros/CH_fourier_spectral_solver.h | 27 +- .../srcMacros/fft_manager_in_place.cpp | 339 ++-- .../srcMacros/fft_manager_in_place.h | 15 +- .../srcMacros/fft_manager_out_of_place.cpp | 29 +- .../srcMacros/fft_manager_out_of_place.h | 17 +- .../srcMacros/fftc_cufft_in_place.cpp | 40 +- .../srcMacros/fftc_cufft_out_of_place.cpp | 38 +- .../srcMacros/fftc_fftw_in_place.cpp | 31 +- .../srcMacros/fftc_fftw_out_of_place.cpp | 31 +- .../phaseField/srcMacros/fourier_space.cpp | 21 +- examples/phaseField/srcMacros/fourier_space.h | 19 +- .../phaseField/srcMacros/global_arrays.cpp | 3 +- examples/phaseField/srcMacros/global_arrays.h | 5 +- .../phaseField/srcMacros/initialize_comp.cpp | 13 +- .../phaseField/srcMacros/initialize_comp.h | 2 +- .../srcMacros/local_free_energy.cpp | 166 +- .../phaseField/srcMacros/local_free_energy.h | 2 +- examples/phaseField/srcMacros/main.cpp | 7 +- examples/phaseField/srcMacros/outputs.cpp | 348 ++-- examples/phaseField/srcMacros/outputs.h | 5 +- .../phaseField/srcMacros/sim_parameters.cpp | 37 +- .../phaseField/srcMacros/sim_parameters.h | 3 +- examples/phaseFieldMPI/complex_arrays.cpp | 23 +- examples/phaseFieldMPI/complex_arrays.h | 9 +- examples/phaseFieldMPI/fourier_space.cpp | 30 +- examples/phaseFieldMPI/fourier_space.h | 13 +- examples/phaseFieldMPI/global_arrays.cpp | 5 +- examples/phaseFieldMPI/global_arrays.h | 5 +- examples/phaseFieldMPI/heffte_fft.h | 175 +- examples/phaseFieldMPI/initialize_comp.cpp | 5 +- examples/phaseFieldMPI/initialize_comp.h | 2 +- examples/phaseFieldMPI/main.cpp | 13 +- examples/phaseFieldMPI/profile.cpp | 60 +- examples/phaseFieldMPI/profile.h | 30 +- examples/phaseFieldMPI/sim_parameters.cpp | 37 +- examples/phaseFieldMPI/sim_parameters.h | 7 +- examples/phaseFieldMPI/system.cpp | 96 +- examples/phaseFieldMPI/system.h | 5 +- examples/phaseFieldMPI/vtk_writer_mpi_io.cpp | 49 +- examples/phaseFieldMPI/vtk_writer_mpi_io.h | 12 +- examples/pointcloud/graphics-reader.h | 813 ++++---- examples/pointcloud/pointcloud-gbl.cpp | 1367 +++++++------- examples/pointcloud/pointcloud-rk.cpp | 1652 ++++++++--------- examples/random_numbers.cpp | 13 +- examples/sparsetests/matVec.cpp | 80 +- examples/sparsetests/powerIter.cpp | 177 +- examples/sparsetests/sparseMatVec.cpp | 60 +- examples/sparsetests/sparsePowerIter.cpp | 97 +- examples/test_cramers_rule.cpp | 317 ++-- examples/test_drrak.cpp | 91 +- examples/test_dual_types.cpp | 377 ++-- examples/test_for.cpp | 299 ++- examples/test_lu_solve.cpp | 488 +++-- examples/test_qr_solve.cpp | 351 ++-- examples/test_rocm/SomeClass.cpp | 5 +- examples/test_rocm/SomeClass.h | 6 +- examples/test_rocm/main.cpp | 3 +- examples/test_set_values.cpp | 150 +- examples/test_shared_ptr.cpp | 10 +- examples/virtualFcnKokkos/child.cpp | 28 +- examples/virtualFcnKokkos/child.hpp | 80 +- examples/virtualFcnKokkos/inherited_inits.cpp | 47 +- examples/virtualFcnKokkos/inherited_inits.hpp | 13 +- examples/virtualFcnKokkos/kokkos_alias.h | 14 +- .../virtualFcnKokkos/main_kokkos_vfcn.cpp | 39 +- examples/virtualFcnKokkos/parents.h | 19 +- examples/virtualFcnMATAR/classes.cpp | 38 +- examples/virtualFcnMATAR/classes.hpp | 33 +- examples/virtualFcnMATAR/main.cpp | 19 +- examples/watt-graph/floyd.cpp | 63 +- examples/watt-graph/kokkos_floyd.cpp | 67 +- 128 files changed, 7447 insertions(+), 8973 deletions(-) mode change 100755 => 100644 examples/pointcloud/graphics-reader.h mode change 100755 => 100644 examples/pointcloud/pointcloud-gbl.cpp mode change 100755 => 100644 examples/pointcloud/pointcloud-rk.cpp diff --git a/examples/CSCKokkos.cpp b/examples/CSCKokkos.cpp index f3f95beb..7cfb40fe 100644 --- a/examples/CSCKokkos.cpp +++ b/examples/CSCKokkos.cpp @@ -36,17 +36,17 @@ #include #include -using namespace mtr; // matar namespace +using namespace mtr; // matar namespace -int main(int argc, char* argv[]) -{ - Kokkos::initialize(); { +int main(int argc, char* argv[]) { + Kokkos::initialize(); + { size_t nnz = 6; size_t dim1 = 3; size_t dim2 = 10; CArrayKokkos starts(dim2 + 1); CArrayKokkos rows(nnz); - CArrayKokkos array(nnz + 1); + CArrayKokkos array(nnz + 1); RUN({ starts(1) = 1; starts(2) = 2; @@ -86,37 +86,34 @@ int main(int argc, char* argv[]) auto A = pre_A; int* values = A.pointer(); auto a_start = A.get_starts(); - int total = 0; + int total = 0; - RUN({ - printf("This matix is %ld x %ld \n", A.dim1(), A.dim2()); - }); + RUN({ printf("This matix is %ld x %ld \n", A.dim1(), A.dim2()); }); - RUN({ - printf("nnz : %ld \n", A.nnz()); - }); + RUN({ printf("nnz : %ld \n", A.nnz()); }); int loc_total = 0; - loc_total += 0; // Get rid of warning + loc_total += 0; // Get rid of warning FOR_REDUCE_SUM(i, 0, nnz, loc_total, { - loc_total += values[i]; + loc_total += values[i]; }, total); printf("Sum of nnz from pointer method %d\n", total); total = 0; FOR_REDUCE_SUM(i, 0, nnz, loc_total, { - loc_total += a_start[i]; + loc_total += a_start[i]; }, total); printf("Sum of start indices form .get_starts() %d\n", total); total = 0; FOR_REDUCE_SUM(i, 0, dim1, j, 0, dim2 - 1, - loc_total, { - loc_total += A(i, j); + loc_total, { + loc_total += A(i, j); }, total); printf("Sum of nnz in array notation %d\n", total); - } Kokkos::finalize(); + } + Kokkos::finalize(); return 0; } diff --git a/examples/CSRKokkos.cpp b/examples/CSRKokkos.cpp index 7dab444d..815cb011 100644 --- a/examples/CSRKokkos.cpp +++ b/examples/CSRKokkos.cpp @@ -36,17 +36,17 @@ #include #include -using namespace mtr; // matar namespace +using namespace mtr; // matar namespace -int main(int argc, char* argv[]) -{ - Kokkos::initialize(); { +int main(int argc, char* argv[]) { + Kokkos::initialize(); + { size_t nnz = 6; size_t dim1 = 3; size_t dim2 = 10; CArrayKokkos starts(dim1 + 1); CArrayKokkos columns(nnz); - CArrayKokkos array(nnz); + CArrayKokkos array(nnz); RUN({ for (int i = 0; i < 4; i++) { starts(i) = 2 * i; @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) } }); - int column_arr[] = { 0, 2, 2, 0, 1, 2 }; + int column_arr[] = {0, 2, 2, 0, 1, 2}; CArrayKokkos data(6); CArrayKokkos row(4); CArrayKokkos column(6); @@ -116,6 +116,7 @@ int main(int argc, char* argv[]) printf("Sum of nnz in array notation %d\n", total); auto ss = A.begin(0); */ - } Kokkos::finalize(); + } + Kokkos::finalize(); return 0; } diff --git a/examples/ann_kokkos.cpp b/examples/ann_kokkos.cpp index 9d7b1ffd..030f16a5 100644 --- a/examples/ann_kokkos.cpp +++ b/examples/ann_kokkos.cpp @@ -39,35 +39,30 @@ #include "matar.h" -using namespace mtr; // matar namespace - - +using namespace mtr; // matar namespace // ================================================================= // Artificial Neural Network (ANN) // -// For a single layer, we have x_i inputs with weights_{ij}, +// For a single layer, we have x_i inputs with weights_{ij}, // creating y_j outputs. We have // y_j = Fcn(b_j) = Fcn( Sum_i {x_i w_{ij}} ) -// where the activation function Fcn is applied to b_j, creating +// where the activation function Fcn is applied to b_j, creating // outputs y_j. For multiple layers, we have // b_j^l = Sum_i (x_i^{l-1} w_{ij}^l) -// where l is a layer, and as before, an activation function is +// where l is a layer, and as before, an activation function is // applied to b_j^l, creating outputs y_j^l. -// +// // ================================================================= - // ================================================================= // // Number of nodes in each layer including inputs and outputs // // ================================================================= -std::vector num_nodes_in_layer = {64000, 30000, 8000, 4000, 2000, 1000, 100} ; +std::vector num_nodes_in_layer = {64000, 30000, 8000, 4000, 2000, 1000, 100}; // {9, 50, 100, 300, 200, 100, 20, 6} - - // ================================================================= // // data types and classes @@ -75,82 +70,67 @@ std::vector num_nodes_in_layer = {64000, 30000, 8000, 4000, 2000, 1000, // ================================================================= // array of ANN structs -struct ANNLayer_t{ - - DCArrayKokkos outputs; // dims = [layer] - DFArrayKokkos weights; // dims = [layer-1, layer] - DCArrayKokkos biases; // dims = [layer] - -}; // end struct - +struct ANNLayer_t { + DCArrayKokkos outputs; // dims = [layer] + DFArrayKokkos weights; // dims = [layer-1, layer] + DCArrayKokkos biases; // dims = [layer] +}; // end struct // ================================================================= // // functions // // ================================================================= -void vec_mat_multiply(DCArrayKokkos &inputs, - DCArrayKokkos &outputs, - DFArrayKokkos &matrix){ - +void vec_mat_multiply(DCArrayKokkos& inputs, DCArrayKokkos& outputs, DFArrayKokkos& matrix) { const size_t num_i = inputs.size(); const size_t num_j = outputs.size(); using team_t = typename Kokkos::TeamPolicy<>::member_type; - Kokkos::parallel_for ("MatVec", Kokkos::TeamPolicy<> (num_j, Kokkos::AUTO), - KOKKOS_LAMBDA (const team_t& team_h) { - - float sum = 0; - int j = team_h.league_rank(); - Kokkos::parallel_reduce (Kokkos::TeamThreadRange (team_h, num_i), - [&] (int i, float& lsum) { - lsum += inputs(i)*matrix(i,j); - }, sum); // end parallel reduce - - outputs(j) = sum; - - }); // end parallel for - - - FOR_ALL(j,0,num_j, { - if(fabs(outputs(j) - num_i)>= 1e-15){ - printf("error in vec mat multiply test \n"); - } + Kokkos::parallel_for( + "MatVec", + Kokkos::TeamPolicy<>(num_j, Kokkos::AUTO), + KOKKOS_LAMBDA(const team_t& team_h) { + float sum = 0; + int j = team_h.league_rank(); + Kokkos::parallel_reduce( + Kokkos::TeamThreadRange(team_h, num_i), + [&](int i, float& lsum) { + lsum += inputs(i) * matrix(i, j); + }, + sum); // end parallel reduce + + outputs(j) = sum; + }); // end parallel for + + FOR_ALL(j, 0, num_j, { + if (fabs(outputs(j) - num_i) >= 1e-15) { + printf("error in vec mat multiply test \n"); + } }); - - return; -}; // end function + return; -KOKKOS_INLINE_FUNCTION -float sigmoid(const float value){ - return 1.0/(1.0 + exp(-value)); // exp2f doesn't work with CUDA -}; // end function +}; // end function +KOKKOS_INLINE_FUNCTION float sigmoid(const float value) { + return 1.0 / (1.0 + exp(-value)); // exp2f doesn't work with CUDA +}; // end function -KOKKOS_INLINE_FUNCTION -float sigmoid_derivative(const float value){ +KOKKOS_INLINE_FUNCTION float sigmoid_derivative(const float value) { float sigval = sigmoid(value); - return sigval*(1.0 - sigval); // exp2f doesn't work with CUDA -}; // end function - - - + return sigval * (1.0 - sigval); // exp2f doesn't work with CUDA +}; // end function -void forward_propagate_layer(DCArrayKokkos &inputs, - DCArrayKokkos &outputs, - DFArrayKokkos &weights, - const DCArrayKokkos &biases){ - +void forward_propagate_layer(DCArrayKokkos& inputs, DCArrayKokkos& outputs, DFArrayKokkos& weights, + const DCArrayKokkos& biases) { const size_t num_i = inputs.size(); const size_t num_j = outputs.size(); - /* FOR_ALL(j, 0, num_j,{ - //printf("thread = %d \n", omp_get_thread_num()); + //printf("thread = %d \n", omp_get_thread_num()); float value = 0.0; for(int i=0; i &inputs, }); // end parallel for */ - // For a GPU, use the nested parallelism below here - - using team_t = typename Kokkos::TeamPolicy<>::member_type; - Kokkos::parallel_for ("MatVec", Kokkos::TeamPolicy<> (num_j, Kokkos::AUTO), - KOKKOS_LAMBDA (const team_t& team_h) { - - float sum = 0; - int j = team_h.league_rank(); - Kokkos::parallel_reduce (Kokkos::TeamThreadRange (team_h, num_i), - [&] (int i, float& lsum) { - lsum += inputs(i)*weights(i,j) + biases(j); - }, sum); // end parallel reduce - - outputs(j) = 1.0/(1.0 + exp(-sum)); - - }); // end parallel for - + using team_t = typename Kokkos::TeamPolicy<>::member_type; + Kokkos::parallel_for( + "MatVec", + Kokkos::TeamPolicy<>(num_j, Kokkos::AUTO), + KOKKOS_LAMBDA(const team_t& team_h) { + float sum = 0; + int j = team_h.league_rank(); + Kokkos::parallel_reduce( + Kokkos::TeamThreadRange(team_h, num_i), + [&](int i, float& lsum) { + lsum += inputs(i) * weights(i, j) + biases(j); + }, + sum); // end parallel reduce + + outputs(j) = 1.0 / (1.0 + exp(-sum)); + }); // end parallel for return; -}; // end function - +}; // end function -void set_biases(const DCArrayKokkos &biases){ +void set_biases(const DCArrayKokkos& biases) { const size_t num_j = biases.size(); - FOR_ALL(j,0,num_j, { - biases(j) = 0.0; - }); // end parallel for - -}; // end function - + FOR_ALL(j, 0, num_j, { + biases(j) = 0.0; + }); // end parallel for -void set_weights(const DFArrayKokkos &weights){ +}; // end function +void set_weights(const DFArrayKokkos& weights) { const size_t num_i = weights.dims(0); const size_t num_j = weights.dims(1); - - FOR_ALL(i,0,num_i, - j,0,num_j, { - - weights(i,j) = 1.0; - }); // end parallel for -}; // end function + FOR_ALL(i, 0, num_i, + j, 0, num_j, { + weights(i, j) = 1.0; + }); // end parallel for +}; // end function // ================================================================= // // Main function // // ================================================================= -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { Kokkos::initialize(argc, argv); { - // ================================================================= // allocate arrays // ================================================================= // note: the num_nodes_in_layer has the inputs into the ANN, so subtract 1 for the layers - size_t num_layers = num_nodes_in_layer.size()-1; + size_t num_layers = num_nodes_in_layer.size() - 1; - CMatrix ANNLayers(num_layers); // starts at 1 and goes to num_layers + CMatrix ANNLayers(num_layers); // starts at 1 and goes to num_layers // input and ouput values to ANN - DCArrayKokkos inputs(num_nodes_in_layer[0]); - + DCArrayKokkos inputs(num_nodes_in_layer[0]); // set the strides // layer 0 are the inputs to the ANN // layer n-1 are the outputs from the ANN - for (size_t layer=1; layer<=num_layers; layer++){ - + for (size_t layer = 1; layer <= num_layers; layer++) { // dimensions - size_t num_i = num_nodes_in_layer[layer-1]; + size_t num_i = num_nodes_in_layer[layer - 1]; size_t num_j = num_nodes_in_layer[layer]; // allocate the weights in this layer - ANNLayers(layer).weights = DFArrayKokkos (num_i, num_j); - ANNLayers(layer).outputs = DCArrayKokkos (num_j); - ANNLayers(layer).biases = DCArrayKokkos (num_j); - - } // end for + ANNLayers(layer).weights = DFArrayKokkos(num_i, num_j); + ANNLayers(layer).outputs = DCArrayKokkos(num_j); + ANNLayers(layer).biases = DCArrayKokkos(num_j); + } // end for // ================================================================= // set weights, biases, and inputs // ================================================================= - + // inputs to ANN - for (size_t i=0; i