<br><div class="gmail_quote">On Wed, Apr 6, 2011 at 9:06 PM, elsa <span dir="ltr"><<a href="mailto:kerensaelise@hotmail.com">kerensaelise@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi guys,<br>
<br>
I want to try out some pooling of processors, but I'm not sure if it<br>
is possible to do what I want to do. Basically, I want to have a<br>
global object, that is updated during the execution of a function, and<br>
I want to be able to run this function several times on parallel<br>
processors. The order in which the function runs doesn't matter, and<br>
the value of the object doesn't matter to the function, but I do want<br>
the processors to take turns 'nicely' when updating the object, so<br>
there are no collisions. Here is an extremely simplified and trivial<br>
example of what I have in mind:<br>
<br>
from multiprocessing import Pool<br>
import random<br>
<br>
p=Pool(4)<br>
myDict={}<br>
<br>
def update(value):<br>
    global myDict<br>
    index=random.random()<br>
    myDict[index]+=value<br>
<br>
total=1000<br>
<br>
p.map(update,range(total))<br>
<br>
<br>
After, I would also like to be able to use several processors to<br>
access the global object (but not modify it). Again, order doesn't<br>
matter:<br>
<br>
p1=Pool(4)<br>
<br>
def getValues(index):<br>
    global myDict<br>
    print myDict[index]<br>
<br>
p1.map(getValues,keys.myDict)<br>
<br>
Is there a way to do this </blockquote></div><br>This should give you a synchronized wrapper around an object in shared memory:<br><br><a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Value">http://docs.python.org/library/multiprocessing.html#multiprocessing.Value</a><br>
<br>