58 #include <Teuchos_CommHelpers.hpp>
63 #elif defined(__unix__) || \
66 (defined(__APPLE__) && \
69 # include <sys/resource.h>
70 # if defined(__APPLE__) && \
72 # include <mach/mach.h>
73 # elif (defined(_AIX) || \
74 defined(__TOS__AIX__)) || \
75 (defined(__sun__) || \
82 # elif defined(__linux__) || \
85 defined(__gnu_linux__)
87 # endif // defined(__APPLE__) && ...
89 # error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
90 #endif // defined(_WIN32)
117 s <<
"Estimated memory usage across all processors:" << endl
118 <<
" Current Peak " << endl
119 <<
" ------------ ------------" << endl <<
" Min: ";
136 s << std::setw(9) << std::setfill(
' ');
139 else if (num < (1 << 20))
140 s << (static_cast<double>(num) / (1 << 10)) <<
" KB ";
141 else if (num < (1 << 30))
142 s << (static_cast<double>(num) / (1 << 20)) <<
" MB ";
144 s << (static_cast<double>(num) / (1 << 30)) <<
" GB ";
157 return current + peak;
171 PROCESS_MEMORY_COUNTERS info;
172 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
173 mem = (size_t)(info.PeakWorkingSetSize);
176 # elif (defined(_AIX) || \
177 defined(__TOS__AIX__)) || \
178 (defined(__sun__) || \
181 (defined(__SVR4) || \
183 struct psinfo psinfo;
185 if ((fd = open(
"/proc/self/psinfo", O_RDONLY)) == -1)
187 if (read(fd, &psinfo,
sizeof(psinfo)) !=
sizeof(psinfo))
193 mem = (size_t)(psinfo.pr_rssize * 1024L);
196 # elif defined(__unix__) || \
199 (defined(__APPLE__) && \
201 struct rusage rusage;
202 getrusage(RUSAGE_SELF, &rusage);
203 # if defined(__APPLE__) && \
205 mem = (size_t)(rusage.ru_maxrss);
207 mem = (size_t)(rusage.ru_maxrss * 1024L);
208 # endif // defined(__APPLE__) && ...
213 # endif // defined(_WIN32)
228 PROCESS_MEMORY_COUNTERS info;
229 GetProcessMemoryInfo(GetCurrentProcess(), &info,
sizeof(info));
230 mem = (size_t)(info.WorkingSetSize);
233 # elif defined(__APPLE__) && \
235 struct mach_task_basic_info info;
236 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
237 if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
238 (task_info_t)(&info), &infoCount) != KERN_SUCCESS)
240 mem = (size_t)(info.resident_size);
243 # elif defined(__linux__) || \
244 defined(__linux) || \
246 defined(__gnu_linux__)
249 if ((fp = fopen(
"/proc/self/statm",
"r")) == NULL)
251 if (fscanf(fp,
"%*s%ld", &rss) != 1)
257 mem = (size_t)(rss) * (size_t)(sysconf(_SC_PAGESIZE));
262 # endif // defined(_WIN32)
274 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.