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

Revision 1197, 2.0 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 dcworms.schedframe.scheduling.Executable;
9
10import schedframe.scheduling.tasks.TaskInterface;
11
12public class TaskToApp {
13       
14        private static int ABINIT = 20;
15        private static int C_RAY = 40;
16        private static int TAR = 60;
17        private static int LIN_3GB = 70;
18        private static int LIN_TINY = 80;
19        private static int FFT = 100;
20        private static Random rand = new Random(5);
21        private static Map<String, AppType> mapping = new TreeMap<String, AppType>();
22
23        private static Random randLoad = new Random(5);
24        private static Map<String, Double> loadMapping = new HashMap<String, Double>();
25        private static double [] loadLevels = {0.25, 0.5, 0.75, 1};
26       
27        public AppType getAppType(TaskInterface<?> task){
28
29                AppType appType = null;
30                if(mapping.get(task.getJobId())!= null){
31                        appType = mapping.get(task.getJobId());
32                        Executable exec = (Executable) task;
33                        exec.getDescription().getExecution().getExecutable().getApplication().setName(appType.toString());
34                }else{
35                        appType = randomAppType();
36                        mapping.put(task.getJobId(), appType);
37                }
38                return appType;
39        }
40       
41        private AppType randomAppType(){
42                AppType appType = null;
43                int n = rand.nextInt(100);
44                if(n < ABINIT){
45                        appType = AppType.abinit;
46                }else if(n < C_RAY){
47                        appType = AppType.c_ray;
48                }else if(n < TAR){
49                        appType = AppType.tar;
50                }else if(n < LIN_3GB){
51                        appType = AppType.lin_3gb;
52                }else if(n < LIN_TINY){
53                        appType = AppType.lin_tiny;
54                }else if(n < FFT){
55                        appType = AppType.fft;
56                }
57                return appType;
58        }
59       
60        public double getAppLoad(TaskInterface<?> task){
61                double appLoad = 0;
62                if(loadMapping.get(task.getJobId())!= null){
63                        appLoad = loadMapping.get(task.getJobId());
64                }else{
65                        appLoad = randomAppLoad();
66                        loadMapping.put(task.getJobId(), appLoad);
67                }return appLoad;
68        }
69       
70        private double randomAppLoad(){
71                double appLoad = 0;
72                int n = randLoad.nextInt(7);
73                appLoad = loadLevels[n];
74                return appLoad;
75        }
76       
77}
Note: See TracBrowser for help on using the repository browser.