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

Revision 539, 1.8 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
RevLine 
[477]1package example.timeestimation;
2
3
4import java.util.Map;
5
[539]6import dcworms.schedframe.scheduling.ExecTask;
7
[477]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 *
[539]17 * @author Marcin Krystek && Wojciech Piatek
[477]18 *
19 */
20
[539]21public class DefaultTimeEstimationPlugin extends BaseTimeEstimationPlugin{
22
[477]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,
[539]26         * task description and task completion percentage.
[477]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         */
[539]32        public double execTimeEstimation(SchedulingEvent event, ExecTask task,
[477]33                        Map<ResourceUnitName, ResourceUnit> allocatedResources,
[539]34                        double completionPercentage) {
[477]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
[539]45                // estimate remainingTaskLength
46                double remainingLength =  task.getLength() * (1 - completionPercentage/100);
47               
[477]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.ceil(execTime);
58                return execTime;
59        }
60
61}
Note: See TracBrowser for help on using the repository browser.