Peano
Loading...
Searching...
No Matches
STDVectorStackOverObjectsWithSmartPointers.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 STDVectorStackOverObjectsWithSmartPointers;
23 } // namespace stacks
24} // namespace peano4
25
51template <class T>
53private:
58
62 std::vector<T> _data;
63
64 using FlattenedContainer = std::vector<typename T::FlattenedType>;
65
71
74 int _ioTag;
75
76#ifdef Parallel
77 MPI_Request* _ioMPIRequest;
78#endif
79
80public:
82
84
92
111
118 protected:
123
124 std::vector<T> _data;
125
130 const int remainingElements = parentStack->size() - numberOfElements;
131
132 _data.insert(
133 _data.end(),
134 std::make_move_iterator(parentStack->_data.begin() + remainingElements),
135 std::make_move_iterator(parentStack->_data.end())
136 );
137 parentStack->_data.erase(parentStack->_data.begin() + remainingElements, parentStack->_data.end());
138 }
139
140 public:
141 int size() const { return _data.size(); }
142
143 const T& get(int index) const {
144 assertion2(index >= 0, index, size());
145 assertion2(index < size(), index, size());
146 return _data[index];
147 }
148
149 T& get(int index) {
150 assertion2(index >= 0, index, size());
151 assertion2(index < size(), index, size());
152 return _data[index];
153 }
154
155 std::string toString() const {
156 std::ostringstream msg;
157 msg << "(size=" << size() << ")";
158 return msg.str();
159 }
160 };
161
163 protected:
165
167
168 const int _size;
169 const int _baseElement;
170
177 _parentStack(parentStack),
178 _size(numberOfElements),
179 _baseElement(parentStack->_data.size()) {}
180
181 public:
182 int size() const { return _size; }
183
194 T* set(int index, const T& value) {
195 assertion2(index >= 0, index, _size);
196 assertion2(index < _size, index, _size);
197 _parentStack->_data[_baseElement + index] = value;
198 return &(_parentStack->_data[_baseElement + index]);
199 }
200
201 const T& get(int index) const {
202 assertion2(index >= 0, index, _size);
203 assertion2(index < _size, index, _size);
204 return _parentStack->_data[_baseElement + index];
205 }
206
207 T& get(int index) {
208 assertion2(index >= 0, index, _size);
209 assertion2(index < _size, index, _size);
210 return _parentStack->_data[_baseElement + index];
211 }
212
213 std::string toString() const {
214 std::ostringstream msg;
215 msg << "(size=" << _size << ",baseElement=" << _baseElement << ")";
216 return msg.str();
217 }
218 };
219
227 T pop();
228
234 T& top(int shift = 0);
235
241 const T& top(int shift = 0) const;
242
246 void push(const T& element);
247
255 PopBlockStackView popBlock(int numberOfElements);
256
262 PushBlockStackView pushBlock(int numberOfElements);
263
264 int size() const;
265
266 bool empty() const;
267
268 void clear();
269
293 void startSend(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm);
294
310 peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements
311 );
312
336
344
352 void reverse();
353
354 std::string toString() const;
355};
356
357#include "STDVectorStackOverObjectsWithSmartPointers.cpph"
#define assertion2(expr, param0, param1)
#define assertion(expr)
SendReceiveContext
There are three different scenarios when we merge data:
PopBlockStackView(int numberOfElements, peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T > *parentStack)
Constructor.
PushBlockStackView(int numberOfElements, peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T > *parentStack)
Constructor.
Stack over objects, where some of the properties per object are realised through smart pointers.
T & top(int shift=0)
Get top element or shiftth top element.
STDVectorStackOverObjectsWithSmartPointers(const STDVectorStackOverObjectsWithSmartPointers< T > &)
void reverse()
Reversing a stream is something I need extremely rarely.
STDVectorStackOverObjectsWithSmartPointers< T > & operator=(const STDVectorStackOverObjectsWithSmartPointers< 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.
bool tryToFinishSendOrReceive()
Finish a send or receive if it is still pending.
void startReceive(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements)
Trigger a receive.
int sendingOrReceiving() const
I need this one to find out whether I'm waiting for data.
FlattenedContainer _flattenedData
We cannot send out _data, as each element in _data hosts at least one smart pointer.
void startSend(peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm)
Start the actual send process.
PushBlockStackView pushBlock(int numberOfElements)
Push a block on the output stack.
void clone(const STDVectorStackOverObjectsWithSmartPointers< T > &data)
Clone data into the current object on which clone() is called.
const T & top(int shift=0) const
Get top element or shiftth top element.
PopBlockStackView popBlock(int numberOfElements)
This operation grabs numberOfElements from the input stack en block and returns a view to it.
void push(const T &element)
Pushes element to a stack.
Log Device.
Definition Log.h:517