-
Notifications
You must be signed in to change notification settings - Fork 0
/
tema1.py
72 lines (50 loc) · 1.57 KB
/
tema1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def tiempo_cpu(numero_ins, clocks_por_ins, tiempo_ciclo):
return numero_ins * clocks_por_ins * tiempo_ciclo
def mejora(tiempo_x, tiempo_y):
return tiempo_y / tiempo_x
def mips(numero_ins, tiempo):
return numero_ins / (tiempo * 1000000)
def mflops(numero_ins_fp, tiempo):
return mips(numero_ins_fp, tiempo)
def amdahl(enhancement_tuples):
mejora = []
no_mejora = []
done = []
# Distinguimos si mejora o no
for e in enhancement_tuples:
nombre, porcentaje, bef, aft = e
if bef == aft:
no_mejora.append(e)
else:
mejora.append(e)
# Por cada instrucion
ag = 1
for e in mejora:
nombre, porcentaje, bef, aft = e
am = bef/aft
tot = 0
print("\t")
for e in enhancement_tuples:
nombre2, porcentaje2, bef2, aft2 = e
if nombre2 in done:
print("({} * {}) + ".format(porcentaje2, aft2), end='')
tot += porcentaje2 * aft2
else:
print("({} * {}) + ".format(porcentaje2, bef2), end='')
tot += porcentaje2 * bef2
print()
fm = (porcentaje * bef) / tot
agtmp = 1 / ((1-fm) + (fm/am))
ag *= agtmp
print("{}, AG={:f}, FM={:f}, AM={:f}".format(nombre, agtmp, fm, am))
done.append(nombre)
return ag
def main():
speedup = amdahl([
("SCF", 15/100, 40, 2),
("MCF", 10/100, 60, 15),
("DCF", 5/100, 100, 10),
("INT", 70/100, 2, 2)])
print(speedup)
if __name__ == "__main__":
main()