26 #include <Teuchos_CommHelpers.hpp>
31 #elif defined(__unix__) || \
34 (defined(__APPLE__) && \
37 # include <sys/resource.h>
38 # if defined(__APPLE__) && \
40 # include <mach/mach.h>
41 # elif (defined(_AIX) || \
42 defined(__TOS__AIX__)) || \
43 (defined(__sun__) || \
50 # elif defined(__linux__) || \
53 defined(__gnu_linux__)
55 # endif // defined(__APPLE__) && ...
57 # error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
58 #endif // defined(_WIN32)
85 s <<
"Estimated memory usage across all processors:" << endl
86 <<
" Current Peak " << endl
87 <<
" ------------ ------------" << endl <<
" Min: ";
104 s << std::setw(9) << std::setfill(
' ');
107 else if (num < (1 << 20))
108 s << (static_cast<double>(num) / (1 << 10)) <<
" KB ";
109 else if (num < (1 << 30))
110 s << (static_cast<double>(num) / (1 << 20)) <<
" MB ";
112 s << (static_cast<double>(num) / (1 << 30)) <<
" GB ";
125 return current + peak;
139 PROCESS_MEMORY_COUNTERS info;
140 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
141 mem = (size_t)(info.PeakWorkingSetSize);
144 # elif (defined(_AIX) || \
145 defined(__TOS__AIX__)) || \
146 (defined(__sun__) || \
149 (defined(__SVR4) || \
151 struct psinfo psinfo;
153 if ((fd = open(
"/proc/self/psinfo", O_RDONLY)) == -1)
155 if (read(fd, &psinfo,
sizeof(psinfo)) !=
sizeof(psinfo))
161 mem = (size_t)(psinfo.pr_rssize * 1024L);
164 # elif defined(__unix__) || \
167 (defined(__APPLE__) && \
169 struct rusage rusage;
170 getrusage(RUSAGE_SELF, &rusage);
171 # if defined(__APPLE__) && \
173 mem = (size_t)(rusage.ru_maxrss);
175 mem = (size_t)(rusage.ru_maxrss * 1024L);
176 # endif // defined(__APPLE__) && ...
181 # endif // defined(_WIN32)
196 PROCESS_MEMORY_COUNTERS info;
197 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
198 mem = (size_t)(info.WorkingSetSize);
201 # elif defined(__APPLE__) && \
203 struct mach_task_basic_info info;
204 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
205 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
206 (task_info_t)(&info), &infoCount) != KERN_SUCCESS)
208 mem = (size_t)(info.resident_size);
211 # elif defined(__linux__) || \
212 defined(__linux) || \
214 defined(__gnu_linux__)
217 if ((fp = fopen(
"/proc/self/statm",
"r")) == NULL)
219 if (fscanf(fp,
"%*s%ld", &rss) != 1)
225 mem = (size_t)(rss) * (size_t)(sysconf(_SC_PAGESIZE));
230 # endif // defined(_WIN32)
242 size_t min(0), max(0), tot(0);
virtual int getRank() const =0
The memory usage information.
MemUsage getCurrentRSS(const Teuchos::Comm< int > &comm)
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
MemUsage getMemoryUsage(const Teuchos::Comm< int > &comm)
Get memory usage in B.
MemUsage getPeakRSS(const Teuchos::Comm< int > &comm)
void pretty(std::ostream &s, size_t num)
void printMemoryUsage(std::ostream &s, const Teuchos::Comm< int > &comm)
Print memory usage to stream.
MemUsage reduceMemUsage(size_t &mem, const Teuchos::Comm< int > &comm, const MemUsageType &type)
Reduce the memory usage over all the processors.