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

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