MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
Array.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <Kokkos_Core.hpp>
16
17namespace mrmd::data
18{
19template <class ScalarType, int N>
20struct ArrayT
21{
22 ScalarType data_[N];
23
24 KOKKOS_INLINE_FUNCTION
25 ArrayT() { init(); }
26
27 KOKKOS_INLINE_FUNCTION
28 ArrayT(const ArrayT& rhs)
29 {
30 for (int i = 0; i < N; i++)
31 {
32 data_[i] = rhs.data_[i];
33 }
34 }
35
36 KOKKOS_INLINE_FUNCTION
37 void init()
38 {
39 for (int i = 0; i < N; i++)
40 {
41 data_[i] = 0;
42 }
43 }
44
45 KOKKOS_INLINE_FUNCTION
47 {
48 for (int i = 0; i < N; i++)
49 {
50 data_[i] += src.data_[i];
51 }
52 return *this;
53 }
54
55 KOKKOS_INLINE_FUNCTION
56 void operator+=(const ArrayT& src)
57 {
58 for (int i = 0; i < N; i++)
59 {
60 data_[i] += src.data_[i];
61 }
62 }
63
64 KOKKOS_INLINE_FUNCTION
65 ScalarType operator[](idx_t idx) const { return data_[idx]; }
66};
67} // namespace mrmd::data
68
69namespace Kokkos
70{ // reduction identity must be defined in Kokkos namespace
71template <class ScalarType, int N>
72struct reduction_identity<mrmd::data::ArrayT<ScalarType, N>>
73{
74 KOKKOS_FORCEINLINE_FUNCTION static mrmd::data::ArrayT<ScalarType, N> sum()
75 {
77 }
78};
79} // namespace Kokkos
Definition SPC.hpp:46
Definition Array.hpp:18
Definition BerendsenBarostat.cpp:18
int64_t idx_t
Definition datatypes.hpp:91
static KOKKOS_FORCEINLINE_FUNCTION mrmd::data::ArrayT< ScalarType, N > sum()
Definition Array.hpp:74
Definition Array.hpp:21
KOKKOS_INLINE_FUNCTION void init()
Definition Array.hpp:37
KOKKOS_INLINE_FUNCTION ArrayT & operator+=(const ArrayT &src)
Definition Array.hpp:46
KOKKOS_INLINE_FUNCTION ArrayT()
Definition Array.hpp:25
KOKKOS_INLINE_FUNCTION ArrayT(const ArrayT &rhs)
Definition Array.hpp:28
KOKKOS_INLINE_FUNCTION ScalarType operator[](idx_t idx) const
Definition Array.hpp:65
KOKKOS_INLINE_FUNCTION void operator+=(const ArrayT &src)
Definition Array.hpp:56
ScalarType data_[N]
Definition Array.hpp:22