MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
ScratchSpace< T > Class Template Reference

This class is a ScratchSpace. More...

#include <scratch.h>

Inheritance diagram for ScratchSpace< T >:
[legend]
Collaboration diagram for ScratchSpace< T >:
[legend]

Classes

struct  p_
 

Public Types

using value_type = T
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using difference_type = long
 
using size_type = std::size_t
 
using value_type = T
 
using reference = typename Storage::reference
 
using const_reference = typename Storage::const_reference
 
using pointer = typename Storage::pointer
 
using const_pointer = typename Storage::const_pointer
 
using iterator = typename Storage::iterator
 
using const_iterator = typename Storage::const_iterator
 
using size_type = MLong
 

Public Member Functions

 ScratchSpace (MInt num, const MString &name, const MString &varname)
 1D Scratch constructor More...
 
 ScratchSpace (MInt num0, MInt num1, const MString &name, const MString &varname)
 2D Scratch constructor More...
 
 ScratchSpace (MInt num0, MInt num1, MInt num2, const MString &name, const MString &varname)
 3D Scratch constructor More...
 
 ~ScratchSpace ()
 Destructor. More...
 
template<class Integral >
reference operator[] (const Integral)
 1D Scratch access More...
 
template<class Integral >
reference operator() (const Integral)
 1D Scratch access More...
 
template<class Integral >
reference operator() (const Integral, const Integral)
 2D Scratch access More...
 
template<class Integral >
reference operator() (const Integral, const Integral, const Integral)
 3D Scratch access More...
 
template<class Integral >
const_reference operator[] (const Integral i) const
 1D Scratch const access More...
 
template<class Integral >
const_reference operator() (const Integral i) const
 1D Scratch const access More...
 
template<class Integral >
const_reference operator() (const Integral, const Integral) const
 2D Scratch const access More...
 
template<class Integral >
const_reference operator() (const Integral, const Integral, const Integral) const
 3D Scratch const access More...
 
ScratchSpace< T > & operator= (ScratchSpace< T > &)
 copy entries of S to this, given there is enough space available More...
 
iterator begin ()
 
iterator cbegin () const
 
iterator end ()
 
iterator cend () const
 
pointer data ()
 
const_pointer data () const
 
MInt size0 () const
 
MInt size1 () const
 
MInt size2 () const
 
size_t getMemsize () const
 
size_type size () const
 
MBool empty () const
 
void fill (T val)
 fill the scratch with a given value More...
 
MString printSelf () const override
 Returns a string summing up this scratch space element information. More...
 
MString printSelfReport () const override
 Returns a shortened string summing up this scratch space element information. More...
 
T * getPointer () const
 Deprecated: use begin() instead! More...
 
 ScratchSpace ()=delete
 
 ScratchSpace (const ScratchSpace< T > &)=delete
 
void * operator new (std::size_t)=delete
 
void * operator new (std::size_t, void *p)=delete
 
void * operator new[] (std::size_t)=delete
 
void * operator new[] (std::size_t, void *p)=delete
 
void operator delete (void *)=delete
 
void operator delete (void *p, void *)=delete
 
void operator delete[] (void *)=delete
 
void operator delete[] (void *p, void *)=delete
 
 ScratchSpace (const size_type size_, const MString &, const MString &)
 
 ScratchSpace (const size_type size0, const size_type size1, const MString &, const MString &)
 
size_type size () const
 
void fill (const T value)
 
reference operator[] (const size_type pos)
 
reference operator() (const size_type pos)
 
const_reference operator[] (const size_type pos) const
 
const_reference operator() (const size_type pos) const
 
reference operator() (const size_type i, const size_type j)
 
const_reference operator() (const size_type i, const size_type j) const
 
T * getPointer ()
 
pointer data ()
 
const_pointer data () const
 
iterator begin ()
 
iterator end ()
 
iterator cbegin () const
 
iterator cend () const
 
MInt size0 () const
 
MInt size1 () const
 
MInt size2 () const
 
- Public Member Functions inherited from ScratchSpaceBase
 ScratchSpaceBase (size_t num, size_t size, MString name, MString varname)
 Constructor. More...
 
virtual MString printSelfReport () const =0
 
virtual MString printSelf () const =0
 

Public Attributes

pointer p
 Deprecated: use [] instead! More...
 
p_ p
 
- Public Attributes inherited from ScratchSpaceBase
const size_t m_memsize
 
const size_t m_memsizePadded
 
const MString m_calling_function
 
const MString m_variable_name
 
MInt m_object_id {}
 
MBool m_nonterminal
 
MBool m_destroy
 

Private Types

using Storage = std::vector< T >
 

Private Member Functions

void init ()
 extended constructor functionality More...
 
void checkForEmptyScratch () const
 Checks if scratch space is empty before returning a pointer to it. More...
 
template<class Integral >
void testBounds (const Integral &i) const
 Assert the bounds of 1D acces to an array. More...
 
template<class Integral >
MBool checkBounds (const Integral &i) const
 
template<class Integral >
MBool checkBounds (const Integral &i, maia::maia_unsigned) const
 
template<class Integral >
MBool checkBounds (const Integral &i, maia::maia_signed) const
 

Private Attributes

pointer last
 
const MInt m_size0
 
const MInt m_size1
 
const MInt m_size2
 
size_type m_size0
 
size_type m_size1
 
size_type m_size2
 
Storage m_data
 

Friends

template<class >
std::ostream & operator<< (std::ostream &os, const ScratchSpace &s)
 Print contents of scratch space object. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ScratchSpaceBase
static const uintptr_t ALIGNMENT_BOUNDARY = MAIA_SCRATCH_ALIGNMENT_BOUNDARY
 

Detailed Description

template<typename T>
class ScratchSpace< T >
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

This class is a derivative of ScratchSpaceBase and is responsible for the management of the scratch space to be allocated. Scratch objects partially model the container concept and should be usable with some, but not all, STL algorithms.

Definition at line 758 of file scratch.h.

Member Typedef Documentation

◆ const_iterator [1/2]

template<typename T >
using ScratchSpace< T >::const_iterator = const_pointer

Definition at line 240 of file scratch.h.

◆ const_iterator [2/2]

template<typename T >
using ScratchSpace< T >::const_iterator = typename Storage::const_iterator

Definition at line 768 of file scratch.h.

◆ const_pointer [1/2]

template<typename T >
using ScratchSpace< T >::const_pointer = const value_type*

Definition at line 238 of file scratch.h.

◆ const_pointer [2/2]

template<typename T >
using ScratchSpace< T >::const_pointer = typename Storage::const_pointer

Definition at line 766 of file scratch.h.

◆ const_reference [1/2]

template<typename T >
using ScratchSpace< T >::const_reference = const value_type&

Definition at line 236 of file scratch.h.

◆ const_reference [2/2]

template<typename T >
using ScratchSpace< T >::const_reference = typename Storage::const_reference

Definition at line 764 of file scratch.h.

◆ difference_type

template<typename T >
using ScratchSpace< T >::difference_type = long

Definition at line 241 of file scratch.h.

◆ iterator [1/2]

template<typename T >
using ScratchSpace< T >::iterator = pointer

Definition at line 239 of file scratch.h.

◆ iterator [2/2]

template<typename T >
using ScratchSpace< T >::iterator = typename Storage::iterator

Definition at line 767 of file scratch.h.

◆ pointer [1/2]

template<typename T >
using ScratchSpace< T >::pointer = value_type*

Definition at line 237 of file scratch.h.

◆ pointer [2/2]

template<typename T >
using ScratchSpace< T >::pointer = typename Storage::pointer

Definition at line 765 of file scratch.h.

◆ reference [1/2]

template<typename T >
using ScratchSpace< T >::reference = value_type&

Definition at line 235 of file scratch.h.

◆ reference [2/2]

template<typename T >
using ScratchSpace< T >::reference = typename Storage::reference

Definition at line 763 of file scratch.h.

◆ size_type [1/2]

template<typename T >
using ScratchSpace< T >::size_type = std::size_t

Definition at line 242 of file scratch.h.

◆ size_type [2/2]

template<typename T >
using ScratchSpace< T >::size_type = MLong

Definition at line 769 of file scratch.h.

◆ Storage

template<typename T >
using ScratchSpace< T >::Storage = std::vector<T>
private

Definition at line 759 of file scratch.h.

◆ value_type [1/2]

template<typename T >
using ScratchSpace< T >::value_type = T

Definition at line 234 of file scratch.h.

◆ value_type [2/2]

template<typename T >
using ScratchSpace< T >::value_type = T

Definition at line 762 of file scratch.h.

Constructor & Destructor Documentation

◆ ScratchSpace() [1/7]

template<class T >
ScratchSpace< T >::ScratchSpace ( MInt  num,
const MString name,
const MString varname 
)

Constructor.

Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

Allocates a scratch space element of a certain type. If not enough memory is available provided by the Scratch class, it terminates the program run. Otherwise the properties of this management object are set and a pointer to this object is stored in the management list of the Scratch class. If a maximum of memory of the Scratch is used, the state stored to be outputed at the end of the program run to enable memory analysis.

Parameters
[num]num number of elements in array
[name]name the name of the calling function
[varname]varname the name of the array variable

Note: If MAIA_EXTRA_DEBUG is defined writes a SCRATCH_DOUBLE_ALLOCATION WARNING at run-time if allocation of two variables with the same name is performed.

Definition at line 388 of file scratch.h.

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}
static char * m_nextfree
Definition: scratch.h:168
This class is a base class for all ScratchSpaces.
Definition: scratch.h:182
pointer last
Definition: scratch.h:333
const MInt m_size2
Definition: scratch.h:337
const MInt m_size1
Definition: scratch.h:336
pointer p
Deprecated: use [] instead!
Definition: scratch.h:315
const MInt m_size0
Definition: scratch.h:335
void init()
extended constructor functionality
Definition: scratch.h:451
constexpr T mMax(const T &x, const T &y)
Definition: functions.h:94

◆ ScratchSpace() [2/7]

template<class T >
ScratchSpace< T >::ScratchSpace ( MInt  num0,
MInt  num1,
const MString name,
const MString varname 
)

Constructor for 2D scratch.

Author
Lennart
Date
26.02.2013

This is the 2D-extension of the 1D constructor above. Unfortunately, the order of constructor arguments prohibits the use of a constructor default value for the second dimension, so most of the code here is redundant.

Definition at line 408 of file scratch.h.

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}

◆ ScratchSpace() [3/7]

template<class T >
ScratchSpace< T >::ScratchSpace ( MInt  num0,
MInt  num1,
MInt  num2,
const MString name,
const MString varname 
)

Constructor for 3D scratch.

Author
Lennart
Date
26.02.2013

This is the 3D-extension of the 1D constructor above. Unfortunately, the order of constructor arguments prohibits the use of constructor default values for the second and third dimension, so most of the code here is redundant.

Definition at line 430 of file scratch.h.

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}

◆ ~ScratchSpace()

template<class T >
ScratchSpace< T >::~ScratchSpace
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

Removes this scratch space elemet from the list of all scratch elements.

Only delete if we are at the last element (guaranteed by C++)

Definition at line 521 of file scratch.h.

521 {
522 if(!m_destroy) {
523 auto it = Scratch::m_scratchSpaces.end();
524 it--;
525
527 if((*it)->m_object_id == m_object_id) {
530 Scratch::m_scratchSpaces.erase(it);
531 }
532
533 if(m_nonterminal) {
535 }
536 }
537}
static ScratchList m_scratchSpaces
Definition: scratch.h:169
static size_t m_usedmemsize
Definition: scratch.h:167
MBool m_nonterminal
Definition: scratch.h:191
MBool m_destroy
Definition: scratch.h:192
const size_t m_memsizePadded
Definition: scratch.h:187
MInt m_object_id
Definition: scratch.h:190

◆ ScratchSpace() [4/7]

template<typename T >
ScratchSpace< T >::ScratchSpace ( )
delete

◆ ScratchSpace() [5/7]

template<typename T >
ScratchSpace< T >::ScratchSpace ( const ScratchSpace< T > &  )
delete

◆ ScratchSpace() [6/7]

template<typename T >
ScratchSpace< T >::ScratchSpace ( const size_type  size_,
const MString ,
const MString  
)
inline

Definition at line 771 of file scratch.h.

772 : m_size0(size_), m_size1(1), m_data(m_size0 * m_size1), p{*this} {}
Storage m_data
Definition: scratch.h:819

◆ ScratchSpace() [7/7]

template<typename T >
ScratchSpace< T >::ScratchSpace ( const size_type  size0,
const size_type  size1,
const MString ,
const MString  
)
inline

Definition at line 773 of file scratch.h.

774 : m_size0(size0), m_size1(size1), m_data(m_size0 * m_size1), p{*this} {}
MInt size1() const
Definition: scratch.h:299
MInt size0() const
Definition: scratch.h:298

Member Function Documentation

◆ begin() [1/2]

template<typename T >
iterator ScratchSpace< T >::begin ( )
inline

Definition at line 273 of file scratch.h.

273 {
275 return p;
276 }
void checkForEmptyScratch() const
Checks if scratch space is empty before returning a pointer to it.
Definition: scratch.h:738

◆ begin() [2/2]

template<typename T >
iterator ScratchSpace< T >::begin ( )
inline

Definition at line 800 of file scratch.h.

800{ return m_data.begin(); }

◆ cbegin() [1/2]

template<typename T >
iterator ScratchSpace< T >::cbegin ( ) const
inline

Definition at line 277 of file scratch.h.

277 {
279 return p;
280 }

◆ cbegin() [2/2]

template<typename T >
iterator ScratchSpace< T >::cbegin ( ) const
inline

Definition at line 802 of file scratch.h.

802{ return m_data.cbegin(); }

◆ cend() [1/2]

template<typename T >
iterator ScratchSpace< T >::cend ( ) const
inline

Definition at line 285 of file scratch.h.

285 {
287 return last;
288 }

◆ cend() [2/2]

template<typename T >
iterator ScratchSpace< T >::cend ( ) const
inline

Definition at line 803 of file scratch.h.

803{ return m_data.cend(); }

◆ checkBounds() [1/3]

template<typename T >
template<class Integral >
MBool ScratchSpace< T >::checkBounds ( const Integral &  i) const
inlineprivate

Definition at line 351 of file scratch.h.

351 {
352 using type = typename maia::is_unsigned<Integral>::type;
353 return checkBounds(i, type());
354 }
MBool checkBounds(const Integral &i) const
Definition: scratch.h:351

◆ checkBounds() [2/3]

template<typename T >
template<class Integral >
MBool ScratchSpace< T >::checkBounds ( const Integral &  i,
maia::maia_signed   
) const
inlineprivate

Definition at line 360 of file scratch.h.

360 {
361 return i >= 0 && static_cast<size_type>(i) < size();
362 }
size_type size() const
Definition: scratch.h:302
std::size_t size_type
Definition: scratch.h:242

◆ checkBounds() [3/3]

template<typename T >
template<class Integral >
MBool ScratchSpace< T >::checkBounds ( const Integral &  i,
maia::maia_unsigned   
) const
inlineprivate

Definition at line 356 of file scratch.h.

356 {
357 return static_cast<size_type>(i) < size();
358 }

◆ checkForEmptyScratch()

template<class T >
void ScratchSpace< T >::checkForEmptyScratch
inlineprivate

Note: the check is only performed if NDEBUG is not defined, and MAIA_EXTRA_DEBUG is defined.

Definition at line 738 of file scratch.h.

738 {
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}
const MString m_variable_name
Definition: scratch.h:189
const MString m_calling_function
Definition: scratch.h:188
MBool empty() const
Definition: scratch.h:306
InfoOutFile m_log

◆ data() [1/4]

template<typename T >
pointer ScratchSpace< T >::data ( )
inline

Definition at line 289 of file scratch.h.

289 {
291 return begin();
292 }
iterator begin()
Definition: scratch.h:273

◆ data() [2/4]

template<typename T >
pointer ScratchSpace< T >::data ( )
inline

Definition at line 797 of file scratch.h.

797{ return m_data.data(); }

◆ data() [3/4]

template<typename T >
const_pointer ScratchSpace< T >::data ( ) const
inline

Definition at line 293 of file scratch.h.

293 {
295 return begin();
296 }

◆ data() [4/4]

template<typename T >
const_pointer ScratchSpace< T >::data ( ) const
inline

Definition at line 798 of file scratch.h.

798{ return m_data.data(); }

◆ empty()

template<typename T >
MBool ScratchSpace< T >::empty ( ) const
inline

Definition at line 306 of file scratch.h.

