Skip to content

Commit cced7f8

Browse files
authored
Merge pull request #2366 from DARMA-tasking/2365-add-aliases-for-greater-than-3-dimensions-and-write-example
#2365: index: add aliases for greater than 3 dimensions and write exa…
2 parents c519afc + 7318517 commit cced7f8

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

examples/collection/4d_collection.cc

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
//@HEADER
3+
// *****************************************************************************
4+
//
5+
// 4d_collection.cc
6+
// DARMA/vt => Virtual Transport
7+
//
8+
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9+
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10+
// Government retains certain rights in this software.
11+
//
12+
// Redistribution and use in source and binary forms, with or without
13+
// modification, are permitted provided that the following conditions are met:
14+
//
15+
// * Redistributions of source code must retain the above copyright notice,
16+
// this list of conditions and the following disclaimer.
17+
//
18+
// * Redistributions in binary form must reproduce the above copyright notice,
19+
// this list of conditions and the following disclaimer in the documentation
20+
// and/or other materials provided with the distribution.
21+
//
22+
// * Neither the name of the copyright holder nor the names of its
23+
// contributors may be used to endorse or promote products derived from this
24+
// software without specific prior written permission.
25+
//
26+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
// POSSIBILITY OF SUCH DAMAGE.
37+
//
38+
// Questions? Contact darma@sandia.gov
39+
//
40+
// *****************************************************************************
41+
//@HEADER
42+
*/
43+
44+
#include <vt/transport.h>
45+
46+
struct Example4D : vt::Collection<Example4D, vt::Index4D> {
47+
48+
Example4D() = default;
49+
50+
void hello() {
51+
fmt::print(
52+
"{}: Hello from Example4D: {}\n", vt::theContext()->getNode(), getIndex()
53+
);
54+
}
55+
56+
};
57+
58+
int main(int argc, char** argv) {
59+
vt::initialize(argc, argv);
60+
61+
auto range = vt::Index4D(2,4,3,2);
62+
63+
auto proxy = vt::makeCollection<Example4D>("4d_collection")
64+
.bounds(range)
65+
.bulkInsert()
66+
.wait();
67+
68+
if (vt::theContext()->getNode() == 0) {
69+
proxy.broadcast<&Example4D::hello>();
70+
}
71+
72+
73+
vt::finalize();
74+
return 0;
75+
}

examples/collection/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(
1010
insertable_collection
1111
reduce_integral
1212
transpose
13+
4d_collection
1314
)
1415

1516
foreach(EXAMPLE_NAME ${COLLECTION_EXAMPLES})

src/vt/topos/index/dense/dense_array.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
125125
DenseIndexArrayType operator+(DenseIndexArrayType const& other) const;
126126
DenseIndexArrayType operator-(DenseIndexArrayType const& other) const;
127127

128-
// special accessors (x,y,z) enabled depending on the number of dimensions
128+
// special accessors (x,y,z,u,v,w) enabled depending on the number of dimensions
129129
template <
130130
typename T = void, typename = typename std::enable_if<ndim >= 1, T>::type
131131
>
@@ -141,6 +141,21 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
141141
>
142142
IndexType z() const;
143143

144+
template <
145+
typename T = void, typename = typename std::enable_if<ndim >= 4, T>::type
146+
>
147+
IndexType u() const;
148+
149+
template <
150+
typename T = void, typename = typename std::enable_if<ndim >= 5, T>::type
151+
>
152+
IndexType v() const;
153+
154+
template <
155+
typename T = void, typename = typename std::enable_if<ndim >= 6, T>::type
156+
>
157+
IndexType w() const;
158+
144159
template <typename IndexT, NumDimensionsType nd>
145160
friend std::ostream& operator<<(
146161
std::ostream& os, DenseIndexArray<IndexT,nd> const& idx

src/vt/topos/index/dense/dense_array.impl.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ DenseIndexArray<IndexType, ndim>::operator-(DenseIndexArrayType const& other) co
231231
return val;
232232
}
233233

