26 #elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
28 #include <sys/resource.h>
30 #if defined(__APPLE__) && defined(__MACH__)
31 #include <mach/mach.h>
33 #elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
37 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
43 #error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
55 PROCESS_MEMORY_COUNTERS info;
56 GetProcessMemoryInfo( GetCurrentProcess( ), &info,
sizeof(info) );
57 return (
size_t)info.PeakWorkingSetSize;
59 #elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
63 if ( (fd = open(
"/proc/self/psinfo", O_RDONLY )) == -1 )
65 if ( read( fd, &psinfo,
sizeof(psinfo) ) !=
sizeof(psinfo) )
71 return (
size_t)(psinfo.pr_rssize * 1024
L);
73 #elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
76 getrusage( RUSAGE_SELF, &rusage );
77 #if defined(__APPLE__) && defined(__MACH__)
78 return (
size_t)rusage.ru_maxrss;
80 return (
size_t)(rusage.ru_maxrss * 1024
L);
97 PROCESS_MEMORY_COUNTERS info;
98 GetProcessMemoryInfo( GetCurrentProcess( ), &info,
sizeof(info) );
99 return (
size_t)info.WorkingSetSize;
101 #elif defined(__APPLE__) && defined(__MACH__)
103 struct mach_task_basic_info info;
104 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
105 if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO,
106 (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
108 return (
size_t)info.resident_size;
110 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
114 if ( (
fp = fopen(
"/proc/self/statm",
"r" )) == NULL )
116 if ( fscanf(
fp,
"%*s%ld", &rss ) != 1 )
122 return (
size_t)rss * (size_t)sysconf( _SC_PAGESIZE);
130 inline int enforceMemoryLimit(
const MPI_Comm& PROTEUS_COMM_WORLD,
int rank,
double max_rss_gb,
const char* msg)
132 double current, current_global,gb(1.0e-9);
137 MPI_Allreduce(¤t,¤t_global,1,MPI_DOUBLE,MPI_MAX,PROTEUS_COMM_WORLD);
138 if (current > max_rss_gb)
140 std::cout<<
"Raising PETSC_ERR_MEM, Memory usage on rank "<<rank<<
'\t'<<current<<
"GB"<<
'\t'<<
"limit "<<max_rss_gb<<std::endl;
141 SETERRABORT(PROTEUS_COMM_WORLD,PETSC_ERR_MEM,
"Exceeded Proteus memory limit");
144 std::cout<<msg<<std::endl
145 <<
"Max memory usage per core "<<current_global<<
"GB"<<std::endl;
151 extern int partitionNodes(
const MPI_Comm& PROTEUS_COMM_WORLD,
Mesh& mesh,
int nNodes_overlap);
159 const int *elementOffsets_subdomain_owned,
160 const int *nodeOffsets_subdomain_owned,
161 const int *elementNumbering_subdomain2global,
162 const int *nodeNumbering_subdomain2global,
163 int& nDOF_all_processes,
165 int& max_dof_neighbors,
166 int *offsets_subdomain_owned,
168 int* subdomain2global,
169 double * lagrangeNodesArray);
172 const int *elementBoundaryOffsets_subdomain_owned,
173 const int *nodeOffsets_subdomain_owned,
174 const int *elementBoundaryNumbering_subdomain2global,
175 const int *nodeNumbering_subdomain2global,
176 int& nDOF_all_processes,
178 int& max_dof_neighbors,
179 int *offsets_subdomain_owned,
181 int *subdomain2global,
182 double * lagrangeNodesArray);
185 const int *edgeOffsets_subdomain_owned,
186 const int *nodeOffsets_subdomain_owned,
187 const int *edgeNumbering_subdomain2global,
188 const int *nodeNumbering_subdomain2global,
189 int& nDOF_all_processes,
191 int& max_dof_neighbors,
192 int *offsets_subdomain_owned,
194 int *subdomain2global,
195 double * lagrangeNodesArray);
198 const int *edgeOffsets_subdomain_owned,
199 const int *nodeOffsets_subdomain_owned,
200 const int *edgeNumbering_subdomain2global,
201 const int *nodeNumbering_subdomain2global,
202 int& nDOF_all_processes,
204 int& max_dof_neighbors,
205 int *offsets_subdomain_owned,
207 int *subdomain2global,
208 double * lagrangeNodesArray);
211 const int *elementOffsets_subdomain_owned,
212 const int *elementNumbering_subdomain2global,
214 int& nDOF_all_processes,
216 int& max_dof_neighbors,
217 int *offsets_subdomain_owned,
219 int* subdomain2global);