Changeset 5989


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

References #1259: Add support for Slurm

Implemented support for setting options that go into the sbatch file.

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

    r5987 r5989  
    9292 
    9393  private Map<String, String> qsubOptions;
     94  private Map<String, String> sbatchOptions;
    9495 
    9596  /**
     
    103104    this.nice = null;
    104105    this.qsubOptions = new LinkedHashMap<>();
     106    this.sbatchOptions = new LinkedHashMap<>();
    105107  }
    106108
     
    254256  }
    255257 
    256   /**
    257     The priority must be between -1023 and +1024. Other generic qsub
     258 
     259  /**
     260    Set an option for the 'sbatch' command (Slurm). See
     261    https://slurm.schedmd.com/sbatch.html for
     262    a lot more information. The options will go into the
     263    script file using the #SBATCH prefix. It is not recommended
     264    to override options that are automatically set when submitting
     265    the job. This is currently: TODO (-terse, -S, -N, -wd, -o, -e
     266    and -p).
     267   
     268    @param option The name of the option (with or without the hyphen)
     269    @param value The value of the option (null will remove it)
     270    @since 1.4
     271  */
     272  public void setSbatchOption(String option, String value)
     273  {
     274    checkLocked("setSbatchOption(" + option + ")");
     275    if (option == null) return;
     276    if (option.startsWith("-")) option = option.substring(1); // Remove '-'
     277    if (option.startsWith("-")) option = option.substring(1); // Remove '--'
     278    if (value == null)
     279    {
     280      sbatchOptions.remove(option);
     281    }
     282    else
     283    {
     284      sbatchOptions.put(option, value);
     285    }
     286  }
     287
     288  /**
     289    Get the value of a sbatch option.
     290    @param option The name of the option (with or without the hyphen)
     291    @since 1.4
     292  */
     293  public String getSbatchOption(String option)
     294  {
     295    if (option == null) return null;
     296    if (option.startsWith("-")) option = option.substring(1); // Remove '-'
     297    if (option.startsWith("-")) option = option.substring(1); // Remove '--'
     298    return sbatchOptions.get(option);
     299  }
     300 
     301  /**
     302    Get all options that has been specified for sbatch so far.
     303    @return A read-only map with the sbatch options
     304    @since 1.4
     305  */
     306  public Map<String, String> getSbatchOptions()
     307  {
     308    return Collections.unmodifiableMap(sbatchOptions);
     309  }
     310
     311  /**
     312    Add all sbatch options in this configuration to the script.
     313    Each option will create a line:
     314    #SBATCH --&lt;option&gt;=&lt;value&gt;
     315    or:
     316    #SBATCH -&lt;option&gt;=&lt;value&gt;
     317  */
     318  public void appendSbatchOptionsToScript(StringBuilder script, Set<String> ignore)
     319  {
     320    for (Map.Entry<String, String> entry : sbatchOptions.entrySet())
     321    {
     322      String option = entry.getKey();
     323      if (ignore == null || !ignore.contains(option))
     324      {
     325        String prefix = option.length() == 1 ? "-" : "--";
     326        script.append("#SBATCH " + prefix + option + "=" + entry.getValue() + "\n");
     327      }
     328    }
     329  }
     330 
     331  /**
     332    The priority must be between -1023 and +1024 and 'nice' must be
     333    between -2147483645 and +2147483645. Other generic qsub or sbatch
    258334    options are not checked.
    259335  */
  • extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/engine/SlurmEngine.java

    r5987 r5989  
    3636      LoggerFactory.getLogger(SlurmEngine.class);
    3737
     38  private static final Set<String> ignoredSbatchOptions =
     39      new HashSet<>(); // TODO
     40
    3841  public SlurmEngine()
    3942  {}
     
    7578    script.append("#SBATCH --nodes=1\n"); // 1 task on 1 node
    7679    script.append("#SBATCH --ntasks=1\n");
    77     script.append("#SBATCH --cpus-per-task=2\n");
     80//    script.append("#SBATCH --cpus-per-task=2\n");
    7881   
    7982    if (config.getSlurmNice() != null)
     
    8184      script.append("#SBATCH --nice=" + config.getSlurmNice() + "\n");
    8285    }
    83 //    config.appendQsubOptionsToScript(script, ignoredQsubOptions);
     86    config.appendSbatchOptionsToScript(script, ignoredSbatchOptions);
    8487   
    8588    script.append("# --- end sbatch options ---\n");
Note: See TracChangeset for help on using the changeset viewer.