11 #include <sys/types.h>
15 int sbrk(
int) {
return 0; }
19 int memusageinit::initialized;
20 unsigned long memusageinit::sbrkval;
23 if ( initialized == 0 ) {
24 sbrkval = (
unsigned long) sbrk(0);
29 unsigned long memusageinit::memusage_sbrk() {
30 unsigned long newval = (
unsigned long) sbrk(0);
31 return ( newval - memusageinit::sbrkval );
36 #define MEMUSAGE_USE_SBRK
43 #ifdef MEMUSAGE_USE_SBRK
49 #ifdef MEMUSAGE_USE_MSTATS
51 #include <malloc/malloc.h>
54 struct mstats ms = mstats();
55 unsigned long memtotal = ms.bytes_used;
69 struct mallinfo mi = mallinfo();
71 unsigned long memtotal = (
unsigned int) mi.uordblks;
72 unsigned long memtotal2 = (
unsigned int) mi.usmblks;
73 memtotal2 += (
unsigned int) mi.hblkhd;
74 if ( memtotal2 > memtotal ) memtotal = memtotal2;
91 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
92 sprintf(pscmd,
"/bin/ps -o rss= -p %d", getpid());
94 sprintf(pscmd,
"/bin/ps -o vsz= -p %d", getpid());
96 unsigned long vsz = 0;
97 FILE *p = popen(pscmd,
"r");
99 fscanf(p,
"%ld", &vsz);
102 return ( vsz * (
unsigned long) 1024 );
110 #include <spi/include/kernel/memory.h>
111 inline long long memusage_bgq(){
113 Kernel_GetMemorySize(KERNEL_MEMSIZE_HEAP, &heap);
123 inline long long memusage_bgp(){
124 struct mallinfo m = mallinfo();
125 long long hblkhd = (
unsigned int) m.hblkhd;
126 long long uordblks = (
unsigned int) m.uordblks;
127 return hblkhd + uordblks;
135 static int failed_once = 0;
136 if ( failed_once )
return 0;
138 FILE *f = fopen(
"/proc/self/stat",
"r");
139 if ( ! f ) { failed_once = 1;
return 0; }
140 for (
int i=0; i<22; ++i ) fscanf(f,
"%*s");
141 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
145 unsigned long vsz = 0;
146 fscanf(f,
"%lu",&vsz);
148 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
149 vsz *= sysconf(_SC_PAGESIZE);
151 if ( ! vsz ) failed_once = 1;
160 unsigned long memtotal = 0;
161 const char* s =
"ERROR";
163 if ( ! CmiMemoryIs(CMI_MEMORY_IS_OS) ) {
164 memtotal = CmiMemoryUsage(); s =
"CmiMemoryUsage";
168 if( ! memtotal) { memtotal = memusage_bgq(); s=
"Kernel_GetMemorySize on BG/Q"; }
172 if( ! memtotal) { memtotal = memusage_bgp(); s=
"mallinfo on BG/P"; }
175 #if defined(WIN32) && !defined(__CYGWIN__)
177 memtotal = CmiMemoryUsage(); s =
"GetProcessMemoryInfo";
189 if ( ! memtotal ) { memtotal = memusageinit::memusage_sbrk(); s =
"sbrk"; }
191 if ( ! memtotal ) { memtotal =
memusage_ps(); s =
"ps"; }
193 if ( ! memtotal ) { memtotal = CmiMemoryUsage(); s =
"CmiMemoryUsage"; }
195 if ( ! memtotal ) s =
"nothing";
197 if ( source ) *source = s;
unsigned long memusage_mallinfo()
if(ComputeNonbondedUtil::goMethod==2)
unsigned long memusage_ps()
unsigned long memusage_proc_self_stat()
unsigned long memusage(const char **source)
unsigned long memusage_mstats()