use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.
the class MOResourceScheduler method rescheduleTasks.
@SuppressWarnings("unchecked")
public List<Gap> rescheduleTasks(LocalOptimizationState state, PriorityQueue<AllocatableAction> rescheduledActions) {
this.runActionsCost = 0;
this.runActionsEnergy = 0;
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
for (int implId = 0; implId < CoreManager.getNumberCoreImplementations(coreId); implId++) {
MOProfile profile = (MOProfile) this.getProfile(coreId, implId);
runActionsEnergy += profile.getPower() * profile.getExecutionCount() * profile.getAverageExecutionTime();
runActionsCost += profile.getPrice() * profile.getExecutionCount() * profile.getAverageExecutionTime();
}
}
/*
*
* ReadyActions contains those actions that have no dependencies with other actions scheduled on the node, but
* they have data dependencies with tasks on other resources. They are sorted by the expected time when these
* dependencies will be solved.
*
* SelectableActions contains those actions that have no data dependencies with other actions but they wait for
* resources to be released.
*
* Running actions contains a list of Actions that are executing or potentially executing at the moment.
*
* All Actions that need to be rescheduled have the onOptimization and scheduled flags on.
*
* Those actions that are running or could potentially be started ( no dependencies with other actions in the
* resource) are already locked to avoid their start without being on the runningActions set.
*/
Gap gap = state.peekFirstGap();
ResourceDescription gapResource = gap.getResources();
PriorityQueue<SchedulingEvent> schedulingQueue = new PriorityQueue<>();
// For every running action we create a start event on their real start timeStamp
for (AllocatableAction action : state.getRunningActions()) {
manageRunningAction(action, state);
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
schedulingQueue.offer(new SchedulingEvent.End(actionDSI.getExpectedEnd(), action));
}
while (state.areRunnableActions() && !gapResource.isDynamicUseless()) {
AllocatableAction top = state.getMostPrioritaryRunnableAction();
state.replaceAction(top);
if (state.canActionRun()) {
state.removeMostPrioritaryRunnableAction();
// Start the current action
MOSchedulingInformation topDSI = (MOSchedulingInformation) top.getSchedulingInfo();
topDSI.lock();
topDSI.clearPredecessors();
manageRunningAction(top, state);
if (tryToLaunch(top)) {
schedulingQueue.offer(new SchedulingEvent.End(topDSI.getExpectedEnd(), top));
}
} else {
break;
}
}
while (!schedulingQueue.isEmpty() || state.areActionsToBeRescheduled()) {
while (!schedulingQueue.isEmpty()) {
SchedulingEvent e = schedulingQueue.poll();
/*
* Start Event: - sets the expected start and end times - adds resource dependencies with the previous
* actions - if there's a gap before the dependency -tries to fill it with other tasks - if all the
* resources released by the predecessor are used later - the action is unlocked
*
* End Event:
*
*/
List<SchedulingEvent> result = e.process(state, (MOResourceScheduler<WorkerResourceDescription>) this, rescheduledActions);
for (SchedulingEvent r : result) {
schedulingQueue.offer(r);
}
}
if (state.areActionsToBeRescheduled()) {
AllocatableAction topAction = state.getEarliestActionToBeRescheduled();
MOSchedulingInformation topActionDSI = (MOSchedulingInformation) topAction.getSchedulingInfo();
topActionDSI.lock();
topActionDSI.setToReschedule(false);
schedulingQueue.offer(new SchedulingEvent.Start(topActionDSI.getExpectedStart(), topAction));
}
}
for (Gap g : state.getGaps()) {
state.removeTmpGap(g);
}
this.pendingActionsCost = state.getTotalCost();
this.pendingActionsEnergy = state.getTotalEnergy();
this.implementationsCount = state.getImplementationsCount();
this.expectedEndTimeRunning = state.getEndRunningTime();
this.runningImplementationsCount = state.getRunningImplementations();
this.runningActionsEnergy = state.getRunningEnergy();
this.runningActionsCost = state.getRunningCost();
this.resourceBlockingAction = state.getResourceBlockingAction();
this.dataBlockingAction = state.getDataBlockingAction();
return state.getGaps();
}
use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.
the class MOResourceScheduler method scanActions.
// Classifies actions according to their start times. Selectable actions are
// those that can be selected to run from t=0. Ready actions are those actions
// that have data dependencies with tasks scheduled in other nodes. Actions
// with dependencies with actions scheduled in the same node, are not
// classified in any list since we cannot know the start time.
public List<AllocatableAction> scanActions(LocalOptimizationState state) {
List<AllocatableAction> pendingToUnlockActions = new LinkedList<AllocatableAction>();
PriorityQueue<AllocatableAction> actions = new PriorityQueue<AllocatableAction>(1, getScanComparator());
MOSchedulingInformation blockSI = (MOSchedulingInformation) dataBlockingAction.getSchedulingInfo();
List<AllocatableAction> blockActions = blockSI.getSuccessors();
for (AllocatableAction gapAction : blockActions) {
MOSchedulingInformation dsi = (MOSchedulingInformation) gapAction.getSchedulingInfo();
dsi.lock();
dsi.setOnOptimization(true);
actions.add(gapAction);
}
blockSI = (MOSchedulingInformation) resourceBlockingAction.getSchedulingInfo();
blockActions = blockSI.getSuccessors();
for (AllocatableAction gapAction : blockActions) {
MOSchedulingInformation dsi = (MOSchedulingInformation) gapAction.getSchedulingInfo();
dsi.lock();
dsi.setOnOptimization(true);
actions.add(gapAction);
}
LinkedList<AllocatableAction> modified = new LinkedList<>();
while (true) {
try {
for (Gap g : gaps) {
AllocatableAction gapAction = g.getOrigin();
if (gapAction != null) {
MOSchedulingInformation dsi = (MOSchedulingInformation) gapAction.getSchedulingInfo();
dsi.lock();
dsi.setOnOptimization(true);
modified.add(gapAction);
}
}
break;
} catch (ConcurrentModificationException cme) {
for (AllocatableAction action : modified) {
MOSchedulingInformation dsi = (MOSchedulingInformation) action.getSchedulingInfo();
dsi.setOnOptimization(false);
dsi.unlock();
}
modified.clear();
}
}
actions.addAll(modified);
AllocatableAction action;
while ((action = actions.poll()) != null) {
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
// System.out.println(" ** Evaluating Action "+ action + " with SI: "+ actionDSI.hashCode());
if (!actionDSI.isScheduled()) {
try {
actionDSI.unlock();
} catch (IllegalMonitorStateException e) {
LOGGER.debug(LOG_PREFIX + "Illegal Monitor Exception scaning actions. Ignoring...");
}
// scheduled ");
continue;
}
// Data Dependencies analysis
boolean hasInternal = false;
boolean hasExternal = false;
long startTime = 0;
while (true) {
List<MOSchedulingInformation> managedDSIs = new LinkedList<>();
try {
List<AllocatableAction> dPreds = action.getDataPredecessors();
for (AllocatableAction dPred : dPreds) {
MOSchedulingInformation dPredDSI = (MOSchedulingInformation) dPred.getSchedulingInfo();
if (dPred.getAssignedResource() == this) {
if (dPredDSI.tryToLock()) {
if (dPredDSI.isScheduled()) {
hasInternal = true;
dPredDSI.addOptimizingSuccessor(action);
managedDSIs.add(dPredDSI);
}
dPredDSI.unlock();
}
// else
// The predecessor is trying to be unscheduled but it is
// blocked by another successor reschedule.
} else {
hasExternal = true;
startTime = Math.max(startTime, dPredDSI.getExpectedEnd());
}
}
break;
} catch (ConcurrentModificationException cme) {
for (MOSchedulingInformation dsi : managedDSIs) {
dsi.removeOptimizingSuccessor(action);
}
}
}
// Resource Dependencies analysis
boolean hasResourcePredecessors = false;
List<Gap> rPredGaps = actionDSI.getPredecessors();
for (Gap rPredGap : rPredGaps) {
AllocatableAction rPred = rPredGap.getOrigin();
if (rPred != null) {
MOSchedulingInformation rPredDSI = (MOSchedulingInformation) rPred.getSchedulingInfo();
if (rPredDSI.tryToLock()) {
if (rPredDSI.isScheduled()) {
hasResourcePredecessors = true;
if (!rPredDSI.isOnOptimization()) {
rPredDSI.setOnOptimization(true);
actions.add(rPred);
} else {
rPredDSI.unlock();
}
} else {
rPredDSI.unlock();
}
}
}
// else the predecessor was already executed
}
actionDSI.setExpectedStart(startTime);
actionDSI.setToReschedule(true);
// System.out.println(" ** Classifiying Action "+ action + " with SI: "+ actionDSI.hashCode());
state.classifyAction(action, hasInternal, hasExternal, hasResourcePredecessors, startTime);
if (hasResourcePredecessors || hasInternal) {
// The action has a blocked predecessor in the resource that will block its execution
actionDSI.unlock();
} else {
pendingToUnlockActions.add(action);
}
// System.out.println(" ** END evaluation Action "+ action + " with SI: "+ actionDSI.hashCode());
}
return pendingToUnlockActions;
}
use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.
the class MOSchedulingInformation method removePredecessor.
public Gap removePredecessor(AllocatableAction successor) {
Iterator<Gap> it = resourcePredecessors.iterator();
Gap g = null;
while (it.hasNext()) {
g = it.next();
if (g.getOrigin() == successor) {
it.remove();
}
}
return g;
}
use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.
the class MOResourceScheduler method addGap.
private void addGap(Gap g) {
AllocatableAction gapAction = g.getOrigin();
ResourceDescription releasedResources = g.getResources();
boolean merged = false;
for (Gap registeredGap : gaps) {
if (registeredGap.getOrigin() == gapAction) {
ResourceDescription registeredResources = registeredGap.getResources();
registeredResources.increaseDynamic(releasedResources);
merged = true;
break;
}
}
if (!merged) {
Iterator<Gap> gapIt = gaps.iterator();
int index = 0;
Gap gap;
while (gapIt.hasNext() && (gap = gapIt.next()) != null && gap.getInitialTime() <= g.getInitialTime()) {
index++;
}
gaps.add(index, g);
}
}
use of es.bsc.compss.scheduler.multiobjective.types.Gap 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