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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2859 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.