Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include "defun-dld.h"
00028 #include "nproc.h"
00029
00030 DEFUN_DLD (nproc, args, nargout,
00031 "-*- texinfo -*-\n\
00032 @deftypefn {Loadable Function} {} nproc ()\n\
00033 @deftypefnx {Loadable Function} {} nproc (@var{query})\n\
00034 Return the current number of available processors.\n\
00035 \n\
00036 If called with the optional argument @var{query}, modify how processors\n\
00037 are counted as follows:\n\
00038 @table @code\n\
00039 @item all\n\
00040 total number of processors.\n\
00041 \n\
00042 @item current\n\
00043 processors available to the current process.\n\
00044 \n\
00045 @item overridable\n\
00046 likewise, but overridable through the @w{@env{OMP_NUM_THREADS}} environment\n\
00047 variable.\n\
00048 @end table\n\
00049 @end deftypefn")
00050 {
00051 octave_value retval;
00052
00053 int nargin = args.length ();
00054
00055 if ((nargin != 0 && nargin != 1) || (nargout != 0 && nargout != 1))
00056 {
00057 print_usage ();
00058 return retval;
00059 }
00060
00061 nproc_query query = NPROC_CURRENT;
00062 if (nargin == 1)
00063 {
00064 std::string arg = args(0).string_value ();
00065
00066 std::transform (arg.begin (), arg.end (), arg.begin (), tolower);
00067
00068 if (arg == "all")
00069 query = NPROC_ALL;
00070 else if (arg == "current")
00071 query = NPROC_CURRENT;
00072 else if (arg == "overridable")
00073 query = NPROC_CURRENT_OVERRIDABLE;
00074 else
00075 {
00076 error ("nproc: invalid value for QUERY");
00077 return retval;
00078 }
00079 }
00080
00081 retval = num_processors (query);
00082
00083 return retval;
00084 }
00085
00086
00087
00088
00089
00090
00091