1

I am trying to create a parallel for loop using @parallel, in order to compute a cumulative sum of a SharedArray. A simple test I'm running looks like this:

p = SharedArray{Float64}(10,10);

@parallel for i = 1 : 5
    p = p .+ 1
end

p

However, when printing p, I just get a series of zeros, as if the for loop never happened. I have tested that the code actually enters the for loop by having it print on each loop.

I realize that this question may possibly have a straightforward answer to many people, but following the Julia manual and looking for answers online has not lead me to a solution so far.

Thanks in advance,

Simos

1 Answer 1

0

Does changing the = operator .= have the desired outcome?

@parallel for i = 1 : 5
    p .= p .+ 1
end

edit: formatting.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that seemed to to the trick, thank you! Would be glad to know why this operator changes the result so drastically, since it has no effect when doing calculations in the serial version of the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.