Julia has been good in my parallel computing works, however I encounter an issue recently. Let’s say I have an array a and I would like a @view as a shortcut to modify or refer to part of a, so I make a data structure about this, e.g.
using Distributed
@everywhere struct MyArray
a::Vector
b::SubArray
MyArray(a::Vector) = new(a, @view a[1:2])
end
Now I would like to create an array, launch a parallel computing on some workers with this array and calculate some stuff:
But when I run these code I get remoteResult = 10.0 and localResult = 7.0. It seems that the relation between a SubArray and an Array is removed after they are transferred to a worker.
I would like to know whether (1) this is an inconsistency in Julia Distributed, or (2) I am using parallel features improperly? If (2), what should I do instead?
I don’t have the answer but conceptually, modifying a portion of an array on different workers and expecting that the local array will be modified by what the remote machine did doesn’t make sense to me.
what you should do instead is split up your work and return the sub-result from each worker and then reduce the various results together at the end. if the result is a sum, do a sum of the first half on one machine and the sum of the second half on the other… then when the result comes back… add them together
I certainly do not expect some modification happened remotely should affect a local array; what is surprising here is: when I copy both an array and its view to a remote machine, the relation between them seems broken.