From 5664125e5720aa4dc6e59d8684fbacff364e46e0 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Thu, 21 Sep 2017 16:11:56 +0900 Subject: [PATCH] mcexec: verify number of processes for partitioned execution --- executer/user/mcexec.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 9cf96045..cd3c8305 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -2150,6 +2150,11 @@ int main(int argc, char **argv) return 1; } + if (nr_processes > ncpu) { + fprintf(stderr, "error: nr_processes can't exceed nr. of CPUs\n"); + return EINVAL; + } + if (nr_threads > 0) { n_threads = nr_threads; } @@ -2162,13 +2167,16 @@ int main(int argc, char **argv) * When running with partitioned execution, do not allow * more threads then the corresponding number of CPUs. */ - if (nr_processes > 0) { + if (nr_processes > 0 && nr_processes < ncpu) { n_threads = (ncpu / nr_processes) + 4; if (n_threads == 0) { n_threads = 2; } } + else if (nr_processes == ncpu) { + n_threads = 1; + } else { n_threads = ncpu; }