Peano
Loading...
Searching...
No Matches
STDVectorStackOverSmartPointers.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include <algorithm>
6#include <vector>
7
8#include "stacks.h"
9#include "STDVectorStack.h"
10#include "tarch/Assertions.h"
14#include "tarch/logging/Log.h"
16#include "tarch/mpi/Rank.h"
18
19namespace peano4 {
20 namespace stacks {
21 template <class T>
22 class STDVectorStackOverSmartPointers;
23 } // namespace stacks
24} // namespace peano4
25
91template <class T>
93private:
98
102 std::vector<T> _data;
103
109 typename T::DoFType* _gatheredData;
110
119
127
131
132#ifdef Parallel
133 MPI_Request* _ioMPIRequest;
136#endif
137
142 void gather();
143
152
164 void scatter();
165
170
180
181public:
183
185
193
212
219 protected:
224
225 std::vector<T> _data;
226
231 const int remainingElements = parentStack->size() - numberOfElements;
232
233 _data.insert(
234 _data.end(),
235 std::make_move_iterator(parentStack->_data.begin() + remainingElements),
236 std::make_move_iterator(parentStack->_data.end())
237 );
238 parentStack->_data.erase(parentStack->_data.begin() + remainingElements, parentStack->_data.end());
239 }
240
241 public:
242 int size() const { return _data.size(); }
243
244 const T& get(int index) const {
245 assertion2(index >= 0, index, size());
246 assertion2(index < size(), index, size());
247 return _data[index];
248 }
249
250 T& get(int index) {
251 assertion2(index >= 0, index, size());
252 assertion2(index < size(), index, size());
253 return _data[index];
254 }
255
256 std::string toString() const {
257 std::ostringstream msg;
258 msg << "(size=" << size() << ")";
259 return msg.str();
260 }
261 };
262
264 protected:
266
268
269 const int _size;
270 const int _baseElement;
271
278 _parentStack(parentStack),
279 _size(numberOfElements),
280 _baseElement(parentStack->_data.size()) {}
281
282 public:
283 int size() const { return _size; }
284
295 T* set(int index, const T& value) {
296 assertion2(index >= 0, index, _size);
297 assertion2(index < _size, index, _size);
298 _parentStack->_data[_baseElement + index] = value;
299 return &(_parentStack->_data[_baseElement + index]);
300 }
301
302 const T& get(int index) const {
303 assertion2(index >= 0, index, _size);
304 assertion2(index < _size, index, _size);
305 return _parentStack->_data[_baseElement + index];
306 }
307
308 T& get(int index) {
309 assertion2(index >= 0, index, _size);
310 assertion2(index < _size, index, _size);
311 return _parentStack->_data[_baseElement + index];
312 }
313
314 std::string toString() const {
315 std::ostringstream msg;
316 msg << "(size=" << _size << ",baseElement=" << _baseElement << ")";
317 return msg.str();
318 }
319 };
320
328 T pop();
329
335 T& top(int shift = 0);
336
342 const T& top(int shift = 0) const;
343
347 void push(const T& element);
348
356 PopBlockStackView popBlock(int numberOfElements);
357
363 PushBlockStackView pushBlock(int numberOfElements);
364
365 int size() const;
366
367 bool empty() const;
368
369 void clear();
370
400 void startSend(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm);
401
415 peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements
416 );
417
442
450
458 void reverse();
459
460 std::string toString() const;
461};
462
463#include "STDVectorStackOverSmartPointers.cpph"
#define assertion2(expr, param0, param1)
#define assertion(expr)
SendReceiveContext
There are three different scenarios when we merge data:
PopBlockStackView(int numberOfElements, peano4::stacks::STDVectorStackOverSmartPointers< T > *parentStack)
Constructor.
PushBlockStackView(int numberOfElements, peano4::stacks::STDVectorStackOverSmartPointers< T > *parentStack)
Constructor.
This stack hosts data of constant size which are stored on the heap and subject to smart pointers.
void startReceive(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements)
Counterpart of startSend()
void push(const T &element)
Pushes element to a stack.
bool tryToFinishSendOrReceive()
Semantics are alost an exact 1:1 copy of the superclass implementation.
PushBlockStackView pushBlock(int numberOfElements)
Push a block on the output stack.
STDVectorStackOverSmartPointers(const STDVectorStackOverSmartPointers< T > &)
const T & top(int shift=0) const
Get top element or shiftth top element.
void clone(const STDVectorStackOverSmartPointers< T > &data)
Clone data into the current object on which clone() is called.
void startSend(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm)
Start the actual send process.
void scatter()
Scatter received gathered data.
void gatherMetaData()
Allocate buffer and gather.
void gather()
Allocate buffer and gather.
PopBlockStackView popBlock(int numberOfElements)
This operation grabs numberOfElements from the input stack en block and returns a view to it.
int sendingOrReceiving() const
I need this one to find out whether I'm waiting for data.
T & top(int shift=0)
Get top element or shiftth top element.
int * _gatheredMetaData
Meta data with size of memory chunks.
void reverse()
Reversing a stream is something I need extremely rarely.
STDVectorStackOverSmartPointers< T > & operator=(const STDVectorStackOverSmartPointers< T > &stack)
One is allowed to copy a stack but it has to be empty.
std::vector< T > _data
This is the attribute holding all the temporary stacks.
Log Device.
Definition Log.h:517