Show More
@@ -58,9 +58,9 b' The code to generate the simple DAG:' | |||
|
58 | 58 | .. sourcecode:: python |
|
59 | 59 | |
|
60 | 60 | import networkx as nx |
|
61 | ||
|
61 | ||
|
62 | 62 | G = nx.DiGraph() |
|
63 | ||
|
63 | ||
|
64 | 64 | # add 5 nodes, labeled 0-4: |
|
65 | 65 | map(G.add_node, range(5)) |
|
66 | 66 | # 1,2 depend on 0: |
@@ -71,7 +71,7 b' The code to generate the simple DAG:' | |||
|
71 | 71 | G.add_edge(2,3) |
|
72 | 72 | # 4 depends on 1 |
|
73 | 73 | G.add_edge(1,4) |
|
74 | ||
|
74 | ||
|
75 | 75 | # now draw the graph: |
|
76 | 76 | pos = { 0 : (0,0), 1 : (1,1), 2 : (-1,1), |
|
77 | 77 | 3 : (0,2), 4 : (2,2)} |
@@ -96,11 +96,11 b' Now, we need to build our dict of jobs corresponding to the nodes on the graph:' | |||
|
96 | 96 | .. sourcecode:: ipython |
|
97 | 97 | |
|
98 | 98 | In [3]: jobs = {} |
|
99 | ||
|
99 | ||
|
100 | 100 | # in reality, each job would presumably be different |
|
101 | 101 | # randomwait is just a function that sleeps for a random interval |
|
102 | 102 | In [4]: for node in G: |
|
103 |
...: jobs[node] = randomwait |
|
|
103 | ...: jobs[node] = randomwait | |
|
104 | 104 | |
|
105 | 105 | Once we have a dict of jobs matching the nodes on the graph, we can start submitting jobs, |
|
106 | 106 | and linking up the dependencies. Since we don't know a job's msg_id until it is submitted, |
@@ -114,10 +114,10 b' on which it depends:' | |||
|
114 | 114 | |
|
115 | 115 | In [5]: rc = Client() |
|
116 | 116 | In [5]: view = rc.load_balanced_view() |
|
117 | ||
|
117 | ||
|
118 | 118 | In [6]: results = {} |
|
119 | ||
|
120 |
In [7]: for node in |
|
|
119 | ||
|
120 | In [7]: for node in nx.topological_sort(G): | |
|
121 | 121 | ...: # get list of AsyncResult objects from nodes |
|
122 | 122 | ...: # leading into this one as dependencies |
|
123 | 123 | ...: deps = [ results[n] for n in G.predecessors(node) ] |
@@ -152,18 +152,18 b' will be at the top, and quick, small tasks will be at the bottom.' | |||
|
152 | 152 | .. sourcecode:: ipython |
|
153 | 153 | |
|
154 | 154 | In [10]: from matplotlib.dates import date2num |
|
155 | ||
|
155 | ||
|
156 | 156 | In [11]: from matplotlib.cm import gist_rainbow |
|
157 | ||
|
157 | ||
|
158 | 158 | In [12]: pos = {}; colors = {} |
|
159 | ||
|
159 | ||
|
160 | 160 | In [12]: for node in G: |
|
161 | 161 | ....: md = results[node].metadata |
|
162 | 162 | ....: start = date2num(md.started) |
|
163 | 163 | ....: runtime = date2num(md.completed) - start |
|
164 | 164 | ....: pos[node] = (start, runtime) |
|
165 | 165 | ....: colors[node] = md.engine_id |
|
166 | ||
|
166 | ||
|
167 | 167 | In [13]: nx.draw(G, pos, node_list=colors.keys(), node_color=colors.values(), |
|
168 | 168 | ....: cmap=gist_rainbow) |
|
169 | 169 |
General Comments 0
You need to be logged in to leave comments.
Login now