Program: 144010
Project: 144010
Buggy source:
@Override public void performIterationUpdates(){
  previousPoint=currentPoint.copy();
  if (subProblemSelectionMethod == SubProblemSelectionMethod.ALL) {
    primalToleranceAdder=new DoubleAdder();
    dualToleranceAdder=new DoubleAdder();
  }
  int[] selectedSubProblemIndexes=subProblemSelectionMethod.selectSubProblems(this);
  Arrays.sort(selectedSubProblemIndexes);
  Set<Integer> affectedConsensusVariables=new HashSet<>();
  List<Callable<Object>> subProblemTasks=new ArrayList<>();
  List<Callable<Object>> residualComputationTasks=new ArrayList<>();
  int temporaryIndex=0;
  for (int subProblemIndex=0; subProblemIndex < objective.getNumberOfTerms(); subProblemIndex++) {
    final boolean solveSubProblem=(temporaryIndex < selectedSubProblemIndexes.length && selectedSubProblemIndexes[temporaryIndex] == subProblemIndex) || currentIteration == 1;
    if (solveSubProblem || penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
      int[] variableIndexes=objective.getTermVariables(subProblemIndex);
      final int currentSubProblemIndex=subProblemIndex;
      Vector variables=variableCopies.get(subProblemIndex);
      Vector multipliers=lagrangeMultipliers.get(subProblemIndex);
      Vector consensusVariables=Vectors.build(variableIndexes.length,currentPoint.type());
      consensusVariables.set(currentPoint.get(variableIndexes));
      if (currentIteration > 1 && subProblemSelectionMethod != SubProblemSelectionMethod.ALL)       for (      int variableIndex : variableIndexes)       affectedConsensusVariables.add(variableIndex);
      if (solveSubProblem) {
        subProblemTasks.add(Executors.callable(() -> processSubProblem(currentSubProblemIndex,variableIndexes,variables,consensusVariables,multipliers,variableCopiesSum)));
        temporaryIndex++;
      }
      if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
        if (subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
          primalToleranceAdder.add(-variables.norm(VectorNorm.L2_SQUARED));
          dualToleranceAdder.add(-multipliers.norm(VectorNorm.L2_SQUARED));
        }
        residualComputationTasks.add(Executors.callable(() -> computeResiduals(currentSubProblemIndex,variables,consensusVariables,multipliers,solveSubProblem)));
      }
    }
  }
  for (int constraintIndex=0; constraintIndex < constraints.size(); constraintIndex++) {
    int[] variableIndexes=constraintsVariablesIndexes.get(constraintIndex);
    final int currentConstraintIndex=constraintIndex;
    int subProblemIndex=objective.getNumberOfTerms() + constraintIndex;
    Vector variables=variableCopies.get(subProblemIndex);
    Vector multipliers=lagrangeMultipliers.get(subProblemIndex);
    Vector consensusVariables=Vectors.build(variableIndexes.length,currentPoint.type());
    consensusVariables.set(currentPoint.get(variableIndexes));
    subProblemTasks.add(Executors.callable(() -> processConstraint(currentConstraintIndex,variableIndexes,variables,consensusVariables,multipliers,variableCopiesSum)));
    if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
      if (subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
        primalToleranceAdder.add(-variables.norm(VectorNorm.L2_SQUARED));
        dualToleranceAdder.add(-multipliers.norm(VectorNorm.L2_SQUARED));
      }
      residualComputationTasks.add(Executors.callable(() -> computeResiduals(subProblemIndex,variables,consensusVariables,multipliers,true)));
    }
  }
  try {
    taskExecutor.invokeAll(subProblemTasks);
  }
 catch (  InterruptedException e) {
    logger.error("String_Node_Str");
  }
  if (currentIteration > 1 && subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
    int[] affectedConsensusVariablesIndexes=ArrayUtils.toPrimitive(affectedConsensusVariables.toArray(new Integer[affectedConsensusVariables.size()]));
    currentPoint.set(affectedConsensusVariablesIndexes,variableCopiesSum.get(affectedConsensusVariablesIndexes).divElementwise(variableCopiesCounts).get(affectedConsensusVariablesIndexes).maxElementwiseInPlace(0).minElementwiseInPlace(1));
  }
 else {
    currentPoint=variableCopiesSum.divElementwise(variableCopiesCounts).maxElementwiseInPlace(0).minElementwiseInPlace(1);
  }
  if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING || checkForPrimalAndDualResidualConvergence) {
    try {
      taskExecutor.invokeAll(residualComputationTasks);
    }
 catch (    InterruptedException e) {
      logger.error("String_Node_Str");
    }
    if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence) {
      primalResidual=Math.sqrt(primalResidualSquaredTerms.sum());
      dualResidual=penaltyParameter * Math.sqrt(currentPoint.sub(previousPoint).map(x -> x * x).multElementwise(variableCopiesCounts).sum());
    }
  }
  penaltyParameterSettingMethod.updatePenaltyParameter(this);
  if (checkForObjectiveConvergence || logObjectiveValue) {
    previousObjectiveValue=currentObjectiveValue;
    currentObjectiveValue=objective.getValue(currentPoint);
  }
  if (checkForGradientConvergence || logGradientNorm) {
    previousGradient=currentGradient;
    try {
      currentGradient=objective.getGradient(currentPoint);
    }
 catch (    NonSmoothFunctionException e) {
      throw new UnsupportedOperationException("String_Node_Str" + "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
@Override public void performIterationUpdates(){
  previousPoint=currentPoint.copy();
  if (subProblemSelectionMethod == SubProblemSelectionMethod.ALL) {
    primalToleranceAdder=new DoubleAdder();
    dualToleranceAdder=new DoubleAdder();
  }
  int[] selectedSubProblemIndexes=subProblemSelectionMethod.selectSubProblems(this);
  Arrays.sort(selectedSubProblemIndexes);
  Set<Integer> affectedConsensusVariables=new HashSet<>();
  List<Callable<Object>> subProblemTasks=new ArrayList<>();
  List<Callable<Object>> residualComputationTasks=new ArrayList<>();
  int temporaryIndex=0;
  for (int subProblemIndex=0; subProblemIndex < objective.getNumberOfTerms(); subProblemIndex++) {
    final boolean solveSubProblem=(temporaryIndex < selectedSubProblemIndexes.length && selectedSubProblemIndexes[temporaryIndex] == subProblemIndex) || currentIteration == 1;
    if (solveSubProblem || penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
      int[] variableIndexes=objective.getTermVariables(subProblemIndex);
      final int currentSubProblemIndex=subProblemIndex;
      Vector variables=variableCopies.get(subProblemIndex);
      Vector multipliers=lagrangeMultipliers.get(subProblemIndex);
      Vector consensusVariables=Vectors.build(variableIndexes.length,currentPoint.type());
      consensusVariables.set(currentPoint.get(variableIndexes));
      if (currentIteration > 1 && subProblemSelectionMethod != SubProblemSelectionMethod.ALL)       for (      int variableIndex : variableIndexes)       affectedConsensusVariables.add(variableIndex);
      if (solveSubProblem) {
        subProblemTasks.add(Executors.callable(() -> processSubProblem(currentSubProblemIndex,variableIndexes,variables,consensusVariables,multipliers,variableCopiesSum)));
        temporaryIndex++;
      }
      if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
        if (subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
          primalToleranceAdder.add(-variables.norm(VectorNorm.L2_SQUARED));
          dualToleranceAdder.add(-multipliers.norm(VectorNorm.L2_SQUARED));
        }
        residualComputationTasks.add(Executors.callable(() -> computeResiduals(currentSubProblemIndex,variables,consensusVariables,multipliers,solveSubProblem)));
      }
    }
  }
  for (int constraintIndex=0; constraintIndex < constraints.size(); constraintIndex++) {
    int[] variableIndexes=constraintsVariablesIndexes.get(constraintIndex);
    final int currentConstraintIndex=constraintIndex;
    int subProblemIndex=objective.getNumberOfTerms() + constraintIndex;
    Vector variables=variableCopies.get(subProblemIndex);
    Vector multipliers=lagrangeMultipliers.get(subProblemIndex);
    Vector consensusVariables=Vectors.build(variableIndexes.length,currentPoint.type());
    consensusVariables.set(currentPoint.get(variableIndexes));
    subProblemTasks.add(Executors.callable(() -> processConstraint(currentConstraintIndex,variableIndexes,variables,consensusVariables,multipliers,variableCopiesSum)));
    if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING) {
      if (subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
        primalToleranceAdder.add(-variables.norm(VectorNorm.L2_SQUARED));
        dualToleranceAdder.add(-multipliers.norm(VectorNorm.L2_SQUARED));
      }
      residualComputationTasks.add(Executors.callable(() -> computeResiduals(subProblemIndex,variables,consensusVariables,multipliers,true)));
    }
  }
  try {
    taskExecutor.invokeAll(subProblemTasks);
  }
 catch (  InterruptedException e) {
    logger.error("String_Node_Str");
  }
  if (currentIteration > 1 && subProblemSelectionMethod != SubProblemSelectionMethod.ALL) {
    int[] affectedConsensusVariablesIndexes=ArrayUtils.toPrimitive(affectedConsensusVariables.toArray(new Integer[affectedConsensusVariables.size()]));
    currentPoint.set(affectedConsensusVariablesIndexes,variableCopiesSum.get(affectedConsensusVariablesIndexes).divElementwise(variableCopiesCounts.get(affectedConsensusVariablesIndexes)).maxElementwiseInPlace(0).minElementwiseInPlace(1));
  }
 else {
    currentPoint=variableCopiesSum.divElementwise(variableCopiesCounts).maxElementwiseInPlace(0).minElementwiseInPlace(1);
  }
  if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || subProblemSelectionMethod == SubProblemSelectionMethod.CONSENSUS_FOCUSED_SAMPLING || checkForPrimalAndDualResidualConvergence) {
    try {
      taskExecutor.invokeAll(residualComputationTasks);
    }
 catch (    InterruptedException e) {
      logger.error("String_Node_Str");
    }
    if (penaltyParameterSettingMethod == PenaltyParameterSettingMethod.ADAPTIVE || checkForPrimalAndDualResidualConvergence) {
      primalResidual=Math.sqrt(primalResidualSquaredTerms.sum());
      dualResidual=penaltyParameter * Math.sqrt(currentPoint.sub(previousPoint).map(x -> x * x).multElementwise(variableCopiesCounts).sum());
    }
  }
  penaltyParameterSettingMethod.updatePenaltyParameter(this);
  if (checkForObjectiveConvergence || logObjectiveValue) {
    previousObjectiveValue=currentObjectiveValue;
    currentObjectiveValue=objective.getValue(currentPoint);
  }
  if (checkForGradientConvergence || logGradientNorm) {
    previousGradient=currentGradient;
    try {
      currentGradient=objective.getGradient(currentPoint);
    }
 catch (    NonSmoothFunctionException e) {
      throw new UnsupportedOperationException("String_Node_Str" + "String_Node_Str");
    }
  }
}