use of es.bsc.compss.scheduler.types.AllocatableAction in project compss by bsc-wdc.
the class AllocatableActionTest method completed.
/*---------------------------------------------------------
----------------------------------------------------------
--------------------- SCHEDULER ACTIONS ------------------
----------------------------------------------------------
--------------------------------------------------------*/
public void completed(FakeAllocatableAction action) throws BlockedActionException, UnassignedActionException, InvalidSchedulingException {
FakeResourceScheduler resource = (FakeResourceScheduler) action.getAssignedResource();
List<AllocatableAction> dataFree = action.completed();
List<AllocatableAction> resourceFree = resource.unscheduleAction(action);
Set<AllocatableAction> freeTasks = new HashSet<>();
freeTasks.addAll(dataFree);
freeTasks.addAll(resourceFree);
for (AllocatableAction a : freeTasks) {
FakeAllocatableAction fa = (FakeAllocatableAction) a;
fa.tryToLaunch();
}
}
use of es.bsc.compss.scheduler.types.AllocatableAction 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.types.AllocatableAction in project compss by bsc-wdc.
the class MOScheduleOptimizer method globalOptimization.
/*--------------------------------------------------
---------------------------------------------------
--------------- Local optimization ---------------
---------------------------------------------------
--------------------------------------------------*/
@SuppressWarnings("unchecked")
public void globalOptimization(long optimizationTS, Collection<ResourceScheduler<? extends WorkerResourceDescription>> workers) {
LOGGER.debug(LOG_PREFIX + " --- Start Global Optimization ---");
int workersCount = workers.size();
if (workersCount == 0) {
return;
}
OptimizationWorker[] optimizedWorkers = new OptimizationWorker[workersCount];
LinkedList<OptimizationWorker> receivers = new LinkedList<>();
int i = 0;
for (ResourceScheduler<? extends WorkerResourceDescription> worker : workers) {
optimizedWorkers[i] = new OptimizationWorker((MOResourceScheduler<WorkerResourceDescription>) worker);
i++;
}
boolean hasDonated = true;
while (hasDonated) {
optimizationTS = System.currentTimeMillis();
hasDonated = false;
LOGGER.debug(LOG_PREFIX + " --- Iteration of global Optimization ---");
// Perform local optimizations
for (OptimizationWorker ow : optimizedWorkers) {
LOGGER.debug(LOG_PREFIX + "Optimizing localy resource " + ow.getName());
ow.localOptimization(optimizationTS);
LOGGER.debug(LOG_PREFIX + "Resource " + ow.getName() + " will end at " + ow.getDonationIndicator());
}
LinkedList<OptimizationWorker> donors = determineDonorAndReceivers(optimizedWorkers, receivers);
while (!hasDonated && !donors.isEmpty()) {
OptimizationWorker donor = donors.remove();
AllocatableAction candidate;
while (!hasDonated && (candidate = donor.pollDonorAction()) != null) {
/*
* if (candidate == null) { break; }
*/
Iterator<OptimizationWorker> recIt = receivers.iterator();
while (recIt.hasNext()) {
OptimizationWorker receiver = recIt.next();
if (move(candidate, donor, receiver)) {
hasDonated = true;
break;
}
}
}
}
LOGGER.debug(LOG_PREFIX + "--- Optimization Iteration finished ---");
}
LOGGER.debug(LOG_PREFIX + "--- Global Optimization finished ---");
}
use of es.bsc.compss.scheduler.types.AllocatableAction in project compss by bsc-wdc.
the class MOScheduler method handleDependencyFreeActions.
/**
* Notifies to the scheduler that some actions have become free of data dependencies or resource dependencies.
*
* @param <T>
* @param dataFreeActions
* IN, list of actions free of data dependencies
* @param resourceFreeActions
* IN, list of actions free of resource dependencies
* @param blockedCandidates
* OUT, list of blocked candidates
* @param resource
* Resource where the previous task was executed
*/
@Override
public <T extends WorkerResourceDescription> void handleDependencyFreeActions(List<AllocatableAction> dataFreeActions, List<AllocatableAction> resourceFreeActions, List<AllocatableAction> blockedCandidates, ResourceScheduler<T> resource) {
Set<AllocatableAction> freeTasks = new HashSet<>();
freeTasks.addAll(dataFreeActions);
freeTasks.addAll(resourceFreeActions);
for (AllocatableAction freeAction : freeTasks) {
tryToLaunch(freeAction);
}
}
use of es.bsc.compss.scheduler.types.AllocatableAction in project compss by bsc-wdc.
the class LocalOptimizationState method checkGapForReserve.
private boolean checkGapForReserve(Gap g, ResourceDescription requirements, long reserveStart, List<Gap> previousGaps) {
boolean remove = false;
AllocatableAction gapAction = g.getOrigin();
ResourceDescription rd = g.getResources();
ResourceDescription reduction = ResourceDescription.reduceCommonDynamics(rd, requirements);
if (!reduction.isDynamicUseless()) {
Gap tmpGap = new Gap(g.getInitialTime(), reserveStart, g.getOrigin(), reduction, 0);
previousGaps.add(tmpGap);
if (gapAction != null) {
MOSchedulingInformation gapDSI = (MOSchedulingInformation) gapAction.getSchedulingInfo();
// Remove resources from the first gap
gapDSI.addGap();
}
// If the gap has been fully used
if (rd.isDynamicUseless()) {
// Remove the gap
remove = true;
if (gapAction != null) {
MOSchedulingInformation gapDSI = (MOSchedulingInformation) gapAction.getSchedulingInfo();
gapDSI.removeGap();
}
}
}
return remove;
}
Aggregations