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

Revision 477, 2.1 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.Parameters;
8import schedframe.PluginConfiguration;
9import schedframe.events.scheduling.SchedulingEvent;
10import schedframe.resources.units.PEUnit;
11import schedframe.resources.units.ResourceUnit;
12import schedframe.resources.units.ResourceUnitName;
13import schedframe.resources.units.StandardResourceUnitName;
14
15
16/**
17 *
18 * @author Marcin Krystek
19 *
20 */
21public class DefaultTimeEstimationPlugin implements schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin{
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 remaining length (in instructions).
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,
33                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
34                        ExecTask task, 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                double remainingLength =  task.getLength() * (1- completionPercentage);
46                // do the calculation
47                double execTime = (remainingLength / (cnt * speed));
48
49                // if the result is very close to 0, but less then one millisecond then round this result to 0.001
50                if (Double.compare(execTime, 0.001) < 0) {
51                        execTime = 0.001;
52                }
53
54                // time is measured in integer units, so get the nearest execTime int value.
55                execTime = Math.ceil(execTime);
56                return execTime;
57        }
58
59        public PluginConfiguration getConfiguration() {
60                return null;
61        }
62
63        public String getName() {
64                return "ExampleTimeEstimationPlugin";
65        }
66
67        public void init(Parameters parameters) {
68        }
69
70}
Note: See TracBrowser for help on using the repository browser.