Mercurial > hg > octave-nkf
comparison src/DLD-FUNCTIONS/nproc.cc @ 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 | src/DLD-FUNCTIONS/nprocs.cc@a1b2da4967ac |
children | a1e386b9ef4b |
comparison
equal
deleted
inserted
replaced
12511:85e87b865f71 | 12512:77b14e634166 |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2011 Iain Murray | |
4 | |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "defun-dld.h" | |
28 #include "nproc.h" | |
29 | |
30 DEFUN_DLD (nproc, args, nargout, | |
31 "-*- texinfo -*-\n\ | |
32 @deftypefn {Loadable Function} {} nproc ()\n\ | |
33 @deftypefnx {Loadable Function} {} nproc (@var{query})\n\ | |
34 Return the current number of available processors.\n\ | |
35 \n\ | |
36 If called with the optional argument @var{query}, modify how processors\n\ | |
37 are counted as follows:\n\ | |
38 @table @code\n\ | |
39 @item all\n\ | |
40 total number of processors.\n\ | |
41 \n\ | |
42 @item current\n\ | |
43 processors available to the current process.\n\ | |
44 \n\ | |
45 @item overridable\n\ | |
46 likewise, but overridable through the OMP_NUM_THREADS environment variable.\n\ | |
47 @end table\n\ | |
48 @end deftypefn") | |
49 { | |
50 octave_value retval; | |
51 | |
52 int nargin = args.length (); | |
53 | |
54 if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1)) | |
55 { | |
56 print_usage (); | |
57 return retval; | |
58 } | |
59 | |
60 nproc_query query = NPROC_CURRENT; | |
61 if (nargin == 1) | |
62 { | |
63 std::string arg = args(0).string_value (); | |
64 | |
65 std::transform (arg.begin (), arg.end (), arg.begin (), tolower); | |
66 | |
67 if (arg == "all") | |
68 query = NPROC_ALL; | |
69 else if (arg == "current") | |
70 query = NPROC_CURRENT; | |
71 else if (arg == "overridable") | |
72 query = NPROC_CURRENT_OVERRIDABLE; | |
73 else | |
74 { | |
75 error ("nproc: invalid value for QUERY"); | |
76 return retval; | |
77 } | |
78 } | |
79 | |
80 retval = num_processors (query); | |
81 | |
82 return retval; | |
83 } | |
84 | |
85 /* | |
86 | |
87 %% Must always report at least 1 cpu available | |
88 %!assert (nproc () >= 1); | |
89 | |
90 */ |