Class: SlurmManager

Inherits:
QueueManager show all
Defined in:
lib/autoflow/queue_managers/slurm_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from QueueManager

#asign_queue_id, #close_file, #create_file, #create_folder, descendants, #exec, #get_all_deps, #get_dependencies, #get_queue_system_dependencies, #get_relations_and_folders, #init_log, #initialize, #launch2queue_system, #launch_all_jobs, #launch_job_in_folder, #make_environment_file, #read_file, #rm_done_dependencies, select_manager, select_queue_manager, #sort_jobs_by_dependencies, #system_call, system_call, #write_file, #write_job

Constructor Details

This class inherits a constructor from QueueManager

Class Method Details

.available?(options) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 50

def self.available?(options)
  available = true
  shell_output = system_call("type 'sbatch'", nil, options[:remote], options[:ssh])
  available = false if shell_output.empty?
  return available
end

.priorityObject



57
58
59
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 57

def self.priority
  return 100 
end

Instance Method Details

#get_queue_system_id(shell_output) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 42

def get_queue_system_id(shell_output)
  queue_id = nil
  shell_output.chomp!
  fields = shell_output.split(' ')
  queue_id = fields[3]
  return queue_id
end

#parse_additional_options(string, attribs) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 3

def parse_additional_options(string, attribs)
  expresions = %w[%C %T %M %N ]
  values = [attribs[:cpu], attribs[:time], attribs[:mem], attribs[:node]]
  new_string = string.dup
  expresions.each_with_index do |exp, i|
    new_string.gsub!(exp, "#{values[i]}")
  end
  return new_string
end

#submit_job(job, ar_dependencies) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 32

def submit_job(job, ar_dependencies)
  final_dep = get_all_deps(ar_dependencies)
  dependencies = nil
  dependencies='--dependency=afterok:'+final_dep.join(':') if !final_dep.empty?  
  cmd = "sbatch #{dependencies} #{job.name}.sh"
  STDOUT.puts cmd if @show_submit
  queue_id = get_queue_system_id(system_call(cmd, job.attrib[:exec_folder]))
  return queue_id
end

#write_header(id, job, sh_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/autoflow/queue_managers/slurm_manager.rb', line 13

def write_header(id, job, sh_name)
  if !job.attrib[:ntask]
    write_file(sh_name, "#SBATCH --cpus=#{job.attrib[:cpu]}")
  else
    write_file(sh_name, "#SBATCH --ntasks=#{job.attrib[:cpu]}")
    write_file(sh_name, "#SBATCH --nodes=#{job.attrib[:multinode]}") if job.attrib[:multinode] > 0
  end
  write_file(sh_name,  "#SBATCH --mem=#{job.attrib[:mem]}")
  write_file(sh_name, "#SBATCH --time=#{job.attrib[:time]}")
  write_file(sh_name,  "#SBATCH --constraint=#{job.attrib[:node]}") if !job.attrib[:node].nil?
  write_file(sh_name, '#SBATCH --error=job.%J.err')
  write_file(sh_name, '#SBATCH --output=job.%J.out')
  write_file(sh_name, "#SBATCH --#{job.attrib[:additional_job_options][0]}=#{parse_additional_options(job.attrib[:additional_job_options][1], job.attrib)}") if !job.attrib[:additional_job_options].nil?
  if job.attrib[:ntask]
    write_file(sh_name, 'srun hostname -s > workers') if job.attrib[:cpu_asign] == 'list'
  end
end