aboutsummaryrefslogtreecommitdiff
path: root/Carpet
diff options
context:
space:
mode:
authorknarf <knarf@cct.lsu.edu>2010-08-26 14:13:11 -0400
committerBarry Wardell <barry.wardell@gmail.com>2011-12-14 18:24:06 +0000
commit24245fdb30afc9550ebe71b4b6b166e4aeba4281 (patch)
tree8011568eb30d3d84a97f458c12adafe0a4a59670 /Carpet
parente8df675353337cc999d3551e8086c62f8c6f97dd (diff)
LoopControl: realloc more memory for thread structures when needed instead of aborting
Diffstat (limited to 'Carpet')
-rw-r--r--Carpet/LoopControl/src/loopcontrol.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Carpet/LoopControl/src/loopcontrol.c b/Carpet/LoopControl/src/loopcontrol.c
index 3c0355ebe..e491fcd01 100644
--- a/Carpet/LoopControl/src/loopcontrol.c
+++ b/Carpet/LoopControl/src/loopcontrol.c
@@ -408,7 +408,8 @@ lc_statset_init (lc_statset_t * restrict const ls,
static int saved_maxthreads = -1;
static lc_topology_t * restrict * saved_topologies = NULL;
static int * restrict saved_ntopologies = NULL;
-
+
+ // Allocate memory the first time this function is called
if (saved_maxthreads < 0) {
saved_maxthreads = omp_get_max_threads();
saved_topologies = malloc (saved_maxthreads * sizeof * saved_topologies );
@@ -420,11 +421,18 @@ lc_statset_init (lc_statset_t * restrict const ls,
saved_ntopologies[n] = -1;
}
}
-
+ // Reallocate memory in case we need more
if (num_threads > saved_maxthreads) {
- CCTK_VWarn (CCTK_WARN_ABORT, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Thread count inconsistency (now called with %d threads, was called with %d before)",
- num_threads, saved_maxthreads);
+ int old_saved_maxthreads = saved_maxthreads;
+ saved_maxthreads = num_threads;
+ saved_topologies = realloc (saved_topologies, saved_maxthreads * sizeof * saved_topologies );
+ saved_ntopologies = realloc (saved_ntopologies, saved_maxthreads * sizeof * saved_ntopologies);
+ assert (saved_topologies );
+ assert (saved_ntopologies);
+ for (int n=old_saved_maxthreads; n<saved_maxthreads; ++n) {
+ saved_topologies [n] = NULL;
+ saved_ntopologies[n] = -1;
+ }
}
if (! saved_topologies[num_threads-1]) {