Search in sources :

Example 1 with Gap

use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.

the class MOResourceScheduler method scheduleUsingGaps.

private void scheduleUsingGaps(AllocatableAction action, List<Gap> gaps) {
    long expectedStart = 0;
    // Compute start time due to data dependencies
    for (AllocatableAction predecessor : action.getDataPredecessors()) {
        MOSchedulingInformation predDSI = ((MOSchedulingInformation) predecessor.getSchedulingInfo());
        if (predDSI.isScheduled()) {
            long predEnd = predDSI.getExpectedEnd();
            expectedStart = Math.max(expectedStart, predEnd);
        }
    }
    MOSchedulingInformation schedInfo = (MOSchedulingInformation) action.getSchedulingInfo();
    if (expectedStart == Long.MAX_VALUE) {
        // There is some data dependency with blocked tasks in some resource
        Gap opActionGap = new Gap(0, 0, dataBlockingAction, action.getAssignedImplementation().getRequirements().copy(), 0);
        MOSchedulingInformation dbaDSI = (MOSchedulingInformation) dataBlockingAction.getSchedulingInfo();
        dbaDSI.lock();
        schedInfo.lock();
        dbaDSI.addSuccessor(action);
        schedInfo.addPredecessor(opActionGap);
        schedInfo.setExpectedStart(Long.MAX_VALUE);
        schedInfo.setExpectedEnd(Long.MAX_VALUE);
        schedInfo.scheduled();
        dbaDSI.unlock();
        schedInfo.unlock();
        return;
    }
    Implementation impl = action.getAssignedImplementation();
    MOProfile p = (MOProfile) getProfile(impl);
    ResourceDescription constraints = impl.getRequirements().copy();
    List<Gap> predecessors = new LinkedList<>();
    Iterator<Gap> gapIt = ((LinkedList<Gap>) gaps).descendingIterator();
    boolean fullyCoveredReqs = false;
    // Check gaps before data start
    while (gapIt.hasNext() && !fullyCoveredReqs) {
        Gap gap = gapIt.next();
        if (gap.getInitialTime() <= expectedStart) {
            useGap(gap, constraints, predecessors);
            fullyCoveredReqs = constraints.isDynamicUseless();
            if (gap.getResources().isDynamicUseless()) {
                gapIt.remove();
            }
        }
    }
    // Check gaps after data start
    gapIt = gaps.iterator();
    while (gapIt.hasNext() && !fullyCoveredReqs) {
        Gap gap = gapIt.next();
        if (gap.getInitialTime() > expectedStart) {
            if (gap.getInitialTime() < Long.MAX_VALUE) {
                useGap(gap, constraints, predecessors);
                fullyCoveredReqs = constraints.isDynamicUseless();
                if (gap.getResources().isDynamicUseless()) {
                    gapIt.remove();
                }
            }
        }
    }
    if (!fullyCoveredReqs) {
        // Action gets blocked due to lack of resources
        for (Gap pGap : predecessors) {
            addGap(pGap);
            AllocatableAction predecessor = (AllocatableAction) pGap.getOrigin();
            if (predecessor != null) {
                MOSchedulingInformation predDSI = ((MOSchedulingInformation) predecessor.getSchedulingInfo());
                predDSI.unlock();
            }
        }
        Gap opActionGap = new Gap(0, 0, resourceBlockingAction, action.getAssignedImplementation().getRequirements(), 0);
        MOSchedulingInformation rbaDSI = (MOSchedulingInformation) resourceBlockingAction.getSchedulingInfo();
        rbaDSI.lock();
        schedInfo.lock();
        rbaDSI.addSuccessor(action);
        schedInfo.addPredecessor(opActionGap);
        schedInfo.scheduled();
        schedInfo.setExpectedStart(Long.MAX_VALUE);
        schedInfo.setExpectedEnd(Long.MAX_VALUE);
        rbaDSI.unlock();
        schedInfo.unlock();
        return;
    }
    // Lock acces to the current task
    schedInfo.lock();
    schedInfo.scheduled();
    // Add dependencies
    // Unlock access to predecessor
    StringBuilder sb = null;
    if (IS_DEBUG) {
        sb = new StringBuilder("Predecessors: ");
    }
    for (Gap pGap : predecessors) {
        AllocatableAction predecessor = pGap.getOrigin();
        if (predecessor != null) {
            MOSchedulingInformation predDSI = ((MOSchedulingInformation) predecessor.getSchedulingInfo());
            if (predDSI.isScheduled()) {
                long predEnd = predDSI.getExpectedEnd();
                expectedStart = Math.max(expectedStart, predEnd);
                predDSI.addSuccessor(action);
            }
            predDSI.unlock();
        }
        schedInfo.addPredecessor(pGap);
        if (IS_DEBUG) {
            sb.append(pGap.getOrigin()).append(" with ").append(pGap.getResources().getDynamicDescription()).append(", ");
        }
    }
    // Compute end time
    schedInfo.setExpectedStart(expectedStart);
    long expectedEnd = expectedStart;
    if (p != null) {
        expectedEnd += p.getAverageExecutionTime();
        pendingActionsCost += p.getPrice() * p.getAverageExecutionTime();
        pendingActionsEnergy += p.getPower() * p.getAverageExecutionTime();
    }
    schedInfo.setExpectedEnd(expectedEnd);
    // Unlock access to current task
    schedInfo.unlock();
    if (action.isToReleaseResources()) {
        // Create new Gap correspondin to the resources released by the action
        addGap(new Gap(expectedEnd, Long.MAX_VALUE, action, impl.getRequirements().copy(), 0));
    } else {
        addGap(new Gap(Long.MAX_VALUE, Long.MAX_VALUE, action, impl.getRequirements().copy(), 0));
    }
    if (IS_DEBUG) {
        LOGGER.debug(LOG_PREFIX + "Scheduled " + action.toString() + ". Interval [ " + expectedStart + " - " + expectedEnd + "] " + sb.toString());
    }
}
Also used : WorkerResourceDescription(es.bsc.compss.types.resources.WorkerResourceDescription) ResourceDescription(es.bsc.compss.types.resources.ResourceDescription) Gap(es.bsc.compss.scheduler.multiobjective.types.Gap) AllocatableAction(es.bsc.compss.scheduler.types.AllocatableAction) Implementation(es.bsc.compss.types.implementations.Implementation) MOProfile(es.bsc.compss.scheduler.multiobjective.types.MOProfile) LinkedList(java.util.LinkedList)

