class Origen::Application::LSF

Responsible for handling all submissions to the LSF

Public Class Methods

configuration() { |config| ... } click to toggle source

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/
    config.lsf.project =  "msg.nevis"
  end
end

# Change the default group
Origen.config.lsf.group = "lam"
# File lib/origen/application/lsf.rb, line 76
def self.configuration
  @config ||= Configuration.new
  yield @config if block_given?
  @config
end

Public Instance Methods

config()
Alias for: configuration
configuration() click to toggle source

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

# File lib/origen/application/lsf.rb, line 84
def configuration
  self.class.configuration
end
Also aliased as: config
limit_job_submissions() { || ... } click to toggle source

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.

# File lib/origen/application/lsf.rb, line 171
def limit_job_submissions
  @local_job_count ||= 0
  if @local_job_count == 100
    while remote_jobs_count > config.max_jobs
      puts 'Waiting for submitted jobs count to fall below limit...'
      sleep 5
    end
    @local_job_count = 0
    yield
  else
    @local_job_count += 1
    yield
  end
end
queuing_job_ids() click to toggle source
# File lib/origen/application/lsf.rb, line 129
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_count() click to toggle source
# File lib/origen/application/lsf.rb, line 149
def remote_jobs_count
  i = 0
  `bjobs 2>&1`.split("\n").each do |line|
    if line =~ /^(\d+).*(RUN|PEND)/
      if config.queue_count_only && config.queue
        # only count jobs for current queue, helpful for when
        # you have a service account user that runs lsf for a
        # lot of jobs in addition to origen jobs
        if line =~ /#{config.queue}/
          i += 1
        end
      else
        i += 1
      end
    end
  end
  i
end
running_job_ids() click to toggle source
# File lib/origen/application/lsf.rb, line 139
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 = {}) click to toggle source

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

# File lib/origen/application/lsf.rb, line 90
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}" : ''
    cores = options[:cores] || config.cores
    cores = cores ? "-n #{cores}" : ''
    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} #{cores} '#{command}'"
    if config.debug
      puts cmd
      '496212' # Return a dummy ID to keep the caller happy
    else
      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