00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef BOXLAYOUT_H
00029 #define BOXLAYOUT_H
00030
00031 #ifndef WRAPPER
00032 #include "Box.H"
00033 #include "Vector.H"
00034 class DataIterator;
00035 class LayoutIterator;
00036 #include "RefCountedPtr.H"
00037 #include "DataIndex.H"
00038 #include "SPMD.H"
00039 #endif
00040
00041
00042
00044
00092 class BoxLayout
00093 {
00094 public:
00096 BoxLayout();
00097
00099
00102 BoxLayout(const Vector<Box>& a_boxes,
00103 const Vector<int>& a_procIDs);
00104
00106
00111 virtual
00112 ~BoxLayout();
00113
00115
00117 BoxLayout& operator=(const BoxLayout& a_rhs);
00118
00120
00126 virtual void
00127 define(const Vector<Box>& a_boxes,
00128 const Vector<int>& a_procIDs);
00129
00130
00132
00134 const Box&
00135 operator[](const LayoutIndex& it) const;
00136
00138 Box&
00139 operator[](const LayoutIndex& it);
00140
00142
00145 inline bool
00146 operator==(const BoxLayout& rhs) const ;
00147 bool eq(const BoxLayout& rhs) const { return *this == rhs;}
00148
00149
00150
00151 bool check(const LayoutIndex& index) const
00152 { return index.m_layoutIntPtr == m_layout;}
00153
00154
00156
00160 DataIndex
00161 addBox(const Box& box, int procID);
00162
00164
00166 virtual void
00167 close();
00168
00170
00195 virtual void
00196 deepCopy(const BoxLayout& a_source);
00197
00199
00203 Box get(const LayoutIndex& it) const;
00204
00205
00208 bool
00209 isClosed() const;
00210
00211
00213
00215 bool
00216 isSorted() const {return isClosed();}
00217
00219
00220
00221 DataIterator
00222 dataIterator() const;
00223
00225
00227 LayoutIterator
00228 layoutIterator() const;
00229
00231 #ifndef WRAPPER
00232 void
00233 print() const;
00234 #endif
00235 void p() const { print();}
00236
00238
00245 unsigned int
00246 procID(const LayoutIndex& a_index) const ;
00247
00249
00250
00251 int numBoxes(const int procID) const;
00252
00254
00257 void
00258 setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00259
00261 inline unsigned int
00262 size() const ;
00263
00264
00265
00267
00270 void
00271 sort();
00272
00274
00280 friend void coarsen(BoxLayout& output, const BoxLayout& input, int refinement);
00281
00283
00285 friend void refine(BoxLayout& output, const BoxLayout& input, int refinement);
00286
00287 struct Entry
00288 {
00289 Entry(): m_procID(::procID()){;}
00290 Entry(const Box& a_box)
00291 :box(a_box), m_procID(::procID()){}
00292 Entry(const Box& a_box, const unsigned int a_index)
00293 :box(a_box), index(a_index), m_procID(::procID()){}
00294 bool operator < (const Entry& rhs) const
00295 { return box < rhs.box;}
00296
00297 Box box;
00298 unsigned int index;
00299 unsigned int m_procID;
00300 };
00301
00302
00303 unsigned int index(const LayoutIndex& index) const;
00304
00305 protected:
00306
00307 void setIndexVector();
00308 friend class LayoutIterator;
00309 friend class DataIterator;
00310
00311 RefCountedPtr<Vector<Entry> > m_boxes;
00312 RefCountedPtr<Vector<unsigned int> > m_index;
00313 RefCountedPtr<int> m_layout;
00314 RefCountedPtr<bool> m_closed;
00315 RefCountedPtr<DataIterator> m_dataIterator;
00316
00317 private:
00318
00319 };
00320
00321 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00322
00323 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00324
00325 #ifndef WRAPPER
00326
00327 inline
00328 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00329 { coarsen(output, input, refinement);}
00330
00331 inline
00332 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00333 { refine(output, input, refinement);}
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 inline const Box&
00369 BoxLayout::operator[](const LayoutIndex& index) const
00370 {
00371 assert(check(index));
00372 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00373 }
00374
00375 inline Box&
00376 BoxLayout::operator[](const LayoutIndex& index)
00377 {
00378 if(*m_closed)
00379 {
00380 MayDay::Error("attempt to modify closed BoxLayout");
00381 }
00382 assert(check(index));
00383 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00384 }
00385
00386 inline bool
00387 BoxLayout::operator==(const BoxLayout& rhs) const
00388 {
00389 return m_boxes == rhs.m_boxes;
00390 }
00391
00392
00393
00394
00395
00396
00397 inline Box
00398 BoxLayout::get(const LayoutIndex& index) const
00399 {
00400 assert(check(index));
00401 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00402 }
00403
00404 inline unsigned int
00405 BoxLayout::index(const LayoutIndex& a_index) const
00406 {
00407 return m_index->operator[](a_index.m_index);
00408 }
00409
00410 inline bool
00411 BoxLayout::isClosed() const
00412 {
00413 return *m_closed;
00414 }
00415
00416 inline unsigned int
00417 BoxLayout::procID(const LayoutIndex& a_index) const
00418 {
00419 assert(check(a_index));
00420 return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00421 }
00422
00423 inline void
00424 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00425 {
00426 assert(check(a_index));
00427 m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00428 }
00429
00430 inline unsigned int
00431 BoxLayout::size() const
00432 {
00433 return m_boxes->size();
00434 }
00435
00436
00437
00438
00439
00440 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00441
00442 #endif
00443
00444
00445 #endif // DATAPLAN_H
00446