# HG changeset patch # User Iain Murray # Date 1300395499 25200 # Node ID 77b14e634166d5d3951fca61b18213c82faf41aa # Parent 85e87b865f71cdc2487679670aa77f5c0f26373f Replace nprocs with nproc function. Use gnulib module for portability across platforms. diff -r 85e87b865f71 -r 77b14e634166 ChangeLog --- a/ChangeLog Mon Mar 14 23:36:20 2011 -0600 +++ b/ChangeLog Thu Mar 17 13:58:19 2011 -0700 @@ -1,3 +1,7 @@ +2011-03-17 Iain Murray + + * bootstrap.conf (gnulib_modules): Include nproc in the list. + 2011-03-08 Rik * mk-opts.pl: Recode using more modern Perl syntax. diff -r 85e87b865f71 -r 77b14e634166 bootstrap.conf --- a/bootstrap.conf Mon Mar 14 23:36:20 2011 -0600 +++ b/bootstrap.conf Thu Mar 17 13:58:19 2011 -0700 @@ -36,6 +36,7 @@ mkstemp mktime nanosleep + nproc pathmax progname readlink diff -r 85e87b865f71 -r 77b14e634166 doc/ChangeLog --- a/doc/ChangeLog Mon Mar 14 23:36:20 2011 -0600 +++ b/doc/ChangeLog Thu Mar 17 13:58:19 2011 -0700 @@ -1,3 +1,8 @@ +2011-03-17 Iain Murray + + * interpreter/system.txi: Remove nprocs and nprocs_conf functions + from documentation and replace with nproc. + 2010-03-16 Rik * interpreter/system.txi: Add nproc and nproc_conf functions to diff -r 85e87b865f71 -r 77b14e634166 doc/interpreter/system.txi --- a/doc/interpreter/system.txi Mon Mar 14 23:36:20 2011 -0600 +++ b/doc/interpreter/system.txi Thu Mar 17 13:58:19 2011 -0700 @@ -470,9 +470,7 @@ @DOCSTRING(uname) -@DOCSTRING(nprocs) - -@DOCSTRING(nprocs_conf) +@DOCSTRING(nproc) @DOCSTRING(ispc) diff -r 85e87b865f71 -r 77b14e634166 src/ChangeLog --- a/src/ChangeLog Mon Mar 14 23:36:20 2011 -0600 +++ b/src/ChangeLog Thu Mar 17 13:58:19 2011 -0700 @@ -1,3 +1,10 @@ +2011-03-17 Iain Murray + + * DLD-FUNCTIONS/nprocs.cc: Delete file. + * DLD-FUNCTIONS/nproc.cc: New file. New function nproc provided by + gnulib. + * DLD-FUNCTIONS/module-files: Add nproc.cc. + 2011-03-16 Iain Murray * DLD-FUNCTIONS/nprocs.cc: New file. diff -r 85e87b865f71 -r 77b14e634166 src/DLD-FUNCTIONS/module-files --- a/src/DLD-FUNCTIONS/module-files Mon Mar 14 23:36:20 2011 -0600 +++ b/src/DLD-FUNCTIONS/module-files Thu Mar 17 13:58:19 2011 -0700 @@ -55,7 +55,7 @@ max.cc md5sum.cc mgorth.cc -nprocs.cc +nproc.cc onCleanup.cc pinv.cc qr.cc diff -r 85e87b865f71 -r 77b14e634166 src/DLD-FUNCTIONS/nproc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/DLD-FUNCTIONS/nproc.cc Thu Mar 17 13:58:19 2011 -0700 @@ -0,0 +1,90 @@ +/* + +Copyright (C) 2011 Iain Murray + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "defun-dld.h" +#include "nproc.h" + +DEFUN_DLD (nproc, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} nproc ()\n\ +@deftypefnx {Loadable Function} {} nproc (@var{query})\n\ +Return the current number of available processors.\n\ +\n\ +If called with the optional argument @var{query}, modify how processors\n\ +are counted as follows:\n\ +@table @code\n\ +@item all\n\ +total number of processors.\n\ +\n\ +@item current\n\ +processors available to the current process.\n\ +\n\ +@item overridable\n\ +likewise, but overridable through the OMP_NUM_THREADS environment variable.\n\ +@end table\n\ +@end deftypefn") +{ + octave_value retval; + + int nargin = args.length (); + + if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1)) + { + print_usage (); + return retval; + } + + nproc_query query = NPROC_CURRENT; + if (nargin == 1) + { + std::string arg = args(0).string_value (); + + std::transform (arg.begin (), arg.end (), arg.begin (), tolower); + + if (arg == "all") + query = NPROC_ALL; + else if (arg == "current") + query = NPROC_CURRENT; + else if (arg == "overridable") + query = NPROC_CURRENT_OVERRIDABLE; + else + { + error ("nproc: invalid value for QUERY"); + return retval; + } + } + + retval = num_processors (query); + + return retval; +} + +/* + +%% Must always report at least 1 cpu available +%!assert (nproc () >= 1); + +*/ diff -r 85e87b865f71 -r 77b14e634166 src/DLD-FUNCTIONS/nprocs.cc --- a/src/DLD-FUNCTIONS/nprocs.cc Mon Mar 14 23:36:20 2011 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - -Copyright (C) 2011 Iain Murray - - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "defun-dld.h" -#include "sys/sysinfo.h" - -DEFUN_DLD (nprocs, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} nprocs ()\n\ -Return the number of available processors.\n\ -@seealso{nprocs_conf}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin != 0 || (nargout != 0 && nargout != 1)) - { - print_usage (); - return retval; - } - - retval = get_nprocs (); - - return retval; -} - -DEFUN_DLD (nprocs_conf, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} nprocs_conf ()\n\ -Return the number of number of processors the operating system has\n\ -configured. This number may be less than the total available as reported by\n\ -@code{nprocs}.\n\ -@seealso{nprocs}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin != 0 || (nargout != 0 && nargout != 1)) - { - print_usage (); - return retval; - } - - retval = get_nprocs_conf (); - - return retval; -} -