source: DCWoRMS/branches/coolemall/src/test/PhaseTimeEstimationPlugin.java @ 896

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