aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Carpet/CarpetLib/schedule.ccl6
-rw-r--r--Carpet/CarpetLib/src/mem.cc40
2 files changed, 46 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/schedule.ccl b/Carpet/CarpetLib/schedule.ccl
index 98cd00692..d371bc7a5 100644
--- a/Carpet/CarpetLib/schedule.ccl
+++ b/Carpet/CarpetLib/schedule.ccl
@@ -1,5 +1,11 @@
# Schedule definitions for thorn CarpetLib
+SCHEDULE CarpetLib_setmemlimit AT WRAGH
+{
+ LANG: C
+ OPTIONS: global
+} "Set operating system memory limit"
+
SCHEDULE CarpetLib_printtimestats AT analysis
{
LANG: C
diff --git a/Carpet/CarpetLib/src/mem.cc b/Carpet/CarpetLib/src/mem.cc
index 8a6260c9a..65d4f5e98 100644
--- a/Carpet/CarpetLib/src/mem.cc
+++ b/Carpet/CarpetLib/src/mem.cc
@@ -16,6 +16,9 @@
# include <malloc.h>
#endif
+#include <sys/resource.h>
+#include <sys/time.h>
+
#include "defs.hh"
#include "dist.hh"
@@ -202,6 +205,43 @@ alloc (size_t nbytes)
+extern "C" void CarpetLib_setmemlimit (CCTK_ARGUMENTS);
+
+void CarpetLib_setmemlimit (CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ // Set address space limit
+ struct rlimit aslimit;
+ {
+ int const ierr = getrlimit (RLIMIT_AS, & aslimit);
+ assert (not ierr);
+ }
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Old address space size limit: hard=%lld, soft=%lld",
+ (long long) aslimit.rlim_max, (long long) aslimit.rlim_cur);
+ if (max_allowed_memory_MB > 0) {
+ aslimit.rlim_cur = max_allowed_memory_MB * 1000000LL;
+ }
+ {
+ int const ierr = setrlimit (RLIMIT_AS, & aslimit);
+ assert (not ierr);
+ }
+ {
+ int const ierr = getrlimit (RLIMIT_AS, & aslimit);
+ assert (not ierr);
+ }
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Old address space size limit: hard=%lld, soft=%lld",
+ (long long) aslimit.rlim_max, (long long) aslimit.rlim_cur);
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Unlimited address space size indicated by %lld",
+ (long long) RLIM_INFINITY);
+}
+
+
+
extern "C" void CarpetLib_printmemstats (CCTK_ARGUMENTS);
void CarpetLib_printmemstats (CCTK_ARGUMENTS)