1 #ifndef DASH__HALO_HALOMATRIXWRAPPER_H 2 #define DASH__HALO_HALOMATRIXWRAPPER_H 6 #include <dash/Matrix.h> 7 #include <dash/Pattern.h> 8 #include <dash/halo/StencilOperator.h> 9 #include <dash/halo/CoordinateAccess.h> 10 #include <dash/halo/Types.h> 12 #include <type_traits> 52 template <
typename MatrixT, SignalReady SigReady = SignalReady::OFF>
56 using pattern_index_t =
typename Pattern_t::index_type;
62 using Element_t =
typename MatrixT::value_type;
69 using ElementCoords_t = std::array<pattern_index_t, NumDimensions>;
70 using region_index_t = internal::region_index_t;
71 using stencil_dist_t = internal::spoint_value_t;
76 using pattern_size_t =
typename Pattern_t::size_type;
77 using signed_pattern_size_t =
typename std::make_signed<pattern_size_t>::type;
86 template <
size_t NumStencilPointsFirst,
typename... StencilSpecRestT>
89 const StencilSpecRestT&... stencil_spec)
90 : _matrix(matrix), _glob_bnd_spec(glob_bnd_spec),
91 _halo_spec(stencil_spec_first, stencil_spec...),
92 _view_global(matrix.
local.offsets(), matrix.
local.extents()),
93 _haloblock(matrix.
begin().globmem(), matrix.pattern(), _view_global,
94 _halo_spec, glob_bnd_spec),
97 _halo_env(_haloblock, matrix.lbegin(), matrix.team(), matrix.pattern().teamspec()) {
106 template <
typename StencilPo
intT = StencilPo
int<NumDimensions>>
108 stencil_dist_t dist, std::enable_if_t<std::is_integral<stencil_dist_t>::value, std::nullptr_t> =
nullptr )
118 template <
typename StencilPo
intT = StencilPo
int<NumDimensions>>
128 template <
typename StencilPo
intT, std::
size_t NumStencilPo
ints>
137 template <
typename...
StencilSpecT,
typename std::enable_if_t<
sizeof...(StencilSpecT) >= 2,
bool>>
191 _halo_env.
wait(index);
242 template <
typename FunctionT>
244 using signed_extent_t =
typename std::make_signed<pattern_size_t>::type;
246 if(!region.is_custom_region()) {
250 const auto& spec = region.spec();
251 std::array<signed_extent_t, NumDimensions> coords_offset{};
252 const auto& reg_ext = region.view().extents();
253 for(
auto d = 0; d < NumDimensions; ++d) {
255 coords_offset[d] -= reg_ext[d];
259 coords_offset[d] = reg_ext[d];
263 auto it_mem = range_mem.first;
264 auto it_reg_end = region.end();
266 std::distance(range_mem.first, range_mem.second) == region.size(),
267 "Range distance of the HaloMemory is unequal region size");
268 const auto& pattern = _matrix.
pattern();
269 for(
auto it = region.begin(); it != it_reg_end; ++it, ++it_mem) {
270 auto coords = pattern.coords(it.rpos(), region.view());
271 for(
auto d = 0; d < NumDimensions; ++d) {
272 coords[d] += coords_offset[d];
286 const auto& offsets = _view_global.offsets();
287 for(
auto d = 0; d < NumDimensions; ++d) {
288 coords[d] -= offsets[d];
291 return halo_element_at(coords);
299 return halo_element_at(coords);
306 template <
typename StencilSpecT>
309 for(
const auto& stencil : stencil_spec.
specs()) {
313 "Stencil point extent higher than halo region extent.");
326 Element_t* halo_element_at(ElementCoords_t& coords) {
328 const auto& spec = _halo_spec.
spec(
index);
331 if(spec.level() == 0 || range_mem.first == range_mem.second)
334 if(!halo_memory.to_halo_mem_coords_check(
index, coords))
337 return &*(range_mem.first + halo_memory.offset(
index, coords));
354 #endif // DASH__HALO_HALOMATRIXWRAPPER_H HaloUpdateEnv_t & halo_env()
Returns the halo environment management object HaloUpdateEnv.
void update()
Initiates a blocking halo region update for all halo elements.
const ViewSpec_t & view_local() const
Returns the local ViewSpec.
constexpr region_extent_t extent(const region_index_t index) const
Extent for a given region index.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
HaloMatrixWrapper(MatrixT &matrix, stencil_dist_t dist, std::enable_if_t< std::is_integral< stencil_dist_t >::value, std::nullptr_t >=nullptr)
Constructor that takes Matrix and a stencil point distance to create a HaloMatrixWrapper with a full ...
void wait()
Waits until all halo updates are finished.
void update_at(region_index_t index)
Initiates a blocking halo region update for all halo elements within the the given region...
constexpr auto local(ViewType &v) -> typename std::enable_if<(std::is_pointer< typename ViewType::iterator >::value||(dash::view_traits< ViewValueT >::is_local::value)), ViewType &>::type
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.
MatrixT & matrix()
Returns the underlying NArray.
MemRange_t range_at(region_index_t index)
Returns the range of all halo elements for the given region index.
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
const HaloBlock_t & halo_block()
Returns the underlying HaloBlock.
Takes the local part of the NArray and builds halo and boundary regions.
Specifies view parameters for implementing submat, rows and cols.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
void wait()
Waits until all halo updates are finished.
constexpr const StencilArray_t & specs() const
HaloMatrixWrapper(MatrixT &matrix, const StencilSpec< StencilPointT, NumStencilPoints > stencil_spec)
Constructor that takes Matrix and a user defined number of stencil specifications (StencilSpec)...
const MatrixT & matrix() const
Returns the underlying NArray.
Element_t * halo_element_at_local(ElementCoords_t coords)
Returns the halo value for a given local coordinate or nullptr if no halo element exists...
Stencil point with raletive coordinates for N dimensions e.g.
HaloMatrixWrapper(MatrixT &matrix, const GlobBoundSpec_t &glob_bnd_spec, stencil_dist_t dist, std::enable_if_t< std::is_integral< stencil_dist_t >::value, std::nullptr_t >=nullptr)
Constructor that takes Matrix and a stencil point distance to create a HaloMatrixWrapper with a full ...
HaloMatrixWrapper(MatrixT &matrix, const StencilSpecT &... stencil_spec)
Constructor that takes Matrix and a user defined number of stencil specifications (StencilSpec)...
Element_t * halo_element_at_global(ElementCoords_t coords)
Returns the halo value for a given global coordinate or nullptr if no halo element exists...
void update_async_at(region_index_t index)
Initiates an asychronous halo region update for all halo elements within the given region...
static constexpr dim_t ndim() noexcept
Number of dimensions of the cartesian space partitioned by the pattern.
void set_custom_halos(FunctionT f)
Sets all global border halo elements.
void update()
Initiates a blocking halo region update for all halo elements.
region_index_t index_at(const ViewSpec_t &view, const ElementCoords_t &coords) const
Returns the region index belonging to the given coordinates and ViewSpec.
Contains all specified Halo regions.
As known from classic stencil algorithms, boundaries are the outermost elements within a block that a...
void wait(region_index_t index)
Waits until the halo updates for the given halo region is finished.
PatternT pattern_type
The type of the pattern specifying linear iteration order and how elements are distribute to units...
const RegionVector_t & boundary_regions() const
Returns all boundary regions.
Provides RegionIter and some region metadata like RegionSpec, size etc.
void update_async_at(region_index_t index)
Initiates an asychronous halo region update for all halo elements within the given region...
HaloMemory_t & halo_memory()
Returns the halo memory management object HaloMemory.
HaloMatrixWrapper(MatrixT &matrix, const GlobBoundSpec_t &glob_bnd_spec, const StencilSpec< StencilPoint< NumDimensions >, NumStencilPointsFirst > &stencil_spec_first, const StencilSpecRestT &... stencil_spec)
Constructor that takes Matrix, a GlobalBoundarySpec and a user defined number of stencil specificatio...
void update_async()
Initiates an asychronous halo region update for all halo elements.
void update_async()
Initiates an asychronous halo region update for all halo elements.
constexpr RegionSpec_t spec(const region_index_t index) const
Matching RegionSpec for a given region index.
The StencilOperator provides stencil specific iterator and functions for a given HaloBlock and HaloMe...
void update_at(region_index_t index)
Initiates a blocking halo region update for all halo elements within the the given region...
A collection of stencil points (Stencil) e.g.
Global boundary property specification for every dimension.
Region specification connecting RegionCoords with an extent.
ElementT * lbegin() noexcept
Pointer to first element in local range.
const HaloUpdateEnv_t & halo_env() const
Returns the halo environment management object HaloUpdateEnv.
StencilOperator< HaloBlock_t, StencilSpecT > stencil_operator(const StencilSpecT &stencil_spec)
Crates StencilOperator for a given StencilSpec.
static constexpr MemArrange memory_order() noexcept
Memory order followed by the pattern.