DASH  0.3.0
dash::halo::HaloMemory< HaloBlockT > Class Template Reference

Mangages the memory for all halo regions provided by the given HaloBlock. More...

#include <HaloMemory.h>

Public Types

using Element_t = typename HaloBlockT::Element_t
 
using ElementCoords_t = std::array< typename Pattern_t::index_type, NumDimensions >
 
using HaloBuffer_t = std::vector< Element_t >
 
using pattern_size_t = typename Pattern_t::size_type
 
using iterator = typename HaloBuffer_t::iterator
 
using const_iterator = const iterator
 
using MemRange_t = std::pair< iterator, iterator >
 

Public Member Functions

 HaloMemory (const HaloBlockT &haloblock)
 Constructor. More...
 
iterator first_element_at (region_index_t index)
 Iterator to the first halo element for the given region index. More...
 
MemRange_t range_at (region_index_t index)
 Returns the range of all halo elements for the given region index. More...
 
iterator begin ()
 Returns an iterator to the first halo element. More...
 
const_iterator begin () const
 Returns a const iterator to the first halo element. More...
 
iterator end ()
 Returns an iterator to the end of the halo elements. More...
 
const_iterator end () const
 Returns a const iterator to the end of the halo elements. More...
 
const HaloBuffer_t & buffer () const
 Container storing all halo elements. More...
 
bool to_halo_mem_coords_check (const region_index_t region_index, ElementCoords_t &coords) const
 Converts coordinates to halo memory coordinates for a given region index and returns true if the coordinates are valid and false if not. More...
 
void to_halo_mem_coords (const region_index_t region_index, ElementCoords_t &coords) const
 Converts coordinates to halo memory coordinates for a given region index. More...
 
pattern_size_t offset (const region_index_t region_index, const ElementCoords_t &coords) const
 

Detailed Description

template<typename HaloBlockT>
class dash::halo::HaloMemory< HaloBlockT >

Mangages the memory for all halo regions provided by the given HaloBlock.

Definition at line 20 of file HaloMemory.h.

Constructor & Destructor Documentation

◆ HaloMemory()

template<typename HaloBlockT>
dash::halo::HaloMemory< HaloBlockT >::HaloMemory ( const HaloBlockT &  haloblock)
inline

Constructor.

Definition at line 47 of file HaloMemory.h.

47  : _haloblock(haloblock) {
48  _halobuffer.resize(haloblock.halo_size());
49  auto it = _halobuffer.begin();
50  std::fill(_halo_offsets.begin(), _halo_offsets.end(), _halobuffer.end());
51  for(const auto& region : haloblock.halo_regions()) {
52  _halo_offsets[region.index()] = it;
53  it += region.size();
54  }
55  }
void fill(GlobIterType first, GlobIterType last, const typename GlobIterType::value_type &value)
Assigns the given value to the elements in the range [first, last)
Definition: Fill.h:35

Member Function Documentation

◆ begin() [1/2]

template<typename HaloBlockT>
iterator dash::halo::HaloMemory< HaloBlockT >::begin ( )
inline

Returns an iterator to the first halo element.

Definition at line 90 of file HaloMemory.h.

90 { return _halobuffer.begin(); }

◆ begin() [2/2]

template<typename HaloBlockT>
const_iterator dash::halo::HaloMemory< HaloBlockT >::begin ( ) const
inline

Returns a const iterator to the first halo element.

Definition at line 95 of file HaloMemory.h.

95 { return _halobuffer.begin(); }

◆ buffer()

template<typename HaloBlockT>
const HaloBuffer_t& dash::halo::HaloMemory< HaloBlockT >::buffer ( ) const
inline

Container storing all halo elements.

Returns
Reference to the container storing all halo elements

Definition at line 112 of file HaloMemory.h.

112 { return _halobuffer; }

◆ end() [1/2]

template<typename HaloBlockT>
iterator dash::halo::HaloMemory< HaloBlockT >::end ( )
inline

Returns an iterator to the end of the halo elements.

Definition at line 100 of file HaloMemory.h.

100 { return _halobuffer.end(); }

◆ end() [2/2]

template<typename HaloBlockT>
const_iterator dash::halo::HaloMemory< HaloBlockT >::end ( ) const
inline

Returns a const iterator to the end of the halo elements.

Definition at line 105 of file HaloMemory.h.

105 { return _halobuffer.end(); }

◆ first_element_at()

template<typename HaloBlockT>
iterator dash::halo::HaloMemory< HaloBlockT >::first_element_at ( region_index_t  index)
inline

Iterator to the first halo element for the given region index.

Parameters
indexhalo region index
Returns
Iterator to the first halo element. If no region exists the end iterator will be returned.

Definition at line 63 of file HaloMemory.h.

63  {
64  return _halo_offsets[index];
65  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60

◆ range_at()

template<typename HaloBlockT>
MemRange_t dash::halo::HaloMemory< HaloBlockT >::range_at ( region_index_t  index)
inline

Returns the range of all halo elements for the given region index.

Parameters
indexhalo region index
Returns
Pair of iterator. First points ot the beginning and second to the end.

Definition at line 73 of file HaloMemory.h.

Referenced by dash::halo::HaloMatrixWrapper< MatrixT, SigReady >::set_custom_halos(), and dash::halo::HaloMatrixWrapper< MatrixT, SigReady >::stencil_operator().

73  {
74  auto it = _halo_offsets[index];
75  if(it == _halobuffer.end())
76  return std::make_pair(it, it);
77 
78  auto* region = _haloblock.halo_region(index);
79 
80  DASH_ASSERT_MSG(
81  region != nullptr,
82  "HaloMemory manages memory for a region that seemed to be empty.");
83 
84  return std::make_pair(it, it + region->size());
85  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60

◆ to_halo_mem_coords()

template<typename HaloBlockT>
void dash::halo::HaloMemory< HaloBlockT >::to_halo_mem_coords ( const region_index_t  region_index,
ElementCoords_t &  coords 
) const
inline

Converts coordinates to halo memory coordinates for a given region index.

Definition at line 139 of file HaloMemory.h.

140  {
141  const auto& extents =
142  _haloblock.halo_region(region_index)->view().extents();
143  for(dim_t d = 0; d < NumDimensions; ++d) {
144  if(coords[d] < 0) {
145  coords[d] += extents[d];
146  continue;
147  }
148 
149  if(static_cast<extent_t>(coords[d]) >= _haloblock.view().extent(d))
150  coords[d] -= _haloblock.view().extent(d);
151  }
152  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ to_halo_mem_coords_check()

template<typename HaloBlockT>
bool dash::halo::HaloMemory< HaloBlockT >::to_halo_mem_coords_check ( const region_index_t  region_index,
ElementCoords_t &  coords 
) const
inline

Converts coordinates to halo memory coordinates for a given region index and returns true if the coordinates are valid and false if not.

Definition at line 119 of file HaloMemory.h.

120  {
121  const auto& extents =
122  _haloblock.halo_region(region_index)->view().extents();
123  for(auto d = 0; d < NumDimensions; ++d) {
124  if(coords[d] < 0)
125  coords[d] += extents[d];
126  else if(static_cast<extent_t>(coords[d]) >= _haloblock.view().extent(d))
127  coords[d] -= _haloblock.view().extent(d);
128 
129  if(static_cast<extent_t>(coords[d]) >= extents[d] || coords[d] < 0)
130  return false;
131  }
132 
133  return true;
134  }

The documentation for this class was generated from the following file: