MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
Scratch Class Reference

This class holds the complete scratch space. More...

#include <scratch.h>

Collaboration diagram for Scratch:
[legend]

Public Member Functions

 Scratch (MFloat size, MInt Cells)
 Constructor. More...
 
 ~Scratch ()
 Destructor. More...
 

Static Public Member Functions

static char * getEndPointer ()
 Returns a pointer to the end of the scratch. More...
 
static size_t getAvailableMemory ()
 Returns the amount of available memory in scratch. More...
 
static size_t getTotalMemory ()
 Returns the amount of total available memory in scratch. More...
 
static MString printSelfScratch ()
 Returns a string summing up the scratch state information. More...
 
static MString printSelf ()
 Returns a string summing up the scratch state information and all scratch space elements information. More...
 
static MString printSelfReport ()
 Returns a shortened string summing up the scratch space state information. More...
 
static MFloat getAvailableMemory ()
 

Static Public Attributes

static size_t m_number_of_cells
 
static size_t m_number_of_elements
 
static MInt m_object_id = 0
 
static char * m_totalScratch
 
static size_t m_usedmemsize
 
static char * m_nextfree
 
static ScratchList m_scratchSpaces
 
static char * m_maxused
 
static MString m_report
 

Static Private Attributes

static const uintptr_t ALIGNMENT_BOUNDARY = MAIA_SCRATCH_ALIGNMENT_BOUNDARY
 

Friends

class ScratchSpaceBase
 

Detailed Description

Authors
Andreas Lintermann, Stephan Schlimpert, Christoph Siewert
Date
10.05.2011, 10.06.2011, 21.10.2011

This class defines the overall size of the scratch space and tracks the sizes and allocation of newly requested Scratch space arrays.

Definition at line 91 of file scratch.h.

Constructor & Destructor Documentation

◆ Scratch()

Scratch::Scratch ( MFloat  size,
MInt  Cells 
)
Authors
Andreas Lintermann, Stephan Schlimpert, Christoph Siewert
Date
10.05.2011, 10.06.2011, 21.10.2011
Note
Base memory now points to an aligned memory address, Lennart Schneiders, 12.12.2012

Allocates space of "size * sizeof(MFloat) * Cells" bytes, that is "size" MFloat for every cell.

Parameters
[in]sizenumber of MFloat for every cell.
[in]Cellsnumber of cells.

Definition at line 27 of file scratch.cpp.

27 {
28 m_number_of_cells = Cells;
33
35 ASSERT((((uintptr_t)m_nextfree) % ALIGNMENT_BOUNDARY == 0), "Scratch memory is not aligned");
36
38}
static MString m_report
Definition: scratch.h:171
static const uintptr_t ALIGNMENT_BOUNDARY
Definition: scratch.h:94
static size_t m_number_of_elements
Definition: scratch.h:164
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 m_number_of_cells
Definition: scratch.h:163
static char * m_maxused
Definition: scratch.h:170
static char * m_totalScratch
Definition: scratch.h:166
double MFloat
Definition: maiatypes.h:52

◆ ~Scratch()

Scratch::~Scratch ( )
inline
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011

Definition at line 117 of file scratch.h.

117 {
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 };
static ScratchList m_scratchSpaces
Definition: scratch.h:169
static MInt m_object_id
Definition: scratch.h:165
static size_t m_usedmemsize
Definition: scratch.h:167

Member Function Documentation

◆ getAvailableMemory() [1/2]

static size_t Scratch::getAvailableMemory ( )
inlinestatic
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011
Returns
the amount of available memory

Definition at line 148 of file scratch.h.

◆ getAvailableMemory() [2/2]

static MFloat Scratch::getAvailableMemory ( )
inlinestatic

Definition at line 837 of file scratch.h.

837{ return 100; }

◆ getEndPointer()

static char * Scratch::getEndPointer ( )
inlinestatic
Authors
Andreas Lintermann, Stephan Schlimpert, Christoph Siewert
Date
10.05.2011, 10.06.2011, 21.01.2011
Returns
a pointer to the end of the scratch

Definition at line 137 of file scratch.h.

137{ return (char*)(size_t)(m_totalScratch + m_number_of_elements - 1); }

◆ getTotalMemory()

static size_t Scratch::getTotalMemory ( )
inlinestatic
Author
Andreas Lintermann. Christoph Siewert
Date
10.05.2011, 21.10.2011
Returns
the amount of total available memory

Definition at line 157 of file scratch.h.

157{ return (getEndPointer() + 1 - m_totalScratch); }
static char * getEndPointer()
Returns a pointer to the end of the scratch.
Definition: scratch.h:137

◆ printSelf()

string Scratch::printSelf ( )
static
Author
Andreas Lintermann, Christoph Siewert
Date
10.05.2011, 21.10.2011
Returns
a string summing up the scratch state information and all scratch space elements information

