DASH  0.3.0
LocalListRef.h
1 #ifndef DASH__LIST__LOCAL_LIST_REF_H__INCLUDED
2 #define DASH__LIST__LOCAL_LIST_REF_H__INCLUDED
3 
4 #include <iterator>
5 #include <limits>
6 
7 #include <dash/Types.h>
8 #include <dash/GlobRef.h>
9 #include <dash/Team.h>
10 #include <dash/Exception.h>
11 #include <dash/Cartesian.h>
12 #include <dash/Dimensional.h>
13 #include <dash/memory/GlobHeapMem.h>
14 #include <dash/Allocator.h>
15 
16 #include <dash/list/internal/ListTypes.h>
17 
18 #include <dash/iterator/GlobIter.h>
19 
20 namespace dash {
21 
22 // forward declaration
23 template<
24  typename ElementType,
25  class AllocatorType >
26 class List;
27 
33 template<
34  typename T,
35  class LMemSpace >
36 class LocalListRef
37 {
38  template <typename T_, typename LM_>
39  friend class LocalListRef;
40 
41  static const dim_t NumDimensions = 1;
42 
43 private:
44  typedef LocalListRef<T, LMemSpace>
45  self_t;
46  typedef List<T, LMemSpace>
47  list_type;
48  typedef ViewSpec<NumDimensions, dash::default_index_t>
49  ViewSpec_t;
50 
51  typedef typename list_type::node_type ListNode_t;
52 
53  typedef typename list_type::glob_mem_type
54  glob_mem_type;
55 
57 public:
59 
61 public:
62  typedef T value_type;
63  typedef typename std::make_unsigned<index_type>::type size_type;
64  typedef typename std::make_unsigned<index_type>::type difference_type;
65 
66  typedef typename glob_mem_type::local_pointer pointer;
68 
69  typedef typename list_type::local_reference reference;
70  typedef typename list_type::const_local_reference const_reference;
71 
72  typedef typename list_type::local_iterator iterator;
74 
75  typedef std::reverse_iterator< iterator> reverse_iterator;
76  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77 
78 public:
83  list_type * list)
84  : _list(list)
85  { }
86 
89  list_type * list,
91  const ViewSpec_t & viewspec)
92  : _list(list),
93  _viewspec(viewspec)
94  { }
95 
99  inline iterator begin() const noexcept
100  {
101  return _list->_lbegin;
102  }
103 
107  inline iterator end() const noexcept
108  {
109  return _list->_lend;
110  }
111 
112  inline iterator insert(
114  const_iterator position,
116  const value_type & value)
117  {
118  DASH_LOG_TRACE("LocalListRef.insert()");
119  // New element node:
120  ListNode_t node;
121  node.lprev = nullptr;
122  node.lnext = nullptr;
123  node.gprev = _gprev;
124  node.gnext = _gnext;
125  iterator it_insert_end = _list->_end;
127  "dash::LocalListRef.pop_back is not implemented");
128 
129  DASH_LOG_TRACE("LocalListRef.insert >");
130  return it_insert_end;
131  }
132 
139  inline void push_back(const value_type & value)
140  {
141  DASH_LOG_TRACE("LocalListRef.push_back()");
142  // Pointer to new node element:
143  ListNode_t * node_lptr = nullptr;
144  // New element node:
145  ListNode_t node;
146  node.value = value;
147  node.lprev = nullptr;
148  node.lnext = nullptr;
149  node.gprev = _gprev;
150  node.gnext = _gnext;
151  // Local capacity before operation:
152  auto l_cap_old = _list->_globmem->local_size();
153  // Number of local elements before operation:
154  auto l_size_old = _list->_local_sizes.local[0];
155  // Update local size:
156  _list->_local_sizes.local[0]++;
157  // Number of local elements after operation:
158  auto l_size_new = _list->_local_sizes.local[0];
159 
160  DASH_LOG_TRACE_VAR("LocalListRef.push_back", l_cap_old);
161  DASH_LOG_TRACE_VAR("LocalListRef.push_back", l_size_old);
162  if (l_size_new > l_cap_old) {
163  DASH_LOG_TRACE("LocalListRef.push_back",
164  "globmem.grow(", _list->_local_buffer_size, ")");
165  // Acquire local memory for new node:
166  node_lptr = static_cast<ListNode_t *>(
167  _list->_globmem->grow(_list->_local_buffer_size));
168  DASH_ASSERT_GT(_list->_globmem->local_size(), l_cap_old,
169  "local capacity not increased after globmem.grow()");
170  } else {
171  // No allocation required (cast from LocalBucketIter<T> to T *):
172  node_lptr = static_cast<ListNode_t *>(
173  _list->_globmem->lbegin() + l_size_old);
174  }
175  // Local capacity before operation:
176  auto l_cap_new = _list->_globmem->local_size();
177  DASH_LOG_TRACE("LocalListRef.push_back",
178  "node target address:", node_lptr);
179  if (l_size_old > 0) {
180  // Set node predecessor (cast from LocalBucketIter<T> to T *):
181  node.lprev = static_cast<ListNode_t *>(
182  _list->_globmem->lbegin() + (l_size_old - 1));
183  // Set successor of node predecessor to new node:
184  DASH_ASSERT(node.lprev->lnext == nullptr);
185  node.lprev->lnext = node_lptr;
186  DASH_LOG_TRACE_VAR("LocalListRef.push_back", node.lprev->lnext);
187  }
188  DASH_LOG_TRACE_VAR("LocalListRef.push_back", node.lprev);
189  DASH_LOG_TRACE_VAR("LocalListRef.push_back", node.value);
190  DASH_LOG_TRACE_VAR("LocalListRef.push_back", node.lnext);
191  // Copy new node to target address:
192  *node_lptr = node;
193  DASH_LOG_TRACE_VAR("LocalListRef.push_back", l_cap_new);
194  DASH_LOG_TRACE_VAR("LocalListRef.push_back", l_size_new);
195  DASH_LOG_TRACE("LocalListRef.push_back >");
196  }
197 
202  void pop_back()
203  {
205  "dash::LocalListRef.pop_back is not implemented");
206  }
207 
211  reference back()
212  {
214  "dash::LocalListRef._back is not implemented");
215  }
216 
223  inline void push_front(const value_type & value)
224  {
226  "dash::ListLocalRef.push_front is not implemented");
227  }
228 
233  void pop_front()
234  {
236  "dash::LocalListRef.pop_front is not implemented");
237  }
238 
242  reference front()
243  {
245  "dash::LocalListRef.front is not implemented");
246  }
247 
251  inline size_type size() const noexcept
252  {
253  return _list->lsize();
254  }
255 
261  constexpr bool is_local(
263  index_type global_index) const
264  {
265  return true;
266  }
267 
268 private:
270  list_type * const _list;
272  ViewSpec_t _viewspec;
273 
274  dart_gptr_t _gprev{};
275  dart_gptr_t _gnext{};
276 };
277 
278 } // namespace dash
279 
280 #endif // DASH__LIST__LOCAL_LIST_REF_H__INCLUDED
reference back()
Accesses the last element in the list.
Definition: LocalListRef.h:211
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
void pop_front()
Removes and destroys the first element in the list, reducing the container size by one...
Definition: LocalListRef.h:233
reference front()
Accesses the first element in the list.
Definition: LocalListRef.h:242
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
size_type size() const noexcept
Number of list elements in local memory.
Definition: LocalListRef.h:251
iterator end() const noexcept
Pointer past final local element in the list.
Definition: LocalListRef.h:107
void push_back(const value_type &value)
Inserts a new element at the end of the list, after its current last element.
Definition: LocalListRef.h:139
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
Definition: Types.h:59
iterator insert(const_iterator position, const value_type &value)
Definition: LocalListRef.h:112
dash::default_index_t index_type
Type definitions required for dash::List concept:
Definition: LocalListRef.h:58
local_pointer grow(size_type num_elements)
Increase capacity of local segment of global memory region by the given number of elements...
Definition: GlobHeapMem.h:485
DART Global pointer type.
Definition: dart_globmem.h:77
constexpr size_type local_size() const noexcept
Number of elements in local memory space.
Definition: GlobHeapMem.h:430
LocalListRef(list_type *list)
Constructor, creates a local access proxy for the given list.
Definition: LocalListRef.h:82
LocalListRef(list_type *list, const ViewSpec_t &viewspec)
Definition: LocalListRef.h:87
void pop_back()
Removes and destroys the last element in the list, reducing the container size by one...
Definition: LocalListRef.h:202
T value_type
Type definitions required for std::list concept:
Definition: LocalListRef.h:62
iterator begin() const noexcept
Pointer to initial local element in the list.
Definition: LocalListRef.h:99
constexpr bool is_local(index_type global_index) const
Checks whether the given global index is local to the calling unit.
Definition: LocalListRef.h:261
constexpr size_type lsize() const noexcept
The number of elements in the local part of the list.
Definition: List.h:549
void push_front(const value_type &value)
Inserts a new element at the beginning of the list, before its current first element.
Definition: LocalListRef.h:223
local_pointer & lbegin() noexcept
Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapM...
Definition: GlobHeapMem.h:831
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732