1 #ifndef DASH__DIMENSIONAL_H_ 2 #define DASH__DIMENSIONAL_H_ 4 #include <dash/Types.h> 5 #include <dash/Distribution.h> 7 #include <dash/Exception.h> 55 template <
typename DimensionalType>
63 template <
typename DimensionalType>
71 template <dim_t Dim,
typename DimensionalType>
72 constexpr
typename DimensionalType::extent_type
80 template <
typename DimensionalType>
81 constexpr
typename DimensionalType::extent_type
100 template <
typename ElementType, dim_t NumDimensions>
103 template <
typename E_, dim_t ND_>
104 friend std::ostream & operator<<(
112 std::array<ElementType, NumDimensions> _values;
118 template <
typename ... Values>
120 ElementType & value, Values ...
values)
121 : _values {{ value, (ElementType)values... }} {
123 sizeof...(
values) == NumDimensions-1,
124 "Invalid number of arguments");
131 : _values(
std::move(values))
135 constexpr
Dimensional(
const self_t & other) =
default;
136 self_t & operator=(
const self_t & other) =
default;
142 constexpr
const std::array<ElementType, NumDimensions> &
values()
const {
154 dimension, NumDimensions,
155 "Dimension for Dimensional::extent() must be lower than " <<
157 return _values[dimension];
168 return _values[dimension];
180 return _values[dimension];
187 return this == &other || _values == other._values;
194 return !(*
this == other);
201 return NumDimensions;
208 return NumDimensions;
221 template <dim_t NumDimensions>
224 template<dim_t NumDimensions_>
226 std::ostream & operator<<(
240 this->_values[0] = BLOCKED;
241 for (
dim_t i = 1; i < NumDimensions; ++i) {
242 this->_values[i] = NONE;
257 template <
typename... Values>
261 for (
dim_t i = 1; i < NumDimensions; ++i) {
262 if (this->_values[i].type == dash::internal::DIST_TILE) {
283 DASH_LOG_TRACE_VAR(
"DistributionSpec(distribution[])", values);
284 for (
dim_t i = 1; i < NumDimensions; ++i) {
285 if (this->_values[i].type == dash::internal::DIST_TILE) {
296 unsigned int dimension)
const {
298 this->_values[dimension].type == dash::internal::DIST_TILE);
309 bool _is_tiled{
false};
312 template<dim_t NumDimensions>
313 std::ostream & operator<<(
317 os <<
"dash::DistributionSpec<" << NumDimensions <<
">(";
318 for (
dim_t d = 0; d < NumDimensions; d++) {
319 if (distspec._values[d].type == dash::internal::DIST_TILE) {
320 os <<
"TILE(" << distspec._values[d].blocksz <<
")";
322 else if (distspec._values[d].type == dash::internal::DIST_BLOCKCYCLIC) {
323 os <<
"BLOCKCYCLIC(" << distspec._values[d].blocksz <<
")";
325 else if (distspec._values[d].type == dash::internal::DIST_CYCLIC) {
328 else if (distspec._values[d].type == dash::internal::DIST_BLOCKED) {
331 else if (distspec._values[d].type == dash::internal::DIST_NONE) {
334 if (d < NumDimensions-1) {
345 template<
typename IndexType =
int>
347 typedef typename std::make_unsigned<IndexType>::type SizeType;
363 std::array<IndexType, NumDimensions>
begin;
365 std::array<IndexType, NumDimensions>
end;
377 template<
typename IndexType>
378 std::ostream & operator<<(
381 os <<
"dash::ViewRange<" <<
typeid(IndexType).name() <<
">(" 382 <<
"begin:" << viewrange.begin <<
" " 383 <<
"end:" << viewrange.end <<
")";
390 template<
typename IndexType>
405 template<
typename IndexType>
409 return !(lhs == rhs);
412 template<
typename IndexType>
413 std::ostream & operator<<(
416 os <<
"dash::ViewPair<" <<
typeid(IndexType).name() <<
">(" 417 <<
"offset:" << viewpair.
offset <<
" " 418 <<
"extent:" << viewpair.
extent <<
")";
435 typedef typename std::make_unsigned<IndexType>::type
444 using index_type = IndexType;
445 using size_type = SizeType;
448 template<dim_t NDim_,
typename IndexType_>
449 friend std::ostream& operator<<(
455 SizeType _rank = NumDimensions;
456 std::array<SizeType, NumDimensions> _extents = {{ }};
457 std::array<IndexType, NumDimensions> _offsets = {{ }};
468 for (
dim_t i = 0; i < NumDimensions; i++) {
479 const std::array<SizeType, NumDimensions> & extents)
481 _rank(NumDimensions),
484 for (
auto i = 0; i < NumDimensions; ++i) {
486 _size *= _extents[i];
494 const std::array<IndexType, NumDimensions> & offsets,
495 const std::array<SizeType, NumDimensions> & extents)
497 _rank(NumDimensions),
501 for (
auto i = 0; i < NumDimensions; ++i) {
502 _size *= _extents[i];
509 constexpr
ViewSpec(
const self_t & other) =
default;
514 constexpr
ViewSpec(self_t && other) =
default;
519 self_t & operator=(
const self_t & other) =
default;
524 self_t & operator=(self_t && other) =
default;
526 static constexpr
auto ndim() {
return NumDimensions; }
533 return (_extents == other._extents &&
534 _offsets == other._offsets &&
535 _rank == other._rank);
543 return !(*
this == other);
549 template<
typename ... Args>
553 sizeof...(Args) == (NumDimensions-1),
554 "Invalid number of arguments");
555 std::array<SizeType, NumDimensions> extents =
556 { arg, (SizeType)(args)... };
563 void resize(
const std::array<ViewPair_t, NumDimensions> & view)
565 _rank = NumDimensions;
566 for (
dim_t i = 0; i < NumDimensions; i++) {
567 _offsets[i] = view[i].offset;
568 _extents[i] = view[i].extent;
576 template<
typename SizeType_>
577 void resize(
const std::array<SizeType_, NumDimensions> & extents)
579 _rank = NumDimensions;
580 for (
dim_t i = 0; i < NumDimensions; i++) {
581 _extents[i] = extents[i];
595 _offsets[dimension] = offset;
596 _extents[dimension] =
extent;
626 ViewSpec<NumDimensions-1, IndexType>
629 std::array<SizeType, NumDimensions-1> slice_extents;
630 std::array<IndexType, NumDimensions-1> slice_offsets;
631 for (
dim_t d = dimension; d < _rank-1; d++) {
632 slice_offsets[d] = _offsets[d+1];
633 slice_extents[d] = _extents[d+1];
635 return ViewSpec<NumDimensions-1, IndexType>(slice_offsets,
646 dimensions, NumDimensions+1,
647 "Maximum dimension for ViewSpec::set_rank is " << NumDimensions);
652 constexpr SizeType
size()
const 657 constexpr SizeType
size(
dim_t dimension)
const 659 return _extents[dimension];
662 constexpr
const std::array<SizeType, NumDimensions> & extents()
const 668 return _extents[
dim];
671 constexpr
const std::array<IndexType, NumDimensions> & offsets()
const 676 constexpr range_type range(
dim_t dim)
const 679 static_cast<IndexType
>(_offsets[
dim]),
680 static_cast<IndexType>(_offsets[dim] + _extents[dim]) };
683 constexpr IndexType offset(
dim_t dim)
const 685 return _offsets[
dim];
688 region_type region()
const 691 reg.begin = _offsets;
693 for (
dim_t d = 0; d < NumDimensions; ++d) {
694 reg.end[d] +=
static_cast<IndexType
>(_extents[d]);
703 for (SizeType d = 0; d < NumDimensions; ++d) {
704 _size *= _extents[d];
709 template<
typename ElementType, dim_t NumDimensions>
710 std::ostream & operator<<(
714 std::ostringstream ss;
715 ss <<
"dash::Dimensional<" 716 <<
typeid(ElementType).name() <<
"," 717 << NumDimensions <<
">(";
718 for (
auto d = 0; d < NumDimensions; ++d) {
719 ss << dimensional._values[d] << ((d < NumDimensions-1) ?
"," :
"");
722 return operator<<(os, ss.str());
725 template<dim_t NumDimensions,
typename IndexType>
726 std::ostream& operator<<(
730 std::ostringstream ss;
731 ss <<
"dash::ViewSpec<" << NumDimensions <<
">" 733 for (
auto d = 0; d < NumDimensions; ++d) {
737 ss << viewspec.offsets()[d];
740 for (
auto d = 0; d < NumDimensions; ++d) {
744 ss << viewspec.extents()[d];
747 return operator<<(os, ss.str());
752 #endif // DASH__DIMENSIONAL_H_ void resize_dim(dim_t dimension, IndexType offset, SizeType extent)
Change the view specification's extent and offset in the given dimension.
void resize(const std::array< ViewPair_t, NumDimensions > &view)
Change the view specification's extent and offset in every dimension.
constexpr dim_t rank(const DimensionalType &d)
ViewSpec()
Default constructor, initialize with extent and offset 0 in all dimensions.
IndexType offset
Offset in dimension.
constexpr const std::array< ElementType, NumDimensions > & values() const
Return value with all dimensions as array of NumDimensions elements.
Representation of a ViewPair as region specified by origin and end coordinates.
DistributionSpec()
Default constructor, initializes default blocked distribution (BLOCKED, NONE*).
size_t size()
Return the number of units in the global team.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
constexpr dim_t rank() const
The number of dimensions of the value.
ElementType & operator[](size_t dimension)
Subscript assignment operator, access to value in dimension given by index.
static constexpr dim_t ndim()
The number of dimensions of the value.
DistributionSpec(const std::array< Distribution, NumDimensions > &values)
Constructor, initializes distribution with given distribution types for every dimension.
bool is_tiled() const
Whether the distribution is tiled in any dimension.
Specifies view parameters for implementing submat, rows and cols.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
bool is_tiled_in_dimension(unsigned int dimension) const
Whether the distribution in the given dimension is tiled.
constexpr Dimensional(std::array< ElementType, NumDimensions > values)
Constructor, expects array containing values for every dimension.
SizeType extent
Extent in dimension.
constexpr bool operator!=(const self_t &other) const
Equality comparison operator.
ViewSpec(const std::array< IndexType, NumDimensions > &offsets, const std::array< SizeType, NumDimensions > &extents)
Constructor, initialize with given extents and offsets.
ViewSpec(const std::array< SizeType, NumDimensions > &extents)
Constructor, initialize with given extents and offset 0 in all dimensions.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
void resize(SizeType arg, Args... args)
Change the view specification's extent in every dimension.
ElementType dim(dim_t dimension) const
The value in the given dimension.
Base class for dimensional attributes, stores an n-dimensional value with identical type all dimensio...
constexpr dim_t ndim(const DimensionalType &d)
Specifies how a Pattern distributes elements to units in a specific dimension.
constexpr ElementType operator[](size_t dimension) const
Subscript operator, access to value in dimension given by index.
ViewSpec< NumDimensions-1, IndexType > slice(dim_t dimension)
Slice the view in the specified dimension at the given offset.
void set_rank(dim_t dimensions)
Set rank of the view spec to a dimensionality between 1 and NumDimensions.
constexpr bool operator==(const self_t &other) const
Equality comparison operator.
DistributionSpec(Distribution value, Values... values)
Constructor, initializes distribution with given distribution types for every dimension.
void resize(const std::array< SizeType_, NumDimensions > &extents)
Change the view specification's extent in every dimension.
constexpr bool operator!=(const self_t &other) const
Equality comparison operator.
constexpr Dimensional(ElementType &value, Values ... values)
Constructor, expects one value for every dimension.
Offset and extent in a single dimension.
constexpr DimensionalType::extent_type extent(const DimensionalType &d)
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
constexpr bool operator==(const self_t &other) const
Equality comparison operator.
DistributionSpec describes distribution patterns of all dimensions,.