234-
// special accessors (x,y,z) enabled depending on the number of dimensions
234+
// special accessors (x,y,z,u,v,w) enabled depending on the number of dimensions
235235
template <typename IndexType, NumDimensionsType ndim>
236236
template <typename T, typename>
237237
IndexType DenseIndexArray<IndexType, ndim>::x() const {
@@ -250,6 +250,24 @@ IndexType DenseIndexArray<IndexType, ndim>::z() const {
250250
return dims[2];
251251
}
252252

253+
template <typename IndexType, NumDimensionsType ndim>
254+
template <typename T, typename>
255+
IndexType DenseIndexArray<IndexType, ndim>::u() const {
256+
return dims[3];
257+
}
258+
259+
template <typename IndexType, NumDimensionsType ndim>
260+
template <typename T, typename>
261+
IndexType DenseIndexArray<IndexType, ndim>::v() const {
262+
return dims[4];
263+
}
264+
265+
template <typename IndexType, NumDimensionsType ndim>
266+
template <typename T, typename>
267+
IndexType DenseIndexArray<IndexType, ndim>::w() const {
268+
return dims[5];
269+
}
270+
253271
template <typename IndexT, NumDimensionsType nd>
254272
std::ostream& operator<<(
255273
std::ostream& os, ::vt::index::DenseIndexArray<IndexT,nd> const& idx

src/vt/topos/index/index.h

+12
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,17 @@ using IdxBase = int32_t;
5959
template <typename T = IdxBase> using Index1D = DenseIndexArray<T, 1>;
6060
template <typename T = IdxBase> using Index2D = DenseIndexArray<T, 2>;
6161
template <typename T = IdxBase> using Index3D = DenseIndexArray<T, 3>;
62+
template <typename T = IdxBase> using Index4D = DenseIndexArray<T, 4>;
63+
template <typename T = IdxBase> using Index5D = DenseIndexArray<T, 5>;
64+
template <typename T = IdxBase> using Index6D = DenseIndexArray<T, 6>;
6265
template <typename T, int8_t N> using IdxType = DenseIndexArray<T, N>;
6366

6467
static_assert(IndexTraits<Index1D<IdxBase>>::is_index, "Does not conform");
6568
static_assert(IndexTraits<Index2D<IdxBase>>::is_index, "Does not conform");
6669
static_assert(IndexTraits<Index3D<IdxBase>>::is_index, "Does not conform");
70+
static_assert(IndexTraits<Index4D<IdxBase>>::is_index, "Does not conform");
71+
static_assert(IndexTraits<Index5D<IdxBase>>::is_index, "Does not conform");
72+
static_assert(IndexTraits<Index6D<IdxBase>>::is_index, "Does not conform");
6773

6874
}} // end namespace vt::index
6975

@@ -76,13 +82,19 @@ using IdxBase = index::IdxBase;
7682
using Index1D = index::Index1D<index::IdxBase>;
7783
using Index2D = index::Index2D<index::IdxBase>;
7884
using Index3D = index::Index3D<index::IdxBase>;
85+
using Index4D = index::Index4D<index::IdxBase>;
86+
using Index5D = index::Index5D<index::IdxBase>;
87+
using Index6D = index::Index6D<index::IdxBase>;
7988
template <int8_t N>
8089
using IndexND = index::IdxType<index::IdxBase, N>;
8190

8291
template <typename T, int8_t N> using IdxType = index::IdxType<T, N>;
8392
template <typename T> using IdxType1D = index::Index1D<T>;
8493
template <typename T> using IdxType2D = index::Index2D<T>;
8594
template <typename T> using IdxType3D = index::Index3D<T>;
95+
template <typename T> using IdxType4D = index::Index4D<T>;
96+
template <typename T> using IdxType5D = index::Index5D<T>;
97+
template <typename T> using IdxType6D = index::Index6D<T>;
8698

8799
} // end namespace vt
88100

0 commit comments

Comments
 (0)