306 {
307 ASSERT(last >= p, "Scratch cannot have negative size!");
308 return static_cast<bool>(last - p == 0);
309 }

◆ end() [1/2]

template<typename T >
iterator ScratchSpace< T >::end ( )
inline

Definition at line 281 of file scratch.h.

281 {
283 return last;
284 }

◆ end() [2/2]

template<typename T >
iterator ScratchSpace< T >::end ( )
inline

Definition at line 801 of file scratch.h.

801{ return m_data.end(); }

◆ fill() [1/2]

template<typename T >
void ScratchSpace< T >::fill ( const T  value)
inline

Definition at line 777 of file scratch.h.

777{ std::fill(begin(), end(), value); }
iterator end()
Definition: scratch.h:281

◆ fill() [2/2]

template<typename T >
void ScratchSpace< T >::fill ( val)
inline

Definition at line 311 of file scratch.h.

◆ getMemsize()

template<typename T >
size_t ScratchSpace< T >::getMemsize ( ) const
inline

Definition at line 301 of file scratch.h.

301{ return (last - p) * sizeof(T); }

◆ getPointer() [1/2]

template<typename T >
T * ScratchSpace< T >::getPointer ( )
inline

Definition at line 796 of file scratch.h.

796{ return m_data.data(); }

◆ getPointer() [2/2]

template<typename T >
T * ScratchSpace< T >::getPointer ( ) const
inline

Definition at line 316 of file scratch.h.

◆ init()

template<class T >
void ScratchSpace< T >::init
private
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

Content was moved from the constructor body to this function since it is the same for all above constructors (Lennart)

Note
added 'placement new' operator, as previously the use of non-primitive types resulted in undefined behavior, Lennart 2013

Check if allocation would exceed the available scratch space:

Check for double allocation:

Definition at line 451 of file scratch.h.

451 {
453
455 Scratch::m_scratchSpaces.push_back(this);
456
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 }
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}
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 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 MString printSelfScratch()
Returns a string summing up the scratch state information.
Definition: scratch.cpp:48
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
const size_t m_memsize
Definition: scratch.h:186
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52

◆ operator delete() [1/2]

template<typename T >
void ScratchSpace< T >::operator delete ( void *  )
delete

◆ operator delete() [2/2]

template<typename T >
void ScratchSpace< T >::operator delete ( void *  p,
void *   
)
delete

◆ operator delete[]() [1/2]

template<typename T >
void ScratchSpace< T >::operator delete[] ( void *  )
delete

◆ operator delete[]() [2/2]

template<typename T >
void ScratchSpace< T >::operator delete[] ( void *  p,
void *   
)
delete

◆ operator new() [1/2]

template<typename T >
void * ScratchSpace< T >::operator new ( std::size_t  )
delete

◆ operator new() [2/2]

template<typename T >
void * ScratchSpace< T >::operator new ( std::size_t  ,
void *  p 
)
delete

◆ operator new[]() [1/2]

template<typename T >
void * ScratchSpace< T >::operator new[] ( std::size_t  )
delete

◆ operator new[]() [2/2]

template<typename T >
void * ScratchSpace< T >::operator new[] ( std::size_t  ,
void *  p 
)
delete

◆ operator()() [1/10]

template<class T >
template<class Integral >
ScratchSpace< T >::const_reference ScratchSpace< T >::operator() ( const Integral  i) const
inline

Definition at line 631 of file scratch.h.

631 {
632#if defined(MAIA_ASSERTS)
633 testBounds(i);
634#endif
635 return p[i];
636}
void testBounds(const Integral &i) const
Assert the bounds of 1D acces to an array.
Definition: scratch.h:601

◆ operator()() [2/10]

template<class T >
template<class Integral >
ScratchSpace< T >::reference ScratchSpace< T >::operator() ( const Integral  i)
inline

Access the i-th element of the scratch object.

Returns
Refernence to the i-th scratch space element
Parameters
[i]Index of Integral type.
[Integral]Type that models the Integral concept.

Note: if NDEBUG is not defined, the array bounds are checked: i >= 0 and i < size. If bound checking fails the program will terminate with a SCRATCH_OUT_OF_BOUNDS ERROR.

Definition at line 623 of file scratch.h.

