[torquedev] sorting node names in pbstop

Jonathan Billings jsbillin at umich.edu
Thu Aug 28 12:31:31 MDT 2008


I noticed that pbstop (from .../torque-2.3.3/contrib) used the default
alphanumeric sort in perl for node names when displaying the list of
nodes for the grid.  Since I've used a couple clusters that had an
unfortunate naming scheme that didn't zero justify the numbers, the
grid wouldn't have the cluster nodes in the correct order.

For example, on an SGI altix, the node r1i3n10 sorts before r1i3n2,
and on a rocks cluster, compute-1-10 sorts before compute-1-2.

I've created a patch that fixes this behavior by only comparing the
numeric parts of the node name (and falling back to the normal
comparison when no numbers are found.

Here's the patch I'm using.  I realize this is a purely cosmetic fix
but I think the 'pbstop' utility is useful.

--- torque-2.3.3/contrib/pbstop.pbstopfix	2008-08-28 14:15:01.000000000 -0400
+++ torque-2.3.3/contrib/pbstop	2008-08-28 14:25:34.000000000 -0400
@@ -730,7 +730,19 @@
     foreach my $server (keys %$allnodes ) {
         my (@cluster, @ts);
-        foreach my $node ( sort keys %{$allnodes->{$server}} ) {
+        foreach my $node ( sort {
+            # turn the string into an array of numbers
+            my @a = $a =~ /(\d+)/g;
+            my @b = $b =~ /(\d+)/g;
+            my $t;
+            # iterate through the arrays, comparing each element
+            while (@a and @b) {
+                return $t if ($t = shift(@a) <=> shift(@b)) != 0;
+            }
+            # Return an alphanumeric sort if all numbers match or
+            # if there are no numbers.
+            return $a cmp $b;
+        } keys %{$allnodes->{$server}} ) {
             $$allnodes{$server}{$node}{np} > $maxnodegrid
                 ? push(@ts, $node)
                 : push(@cluster, $node);

Jonathan Billings <jsbillin at umich.edu>
The College of Language, Science and Arts
LS&A IT - Research Systems and Support

More information about the torquedev mailing list