Julia: Using distributed arrays in expressions

I am trying to generate and evaluate expressions in different processes. The expression contains the local part of the distributed array, which seems to cause problems. For example,

< p>

addprocs(2)
x = [i for i = 1:10]
foo = @spawnat 2 quote
out = x[1]
for i = 2:5
out += x[i]
end
out
end
eval(fetch(foo))

< p>Gives as expected

Out []: 15

But if I try to replace the vector x with the distributed array dx and use only the expression In the local block, the following error will appear.

# Construct a distributed array dx = [1,2,3,4,5,6,7,8, 9,10] # 
dx = DArray(I->[i for i in I[1]], (10, ))
dfoo = @spawnat 2 quote
out = localpart( dx)[1]
for i = 2:5
out += localpart(dx)[i]
end
out
end
eval( fetch(dfoo))


Out []: ERROR: BoundsError()
while loading In[9], in expression starting on line 9

in getindex at array.jl:246
in anonymous at In[9]:2

I think the problem is that localpart() is not recognized when evaluating expressions.
Am I right? ?
Is there a solution to this problem?

Thank you

The reference function here is 2, not the evaluation itself. It is like an error in the spawnat macro.

Look at this:

addprocs(2)
foo = @spawnat 2 quote
myid()
end
eval(fetch(foo)) # => 1

And calculate the sum of the distributed array: (not related to @spawnat)

# Construct a distributed array dx = [1,2,3,4,5,6,7,8,9,10] # 
dx = DArray(I ->[i for i in I[1]], (10, ))
dfoo = @spawnat 2 quote
sum(localpart(dx))
end
eval( fetch(dfoo))==sum(localpart(dx)) # => true

I tried to generate and calculate expressions on different processes. Expressions contain distributions The local part of the formula array, which seems to cause problems. For example,

addprocs(2)
x = [i for i = 1:10]
foo = @spawnat 2 quote
out = x[1]
for i = 2:5
out += x[i]
end
out
end
eval(fetch(foo))

Gives as expected

Out []: 15

However, if I try to replace the vector x with a distributed array dx and use only the local block in the expression, the following error appears.

# Construct a distributed array dx = [1,2,3,4,5,6,7,8,9,10] # 
dx = DArray(I->[i for i in I[1]], (10, ))
dfoo = @spawnat 2 quote
out = localpart(dx)[1]
for i = 2:5
out += localpart(dx)[i]
end
out
end
eval(fetch(dfoo))


Out [ ]: ERROR: BoundsError()
while loading In[9], in expression starting on line 9

in getindex at array.jl:246
in anonymous at In[9 ]:2

I think the problem is that localpart() is not recognized when evaluating expressions.
Am I right?
Is there a solution to this problem?

Thank you

The reference function here is 2, not the evaluation itself. It is like a spawnat macro error.

Look at this:

addprocs(2)
foo = @spawnat 2 quote
myid()
end
eval(fetch(foo)) # => 1

and calculate the sum of the distributed array: (not related to @spawnat)

 # Construct a distributed array dx = [1,2,3,4,5,6,7,8,9,10] # 
dx = DArray(I->[i for i in I[1]] , (10, ))
dfoo = @spawnat 2 quote
sum(localpart(dx))
end
eval(fetch(dfoo))==sum(localpart(dx) )) # => true

Leave a Comment

Your email address will not be published.