I'm trying to understand what happens with IPython parallel's non-copying send/receive of numpy arrays. I understand that the non-copying receive of a message is read-only, but this leads me to expect that the numpy array that I receive acts like a view, pointing to the original array (at least on shared memory machines). I would then expect that if the numpy array is modified on one of the compute nodes, my view of that array in the notebook would be updated, however, that doesn't seem to be the case. To demonstrate what's confusing me, the code
from IPython.parallel import Client
dv = Client()[:]
with dv.sync_imports():
import numpy
dv.execute('a = numpy.zeros(2)')
print dv['a']
mya = dv['a'][1] # my copy of the array in the notebook
# mya[0] = -1 # can't assign to mya because it is read-only
dv.execute('a[1] = 1') # update the arrays on the compute nodes
print mya # value of mya is not updated
print dv['a'] # even though the arrays are updated on the compute nodes
has output
importing numpy on engine(s)
[array([ 0., 0.]), array([ 0., 0.]), array([ 0., 0.]), array([ 0., 0.])]
[ 0. 0.]
[array([ 0., 1.]), array([ 0., 1.]), array([ 0., 1.]), array([ 0., 1.])]
I would think that the point of having the non-copying sends is to save memory by having every view of the array point to the same chunk of memory, but that doesn't seem to be the case here. What is happening under the hood, and how am I misunderstanding the use of the non-copying sends?
The context of my main question above is a shared memory environment (my laptop), but a possibly related question I have is how do non-copying sends of numpy arrays work and what is their use in the distributed memory case, where compute nodes are different physical machines and you must (I assume) send the numpy arrays over the network (effectively making a copy on the receiving machine), so having a view to the original memory location wouldn't make sense.