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    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 #ifndef _DATAITERATOR_H_
00053 #define _DATAITERATOR_H_
00054 
00055 #include "DataIndex.H"
00056 #include "BoxLayout.H"
00057 #include "SPMD.H"
00058 
00059 #ifdef MPI
00060 
00062 
00077 class DataIterator
00078 {
00079   //Note: parallel version doesn't inherit LayoutIterator, serial version does
00080 public:
00081 
00083   DataIterator();
00084 
00085   DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}
00086 
00087   ~DataIterator()
00088   {}
00089 
00091 
00092   inline const DataIndex& operator()() const ;
00094 
00095   DataIndex i() const { return this->operator()();}
00096 
00098   inline void operator++();
00100   void incr() { ++(*this);}
00101 
00103   bool ok() const;
00104 
00106   void begin();
00107 
00109   void reset();
00110 
00112 
00113   void end();
00114 
00115 private:
00116 
00117   friend class BoxLayout;
00118   friend class DisjointBoxLayout;
00119 
00120   DataIterator(const BoxLayout& boxlayout, const int* layoutID);
00121 
00122   BoxLayout m_layout;
00123 
00124   unsigned int m_index;
00125 
00126   DataIndex m_current;
00127 
00128   unsigned int m_procID;
00129 
00130 };
00131 
00132 inline DataIterator::DataIterator()
00133   : m_index(0), m_procID(0)
00134 {}
00135 
00136 inline const DataIndex& DataIterator::operator()() const
00137 {
00138   assert(ok());
00139   return m_current;
00140 }
00141 
00142 inline void DataIterator::operator++()
00143 {
00144   const Entry* box;
00145   while(++m_index < m_layout.size())
00146     {
00147       box = &(*(m_layout.m_boxes))[m_index];
00148       if(box->m_procID == m_procID)
00149         {
00150           m_current.m_index = box->index;
00151           return;
00152         }
00153     }
00154 
00155 }
00156 
00157 inline bool DataIterator::ok() const
00158 {
00159   return m_index < m_layout.size();
00160 }
00161 
00162 inline void DataIterator::reset()
00163 {
00164   begin();
00165 }
00166 
00167 inline void DataIterator::begin()
00168 {
00169   m_index = 0;
00170   const Entry* box;
00171   while(m_index < m_layout.size())
00172     {
00173       box = &(*(m_layout.m_boxes))[m_index];
00174       if(box->m_procID == m_procID)
00175         {
00176           m_current.m_index = box->index;
00177           return;
00178         }
00179       ++m_index;
00180     }
00181 }
00182 
00183 #else
00184 
00185 // serial version
00186 #include "LayoutIterator.H"
00187 
00188 class DataIterator : public LayoutIterator
00189 {
00190 public:
00191   DataIterator()
00192   {}
00193 
00194   DataIterator(const BoxLayout& a_layout){*this = a_layout.dataIterator();}
00195 
00197 
00198   const DataIndex& operator()() const
00199   {
00200     return (const DataIndex&)(LayoutIterator::operator()());
00201   };
00202 
00204 
00205   DataIndex i() const {return this->operator()();}
00206 
00207 private:
00208   friend class BoxLayout;
00209   friend class DisjointBoxLayout;
00210 
00211   DataIterator(const BoxLayout& boxlayout, const int* layoutID)
00212     :
00213     LayoutIterator(boxlayout, layoutID)
00214   {}
00215 };
00216 
00217 #endif  /*MPI*/
00218 
00219 #define DATAITERATOR(CLASS, BOXLAYOUT) \
00220         DataIterator dit = BOXLAYOUT .dataIterator(); \
00221         for(dit.begin(); dit.ok(); ++dit) {     \
00222         DataIndex di = dit();                   \
00223         MT_BEGIN1(CLASS, DataIndex, di)
00224 
00225 #define ENDITERATOR(CLASS)  \
00226         MT_END1(CLASS, DataIndex, di) \
00227         }
00228 
00229 #define DATAITERATOR1(CLASS, BOXLAYOUT, TYPE1, VAL1) \
00230         DataIterator dit = BOXLAYOUT .dataIterator(); \
00231         for(dit.begin(); dit.ok(); ++dit) {     \
00232         DataIndex di = dit();                   \
00233         MT_BEGIN2(CLASS, TYPE1, VAL1, DataIndex, di)
00234 
00235 #define ENDITERATOR1(CLASS, TYPE1, VAL1)  \
00236         MT_END2(CLASS, TYPE1, VAL1, DataIndex, di) \
00237         }
00238 
00239 #define DATAITERATOR2(CLASS, BOXLAYOUT, TYPE1, VAL1, TYPE2, VAL2) \
00240         DataIterator dit = BOXLAYOUT .dataIterator(); \
00241         for(dit.begin(); dit.ok(); ++dit) {     \
00242         DataIndex di = dit();                   \
00243         MT_BEGIN3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di)
00244 
00245 #define ENDITERATOR2(CLASS, TYPE1, VAL1, TYPE2, VAL2)  \
00246         MT_END3(CLASS, TYPE1, VAL1, TYPE2, VAL2, DataIndex, di) \
00247         }
00248 
00249 #endif

Generated on Wed Jan 19 17:51:23 2005 for Chombo&INSwithParticles by doxygen1.2.16