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

Proxy StencilOperator for inner elements only. More...

#include <StencilOperator.h>

Public Types

using Element_t = typename StencilOperatorT::Element_t
 
using ViewSpec_t = typename StencilOperatorT::ViewSpec_t
 
using Coords_t = typename StencilOperatorT::Coords_t
 
using iterator = typename StencilOperatorT::iterator_inner
 
using const_iterator = const iterator
 
using StencilOffsets_t = typename StencilOperatorT::StencilOffsets_t
 

Public Member Functions

 StencilOperatorInner (StencilOperatorT *stencil_op)
 
iterator begin () noexcept
 Returns the begin iterator for all inner elements. More...
 
const_iterator begin () const noexcept
 Returns the begin const iterator for all inner elements. More...
 
iterator end () noexcept
 Returns the end iterator for all inner elements. More...
 
const_iterator end () const noexcept
 Returns the end const iterator for all inner elements. More...
 
const ViewSpec_t & view () const
 Returns a view for all inner elements. 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 within the inner view. More...
 
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 inner elements using a user-defined stencil operation. More...
 
template<typename Op >
void update (iterator begin, iterator end, Element_t *begin_dst, Op operation)
 Updates all inner elements within a user defined range using a user-defined stencil operation. More...
 
template<typename Op >
void update_blocked (const Coords_t &begin_coords, const Coords_t &end_coords, Element_t *begin_dst, Op operation)
 Updates all inner elements within a user defined range using a user-defined stencil operation. More...
 

Detailed Description

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

Proxy StencilOperator for inner elements only.

Definition at line 30 of file StencilOperator.h.

Member Function Documentation

◆ begin() [1/2]

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

Returns the begin iterator for all inner elements.

Definition at line 52 of file StencilOperator.h.

52 { return _stencil_op->_ibegin; }

◆ begin() [2/2]

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

Returns the begin const iterator for all inner elements.

Definition at line 57 of file StencilOperator.h.

57 { return _stencil_op->_ibegin; }

◆ end() [1/2]

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

Returns the end iterator for all inner elements.

Definition at line 62 of file StencilOperator.h.

62 { return _stencil_op->_iend; }

◆ end() [2/2]

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

Returns the end const iterator for all inner elements.

Definition at line 67 of file StencilOperator.h.

67 { return _stencil_op->_iend; }

◆ get_value_at()

template<typename StencilOperatorT>
template<typename BinaryFunc = std::plus<Element_t>>
Element_t dash::halo::StencilOperatorInner< 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. No test for halo elements. -> useful only for elements with stencil points pointing to inner elements. (no halo elements)

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

Definition at line 114 of file StencilOperator.h.

116  {
117  auto* center = _stencil_op->_local_memory + _stencil_op->get_offset(coords);
118  Element_t value = *center * coefficient_center;
119 
120  for(auto i = 0; i < NumStencilPoints; ++i) {
121  auto& stencil_point_value = center[_stencil_op->_stencil_offsets[i]];
122  value = op(value, _stencil_op->_stencil_spec[i].coefficient()
123  * stencil_point_value);
124  }
125 
126  return value;
127  }
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

◆ set_values_at()

template<typename StencilOperatorT>
template<typename BinaryFunc = internal::replace<Element_t>>
void dash::halo::StencilOperatorInner< 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 within the inner view.

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 87 of file StencilOperator.h.

89  {
90  auto* center = _stencil_op->_local_memory + _stencil_op->get_offset(coords);
91 
92  *center = op(*center, coefficient_center * value);
93  for(auto i = 0; i < NumStencilPoints; ++i) {
94  auto& stencil_point_value = center[_stencil_op->_stencil_offsets[i]];
95  stencil_point_value =
96  op(stencil_point_value,
97  _stencil_op->_stencil_spec[i].coefficient() * value);
98  }
99  }
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::StencilOperatorInner< StencilOperatorT >::update ( Element_t *  begin_dst,
Op  operation 
)
inline

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

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

Definition at line 136 of file StencilOperator.h.

136  {
137  update(begin(), end(), begin_dst, operation);
138  }
void update(Element_t *begin_dst, Op operation)
Updates all inner elements using a user-defined stencil operation.
iterator end() noexcept
Returns the end iterator for all inner elements.
iterator begin() noexcept
Returns the begin iterator for all inner elements.

◆ update() [2/2]

