DASH  0.3.0
dash::halo::StencilOperatorBoundary< StencilOperatorT > Class Template Reference

Proxy StencilOperator for boundary elements only. More...

#include <StencilOperator.h>

Public Types

using Element_t = typename StencilOperatorT::Element_t
 
using uindex_t = typename StencilOperatorT::uindex_t
 
using ViewSpec_t = typename StencilOperatorT::ViewSpec_t
 
using Coords_t = typename StencilOperatorT::Coords_t
 
using iterator = typename StencilOperatorT::iterator_bnd
 
using const_iterator = const iterator
 
using BoundaryViews_t = typename StencilSpecViews_t::BoundaryViews_t
 
using RegionCoords_t = RegionCoords< NumDimensions >
 

Public Member Functions

 StencilOperatorBoundary (const StencilOperatorT *stencil_op)
 
iterator begin () noexcept
 Returns the begin iterator for all boundary elements. More...
 
const_iterator begin () const noexcept
 Returns the begin const iterator for all boundary elements. More...
 
iterator end () noexcept
 Returns the end iterator for all boundary elements. More...
 
const_iterator end () const noexcept
 Returns the end const iterator for all boundary elements. More...
 
const BoundaryViews_t & view () const
 Returns all boundary views including all boundary elements (no dublicates) Unlike the view methods in StencilOperator and StencilOperatorInner this method returns a container with views. More...
 
uindex_t boundary_size () const
 Returns the number of all boundary elements (no dublicates) More...
 
template<typename BinaryFunc = internal::replace<Element_t>>
void set_values_at (const Coords_t &coords, Element_t value, Element_t coefficient_center, BinaryFunc op=BinaryFunc())
 Modifies all stencil point elements and the center with halo check. More...
 
std::pair< iterator, iterator > iterator_at (dim_t dim, RegionPos pos)
 Returns a pair of boundary iterators (first: begin, second: end) for a given dimension and RegionPos. More...
 
std::pair< iterator, iterator > iterator_at (region_index_t index)
 
template<typename BinaryFunc = std::plus<Element_t>>
Element_t get_value_at (const Coords_t &coords, Element_t coefficient_center, BinaryFunc op=BinaryFunc()) const
 Returns the result of the given operation done on all stencil point elements and the center. More...
 
template<typename Op >
void update (Element_t *begin_dst, Op operation)
 Updates all boundary elements using a user-defined stencil operation. More...
 
template<typename Op >
void update (const iterator &begin, const iterator &end, Element_t *begin_out, Op operation)
 Updates all boundary elements within a user defined range using a userdefined stencil operation. More...
 

Detailed Description

template<typename StencilOperatorT>
class dash::halo::StencilOperatorBoundary< StencilOperatorT >

Proxy StencilOperator for boundary elements only.

Definition at line 393 of file StencilOperator.h.

Member Function Documentation

◆ begin() [1/2]

template<typename StencilOperatorT>
iterator dash::halo::StencilOperatorBoundary< StencilOperatorT >::begin ( )
inlinenoexcept

Returns the begin iterator for all boundary elements.

Definition at line 418 of file StencilOperator.h.

418 { return _stencil_op->_bbegin; }

◆ begin() [2/2]

template<typename StencilOperatorT>
const_iterator dash::halo::StencilOperatorBoundary< StencilOperatorT >::begin ( ) const
inlinenoexcept

Returns the begin const iterator for all boundary elements.

Definition at line 423 of file StencilOperator.h.

423 { return _stencil_op->_bbegin; }

◆ boundary_size()

template<typename StencilOperatorT>
uindex_t dash::halo::StencilOperatorBoundary< StencilOperatorT >::boundary_size ( ) const
inline

Returns the number of all boundary elements (no dublicates)

Definition at line 448 of file StencilOperator.h.

448  {
449  return _stencil_op->_spec_views.boundary_size();
450  }

◆ end() [1/2]

template<typename StencilOperatorT>
iterator dash::halo::StencilOperatorBoundary< StencilOperatorT >::end ( )
inlinenoexcept

