MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
genericobject.cpp
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#include "genericobject.h"
8
9#include <fstream>
10#include <iomanip>
11#include <typeinfo>
12#include "COMM/mpioverride.h"
13#include "IO/infoout.h"
14#include "UTIL/debug.h"
15#include "UTIL/timer.h"
16#include "globalvariables.h"
17
18using namespace std;
19using namespace maia::alloc;
20
26void printAllocatedMemory(const MLong oldAllocatedBytes, const MString& solverName, const MPI_Comm comm) {
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}
50
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}
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
void printAllocatedMemory(const MLong oldAllocatedBytes, const MString &solverName, const MPI_Comm comm)
Prints currently allocated memory.
MInt globalNoDomains()
Return global number of domains.
MInt globalDomainId()
Return global domain id.
InfoOutFile m_log
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
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