source: DCWoRMS/trunk/src/example/timeestimation/DefaultTimeEstimationPlugin.java @ 681

Revision 681, 1.9 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.timeestimation;
2
3
4import java.util.Map;
5
6import dcworms.schedframe.scheduling.ExecTask;
7
8import schedframe.events.scheduling.SchedulingEvent;
9import schedframe.resources.units.PEUnit;
10import schedframe.resources.units.ResourceUnit;
11import schedframe.resources.units.ResourceUnitName;
12import schedframe.resources.units.StandardResourceUnitName;
13
14
15/**
16 *
17 * @author Marcin Krystek && Wojciech Piatek
18 *
19 */
20
21public class DefaultTimeEstimationPlugin extends BaseTimeEstimationPlugin{
22
23        /*
24         * This method should return an estimation of time required to execute the task.
25         * Requested calculation should be done based on the resources allocated for the task,
26         * task description and task completion percentage.
27         *
28         * Example implementation calculate the estimation based on cpu processing power.
29         * There is also a simple assumption, that cpu processing power is a linear function
30         * of number of allocated cpus and their speed.
31         */
32        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
33                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
34                        double completionPercentage) {
35               
36                // collect all information necessary to do the calculation
37                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
38
39                // obtain single pe speed
40                int speed = peUnit.getSpeed();
41
42                // number of used pe 
43                int cnt = peUnit.getUsedAmount();
44
45                // estimate remainingTaskLength
46                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
47               
48                // do the calculation
49                double execTime = (remainingLength / (cnt * speed));
50
51                // if the result is very close to 0, but less then one millisecond then round this result to 0.001
52                if (Double.compare(execTime, 0.001) < 0) {
53                        execTime = 0.001;
54                }
55
56                // time is measured in integer units, so get the nearest execTime int value.
57                execTime = Math.round(execTime);
58                return execTime;
59        }
60
61}
Note: See TracBrowser for help on using the repository browser.