summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorStefan van der Walt <stefanv@berkeley.edu>2019-10-28 11:46:30 -0700
committerJarrod Millman <jarrod.millman@gmail.com>2019-10-29 12:00:40 -0700
commit42beadf580accceec5e30aa4fd4d2613f62075f4 (patch)
tree1d8d774026f359b6783b8362e06ad30574d842b3 /examples
parent70ba4e945e225e87f40fa51aced1e40e4fc06729 (diff)
downloadnetworkx-42beadf580accceec5e30aa4fd4d2613f62075f4.tar.gz
Remove shim that worked around using starmap
Diffstat (limited to 'examples')
-rw-r--r--examples/advanced/plot_parallel_betweenness.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/examples/advanced/plot_parallel_betweenness.py b/examples/advanced/plot_parallel_betweenness.py
index ae098477..d2058d1d 100644
--- a/examples/advanced/plot_parallel_betweenness.py
+++ b/examples/advanced/plot_parallel_betweenness.py
@@ -30,26 +30,17 @@ def chunks(l, n):
yield x
-def _betmap(G_normalized_weight_sources_tuple):
- """Pool for multiprocess only accepts functions with one argument.
- This function uses a tuple as its only argument. We use a named tuple for
- python 3 compatibility, and then unpack it when we send it to
- `betweenness_centrality_source`
- """
- return nx.betweenness_centrality_source(*G_normalized_weight_sources_tuple)
-
-
def betweenness_centrality_parallel(G, processes=None):
"""Parallel betweenness centrality function"""
p = Pool(processes=processes)
node_divisor = len(p._pool) * 4
node_chunks = list(chunks(G.nodes(), int(G.order() / node_divisor)))
num_chunks = len(node_chunks)
- bt_sc = p.map(_betmap,
- zip([G] * num_chunks,
- [True] * num_chunks,
- [None] * num_chunks,
- node_chunks))
+ bt_sc = p.starmap(nx.betweenness_centrality_source,
+ zip([G] * num_chunks,
+ [True] * num_chunks,
+ [None] * num_chunks,
+ node_chunks))
# Reduce the partial solutions
bt_c = bt_sc[0]