template<typename StencilOperatorT>
template<typename Op >
void dash::halo::StencilOperatorInner< StencilOperatorT >::update ( iterator  begin,
iterator  end,
Element_t *  begin_dst,
Op  operation 
)
inline

Updates all inner elements within a user defined range using a user-defined stencil operation.

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

Definition at line 150 of file StencilOperator.h.

150  {
151  if(begin < this->begin() || end < this->begin() ||
152  begin > this->end() || end > this->end()) {
153 
154  DASH_LOG_ERROR("Begin or End iterator located outside of inner view.");
155 
156  return;
157  }
158 
159  end -= 1;
160 
161  const auto& view = this->view();
162  const auto& offsets_view = view.offsets();
163  const auto& extents_view = view.extents();
164  auto end_coords_view = offsets_view;
165  for(auto d = 0; d < NumDimensions; ++d) {
166  end_coords_view[d] += extents_view[d];
167  }
168 
169  auto begin_coords = begin.coords();
170  auto end_coords = end.coords();
171 
172  auto center = _stencil_op->_local_memory;
173  auto offsets = _stencil_op->set_dimension_offsets();
174  auto offset = 0;
175  for(dim_t d = 0; d < NumDimensions; ++d) {
176  offset += offsets[d] * begin_coords[d];
177  }
178  center += offset;
179  auto center_dst = begin_dst + offset;
180 
181  // specialization for 2-D
182  if(NumDimensions == 2) {
183  if(begin_coords[0] == end_coords[0]) {
184  auto center_i = center;
185  auto center_dst_i = center_dst;
186  auto offset_i = offset;
187  for(int j = begin_coords[1]; j <= end_coords[1];
188  ++j, ++center_i, ++center_dst_i, ++offset_i) {
189  operation(center_i, center_dst_i, offset_i,
190  _stencil_op->_stencil_offsets);
191  }
192 
193  return;
194  }
195 
196  auto center_i = center;
197  auto center_dst_i = center_dst;
198  auto offset_i = offset;
199  auto align_offset = begin_coords[1] - offsets_view[1];
200  for(int j = begin_coords[1]; j < end_coords_view[1];
201  ++j, ++center_i, ++center_dst_i, ++offset_i) {
202  operation(center_i, center_dst_i, offset_i,
203  _stencil_op->_stencil_offsets);
204  }
205 
206  center += offsets[0] - align_offset;
207  center_dst += offsets[0] - align_offset;
208  offset += offsets[0] - align_offset;
209  for(int i = begin_coords[0] + 1; i < end_coords[0]; ++i,
210  center += offsets[0], center_dst += offsets[0],
211  offset += offsets[0]) {
212  center_i = center;
213  center_dst_i = center_dst;
214  offset_i = offset;
215  for(int j = offsets_view[1]; j < end_coords_view[1];
216  ++j, ++center_i, ++center_dst_i, ++offset_i) {
217  operation(center_i, center_dst_i, offset_i,
218  _stencil_op->_stencil_offsets);
219  }
220  }
221 
222  center_i = center;
223  center_dst_i = center_dst;
224  offset_i = offset;
225  for(int j = offsets_view[1]; j <= end_coords[1];
226  ++j, ++center_i, ++center_dst_i, ++offset_i) {
227  operation(center_i, center_dst_i, offset_i,
228  _stencil_op->_stencil_offsets);
229  }
230  return;
231  }
232 
233  // specialization for 3-D
234  if(NumDimensions == 3) {
235  for(int i = begin_coords[0]; i <= end_coords[0]; ++i,
236  center += offsets[0], center_dst += offsets[0],
237  offset += offsets[0]) {
238  auto center_i = center;
239  auto center_dst_i = center_dst;
240  auto offset_i = offset;
241  for(int j = begin_coords[1]; j <= end_coords[1]; ++j,
242  center_i += offsets[1], center_dst_i += offsets[1],
243  offset_i += offsets[1]) {
244  auto center_j = center_i;
245  auto center_dst_j = center_dst_i;
246  auto offset_j = offset_i;
247  for(int k = begin_coords[2]; k <= end_coords[2];
248  ++k, ++center_j, ++center_dst_j, ++offset_j) {
249  operation(center_j, center_dst_j, offset_j,
250  _stencil_op->_stencil_offsets);
251  }
252  }
253  }
254 
255  return;
256  }
257 
258  // dimensions above 3-D
259  for(int i = begin_coords[0]; i <= end_coords[0]; ++i, center += offsets[0],
260  center_dst += offsets[0], offset += offsets[0]) {
261  Loop<1, Op>()(_stencil_op->_stencil_offsets, offsets, begin_coords,
262  end_coords, center, center_dst, offset, operation);
263  }
264  }
const ViewSpec_t & view() const
Returns a view for all inner elements.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
iterator end() noexcept
Returns the end iterator for all inner elements.
iterator begin() noexcept
Returns the begin iterator for all inner elements.

