From 2f5a95327b96c1d647817a135a10e815b15cd23a Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 26 Sep 2015 15:13:17 +0100 Subject: [PATCH] add numcpus and numjobs --- example/cubefile | 3 +++ main.cc | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/example/cubefile b/example/cubefile index c310da6..1344d1b 100644 --- a/example/cubefile +++ b/example/cubefile @@ -7,6 +7,9 @@ if (=s $CC "") [ echo "using compiler:" $CC ] +echo "number of CPUs:" $numcpus +echo "number of jobs:" $numjobs + rule all test OBJ = (strreplace (glob "*.c") ".c" ".o") diff --git a/main.cc b/main.cc index ca4e2de..20390ad 100644 --- a/main.cc +++ b/main.cc @@ -1,3 +1,4 @@ +#include #include #include @@ -5,6 +6,7 @@ #include #include #include +#include #include @@ -289,6 +291,10 @@ int main(int argc, char **argv) { cscript::init_lib_string(os.cs); cscript::init_lib_list(os.cs); + int ncpus = ostd::cpu_count_get(); + os.cs.add_ident(cscript::ID_VAR, "numcpus", INT_MAX, 1, &ncpus); + os.cs.add_ident(cscript::ID_VAR, "numjobs", INT_MAX, 1, &os.jobs); + ConstCharRange fname = "cubefile"; ConstCharRange fcont; @@ -307,9 +313,12 @@ int main(int argc, char **argv) { break; case 'h': return ob_print_help(argv[0], ostd::out, 0); - case 'j': - os.jobs = ostd::max(1, atoi(optarg)); + case 'j': { + int val = atoi(optarg); + if (!val) val = ncpus + 1; + os.jobs = ostd::max(1, val); break; + } case 'E': ignore_env = true; break;