|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +$ARGC=scalar @ARGV; |
| 4 | +if($ARGC != 1 || ($ARGV[0] ne "HEAD" && $ARGV[0] ne "BODY") ){ |
| 5 | + print "Usage <script.pl> <HEAD or BODY>\n"; |
| 6 | + print "HEAD requests the script return the head node\n"; |
| 7 | + print "BODY requests the script return the remaining nodes\n"; |
| 8 | + exit 1; |
| 9 | +} |
| 10 | + |
| 11 | +$nodestr=$ENV{SLURM_JOB_NODELIST}; |
| 12 | +#$nodestr="test[08897-08898]"; |
| 13 | + |
| 14 | +#$nodestr="test[1-33]"; |
| 15 | +#$nodestr="test[01,2-3,4,5]"; |
| 16 | +#print "Node string is $nodestr"; |
| 17 | + |
| 18 | +@nodes = (); |
| 19 | + |
| 20 | +if(!($nodestr=~m/(.*)\[(.*)\]/)){ |
| 21 | + print "Stage 1: Could not parse node list '$nodestr'\n"; |
| 22 | + exit 1; |
| 23 | +} |
| 24 | +$stub = $1; |
| 25 | +$list=$2; |
| 26 | +@list_split = split(',', $list); |
| 27 | +foreach $l (@list_split){ |
| 28 | + if($l=~m/(\d+)\-(\d+)/){ |
| 29 | + $start=$1; |
| 30 | + $end=$2; |
| 31 | + for($i=$start;$i<=$end;$i++){ |
| 32 | + $i=sprintf("%05d", $i); |
| 33 | + push(@nodes, "${stub}${i}"); |
| 34 | + } |
| 35 | + }elsif($l=~m/(\d+)/){ |
| 36 | + $i=$1; |
| 37 | + $i=sprintf("%05d", $i); |
| 38 | + push(@nodes, "${stub}${i}"); |
| 39 | + }else{ |
| 40 | + print "Stage 2: Could not parse list element '$l'\n"; |
| 41 | + exit 1; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +if($ARGV[0] eq "HEAD"){ |
| 47 | + print "$nodes[0]\n"; |
| 48 | +}else{ |
| 49 | + $bodynodes = (scalar @nodes) -1; |
| 50 | + $out=""; |
| 51 | + for($b=0;$b<$bodynodes;$b++){ |
| 52 | + $node = $nodes[$b+1]; |
| 53 | + $out = $out . "${node},"; |
| 54 | + } |
| 55 | + $out=~s/\,$//; |
| 56 | + print "$out\n"; |
| 57 | +} |
| 58 | + |
0 commit comments