Commit 07358b1b authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

Optimization in DP2: loop unrolling. About 2-3x speedup

parent 2510dd0e
......@@ -49,19 +49,48 @@ double IndepDP2::tryGuess(Instance& instance, std::vector<int> taskSet, double m
for(int i = 0; i <= N; i++)
CPUload[index][i] = 0;
for(int t : taskSet) {
int taskType = instance.taskTypes[t];
int taskType = instance.taskTypes[t];
int nextIndex = getResult ? index+1: index;
for(int l = N; l >= 0; l--) {
if(instance.execTimes[0][taskType] > maxlen && instance.execTimes[1][taskType] > maxlen)
return -1; // Problem is not feasible: task t cannot be placed on any resource
double newLoad = std::numeric_limits<double>::infinity();
if(instance.execTimes[0][taskType] <= maxlen)
newLoad = CPUload[index][l] + instance.execTimes[0][taskType];
if((instance.execTimes[1][taskType] <= maxlen) && (discreteGPUtimings[taskType] <= l))
newLoad = min(newLoad, CPUload[index][l - discreteGPUtimings[taskType]]);
CPUload[nextIndex][l] = newLoad;
double exec0 = instance.execTimes[0][taskType];
double exec1 = instance.execTimes[1][taskType];
int discreteGPUtime = discreteGPUtimings[taskType];
// Possible optimization if needed: run this test for all
// taskTypes (which appear in the taskSet) instead of for all
// tasks
if(exec0 > maxlen && exec1 > maxlen)
return -1; // Problem is not feasible: task t cannot be placed on any resource
if((exec0 <= maxlen) && (exec1 <= maxlen)) {
for(int l = N; l >= discreteGPUtime; --l) {
CPUload[nextIndex][l] = min(CPUload[index][l] + exec0, CPUload[index][l - discreteGPUtime]);
}
for(int l = discreteGPUtime - 1; l >= 0; --l) {
CPUload[nextIndex][l] = CPUload[index][l] + exec0;
}
} else if ((exec0 <= maxlen) && (exec1 > maxlen)) {
for(int l = N; l >= 0; --l) {
CPUload[nextIndex][l] = CPUload[index][l] + exec0;
}
} else /* ((exec0 > maxlen) && (exec1 <= maxlen)) */ {
for(int l = N; l >= discreteGPUtime; --l) {
CPUload[nextIndex][l] = CPUload[index][l - discreteGPUtime];
}
for(int l = discreteGPUtime - 1; l >= 0; l--) {
CPUload[nextIndex][l] = std::numeric_limits<double>::infinity();
}
}
if(getResult) index++;
// for(int l = N; l >= 0; l--) {
// double newLoad = std::numeric_limits<double>::infinity();
// if( <= maxlen)
// newLoad = CPUload[index][l] + instance.execTimes[0][taskType];
// if((instance.execTimes[1][taskType] <= maxlen) && (discreteGPUtimings[taskType] <= l))
// newLoad = min(newLoad, CPUload[index][l - discreteGPUtimings[taskType]]);
// CPUload[nextIndex][l] = newLoad;
// }
index = nextIndex;
}
double value = CPUload[index][N];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment