[894] | 1 | #!/usr/bin/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 | for xsize, ysize in ((3, 3), (4, 4), (4, 8), (8, 8), (8, 16), (16, 16)): |
---|
| 84 | # -------------------------------------------------------------------- |
---|
| 85 | # simulation without faults |
---|
| 86 | # -------------------------------------------------------------------- |
---|
| 87 | cfgname = 'output_{0}_{1}'.format(xsize, ysize) |
---|
| 88 | args = RunArguments(cfgname, xsize, ysize) |
---|
| 89 | onerun.run(args) |
---|
| 90 | |
---|
| 91 | for pct in (10, 20, 30, 40, 50, 60): |
---|
| 92 | # -------------------------------------------------------------------- |
---|
| 93 | # simulation with random faulty cores |
---|
| 94 | # -------------------------------------------------------------------- |
---|
| 95 | cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 96 | args = RunArguments(cfgname, xsize, ysize) |
---|
| 97 | |
---|
| 98 | faultycount = args.get_faultycorecount(pct) |
---|
| 99 | print "{0}/{1} faulty cores\n".\ |
---|
| 100 | format(faultycount, args.get_totalcores()) |
---|
| 101 | |
---|
| 102 | n = 0 |
---|
| 103 | while n < faultycount: |
---|
| 104 | cx = random.randint(0, args.xmax) |
---|
| 105 | cy = random.randint(0, args.ymax) |
---|
| 106 | cl = random.randint(0, args.pmax) |
---|
| 107 | if args.add_faultycore((cx, cy, cl)): n += 1 |
---|
| 108 | |
---|
| 109 | onerun.run(args) |
---|
| 110 | |
---|
| 111 | # -------------------------------------------------------------------- |
---|
| 112 | # simulation with random faulty routers |
---|
| 113 | # -------------------------------------------------------------------- |
---|
| 114 | cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 115 | args = RunArguments(cfgname, xsize, ysize) |
---|
| 116 | |
---|
| 117 | faultycount = args.get_faultyroutercount(pct) |
---|
| 118 | print "{0}/{1} faulty routers\n".\ |
---|
| 119 | format(faultycount, args.get_totalclusters()) |
---|
| 120 | |
---|
| 121 | n = 0 |
---|
| 122 | while n < faultycount: |
---|
| 123 | cx = random.randint(0, args.xmax) |
---|
| 124 | cy = random.randint(0, args.ymax) |
---|
| 125 | if args.add_faultyrouter((cx, cy)): n += 1 |
---|
| 126 | |
---|
| 127 | onerun.run(args) |
---|
| 128 | |
---|
| 129 | # -------------------------------------------------------------------- |
---|
| 130 | # simulation with random faulty routers and cores |
---|
| 131 | # -------------------------------------------------------------------- |
---|
| 132 | cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 133 | args = RunArguments(cfgname, xsize, ysize) |
---|
| 134 | |
---|
| 135 | total = args.get_totalclusters() + args.get_totalcores() |
---|
| 136 | faultycount = args.get_faultycount(total, pct) |
---|
| 137 | print "{0}/{1} faulty routers/cores\n".\ |
---|
| 138 | format(faultycount, total) |
---|
| 139 | |
---|
| 140 | n = 0 |
---|
| 141 | while n < faultycount: |
---|
| 142 | cx = random.randint(0, args.xmax) |
---|
| 143 | cy = random.randint(0, args.ymax) |
---|
| 144 | if (random.random() < 0.05): # faulty router: 5% of probability |
---|
| 145 | if not args.add_faultyrouter((cx, cy)): |
---|
| 146 | continue |
---|
| 147 | |
---|
| 148 | else: # faulty core: 95% of probability |
---|
| 149 | cl = random.randint(0, args.pmax) |
---|
| 150 | if not args.add_faultycore((cx, cy, cl)): |
---|
| 151 | continue |
---|
| 152 | |
---|
| 153 | n += 1 |
---|
| 154 | |
---|
| 155 | onerun.run(args) |
---|
| 156 | |
---|