00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef LFIELD_H
00012 #define LFIELD_H
00013
00014
00015 #include "Utility/Pooled.h"
00016 #include "Field/CompressedBrickIterator.h"
00017
00018 #ifdef IPPL_USE_STANDARD_HEADERS
00019 #include <iostream>
00020 using namespace std;
00021 #else
00022 #include <iostream.h>
00023 #endif
00024
00025
00026 template <class T, unsigned Dim> class LField;
00027 template <class T, unsigned Dim>
00028 ostream& operator<<(ostream&, const LField<T,Dim>&);
00029
00030
00031
00032
00033 template <int Dim>
00034 struct ToTheDim
00035 {
00036 inline static int calc(int n)
00037 {
00038 return ToTheDim<Dim-1>::calc(n) * n;
00039 }
00040 };
00041
00042 template<>
00043 struct ToTheDim<1>
00044 {
00045 inline static int calc(int n)
00046 {
00047 return n;
00048 }
00049 };
00050
00051
00053
00054
00055 template<class T, unsigned Dim>
00056 class LField : public Pooled< LField<T,Dim> >
00057 {
00058
00059 public:
00060
00061 typedef CompressedBrickIterator<T,Dim> iterator;
00062
00063
00064 typedef NDIndex<Dim> Domain_t;
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 LField(const NDIndex<Dim>& owned,
00075 const NDIndex<Dim>& allocated,
00076 int vnode = -1);
00077
00078
00079 LField(const LField<T,Dim>&);
00080
00081
00082
00083 ~LField();
00084
00085
00086
00087
00088
00089
00090 int size(unsigned d) const { return Owned[d].length(); }
00091 const NDIndex<Dim>& getAllocated() const { return Allocated; }
00092 const NDIndex<Dim>& getOwned() const { return Owned; }
00093 T* getP() { return P; }
00094
00095
00096 int getVnode() const { return vnode_m; }
00097
00098
00099
00100
00101
00102
00103 const iterator& begin() const { return Begin; }
00104 const iterator& end() const { return End; }
00105
00106
00107 iterator begin(const NDIndex<Dim>& domain);
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 iterator begin(const NDIndex<Dim>& domain, T&);
00121
00122
00123
00124
00125
00126
00127 inline bool IsCompressed() const
00128 {
00129 return P==0;
00130 }
00131
00132
00133
00134
00135
00136 bool TryCompress(bool baseOnPhysicalCells = false);
00137
00138
00139 inline bool CanCompress() const
00140 {
00141 if (!IsCompressed())
00142 return CanCompress(*Begin);
00143 return true;
00144 }
00145
00146
00147
00148
00149
00150 bool CanCompress(T x) const;
00151
00152
00153
00154 inline void Compress()
00155 {
00156 if (!IsCompressed())
00157 Compress(*P);
00158 }
00159
00160
00161 void Compress(const T &val);
00162
00163
00164
00165 inline void Uncompress(bool fill_domain = true)
00166 {
00167 if (IsCompressed())
00168 ReallyUncompress(fill_domain);
00169 }
00170
00171
00172 T &getCompressedData() { return CompressedData; }
00173 const T &getCompressedData() const { return CompressedData; }
00174
00175
00176
00177
00178
00179 bool OverlapCacheInitialized() { return overlapCacheInited; }
00180
00181 void AddToOverlapCache(LField<T, Dim> *newCacheItem)
00182 {
00183 if (overlap.size() == 0)
00184 overlap.reserve(ToTheDim<Dim>::calc(3)-1);
00185 overlap.push_back(newCacheItem);
00186 overlapCacheInited = true;
00187 }
00188
00189 typedef typename vector< LField<T, Dim> *>::iterator OverlapIterator;
00190
00191 OverlapIterator BeginOverlap() { return overlap.begin(); }
00192 OverlapIterator EndOverlap() { return overlap.end(); }
00193
00194
00195
00196
00197
00198 void swapData( LField<T,Dim>& a );
00199
00200
00201
00202
00203
00204
00205 void write(ostream&) const;
00206
00207 private:
00208
00209
00210
00211
00212
00213
00214
00215 int vnode_m;
00216
00217
00218
00219 T* P;
00220
00221
00222
00223 NDIndex<Dim> Owned;
00224
00225
00226
00227 NDIndex<Dim> Allocated;
00228
00229
00230
00231 iterator Begin;
00232
00233
00234
00235 iterator End;
00236
00237
00238
00239 T CompressedData;
00240
00241
00242
00243 vector< LField<T, Dim> * > overlap;
00244 bool overlapCacheInited;
00245
00246
00247
00248
00249
00250
00251
00252 mutable int allocCompressIndex;
00253 mutable int ownedCompressIndex;
00254
00255
00256
00257
00258 long offsetBlocks;
00259
00260
00261
00262 bool CanCompressBasedOnPhysicalCells() const;
00263 void ReallyUncompress(bool fill_domain);
00264 void CompressBasedOnPhysicalCells();
00265
00266
00267
00268
00269 void allocateStorage(int newsize);
00270
00271
00272
00273 void deallocateStorage();
00274
00275
00276
00277 LField();
00278 const LField<T,Dim> &operator=(const LField<T,Dim> &);
00279 };
00280
00281
00282 template<class T, unsigned Dim>
00283 inline
00284 ostream& operator<<(ostream& out, const LField<T,Dim>& a)
00285 {
00286 TAU_TYPE_STRING(taustr, "ostream (ostream, " + CT(a) + " )" );
00287 TAU_PROFILE("operator<<()", taustr, TAU_FIELD | TAU_IO);
00288 a.write(out);
00289 return out;
00290 }
00291
00293
00294 #include "Field/LField.cpp"
00295
00296 #endif // LFIELD_H
00297
00298
00299
00300
00301
00302