@@ -121,19 +121,28 @@ def initialize(cluster: nil, bin: nil, conf: nil, bin_overrides: {}, submit_host
121121 # Get a ClusterInfo object containing information about the given cluster
122122 # @return [ClusterInfo] object containing cluster details
123123 def get_cluster_info
124- node_cpu_info = call ( "sinfo" , "-aho %F/%D/% C" ) . strip . split ( '/' )
124+ node_cpu_info = call ( "sinfo" , "-aho %F/%C" ) . strip . split ( '/' ) . map ( & :to_i )
125125 gres_length = call ( "sinfo" , "-o %G" ) . lines . map ( &:strip ) . map ( &:length ) . max + 2
126- gres_lines = call ( "sinfo" , "-ahNO , nodehost,gres:#{ gres_length } ,gresused:#{ gres_length } ,statelong" )
126+ gres_lines = call ( "sinfo" , "-ahNO" , " nodehost,gres:#{ gres_length } ,gresused:#{ gres_length } ,statelong")
127127 . lines . uniq . reject { |line | line . match? ( /maint|drain|down/i ) } . map ( &:split )
128- ClusterInfo . new ( active_nodes : node_cpu_info [ 0 ] . to_i ,
129- total_nodes : ( node_cpu_info [ 3 ] . to_i - node_cpu_info [ 2 ] . to_i ) ,
130- active_processors : node_cpu_info [ 5 ] . to_i ,
131- total_processors : ( node_cpu_info [ 8 ] . to_i - node_cpu_info [ 7 ] . to_i ) ,
132- active_gpus : gres_lines . sum { |line | Slurm . gpus_from_gres ( line [ 2 ] ) } . to_i ,
133- total_gpus : gres_lines . sum { |line | Slurm . gpus_from_gres ( line [ 1 ] ) } . to_i
128+
129+ node_info = sinfo_headers . zip ( node_cpu_info ) . to_h
130+ ClusterInfo . new ( active_nodes : node_info [ 'nodes_allocated' ] ,
131+ total_nodes : node_info [ 'nodes_total' ] ,
132+ active_processors : node_info [ 'cpus_allocated' ] ,
133+ total_processors : node_info [ 'cpus_total' ] ,
134+ active_gpus : gres_lines . sum { |line | Slurm . gpus_from_gres ( line [ 2 ] ) } ,
135+ total_gpus : gres_lines . sum { |line | Slurm . gpus_from_gres ( line [ 1 ] ) }
134136 )
135137 end
136138
139+ def sinfo_headers
140+ [
141+ 'nodes_allocated' , 'nodes_idle' , 'nodes_other' , 'nodes_total' ,
142+ 'cpus_allocated' , 'cpus_idle' , 'cpus_other' , 'cpus_total'
143+ ]
144+ end
145+
137146 # Get a list of hashes detailing each of the jobs on the batch server
138147 # @example Status info for all jobs
139148 # my_batch.get_jobs
0 commit comments