Example 2 with Gap

use of es.bsc.compss.scheduler.multiobjective.types.Gap 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;
}
Also used : OptimizationAction(es.bsc.compss.scheduler.multiobjective.types.OptimizationAction) AllocatableAction(es.bsc.compss.scheduler.types.AllocatableAction) LinkedList(java.util.LinkedList) Implementation(es.bsc.compss.types.implementations.Implementation) ActionNotFoundException(es.bsc.compss.scheduler.exceptions.ActionNotFoundException) WorkerResourceDescription(es.bsc.compss.types.resources.WorkerResourceDescription) ResourceDescription(es.bsc.compss.types.resources.ResourceDescription) Gap(es.bsc.compss.scheduler.multiobjective.types.Gap) MOProfile(es.bsc.compss.scheduler.multiobjective.types.MOProfile)

Example 3 with Gap

use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.

the class MOResourceScheduler method useGap.

private void useGap(Gap gap, ResourceDescription resources, List<Gap> predecessors) {
    AllocatableAction predecessor = (AllocatableAction) gap.getOrigin();
    ResourceDescription gapResource = gap.getResources();
    ResourceDescription usedResources = ResourceDescription.reduceCommonDynamics(gapResource, resources);
    if (usedResources.isDynamicConsuming()) {
        if (predecessor != null) {
            MOSchedulingInformation predDSI = ((MOSchedulingInformation) predecessor.getSchedulingInfo());
            predDSI.lock();
        }
        Gap g = new Gap(gap.getInitialTime(), Long.MAX_VALUE, predecessor, usedResources, 0);
        predecessors.add(g);
    }
}
Also used : WorkerResourceDescription(es.bsc.compss.types.resources.WorkerResourceDescription) ResourceDescription(es.bsc.compss.types.resources.ResourceDescription) Gap(es.bsc.compss.scheduler.multiobjective.types.Gap) AllocatableAction(es.bsc.compss.scheduler.types.AllocatableAction)

Example 4 with Gap

use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.

the class MOResourceScheduler method getResourceFreeTime.

private long getResourceFreeTime(Implementation impl) {
    ResourceDescription rd = impl.getRequirements().copy();
    long resourceFreeTime = 0;
    try {
        for (Gap g : gaps) {
            rd.reduceDynamic(g.getResources());
            if (rd.isDynamicUseless()) {
                resourceFreeTime = g.getInitialTime();
                break;
            }
        }
    } catch (ConcurrentModificationException cme) {
        resourceFreeTime = 0;
    }
    if (resourceFreeTime < 0) {
        resourceFreeTime = 0;
    }
    return resourceFreeTime;
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) WorkerResourceDescription(es.bsc.compss.types.resources.WorkerResourceDescription) ResourceDescription(es.bsc.compss.types.resources.ResourceDescription) Gap(es.bsc.compss.scheduler.multiobjective.types.Gap)

Example 5 with Gap

use of es.bsc.compss.scheduler.multiobjective.types.Gap in project compss by bsc-wdc.

the class MOResourceScheduler method clear.

@Override
public void clear() {
    super.clear();
    gaps.clear();
    addGap(new Gap(Long.MIN_VALUE, Long.MAX_VALUE, null, myWorker.getDescription().copy(), 0));
}
Also used : Gap(es.bsc.compss.scheduler.multiobjective.types.Gap)

Aggregations

Gap (es.bsc.compss.scheduler.multiobjective.types.Gap)15 AllocatableAction (es.bsc.compss.scheduler.types.AllocatableAction)9 WorkerResourceDescription (es.bsc.compss.types.resources.WorkerResourceDescription)7 ResourceDescription (es.bsc.compss.types.resources.ResourceDescription)6 LinkedList (java.util.LinkedList)4 MOProfile (es.bsc.compss.scheduler.multiobjective.types.MOProfile)3 PriorityQueue (java.util.PriorityQueue)3 MOScore (es.bsc.compss.scheduler.multiobjective.types.MOScore)2 OptimizationAction (es.bsc.compss.scheduler.multiobjective.types.OptimizationAction)2 Implementation (es.bsc.compss.types.implementations.Implementation)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 ActionNotFoundException (es.bsc.compss.scheduler.exceptions.ActionNotFoundException)1 LocalOptimizationState (es.bsc.compss.scheduler.multiobjective.types.LocalOptimizationState)1 SchedulingEvent (es.bsc.compss.scheduler.multiobjective.types.SchedulingEvent)1