use of es.bsc.compss.types.resources.ResourceDescription 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;
}
use of es.bsc.compss.types.resources.ResourceDescription in project compss by bsc-wdc.
the class FullGraphResourceScheduler method scheduleUsingGaps.
private void scheduleUsingGaps(AllocatableAction<P, T, I> action, LinkedList<Gap<P, T, I>> gaps) {
long expectedStart = 0;
// Compute start time due to data dependencies
for (AllocatableAction<P, T, I> predecessor : action.getDataPredecessors()) {
FullGraphSchedulingInformation<P, T, I> predDSI = ((FullGraphSchedulingInformation<P, T, I>) predecessor.getSchedulingInfo());
if (predDSI.isScheduled()) {
long predEnd = predDSI.getExpectedEnd();
expectedStart = Math.max(expectedStart, predEnd);
}
}
FullGraphSchedulingInformation<P, T, I> schedInfo = (FullGraphSchedulingInformation<P, T, I>) action.getSchedulingInfo();
I impl = action.getAssignedImplementation();
Profile p = getProfile(impl);
ResourceDescription constraints = impl.getRequirements().copy();
LinkedList<AllocatableAction<P, T, I>> predecessors = new LinkedList<>();
Iterator<Gap<P, T, I>> gapIt = gaps.descendingIterator();
boolean fullyCoveredReqs = false;
// Check gaps before data start
while (gapIt.hasNext() && !fullyCoveredReqs) {
Gap<P, T, I> gap = gapIt.next();
if (gap.getInitialTime() <= expectedStart) {
AllocatableAction<P, T, I> predecessor = (AllocatableAction<P, T, I>) gap.getOrigin();
if (predecessor != null) {
FullGraphSchedulingInformation<P, T, I> predDSI = ((FullGraphSchedulingInformation<P, T, I>) predecessor.getSchedulingInfo());
predDSI.lock();
predecessors.add(predecessor);
}
ResourceDescription gapResource = gap.getResources();
ResourceDescription.reduceCommonDynamics(gapResource, constraints);
if (gapResource.isDynamicUseless()) {
gapIt.remove();
}
if (constraints.isDynamicUseless()) {
fullyCoveredReqs = true;
}
}
}
// Check gaps after data start
gapIt = gaps.iterator();
while (gapIt.hasNext() && !fullyCoveredReqs) {
Gap<P, T, I> gap = gapIt.next();
AllocatableAction<P, T, I> predecessor = (AllocatableAction<P, T, I>) gap.getOrigin();
if (predecessor != null) {
FullGraphSchedulingInformation<P, T, I> predDSI = ((FullGraphSchedulingInformation<P, T, I>) predecessor.getSchedulingInfo());
predDSI.lock();
predecessors.add(predecessor);
}
ResourceDescription gapResource = gap.getResources();
ResourceDescription.reduceCommonDynamics(gapResource, constraints);
if (gapResource.isDynamicUseless()) {
gapIt.remove();
}
if (constraints.isDynamicUseless()) {
fullyCoveredReqs = true;
}
}
// Lock acces to the current task
schedInfo.lock();
schedInfo.scheduled();
// Unlock access to predecessor
for (AllocatableAction<P, T, I> predecessor : predecessors) {
FullGraphSchedulingInformation<P, T, I> predDSI = ((FullGraphSchedulingInformation<P, T, I>) predecessor.getSchedulingInfo());
if (predDSI.isScheduled()) {
long predEnd = predDSI.getExpectedEnd();
expectedStart = Math.max(expectedStart, predEnd);
schedInfo.addPredecessor(predecessor);
predDSI.addSuccessor(action);
}
predDSI.unlock();
}
// Compute end time
schedInfo.setExpectedStart(expectedStart);
long expectedEnd = expectedStart;
if (p != null) {
expectedEnd += p.getAverageExecutionTime();
}
schedInfo.setExpectedEnd(expectedEnd);
// Unlock access to current task
schedInfo.unlock();
// Create new Gap correspondin to the resources released by the action
addGap(new Gap<P, T, I>(expectedEnd, Long.MAX_VALUE, action, impl.getRequirements().copy(), 0));
}
use of es.bsc.compss.types.resources.ResourceDescription in project compss by bsc-wdc.
the class LocalOptimizationState method reserveResources.
public LinkedList<Gap<P, T, I>> reserveResources(ResourceDescription resources, long startTime) {
LinkedList<Gap<P, T, I>> previousGaps = new LinkedList<>();
// Remove requirements from resource description
ResourceDescription requirements = resources.copy();
Iterator<Gap<P, T, I>> gapIt = gaps.iterator();
while (gapIt.hasNext() && !requirements.isDynamicUseless()) {
Gap<P, T, I> g = gapIt.next();
if (checkGapForReserve(g, requirements, startTime, previousGaps)) {
gapIt.remove();
}
}
return previousGaps;
}
use of es.bsc.compss.types.resources.ResourceDescription in project compss by bsc-wdc.
the class MOResourceScheduler method addGap.
private void addGap(Gap g) {
AllocatableAction gapAction = g.getOrigin();
ResourceDescription releasedResources = g.getResources();
boolean merged = false;
for (Gap registeredGap : gaps) {
if (registeredGap.getOrigin() == gapAction) {
ResourceDescription registeredResources = registeredGap.getResources();
registeredResources.increaseDynamic(releasedResources);
merged = true;
break;
}
}
if (!merged) {
Iterator<Gap> gapIt = gaps.iterator();
int index = 0;
Gap gap;
while (gapIt.hasNext() && (gap = gapIt.next()) != null && gap.getInitialTime() <= g.getInitialTime()) {
index++;
}
gaps.add(index, g);
}
}
use of es.bsc.compss.types.resources.ResourceDescription in project compss by bsc-wdc.
the class LocalOptimizationState method replaceAction.
public void replaceAction(AllocatableAction action) {
this.action = action;
if (this.action != null) {
missingResources = this.action.getAssignedImplementation().getRequirements().copy();
// Check if the new peek can run in the already freed resources.
for (Gap gap : gaps) {
ResourceDescription empty = gap.getResources().copy();
topStartTime = gap.getInitialTime();
ResourceDescription.reduceCommonDynamics(empty, missingResources);
if (missingResources.isDynamicUseless()) {
break;
}
}
} else {
missingResources = null;
topStartTime = 0l;
}
}
Aggregations