use of es.bsc.compss.scheduler.multiobjective.types.LocalOptimizationState in project compss by bsc-wdc.
the class MOResourceScheduler method localOptimization.
/*--------------------------------------------------
---------------------------------------------------
-------------- Optimization Methods ---------------
---------------------------------------------------
--------------------------------------------------*/
@SuppressWarnings("unchecked")
public PriorityQueue<AllocatableAction> localOptimization(long updateId, Comparator<AllocatableAction> selectionComparator, Comparator<AllocatableAction> donorComparator) {
// System.out.println("Local Optimization for " + this.getName() + " starts");
LocalOptimizationState state = new LocalOptimizationState(updateId, (MOResourceScheduler<WorkerResourceDescription>) this, getReadyComparator(), selectionComparator);
PriorityQueue<AllocatableAction> actions = new PriorityQueue<AllocatableAction>(1, donorComparator);
synchronized (gaps) {
opAction = new OptimizationAction();
}
// No changes in the Gap structure
// Scan actions: Filters ready and selectable actions
LOGGER.debug(LOG_PREFIX + "Scanning current actions");
List<AllocatableAction> lockedActions = scanActions(state);
// Gets all the pending schedulings
List<AllocatableAction> newPendingSchedulings = new LinkedList<>();
List<AllocatableAction> pendingSchedulings;
synchronized (gaps) {
MOSchedulingInformation opDSI = (MOSchedulingInformation) opAction.getSchedulingInfo();
pendingSchedulings = opDSI.replaceSuccessors(newPendingSchedulings);
}
// Classify pending actions: Filters ready and selectable actions
LOGGER.debug(LOG_PREFIX + "Classify Pending Scheduling/Unscheduling actions");
classifyPendingSchedulings(pendingSchedulings, state);
classifyPendingUnschedulings(state);
// ClassifyActions
LOGGER.debug(LOG_PREFIX + "Reschedule pending actions");
List<Gap> newGaps = rescheduleTasks(state, actions);
// Ensuring there are no locked actions after rescheduling
for (AllocatableAction action : lockedActions) {
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
try {
actionDSI.unlock();
} catch (IllegalMonitorStateException e) {
LOGGER.debug(LOG_PREFIX + "Illegal Monitor Exception when releasing locked actions. Ignoring...");
}
}
/*
* System.out.println("\t is running: "); for (AllocatableAction aa : state.getRunningActions()) {
* System.out.println("\t\t" + aa + " with implementation " + ((aa.getAssignedImplementation() == null) ? "null"
* : aa .getAssignedImplementation().getImplementationId()) + " started " + ((aa.getStartTime() == null) ? "-" :
* (System .currentTimeMillis() - aa.getStartTime())));
*
* }
*
* System.out.println(this.getName() + " has no resources for: "); for (AllocatableAction aa :
* this.resourceBlockingAction .getDataSuccessors()) { System.out .println("\t" + aa + " with" +
* " implementation " + ((aa.getAssignedImplementation() == null) ? "null" : aa.getAssignedImplementation()
* .getImplementationId())); } System.out .println(this.getName() +
* " will wait for data producers to be rescheduled for actions:"); for (AllocatableAction aa :
* this.dataBlockingAction.getDataSuccessors()) { System.out .println("\t" + aa + " with" + " implementation " +
* ((aa.getAssignedImplementation() == null) ? "null" : aa.getAssignedImplementation() .getImplementationId()));
* }
*/
// Schedules all the pending scheduligns and unblocks the scheduling of new actions
LOGGER.debug(LOG_PREFIX + "Manage new gaps");
synchronized (gaps) {
gaps.clear();
gaps.addAll(newGaps);
MOSchedulingInformation opDSI = (MOSchedulingInformation) opAction.getSchedulingInfo();
List<AllocatableAction> successors = opDSI.getSuccessors();
for (AllocatableAction action : successors) {
actions.add(action);
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
actionDSI.lock();
actionDSI.removePredecessor(opAction);
this.scheduleUsingGaps(action, gaps);
actionDSI.unlock();
}
opDSI.clearSuccessors();
opAction = null;
}
// System.out.println("Local Optimization for " + this.getName() + " ends");
return actions;
}
Aggregations