use of es.bsc.compss.scheduler.types.AllocatableAction in project compss by bsc-wdc.
the class ExecutionAction method tryToSchedule.
@SuppressWarnings("unchecked")
@Override
public final void tryToSchedule(Score actionScore) throws BlockedActionException, UnassignedActionException {
// COMPUTE RESOURCE CANDIDATES
List<ResourceScheduler<? extends WorkerResourceDescription>> candidates = new LinkedList<>();
if (this.isTargetResourceEnforced()) {
// The scheduling is forced to a given resource
candidates.add((ResourceScheduler<WorkerResourceDescription>) this.getEnforcedTargetResource());
} else if (isSchedulingConstrained()) {
// The scheduling is constrained by dependencies
for (AllocatableAction a : this.getConstrainingPredecessors()) {
candidates.add((ResourceScheduler<WorkerResourceDescription>) a.getAssignedResource());
}
} else {
// Free scheduling
List<ResourceScheduler<? extends WorkerResourceDescription>> compatibleCandidates = getCompatibleWorkers();
if (compatibleCandidates.size() == 0) {
throw new BlockedActionException();
}
for (ResourceScheduler<? extends WorkerResourceDescription> currentWorker : compatibleCandidates) {
if (currentWorker.getResource().hasAvailableSlots()) {
candidates.add(currentWorker);
}
}
if (candidates.size() == 0) {
throw new UnassignedActionException();
}
}
this.schedule(actionScore, candidates);
}
use of es.bsc.compss.scheduler.types.AllocatableAction in project compss by bsc-wdc.
the class ResourceScheduler method tryToLaunchBlockedActions.
/**
* Tries to launch blocked actions on resource. When an action cannot be launched, its successors are not tried
*/
@SuppressWarnings("unchecked")
public final void tryToLaunchBlockedActions() {
LOGGER.debug("[ResourceScheduler] Try to launch blocked actions on resource " + getName());
while (this.hasBlockedActions()) {
AllocatableAction firstBlocked = this.getFirstBlocked();
Implementation selectedImplementation = firstBlocked.getAssignedImplementation();
if (!firstBlocked.isToReserveResources() || myWorker.canRunNow((T) selectedImplementation.getRequirements())) {
try {
firstBlocked.resumeExecution();
this.removeFirstBlocked();
} catch (ActionNotWaitingException anwe) {
// Not possible. If the task is in blocked list it is waiting
}
} else {
break;
}
}
}
use of es.bsc.compss.scheduler.types.AllocatableAction 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.types.AllocatableAction in project compss by bsc-wdc.
the class TaskScheduler method updateWorkloadState.
protected void updateWorkloadState(WorkloadState state) {
LOGGER.info("[TaskScheduler] Get workload state");
int coreCount = CoreManager.getCoreCount();
Profile[] coreProfile = new Profile[coreCount];
for (int coreId = 0; coreId < coreCount; coreId++) {
coreProfile[coreId] = new Profile();
}
for (ResourceScheduler<? extends WorkerResourceDescription> ui : workers.values()) {
if (ui == null) {
continue;
}
List<Implementation>[] impls = ui.getExecutableImpls();
for (int coreId = 0; coreId < coreCount; coreId++) {
for (Implementation impl : impls[coreId]) {
coreProfile[coreId].accumulate(ui.getProfile(impl));
}
}
AllocatableAction[] runningActions = ui.getHostedActions();
long now = System.currentTimeMillis();
for (AllocatableAction running : runningActions) {
if (running.getImplementations().length > 0) {
Integer coreId = running.getImplementations()[0].getCoreId();
// CoreId can be null for Actions that are not tasks
if (coreId != null) {
state.registerRunning(coreId, now - running.getStartTime());
}
}
}
}
for (int coreId = 0; coreId < coreCount; coreId++) {
state.registerNoResources(coreId, blockedActions.getActionCounts()[coreId]);
state.registerReady(coreId, readyCounts[coreId]);
state.registerTimes(coreId, coreProfile[coreId].getMinExecutionTime(), coreProfile[coreId].getAverageExecutionTime(), coreProfile[coreId].getMaxExecutionTime());
}
}
use of es.bsc.compss.scheduler.types.AllocatableAction 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);
}
}
Aggregations