Sorry, I've blasted that installed version so I can't test it again.
However, very simple commands were hanging and/or core dumping with a
broken pipe error:
a = parcellfun( 2, @(x) (x+1), num2cell([1 2 3]) )

What was a bit odd, and took me a minute to figure out, was that if
nproc was set at 1, everything worked fine.  I don't see an obvious
"if nproc == 1 don't bother to fork" (which would actually make a lot
of sense to include), so I don't know what was really causing the
difference.  Sorry, no time to investigate properly.

Basically, don't just test with nproc = 1.

Attached is that VerboseLevel patch one more time.  It really is
trivial, but I guess it is a good opportunity to learn the proper way
of contributing to a distributed development project like this.
The other way of doing it is to have the output as warnings which can
be switched off, but that can get complicated and annoying really
fast.

PS: Any reason the output is to stderr instead of stdout?  Seems like
a bad practice... especially using the '\r' trick on stderr.  I'm
surprised that actually works, since that is more of a bug-in-waiting
than a feature.
I personally like setting the nominal output stream as a variable up
front (just set to stdout 99.9% of the time).

2009/6/15 Jaroslav Hajek <[email protected]>:
> On Mon, Jun 15, 2009 at 12:51 PM, Travis Collier<[email protected]> wrote:
>> 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).
>
> Do you have an example that I can test? Anyway, there have been a few
> fixes since the release, I think, so you can try updating from SVN.
>
>
> --
> RNDr. Jaroslav Hajek
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>
Index: parcellfun.m
===================================================================
--- parcellfun.m	(revision 5958)
+++ 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,19 @@
 ## @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 controlling the level output is supported.  
+## A value of 0 is quiet, 1 is normal, and 2 or more enables
+## debugging output.
 ##
 ## 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 +44,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 +61,7 @@
 
   uniform_output = true;
   error_handler = [];
+  verbose_level = 1; # default to normal output level
 
   args = varargin;
   nargs = length (varargin);
@@ -75,12 +79,17 @@
         nargs -= 2;
         continue;
       endif
+      if (strcmp (args{nargs-1}, "VerboseLevel"))
+        error_handler = 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 +133,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 +263,7 @@
     end_unwind_protect
 
   else
-    ## parent process. 
+    ## parent process.
     njobs = numel (varargin{1});
     res = cell (nargout, njobs);
 
@@ -296,11 +309,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
 
@@ -319,6 +336,10 @@
 
       ## explicitly recognize all terminated processes.
       for i = 1:nproc
+        if( verbose_level > 1 )
+          fprintf(stderr,'parcellfun: waiting for child processes %d to close\n', pids(i));
+          fflush (stderr);
+        end
         [pid, status] = waitpid (pids(i));
       endfor
 
@@ -333,7 +354,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
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to