ArrayIndex.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <charm++.h>
7 #include <type_traits>
8 
9 namespace Parallel {
10 /*!
11  * \ingroup ParallelGroup
12  * \brief The array index used for indexing Chare Arrays, mostly an
13  * implementation detail
14  *
15  * The implementation is generic and can handle custom array indices. This
16  * replaces the generated, hard-coded Charm++ array indices with a template,
17  * allowing a single implementation to be used for different array indices.
18  */
19 template <class Index>
20 struct ArrayIndex : public CkArrayIndex {
21  static_assert(std::is_pod<Index>::value,
22  "The array index type must be a POD, plain-old-data");
23  // clang-tidy: suspicious use of sizeof
24  static_assert(sizeof(Index) / sizeof(int) <= 3, // NOLINT
25  "The default Charm++ CK_ARRAYINDEX_MAXLEN is 3. If you have "
26  "changed this at Charm++ configuration time then please update "
27  "the static_assert, otherwise your Index type is too large.");
28  // clang-tidy: suspicious use of sizeof
29  static_assert(sizeof(Index) % sizeof(int) == 0, // NOLINT
30  "The Charm++ array Index type must be exactly a multiple of "
31  "the size of an integer, but the user-provided one is not.");
32  static_assert(
33  alignof(Index) == alignof(decltype(index)),
34  "Incorrect alignment of Charm++ array Index type. The "
35  "alignment must match the alignment of the internal Charm++ type");
36 
37  // Use placement new to ensure that the custom index object is placed in the
38  // memory reserved for it in the base class
39  // clang-tidy: mark explicit: it's a conversion constructor
40  ArrayIndex(const Index& array_index) // NOLINT
41  // clang-tidy: do not use unions
42  : array_index_(new (index) Index(array_index)) { // NOLINT
43  // clang-tidy: suspicious use of sizeof
44  nInts = sizeof(array_index) / sizeof(int); // NOLINT
45  }
46 
47  ArrayIndex(const ArrayIndex& rhs) = delete;
48  ArrayIndex& operator=(const ArrayIndex& rhs) = delete;
49 
50  ArrayIndex(ArrayIndex&& /*rhs*/) noexcept = delete;
51  ArrayIndex& operator=(ArrayIndex&& /*rhs*/) noexcept = delete;
52  ~ArrayIndex() = default;
53 
54  private:
55  Index* array_index_ = nullptr;
56 };
57 
64 } // namespace Parallel
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
An integer multi-index.
Definition: Index.hpp:28
The array index used for indexing Chare Arrays, mostly an implementation detail.
Definition: ArrayIndex.hpp:20