in reply to How to Run Script for Multiple Files in Parallel?

you can use module Proc::Queue, that also limits the number of processes running simultaneously.
use Proc::Queue size=>5, qw(run_back); for (@ARGV) { run_back { run_code($_) }; } 1 while wait != -1;

Replies are listed 'Best First'.
Re^2: How to Run Script for Multiple Files in Parallel?
by monkfan (Curate) on Apr 18, 2005 at 16:17 UTC
    Thanks Salva,

    I tried your module. It's easy to use indeed.
    BTW how can we verify that they are actually running in parallel? I tried "top" but it only shows one instances.

    Regards,
    Edward
      To see what is happening you can use Proc::Queue trace mode, just add to your script...
      use Proc::Queue qw(run_back); Proc::Queue::trace(1);
      Also, wrap the forked code inside an eval block and report errors:
      run_back { eval { ... parallel code here ... }; print STDERR $0."[$$]: $@\n" if $@; };
        I tried this:
        use Proc::Queue size=>2, qw(run_back); Proc::Queue::trace(1); my @ARGV = ("file1.fasta","file2.fasta"); for ( @ARGV ) { run_back { eval{ run_code($_) }; print STDERR $0."[$$]: $@\n" if $@; } } 1 while wait != -1; run_code { my $file = shift; #do the rest }
        It gives this:
        Proc::Queue::run_back(CODE(0x824a9d0)) called at mycode_itr.pl line 37 Proc::Queue::fork called at mycode_itr.pl line 37 Proc::Queue::run_back(CODE(0x824a9d0)) called at mycode_itr.pl line 37 Proc::Queue::fork called at mycode_itr.pl line 37 Proc::Queue::wait called at mycode_itr.pl line 38
        Is it correct or is it an error message? If correct, what does it mean? However, now it does show 2 instances under "top".
        Regards,
        Edward