27 #ifndef IPPL_CACHE_LINE_SIZE
28 #define IPPL_CACHE_LINE_SIZE 32
36 #ifndef IPPL_OFFSET_BLOCKS
37 #define IPPL_OFFSET_BLOCKS 16
42 #define LFIELDMSG(x) x
61 #define MAKE_INITIALIZER(T) \
63 struct LFieldInitializer<T> \
65 static void apply(T& x) { x=0; } \
84 template<class
T,
unsigned Dim>
93 Begin(owned, CompressedData),
95 overlapCacheInited(false),
96 allocCompressIndex(0),
97 ownedCompressIndex(-1),
107 this->ReallyUncompress(
true);
113 template<
class T,
unsigned Dim>
121 Allocated(allocated),
122 Begin(owned, CompressedData),
124 overlapCacheInited(false),
125 allocCompressIndex(0),
126 ownedCompressIndex(-1),
147 template<
class T,
unsigned Dim>
149 : vnode_m(lf.vnode_m),
153 Allocated(lf.Allocated),
154 Begin(CompressedData),
156 overlapCacheInited(false),
157 allocCompressIndex(lf.allocCompressIndex),
158 ownedCompressIndex(lf.ownedCompressIndex),
182 std::copy(lf.
P, lf.
P +
n,
P);
198 template<
class T,
unsigned Dim>
212 template<
class T,
unsigned Dim>
223 LFIELDMSG(dbgmsg <<
"Trying to compress LField with domain = "<<getOwned());
224 LFIELDMSG(dbgmsg <<
", baseOnPhysicalCells = " << baseOnPhysicalCells<<
endl);
226 if (baseOnPhysicalCells)
228 if (CanCompressBasedOnPhysicalCells())
230 CompressBasedOnPhysicalCells();
254 template<
class T,
unsigned Dim>
276 int sz = getAllocated().size();
279 T *mid1 = P + allocCompressIndex;
292 LFIELDMSG(dbgmsg <<
"Doing short-cut check, comparing " << *mid1);
293 LFIELDMSG(dbgmsg <<
" to " << val <<
" at last-alloc-domain-failed");
294 LFIELDMSG(dbgmsg <<
" index of " << allocCompressIndex <<
endl);
299 LFIELDMSG(dbgmsg <<
"Short-cut check determined we cannot ");
300 LFIELDMSG(dbgmsg <<
"compress, by comparing " << *mid1<<
" to ");
301 LFIELDMSG(dbgmsg << val <<
" at last-alloc-domain-failed index");
312 LFIELDMSG(dbgmsg <<
"Checking for compression for " << sz <<
" items, ");
320 T *checkptr = mid1 + 1;
321 while (checkptr != end1)
323 if (!(*checkptr++ == val))
325 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
326 LFIELDMSG(dbgmsg << (checkptr - mid1) <<
" compares (");
327 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
329 ADDIPPLSTAT(incCompressionCompares, (checkptr - mid1));
330 allocCompressIndex = (checkptr - ptr1) - 1;
337 while (checkptr != mid1)
339 if (!(*checkptr++ == val))
341 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
342 LFIELDMSG(dbgmsg << (checkptr - ptr1) + (end1 - mid1));
344 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
347 (checkptr - ptr1) + (end1 - mid1));
348 allocCompressIndex = (checkptr - ptr1) - 1;
357 if (!(*ptr1++ == val))
359 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
360 LFIELDMSG(dbgmsg << (ptr1 - P) <<
" compares (");
361 LFIELDMSG(dbgmsg << *(ptr1-1) <<
" != " << val <<
")");
364 allocCompressIndex = (ptr1 - P) - 1;
373 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after " << sz);
376 allocCompressIndex = 0;
388 template<
class T,
unsigned Dim>
416 int sz = getOwned().
size();
420 PAssert_LT((
unsigned int) ownedCompressIndex, getAllocated().size());
421 val = *(P + ownedCompressIndex);
422 LFIELDMSG(dbgmsg <<
"Checking owned cells using previous ");
423 LFIELDMSG(dbgmsg <<
"comparison value " << val <<
" from index = ");
424 LFIELDMSG(dbgmsg << ownedCompressIndex <<
" against " << sz);
433 LFIELDMSG(dbgmsg <<
"Checking owned cells using first element " << val);
434 LFIELDMSG(dbgmsg <<
" for comparison against " << sz <<
" items."<<
endl);
441 for (
int i=0; i < sz; ++i, ++p)
445 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
448 ownedCompressIndex = (&(*p)) - P;
449 LFIELDMSG(dbgmsg <<
"changed ownedCompressIndex to ");
457 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after ");
460 ownedCompressIndex = (-1);
475 template<
class T,
unsigned Dim>
483 LFIELDMSG(dbgmsg <<
"Compressing LField with domain = " << getOwned());
484 LFIELDMSG(dbgmsg <<
" to new value = " << val <<
", already compressed = ");
504 CompressedData = val;
507 Begin.Compress(CompressedData);
525 template<
class T,
unsigned Dim>
540 CompressedData = *(
begin(getOwned()));
543 Begin.Compress(CompressedData);
557 template<
class T,
unsigned Dim>
567 int n = Allocated.size();
571 LFIELDMSG(dbgmsg <<
"Uncompressing LField with domain = " << getOwned());
572 LFIELDMSG(dbgmsg <<
", fill_domain = " << (fill_domain ? 1 : 0) <<
endl);
579 for (
int i=0; i<
n; i++)
585 Begin =
iterator(P,Owned,Allocated,CompressedData);
599 template<
class T,
unsigned Dim>
606 return iterator(P,domain,Allocated,CompressedData);
618 template<
class T,
unsigned Dim>
624 compstore = CompressedData;
625 return iterator(P,domain,Allocated,compstore);
635 template<
class T,
unsigned Dim>
651 T temp = CompressedData;
652 CompressedData =
a.CompressedData;
653 a.CompressedData = temp;
658 int temp = allocCompressIndex;
659 allocCompressIndex =
a.allocCompressIndex;
660 a.allocCompressIndex = temp;
661 temp = ownedCompressIndex;
662 ownedCompressIndex =
a.ownedCompressIndex;
663 a.ownedCompressIndex = temp;
668 int temp = offsetBlocks;
669 offsetBlocks =
a.offsetBlocks;
670 a.offsetBlocks = temp;
674 Begin =
iterator(P,Owned,Allocated,CompressedData);
675 a.Begin =
iterator(
a.P,
a.Owned,
a.Allocated,
a.CompressedData);
692 template<
class T,
unsigned Dim>
708 P =
new T[newsize + extra]();
721 template<
class T,
unsigned Dim>
745 template<
class T,
unsigned Dim>
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
#define IPPL_OFFSET_BLOCKS
#define IPPL_CACHE_LINE_SIZE
#define MAKE_INITIALIZER(T)
Inform & endl(Inform &inf)
#define ADDIPPLSTAT(stat, amount)
std::string::iterator iterator
void ReallyUncompress(bool fill_domain)
void swapData(LField< T, Dim > &a)
CompressedBrickIterator< T, Dim > iterator
void allocateStorage(int newsize)
bool IsCompressed() const
bool CanCompressBasedOnPhysicalCells() const
bool TryCompress(bool baseOnPhysicalCells=false)
void write(std::ostream &) const
void CompressBasedOnPhysicalCells()
const iterator & begin() const
int size(unsigned d) const
static bool noFieldCompression
static bool extraCompressChecks
static bool offsetStorage