forked from applied-numerical-algorithms-group-lbnl/Chombo_4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChombo_DataIterator.H
330 lines (260 loc) · 7.49 KB
/
Chombo_DataIterator.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#ifdef CH_LANG_CC
/*
* _______ __
* / ___/ / ___ __ _ / / ___
* / /__/ _ \/ _ \/ V \/ _ \/ _ \
* \___/_//_/\___/_/_/_/_.__/\___/
* Please refer to Copyright.txt, in Chombo's root directory.
*/
#endif
#ifndef _Chombo_DATAITERATOR_H_
#define _Chombo_DATAITERATOR_H_
#include "Chombo_Vector.H"
#include "Chombo_DataIndex.H"
#include "Chombo_BoxLayout.H"
#include "Chombo_SPMD.H"
#include "Chombo_LayoutIterator.H"
#include "Chombo_NamespaceHeader.H"
#ifdef CH_MPI
///An Iterator based on a BoxLayout object.
/**
An Iterator based on a BoxLayout object. It does not
support a dereferencing operation, since it is intended
to work with all of BoxLayouts, DisjointBoxLayouts, BoxLayoutDatas
LevelDatas, and any object that is built on top
of a BoxLayout object.
DataIterator accesses the data in a BoxLayout-based
object in a <b> data-parallel </b> manner.
This means that it skips over entries for Boxes not
assigned to this processor. The order of access is not defined.
In serial execution mode, there is no difference between
DataIterator and LayoutIterator.
*/
class DataIterator
{
//Note: parallel version doesn't inherit LayoutIterator, serial version does
public:
/// a null constructed DataIterator will return false on ok()
DataIterator();
DataIterator(const BoxLayout& a_layout)
{
*this = a_layout.dataIterator();
}
virtual ~DataIterator()
{}
/// return the index that this iterator is at
/** Aborts if the iterator is not ok() */
const DataIndex& operator()() const ;
/// return a copy of the index that this iterator is at
/** Aborts if the iterator is not ok() */
DataIndex i() const
{
return this->operator()();
}
DataIndex operator[](int ivec) const;
/// move the iterator to the next index in the layout
virtual void operator++();
/// move the iterator to the next index in the layout
void incr()
{
++(*this);
}
/// return true if this iterator is still in the layout
virtual bool ok() const;
/// initialize this iterator to the first index in the layout
void begin();
/// same as begin()
void reset();
/// move this iterator to after the last index in the layout
/** The iterator will be !ok() afterwards. */
void end();
int size() const
{
return m_indices->size();
}
///functions for using measurements of time and memory for load balancing.
///sets m_time values to zero
void clearTime();
//sets memory measurement to zero
void clearPeak();
///gets current time data
Vector<unsigned long long> getTime() const
{
return m_time;
}
///gets current memory data
Vector<unsigned long long> getPeak() const
{
return m_peak;
}
Vector<Box> getBoxes()
{
return m_layout.boxArray();
}
///enables timing. does not set to zero. use clear time for that
void enableTime()
{
//only defines if not defined before
defineTime();
m_timeEnabled = true;
}
///enables measurements based on how much peak memory moves
void enablePeak()
{
//only defines if not defined before
definePeak();
m_peakEnabled = true;
}
///turns off timing
void disableTime()
{
m_timeEnabled = false;
}
///turns off memory measurement
void disablePeak()
{
m_peakEnabled = false;
}
/// After you are finished timing your local elements, call mergeTimes to fill-in off-processor times.
void mergeTime();
/// After you are finished measuring the memory your local elements, call mergeTimes to fill-in off-processor times.
void mergePeak();
private:
friend class BoxLayout;
friend class DisjointBoxLayout;
friend class TimedDataIterator;
DataIterator(const BoxLayout& boxlayout, const int* layoutID);
BoxLayout m_layout;
// RefCountedPtr<Vector<DataIndex> > m_indices;
protected:
const Vector<DataIndex>* m_indices;
int m_current;
void defineTime();
void definePeak();
Vector<unsigned long long> m_time;
Vector<unsigned long long> m_peak;
bool m_timeEnabled;
bool m_timeDefined;
bool m_peakEnabled;
bool m_peakDefined;
unsigned long long m_startTime;
unsigned long long m_startPeak;
};
#else
// serial version
class DataIterator : public LayoutIterator
{
public:
virtual ~DataIterator()
{}
DataIterator()
{}
DataIterator(const BoxLayout& a_layout)
{
*this = a_layout.dataIterator();
}
/// return the index that this iterator is at
/** Aborts if the iterator is not ok() */
const DataIndex& operator()() const
{
return (const DataIndex&)(LayoutIterator::operator()());
};
/// return a copy of the index that this iterator is at
/** Aborts if the iterator is not ok() */
DataIndex i() const
{
return this->operator()();
}
int size() const
{
return this->m_layout.size();
}
DataIndex operator[](int ivec) const
{
return (DataIndex)((*m_indicies)[ivec]);
}
///load balancing function. no-op in serial
void clearTime()
{
}
///load balancing function. no-op in serial
void clearPeak()
{
}
///load balancing function. no-op in serial
Vector<unsigned long long> getTime() const
{
unsigned long long val = 1;
Vector<unsigned long long> retval(m_layout.size(), val);
return retval;
}
Vector<unsigned long long> getPeak() const
{
unsigned long long val = 1;
Vector<unsigned long long> retval(m_layout.size(), val);
return retval;
}
Vector<Box> getBoxes() const
{
return m_layout.boxArray();
}
///load balancing function. no-op in serial
void enableTime()
{
}
void enablePeak()
{
}
///load balancing function. no-op in serial
void disableTime()
{
}
void disablePeak()
{
}
///load balancing function. no-op in serial
void mergeTime()
{
}
void mergePeak()
{
}
private:
friend class BoxLayout;
friend class DisjointBoxLayout;
friend class TimedDataIterator;
protected:
DataIterator(const BoxLayout& boxlayout, const int* layoutID)
:LayoutIterator(boxlayout, layoutID)
{}
};
#define DATAITERATOR(CLASS, BOXLAYOUT) \
DataIterator dit = BOXLAYOUT .dataIterator(); \
for (dit.begin(); dit.ok(); ++dit) \
{ \
DataIndex di = dit(); \
MT_BEGIN1(CLASS, DataIndex, di)
#define ENDITERATOR(CLASS) \
MT_END1(CLASS, DataIndex, di) \
}
#define DATAITERATOR1(CLASS, BOXLAYOUT, TYPE1, VAL1) \
DataIterator dit = BOXLAYOUT .dataIterator(); \
for (dit.begin(); dit.ok(); ++dit) \
{ \
DataIndex di = dit(); \
MT_BEGIN2(CLASS, TYPE1, VAL1, DataIndex, di)
#define ENDITERATOR1(CLASS, TYPE1, VAL1) \
MT_END2(CLASS, TYPE1, VAL1, DataIndex, di) \
}
#define DATAITERATOR2(CLASS, BOXLAYOUT, TYPE1, VAL1, TYPE2, VAL2) \
DataIterator dit = BOXLAYOUT .dataIterator(); \
for (dit.begin(); dit.ok(); ++dit) \
{ \
DataIndex di = dit(); \
MT_BEGIN3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di)
#define ENDITERATOR2(CLASS, TYPE1, VAL1, TYPE2, VAL2) \
MT_END3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di) \
}
#endif
#include "Chombo_NamespaceFooter.H"
#endif