Here is a diff adding a "VerboseLevel" option to parcellfun.
It is against the most current svn snapshot, as of about 15 minutes
ago at least ;)
Anyway, it may seem like a dumb thing, but I really need to be able to
suppress the output to keep track of what is going on at higher levels
(some using the backspace trick for 'counter' output).
It also allows cranking up the verbosity level, which for a function
like this (and many others) can be very helpful debugging.
If anyone has a suggestion of a favored --diff-cmd option (less
verbose or at least treating whitespace a bit more intelligently), it
would be appreciated for future reference.
PS: parcellfun from general 1.1.3 tar.gz posted on octave-forge breaks
in an unhappy core-dump way for me (fresh octave 3.2.0 install from
source on ubuntu jaunty).
--- parcellfun.m (revision 5947)
+++ parcellfun.m (working copy)
@@ -1,17 +1,17 @@
## Copyright (C) 2009 VZLU Prague, a.s., Czech Republic
##
## Author: Jaroslav Hajek
-##
+##
## This program 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.
-##
+##
## This program 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 this program; see the file COPYING. If not, see
## <
http://www.gnu.org/licenses/>.
@@ -22,16 +22,17 @@
## @deftypefnx{Function File} parcellfun (nproc, fun, @dots{},
"ErrorHandler", @var{errfunc})
## Evaluates a function for multiple argument sets using multiple processes.
## @var{nproc} should specify the number of processes. A maximum
recommended value is
-## equal to number of CPUs on your machine or one less.
+## equal to number of CPUs on your machine or one less.
## @var{fun} is a function handle pointing to the requested
evaluating function.
## @var{a1}, @var{a2} etc. should be cell arrays of equal size.
## @var{o1}, @var{o2} etc. will be set to corresponding output arguments.
##
## The UniformOutput and ErrorHandler options are supported with
meaning identical
## to @dfn{cellfun}.
+## A VerboseLevel option is supported controlling level of output. 0
implies quiet and 1 is default.
##
## NOTE: this function is implemented using "fork" and a number of
pipes for IPC.
-## Suitable for systems with an efficient "fork" implementation (such
as GNU/Linux),
+## Suitable for systems with an efficient "fork" implementation (such
as GNU/Linux),
## on other systems (Windows) it should be used with caution.
## Also, if you use a multithreaded BLAS, it may be wise to turn off
multi-threading
## when using this function.
@@ -41,11 +42,11 @@
## especially if unhandled errors occur. Under GNU and compatible
systems, the following
## shell command may be used to display orphaned Octave processes:
## ps --ppid 1 | grep octave
-##
+##
## @end deftypefn
function varargout = parcellfun (nproc, fun, varargin)
-
+
if (nargin < 3 || ! isscalar (nproc) || nproc <= 0)
print_usage ();
endif
@@ -58,6 +59,7 @@
uniform_output = true;
error_handler = [];
+ verbose_level = 1; # controls verbosity of terminal output
args = varargin;
nargs = length (varargin);
@@ -75,12 +77,17 @@
nargs -= 2;
continue;
endif
+ if (strcmp (args{nargs-1}, "VerboseLevel"))
+ verbose_level = args{nargs};
+ nargs -= 2;
+ continue;
+ endif
break;
until (nargs < 2);
endif
args = args(1:nargs);
-
+
if (length (args) == 0)
print_usage ();
elseif (length (args) > 1 && ! size_equal (args{:}))
@@ -124,6 +131,10 @@
## parent process. fork succeded.
nsuc ++;
pids(i) = pid;
+ if( verbose_level > 1 )
+ fprintf(stderr,'parcellfun: child processes %d created\n', pids(i));
+ fflush (stderr);
+ endif
elseif (pid == 0)
## child process.
iproc = i;
@@ -250,7 +261,7 @@
end_unwind_protect
else
- ## parent process.
+ ## parent process.
njobs = numel (varargin{1});
res = cell (nargout, njobs);
@@ -296,11 +307,15 @@
## clear pending state
pending(isubp) = 0;
endif
- fprintf (stderr, "\rparcellfun: %d/%d jobs done", pjobs - sum
(pending != 0), njobs);
+ if( verbose_level > 0 )
+ fprintf (stderr, "\rparcellfun: %d/%d jobs done", pjobs -
sum (pending != 0), njobs);
+ fflush (stderr);
+ endif
+ endwhile
+ if( verbose_level > 0 )
+ fputs (stderr, "\n");
fflush (stderr);
- endwhile
- fputs (stderr, "\n");
- fflush (stderr);
+ endif
unwind_protect_cleanup
@@ -314,6 +329,10 @@
## close all pipe ends
fclose (statr);
for i = 1:nproc
+ if( verbose_level > 1 )
+ fprintf(stderr,'parcellfun: waiting for child processes %d
to close\n', pids(i));
+ fflush (stderr);
+ end
fclose (resr(i));
endfor
@@ -333,7 +352,7 @@
varargout{i} = cell2mat (varargout{i});
endif
endfor
-
+
endif
endfunction
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects_______________________________________________
Octave-dev mailing list
Octave-dev@...
https://lists.sourceforge.net/lists/listinfo/octave-dev