Skip to content

Commit 97c6ecd

Browse files
committed
Added script to generate nodelists on Spock
1 parent f4c7a0b commit 97c6ecd

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

scripts/spock/get_nodes.pl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
12+
$nodestr=$ENV{SLURM_JOB_NODELIST};
13+
#$nodestr="test[1-33]";
14+
#$nodestr="test[01,2-3,4,5]";
15+
16+
@nodes = ();
17+
18+
if(!($nodestr=~m/(.*)\[(.*)\]/)){
19+
print "Stage 1: Could not parse node list '$nodestr'\n";
20+
exit 1;
21+
}
22+
$stub = $1;
23+
$list=$2;
24+
@list_split = split(',', $list);
25+
foreach $l (@list_split){
26+
if($l=~m/(\d+)\-(\d+)/){
27+
$start=$1;
28+
$end=$2;
29+
for($i=$start;$i<=$end;$i++){
30+
if($i <10 && !($i=~m/^0/)){
31+
$i="0${i}";
32+
}
33+
push(@nodes, "${stub}${i}");
34+
}
35+
}elsif($l=~m/(\d+)/){
36+
$i=$1;
37+
if($i <10 && !($i=~m/^0/)){
38+
$i="0${i}";
39+
}
40+
push(@nodes, "${stub}${i}");
41+
}else{
42+
print "Stage 2: Could not parse list element '$l'\n";
43+
exit 1;
44+
}
45+
}
46+
47+
48+
if($ARGV[0] eq "HEAD"){
49+
print "$nodes[0]\n";
50+
}else{
51+
$bodynodes = (scalar @nodes) -1;
52+
$out="";
53+
for($b=0;$b<$bodynodes;$b++){
54+
$node = $nodes[$b+1];
55+
$out = $out . "${node},";
56+
}
57+
$out=~s/\,$//;
58+
print "$out\n";
59+
}
60+

0 commit comments

Comments
 (0)