Returns the end iterator for all boundary elements.

Definition at line 428 of file StencilOperator.h.

428 { return _stencil_op->_bend; }

◆ end() [2/2]

template<typename StencilOperatorT>
const_iterator dash::halo::StencilOperatorBoundary< StencilOperatorT >::end ( ) const
inlinenoexcept

Returns the end const iterator for all boundary elements.

Definition at line 433 of file StencilOperator.h.

433 { return _stencil_op->_bend; }

◆ get_value_at()

template<typename StencilOperatorT>
template<typename BinaryFunc = std::plus<Element_t>>
Element_t dash::halo::StencilOperatorBoundary< StencilOperatorT >::get_value_at ( const Coords_t &  coords,
Element_t  coefficient_center,
BinaryFunc  op = BinaryFunc() 
) const
inline

Returns the result of the given operation done on all stencil point elements and the center.

The stencil points are multiplied with their coefficent (StencilPoint) and the center is multiplied with the given center coefficient. Test and use of halo elements. -> useful only for elements with stencil points pointing to halo elements. (boundary elements)

Parameters
coordscenter coordinate
coefficientfor center
opoperation to use (e.g. std::plus). default: std::plus

Definition at line 547 of file StencilOperator.h.

549  {
550  auto* center = _stencil_op->_local_memory + _stencil_op->get_offset(coords);
551  Element_t value = *center * coefficient_center;
552  auto& stencil_spec = _stencil_op->_stencil_spec;
553  for(auto i = 0; i < NumStencilPoints; ++i) {
554  bool halo = false;
555  auto coords_stencil = coords;
556 
557  for(auto d = 0; d < NumDimensions; ++d) {
558  coords_stencil[d] += stencil_spec[i][d];
559  if(coords_stencil[d] < 0
560  || coords_stencil[d] >= _stencil_op->_view_local->extent(d))
561  halo = true;
562  }
563 
564  if(halo) {
565  auto& halo_memory = *_stencil_op->_halo_memory;
566  auto index = _stencil_op->_halo_block->index_at(
567  *(_stencil_op->_view_local), coords_stencil);
568  auto halomem_pos = halo_memory.first_element_at(index);
569 
570  halo_memory.to_halo_mem_coords(index, coords_stencil);
571  auto offset = halo_memory.offset(index, coords_stencil);
572  value = op(value, stencil_spec[i].coefficient() * halomem_pos[offset]);
573  } else {
574  auto stencil_point_value = center[_stencil_op->_stencil_offsets[i]];
575  value = op(value, stencil_spec[i].coefficient() * stencil_point_value);
576  }
577  }
578 
579  return value;
580  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60
void op(const dash::GlobRef< dash::Atomic< T >> &ref, const BinaryOp binary_op, const T &value)
Atomically executes specified operation on the referenced shared value.
Definition: Operation.h:80

◆ iterator_at()

template<typename StencilOperatorT>
std::pair<iterator, iterator> dash::halo::StencilOperatorBoundary< StencilOperatorT >::iterator_at ( dim_t  dim,
RegionPos  pos 
)
inline

Returns a pair of boundary iterators (first: begin, second: end) for a given dimension and RegionPos.

Iterators of higher dimensions will not iterate over elements which were already covered in lower dimensions. Using all iterators for all dimensions and RegionPos has the same effect as using bbegin and bend.

Definition at line 501 of file StencilOperator.h.

501  {
502  DASH_ASSERT_LT(dim, NumDimensions, "Given dimension to great");
503  const auto& bnd_views = _stencil_op->_spec_views.boundary_views();
504  uindex_t offset = 0;
505  auto it_views = std::begin(bnd_views);
506  for(dim_t d = 0; d < dim; ++d, ++it_views)
507  offset += it_views->size() + (++it_views)->size();
508 
509  if(pos == RegionPos::POST) {
510  offset += it_views->size();
511  ++it_views;
512  }
513 
514  auto it_begin = _stencil_op->_bbegin + offset;
515 
516  return std::make_pair(it_begin, it_begin + it_views->size());
517  }
size_t size()
Return the number of units in the global team.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Definition: Range.h:89
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ set_values_at()

template<typename StencilOperatorT>
template<typename BinaryFunc = internal::replace<Element_t>>
void dash::halo::StencilOperatorBoundary< StencilOperatorT >::set_values_at ( const Coords_t &  coords,
Element_t  value,
Element_t  coefficient_center,
BinaryFunc  op = BinaryFunc() 
)
inline

Modifies all stencil point elements and the center with halo check.

If a stencil point points to a halo element or a non existing element no operation is performed for this one. The stencil points are multiplied with their coefficent (StencilPoint) and the center is multiplied with the given center coefficient. The results then modifies the center/stencil point elements via the given operation.

Parameters
coordscenter coordinate
valuebase value for all points
coefficientfor center
opoperation to use (e.g. std::plus). default: replace

Definition at line 467 of file StencilOperator.h.

469  {
470  auto* center = _stencil_op->_local_memory + _stencil_op->get_offset(coords);
471 
472  *center = op(*center, coefficient_center * value);
473  for(auto i = 0; i < NumStencilPoints; ++i) {
474  bool halo = false;
475  for(auto d = 0; d < NumDimensions; ++d) {
476  auto coord_value = coords[d] + _stencil_op->_stencil_spec[i][d];
477  if(coord_value < 0
478  || coord_value >= _stencil_op->_view_local->extent(d)) {
479  halo = true;
480  break;
481  }
482  }
483 
484  if(halo)
485  continue;
486 
487  auto& stencil_point_value = center[_stencil_op->_stencil_offsets[i]];
488  stencil_point_value =
489  op(stencil_point_value,
490  _stencil_op->_stencil_spec[i].coefficient() * value);
491  }
492  }
void op(const dash::GlobRef< dash::Atomic< T >> &ref, const BinaryOp binary_op, const T &value)
Atomically executes specified operation on the referenced shared value.
Definition: Operation.h:80

◆ update() [1/2]

template<typename StencilOperatorT>
template<typename Op >
void dash::halo::StencilOperatorBoundary< StencilOperatorT >::update ( Element_t *  begin_dst,
Op  operation 
)
inline

Updates all boundary elements using a user-defined stencil operation.

Parameters
begin_dstPointer to the beginning of the destination memory
operationUser-definied operation for updating all boundary elements

Definition at line 589 of file StencilOperator.h.

589  {
590  update(begin(), end(), begin_dst, operation);
591  }
void update(Element_t *begin_dst, Op operation)
Updates all boundary elements using a user-defined stencil operation.
iterator end() noexcept
Returns the end iterator for all boundary elements.
iterator begin() noexcept
Returns the begin iterator for all boundary elements.

◆ update() [2/2]

template<typename StencilOperatorT>
template<typename Op >
void dash::halo::StencilOperatorBoundary< StencilOperatorT >::update ( const iterator &  begin,
const iterator &  end,
Element_t *  begin_out,
Op  operation 
)
inline

Updates all boundary elements within a user defined range using a userdefined stencil operation.

Parameters
beginIterator of the beginnning boundary data element
endIterator of the last boundary data element
begin_dstPointer to the beginning of the destination memory
operationUser-definied operation for updating all inner elements

Definition at line 604 of file StencilOperator.h.

605  {
606  for(auto it = begin; it != end; ++it) {
607  begin_out[it.lpos()] = operation(it);
608  }
609  }
iterator end() noexcept
Returns the end iterator for all boundary elements.
iterator begin() noexcept
Returns the begin iterator for all boundary elements.

◆ view()

template<typename StencilOperatorT>
const BoundaryViews_t& dash::halo::StencilOperatorBoundary< StencilOperatorT >::view ( ) const
inline

Returns all boundary views including all boundary elements (no dublicates) Unlike the view methods in StencilOperator and StencilOperatorInner this method returns a container with views.

Definition at line 441 of file StencilOperator.h.

441  {
442  return _stencil_op->_spec_views.boundary_views();
443  }

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