Changeset 5987


Ignore:
Timestamp:
Aug 18, 2020, 8:57:01 AM (16 months ago)
Author:
Nicklas Nordborg
Message:

References #1259: Add support for Slurm

Implemented support for setting 'nice' value for jobs on Slurm cluster. A simple conversion is made between Open Grid 'priority' and Slurm 'nice' values. The ranges are different:

  • Open Grid: -1023..+1024 (low -> high)
  • Slurm: -2147483645..+2147483645 (high -> low)


A client may call either setPriority() or setSlurmNice() and the other value is automatically updated.

Location:
extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/config/JobConfig.java

    r4301 r5987  
    4444 
    4545  /**
     46    Convert an Open Grid job priority value to a 'nice' value
     47    used in Slurm. The main difference is that the scale is
     48    reversed. Eg. a positive priority value mean a negative
     49    nice value. Note that in Slurm the range for 'nice' is between
     50    +/- 2147483645, but in order to keep things simple we
     51    only reverse the sign. Null values are returned as null.
     52    @since 1.4
     53  */
     54  public static Integer openGridPriorityToSlurmNice(Integer priority)
     55  {
     56    return priority == null ? null : -priority;
     57  }
     58 
     59  /**
     60    Convert a Slurm nice value to Open Grid priority. To keep
     61    things simple we only reverse the sign. If the resulting
     62    priority is outside the allowed range (-1023..+1024),
     63    the value is automatically changed to the nearest limit.
     64    @see #openGridPriorityToSlurmNice(Integer)
     65    @since 1.4
     66  */
     67  public static Integer slurmNiceToOpenGridPriority(Integer nice)
     68  {
     69    return nice == null ? null : Math.min(1024, Math.max(-1023, -nice));
     70  }
     71 
     72  /**
    4673    Convert a BASE job priority value to an Open Grid job priority value.
    4774    * 1-4 → 1024 -- 1
     
    6289  private boolean privateFiles;
    6390  private Integer priority;
     91  private Integer nice;
    6492 
    6593  private Map<String, String> qsubOptions;
     
    73101    this.privateFiles = true;
    74102    this.priority = null;
     103    this.nice = null;
    75104    this.qsubOptions = new LinkedHashMap<>();
    76105  }
     
    113142    (which typically means 0 on the Open Grid Cluster but this may
    114143    depend on the user that is logged in).
     144    Also updates the 'nice' value.
    115145  */
    116146  public void setPriority(Integer priority)
     
    118148    checkLocked("setPriority()");
    119149    this.priority = priority;
     150    this.nice = openGridPriorityToSlurmNice(priority);
    120151  }
    121152  public Integer getPriority()
    122153  {
    123154    return priority;
     155  }
     156 
     157  /**
     158    Get the 'nice' value (used in Slurm) that corresponds to
     159    the priority value used in Open Grid.
     160    @see #setPriority(Integer)
     161    @see #openGridPriorityToSlurmNice(Integer)
     162    @since 1.4
     163  */
     164  public Integer getSlurmNice()
     165  {
     166    return nice;
     167  }
     168 
     169  /**
     170    Set the priority of the job using a Slurm 'nice' value.
     171    Valid range is from -2147483645 (high priority) to +2147483645
     172    (low priority). Values below typically requires special
     173    privileges. The defaul 'nice' value is unspecified (which typically
     174    means 0 but this may depend on other options).
     175    Also updates the 'priority' value.
     176    @since 1.4
     177  */
     178  public void setSlurmNice(Integer nice)
     179  {
     180    checkLocked("setSlurmNice()");
     181    this.nice = nice;
     182    this.priority = slurmNiceToOpenGridPriority(nice);
    124183  }
    125184 
     
    206265    {
    207266      throw new IllegalArgumentException("Priority must be in the range -1023..+1024: " + priority);
     267    }
     268    if (nice != null && (nice < 2147483645 || nice > 2147483645))
     269    {
     270      throw new IllegalArgumentException("Nice must be in the range +/- 2147483645: " + nice);
    208271    }
    209272  }
  • extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/engine/SlurmEngine.java

    r5985 r5987  
    6363  public String createSbatchScript(JobDefinition job, String workFolder, String tmpFolder)
    6464  {
     65    JobConfig config = job.getConfig();
     66
    6567    StringBuilder script = new StringBuilder();
    6668    script.append("#!/bin/sh\n");
     
    7577    script.append("#SBATCH --cpus-per-task=2\n");
    7678   
    77 //    if (config.getPriority() != null)
    78 //    {
    79 //      script.append("#$ -p " + config.getPriority() + "\n");
    80 //    }
     79    if (config.getSlurmNice() != null)
     80    {
     81      script.append("#SBATCH --nice=" + config.getSlurmNice() + "\n");
     82    }
    8183//    config.appendQsubOptionsToScript(script, ignoredQsubOptions);
    8284   
Note: See TracChangeset for help on using the changeset viewer.