-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbalance.py
43 lines (40 loc) · 1005 Bytes
/
balance.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
from util import *
from lpt import lpt, statistics
from all2all import all2all
def load_bal(cx, npart):
''' cx is list of (complexity, gid) pairs on this process
return: an LPT balanced list of gids that should belong to this process
'''
elapse = h.startsw()
#send to rank 0
r = all2all({0:cx})
# make a list of all the (cx, gid)
s = {}
if rank == 0:
c = []
for i in r.values():
c += i
del r
#distribute by LPT
parts = lpt(c, npart)
print statistics(parts)
for i,p in enumerate(parts):
s.update({i : p[1]})
else:
del r
#send each partition to the proper rank
local = all2all(s)
del s
if rank == 0:
print "load_bal time %g" % (h.startsw()-elapse)
return local[0]
if __name__ == '__main__':
from util import serialize, finish
if True:
cx = [(10*rank+i, 10*rank+i) for i in range(1,5)]
print cx
cx = load_bal(cx, nhost)
for r in serialize():
print 'rank %d '%rank, cx
if nhost > 0:
finish()