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 #ifndef DOXYGEN
00042
00043 struct Entry
00044 {
00045 Entry(): m_procID(procID()){;}
00046 Entry(const Box& a_box)
00047 :box(a_box), m_procID(procID()){}
00048 Entry(const Box& a_box, const unsigned int a_index)
00049 :box(a_box), index(a_index), m_procID(procID()){}
00050 bool operator < (const Entry& rhs) const
00051 { return box < rhs.box;}
00052
00053 Box box;
00054 unsigned int index;
00055 unsigned int m_procID;
00056 };
00057
00058 #endif
00059
00061
00116 class BoxLayout
00117 {
00118 public:
00119
00124
00126
00129 BoxLayout();
00130
00132
00135 BoxLayout(const Vector<Box>& a_boxes,
00136 const Vector<int>& a_procIDs);
00137
00139
00144 virtual
00145 ~BoxLayout();
00146
00148
00151 BoxLayout& operator=(const BoxLayout& a_rhs);
00152
00154
00160 virtual void
00161 define(const Vector<Box>& a_boxes,
00162 const Vector<int>& a_procIDs);
00163
00164
00171
00173
00175 const Box&
00176 operator[](const LayoutIndex& it) const;
00177
00179
00181 Box&
00182 operator[](const LayoutIndex& it);
00183
00185
00192 Box get(const LayoutIndex& it) const;
00193
00195
00197 Box get(const LayoutIterator& it) const;
00198
00200
00202 Box get(const DataIterator& it) const;
00203
00205
00213 unsigned int
00214 procID(const LayoutIndex& a_index) const ;
00215
00217
00219 int numBoxes(const int procID) const;
00220
00222
00224 inline unsigned int
00225 size() const ;
00226
00229 unsigned int index(const LayoutIndex& index) const;
00230
00237
00239
00242 inline bool
00243 operator==(const BoxLayout& rhs) const ;
00244
00246
00249 bool eq(const BoxLayout& rhs) const { return *this == rhs;}
00250
00251
00255 bool
00256 isClosed() const;
00257
00259
00261 bool
00262 isSorted() const {return isClosed();}
00263
00266 bool check(const LayoutIndex& index) const
00267 { return index.m_layoutIntPtr == m_layout;}
00268
00269
00276
00278
00282 DataIndex
00283 addBox(const Box& box, int procID);
00284
00286
00288 virtual void
00289 close();
00290
00292
00317 virtual void
00318 deepCopy(const BoxLayout& a_source);
00319
00321
00327 bool coarsenable(int refRatio) const;
00328
00330
00345 friend void coarsen(BoxLayout& output,
00346 const BoxLayout& input,
00347 int refinement);
00348
00350
00365 friend void refine(BoxLayout& output,
00366 const BoxLayout& input,
00367 int refinement);
00368
00370
00373 void
00374 setProcID(const LayoutIndex& a_index, unsigned int a_procID);
00375
00376
00378
00382 void
00383 sort();
00384
00387 void aliasAddBox(const Box& box);
00388
00391 void aliasClose();
00392
00399
00401
00405 DataIterator
00406 dataIterator() const;
00407
00409
00413 LayoutIterator
00414 layoutIterator() const;
00415
00422
00423 #ifndef WRAPPER
00424
00425
00428 void
00429 print() const;
00430 #endif
00431
00432
00435 void p() const { print();}
00436
00439 protected:
00440
00441 void setIndexVector();
00442 friend class LayoutIterator;
00443 friend class DataIterator;
00444
00445 RefCountedPtr<Vector<Entry> > m_boxes;
00446 RefCountedPtr<Vector<unsigned int> > m_index;
00447 RefCountedPtr<int> m_layout;
00448 RefCountedPtr<bool> m_closed;
00449 RefCountedPtr<DataIterator> m_dataIterator;
00450
00451 private:
00452
00453 };
00454
00455 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00456
00457 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement);
00458
00459 #ifndef WRAPPER
00460
00461 inline
00462 void coarsen_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00463 { coarsen(output, input, refinement);}
00464
00465 inline
00466 void refine_bl(BoxLayout& output, const BoxLayout& input, int refinement)
00467 { refine(output, input, refinement);}
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 inline const Box&
00503 BoxLayout::operator[](const LayoutIndex& index) const
00504 {
00505 assert(check(index));
00506 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00507 }
00508
00509 inline Box&
00510 BoxLayout::operator[](const LayoutIndex& index)
00511 {
00512 if(*m_closed)
00513 {
00514 MayDay::Error("attempt to modify closed BoxLayout");
00515 }
00516 assert(check(index));
00517 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00518 }
00519
00520 inline bool
00521 BoxLayout::operator==(const BoxLayout& rhs) const
00522 {
00523 return m_boxes == rhs.m_boxes;
00524 }
00525
00526
00527
00528
00529
00530
00531 inline Box
00532 BoxLayout::get(const LayoutIndex& index) const
00533 {
00534 assert(check(index));
00535 return m_boxes->operator[](m_index->operator[](index.m_index)).box;
00536 }
00537
00538 inline unsigned int
00539 BoxLayout::index(const LayoutIndex& a_index) const
00540 {
00541 return m_index->operator[](a_index.m_index);
00542 }
00543
00544 inline bool
00545 BoxLayout::isClosed() const
00546 {
00547 return *m_closed;
00548 }
00549
00550 inline unsigned int
00551 BoxLayout::procID(const LayoutIndex& a_index) const
00552 {
00553 assert(check(a_index));
00554 return m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID;
00555 }
00556
00557 inline void
00558 BoxLayout::setProcID(const LayoutIndex& a_index, unsigned int a_procID)
00559 {
00560 assert(check(a_index));
00561 m_boxes->operator[](m_index->operator[](a_index.m_index)).m_procID = a_procID;
00562 }
00563
00564 inline unsigned int
00565 BoxLayout::size() const
00566 {
00567 return m_boxes->size();
00568 }
00569
00570
00571
00572
00573
00574 std::ostream& operator<<(std::ostream& os, const BoxLayout& a_layout);
00575
00576 #endif
00577
00578 #endif // DATAPLAN_H