From b5c8031c8f202c8140ee69c901c0e719a244aa77 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Jul 2009 10:51:46 -0400 Subject: [PATCH] use sysconf to determine number of processors --- parallel.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/parallel.c b/parallel.c index 0895c13..8045e22 100644 --- a/parallel.c +++ b/parallel.c @@ -30,6 +30,7 @@ #include #include #include +#include void usage() { printf("parallel [OPTIONS] command -- arguments: for each argument, " @@ -121,9 +122,13 @@ int main(int argc, char **argv) { } } - if (maxjobs < 0 && maxload < 0) { - maxjobs = 1; /* XXX: Maybe we should try to autodetect - number of CPUs? */ + if (maxjobs < 0) { +#ifdef _SC_NPROCESSORS_ONLN + maxjobs = sysconf(_SC_NPROCESSORS_ONLN); +#else +#warning Cannot autodetect number of CPUS on this system: _SC_NPROCESSORS_ONLN not defined. + maxjobs = 1; +#endif } while (optind < argc) { -- 2.39.5