623 {
624#if defined(MAIA_ASSERTS)
625 testBounds(i);
626#endif
627 return p[i];
628}

◆ operator()() [3/10]

template<class T >
template<class Integral >
ScratchSpace< T >::reference ScratchSpace< T >::operator() ( const Integral  i,
const Integral  j 
)
inline

2D and 3D Scratch access

Note: this would probably result in a compilation error if m_sizeX

Definition at line 656 of file scratch.h.

656 {
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}

◆ operator()() [4/10]

template<class T >
template<class Integral >
ScratchSpace< T >::const_reference ScratchSpace< T >::operator() ( const Integral  i,
const Integral  j 
) const
inline

Definition at line 677 of file scratch.h.

677 {
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}

◆ operator()() [5/10]

template<class T >
template<class Integral >
ScratchSpace< T >::reference ScratchSpace< T >::operator() ( const Integral  i,
const Integral  j,
const Integral  k 
)
inline

Definition at line 666 of file scratch.h.

667 {
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}

◆ operator()() [6/10]

template<class T >
template<class Integral >
ScratchSpace< T >::const_reference ScratchSpace< T >::operator() ( const Integral  i,
const Integral  j,
const Integral  k 
) const
inline

Definition at line 687 of file scratch.h.

688 {
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}

◆ operator()() [7/10]

template<typename T >
reference ScratchSpace< T >::operator() ( const size_type  i,
const size_type  j 
)
inline

Definition at line 785 of file scratch.h.

785 {
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 }

◆ operator()() [8/10]

template<typename T >
const_reference ScratchSpace< T >::operator() ( const size_type  i,
const size_type  j 
) const
inline

Definition at line 790 of file scratch.h.

790 {
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 }

◆ operator()() [9/10]

template<typename T >
reference ScratchSpace< T >::operator() ( const size_type  pos)
inline

Definition at line 780 of file scratch.h.

780{ return m_data.at(pos); }

◆ operator()() [10/10]

template<typename T >
const_reference ScratchSpace< T >::operator() ( const size_type  pos) const
inline

Definition at line 782 of file scratch.h.

782{ return m_data.at(pos); }

◆ operator=()

template<class T >
ScratchSpace< T > & ScratchSpace< T >::operator= ( ScratchSpace< T > &  S)

Definition at line 697 of file scratch.h.

697 {
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}
constexpr T mMin(const T &x, const T &y)
Definition: functions.h:90

◆ operator[]() [1/4]

template<class T >
template<class Integral >
ScratchSpace< T >::const_reference ScratchSpace< T >::operator[] ( const Integral  i) const
inline

Definition at line 646 of file scratch.h.

646 {
647 return operator()(i);
648}
reference operator()(const Integral)
1D Scratch access
Definition: scratch.h:623

◆ operator[]() [2/4]

template<class T >
template<class Integral >
ScratchSpace< T >::reference ScratchSpace< T >::operator[] ( const Integral  i)
inline

For 1D access the [] operator is also provided, the () operator should be preferred.

Definition at line 641 of file scratch.h.

641 {
642 return operator()(i);
643}

◆ operator[]() [3/4]

template<typename T >
reference ScratchSpace< T >::operator[] ( const size_type  pos)
inline

Definition at line 779 of file scratch.h.

779{ return m_data.at(pos); }

◆ operator[]() [4/4]

template<typename T >
const_reference ScratchSpace< T >::operator[] ( const size_type  pos) const
inline

Definition at line 781 of file scratch.h.

781{ return m_data.at(pos); }

◆ printSelf()

template<class T >
MString ScratchSpace< T >::printSelf
overridevirtual
Authors
Andreas Lintermann, Stephan Schlimpert, Christoph Siewert
Date
10.05.2011, 10.06.2011, 21.10.2011
Returns
a string summing up this scratch space element information

Implements ScratchSpaceBase.

Definition at line 547 of file scratch.h.

547 {
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";
559 message += "\nVariable name:\t\t";
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}
const MString const MString & message
Definition: functions.h:37
std::basic_string< char > MString
Definition: maiatypes.h:55
MInt id
Definition: maiatypes.h:71

◆ printSelfReport()

template<class T >
MString ScratchSpace< T >::printSelfReport
overridevirtual
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

