1 #ifndef DASH__MATRIX_H_INCLUDED 2 #define DASH__MATRIX_H_INCLUDED 7 #include <dash/Pattern.h> 8 #include <dash/GlobRef.h> 9 #include <dash/HView.h> 10 #include <dash/Meta.h> 12 #include <dash/iterator/GlobIter.h> 14 #include <dash/matrix/MatrixRefView.h> 15 #include <dash/matrix/MatrixRef.h> 16 #include <dash/matrix/LocalMatrixRef.h> 18 #include <dash/memory/MemorySpace.h> 19 #include <dash/memory/UniquePtr.h> 21 #include <type_traits> 100 typename LocalMemSpaceT>
108 typename LocalMemSpaceT>
116 typename LocalMemSpaceT>
117 class LocalMatrixRef;
139 class PatternT = TilePattern<NumDimensions, ROW_MAJOR, IndexT>,
140 typename LocalMemSpaceT = HostSpace>
145 "Type not supported for DASH containers");
147 static_assert(std::is_same<IndexT, typename PatternT::index_type>::value,
148 "Index type IndexT must be the same for Matrix and specified pattern");
151 typedef Matrix<ElementT, NumDimensions, IndexT, PatternT, LocalMemSpaceT>
153 typedef typename std::make_unsigned<IndexT>::type
155 typedef MatrixRefView<ElementT, NumDimensions, PatternT, LocalMemSpaceT>
157 typedef LocalMatrixRef<ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT>
159 typedef LocalMatrixRef<
160 const ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT>
166 typedef GlobStaticMem<LocalMemSpaceT>
171 dim_t NumDimensions1,
172 dim_t NumDimensions2,
175 friend class MatrixRef;
178 dim_t NumDimensions1,
179 dim_t NumDimensions2,
182 friend class LocalMatrixRef;
186 typedef ElementT value_type;
187 typedef typename PatternT::size_type size_type;
188 typedef typename PatternT::index_type difference_type;
189 typedef typename PatternT::index_type index_type;
191 typedef GlobIter< value_type, Pattern_t, GlobMem_t> iterator;
192 typedef GlobIter<const value_type, Pattern_t, GlobMem_t> const_iterator;
194 typedef std::reverse_iterator<iterator> reverse_iterator;
195 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
197 typedef GlobRef<value_type> reference;
198 typedef typename GlobRef<value_type>::const_type const_reference;
201 typedef typename iterator::pointer pointer;
202 typedef typename pointer::const_type const_pointer;
204 typedef ElementT * local_pointer;
205 typedef const ElementT * const_local_pointer;
207 typedef DistributionSpec<NumDimensions> distribution_spec;
208 typedef SizeSpec<NumDimensions, typename PatternT::size_type>
210 typedef TeamSpec<NumDimensions, typename PatternT::index_type>
212 typedef std::array<typename PatternT::size_type, NumDimensions>
214 typedef std::array<typename PatternT::index_type, NumDimensions>
221 typedef LocalMatrixRef<
222 ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT>
227 const ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT>
236 template <dim_t NumViewDim>
242 template <dim_t NumViewDim>
255 typedef std::integral_constant<dim_t, NumDimensions>
rank;
258 return NumDimensions;
263 using unique_gptr_t = decltype(dash::allocate_unique<value_type>(
275 size_type _lcapacity;
281 GlobMem_t _glob_mem{};
285 unique_gptr_t _data{};
309 const size_spec & ss,
310 const distribution_spec & ds = distribution_spec(),
312 const team_spec & ts = team_spec());
319 const PatternT & pat);
325 template<
typename... Args>
327 :
Matrix(PatternT(arg,
std::forward<Args>(args)...))
333 Matrix(
const self_t &) =
delete;
348 self_t &
operator=(
const self_t & other) =
delete;
359 const std::array<index_type, NumDimensions> & block_gcoords);
365 index_type block_gindex);
374 const size_spec & sizespec,
375 const distribution_spec & distribution,
376 const team_spec & teamspec,
393 template<
typename... Args>
397 return allocate(PatternT(arg, args... ));
408 constexpr
Team & team()
const noexcept;
410 constexpr size_type
size()
const noexcept;
411 constexpr size_type local_size()
const noexcept;
412 constexpr size_type local_capacity()
const noexcept;
413 constexpr size_type
extent(
dim_t dim)
const noexcept;
414 constexpr extents_type extents()
const noexcept;
415 constexpr index_type offset(
dim_t dim)
const noexcept;
416 constexpr offsets_type offsets()
const noexcept;
417 constexpr
bool empty()
const noexcept;
460 constexpr
const Pattern_t &
pattern()
const;
467 iterator
begin() noexcept;
474 constexpr const_iterator
begin()
const noexcept;
482 iterator
end() noexcept;
490 constexpr const_iterator
end( )
const noexcept;
497 ElementT *
lbegin() noexcept;
504 constexpr
const ElementT *
lbegin()
const noexcept;
511 ElementT *
lend() noexcept;
518 constexpr
const ElementT *
lend()
const noexcept;
524 template<
dim_t __NumViewDim = NumDimensions-1>
525 typename std::enable_if<
529 constexpr
operator[](
536 template<
dim_t __NumViewDim = NumDimensions-1>
537 typename std::enable_if<
541 constexpr
operator[](
549 template<
dim_t __NumViewDim = NumDimensions-1>
550 typename std::enable_if<(__NumViewDim != 0), view_type<__NumViewDim>>::type
558 template<
dim_t __NumViewDim = NumDimensions-1>
559 typename std::enable_if<(__NumViewDim == 0), reference>::type
564 template<dim_t SubDimension>
570 template<dim_t SubDimension>
582 template<dim_t SubDimension>
593 template<dim_t SubDimension>
692 template<
typename ... Args>
705 template<
typename ... Args>
719 template<
typename... Args>
733 template<
typename... Args>
752 template<dim_t Dimension>
767 void destruct_at_end(value_type *new_last);
786 #include <dash/matrix/internal/Matrix-inl.h> 788 #endif // DASH__MATRIX_H_INCLUDED void flush()
Complete all outstanding non-blocking operations to all units on the container's underlying global me...
constexpr dim_t rank(const DimensionalType &d)
view_type< NumDimensions > cols(size_type offset, size_type range)
Create a view representing the matrix slice within a column range.
Defines how a list of global indices is mapped to single units within a Team.
iterator end() noexcept
Iterator referencing past the last matrix element in global index space.
Matrix(SizeType arg, Args &&... args)
Constructor, creates a new instance of Matrix of given extents.
size_t size()
Return the number of units in the global team.
constexpr const Pattern_t & pattern() const
The pattern used to distribute matrix elements to units in its associated team.
This class is a simple memory pool which holds allocates elements of size ValueType.
const_view_type< NumDimensions > sub(size_type n, size_type range) const
self_t & operator=(const self_t &other)=delete
Copy-assignment operator, deleted.
~Matrix()
Destructor, frees underlying memory.
dash::BlockPattern< NumDimensions, Arrangement, IndexType > Pattern
Template alias for dash::Pattern with the same default template arguments.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
const_view_type< NumDimensions-1 > row(size_type n) const
Projection to given offset in second sub-dimension (rows), same as sub<1>(n).
constexpr bool is_local(size_type g_pos) const
Whether the element at a global, canonical offset in the matrix is local to the active unit...
bool allocate(const size_spec &sizespec, const distribution_spec &distribution, const team_spec &teamspec, dash::Team &team=dash::Team::All())
Explicit allocation of matrix elements, used for delayed allocation of default-constructed Matrix ins...
bool allocate(SizeType arg, Args... args)
Allocation and distribution of matrix elements as specified by given extents.
LocalMatrixRef< const ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT > const_local_type
Type specifying the view on const local matrix elements.
local_type sub_local() noexcept
Local proxy object representing a view consisting of matrix elements that are located in the active u...
void barrier() const
Synchronize units associated with the matrix.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
Matrix(Team &team=dash::Team::Null())
Default constructor, for delayed allocation.
A Team instance specifies a subset of all available units.
void deallocate()
Explicit deallocation of matrix elements, called implicitly in destructor and team deallocation...
constexpr dim_t ndim(const DimensionalType &d)
view_type< NumDimensions > rows(size_type n, size_type range)
Create a view representing the matrix slice within a row range.
std::enable_if<(__NumViewDim !=0), const_view_type< __NumViewDim > >::type constexpr operator[](size_type n) const
Subscript operator, returns a submatrix reference at given offset in global element range...
iterator begin() noexcept
Iterator referencing first matrix element in global index space.
PatternT pattern_type
The type of the pattern specifying linear iteration order and how elements are distribute to units...
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
view_type< NumDimensions > block(const std::array< index_type, NumDimensions > &block_gcoords)
View at block at given global block coordinates.
const_view_type< NumDimensions-1 > col(size_type n) const
Projection to given offset in first sub-dimension (column), same as sub<0>(n).
const_reference operator()(Args... args) const
Fortran-style subscript operator, alias for at().
Type trait indicating whether the specified type is eligible for elements of DASH containers...
LocalMatrixRef< ElementT, NumDimensions, NumDimensions, PatternT, LocalMemSpaceT > local_type
Type specifying the view on local matrix elements.
void flush_local()
Locally complete all outstanding non-blocking operations to all units on the container's underlying g...
static Team & Null()
The invariant Team instance representing an undefined team.
const_reference at(Args... args) const
Fortran-style subscript operator.
constexpr DimensionalType::extent_type extent(const DimensionalType &d)
local_type local
Local view proxy object.
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
ElementT * lbegin() noexcept
Pointer to first element in local range.
ElementT * lend() noexcept
Pointer past final element in local range.