source: DCWoRMS/branches/coolemall/src/test/article/recs/utils/TaskToApp.java @ 1173

Revision 1173, 1.8 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article.recs.utils;
2
3import java.util.HashMap;
4import java.util.Map;
5import java.util.Random;
6import java.util.TreeMap;
7
8import schedframe.scheduling.tasks.TaskInterface;
9
10public class TaskToApp {
11       
12        private static int ABINIT = 20;
13        private static int C_RAY = 40;
14        private static int TAR = 60;
15        private static int LIN_3GB = 70;
16        private static int LIN_TINY = 80;
17        private static int FFT = 100;
18        private static Random rand = new Random(5);
19        private static Map<String, AppType> mapping = new TreeMap<String, AppType>();
20
21        private static Random randLoad = new Random(5);
22        private static Map<String, Double> loadMapping = new HashMap<String, Double>();
23        private static double [] loadLevels = {0.25, 0.5, 0.75, 1};
24       
25        public AppType getAppType(TaskInterface<?> task){
26                AppType appType = null;
27                if(mapping.get(task.getJobId())!= null){
28                        appType = mapping.get(task.getJobId());
29                }else{
30                        appType = randomAppType();
31                        mapping.put(task.getJobId(), appType);
32                }return appType;
33        }
34       
35        private AppType randomAppType(){
36                AppType appType = null;
37                int n = rand.nextInt(100);
38                if(n < ABINIT) {
39                        appType = AppType.abinit;
40                }else if(n < C_RAY){
41                        appType = AppType.c_ray;
42                }else if(n < TAR){
43                        appType = AppType.tar;
44                } else if (n < LIN_3GB){
45                        appType = AppType.lin_3gb;
46                } else if (n < LIN_TINY){
47                        appType = AppType.lin_tiny;
48                } else if (n < FFT){
49                        appType = AppType.fft;
50                }
51                return appType;
52        }
53       
54        public double getAppLoad(TaskInterface<?> task){
55                double appLoad = 0;
56                if(loadMapping.get(task.getJobId())!= null){
57                        appLoad = loadMapping.get(task.getJobId());
58                }else{
59                        appLoad = randomAppLoad();
60                        loadMapping.put(task.getJobId(), appLoad);
61                }return appLoad;
62        }
63       
64       
65        private double randomAppLoad(){
66                double appLoad = 0;
67                int n = randLoad.nextInt(7);
68                appLoad = loadLevels[n];
69                return appLoad;
70        }
71       
72}
Note: See TracBrowser for help on using the repository browser.