Mercurial > octave
changeset 29766:9b19854c8db1
maxNumCompThreads: new function for compatibility
* scripts/legacy/maxNumCompThreads.m: New file.
* scripts/legacy/module.mk: Update.
* __unimplemented__.m (missing_functions): Remove maxNumCompThreads
from the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 16 Jun 2021 11:25:15 -0400 |
parents | 8ee86e0d3690 |
children | 5750f4ad1fbc |
files | scripts/help/__unimplemented__.m scripts/legacy/maxNumCompThreads.m scripts/legacy/module.mk |
diffstat | 3 files changed, 71 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/help/__unimplemented__.m Wed Jun 16 06:31:15 2021 -0700 +++ b/scripts/help/__unimplemented__.m Wed Jun 16 11:25:15 2021 -0400 @@ -980,7 +980,6 @@ "maxflow", "MaximizeCommandWindow", "maxk", - "maxNumCompThreads", "memmapfile", "memoize", "MemoizedFunction",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/legacy/maxNumCompThreads.m Wed Jun 16 11:25:15 2021 -0400 @@ -0,0 +1,70 @@ +######################################################################## +## +## Copyright (C) 2021 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## 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 +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {@var{n} = } maxNumCompThreads () +## @deftypefnx {} {@var{old} =} maxNumCompThreads (@var{n}) +## @deftypefnx {} {@var{old} =} maxNumCompThreads ("automatic") +## This function is provided for Matlab compatibility only. It uses the +## @code{nproc} function to return the number of available processors. +## It may also be called with an argument to set the number of +## computational threads but that setting has no effect. +## @seealso{nproc} +## @end deftypefn + +function retval = maxNumCompThreads (arg) + + persistent nthreads = nproc (); + + if (nargin > 1) + print_usage (); + endif + + retval = nthreads; + + if (nargin == 1) + if (isnumeric (arg) && isscalar (arg) && arg == fix (arg) + && arg > 0 && isfinite (arg)) + ## FIXME: Should there be an upper limit? + nthreads = arg; + warning ("Octave:maxNumCompThreads:no-effect", + "maxNumCompThreads: setting number of threads has no effect"); + elseif (ischar (arg) && strcmpi (arg, "automatic")) + nthreads = nproc (); + endif + endif + +endfunction + +%!test +%! maxNumCompThreads ("automatic"); +%! assert (maxNumCompThreads (), nproc ()); + +%!test +%! warning ("off", "Octave:maxNumCompThreads:no-effect", "local"); +%! maxNumCompThreads (4); +%! assert (maxNumCompThreads ("automatic"), 4); + +%!error <called with too many inputs> maxNumCompThreads (1, 2);
--- a/scripts/legacy/module.mk Wed Jun 16 06:31:15 2021 -0700 +++ b/scripts/legacy/module.mk Wed Jun 16 11:25:15 2021 -0400 @@ -9,6 +9,7 @@ %reldir%/isdir.m \ %reldir%/isequalwithequalnans.m \ %reldir%/isstr.m \ + %reldir%/maxNumCompThreads.m \ %reldir%/setstr.m \ %reldir%/strmatch.m \ %reldir%/strread.m \