Mercurial > hg > octave-lojdl
changeset 12512:77b14e634166
Replace nprocs with nproc function. Use gnulib module for portability across platforms.
author | Iain Murray <iain@iainmurray.net> |
---|---|
date | Thu, 17 Mar 2011 13:58:19 -0700 |
parents | 85e87b865f71 |
children | 6a50edfb186b |
files | ChangeLog bootstrap.conf doc/ChangeLog doc/interpreter/system.txi src/ChangeLog src/DLD-FUNCTIONS/module-files src/DLD-FUNCTIONS/nproc.cc src/DLD-FUNCTIONS/nprocs.cc |
diffstat | 7 files changed, 63 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-03-17 Iain Murray <iain@iainmurray.net> + + * bootstrap.conf (gnulib_modules): Include nproc in the list. + 2011-03-08 Rik <octave@nomad.inbox5.com> * mk-opts.pl: Recode using more modern Perl syntax.
--- a/bootstrap.conf +++ b/bootstrap.conf @@ -36,6 +36,7 @@ mkstemp mktime nanosleep + nproc pathmax progname readlink
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2011-03-17 Iain Murray <iain@iainmurray.net> + + * interpreter/system.txi: Remove nprocs and nprocs_conf functions + from documentation and replace with nproc. + 2010-03-16 Rik <octave@nomad.inbox5.com> * interpreter/system.txi: Add nproc and nproc_conf functions to
--- a/doc/interpreter/system.txi +++ b/doc/interpreter/system.txi @@ -470,9 +470,7 @@ @DOCSTRING(uname) -@DOCSTRING(nprocs) - -@DOCSTRING(nprocs_conf) +@DOCSTRING(nproc) @DOCSTRING(ispc)
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-03-17 Iain Murray <iain@iainmurray.net> + + * 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 <iain@iainmurray.net> * DLD-FUNCTIONS/nprocs.cc: New file.
--- a/src/DLD-FUNCTIONS/module-files +++ b/src/DLD-FUNCTIONS/module-files @@ -55,7 +55,7 @@ max.cc md5sum.cc mgorth.cc -nprocs.cc +nproc.cc onCleanup.cc pinv.cc qr.cc
rename from src/DLD-FUNCTIONS/nprocs.cc rename to src/DLD-FUNCTIONS/nproc.cc --- a/src/DLD-FUNCTIONS/nprocs.cc +++ b/src/DLD-FUNCTIONS/nproc.cc @@ -2,7 +2,6 @@ Copyright (C) 2011 Iain Murray - This file is part of Octave. Octave is free software; you can redistribute it and/or modify it @@ -26,51 +25,66 @@ #endif #include "defun-dld.h" -#include "sys/sysinfo.h" +#include "nproc.h" -DEFUN_DLD (nprocs, args, nargout, +DEFUN_DLD (nproc, args, nargout, "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} nprocs ()\n\ -Return the number of available processors.\n\ -@seealso{nprocs_conf}\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 || (nargout != 0 && nargout != 1)) + if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1)) { print_usage (); return retval; } - retval = get_nprocs (); + 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; } -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 (); +%% Must always report at least 1 cpu available +%!assert (nproc () >= 1); - if (nargin != 0 || (nargout != 0 && nargout != 1)) - { - print_usage (); - return retval; - } - - retval = get_nprocs_conf (); - - return retval; -} - +*/