MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
scratch.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef SCRATCH_H
8#define SCRATCH_H
9
10#ifndef PVPLUGIN // =============== DO MAIA SCRATCH ========
11
12#include <cstdint>
13#include <iomanip>
14#include <list>
15#include <new>
16#include <ostream>
17#include <sstream>
18#include <utility>
19#include "INCLUDE/maiatypes.h"
20#include "IO/infoout.h"
21#include "UTIL/functions.h"
22#include "config.h"
23#include "globalvariables.h"
24
25//#if defined(linux)
26//#include <sys/sysinfo.h>
27// const uintptr_t ALIGNMENT_BOUNDARY = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); // make alignment boundary equal to
28// L1-cache linesize #else const uintptr_t ALIGNMENT_BOUNDARY = 64; // see below #endif
29
30
35namespace maia {
36struct maia_signed {};
37struct maia_unsigned {};
38template <class T>
40 static const MBool value = false;
42};
43template <>
45 static const MBool value = true;
47};
48// used in cartesian grid constructor, comment out to see the errors:
49template <>
51 static const MBool value = true;
53};
54} // namespace maia
55
56template <class T>
57class ScratchSpace;
59
69
75
77
79
80using ScratchList = std::list<ScratchSpaceBase*>;
81
91class Scratch {
92 friend class ScratchSpaceBase;
93
94 static const uintptr_t ALIGNMENT_BOUNDARY = MAIA_SCRATCH_ALIGNMENT_BOUNDARY; // see above
95
96 public:
109 Scratch(MFloat size, MInt Cells);
110
120 m_object_id = 0;
121 m_usedmemsize = 0;
122 m_nextfree = nullptr;
123 m_scratchSpaces.clear();
124 m_maxused = nullptr;
125 m_report = "n/a";
126 delete[] m_totalScratch;
127 m_totalScratch = nullptr;
128 };
129
137 static char* getEndPointer() { return (char*)(size_t)(m_totalScratch + m_number_of_elements - 1); }
138
146 // static size_t getAvailableMemory() {return (getTotalMemory() - m_usedmemsize);}//this leads to errors if the
147 // m_nextfree pointer is corrupted for whatever reason, Lennart
149
157 static size_t getTotalMemory() { return (getEndPointer() + 1 - m_totalScratch); }
158
159 static MString printSelfScratch();
160 static MString printSelf();
161 static MString printSelfReport();
162
163 static size_t m_number_of_cells;
164 static size_t m_number_of_elements;
166 static char* m_totalScratch;
167 static size_t m_usedmemsize;
168 static char* m_nextfree;
170 static char* m_maxused;
172};
173
174
183 public:
184 static const uintptr_t ALIGNMENT_BOUNDARY = MAIA_SCRATCH_ALIGNMENT_BOUNDARY; // see above
185
186 const size_t m_memsize;
187 const size_t m_memsizePadded;
193
208 ScratchSpaceBase(size_t num, size_t size, MString name, MString varname)
209 : m_memsize(num * size),
210 m_memsizePadded((num * size) + ((ALIGNMENT_BOUNDARY - ((num * size) % ALIGNMENT_BOUNDARY)) % ALIGNMENT_BOUNDARY)),
211 m_calling_function(std::move(name)),
212 m_variable_name(std::move(varname)),
213 m_nonterminal(false),
214 m_destroy(false) {
215 ASSERT((((uintptr_t)Scratch::m_nextfree) % ALIGNMENT_BOUNDARY == 0), "Scratch memory is not aligned");
216 }
217 virtual MString printSelfReport() const = 0;
218 virtual MString printSelf() const = 0;
219};
220
231template <class T>
232class ScratchSpace : public ScratchSpaceBase {
233 public:
234 using value_type = T;
238 using const_pointer = const value_type*;
241 using difference_type = long;
242 using size_type = std::size_t;
243
244 ScratchSpace(MInt num, const MString& name, const MString& varname);
245 ScratchSpace(MInt num0, MInt num1, const MString& name,
246 const MString& varname);
247 ScratchSpace(MInt num0, MInt num1, MInt num2, const MString& name,
248 const MString& varname);
250
251 template <class Integral>
252 inline reference operator[](const Integral /*i*/);
253 template <class Integral>
254 inline reference operator()(const Integral /*i*/);
255 template <class Integral>
256 inline reference operator()(const Integral /*i*/, const Integral /*j*/);
257 template <class Integral>
258 inline reference operator()(const Integral /*i*/, const Integral /*j*/, const Integral /*k*/);
259 template <class Integral>
260 inline const_reference operator[](const Integral i) const;
261 template <class Integral>
262 inline const_reference operator()(const Integral i) const;
263 template <class Integral>
264 inline const_reference operator()(const Integral /*i*/, const Integral /*j*/) const;
265 template <class Integral>
266 inline const_reference operator()(const Integral /*i*/, const Integral /*j*/,
267 const Integral /*k*/) const;
269 operator=(ScratchSpace<T>& /*S*/);
270 template <class>
271 friend std::ostream& operator<<(std::ostream& os, const ScratchSpace& s);
272
273 inline iterator begin() {
275 return p;
276 }
277 inline iterator cbegin() const {
279 return p;
280 }
281 inline iterator end() {
283 return last;
284 }
285 inline iterator cend() const {
287 return last;
288 }
291 return begin();
292 }
295 return begin();
296 }
297
298 inline MInt size0() const { return m_size0; }
299 inline MInt size1() const { return m_size1; }
300 inline MInt size2() const { return m_size2; }
301 inline size_t getMemsize() const { return (last - p) * sizeof(T); }
302 inline size_type size() const {
303 ASSERT(last >= p, "Scratch cannot have negative size!");
304 return last - p;
305 }
306 inline MBool empty() const {
307 ASSERT(last >= p, "Scratch cannot have negative size!");
308 return static_cast<bool>(last - p == 0);
309 }
310
311 void fill(T val) { std::fill(p, last, val); }
312 MString printSelf() const override;
313 MString printSelfReport() const override;
314
316 T* getPointer() const { return p; }
317
318 // Disable copying and heap allocation
319 ScratchSpace() = delete;
321
322 void* operator new(std::size_t) = delete;
323 void* operator new(std::size_t, void* p) = delete;
324 void* operator new[](std::size_t) = delete;
325 void* operator new[](std::size_t, void* p) = delete;
326 void operator delete(void*) = delete;
327 void operator delete(void* p, void*) = delete;
328 void operator delete[](void*) = delete;
329 void operator delete[](void* p, void*) = delete;
330
331 private:
332 // TODO labels:toenhance when ".p" is removed: const_iterator first, last;
334 // TODO labels:toenhance this should be std::size_t
338
348 template <class Integral>
349 inline void testBounds(const Integral& i) const;
350 template <class Integral>
351 inline MBool checkBounds(const Integral& i) const {
352 using type = typename maia::is_unsigned<Integral>::type;
353 return checkBounds(i, type());
354 }
355 template <class Integral>
356 inline MBool checkBounds(const Integral& i, maia::maia_unsigned /*unused*/) const {
357 return static_cast<size_type>(i) < size();
358 }
359 template <class Integral>
360 inline MBool checkBounds(const Integral& i, maia::maia_signed /*unused*/) const {
361 return i >= 0 && static_cast<size_type>(i) < size();
362 }
364 void init();
365 inline void checkForEmptyScratch() const;
366};
367
368
387template <class T>
388ScratchSpace<T>::ScratchSpace(MInt num, const MString& name, const MString& varname)
389 : ScratchSpaceBase(mMax(1, num), sizeof(T), name, varname),
390 p(reinterpret_cast<T*>(Scratch::m_nextfree)),
391 last(p + num),
392 m_size0(num),
393 m_size1(1),
394 m_size2(1) {
395 this->init();
396}
397
407template <class T>
408ScratchSpace<T>::ScratchSpace(MInt num0, MInt num1, const MString& name, const MString& varname)
409 : ScratchSpaceBase(mMax(1, num0 * num1), sizeof(T), name, varname),
410 p(reinterpret_cast<T*>(Scratch::m_nextfree)),
411 last(p + (num0 * num1)),
412 m_size0(num0),
413 m_size1(num1),
414 m_size2(1) {
415 this->init();
416}
417
418
429template <class T>
430ScratchSpace<T>::ScratchSpace(MInt num0, MInt num1, MInt num2, const MString& name, const MString& varname)
431 : ScratchSpaceBase(mMax(1, num0 * num1 * num2), sizeof(T), name, varname),
432 p(reinterpret_cast<T*>(Scratch::m_nextfree)),
433 last(p + (num0 * num1 * num2)),
434 m_size0(num0),
435 m_size1(num1),
436 m_size2(num2) {
437 this->init();
438}
439
440
450template <class T>
453
454 m_object_id = Scratch::m_object_id;
455 Scratch::m_scratchSpaces.push_back(this);
456
458 if(Scratch::getAvailableMemory() < m_memsizePadded) {
459 m_destroy = true;
460 std::cerr << Scratch::printSelf();
462 std::stringstream errorMessage, suggestionMessage;
463 errorMessage << "Scratch is not big enough - exceeded size in " << m_calling_function << " with variable "
464 << m_variable_name << std::endl;
465 errorMessage << " " << m_memsize / (1024.0 * 1024.0) << " MB required, but there are only "
466 << Scratch::getAvailableMemory() / (1024.0 * 1024.0) << " MB available" << std::endl;
467 errorMessage << " Suggested to raise the property scratchSize from "
471 << std::endl;
472 m_log << errorMessage.str();
473 mTerm(1, AT_, errorMessage.str());
474 }
475 Scratch::m_usedmemsize += m_memsizePadded;
476 Scratch::m_nextfree += m_memsizePadded;
477
478 for(MInt i = 0; i < (signed)this->size(); i++) {
479 ASSERT(((char*)&p[i] >= &Scratch::m_totalScratch[0])
481 "ScratchSpace '" + m_variable_name + "' out of bounds during init.");
482 new(&p[i]) T(); // 'placement new' operator calling each element's default constructor (no further memory allocated)
483 }
484
485 for(MInt i = 0; i < (signed)this->size(); i++) {
486 new(&p[i]) T(); // 'placement new' operator calling each element's default constructor
487 }
488
490#ifdef MAIA_EXTRA_DEBUG
491 for(ScratchList::iterator it = Scratch::m_scratchSpaces.begin(); it != Scratch::m_scratchSpaces.end(); ++it) {
492 if((*it) == this) continue;
493 if((*it)->m_variable_name == this->m_variable_name) {
494 m_log << "WARNING: SCRATCH_DOUBLE_ALLOCATION: double usage of variable " << this->m_variable_name
495 << " allocated in " << (*it)->m_calling_function << " and " << this->m_calling_function << std::endl;
496 }
497 }
498#endif
499
503 ScratchList::iterator iter;
504 for(iter = Scratch::m_scratchSpaces.begin(); iter != Scratch::m_scratchSpaces.end(); iter++) {
505 Scratch::m_report += (*iter)->printSelfReport();
506 Scratch::m_report += "\n";
507 }
508 Scratch::m_report += "\n\n";
509 }
510}
511
512
520template <class T>
522 if(!m_destroy) {
523 auto it = Scratch::m_scratchSpaces.end();
524 it--;
525
527 if((*it)->m_object_id == m_object_id) {
528 Scratch::m_nextfree -= m_memsizePadded;
529 Scratch::m_usedmemsize -= m_memsizePadded;
530 Scratch::m_scratchSpaces.erase(it);
531 }
532
533 if(m_nonterminal) {
534 Scratch::m_nextfree -= m_memsizePadded;
535 }
536 }
537}
538
546template <class T>
548 std::stringstream id, mem, memsize;
549 mem << p;
550
551 id << m_object_id;
552 memsize << m_memsize;
553
554 MString message = "ScratchSpace ID: ";
555 message += id.str();
556 message += "\n-----------------------------\n";
557 message += "Calling function:\t";
558 message += m_calling_function;
559 message += "\nVariable name:\t\t";
560 message += m_variable_name;
561 message += "\nMemory size:\t\t";
562 message += memsize.str();
563 message += "\nMemory pointer:\t\t";
564 message += mem.str();
565 message += "\nSize:\t\t\t";
566 message += std::to_string(size());
567 message += "\n";
568
569 return message;
570}
571
582template <class T>
584 std::stringstream id, memsize, funct, var;
585 memsize << m_memsize;
586 id << m_object_id;
587
588 MString message = "ID: ";
589 message += id.str();
590 message += " SIZE: ";
591 message += memsize.str();
592 message += " FUNCT: ";
593 message += m_calling_function;
594 message += " VAR: ";
595 message += m_variable_name;
596 return message;
597}
598
599template <class T>
600template <class Integral>
601inline void ScratchSpace<T>::testBounds(const Integral& i) const {
602 ASSERT(checkBounds(i), "SCRATCH_OUT_OF_BOUNDS ERROR: accessing "
603 << m_variable_name << " allocated from " << m_calling_function << " with index " << i
604 << " out of range [0," << size() << ")." << std::endl
605 << "Note: if the array range = [0,0) the array is EMPTY. "
606 << "You cannot dereference elements of an empty array!");
607}
608
621template <class T>
622template <class Integral>
624#if defined(MAIA_ASSERTS)
625 testBounds(i);
626#endif
627 return p[i];
628}
629template <class T>
630template <class Integral>
631inline typename ScratchSpace<T>::const_reference ScratchSpace<T>::operator()(const Integral i) const {
632#if defined(MAIA_ASSERTS)
633 testBounds(i);
634#endif
635 return p[i];
636}
637
639template <class T>
640template <class Integral>
642 return operator()(i);
643}
644template <class T>
645template <class Integral>
646inline typename ScratchSpace<T>::const_reference ScratchSpace<T>::operator[](const Integral i) const {
647 return operator()(i);
648}
649
654template <class T>
655template <class Integral>
656inline typename ScratchSpace<T>::reference ScratchSpace<T>::operator()(const Integral i, const Integral j) {
657 ASSERT(i >= 0 && i < m_size0 && j >= 0 && j < m_size1,
658 "SCRATCH_OUT_OF_BOUNDS ERROR: accessing " << m_variable_name << " allocated from " << m_calling_function
659 << " with indices " << i << "," << j << ". Dimensions are "
660 << m_size0 << "," << m_size1 << ".");
661 return p[m_size1 * i + j];
662}
663
664template <class T>
665template <class Integral>
666inline typename ScratchSpace<T>::reference ScratchSpace<T>::operator()(const Integral i, const Integral j,
667 const Integral k) {
668 ASSERT(i >= 0 && i < m_size0 && j >= 0 && j < m_size1 && k >= 0 && k < m_size2,
669 "SCRATCH_OUT_OF_BOUNDS ERROR: accessing "
670 << m_variable_name << " allocated from " << m_calling_function << " with indices " << i << "," << j << ","
671 << k << ". Dimensions are " << m_size0 << "," << m_size1 << "," << m_size2 << ".");
672 return p[m_size1 * m_size2 * i + m_size2 * j + k];
673}
674
675template <class T>
676template <class Integral>
677inline typename ScratchSpace<T>::const_reference ScratchSpace<T>::operator()(const Integral i, const Integral j) const {
678 ASSERT(i >= 0 && i < m_size0 && j >= 0 && j < m_size1,
679 "SCRATCH_OUT_OF_BOUNDS ERROR: accessing " << m_variable_name << " allocated from " << m_calling_function
680 << " with indices " << i << "," << j << ". Dimensions are "
681 << m_size0 << "," << m_size1 << ".");
682 return p[m_size1 * i + j];
683}
684
685template <class T>
686template <class Integral>
687inline typename ScratchSpace<T>::const_reference ScratchSpace<T>::operator()(const Integral i, const Integral j,
688 const Integral k) const {
689 ASSERT(i >= 0 && i < m_size0 && j >= 0 && j < m_size1 && k >= 0 && k < m_size2,
690 "SCRATCH_OUT_OF_BOUNDS ERROR: accessing "
691 << m_variable_name << " allocated from " << m_calling_function << " with indices " << i << "," << j << ","
692 << k << ". Dimensions are " << m_size0 << "," << m_size1 << "," << m_size2 << ".");
693 return p[m_size1 * m_size2 * i + m_size2 * j + k];
694}
695
696template <class T>
698 for(MInt i = 0; i < mMin(m_size0, S.m_size0); i++) {
699 for(MInt j = 0; j < mMin(m_size1, S.m_size1); j++) {
700 for(MInt k = 0; k < mMin(m_size2, S.m_size2); k++) {
701 p[m_size1 * m_size2 * i + m_size2 * j + k] = S.p[m_size1 * m_size2 * i + m_size2 * j + k];
702 }
703 }
704 }
705 return *this;
706}
707
708
721template <class T>
722std::ostream& operator<<(std::ostream& os, const ScratchSpace<T>& s) {
723 os << s.printSelf();
724 os << "Content:\n";
725 for(typename ScratchSpace<T>::size_type i = 0; i < s.size(); i++) {
726 os << std::setw(7) << i << ": " << s[i] << "\n";
727 }
728 return os;
729}
730
731
737template <class T>
739#ifdef MAIA_EXTRA_DEBUG
740 if(empty()) {
741 m_log << "SCRATCH WARNING: passing a pointer to the empty scratch space " << m_variable_name << " allocated from "
742 << m_calling_function << "! Make sure this pointer will NEVER be dereferenced!" << std::endl;
743 }
744#endif
745}
746
747#else // =============== DO PARAVIEW PLUGIN SCRATCH ========
748
749#include <limits>
750#include <memory>
751#include <vector>
753#include "src/UTIL/functions.h"
754
755using std::to_string;
756
757template <typename T>
759 using Storage = std::vector<T>;
760
761 public:
762 using value_type = T;
763 using reference = typename Storage::reference;
764 using const_reference = typename Storage::const_reference;
765 using pointer = typename Storage::pointer;
766 using const_pointer = typename Storage::const_pointer;
767 using iterator = typename Storage::iterator;
768 using const_iterator = typename Storage::const_iterator;
770
771 ScratchSpace(const size_type size_, const MString&, const MString&)
772 : m_size0(size_), m_size1(1), m_data(m_size0 * m_size1), p{*this} {}
774 : m_size0(size0), m_size1(size1), m_data(m_size0 * m_size1), p{*this} {}
775
776 size_type size() const { return m_data.size(); }
777 void fill(const T value) { std::fill(begin(), end(), value); }
778
779 reference operator[](const size_type pos) { return m_data.at(pos); }
780 reference operator()(const size_type pos) { return m_data.at(pos); }
781 const_reference operator[](const size_type pos) const { return m_data.at(pos); }
782 const_reference operator()(const size_type pos) const { return m_data.at(pos); }
783
784
786 if(i >= m_size0) mTerm(1, FUN_, "index i = " + to_string(i) + " out-of-bounds [0, " + to_string(m_size0) + ")");
787 if(j >= m_size1) mTerm(1, FUN_, "index j = " + to_string(j) + " out-of-bounds [0, " + to_string(m_size1) + ")");
788 return m_data.at(m_size1 * i + j);
789 }
791 if(i >= m_size0) mTerm(1, FUN_, "index i = " + to_string(i) + " out-of-bounds [0, " + to_string(m_size0) + ")");
792 if(j >= m_size1) mTerm(1, FUN_, "index j = " + to_string(j) + " out-of-bounds [0, " + to_string(m_size1) + ")");
793 return m_data.at(m_size1 * i + j);
794 }
795
796 T* getPointer() { return m_data.data(); }
797 pointer data() { return m_data.data(); }
798 const_pointer data() const { return m_data.data(); }
799
800 iterator begin() { return m_data.begin(); }
801 iterator end() { return m_data.end(); }
802 iterator cbegin() const { return m_data.cbegin(); }
803 iterator cend() const { return m_data.cend(); }
804
805 struct p_ {
807 reference operator[](size_type i) { return s[i]; }
808 const_reference operator[](size_type i) const { return s[i]; }
809 };
810
811 inline MInt size0() const { return m_size0; }
812 inline MInt size1() const { return m_size1; }
813 inline MInt size2() const { return m_size2; }
814
815 private:
820
821 public:
823};
824
834
835class Scratch {
836 public:
837 static MFloat getAvailableMemory() { return 100; }
838};
839#endif // PV/MAIA Scratch
840
841#endif // SCRATCH_H
This class holds the complete scratch space.
Definition: scratch.h:91
static size_t getAvailableMemory()
Returns the amount of available memory in scratch.
Definition: scratch.h:148
static MString m_report
Definition: scratch.h:171
static MFloat getAvailableMemory()
Definition: scratch.h:837
static ScratchList m_scratchSpaces
Definition: scratch.h:169
static MString printSelfReport()
Returns a shortened string summing up the scratch space state information.
Definition: scratch.cpp:129
static const uintptr_t ALIGNMENT_BOUNDARY
Definition: scratch.h:94
static size_t m_number_of_elements
Definition: scratch.h:164
static MString printSelf()
Returns a string summing up the scratch state information and all scratch space elements information.
Definition: scratch.cpp:106
static char * getEndPointer()
Returns a pointer to the end of the scratch.
Definition: scratch.h:137
~Scratch()
Destructor.
Definition: scratch.h:117
static char * m_nextfree
Definition: scratch.h:168
static MString printSelfScratch()
Returns a string summing up the scratch state information.
Definition: scratch.cpp:48
static size_t getTotalMemory()
Returns the amount of total available memory in scratch.
Definition: scratch.h:157
static size_t m_number_of_cells
Definition: scratch.h:163
static char * m_maxused
Definition: scratch.h:170
static char * m_totalScratch
Definition: scratch.h:166
static MInt m_object_id
Definition: scratch.h:165
static size_t m_usedmemsize
Definition: scratch.h:167
This class is a base class for all ScratchSpaces.
Definition: scratch.h:182
virtual MString printSelf() const =0
MBool m_nonterminal
Definition: scratch.h:191
const MString m_variable_name
Definition: scratch.h:189
ScratchSpaceBase(size_t num, size_t size, MString name, MString varname)
Constructor.
Definition: scratch.h:208
MBool m_destroy
Definition: scratch.h:192
const MString m_calling_function
Definition: scratch.h:188
static const uintptr_t ALIGNMENT_BOUNDARY
Definition: scratch.h:184
const size_t m_memsizePadded
Definition: scratch.h:187
const size_t m_memsize
Definition: scratch.h:186
virtual MString printSelfReport() const =0
MInt m_object_id
Definition: scratch.h:190
This class is a ScratchSpace.
Definition: scratch.h:758
ScratchSpace(const ScratchSpace< T > &)=delete
size_type size() const
Definition: scratch.h:302
const value_type & const_reference
Definition: scratch.h:236
ScratchSpace(const size_type size_, const MString &, const MString &)
Definition: scratch.h:771
reference operator[](const size_type pos)
Definition: scratch.h:779
MString printSelf() const override
Returns a string summing up this scratch space element information.
Definition: scratch.h:547
iterator cbegin() const
Definition: scratch.h:277
pointer iterator
Definition: scratch.h:239
ScratchSpace()=delete
~ScratchSpace()
Destructor.
Definition: scratch.h:521
pointer data()
Definition: scratch.h:289
friend std::ostream & operator<<(std::ostream &os, const ScratchSpace &s)
Print contents of scratch space object.
Definition: scratch.h:722
reference operator()(const size_type pos)
Definition: scratch.h:780
pointer last
Definition: scratch.h:333
std::size_t size_type
Definition: scratch.h:242
MBool checkBounds(const Integral &i, maia::maia_signed) const
Definition: scratch.h:360
void checkForEmptyScratch() const
Checks if scratch space is empty before returning a pointer to it.
Definition: scratch.h:738
reference operator[](const Integral)
1D Scratch access
Definition: scratch.h:641
const_reference operator()(const size_type pos) const
Definition: scratch.h:782
value_type * pointer
Definition: scratch.h:237
MInt size1() const
Definition: scratch.h:299
const MInt m_size2
Definition: scratch.h:337
reference operator()(const size_type i, const size_type j)
Definition: scratch.h:785
std::vector< T > Storage
Definition: scratch.h:759
const MInt m_size1
Definition: scratch.h:336
T * getPointer() const
Deprecated: use begin() instead!
Definition: scratch.h:316
const_reference operator[](const size_type pos) const
Definition: scratch.h:781
size_type m_size1
Definition: scratch.h:817
void testBounds(const Integral &i) const
Assert the bounds of 1D acces to an array.
Definition: scratch.h:601
long difference_type
Definition: scratch.h:241
const_reference operator()(const size_type i, const size_type j) const
Definition: scratch.h:790
MBool checkBounds(const Integral &i, maia::maia_unsigned) const
Definition: scratch.h:356
MInt size2() const
Definition: scratch.h:300
void fill(T val)
fill the scratch with a given value
Definition: scratch.h:311
T * getPointer()
Definition: scratch.h:796
pointer p
Deprecated: use [] instead!
Definition: scratch.h:315
MInt size0() const
Definition: scratch.h:298
MBool checkBounds(const Integral &i) const
Definition: scratch.h:351
ScratchSpace< T > & operator=(ScratchSpace< T > &)
copy entries of S to this, given there is enough space available
Definition: scratch.h:697
const MInt m_size0
Definition: scratch.h:335
ScratchSpace(const size_type size0, const size_type size1, const MString &, const MString &)
Definition: scratch.h:773
void init()
extended constructor functionality
Definition: scratch.h:451
iterator end()
Definition: scratch.h:281
Storage m_data
Definition: scratch.h:819
size_type m_size2
Definition: scratch.h:818
const_pointer data() const
Definition: scratch.h:293
reference operator()(const Integral)
1D Scratch access
Definition: scratch.h:623
MBool empty() const
Definition: scratch.h:306
const_pointer const_iterator
Definition: scratch.h:240
value_type & reference
Definition: scratch.h:235
size_type m_size0
Definition: scratch.h:816
MString printSelfReport() const override
Returns a shortened string summing up this scratch space element information.
Definition: scratch.h:583
iterator cend() const
Definition: scratch.h:285
const value_type * const_pointer
Definition: scratch.h:238
void fill(const T value)
Definition: scratch.h:777
iterator begin()
Definition: scratch.h:273
size_t getMemsize() const
Definition: scratch.h:301
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
const MString const MString & message
Definition: functions.h:37
constexpr T mMin(const T &x, const T &y)
Definition: functions.h:90
constexpr T mMax(const T &x, const T &y)
Definition: functions.h:94
InfoOutFile m_log
int32_t MInt
Definition: maiatypes.h:62
uint32_t MUint
Definition: maiatypes.h:63
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
MInt id
Definition: maiatypes.h:71
uint64_t MUlong
Definition: maiatypes.h:65
Namespace for auxiliary functions/classes.
std::list< ScratchSpaceBase * > ScratchList
Definition: scratch.h:80
std::ostream & operator<<(std::ostream &os, const ScratchSpace< T > &s)
Print contents of scratch space object.
Definition: scratch.h:722
reference operator[](size_type i)
Definition: scratch.h:807
const_reference operator[](size_type i) const
Definition: scratch.h:808
ScratchSpace< T > & s
Definition: scratch.h:806
static const MBool value
Definition: scratch.h:40