<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi,<br><br>thanks for your response.<br><br>I checked out multiprocessing.value, however from what I can make out, it works with object of only a very limited type. Is there a way to do this for more complex objects? (In reality, my object is a large multi-dimensional numpy array).<br><br>Thanks,<br><br>Elsa.<br><br><hr id="stopSpelling">Date: Wed, 6 Apr 2011 22:20:06 -0700<br>Subject: Re: multiprocessing<br>From: drsalists@gmail.com<br>To: kerensaelise@hotmail.com<br>CC: python-list@python.org<br><br><br><div class="ecxgmail_quote">On Wed, Apr 6, 2011 at 9:06 PM, elsa <span dir="ltr"><<a target="_blank">kerensaelise@hotmail.com</a>></span> wrote:<br><blockquote class="ecxgmail_quote" style="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 target="_blank">http://docs.python.org/library/multiprocessing.html#multiprocessing.Value</a><br>
<br> </body>
</html>