Search in sources :

Example 1 with OptimizationAction

use of es.bsc.compss.scheduler.multiobjective.types.OptimizationAction 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 2 with OptimizationAction

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

Aggregations

Gap (es.bsc.compss.scheduler.multiobjective.types.Gap)2 OptimizationAction (es.bsc.compss.scheduler.multiobjective.types.OptimizationAction)2 AllocatableAction (es.bsc.compss.scheduler.types.AllocatableAction)2 WorkerResourceDescription (es.bsc.compss.types.resources.WorkerResourceDescription)2 LinkedList (java.util.LinkedList)2 ActionNotFoundException (es.bsc.compss.scheduler.exceptions.ActionNotFoundException)1 LocalOptimizationState (es.bsc.compss.scheduler.multiobjective.types.LocalOptimizationState)1 MOProfile (es.bsc.compss.scheduler.multiobjective.types.MOProfile)1 Implementation (es.bsc.compss.types.implementations.Implementation)1 ResourceDescription (es.bsc.compss.types.resources.ResourceDescription)1 PriorityQueue (java.util.PriorityQueue)1