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 8 files changed, 109 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- 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  <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	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
--- 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  <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	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)
 
--- 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  <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	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
--- /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
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#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);
+
+*/
--- 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
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#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;
-}
-