Imagine that a parallel computation is to be performed. Let us imagine that due to RAM requirements it is essential that memory is shared across sub-processes. Let us also assume that no shared memory is ever altered, but only read from. My question is if it can ever matter (in terms of performance) how the shared memory is referenced.
As an example consider the following (and let's assume we are on a system that uses Copy on Write such that a
is not copied to each sub-process)
from multiprocessing import Pool
a = [5, 8, 0.1, 154]
def function( i ):
return a[i]**2
with Pool(4) as p:
result = p.map( function, [0,1,2,3] )
print(result)
out: [25, 64, 0.010000000000000002, 23716]
Will the four values of a
(index 0,1,2,3) be accessible at the same time? Or will each sub process have to wait until the reference to the list a
is "available" before being able to extract a[i]
?
I suspect that the answer is that separate elements are available at the same time. But I want to be sure.
Thanks for any input :)