-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
131 lines (101 loc) · 4.64 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Copyright (c) 2023 VISTEC - Vidyasirimedhi Institute of Science and Technology
# Distribute under MIT License
# Authors:
# - Sucha Supittayapornpong <sucha.s[-at-]vistec.ac.th>
# - Kanatip Chitavisutthivong <kanatip.c_s18[-at-]vistec.ac.th>
import os
import multiprocessing as mp
import platform
from functools import partial
import network_generator as netgen
from topology_automorphism import Topology
import state_helper as helper
from state_helper import HCONST, initHCONST
from optimization import Optimization
from verification import Verification
from solution_grouping import SolutionGrouping
from bcube_routing import BCubeRouting
from slimfly_routing import SlimFlyRouting
ProcessorCount = mp.cpu_count()
NumThread = ProcessorCount
NumLPThread = ProcessorCount
if platform.system() == 'Darwin':
mp.set_start_method("fork") # Workaround for mac
TOPOLOGY = {'BCube': partial(netgen.generateBCube),
'MixedNodes': partial(netgen.generateMixedNodes),
'SlimFly': partial(netgen.loadSlimFly),
'AbstractAugmentExpander': partial(netgen.generateAbstractAugmentExpander),
'FatTreePartial': partial(netgen.generateFatTreePartial),
'Torus2D': partial(netgen.generateTorus2D),
'FatClique': partial(netgen.generateFatClique),
'2LevelClos': partial(netgen.generate2LevelClos),
'Clique': partial(netgen.generateClique),
'BinaryCube': partial(netgen.generateBinaryCube),
'DRing': partial(netgen.generateDRing),
'Torus3D': partial(netgen.generateTorus3D),
'Grid3D': partial(netgen.generateGrid3D),
'Grid2D': partial(netgen.generateGrid2D),
'Ring': partial(netgen.generateRing),
}
def process(G, toponame, verify, group_solution):
rootdir = '.'
initHCONST(rootdir, toponame)
helper.makePrecomputationDirectory()
helper.makeOutputDirectory()
topo = Topology(G, toponame, NumThread)
opt = Optimization(topo, NumLPThread)
opt.optimize()
if verify == True:
ver = Verification(toponame, NumThread)
ver.verifyAllLinkLoad()
if group_solution == True:
grp = SolutionGrouping(rootdir, toponame, NumThread)
grp.groupSolution()
def run_example(topology, topo_params, verify=True, group_solution=True):
if topology in TOPOLOGY.keys():
if topology == 'BCube':
G, toponame, mappingAddrToBaddr, mappingBaddrToAddr = TOPOLOGY[topology](topo_params)
else:
G, toponame = TOPOLOGY[topology](topo_params)
process(G, toponame, verify, group_solution)
else:
print('There is no specified topology in this example.')
def process_SlimflyVAL(G, toponame, verify):
rootdir = '.'
initHCONST(rootdir, toponame)
helper.makePrecomputationDirectory()
helper.makeOutputDirectory()
topo = Topology(G, toponame, NumThread)
sfRouting = SlimFlyRouting(topo, NumThread)
if verify == True:
sfRouting.verifyAllLinkLoad(NumThread)
def run_SlimflyVAL(topo_params, verify=True):
G, toponame = TOPOLOGY['SlimFly'](topo_params)
process_SlimflyVAL(G, toponame, verify)
def process_BCubePaper(G, toponame, topo_params, mappingAddrToBaddr, mappingBaddrToAddr, verify):
rootdir = '.'
initHCONST(rootdir, toponame)
helper.makePrecomputationDirectory()
helper.makeOutputDirectory()
topo = Topology(G, toponame, NumThread)
K = topo_params['K']
numPort = topo_params['numPort']
bcRouting = BCubeRouting(K, numPort, mappingAddrToBaddr, mappingBaddrToAddr, topo)
if verify == True:
bcRouting.verifyAllLinkLoad(NumThread)
def run_BCubePaper(topo_params, verify=True):
G, toponame, mappingAddrToBaddr, mappingBaddrToAddr = TOPOLOGY['BCube'](topo_params)
process_BCubePaper(G, toponame, topo_params, mappingAddrToBaddr, mappingBaddrToAddr, verify)
if __name__ == '__main__':
topo_params = {'numGroup':4}
run_example('MixedNodes', topo_params=topo_params)
# topo_params = {'numServerPerToR':1, 'numToR':4, 'linkCapacity':1}
# run_example('Clique', topo_params=topo_params, , group_solution=True)
# topo_params = {'K':1, 'numPort':4}
# run_example('BCube', topo_params=topo_params, verify=False, group_solution=False)
# run_BCubePaper(topo_params, verify=True)
# topo_params = {'netRadix':5, 'numServerPerToR':7}
# run_example('SlimFly', topo_params=topo_params, verify=False, group_solution=False)
# run_SlimflyVAL(topo_params, verify=True)
# topo_params = {'numServerPerToR':2, 'numLocalToR':2, 'numSubblock':2, 'numBlock':2}
# run_example('FatClique', topo_params=topo_params, verify=False, group_solution=False)