diff options
author | knarf@cct.lsu.edu <knarf@cct.lsu.edu> | 2010-08-26 14:13:11 -0400 |
---|---|---|
committer | knarf@cct.lsu.edu <knarf@cct.lsu.edu> | 2010-08-26 14:13:11 -0400 |
commit | 9abecff4c3279a2f22e4aa9a98f5342b0756b719 (patch) | |
tree | 3abbe6f58a6e420eabaff6e83e5a6e36b9b864f3 /Carpet | |
parent | 9ee9f2bb21ab0f4927aa630552b0e0015bdedb15 (diff) |
LoopControl: realloc more memory for thread structures when needed instead of aborting
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/LoopControl/src/loopcontrol.c | 18 |
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]) { |