use of es.bsc.compss.scheduler.exceptions.ActionNotFoundException in project compss by bsc-wdc.
the class MOResourceScheduler method unscheduleAction.
@Override
public List<AllocatableAction> unscheduleAction(AllocatableAction action) throws ActionNotFoundException {
super.unscheduleAction(action);
List<AllocatableAction> freeActions = new LinkedList<>();
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
List<Gap> resources = new LinkedList<>();
// Block all predecessors
for (Gap pGap : actionDSI.getPredecessors()) {
AllocatableAction pred = pGap.getOrigin();
if (pred != null) {
MOSchedulingInformation predDSI = (MOSchedulingInformation) pred.getSchedulingInfo();
predDSI.lock();
}
}
// Block Action
actionDSI.lock();
if (!actionDSI.isScheduled() || action.getAssignedResource() != this) {
for (Gap pGap : actionDSI.getPredecessors()) {
AllocatableAction pred = pGap.getOrigin();
if (pred != null) {
MOSchedulingInformation predDSI = (MOSchedulingInformation) pred.getSchedulingInfo();
predDSI.unlock();
}
}
actionDSI.unscheduled();
actionDSI.unlock();
throw new ActionNotFoundException();
}
ResourceDescription unassignedResources = action.getAssignedImplementation().getRequirements().copy();
// Remove the scheduling dependency on the predecessor
for (Gap pGap : actionDSI.getPredecessors()) {
AllocatableAction pred = pGap.getOrigin();
if (pred != null) {
if (!(pred instanceof OptimizationAction)) {
resources.add(new Gap(pGap.getInitialTime(), Long.MAX_VALUE, pred, pGap.getResources().copy(), 0));
unassignedResources.reduceDynamic(pGap.getResources());
}
MOSchedulingInformation predDSI = (MOSchedulingInformation) pred.getSchedulingInfo();
predDSI.removeSuccessor(action);
}
}
resources.add(new Gap(Long.MIN_VALUE, Long.MAX_VALUE, null, unassignedResources, 0));
// Remove all predecessors for
actionDSI.clearPredecessors();
// Block all successors
List<MOSchedulingInformation> successorsDSIs = new LinkedList<MOSchedulingInformation>();
for (AllocatableAction successor : actionDSI.getSuccessors()) {
MOSchedulingInformation succDSI = (MOSchedulingInformation) successor.getSchedulingInfo();
succDSI.lock();
successorsDSIs.add(succDSI);
}
// For each successor look for the resources
for (AllocatableAction successor : actionDSI.getSuccessors()) {
MOSchedulingInformation succDSI = (MOSchedulingInformation) successor.getSchedulingInfo();
// Gets the resources that was supposed to get from the task and remove the dependency
Gap toCover = succDSI.removePredecessor(action);
if (toCover != null) {
ResourceDescription resToCover = toCover.getResources();
// Scans the resources related to the task to cover its requirements
Iterator<Gap> gIt = resources.iterator();
while (gIt.hasNext()) {
Gap availableGap = gIt.next();
// Takes the resources from a predecessor,
ResourceDescription availableDesc = availableGap.getResources();
ResourceDescription usedResources = ResourceDescription.reduceCommonDynamics(availableDesc, resToCover);
// If all the resources required for the successor are covered -> move to the next successor
if (!usedResources.isDynamicUseless()) {
AllocatableAction availableOrigin = availableGap.getOrigin();
MOSchedulingInformation availableDSI = null;
if (availableOrigin != null) {
availableDSI = (MOSchedulingInformation) availableOrigin.getSchedulingInfo();
availableDSI.addSuccessor(successor);
succDSI.addPredecessor(new Gap(availableGap.getInitialTime(), Long.MAX_VALUE, availableOrigin, usedResources, 0));
}
if (availableDesc.isDynamicUseless()) {
gIt.remove();
if (availableDSI != null) {
availableDSI.unlock();
}
}
if (resToCover.isDynamicUseless()) {
break;
}
}
}
}
if (succDSI.isExecutable()) {
freeActions.add(successor);
}
}
// Clear action's successors
actionDSI.clearSuccessors();
// Indicate that the task is fully unsheduled
actionDSI.unscheduled();
// Register those resources occupied by the task that haven't been used as free
synchronized (gaps) {
if (actionDSI.isOnOptimization()) {
pendingUnschedulings.add(action);
}
Iterator<Gap> gIt = gaps.iterator();
while (gIt.hasNext()) {
Gap g = gIt.next();
if (g.getOrigin() == action) {
gIt.remove();
}
}
for (Gap newGap : resources) {
AllocatableAction gapAction = newGap.getOrigin();
addGap(newGap);
if (gapAction != null) {
((MOSchedulingInformation) gapAction.getSchedulingInfo()).unlock();
}
}
}
Implementation impl = action.getAssignedImplementation();
MOProfile p = (MOProfile) getProfile(impl);
if (p != null) {
long length = actionDSI.getExpectedEnd() - (actionDSI.getExpectedStart() < 0 ? 0 : actionDSI.getExpectedStart());
pendingActionsCost -= p.getPrice() * length;
pendingActionsEnergy -= p.getPower() * length;
}
actionDSI.unlock();
for (MOSchedulingInformation successorsDSI : successorsDSIs) {
successorsDSI.unlock();
}
return freeActions;
}
use of es.bsc.compss.scheduler.exceptions.ActionNotFoundException in project compss by bsc-wdc.
the class MOScheduleOptimizer method move.
private boolean move(AllocatableAction action, OptimizationWorker donor, OptimizationWorker receiver) {
LOGGER.debug(LOG_PREFIX + "Trying to move " + action + " from " + donor.getName() + " to " + receiver.getName());
List<AllocatableAction> dataPreds = action.getDataPredecessors();
long dataAvailable = 0;
try {
for (AllocatableAction dataPred : dataPreds) {
MOSchedulingInformation dsi = (MOSchedulingInformation) dataPred.getSchedulingInfo();
dataAvailable = Math.max(dataAvailable, dsi.getExpectedEnd());
}
} catch (ConcurrentModificationException cme) {
dataAvailable = 0;
dataPreds = action.getDataPredecessors();
}
Implementation bestImpl = null;
List<Implementation> impls = action.getCompatibleImplementations(receiver.getResource());
Score bestScore = null;
for (Implementation impl : impls) {
MOScore actionScore = MOScheduler.getActionScore(action);
MOScore score = ((MOResourceScheduler<?>) (receiver.getResource())).generateMoveImplementationScore(action, null, impl, actionScore, (long) (OPTIMIZATION_THRESHOLD * 2.5));
if (Score.isBetter(score, bestScore)) {
bestImpl = impl;
bestScore = score;
}
}
Implementation currentImpl = action.getAssignedImplementation();
MOScore actionScore = MOScheduler.getActionScore(action);
LOGGER.debug(LOG_PREFIX + "Calculating score for current execution");
MOScore currentScore = ((MOResourceScheduler<?>) (action.getAssignedResource())).generateCurrentImplementationScore(action, currentImpl, actionScore);
LOGGER.debug(LOG_PREFIX + "Comparing scores: \n" + bestScore + "\n " + currentScore);
if (bestImpl != null && Score.isBetter(bestScore, currentScore)) {
try {
LOGGER.debug(LOG_PREFIX + "Moving " + action + " from " + donor.getName() + " to " + receiver.getName());
unscheduleFromWorker(action);
scheduleOnWorker(action, bestImpl, receiver);
} catch (ActionNotFoundException anfe) {
// Action was already moved from the resource. Recompute Optimizations!!!
}
return true;
} else {
LOGGER.debug(LOG_PREFIX + "Action " + action + " not moved because new position is not better than actual");
}
return false;
}
use of es.bsc.compss.scheduler.exceptions.ActionNotFoundException in project compss by bsc-wdc.
the class TaskScheduler method workerRemoved.
/**
* One worker has been removed from the pool; the Task Scheduler is notified to modify any internal structure using
* that information.
*
* @param <T>
* @param resource
* removed worker
*/
protected <T extends WorkerResourceDescription> void workerRemoved(ResourceScheduler<T> resource) {
LOGGER.info("[TaskScheduler] Remove worker " + resource.getName());
// There are no internal structures worker-related. No need to do anything.
PriorityQueue<AllocatableAction> blockedOnResource = resource.getBlockedActions();
for (AllocatableAction action : blockedOnResource) {
try {
resource.unscheduleAction(action);
} catch (ActionNotFoundException ex) {
// Task was already moved from the worker. Do nothing!
continue;
}
Score actionScore = generateActionScore(action);
try {
scheduleAction(action, actionScore);
tryToLaunch(action);
} catch (BlockedActionException bae) {
if (!action.hasDataPredecessors()) {
removeFromReady(action);
}
addToBlocked(action);
}
}
}
use of es.bsc.compss.scheduler.exceptions.ActionNotFoundException in project compss by bsc-wdc.
the class TaskScheduler method errorOnAction.
/**
* Registers an error on the action given as a parameter. The action itself processes the error and triggers with
* any possible solution to re-execute it. This code is executed only on re-schedule (no resubmit)
*
* @param action
* action raising the error
*/
@SuppressWarnings("unchecked")
public final void errorOnAction(AllocatableAction action) {
LOGGER.warn("[TaskScheduler] Error on action " + action);
List<AllocatableAction> resourceFree = new LinkedList<>();
ResourceScheduler<WorkerResourceDescription> resource = (ResourceScheduler<WorkerResourceDescription>) action.getAssignedResource();
boolean failed = false;
// Process the action error (removes the assigned resource)
try {
action.error();
} catch (FailedActionException fae) {
// Action has completely failed
failed = true;
LOGGER.warn("[TaskScheduler] Action completely failed " + action);
removeFromReady(action);
// Free all the dependent tasks
for (AllocatableAction failedAction : action.failed()) {
try {
resourceFree.addAll(resource.unscheduleAction(failedAction));
} catch (ActionNotFoundException anfe) {
// Once the action starts running should cannot be moved from the resource
}
}
}
// We free the current task and get the free actions from the resource
try {
resourceFree.addAll(resource.unscheduleAction(action));
} catch (ActionNotFoundException anfe) {
// Once the action starts running should cannot be moved from the resource
}
workerLoadUpdate(resource);
if (!failed) {
// Try to re-schedule the action
Score actionScore = generateActionScore(action);
try {
scheduleAction(action, actionScore);
tryToLaunch(action);
} catch (BlockedActionException bae) {
removeFromReady(action);
addToBlocked(action);
}
}
List<AllocatableAction> blockedCandidates = new LinkedList<>();
handleDependencyFreeActions(new LinkedList<>(), resourceFree, blockedCandidates, resource);
for (AllocatableAction aa : blockedCandidates) {
removeFromReady(aa);
addToBlocked(aa);
}
}
use of es.bsc.compss.scheduler.exceptions.ActionNotFoundException in project compss by bsc-wdc.
the class TaskScheduler method actionCompleted.
/**
* Registers an action as completed and releases all the resource and data dependencies.
*
* @param action
* action that has finished
*/
@SuppressWarnings("unchecked")
public final void actionCompleted(AllocatableAction action) {
LOGGER.info("[TaskScheduler] Action completed " + action);
// Mark action as finished
removeFromReady(action);
ResourceScheduler<WorkerResourceDescription> resource = (ResourceScheduler<WorkerResourceDescription>) action.getAssignedResource();
List<AllocatableAction> resourceFree;
try {
resourceFree = resource.unscheduleAction(action);
} catch (ActionNotFoundException ex) {
// Once the action starts running should cannot be moved from the resource
resourceFree = new LinkedList<>();
}
// Get the data free actions and mark them as ready
List<AllocatableAction> dataFreeActions = action.completed();
Iterator<AllocatableAction> dataFreeIter = dataFreeActions.iterator();
while (dataFreeIter.hasNext()) {
AllocatableAction dataFreeAction = dataFreeIter.next();
addToReady(dataFreeAction);
}
// We update the worker load
workerLoadUpdate(resource);
// Schedule data free actions
List<AllocatableAction> blockedCandidates = new LinkedList<>();
// Actions can only be scheduled and those that remain blocked must be added to the blockedCandidates list
// and those that remain unassigned must be added to the unassigned list
handleDependencyFreeActions(dataFreeActions, resourceFree, blockedCandidates, resource);
for (AllocatableAction aa : blockedCandidates) {
removeFromReady(aa);
addToBlocked(aa);
}
}
Aggregations