1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import onerun |
---|
4 | import os |
---|
5 | import random |
---|
6 | from math import ceil |
---|
7 | from sys import exit |
---|
8 | |
---|
9 | class RunArguments: |
---|
10 | def __init__(self, name, x, y): |
---|
11 | self.path = os.getcwd() |
---|
12 | self.outpath = name |
---|
13 | self.x = x |
---|
14 | self.y = y |
---|
15 | self.nprocs = 4 |
---|
16 | self.compileonly = False |
---|
17 | self.batchmode = True |
---|
18 | self.faultyrouter = [] |
---|
19 | self.faultymask = 0xF |
---|
20 | self.faultycore = [] |
---|
21 | self.debug = None |
---|
22 | |
---|
23 | self.xmax = self.x - 1 |
---|
24 | self.ymax = self.y - 1 |
---|
25 | self.pmax = self.nprocs - 1 |
---|
26 | |
---|
27 | # init random number generator |
---|
28 | random.seed() |
---|
29 | |
---|
30 | def add_faultyrouter(self, x): |
---|
31 | if x in self.faultyrouter: |
---|
32 | return False |
---|
33 | |
---|
34 | self.faultyrouter.append(x) |
---|
35 | return True |
---|
36 | |
---|
37 | def add_faultycore(self, x): |
---|
38 | if x in self.faultycore: |
---|
39 | return False |
---|
40 | |
---|
41 | self.faultycore.append(x) |
---|
42 | return True |
---|
43 | |
---|
44 | def init_faultyrouter(self, x): |
---|
45 | if x == None: return |
---|
46 | self.faultyrouter = x |
---|
47 | |
---|
48 | def init_faultycore(self, x): |
---|
49 | if x == None: return |
---|
50 | self.faultycore = x |
---|
51 | |
---|
52 | def get_faultycount(self, total, pct): |
---|
53 | """ |
---|
54 | Returns the number of faulty elements in a population |
---|
55 | Arguments: |
---|
56 | total -- Total number of elements |
---|
57 | pct -- Percentage of faulty elements |
---|
58 | """ |
---|
59 | return int(ceil(total * float(pct)/100)) |
---|
60 | |
---|
61 | def get_faultycorecount(self, pct): |
---|
62 | """ |
---|
63 | Returns the number of faulty cores in the platform |
---|
64 | Arguments: |
---|
65 | pct -- Percentage of faulty cores |
---|
66 | """ |
---|
67 | return self.get_faultycount(self.get_totalcores(), pct) |
---|
68 | |
---|
69 | def get_faultyroutercount(self, pct): |
---|
70 | """ |
---|
71 | Returns the number of faulty routers in the platform |
---|
72 | Arguments: |
---|
73 | pct -- Percentage of faulty routers |
---|
74 | """ |
---|
75 | return self.get_faultycount(self.get_totalclusters(), pct) |
---|
76 | |
---|
77 | def get_totalclusters(self): |
---|
78 | return self.x * self.y |
---|
79 | |
---|
80 | def get_totalcores(self): |
---|
81 | return self.get_totalclusters() * self.nprocs |
---|
82 | |
---|
83 | # activate the different kinds of simulation |
---|
84 | SIM_FAULTFREE = False |
---|
85 | SIM_FAULTCORES = False |
---|
86 | SIM_FAULTROUTERS = False |
---|
87 | SIM_FAULTMIXED = True |
---|
88 | |
---|
89 | # probability of faulty router (for mixed simul) |
---|
90 | SIM_FAULTMIXED_PROBROUTER = 0.05 # 5% |
---|
91 | |
---|
92 | for xsize, ysize in [(4, 4), (4, 8), (8, 8), (8, 16), (16, 16)]: |
---|
93 | if SIM_FAULTFREE: |
---|
94 | # --------------------------------------------------------------------- |
---|
95 | # simulation without faults |
---|
96 | # --------------------------------------------------------------------- |
---|
97 | cfgname = 'output_{0}_{1}'.format(xsize, ysize) |
---|
98 | args = RunArguments(cfgname, xsize, ysize) |
---|
99 | onerun.run(args) |
---|
100 | |
---|
101 | for pct in xrange(5, 60, 5): # 5, 10, ..., 55 |
---|
102 | if SIM_FAULTCORES: |
---|
103 | # ----------------------------------------------------------------- |
---|
104 | # simulation with random faulty cores |
---|
105 | # ----------------------------------------------------------------- |
---|
106 | cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
107 | args = RunArguments(cfgname, xsize, ysize) |
---|
108 | |
---|
109 | faultycount = args.get_faultycorecount(pct) |
---|
110 | print "{0}/{1} faulty cores\n".\ |
---|
111 | format(faultycount, args.get_totalcores()) |
---|
112 | |
---|
113 | n = 0 |
---|
114 | while n < faultycount: |
---|
115 | cx = random.randint(0, args.xmax) |
---|
116 | cy = random.randint(0, args.ymax) |
---|
117 | cl = random.randint(0, args.pmax) |
---|
118 | if args.add_faultycore((cx, cy, cl)): n += 1 |
---|
119 | |
---|
120 | onerun.run(args) |
---|
121 | |
---|
122 | if SIM_FAULTROUTERS: |
---|
123 | # ----------------------------------------------------------------- |
---|
124 | # simulation with random faulty routers |
---|
125 | # ----------------------------------------------------------------- |
---|
126 | cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
127 | args = RunArguments(cfgname, xsize, ysize) |
---|
128 | |
---|
129 | faultycount = args.get_faultyroutercount(pct) |
---|
130 | print "{0}/{1} faulty routers\n".\ |
---|
131 | format(faultycount, args.get_totalclusters()) |
---|
132 | |
---|
133 | n = 0 |
---|
134 | while n < faultycount: |
---|
135 | cx = random.randint(0, args.xmax) |
---|
136 | cy = random.randint(0, args.ymax) |
---|
137 | if args.add_faultyrouter((cx, cy)): n += 1 |
---|
138 | |
---|
139 | onerun.run(args) |
---|
140 | |
---|
141 | if SIM_FAULTMIXED: |
---|
142 | # ----------------------------------------------------------------- |
---|
143 | # simulation with random faulty routers and cores |
---|
144 | # ----------------------------------------------------------------- |
---|
145 | cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
146 | args = RunArguments(cfgname, xsize, ysize) |
---|
147 | |
---|
148 | total = args.get_totalclusters() + args.get_totalcores() |
---|
149 | faultycount = args.get_faultycount(total, pct) |
---|
150 | |
---|
151 | print "\nprobability of faulty routers: {0}".\ |
---|
152 | format(SIM_FAULTMIXED_PROBROUTER) |
---|
153 | fr = 0 |
---|
154 | fc = 0 |
---|
155 | while (fr + fc) < faultycount: |
---|
156 | cx = random.randint(0, args.xmax) |
---|
157 | cy = random.randint(0, args.ymax) |
---|
158 | if (random.random() < SIM_FAULTMIXED_PROBROUTER): |
---|
159 | # add faulty router |
---|
160 | fr += 1 |
---|
161 | while not args.add_faultyrouter((cx, cy)): |
---|
162 | cx = random.randint(0, args.xmax) |
---|
163 | cy = random.randint(0, args.ymax) |
---|
164 | |
---|
165 | else: |
---|
166 | # add faulty core |
---|
167 | fc += 1 |
---|
168 | cl = random.randint(0, args.pmax) |
---|
169 | while not args.add_faultycore((cx, cy, cl)): |
---|
170 | cx = random.randint(0, args.xmax) |
---|
171 | cy = random.randint(0, args.ymax) |
---|
172 | cl = random.randint(0, args.pmax) |
---|
173 | |
---|
174 | print "faulty routers / faulty cores = {0} / {1}".format(fr, fc) |
---|
175 | onerun.run(args) |
---|
176 | |
---|
177 | # vim: ts=4 : sts=4 : sw=4 : et |
---|