27#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
29#include <sys/resource.h>
31#if defined(__APPLE__) && defined(__MACH__)
34#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
38#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
44#error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
56 PROCESS_MEMORY_COUNTERS info;
57 GetProcessMemoryInfo( GetCurrentProcess( ), &info,
sizeof(info) );
58 return (
size_t)info.PeakWorkingSetSize;
60#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
64 if ( (fd = open(
"/proc/self/psinfo", O_RDONLY )) == -1 )
66 if ( read( fd, &psinfo,
sizeof(psinfo) ) !=
sizeof(psinfo) )
72 return (
size_t)(psinfo.pr_rssize * 1024L);
74#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
77 getrusage( RUSAGE_SELF, &rusage );
78#if defined(__APPLE__) && defined(__MACH__)
79 return (
size_t)rusage.ru_maxrss;
81 return (
size_t)(rusage.ru_maxrss * 1024L);
98 PROCESS_MEMORY_COUNTERS info;
99 GetProcessMemoryInfo( GetCurrentProcess( ), &info,
sizeof(info) );
100 return (
size_t)info.WorkingSetSize;
102#elif defined(__APPLE__) && defined(__MACH__)
104 struct mach_task_basic_info info;
105 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
106 if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO,
107 (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
109 return (
size_t)info.resident_size;
111#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
115 if ( (
fp = fopen(
"/proc/self/statm",
"r" )) == NULL )
117 if ( fscanf(
fp,
"%*s%ld", &rss ) != 1 )
123 return (
size_t)rss * (size_t)sysconf( _SC_PAGESIZE);
131 inline int enforceMemoryLimit(
const MPI_Comm& PROTEUS_COMM_WORLD,
int rank,
double max_rss_gb,
const char* msg)
133 if (max_rss_gb <= 0.0)
135 double current, current_global,gb(1.0e-9);
140 MPI_Allreduce(¤t,¤t_global,1,MPI_DOUBLE,MPI_MAX,PROTEUS_COMM_WORLD);
141 if (current > max_rss_gb)
143 std::cout<<
"Raising PETSC_ERR_MEM, Memory usage on rank "<<rank<<
'\t'<<current<<
"GB"<<
'\t'<<
"limit "<<max_rss_gb<<std::endl;
144 SETERRABORT(PROTEUS_COMM_WORLD,PETSC_ERR_MEM,
"Exceeded Proteus memory limit");
147 std::cout<<msg<<std::endl
148 <<
"Max memory usage per core "<<current_global<<
"GB"<<std::endl;
154 extern int partitionNodes(
const MPI_Comm& PROTEUS_COMM_WORLD,
Mesh& mesh,
int nNodes_overlap);
156 extern int partitionNodesFromTetgenFiles(
const MPI_Comm& PROTEUS_COMM_WORLD,
const char* filebase,
int indexBase,
Mesh& newMesh,
int nNodes_overlap,
double memHardLimit);
163 const int *elementOffsets_subdomain_owned,
164 const int *nodeOffsets_subdomain_owned,
165 const int *elementNumbering_subdomain2global,
166 const int *nodeNumbering_subdomain2global,
167 int& nDOF_all_processes,
169 int& max_dof_neighbors,
170 int *offsets_subdomain_owned,
172 int* subdomain2global,
173 double * lagrangeNodesArray);
176 const int *elementBoundaryOffsets_subdomain_owned,
177 const int *nodeOffsets_subdomain_owned,
178 const int *elementBoundaryNumbering_subdomain2global,
179 const int *nodeNumbering_subdomain2global,
180 int& nDOF_all_processes,
182 int& max_dof_neighbors,
183 int *offsets_subdomain_owned,
185 int *subdomain2global,
186 double * lagrangeNodesArray);
189 const int *edgeOffsets_subdomain_owned,
190 const int *nodeOffsets_subdomain_owned,
191 const int *edgeNumbering_subdomain2global,
192 const int *nodeNumbering_subdomain2global,
193 int& nDOF_all_processes,
195 int& max_dof_neighbors,
196 int *offsets_subdomain_owned,
198 int *subdomain2global,
199 double * lagrangeNodesArray);
202 const int *edgeOffsets_subdomain_owned,
203 const int *nodeOffsets_subdomain_owned,
204 const int *edgeNumbering_subdomain2global,
205 const int *nodeNumbering_subdomain2global,
206 int& nDOF_all_processes,
208 int& max_dof_neighbors,
209 int *offsets_subdomain_owned,
211 int *subdomain2global,
212 double * lagrangeNodesArray);
215 const int *elementOffsets_subdomain_owned,
216 const int *elementNumbering_subdomain2global,
218 int& nDOF_all_processes,
220 int& max_dof_neighbors,
221 int *offsets_subdomain_owned,
223 int* subdomain2global);
int partitionNodesFromTetgenFiles(const MPI_Comm &PROTEUS_COMM_WORLD, const char *filebase, int indexBase, Mesh &newMesh, int nNodes_overlap, double memHardLimit)
int buildQuadraticSubdomain2GlobalMappings_1d(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, const int *elementOffsets_subdomain_owned, const int *nodeOffsets_subdomain_owned, const int *elementNumbering_subdomain2global, const int *nodeNumbering_subdomain2global, int &nDOF_all_processes, int &nDOF_subdomain, int &max_dof_neighbors, int *offsets_subdomain_owned, int *subdomain_l2g, int *subdomain2global, double *lagrangeNodesArray)
int buildQuadraticCubeSubdomain2GlobalMappings_3d(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, const int *edgeOffsets_subdomain_owned, const int *nodeOffsets_subdomain_owned, const int *edgeNumbering_subdomain2global, const int *nodeNumbering_subdomain2global, int &nDOF_all_processes, int &nDOF_subdomain, int &max_dof_neighbors, int *offsets_subdomain_owned, int *subdomain_l2g, int *subdomain2global, double *lagrangeNodesArray)
int partitionNodesFromTriangleFiles(const MPI_Comm &PROTEUS_COMM_WORLD, const char *filebase, int indexBase, Mesh &newMesh, int nNodes_overlap)
int buildDiscontinuousGalerkinSubdomain2GlobalMappings(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, const int *elementOffsets_subdomain_owned, const int *elementNumbering_subdomain2global, int nDOF_element, int &nDOF_all_processes, int &nDOF_subdomain, int &max_dof_neighbors, int *offsets_subdomain_owned, int *subdomain_l2g, int *subdomain2global)
int buildQuadraticSubdomain2GlobalMappings_3d(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, const int *edgeOffsets_subdomain_owned, const int *nodeOffsets_subdomain_owned, const int *edgeNumbering_subdomain2global, const int *nodeNumbering_subdomain2global, int &nDOF_all_processes, int &nDOF_subdomain, int &max_dof_neighbors, int *offsets_subdomain_owned, int *subdomain_l2g, int *subdomain2global, double *lagrangeNodesArray)
int partitionElements(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, int nElements_overlap)
int partitionNodes(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, int nNodes_overlap)
int partitionElementsOriginal(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, int nElements_overlap)
int buildQuadraticSubdomain2GlobalMappings_2d(const MPI_Comm &PROTEUS_COMM_WORLD, Mesh &mesh, const int *elementBoundaryOffsets_subdomain_owned, const int *nodeOffsets_subdomain_owned, const int *elementBoundaryNumbering_subdomain2global, const int *nodeNumbering_subdomain2global, int &nDOF_all_processes, int &nDOF_subdomain, int &max_dof_neighbors, int *offsets_subdomain_owned, int *subdomain_l2g, int *subdomain2global, double *lagrangeNodesArray)
double fp(const double &g, const double &h, const double &hZ)
int enforceMemoryLimit(const MPI_Comm &PROTEUS_COMM_WORLD, int rank, double max_rss_gb, const char *msg)