27#ifndef IPPL_CACHE_LINE_SIZE
28#define IPPL_CACHE_LINE_SIZE 32
36#ifndef IPPL_OFFSET_BLOCKS
37#define IPPL_OFFSET_BLOCKS 16
61#define MAKE_INITIALIZER(T) \
63struct LFieldInitializer<T> \
65 static void apply(T& x) { x=0; } \
84template<class T,
unsigned Dim>
94 Begin(owned, CompressedData),
96 overlapCacheInited(
false),
97 allocCompressIndex(0),
98 ownedCompressIndex(-1),
108 this->ReallyUncompress(
true);
114template<
class T,
unsigned Dim>
122 Allocated(allocated),
124 Begin(owned, CompressedData),
126 overlapCacheInited(false),
127 allocCompressIndex(0),
128 ownedCompressIndex(-1),
149template<
class T,
unsigned Dim>
151 : vnode_m(lf.vnode_m),
155 Allocated(lf.Allocated),
157 Begin(CompressedData),
159 overlapCacheInited(false),
160 allocCompressIndex(lf.allocCompressIndex),
161 ownedCompressIndex(lf.ownedCompressIndex),
185 std::copy(lf.
P, lf.
P + n,
P);
201template<
class T,
unsigned Dim>
215template<
class T,
unsigned Dim>
226 LFIELDMSG(dbgmsg <<
"Trying to compress LField with domain = "<<getOwned());
227 LFIELDMSG(dbgmsg <<
", baseOnPhysicalCells = " << baseOnPhysicalCells<<
endl);
229 if (baseOnPhysicalCells)
231 if (CanCompressBasedOnPhysicalCells())
233 CompressBasedOnPhysicalCells();
257template<
class T,
unsigned Dim>
279 int sz = getAllocated().size();
282 T *mid1 = P + allocCompressIndex;
295 LFIELDMSG(dbgmsg <<
"Doing short-cut check, comparing " << *mid1);
296 LFIELDMSG(dbgmsg <<
" to " << val <<
" at last-alloc-domain-failed");
297 LFIELDMSG(dbgmsg <<
" index of " << allocCompressIndex <<
endl);
302 LFIELDMSG(dbgmsg <<
"Short-cut check determined we cannot ");
303 LFIELDMSG(dbgmsg <<
"compress, by comparing " << *mid1<<
" to ");
304 LFIELDMSG(dbgmsg << val <<
" at last-alloc-domain-failed index");
315 LFIELDMSG(dbgmsg <<
"Checking for compression for " << sz <<
" items, ");
323 T *checkptr = mid1 + 1;
324 while (checkptr != end1)
326 if (!(*checkptr++ == val))
328 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
329 LFIELDMSG(dbgmsg << (checkptr - mid1) <<
" compares (");
330 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
332 ADDIPPLSTAT(incCompressionCompares, (checkptr - mid1));
333 allocCompressIndex = (checkptr - ptr1) - 1;
340 while (checkptr != mid1)
342 if (!(*checkptr++ == val))
344 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
345 LFIELDMSG(dbgmsg << (checkptr - ptr1) + (end1 - mid1));
347 LFIELDMSG(dbgmsg << *(checkptr-1) <<
" != " << val <<
")");
350 (checkptr - ptr1) + (end1 - mid1));
351 allocCompressIndex = (checkptr - ptr1) - 1;
360 if (!(*ptr1++ == val))
362 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
363 LFIELDMSG(dbgmsg << (ptr1 - P) <<
" compares (");
364 LFIELDMSG(dbgmsg << *(ptr1-1) <<
" != " << val <<
")");
367 allocCompressIndex = (ptr1 - P) - 1;
376 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after " << sz);
379 allocCompressIndex = 0;
391template<
class T,
unsigned Dim>
419 int sz = getOwned().
size();
423 PAssert_LT((
unsigned int) ownedCompressIndex, getAllocated().size());
424 val = *(P + ownedCompressIndex);
425 LFIELDMSG(dbgmsg <<
"Checking owned cells using previous ");
426 LFIELDMSG(dbgmsg <<
"comparison value " << val <<
" from index = ");
427 LFIELDMSG(dbgmsg << ownedCompressIndex <<
" against " << sz);
436 LFIELDMSG(dbgmsg <<
"Checking owned cells using first element " << val);
437 LFIELDMSG(dbgmsg <<
" for comparison against " << sz <<
" items."<<
endl);
444 for (
int i=0; i < sz; ++i, ++p)
448 LFIELDMSG(dbgmsg <<
"Found that we cannot compress, after ");
451 ownedCompressIndex = (&(*p)) - P;
452 LFIELDMSG(dbgmsg <<
"changed ownedCompressIndex to ");
460 LFIELDMSG(dbgmsg <<
"Found that we CAN compress, after ");
463 ownedCompressIndex = (-1);
478template<
class T,
unsigned Dim>
486 LFIELDMSG(dbgmsg <<
"Compressing LField with domain = " << getOwned());
487 LFIELDMSG(dbgmsg <<
" to new value = " << val <<
", already compressed = ");
507 CompressedData = val;
510 Begin.Compress(CompressedData);
528template<
class T,
unsigned Dim>
543 CompressedData = *(
begin(getOwned()));
546 Begin.Compress(CompressedData);
560template<
class T,
unsigned Dim>
570 int n = Allocated.size();
574 LFIELDMSG(dbgmsg <<
"Uncompressing LField with domain = " << getOwned());
575 LFIELDMSG(dbgmsg <<
", fill_domain = " << (fill_domain ? 1 : 0) <<
endl);
582 for (
int i=0; i<n; i++)
588 Begin =
iterator(P,Owned,Allocated,CompressedData);
602template<
class T,
unsigned Dim>
609 return iterator(P,domain,Allocated,CompressedData);
621template<
class T,
unsigned Dim>
627 compstore = CompressedData;
628 return iterator(P,domain,Allocated,compstore);
638template<
class T,
unsigned Dim>
654 T temp = CompressedData;
655 CompressedData =
a.CompressedData;
656 a.CompressedData = temp;
661 int temp = allocCompressIndex;
662 allocCompressIndex =
a.allocCompressIndex;
663 a.allocCompressIndex = temp;
664 temp = ownedCompressIndex;
665 ownedCompressIndex =
a.ownedCompressIndex;
666 a.ownedCompressIndex = temp;
671 int temp = offsetBlocks;
672 offsetBlocks =
a.offsetBlocks;
673 a.offsetBlocks = temp;
677 Begin =
iterator(P,Owned,Allocated,CompressedData);
678 a.Begin =
iterator(
a.P,
a.Owned,
a.Allocated,
a.CompressedData);
695template<
class T,
unsigned Dim>
711 P =
new T[newsize + extra]();
714 ADDIPPLSTAT(incLFieldBytes, (newsize+extra)*
sizeof(T));
724template<
class T,
unsigned Dim>
748template<
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)
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