Class: Origen::Application::LSF

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/application/lsf.rb

Overview

Responsible for handling all submissions to the LSF

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configuration {|@config| ... } ⇒ Object

Accessor for the global LSF configuration, use this to modify the default LSF configuration for a given setup. Typically an alternate configuration would be added to the SoC class or the target file, but it can be set from anywhere. This method returns an instance of Origen::Application::LSF::Configuration and can be used as shown in the example.

Example

# soc/nevis.rb

ORIGEN::Runner::LSF.configuration do |config|
# Use "msg.nevis" for the project string when running in Noida
if %x["domainname"] =~ /nidc/
  Origen.config.lsf.project =  "msg.nevis"
end
# Change the default group
Origen.config.lsf.group = "lam"

Yields:



47
48
49
50
51
# File 'lib/origen/application/lsf.rb', line 47

def self.configuration
  @config ||= Configuration.new
  yield @config if block_given?
  @config
end

Instance Method Details

#configurationObject Also known as: config

Returns the configuration for a given LSF instance, which always maps to the global configuration instance.



55
56
57
# File 'lib/origen/application/lsf.rb', line 55

def configuration
  self.class.configuration
end

#limit_job_submissionsObject

Limits the number of jobs submitted to the LSF at one time, IT will start to warn if a single users current job count gets above 500. This method prevents that stage from being reached.



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/origen/application/lsf.rb', line 132

def limit_job_submissions
  if remote_jobs_count > 450
    while remote_jobs_count > 400
      puts 'Waiting for submitted jobs count to fall below limit...'
      sleep 5
    end
    yield
  else
    yield
  end
end

#queuing_job_idsObject



99
100
101
102
103
104
105
106
107
# File 'lib/origen/application/lsf.rb', line 99

def queuing_job_ids
  ids = []
  `bjobs 2>&1`.split("\n").each do |line|
    if line =~ /^(\d+).*PEND/
      ids << Regexp.last_match[1]
    end
  end
  ids
end

#remote_jobs_countObject



119
120
121
122
123
124
125
126
127
# File 'lib/origen/application/lsf.rb', line 119

def remote_jobs_count
  i = 0
  `bjobs 2>&1`.split("\n").each do |line|
    if line =~ /^(\d+).*(RUN|PEND)/
      i += 1
    end
  end
  i
end

#running_job_idsObject



109
110
111
112
113
114
115
116
117
# File 'lib/origen/application/lsf.rb', line 109

def running_job_ids
  ids = []
  `bjobs 2>&1`.split("\n").each do |line|
    if line =~ /^(\d+).*RUN/
      ids << Regexp.last_match[1]
    end
  end
  ids
end

#submit(command, options = {}) ⇒ Object

Submits the given command to the LSF, returns the LSF job ID



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/origen/application/lsf.rb', line 61

def submit(command, options = {})
  options = {
    dependents: [],
    rerunnable: true,  # Will rerun automatically if the execution host fails
  }.merge(options)
  limit_job_submissions do
    group = options[:group] || config.group
    group = group ? "-G #{group}" : ''
    project = options[:project] || config.project
    project = project ? "-P #{project}" : ''
    resource = options[:resource] || config.resource
    resource = resource ? "-R '#{resource}'" : ''
    queue = options[:queue] || config.queue
    queue = queue ? "-q #{queue}" : ''
    rerunnable = options[:rerunnable] ? '-r' : ''
    if options[:dependents].empty?
      dependents = ''
    else
      dependents = options[:dependents].map { |id| "ended(#{id})" }.join(' && ')
      dependents = "-w '#{dependents}'"
    end
    cmd = "bsub -oo /dev/null #{dependents} #{rerunnable} #{group} #{project} #{resource} #{queue} '#{command}'"
    if config.debug
      puts cmd
      '496212'  # Return a dummy ID to keep the caller happy
    else
      # puts cmd
      output = `#{cmd}`
      Origen.log.info output.strip
      if output.split("\n").last =~ /Job <(\d+)> is submitted/
        Regexp.last_match[1]
      else
        :error
      end
    end
  end
end