From: pvtroshin Date: Thu, 22 Jul 2010 13:17:08 +0000 (+0000) Subject: Set number of thread for execution X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4f0c9addc67c90eedbaf6b58945fcb8a4f0cf865;p=jabaws.git Set number of thread for execution git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@2652 e3abac25-378b-4346-85de-24260fe3988d --- diff --git a/runner/compbio/runner/disorder/Jronn.java b/runner/compbio/runner/disorder/Jronn.java index 0bf17e4..e98ac3a 100644 --- a/runner/compbio/runner/disorder/Jronn.java +++ b/runner/compbio/runner/disorder/Jronn.java @@ -23,7 +23,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.security.InvalidParameterException; import java.util.Arrays; import java.util.List; @@ -32,6 +31,7 @@ import org.apache.log4j.Logger; import compbio.data.sequence.AnnotatedSequence; import compbio.data.sequence.SequenceUtil; import compbio.data.sequence.UnknownFileFormatException; +import compbio.engine.client.CommandBuilder; import compbio.engine.client.Executable; import compbio.engine.client.SkeletalExecutable; import compbio.metadata.Limit; @@ -49,142 +49,156 @@ import compbio.runner.Util; */ public class Jronn extends SkeletalExecutable { - - private static Logger log = Logger.getLogger(Jronn.class); - - /** - * Number of cores to use, defaults to 1 for local execution or the value of - * "jronn.cluster.cpunum" property for cluster execution - */ - private int ncoreNumber = 0; - - private String ncorePrm = "-n"; - - - // Cache for Limits information - private static LimitsManager limits; - - public static final String KEY_VALUE_SEPARATOR = Util.SPACE; - public static final String STAT_FILE = "stat.txt"; - - public Jronn() { - addParameters(Arrays.asList("-jar", getLibPath(), "-s=" - + STAT_FILE, "-f=H")); + private static Logger log = Logger.getLogger(Jronn.class); + + /** + * Number of cores to use, defaults to 1 for local execution or the value of + * "jronn.cluster.cpunum" property for cluster execution + */ + private int ncoreNumber = 0; + + private final String ncorePrm = "-n="; + + // Cache for Limits information + private static LimitsManager limits; + + public static final String KEY_VALUE_SEPARATOR = Util.SPACE; + public static final String STAT_FILE = "stat.txt"; + + public Jronn() { + addParameters(Arrays.asList("-jar", getLibPath(), "-s=" + STAT_FILE, + "-f=H")); + } + + @SuppressWarnings("unchecked") + @Override + public List getResults(String workDirectory) + throws ResultNotAvailableException { + List sequences = null; + try { + InputStream inStream = new FileInputStream(new File(workDirectory, + getOutput())); + sequences = SequenceUtil.readJRonn(inStream); + inStream.close(); + } catch (FileNotFoundException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (IOException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (UnknownFileFormatException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); + } catch (NullPointerException e) { + log.error(e.getMessage(), e.getCause()); + throw new ResultNotAvailableException(e); } + return sequences; + } - @SuppressWarnings("unchecked") - @Override - public List getResults(String workDirectory) - throws ResultNotAvailableException { - List sequences = null; - try { - InputStream inStream = new FileInputStream(new File(workDirectory, - getOutput())); - sequences = SequenceUtil.readJRonn(inStream); - inStream.close(); - } catch (FileNotFoundException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } catch (IOException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } catch (UnknownFileFormatException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } catch (NullPointerException e) { - log.error(e.getMessage(), e.getCause()); - throw new ResultNotAvailableException(e); - } - return sequences; - } + private static String getLibPath() { - private static String getLibPath() { - - String settings = ph.getProperty("jronn.jar.file"); - if (compbio.util.Util.isEmpty(settings)) { - throw new NullPointerException( - "Please define jronn.jar.file property in Executable.properties file" - + "and initialize it with the location of jronn jar file"); - } - if (new File(settings).isAbsolute()) { - // Jronn jar can be found so no actions necessary - // no further actions is necessary - return settings; - } - return compbio.engine.client.Util.convertToAbsolute(settings); + String settings = ph.getProperty("jronn.jar.file"); + if (compbio.util.Util.isEmpty(settings)) { + throw new NullPointerException( + "Please define jronn.jar.file property in Executable.properties file" + + "and initialize it with the location of jronn jar file"); } - - @Override - public List getCreatedFiles() { - return Arrays.asList(getOutput(), getError()); + if (new File(settings).isAbsolute()) { + // Jronn jar can be found so no actions necessary + // no further actions is necessary + return settings; } - - @Override - public Jronn setInput(String inFile) { - super.setInput(inFile); - cbuilder.setParam("-i=" + inFile); - return this; + return compbio.engine.client.Util.convertToAbsolute(settings); + } + + @Override + public List getCreatedFiles() { + return Arrays.asList(getOutput(), getError()); + } + + @Override + public Jronn setInput(String inFile) { + super.setInput(inFile); + cbuilder.setParam("-i=" + inFile); + return this; + } + + @Override + public Jronn setOutput(String outFile) { + super.setOutput(outFile); + cbuilder.setParam("-o=" + outFile); + return this; + } + + @Override + public Limit getLimit(String presetName) { + if (limits == null) { + limits = getLimits(); } - - @Override - public Jronn setOutput(String outFile) { - super.setOutput(outFile); - cbuilder.setParam("-o=" + outFile); - return this; + Limit limit = null; + if (limits != null) { + // this returns default limit if preset is undefined! + limit = limits.getLimitByName(presetName); } - - @Override - public Limit getLimit(String presetName) { - if (limits == null) { - limits = getLimits(); - } - Limit limit = null; - if (limits != null) { - // this returns default limit if preset is undefined! - limit = limits.getLimitByName(presetName); - } - // If limit is not defined for a particular preset, then return default - // limit - if (limit == null) { - log.debug("Limit for the preset " + presetName - + " is not found. Using default"); - limit = limits.getDefaultLimit(); - } - return limit; + // If limit is not defined for a particular preset, then return default + // limit + if (limit == null) { + log.debug("Limit for the preset " + presetName + + " is not found. Using default"); + limit = limits.getDefaultLimit(); } - - @Override - public LimitsManager getLimits() { - // synchronise on static field - synchronized (log) { - if (limits == null) { - limits = Util.getLimits(this.getClass()); - } - } - return limits; + return limit; + } + + @Override + public LimitsManager getLimits() { + // synchronise on static field + synchronized (log) { + if (limits == null) { + limits = Util.getLimits(this.getClass()); + } } - - @Override - public Class> getType() { - return this.getClass(); + return limits; + } + + @Override + public Class> getType() { + return this.getClass(); + } + + public static String getStatFile() { + return STAT_FILE; + } + + public void setNCore(int ncoreNumber) { + if (ncoreNumber < 1 || ncoreNumber > 100) { + throw new IndexOutOfBoundsException( + "Number of cores must be within 1 and 100 "); } - - public static String getStatFile() { - return STAT_FILE; + this.ncoreNumber = ncoreNumber; + cbuilder.setParam(ncorePrm + Integer.toString(getNCore())); + } + + int getNCore() { + return ncoreNumber; + } + + @Override + public CommandBuilder getParameters(ExecProvider provider) { + // Limit number of cores to 1 for ANY execution which does not set + // Ncores explicitly using setNCore method + if (ncoreNumber == 0) { + setNCore(1); } - - public void setNCore(int ncoreNumber) { - if (ncoreNumber < 1 || ncoreNumber > 100) { - throw new IndexOutOfBoundsException( - "Number of cores must be within 1 and 100 "); - } - this.ncoreNumber = ncoreNumber; - cbuilder.setParam(ncorePrm, Integer.toString(getNCore())); + // If number of cores is provided, set it for the cluster execution only! + if (provider == Executable.ExecProvider.Cluster) { + int cpunum = SkeletalExecutable.getClusterCpuNum(getType()); + if (cpunum != 0) { + setNCore(cpunum); + } } + return super.getParameters(provider); + } - int getNCore() { - return ncoreNumber; - } - - }