36 #ifndef IPPL_CACHE_LINE_SIZE
37 #define IPPL_CACHE_LINE_SIZE 32
45 #ifndef IPPL_OFFSET_BLOCKS
46 #define IPPL_OFFSET_BLOCKS 16
51 #define LFIELDMSG(x) x
70 #define MAKE_INITIALIZER(T) \
72 struct LFieldInitializer<T> \
74 static void apply(T& x) { x=0; } \
93 template<class
T,
unsigned Dim>
101 Allocated(allocated),
102 Begin(owned, CompressedData),
104 overlapCacheInited(false),
105 allocCompressIndex(0),
106 ownedCompressIndex(-1),
116 this->ReallyUncompress(
true);
122 template<
class T,
unsigned Dim>
130 Allocated(allocated),
131 Begin(owned, CompressedData),
133 overlapCacheInited(false),
134 allocCompressIndex(0),
135 ownedCompressIndex(-1),
156 template<
class T,
unsigned Dim>
158 : vnode_m(lf.vnode_m),
162 Allocated(lf.Allocated),
163 Begin(CompressedData),
165 overlapCacheInited(false),
166 allocCompressIndex(lf.allocCompressIndex),
167 ownedCompressIndex(lf.ownedCompressIndex),
191 std::copy(lf.
P, lf.
P + n,
P);
207 template<
class T,
unsigned Dim>
221 template<
class T,
unsigned Dim>
232 LFIELDMSG(dbgmsg <<
"Trying to compress LField with domain = "<<getOwned());
233 LFIELDMSG(dbgmsg <<
", baseOnPhysicalCells = " << baseOnPhysicalCells<<
endl);
235 if (baseOnPhysicalCells)
237 if (CanCompressBasedOnPhysicalCells())
239 CompressBasedOnPhysicalCells();
263 template<
class T,
unsigned Dim>
285 int sz = getAllocated().size();
288 T *mid1 = P + allocCompressIndex;
301 LFIELDMSG(dbgmsg <<
"Doing short-cut check, comparing " << *mid1);
302 LFIELDMSG(dbgmsg <<
" to " << val <<
" at last-alloc-domain-failed");
303 LFIELDMSG(dbgmsg <<
" index of " << allocCompressIndex <<
endl);
308 LFIELDMSG(dbgmsg <<
"Short-cut check determined we cannot ");
309 LFIELDMSG(dbgmsg <<
"compress, by comparing " << *mid1<<
" to ");
310 LFIELDMSG(dbgmsg << val <<
" at last-alloc-domain-failed index");
321 LFIELDMSG(dbgmsg <<
"Checking for compression for " << sz <<
" items, ");
329 T *checkptr = mid1 + 1;
330 while (checkptr != end1)
332 if (!(*checkptr++ == val))
334 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
335 LFIELDMSG(dbgmsg << (checkptr - mid1) <<
" compares (");
336 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
338 ADDIPPLSTAT(incCompressionCompares, (checkptr - mid1));
339 allocCompressIndex = (checkptr - ptr1) - 1;
346 while (checkptr != mid1)
348 if (!(*checkptr++ == val))
350 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
351 LFIELDMSG(dbgmsg << (checkptr - ptr1) + (end1 - mid1));
353 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
356 (checkptr - ptr1) + (end1 - mid1));
357 allocCompressIndex = (checkptr - ptr1) - 1;
366 if (!(*ptr1++ == val))
368 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
369 LFIELDMSG(dbgmsg << (ptr1 - P) <<
" compares (");
370 LFIELDMSG(dbgmsg << *(ptr1-1) <<
" != " << val <<
")");
373 allocCompressIndex = (ptr1 - P) - 1;
382 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after " << sz);
385 allocCompressIndex = 0;
397 template<
class T,
unsigned Dim>
425 int sz = getOwned().
size();
429 PAssert_LT((
unsigned int) ownedCompressIndex, getAllocated().size());
430 val = *(P + ownedCompressIndex);
431 LFIELDMSG(dbgmsg <<
"Checking owned cells using previous ");
432 LFIELDMSG(dbgmsg <<
"comparison value " << val <<
" from index = ");
433 LFIELDMSG(dbgmsg << ownedCompressIndex <<
" against " << sz);
442 LFIELDMSG(dbgmsg <<
"Checking owned cells using first element " << val);
443 LFIELDMSG(dbgmsg <<
" for comparison against " << sz <<
" items."<<
endl);
450 for (
int i=0; i < sz; ++i, ++p)
454 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
457 ownedCompressIndex = (&(*p)) - P;
458 LFIELDMSG(dbgmsg <<
"changed ownedCompressIndex to ");
466 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after ");
469 ownedCompressIndex = (-1);
484 template<
class T,
unsigned Dim>
492 LFIELDMSG(dbgmsg <<
"Compressing LField with domain = " << getOwned());
493 LFIELDMSG(dbgmsg <<
" to new value = " << val <<
", already compressed = ");
502 for (
iterator lit = begin(); lit != end(); ++lit)
513 CompressedData = val;
516 Begin.Compress(CompressedData);
534 template<
class T,
unsigned Dim>
549 CompressedData = *(begin(getOwned()));
552 Begin.Compress(CompressedData);
566 template<
class T,
unsigned Dim>
576 int n = Allocated.size();
580 LFIELDMSG(dbgmsg <<
"Uncompressing LField with domain = " << getOwned());
581 LFIELDMSG(dbgmsg <<
", fill_domain = " << (fill_domain ? 1 : 0) <<
endl);
588 for (
int i=0; i<
n; i++)
596 for (
int i=0; i<
n; i++)
603 Begin =
iterator(P,Owned,Allocated,CompressedData);
617 template<
class T,
unsigned Dim>
624 return iterator(P,domain,Allocated,CompressedData);
636 template<
class T,
unsigned Dim>
642 compstore = CompressedData;
643 return iterator(P,domain,Allocated,compstore);
653 template<
class T,
unsigned Dim>
669 T temp = CompressedData;
676 int temp = allocCompressIndex;
679 temp = ownedCompressIndex;
686 int temp = offsetBlocks;
692 Begin =
iterator(P,Owned,Allocated,CompressedData);
712 template<
class T,
unsigned Dim>
729 P = (
T *)valloc(
sizeof(
T) * (newsize + extra));
731 P =
new T[newsize + extra];
745 template<
class T,
unsigned Dim>
777 template<
class T,
unsigned Dim>
782 for (
iterator p = begin(); p!=end(); ++p)
static bool extraCompressChecks
bool TryCompress(bool baseOnPhysicalCells=false)
void swapData(LField< T, Dim > &a)
bool CanCompressBasedOnPhysicalCells() const
#define IPPL_CACHE_LINE_SIZE
void write(std::ostream &) const
void ReallyUncompress(bool fill_domain)
const iterator & begin() const
static bool offsetStorage
CompressedBrickIterator< T, Dim > iterator
static bool noFieldCompression
#define IPPL_OFFSET_BLOCKS
int size(unsigned d) const
bool IsCompressed() const
void CompressBasedOnPhysicalCells()
#define ADDIPPLSTAT(stat, amount)
std::string::iterator iterator
void allocateStorage(int newsize)
Inform & endl(Inform &inf)
#define MAKE_INITIALIZER(T)