use of es.bsc.compss.types.resources.WorkerResourceDescription in project compss by bsc-wdc.
the class MOResourceScheduler method rescheduleTasks.
@SuppressWarnings("unchecked")
public List<Gap> rescheduleTasks(LocalOptimizationState state, PriorityQueue<AllocatableAction> rescheduledActions) {
this.runActionsCost = 0;
this.runActionsEnergy = 0;
for (int coreId = 0; coreId < CoreManager.getCoreCount(); coreId++) {
for (int implId = 0; implId < CoreManager.getNumberCoreImplementations(coreId); implId++) {
MOProfile profile = (MOProfile) this.getProfile(coreId, implId);
runActionsEnergy += profile.getPower() * profile.getExecutionCount() * profile.getAverageExecutionTime();
runActionsCost += profile.getPrice() * profile.getExecutionCount() * profile.getAverageExecutionTime();
}
}
/*
*
* ReadyActions contains those actions that have no dependencies with other actions scheduled on the node, but
* they have data dependencies with tasks on other resources. They are sorted by the expected time when these
* dependencies will be solved.
*
* SelectableActions contains those actions that have no data dependencies with other actions but they wait for
* resources to be released.
*
* Running actions contains a list of Actions that are executing or potentially executing at the moment.
*
* All Actions that need to be rescheduled have the onOptimization and scheduled flags on.
*
* Those actions that are running or could potentially be started ( no dependencies with other actions in the
* resource) are already locked to avoid their start without being on the runningActions set.
*/
Gap gap = state.peekFirstGap();
ResourceDescription gapResource = gap.getResources();
PriorityQueue<SchedulingEvent> schedulingQueue = new PriorityQueue<>();
// For every running action we create a start event on their real start timeStamp
for (AllocatableAction action : state.getRunningActions()) {
manageRunningAction(action, state);
MOSchedulingInformation actionDSI = (MOSchedulingInformation) action.getSchedulingInfo();
schedulingQueue.offer(new SchedulingEvent.End(actionDSI.getExpectedEnd(), action));
}
while (state.areRunnableActions() && !gapResource.isDynamicUseless()) {
AllocatableAction top = state.getMostPrioritaryRunnableAction();
state.replaceAction(top);
if (state.canActionRun()) {
state.removeMostPrioritaryRunnableAction();
// Start the current action
MOSchedulingInformation topDSI = (MOSchedulingInformation) top.getSchedulingInfo();
topDSI.lock();
topDSI.clearPredecessors();
manageRunningAction(top, state);
if (tryToLaunch(top)) {
schedulingQueue.offer(new SchedulingEvent.End(topDSI.getExpectedEnd(), top));
}
} else {
break;
}
}
while (!schedulingQueue.isEmpty() || state.areActionsToBeRescheduled()) {
while (!schedulingQueue.isEmpty()) {
SchedulingEvent e = schedulingQueue.poll();
/*
* Start Event: - sets the expected start and end times - adds resource dependencies with the previous
* actions - if there's a gap before the dependency -tries to fill it with other tasks - if all the
* resources released by the predecessor are used later - the action is unlocked
*
* End Event:
*
*/
List<SchedulingEvent> result = e.process(state, (MOResourceScheduler<WorkerResourceDescription>) this, rescheduledActions);
for (SchedulingEvent r : result) {
schedulingQueue.offer(r);
}
}
if (state.areActionsToBeRescheduled()) {
AllocatableAction topAction = state.getEarliestActionToBeRescheduled();
MOSchedulingInformation topActionDSI = (MOSchedulingInformation) topAction.getSchedulingInfo();
topActionDSI.lock();
topActionDSI.setToReschedule(false);
schedulingQueue.offer(new SchedulingEvent.Start(topActionDSI.getExpectedStart(), topAction));
}
}
for (Gap g : state.getGaps()) {
state.removeTmpGap(g);
}
this.pendingActionsCost = state.getTotalCost();
this.pendingActionsEnergy = state.getTotalEnergy();
this.implementationsCount = state.getImplementationsCount();
this.expectedEndTimeRunning = state.getEndRunningTime();
this.runningImplementationsCount = state.getRunningImplementations();
this.runningActionsEnergy = state.getRunningEnergy();
this.runningActionsCost = state.getRunningCost();
this.resourceBlockingAction = state.getResourceBlockingAction();
this.dataBlockingAction = state.getDataBlockingAction();
return state.getGaps();
}
use of es.bsc.compss.types.resources.WorkerResourceDescription in project compss by bsc-wdc.
the class ReduceWorkerAction method doAction.
@Override
protected void doAction() {
(new Thread() {
@SuppressWarnings("unchecked")
@Override
public void run() {
Thread.currentThread().setName(worker.getName() + " stopper");
CloudMethodWorker w = (CloudMethodWorker) worker.getResource();
PendingReduction<WorkerResourceDescription> crd = (PendingReduction<WorkerResourceDescription>) ru;
ResourceManager.reduceResource(w, crd);
w.endTask((MethodResourceDescription) getResourceConsumption());
try {
ru.waitForCompletion();
} catch (Exception e) {
LOGGER.error("ERROR: Exception raised on worker reduction", e);
ErrorManager.warn("Exception reducing worker. Check runtime.log for more details", e);
notifyError();
}
notifyCompleted();
}
}).start();
}
use of es.bsc.compss.types.resources.WorkerResourceDescription 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.types.resources.WorkerResourceDescription in project compss by bsc-wdc.
the class Action method findAvailableWorkers.
@SuppressWarnings("unchecked")
public Map<Worker<?>, List<Implementation>> findAvailableWorkers() {
Map<Worker<?>, List<Implementation>> m = new HashMap<>();
List<ResourceScheduler<? extends WorkerResourceDescription>> compatibleWorkers = getCoreElementExecutors(coreId);
for (ResourceScheduler<? extends WorkerResourceDescription> ui : compatibleWorkers) {
Worker<WorkerResourceDescription> r = (Worker<WorkerResourceDescription>) ui.getResource();
List<Implementation> compatibleImpls = r.getExecutableImpls(coreId);
List<Implementation> runnableImpls = new LinkedList<>();
for (Implementation impl : compatibleImpls) {
if (r.canRunNow(impl.getRequirements())) {
runnableImpls.add(impl);
}
}
if (runnableImpls.size() > 0) {
m.put((Worker<?>) r, runnableImpls);
}
}
return m;
}
use of es.bsc.compss.types.resources.WorkerResourceDescription in project compss by bsc-wdc.
the class TestAvailable method availableResourcesTest.
/*
* ********************************************************************************************************
* AVAILABLE RESOURCES TEST IMPLEMENTATION
* ********************************************************************************************************
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void availableResourcesTest() {
// Get CoreCount
coreCount = CoreManager.getCoreCount();
// Loading Core names from the interface
idToSignatures = new LinkedList[coreCount];
for (int coreId = 0; coreId < coreCount; coreId++) {
idToSignatures[coreId] = new LinkedList<String>();
}
for (Entry<String, Integer> entry : CoreManager.getSignaturesToId().entrySet()) {
String signature = entry.getKey();
Integer coreId = entry.getValue();
idToSignatures[coreId].add(signature);
}
// Search for the specific CoreElement ids
boolean found_ce1 = false;
boolean found_ce2 = false;
int ce1 = 0;
int ce2 = 0;
coreToName = new String[coreCount];
for (int i = 0; i < coreCount; i++) {
int cutValue = idToSignatures[i].getFirst().indexOf("(");
coreToName[i] = idToSignatures[i].getFirst().substring(0, cutValue);
if (coreToName[i].equals(NAME_CORE_ELEMENT_1)) {
ce1 = i;
found_ce1 = true;
}
if (coreToName[i].equals(NAME_CORE_ELEMENT_2)) {
ce2 = i;
found_ce2 = true;
}
}
// Check results
if (!found_ce1) {
System.out.println("[ERROR] " + NAME_CORE_ELEMENT_1 + " not found.");
System.exit(-1);
}
if (!found_ce2) {
System.out.println("[ERROR] " + NAME_CORE_ELEMENT_2 + " not found.");
System.exit(-1);
}
/*
* ********************************************************************************************************
* Reserve and free for computingUnits test
* ********************************************************************************************************
*/
Worker worker = ResourceManager.getWorker(NAME_WORKER);
System.out.println("Worker " + NAME_WORKER + ": " + worker.getDescription());
System.out.println("Implementation 1: " + CoreManager.getCoreImplementations(ce1).get(0));
WorkerResourceDescription consumed1 = worker.runTask(CoreManager.getCoreImplementations(ce1).get(0).getRequirements());
WorkerResourceDescription consumed2 = worker.runTask(CoreManager.getCoreImplementations(ce1).get(0).getRequirements());
System.out.println("CONSUMED: " + consumed1);
System.out.println("CONSUMED: " + consumed2);
// System.out.println("REMAINING: " + ((MethodWorker)worker).getAvailable());
ActionOrchestrator orchestrator = COMPSsRuntimeImpl.getOrchestrator();
Action a = new Action(orchestrator, ce1);
if (a.findAvailableWorkers().containsKey(worker)) {
System.out.println("[ERROR] Available resources for CORE reserve is not working");
System.exit(-1);
}
worker.endTask(consumed1);
if (!a.findAvailableWorkers().containsKey(worker)) {
System.out.println("[ERROR] Available resources for CORE free is not working");
System.exit(-1);
}
worker.endTask(consumed2);
// System.out.println("FREE");
// System.out.println("FREE");
// System.out.println("TOTAL: " + ((MethodWorker)worker).getAvailable());
// System.out.println();
/*
* ********************************************************************************************************
* Reserve and free for memorySize test
* ********************************************************************************************************
*/
a = new Action(orchestrator, ce2);
// System.out.println("Worker " + NAME_WORKER + ": " + worker.getDescription());
// System.out.println("Implementation 1: " + CoreManager.getCoreImplementations(ce2)[0]);
consumed1 = worker.runTask(CoreManager.getCoreImplementations(ce2).get(0).getRequirements());
consumed2 = worker.runTask(CoreManager.getCoreImplementations(ce2).get(0).getRequirements());
// System.out.println("REMAINING: " + ((MethodWorker)worker).getAvailable());
if (a.findAvailableWorkers().containsKey(worker)) {
System.out.println("[ERROR] Available resources for MEMORY reserve is not working");
System.exit(-1);
}
worker.endTask(consumed1);
if (!a.findAvailableWorkers().containsKey(worker)) {
System.out.println("[ERROR] Available resources for MEMORY free is not working");
System.exit(-1);
}
worker.endTask(consumed2);
// System.out.println("FREE");
// System.out.println("FREE");
// System.out.println("TOTAL: " + ((MethodWorker)worker).getAvailable());
// System.out.println();
System.out.println("[LOG] * Available Resources test passed");
}
Aggregations