Definition at line 106 of file scratch.cpp.

106 {
107 string message = printSelfScratch();
108 ScratchList::iterator iter;
109
110 for(iter = Scratch::m_scratchSpaces.begin(); iter != Scratch::m_scratchSpaces.end(); iter++) {
111 message += (*iter)->printSelf();
112 message += "\n";
113 }
114
115 message += "\n\n";
116 return message;
117}
const MString const MString & message
Definition: functions.h:37

◆ printSelfReport()

string Scratch::printSelfReport ( )
static
Author
Andreas Lintermann
Date
10.05.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 the scratch space state information

Definition at line 129 of file scratch.cpp.

129 {
130 string message = m_report;
131 message += "\n\n";
132 return message;
133}

◆ printSelfScratch()

string Scratch::printSelfScratch ( )
static
Authors
Andreas Lintermann, Stephan Schlimpert, Christoph Siewert
Date
10.05.2011, 10.06.2011, 21.10.2011
Returns
a string summing up the scratch state information

Definition at line 48 of file scratch.cpp.

48 {
49 stringstream begin, end, nextfree, number, total, totalmb, used, usedmb, available, availablemb, maxmem, maxmemmb;
50 const MFloat bytesInAMegaByte = 1048576.0;
51 begin << (MInt*)m_totalScratch;
52 end << (MInt*)getEndPointer();
53 nextfree << (MInt*)m_nextfree;
54 number << m_number_of_elements;
55 total << getTotalMemory();
56 totalmb << (MFloat)getTotalMemory() / bytesInAMegaByte;
57 used << m_usedmemsize;
58 usedmb << (MFloat)m_usedmemsize / bytesInAMegaByte;
59 available << getAvailableMemory();
60 availablemb << (MFloat)getAvailableMemory() / bytesInAMegaByte;
61 maxmem << (m_maxused - m_totalScratch);
62 maxmemmb << (MFloat)(m_maxused - m_totalScratch) / bytesInAMegaByte;
63
64 string message = "\n\nScratch:";
65 message += "\n-----------------------------\n";
66 message += "Bytes allocated:\t\t";
67 message += number.str();
68 message += "\nTotal memory:\t\t\t";
69 message += total.str();
70 message += "\t(";
71 message += totalmb.str();
72 message += "MB)";
73 message += "\nUsed memory:\t\t\t";
74 message += used.str();
75 message += "\t(";
76 message += usedmb.str();
77 message += "MB)";
78 message += "\nFree memory:\t\t\t";
79 message += available.str();
80 message += "\t(";
81 message += availablemb.str();
82 message += "MB)";
83 message += "\nMax memory:\t\t\t";
84 message += maxmem.str();
85 message += "\t(";
86 message += maxmemmb.str();
87 message += "MB)";
88 message += "\nScratch start pointer:\t\t";
89 message += begin.str();
90 message += "\nScratch end pointer:\t\t";
91 message += end.str();
92 message += "\nNext free pointer:\t\t";
93 message += nextfree.str();
94 message += "\n\n";
95
96 return message;
97}
static size_t getAvailableMemory()
Returns the amount of available memory in scratch.
Definition: scratch.h:148
static size_t getTotalMemory()
Returns the amount of total available memory in scratch.
Definition: scratch.h:157
int32_t MInt
Definition: maiatypes.h:62

Friends And Related Function Documentation

◆ ScratchSpaceBase

friend class ScratchSpaceBase
friend

Definition at line 92 of file scratch.h.

Member Data Documentation

◆ ALIGNMENT_BOUNDARY

const uintptr_t Scratch::ALIGNMENT_BOUNDARY = MAIA_SCRATCH_ALIGNMENT_BOUNDARY
staticprivate

Definition at line 94 of file scratch.h.

◆ m_maxused

char * Scratch::m_maxused
static

Definition at line 170 of file scratch.h.

◆ m_nextfree

char * Scratch::m_nextfree
static

Definition at line 168 of file scratch.h.

◆ m_number_of_cells

size_t Scratch::m_number_of_cells
static

Definition at line 163 of file scratch.h.

◆ m_number_of_elements

size_t Scratch::m_number_of_elements
static

Definition at line 164 of file scratch.h.

◆ m_object_id

MInt Scratch::m_object_id = 0
static

Definition at line 165 of file scratch.h.

◆ m_report

string Scratch::m_report
static

Definition at line 171 of file scratch.h.

◆ m_scratchSpaces

ScratchList Scratch::m_scratchSpaces
static

Definition at line 169 of file scratch.h.

◆ m_totalScratch

char * Scratch::m_totalScratch
static

Definition at line 166 of file scratch.h.

◆ m_usedmemsize

size_t Scratch::m_usedmemsize
static

Definition at line 167 of file scratch.h.


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