Loading [MathJax]/extensions/tex2jax.js
MAIA bb96820c
Multiphysics at AIA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
genericobject.h File Reference

Go to the source code of this file.

Classes

class  GenericObject
 class containing a generic object More...
 
class  GenericPointer< T >
 class containing a generic pointer More...
 

Functions

void printAllocatedMemory (const MLong oldAllocatedBytes, const MString &solverName, const MPI_Comm comm)
 Prints currently allocated memory. More...
 
MString getMemorySize (MLong noBytes)
 Returns memory size in KB, MB or GB. More...
 

Function Documentation

◆ getMemorySize()

MString getMemorySize ( MLong  noBytes)
Author
Lennart Schneiders
Date
09.12.2011

Definition at line 51 of file genericobject.cpp.

51 {
52 stringstream size;
53 size.str("");
54 char buffer[32];
55 if((MFloat)noBytes / (1024 * 1024) < 1.0) {
56 MFloat tmp = (MFloat)noBytes / (1024);
57 sprintf(buffer, "%6.2f", tmp);
58 size << buffer << " KB";
59 } else if(((MFloat)noBytes / (1024 * 1024 * 1024)) > 1.0) {
60 MFloat tmp = (MFloat)noBytes / (1024 * 1024 * 1024);
61 sprintf(buffer, "%6.2f", tmp);
62 size << buffer << " GB";
63 } else {
64 MFloat tmp = (MFloat)noBytes / (1024 * 1024);
65 sprintf(buffer, "%6.2f", tmp);
66 size << buffer << " MB";
67 }
68 return size.str();
69}
double MFloat
Definition: maiatypes.h:52

◆ printAllocatedMemory()

void printAllocatedMemory ( const MLong  oldAllocatedBytes,
const MString solverName,
const MPI_Comm  comm 
)
Author
Lennart Schneiders
Date
08.12.2011
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 26 of file genericobject.cpp.

26 {
27 TRACE();
28
29 m_log << fixed << "=================================================" << endl;
30 m_log.precision(6);
31 m_log << getMemorySize(g_allocatedBytes - oldAllocatedBytes) << " allocated by " << solverName << "." << endl;
32 m_log << "Total memory: " << getMemorySize(g_allocatedBytes) << "." << endl;
33 m_log << "=================================================" << endl;
34
35 MLong allocBytes = g_allocatedBytes;
36 MLong oldAllocBytes = oldAllocatedBytes;
37 MLong allocMax = allocBytes - oldAllocatedBytes;
38 if(globalNoDomains() > 1) {
39 MPI_Allreduce(MPI_IN_PLACE, &allocBytes, 1, MPI_LONG, MPI_SUM, comm, AT_, "MPI_IN_PLACE", "allocBytes");
40 MPI_Allreduce(MPI_IN_PLACE, &oldAllocBytes, 1, MPI_LONG, MPI_SUM, comm, AT_, "MPI_IN_PLACE", "oldAllocBytes");
41 MPI_Allreduce(MPI_IN_PLACE, &allocMax, 1, MPI_LONG, MPI_MAX, comm, AT_, "MPI_IN_PLACE", "oldAllocBytes");
42 }
43 if(globalDomainId() == 0) {
44 cerr.precision(6);
45 cerr << "=== " << getMemorySize(allocBytes - oldAllocBytes) << " globally allocated by " << solverName
46 << ". Total global memory: " << getMemorySize(allocBytes) << ". ===" << endl;
47 cerr << "=== " << getMemorySize(allocMax) << " maximum globally allocated by " << solverName << ". ===" << endl;
48 }
49}
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
MInt globalNoDomains()
Return global number of domains.
MInt globalDomainId()
Return global domain id.
InfoOutFile m_log
int64_t MLong
Definition: maiatypes.h:64
int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Allreduce
MLong g_allocatedBytes