diff options
author | Erik Schnetter <schnetter@gmail.com> | 2012-03-16 11:15:28 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2012-03-16 11:15:28 -0400 |
commit | c190963648d0234680b92bcdd8781c7f0ac97217 (patch) | |
tree | b6b7825939d1d4daef410fb3dd407a66f755fe68 /Carpet | |
parent | 5fcb19b8d2ff4cfa54d03264a8420c5eb15a020e (diff) | |
parent | 590bd2b9db27b14a9caf56f0a5c413291db5ec85 (diff) |
Merge
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/Carpet/param.ccl | 4 | ||||
-rw-r--r-- | Carpet/Carpet/src/SetupGH.cc | 74 |
2 files changed, 60 insertions, 18 deletions
diff --git a/Carpet/Carpet/param.ccl b/Carpet/Carpet/param.ccl index d37c4e423..30205e7b4 100644 --- a/Carpet/Carpet/param.ccl +++ b/Carpet/Carpet/param.ccl @@ -497,6 +497,10 @@ CCTK_INT num_threads "Number of threads per process" STEERABLE=recover 1:* :: "use this many threads" } -1 +BOOLEAN set_cpu_affinity "Set the process CPU affinity, overwriting the respective system setting" STEERABLE=recover +{ +} "no" + STRING grid_structure_filename "File name to output grid structure to (empty = no output)" STEERABLE=recover diff --git a/Carpet/Carpet/src/SetupGH.cc b/Carpet/Carpet/src/SetupGH.cc index 48718ea59..1afeffe11 100644 --- a/Carpet/Carpet/src/SetupGH.cc +++ b/Carpet/Carpet/src/SetupGH.cc @@ -1,5 +1,6 @@ #define _GNU_SOURCE 1 // needed for sched_getaffinity, best at the top to avoid inconsistent includes +#include <algorithm> #include <cassert> #include <climits> #include <cmath> @@ -323,27 +324,64 @@ namespace Carpet { } } + if (set_cpu_affinity) { #ifdef HAVE_SCHED_GETAFFINITY - cpu_set_t mask; - int const ierr = sched_getaffinity (0, sizeof mask, &mask); - assert (not ierr); - ostringstream buf; - bool isfirst = true; - int first_active = -1; - for (int n=0; n<CPU_SETSIZE; ++n) { - if (first_active == -1 and CPU_ISSET(n, &mask)) { - if (not isfirst) buf << ", "; - isfirst = false; - buf << n; - first_active = n; - } else if (first_active >= 0 and not CPU_ISSET(n, &mask)) { - if (n-1 > first_active) buf << "-" << n-1; - first_active = -1; + cpu_set_t mask; + int const ierr = sched_getaffinity (0, sizeof mask, &mask); + assert (not ierr); + int n0 = -1; + for (int n=0; n<CPU_SETSIZE; ++n) { + if (CPU_ISSET(n, &mask)) { + n0 = n; + break; + } + } + if (n0 >= 0) { + CCTK_VInfo (CCTK_THORNSTRING, + "Selecting cores %d-%d for this process", + n0, n0+mynthreads-1); + CPU_ZERO(&mask); + for (int n=n0; n<min(n0 + mynthreads, CPU_SETSIZE); ++n) { + CPU_SET(n, &mask); + } + int const ierr1 = sched_setaffinity(0, sizeof(mask), &mask); + assert (not ierr1); + } +#else + CCTK_WARN (CCTK_WARN_ALERT, + "Cannot select core set for this process; sched_getaffinity is not available on this system"); +#endif + } + +#ifdef HAVE_SCHED_GETAFFINITY + { + cpu_set_t mask; + int const ierr = sched_getaffinity (0, sizeof mask, &mask); + assert (not ierr); + + ostringstream buf; + int const num_cores = CPU_COUNT(&mask); + bool isfirst = true; + int first_active = -1; + for (int n=0; n<CPU_SETSIZE; ++n) { + if (first_active == -1 and CPU_ISSET(n, &mask)) { + if (not isfirst) buf << ", "; + isfirst = false; + buf << n; + first_active = n; + } else if (first_active >= 0 and not CPU_ISSET(n, &mask)) { + if (n-1 > first_active) buf << "-" << n-1; + first_active = -1; + } + } + CCTK_VInfo (CCTK_THORNSTRING, + "This process runs on %d core%s: %s", + num_cores, num_cores==1 ? "" : "s", buf.str().c_str()); + if (num_cores != mynthreads) { + CCTK_WARN (CCTK_WARN_ALERT, + "The number of threads for this process is different from its number of cores. This may indicate a performance problem."); } } - CCTK_VInfo (CCTK_THORNSTRING, - "This process runs on cores %s", - buf.str().c_str()); #endif } |