Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

DataIterator.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 //
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef _DATAITERATOR_H_
00029 #define _DATAITERATOR_H_
00030 
00031 
00032 #include "DataIndex.H"
00033 #include "BoxLayout.H"
00034 #include "SPMD.H"
00035 
00036 
00037 #ifdef MPI
00038 
00040 
00055 class DataIterator
00056 {
00057   //Note: parallel version doesn't inherit LayoutIterator, serial version does
00058 public:
00059 
00061   DataIterator();
00062 
00063   DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}
00064 
00065   ~DataIterator() {;}
00066 
00068 
00069   inline const DataIndex& operator()() const ;
00071 
00072   DataIndex i() const { return this->operator()();}
00073 
00075   inline void operator++();
00077   void incr() { ++(*this);}
00078 
00080   bool ok() const;
00081 
00083   void begin();
00084 
00086   void reset();
00087 
00089 
00090   void end();
00091 
00092 private:
00093 
00094   friend class BoxLayout;
00095   friend class DisjointBoxLayout;
00096 
00097   DataIterator(const BoxLayout& boxlayout, const int* layoutID);
00098 
00099   BoxLayout m_layout;
00100 
00101   unsigned int m_index;
00102 
00103   DataIndex m_current;
00104 
00105   unsigned int m_procID;
00106 
00107 };
00108 
00109 
00110 inline DataIterator::DataIterator()
00111   : m_index(0), m_procID(0)
00112 {}
00113 
00114 
00115 inline const DataIndex& DataIterator::operator()() const
00116 {
00117   assert(ok());
00118   return m_current;
00119 }
00120 
00121 inline void DataIterator::operator++()
00122 {
00123   const Entry* box;
00124   while(++m_index < m_layout.size())
00125     {
00126       box = &(*(m_layout.m_boxes))[m_index];
00127       if(box->m_procID == m_procID)
00128         {
00129           m_current.m_index = box->index;
00130           return;
00131         }
00132     }
00133 
00134 }
00135 
00136 inline bool DataIterator::ok() const
00137 {
00138   return m_index < m_layout.size();
00139 }
00140 
00141 
00142 
00143 inline void DataIterator::reset()
00144 {
00145   begin();
00146 }
00147 
00148 inline void DataIterator::begin()
00149 {
00150   m_index = 0;
00151   const Entry* box;
00152   while(m_index < m_layout.size())
00153     {
00154       box = &(*(m_layout.m_boxes))[m_index];
00155       if(box->m_procID == m_procID)
00156         {
00157           m_current.m_index = box->index;
00158           return;
00159         }
00160       ++m_index;
00161     }
00162 }
00163 
00164 #else
00165 
00166 // serial version
00167 #include "LayoutIterator.H"
00168 
00169 class DataIterator : public LayoutIterator
00170 {
00171 public:
00172   DataIterator(){;}
00173   DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}
00174 
00176 
00177   const DataIndex& operator()() const
00178   {
00179     return (const DataIndex&)(LayoutIterator::operator()());
00180   };
00181 
00183 
00184   DataIndex i() const {return this->operator()();}
00185 
00186 private:
00187   friend class BoxLayout;
00188   friend class DisjointBoxLayout;
00189 
00190   DataIterator(const BoxLayout& boxlayout, const int* layoutID)
00191         : LayoutIterator(boxlayout, layoutID) {;}
00192 };
00193 
00194 #endif  /*MPI*/
00195 
00196 
00197 #define DATAITERATOR(CLASS, BOXLAYOUT) \
00198         DataIterator dit = BOXLAYOUT .dataIterator(); \
00199         for(dit.begin(); dit.ok(); ++dit) {     \
00200         DataIndex di = dit();                   \
00201         MT_BEGIN1(CLASS, DataIndex, di)
00202 
00203 #define ENDITERATOR(CLASS)  \
00204         MT_END1(CLASS, DataIndex, di) \
00205         }
00206 
00207 #define DATAITERATOR1(CLASS, BOXLAYOUT, TYPE1, VAL1) \
00208         DataIterator dit = BOXLAYOUT .dataIterator(); \
00209         for(dit.begin(); dit.ok(); ++dit) {     \
00210         DataIndex di = dit();                   \
00211         MT_BEGIN2(CLASS, TYPE1, VAL1, DataIndex, di)
00212 
00213 #define ENDITERATOR1(CLASS, TYPE1, VAL1)  \
00214         MT_END2(CLASS, TYPE1, VAL1, DataIndex, di) \
00215         }
00216 
00217 #define DATAITERATOR2(CLASS, BOXLAYOUT, TYPE1, VAL1, TYPE2, VAL2) \
00218         DataIterator dit = BOXLAYOUT .dataIterator(); \
00219         for(dit.begin(); dit.ok(); ++dit) {     \
00220         DataIndex di = dit();                   \
00221         MT_BEGIN3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di)
00222 
00223 #define ENDITERATOR2(CLASS, TYPE1, VAL1, TYPE2, VAL2)  \
00224         MT_END3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di) \
00225         }
00226 
00227 #endif

Generated on Wed Jun 2 13:53:32 2004 for Chombo&INSwithParticles by doxygen 1.3.2