◆ update_blocked()

template<typename StencilOperatorT>
template<typename Op >
void dash::halo::StencilOperatorInner< StencilOperatorT >::update_blocked ( const Coords_t &  begin_coords,
const Coords_t &  end_coords,
Element_t *  begin_dst,
Op  operation 
)
inline

Updates all inner elements within a user defined range using a user-defined stencil operation.

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

Definition at line 276 of file StencilOperator.h.

276  {
277  const auto& view = this->view();
278  const auto& offsets_view = view.offsets();
279  const auto& extents_view = view.extents();
280 
281  for(auto d = 0; d < NumDimensions; ++d) {
282  auto end_coord = offsets_view[d] + extents_view[d];
283  if(begin_coords[d] < offsets_view[d] ||
284  end_coords[d] < offsets_view[d] ||
285  begin_coords[d] >= end_coord ||
286  end_coords[d] >= end_coord) {
287 
288  DASH_LOG_ERROR("Begin or End coordinates located outside of inner view.");
289 
290  return;
291  }
292  }
293 
294  auto center = _stencil_op->_local_memory;
295  auto offsets = _stencil_op->set_dimension_offsets();
296  auto offset = 0;
297  for(dim_t d = 0; d < NumDimensions; ++d) {
298  offset += offsets[d] * begin_coords[d];
299  }
300  center += offset;
301  auto center_dst = begin_dst + offset;
302 
303  // specialization for 2-D
304  if(NumDimensions == 2) {
305  for(int i = begin_coords[0]; i <= end_coords[0]; ++i,
306  center += offsets[0], center_dst += offsets[0],
307  offset += offsets[0]) {
308  auto center_i = center;
309  auto center_dst_i = center_dst;
310  auto offset_i = offset;
311  for(int j = begin_coords[1]; j <= end_coords[1];
312  ++j, ++center_i, ++center_dst_i, ++offset_i) {
313  operation(center_i, center_dst_i, offset_i,
314  _stencil_op->_stencil_offsets);
315  }
316  }
317  return;
318  }
319 
320  // specialization for 3-D
321  if(NumDimensions == 3) {
322  for(int i = begin_coords[0]; i <= end_coords[0]; ++i,
323  center += offsets[0], center_dst += offsets[0],
324  offset += offsets[0]) {
325  auto center_i = center;
326  auto center_dst_i = center_dst;
327  auto offset_i = offset;
328  for(int j = begin_coords[1]; j <= end_coords[1]; ++j,
329  center_i += offsets[1], center_dst_i += offsets[1],
330  offset_i += offsets[1]) {
331  auto center_j = center_i;
332  auto center_dst_j = center_dst_i;
333  auto offset_j = offset_i;
334  for(int k = begin_coords[2]; k <= end_coords[2];
335  ++k, ++center_j, ++center_dst_j, ++offset_j) {
336  operation(center_j, center_dst_j, offset_j,
337  _stencil_op->_stencil_offsets);
338  }
339  }
340  }
341 
342  return;
343  }
344 
345  // dimensions above 3-D
346  for(int i = begin_coords[0]; i <= end_coords[0]; ++i, center += offsets[0],
347  center_dst += offsets[0], offset += offsets[0]) {
348  Loop<1, Op>()(_stencil_op->_stencil_offsets, offsets, begin_coords,
349  end_coords, center, center_dst, offset, operation);
350  }
351  }
const ViewSpec_t & view() const
Returns a view for all inner elements.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ view()

template<typename StencilOperatorT>
const ViewSpec_t& dash::halo::StencilOperatorInner< StencilOperatorT >::view ( ) const
inline

Returns a view for all inner elements.

Definition at line 72 of file StencilOperator.h.

72 { return _stencil_op->_spec_views.inner(); }

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