-
Notifications
You must be signed in to change notification settings - Fork 2
/
parallel_4rec.py
63 lines (48 loc) · 1.28 KB
/
parallel_4rec.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 27 08:49:25 2017
Multiprocessing execution
@author: laci
"""
import multiprocessing as mp
import time
import math
import sparse_methods as m
import sparse_move as sm
import sparse_contract as sc
import graph
import divide as d
def start_calc(fm, fc, fo, nodes, g, out_queue):
new_edges = d.filter_edges(nodes,g.edges)
gs = graph.FixedGraph(nodes, new_edges)
# print("gs.nodes", gs.nodes)
uf = m.recurse(fm, fc, fo, gs)
# print("start uf:", uf)
out_queue.put(uf)
N = 5000
procs = []
cores = 4
chunksize = int(math.ceil(N) / float(cores))
g = graph.BAGraph(N, 0.6)
groups = d.divide(cores, g)
startTime = time.time()
myQueue = mp.Queue()
for i in range(cores):
p = mp.Process(target=start_calc,
args=(sm.independent, sc.one, m.iterated,\
groups[i], g, myQueue))
procs.append(p)
p.start()
result = {}
for i in range(cores):
result.update(myQueue.get())
for p in procs:
p.join()
middleTime = time.time()
uf = m.iterated(sm.independent, sc.one, result, g)
endTime = time.time()
workTime = endTime - startTime
#print results
print("The job took " + str(workTime) + " seconds to complete")
print("Last part" + str(endTime - middleTime) )