This function is used in the report process for tracking the occasion of maximal memory usage during program execution.

Returns
a shortened string summing up this scratch space element information

Implements ScratchSpaceBase.

Definition at line 583 of file scratch.h.

583 {
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: ";
594 message += " VAR: ";
596 return message;
597}

◆ size() [1/2]

template<typename T >
size_type ScratchSpace< T >::size ( ) const
inline

Definition at line 302 of file scratch.h.

302 {
303 ASSERT(last >= p, "Scratch cannot have negative size!");
304 return last - p;
305 }

◆ size() [2/2]

template<typename T >
size_type ScratchSpace< T >::size ( ) const
inline

Definition at line 776 of file scratch.h.

776{ return m_data.size(); }

◆ size0() [1/2]

template<typename T >
MInt ScratchSpace< T >::size0 ( ) const
inline

Definition at line 298 of file scratch.h.

298{ return m_size0; }

◆ size0() [2/2]

template<typename T >
MInt ScratchSpace< T >::size0 ( ) const
inline

Definition at line 811 of file scratch.h.

811{ return m_size0; }

◆ size1() [1/2]

template<typename T >
MInt ScratchSpace< T >::size1 ( ) const
inline

Definition at line 299 of file scratch.h.

299{ return m_size1; }

◆ size1() [2/2]

template<typename T >
MInt ScratchSpace< T >::size1 ( ) const
inline

Definition at line 812 of file scratch.h.

812{ return m_size1; }

◆ size2() [1/2]

template<typename T >
MInt ScratchSpace< T >::size2 ( ) const
inline

Definition at line 300 of file scratch.h.

300{ return m_size2; }

◆ size2() [2/2]

template<typename T >
MInt ScratchSpace< T >::size2 ( ) const
inline

Definition at line 813 of file scratch.h.

813{ return m_size2; }

◆ testBounds()

template<class T >
template<class Integral >
void ScratchSpace< T >::testBounds ( const Integral &  i) const
inlineprivate

Note: the condition is tested by checkBounds, which is overloaded for signed and unsigned indices using the maia::is_unsigned trait.

Todo:
labels:toenhance replace maia::is_unsigned with <type_traits>

Definition at line 601 of file scratch.h.

601 {
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}

Friends And Related Function Documentation

◆ operator<<

template<typename T >
template<class >
std::ostream & operator<< ( std::ostream &  os,
const ScratchSpace< T > &  s 
)
friend
Author
Michael Schlottke (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2015-03-13
Template Parameters
TElement type.
Parameters
[in]osStream object to write to.
[in]sScratch space object.
Returns
Stream object to allow chained writing

Note: if T is not convertible to string, the contents are not printed.

Definition at line 722 of file scratch.h.

722 {
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}
MString printSelf() const override
Returns a string summing up this scratch space element information.
Definition: scratch.h:547

Member Data Documentation

◆ last

template<typename T >
pointer ScratchSpace< T >::last
private

Definition at line 333 of file scratch.h.

◆ m_data

template<typename T >
Storage ScratchSpace< T >::m_data
private

Definition at line 819 of file scratch.h.

◆ m_size0 [1/2]

template<typename T >
const MInt ScratchSpace< T >::m_size0
private

Definition at line 335 of file scratch.h.

◆ m_size0 [2/2]

template<typename T >
size_type ScratchSpace< T >::m_size0
private

Definition at line 816 of file scratch.h.

◆ m_size1 [1/2]

template<typename T >
const MInt ScratchSpace< T >::m_size1
private

Definition at line 336 of file scratch.h.

◆ m_size1 [2/2]

template<typename T >
size_type ScratchSpace< T >::m_size1
private

Definition at line 817 of file scratch.h.

◆ m_size2 [1/2]

template<typename T >
const MInt ScratchSpace< T >::m_size2
private

Definition at line 337 of file scratch.h.

◆ m_size2 [2/2]

template<typename T >
size_type ScratchSpace< T >::m_size2
private

Definition at line 818 of file scratch.h.

◆ p [1/2]

template<typename T >
pointer ScratchSpace< T >::p

Definition at line 315 of file scratch.h.

◆ p [2/2]

template<typename T >
p_ ScratchSpace< T >::p

Definition at line 822 of file scratch.h.


The documentation for this class was generated from the following file: