Using Python's multiprocessing to calculate the sum of integers from one long input line
<p>I want to use Python's multiprocessing module for the following:
Map an input line to a list of integers and calculate the sum of this list.</p>

<p>The input line is initially a string where the items to be summed are separated by spaces.</p>

<p>What I have tried is this:</p>

<pre><code>from itertools import imap

my_input = '1000000000 ' * int(1e6)
print sum(imap(int, my_input.split()))
</code></pre>

<p>This takes about 600ms on my machine, but I would like to make it faster with multiprocessing.</p>

<p>It seems that the bottleneck is in the mapping-part since the sum-method is pretty fast when applied to a ready list of integers:</p>

<pre><code>&gt;&gt;&gt; int_list = [int(1e9)] * int(1e6)
&gt;&gt;&gt; %time sum(int_list)
CPU times: user 7.38 ms, sys: 5 µs, total: 7.38 ms
Wall time: 7.4 ms
&gt;&gt;&gt; 1000000000000000
</code></pre>

<p>I tried to apply the instructions from <a href="https://stackoverflow.com/questions/29785427/how-to-parallel-sum-a-loop-using-multiprocessing-in-python">this question</a> but as I'm quite new to using multiprocessing, I couldn't fit the instructions to this problem.</p>