DASH  0.3.0
Fill.h
1 #ifndef DASH__ALGORITHM__FILL_H__
2 #define DASH__ALGORITHM__FILL_H__
3 
4 #include <dash/internal/Config.h>
5 
6 #include <dash/iterator/GlobIter.h>
7 
8 #include <dash/algorithm/LocalRange.h>
9 #include <dash/algorithm/Operation.h>
10 
11 #include <dash/util/UnitLocality.h>
12 
14 
15 #ifdef DASH_ENABLE_OPENMP
16 #include <omp.h>
17 #endif
18 
19 
20 namespace dash {
21 
34 template <typename GlobIterType>
35 void fill(
37  GlobIterType first,
39  GlobIterType last,
41  const typename GlobIterType::value_type & value)
42 {
43  typedef typename GlobIterType::index_type index_t;
44  typedef typename GlobIterType::value_type value_t;
45 
46  // Global iterators to local range:
47  auto index_range = dash::local_range(first, last);
48  value_t * lfirst = index_range.begin;
49  value_t * llast = index_range.end;
50 
51 #ifdef DASH_ENABLE_OPENMP
53  auto n_threads = uloc.num_domain_threads();
54  auto nlocal = llast - lfirst;
55  DASH_LOG_DEBUG("dash::fill", "thread capacity:", n_threads);
56  #pragma omp parallel for num_threads(n_threads)
57  for (index_t lt = 0; lt < nlocal; ++lt) {
58  lfirst[lt] = value;
59  }
60 
61 #else
62  std::fill(lfirst, llast, value);
63 #endif
64 }
65 
66 } // namespace dash
67 
68 #endif // DASH__ALGORITHM__FILL_H__
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
LocalRange< const typename GlobIterType::value_type > local_range(const GlobIterType &first, const GlobIterType &last)
Resolves the local address range between global iterators.
Definition: LocalRange.h:295
Returns second operand.
Definition: Operation.h:201
int num_domain_threads()
Number of threads currently available to the active unit.
Definition: UnitLocality.h:306
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
Wrapper of a single dart_unit_locality_t object.
Definition: UnitLocality.h:30