How can I run multiple jobs from a large queue at the same time in Perl?
Asked Answered
E

1

7

I would like to program job limits for the LSF command bsub into my Perl script which launches LSF jobs under the hood. If I have something like 2000 jobs, I would like to run at most 20 jobs at any given time. I have seen scripts that launch 20 jobs and then wait for them all to finish before launching another 20.

Edmondedmonda answered 23/9, 2010 at 17:6 Comment(0)
S
12

Several existing Perl modules, including Parallel::ForkManager and Forks::Super (of which I am the author) offer this functionality.

There is also an LSF::JobManager module that I don't know anything else about.


Parallel::ForkManager skeleton

use Parallel::ForkManager;
$pm = new Parallel::ForkManager(20);
foreach $job (@jobsToRun) {
    $pm->start and next;
    system("bsub -K $job");  # bsub -K job  to wait until job finishes, right?
    $pm->finish;
}


And in Forks::Super

use Forks::Super MAX_PROC => 20;
foreach $job (@jobsToRun) {
    fork { cmd => "bsub -K $job" };
}


Situate answered 23/9, 2010 at 18:9 Comment(1)
After all these years of using LSF, I just now learned about bsub -K. Thanks!Beano

© 2022 - 2024 — McMap. All rights reserved.