in reply to How can I convert my script for submitting SLURM jobs from Bash to Perl?

A quick google brings up this, is this the "sbatch" / SLURM you're talking about? https://computing.llnl.gov/linux/slurm/sbatch.html

If that's the case, and if my understanding from a quick skim is correct, then this isn't a plain bash script! There seems to be some preprocessing being done that reads the #SBATCH lines - as has already been noted, lines beginning with # are just comments to bash.

You'll either need to find a monk who's worked with this system before, or give everyone else a quick overview of how this system works.

I will still venture two guesses as to how this might still work with Perl. First, perhaps the system understands more than bash scripts. # lines are just comments to Perl too, so maybe this could work?

#!/usr/bin/perl #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 use warnings; use strict; system("module add gromacs")==0 or warn "Warning: module add failed, code $?"; system("srun resp.com")==0 or warn "Warning: srun failed, code $?";

(This requires "module" and "srun" to be actual commands in your PATH, and not some directives that only sbatch understands.)

Or, even though this isn't exactly a "conversion to Perl", it still gives some control to Perl - this uses IPC::Run3 to feed the "script" to sbatch via STDIN.

#!/usr/bin/perl use warnings; use strict; use IPC::Run3 'run3'; my $script = <<'END_SCRIPT'; #!/bin/bash #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 module add gromacs srun resp.com END_SCRIPT run3 ["sbatch"], \$script;

Even though that's really just a simple wrapper, it still gives you some of the power of Perl, such as being able to generate the script dynamically or do advanced things with STDOUT and STDERR.

I want to convert it to Perl it because I will add on it the other parts after it works.

Sorry, I don't understand, could you explain a bit more?

Replies are listed 'Best First'.
Re^2: How can I convert my script for submitting SLURM jobs from Bash to Perl?
by erhan (Novice) on Feb 18, 2015 at 22:22 UTC
    Thanks for your reply. Yes. I am talking about SLURM. I tried your first code (completely perl ones). It gives the following error: Can't exec "gaussian": No such file or directory at.... resp.com is only one job for run on cluster. I have about 1000 jobs. So I have to convert it to perl script.

      I think the first script needs to be:

      #!/usr/bin/perl #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 use warnings; use strict; system("module add gromacs && srun resp.com")==0 or warn "Warning: command failed, code $?";

      module add gromacs is likely modifying the "local" runtime environment as MidLifeXis explained in his post, above.

      Sorry, but I don't see how the script shown can produce that error message; perhaps you modified it, in that case you need to post the full code, or, the error message is actually coming from one of the two executed commands, in which case that needs to be debugged...

      I'm not sure how many monks here might already have experience with SLURM, gromacs, et al, but if it's only a few, the rest of us will need all the information you can provide so that we can help you best. To that effect, it would be good if you could read I know what I mean. Why don't you? and How do I post a question effectively?

        I run the following code:
        #!/usr/bin/perl #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 use warnings; use strict; system("module add gaussian"); system("srun resp.com")
        It gave this error: Can't exec "gaussian": No such file or directory at...