Module: SLURM

Defined in:
generators/gen_slurm.rb

Overview

output a Slurm topology file, base on the IBLinkinfo output

Class Method Summary (collapse)

Class Method Details

+ (Array) compress(cnodes)

compress, compresses sequences of nodes to make a more compact topology file

takes a sequence a-1, a-2, a-3, ... a-n and converts it to a-[1-n]

Parameters:

  • cnodes (Array)

    List of compute nodes on this switch.

Returns:

  • (Array)

    Compressed list of compute node



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'generators/gen_slurm.rb', line 37

def self.compress(cnodes)
  new_cnodes = []
  last_node = ['', -1] #[lead_in, sequence number]
  this_node = ['', -1]
  count = 0
  first_seq = 0
  cnodes.each do |c|
    chunks = c.split("-")
    this_node[0] = chunks[0..-2].join('-') #Put back together, except for digits at the end
    this_node[1] = chunks[-1].to_i #Convert digits at end to an integer.

    if this_node[0] == last_node[0] && this_node[1] == last_node[1] + 1 #Same basename, with sequence + 1
      first_seq = last_node[1] if count == 0 
      count = count + 1
      last_node[0] = this_node[0]
      last_node[1] = this_node[1]
    else #Either the basename has changed, or the sequence number isn't 1 more
      if count > 0 # We have had at least 1 sequence recorded.
        new_cnodes << "#{last_node[0]}-[#{"%03d"%first_seq}-#{"%03d"%(first_seq+count)}]"
      else #We haven't found a sequence, so we need to output the last node, if there was one.
        if last_node[1] != -1
          new_cnodes << "#{last_node[0]}-#{"%03d"%last_node[1]}"
        end 
      end
      last_node[0] = this_node[0]
      last_node[1] = this_node[1]
      count = 0
      first_seq = 0
    end
  end
  if count > 0 # We have had at least 1 sequence recorded.
    new_cnodes << "#{last_node[0]}-[#{"%03d"%first_seq}-#{"%03d"%(first_seq+count)}]"
  else #We haven't found a sequence, so we need to output the last node, if there was one.
    if last_node[1] != -1
      new_cnodes << "#{last_node[0]}-#{"%03d"%last_node[1]}"
    end 
  end
  return new_cnodes
end

+ (Object) gen(ib, file = 'topology.conf')

Generate a slurm infiniband topology from the IBLinkinfo data.

Parameters:

  • ib (IBLinkInfo)

    The data derived from an iblinkinfo command, and parsed by the IBLinkInfo class parser

  • file (String) (defaults to: 'topology.conf')

    The name of the output file.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'generators/gen_slurm.rb', line 9

def self.gen(ib, file='topology.conf')
  #Output Slurm topology.conf file
  File.open(file, "w") do |fd|
    ib.switch_location.each do |k,loc|
      v = ib.switches[k]
      if v != nil 
        cnodes = []
        switches = []
        (1..loc[4]).each do |i|
          l = ib.location[v[i][9]]
          if l != nil
            if l[1] == :cnode
              cnodes << l[3]
            elsif l[1] == :leaf && (ib.location[k][1] == :spine || ib.location[k][1] == :ex_spine) # || l[1] == :ex_spine || l[1] == :spine
              switches << l[3]
            end
          end
        end
        print(fd, ib.location[k][3], cnodes, switches)
      end
    end
  end
end

Output config line for this switches nodes and switches

Parameters:

  • fd (File)

    File descriptor for the output file

  • switch (String)

    the switches name

  • cnodes (Array)

    the compute nodes on this switch

  • switches (Hash)

    All switches we know of, so we can reference any we are linked to.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'generators/gen_slurm.rb', line 82

def self.print(fd, switch, cnodes, switches)
  fd.print "SwitchName=#{switch}" #The switch
  if switches.length > 0 #Any switches connected to this switch
    switches.sort! #Makes it easier for humans to parse.
    fd.print " Switches=#{switches[0]}"
    (1...switches.length).each do |s|
      fd.print ",#{switches[s]}"
    end
  end
  if cnodes.length > 0 
    cnodes.sort! #Makes it easier for humans to parse. Also helps compressing runs
    new_cnodes = compress(cnodes) #takes a-1, a-2, a-3 and converts it to a-[1-3]
    fd.print " Nodes=#{new_cnodes[0]}" 
    (1...new_cnodes.length).each do |c|
      fd.print ",#{new_cnodes[c]}"
    end
  end
  fd.print "\n"
end