/** Normalizes the (from, to, incr) predicate to a predicate w/ positive increment. */
  private void normalizePredicate() {
    // check for positive increment
    if (_incrVal.getLongValue() >= 0) return;

    long lfrom = _fromVal.getLongValue();
    long lto = _toVal.getLongValue();
    long lincr = _incrVal.getLongValue();

    _fromVal = new IntObject(lfrom - ((lfrom - lto) / lincr * lincr));
    _toVal = new IntObject(lfrom);
    _incrVal = new IntObject(-1 * lincr);
  }
Exemplo n.º 2
0
  protected TaskPartitioner(
      long taskSize, String iterVarName, IntObject fromVal, IntObject toVal, IntObject incrVal) {
    _taskSize = taskSize;

    _iterVarName = iterVarName;
    _fromVal = fromVal;
    _toVal = toVal;
    _incrVal = incrVal;

    _numIter =
        (long)
            Math.ceil(
                ((double) (_toVal.getLongValue() - _fromVal.getLongValue() + 1))
                    / _incrVal.getLongValue());
  }
  protected TaskPartitioner(
      long taskSize, String iterVarName, IntObject fromVal, IntObject toVal, IntObject incrVal) {
    _taskSize = taskSize;
    _iterVarName = iterVarName;
    _fromVal = fromVal;
    _toVal = toVal;
    _incrVal = incrVal;

    // normalize predicate if necessary
    normalizePredicate();

    // compute number of iterations
    _numIter =
        (long)
            Math.ceil(
                ((double) (_toVal.getLongValue() - _fromVal.getLongValue() + 1))
                    / _incrVal.getLongValue());
  }