-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.py
55 lines (42 loc) · 1.12 KB
/
final.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
from psim import PSim
# Implementation of the Dijkstra algorithm for a single algorithm
from DijkstraSingle import *
def Parallel(V, E, w, s):
l = V.keys()
"""
Create a new process for each start vector.
Note that there is an "extra" because the root process
does NOT handle any work - it just scatters and gathers
data.
"""
comm = PSim(len(l) + 1)
# Scatter
if comm.rank==0:
# Loop through all of the processes
for i in range(1, len(l)+1):
comm.send(i, l[i-1])
else:
curr = comm.recv(0)
res = Dijkstra(V, curr)
comm.send(0, res)
# Gather
if comm.rank==0:
# Loop through all of the processes
for i in range(1, len(l)+1):
res = comm.recv(i)
print ""
print "Start: " + str(l[i-1])
print "Path: " + str(res)
G = {'s':{'u':10, 'x':5}, 'u':{'v':1, 'x':2}, 'v':{'y':4}, 'x':{'u':3, 'v':9, 'y':2}, 'y':{'s':7, 'v':6}}
Parallel(G, None, None, None)
"""
def dijkstra(V, E, w, s):
Vt = s
# Loop through all of the vertices but the starting/ending one
for vte in filter(lambda x: not x == Vt, V):
if (s, vte) in w:
l[vte] = w[(s, vte)]
else:
l[vte] = float("inf")
#while not Vt =
"""