Skip to content

Commit

Permalink
Merge pull request #2366 from DARMA-tasking/2365-add-aliases-for-grea…
Browse files Browse the repository at this point in the history
…ter-than-3-dimensions-and-write-example

#2365: index: add aliases for greater than 3 dimensions and write exa…
  • Loading branch information
nlslatt authored Oct 17, 2024
2 parents c519afc + 7318517 commit cced7f8
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
75 changes: 75 additions & 0 deletions examples/collection/4d_collection.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
//@HEADER
// *****************************************************************************
//
// 4d_collection.cc
// DARMA/vt => Virtual Transport
//
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * 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.
//
// * 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 OWNER 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.
//
// Questions? Contact [email protected]
//
// *****************************************************************************
//@HEADER
*/

#include <vt/transport.h>

struct Example4D : vt::Collection<Example4D, vt::Index4D> {

Example4D() = default;

void hello() {
fmt::print(
"{}: Hello from Example4D: {}\n", vt::theContext()->getNode(), getIndex()
);
}

};

int main(int argc, char** argv) {
vt::initialize(argc, argv);

auto range = vt::Index4D(2,4,3,2);

auto proxy = vt::makeCollection<Example4D>("4d_collection")
.bounds(range)
.bulkInsert()
.wait();

if (vt::theContext()->getNode() == 0) {
proxy.broadcast<&Example4D::hello>();
}


vt::finalize();
return 0;
}
1 change: 1 addition & 0 deletions examples/collection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(
insertable_collection
reduce_integral
transpose
4d_collection
)

foreach(EXAMPLE_NAME ${COLLECTION_EXAMPLES})
Expand Down
17 changes: 16 additions & 1 deletion src/vt/topos/index/dense/dense_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
DenseIndexArrayType operator+(DenseIndexArrayType const& other) const;
DenseIndexArrayType operator-(DenseIndexArrayType const& other) const;

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

template <
typename T = void, typename = typename std::enable_if<ndim >= 4, T>::type
>
IndexType u() const;

template <
typename T = void, typename = typename std::enable_if<ndim >= 5, T>::type
>
IndexType v() const;

template <
typename T = void, typename = typename std::enable_if<ndim >= 6, T>::type
>
IndexType w() const;

template <typename IndexT, NumDimensionsType nd>
friend std::ostream& operator<<(
std::ostream& os, DenseIndexArray<IndexT,nd> const& idx
Expand Down
20 changes: 19 additions & 1 deletion src/vt/topos/index/dense/dense_array.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ DenseIndexArray<IndexType, ndim>::operator-(DenseIndexArrayType const& other) co
return val;
}

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

template <typename IndexType, NumDimensionsType ndim>
template <typename T, typename>
IndexType DenseIndexArray<IndexType, ndim>::u() const {
return dims[3];
}

template <typename IndexType, NumDimensionsType ndim>
template <typename T, typename>
IndexType DenseIndexArray<IndexType, ndim>::v() const {
return dims[4];
}

template <typename IndexType, NumDimensionsType ndim>
template <typename T, typename>
IndexType DenseIndexArray<IndexType, ndim>::w() const {
return dims[5];
}

template <typename IndexT, NumDimensionsType nd>
std::ostream& operator<<(
std::ostream& os, ::vt::index::DenseIndexArray<IndexT,nd> const& idx
Expand Down
12 changes: 12 additions & 0 deletions src/vt/topos/index/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ using IdxBase = int32_t;
template <typename T = IdxBase> using Index1D = DenseIndexArray<T, 1>;
template <typename T = IdxBase> using Index2D = DenseIndexArray<T, 2>;
template <typename T = IdxBase> using Index3D = DenseIndexArray<T, 3>;
template <typename T = IdxBase> using Index4D = DenseIndexArray<T, 4>;
template <typename T = IdxBase> using Index5D = DenseIndexArray<T, 5>;
template <typename T = IdxBase> using Index6D = DenseIndexArray<T, 6>;
template <typename T, int8_t N> using IdxType = DenseIndexArray<T, N>;

static_assert(IndexTraits<Index1D<IdxBase>>::is_index, "Does not conform");
static_assert(IndexTraits<Index2D<IdxBase>>::is_index, "Does not conform");
static_assert(IndexTraits<Index3D<IdxBase>>::is_index, "Does not conform");
static_assert(IndexTraits<Index4D<IdxBase>>::is_index, "Does not conform");
static_assert(IndexTraits<Index5D<IdxBase>>::is_index, "Does not conform");
static_assert(IndexTraits<Index6D<IdxBase>>::is_index, "Does not conform");

}} // end namespace vt::index

Expand All @@ -76,13 +82,19 @@ using IdxBase = index::IdxBase;
using Index1D = index::Index1D<index::IdxBase>;
using Index2D = index::Index2D<index::IdxBase>;
using Index3D = index::Index3D<index::IdxBase>;
using Index4D = index::Index4D<index::IdxBase>;
using Index5D = index::Index5D<index::IdxBase>;
using Index6D = index::Index6D<index::IdxBase>;
template <int8_t N>
using IndexND = index::IdxType<index::IdxBase, N>;

template <typename T, int8_t N> using IdxType = index::IdxType<T, N>;
template <typename T> using IdxType1D = index::Index1D<T>;
template <typename T> using IdxType2D = index::Index2D<T>;
template <typename T> using IdxType3D = index::Index3D<T>;
template <typename T> using IdxType4D = index::Index4D<T>;
template <typename T> using IdxType5D = index::Index5D<T>;
template <typename T> using IdxType6D = index::Index6D<T>;

} // end namespace vt

Expand Down

0 comments on commit cced7f8

Please sign in to comment.