<div dir="ltr">Thanks for the responses.<div><br></div><div>I will create another thread to supply a more realistic example. </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 29, 2015 at 10:12 AM, Oscar Benjamin <span dir="ltr"><<a href="mailto:oscar.j.benjamin@gmail.com" target="_blank">oscar.j.benjamin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class=""><div dir="ltr">On Tue, 29 Sep 2015 at 02:22 Rita <<a href="mailto:rmorgan466@gmail.com" target="_blank">rmorgan466@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I am using the multiprocessing with apply_async to do some work. Each task takes a few seconds but I have several thousand tasks. I was wondering if there is a more efficient method and especially when I plan to operate on a  large memory arrays (numpy)</div></blockquote><div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br></div><div>Here is what I have now</div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>import multiprocessing as mp</div><div>import random</div><div><br></div><div>def f(x):</div><div>    count=0</div><div>    for i in range(x):</div><div>        x=random.random()</div><div>        y=random.random()</div><div>        if x*x + y*y<=1:</div><div>            count+=1</div><div><br></div><div>    return count</div></div></div></div></div></blockquote></span><div><br><div></div><div>I assume you're using the code shown as a toy 
example of playing with the multiprocessing module? If not then the 
function f can be made much more efficient.<br></div><br></div><div>The problem is that while it's good that you have distilled your problem into a simple program for testing it's not really possible to find a more efficient way without finding the bottleneck which means looking at the full problem.<br><br>--<br></div><div>Oscar<br></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">--- <span>Get your facts first, then you can distort them as you please.</span>--</div>
</div>