0
$\begingroup$

How will the value, A(2) be available in, line 2, if A(2) is being calculated in, line 3? enter image description here

$\endgroup$
2
$\begingroup$

The point is that it doesn't use the new value, it uses the old value. You want to take the current value of A[i+1] and use it to calculate a new value for A[i]. If you do each operation in order, you'll always do the operation which uses the old value, before overwriting it with a new value.

The problem is, when you vectorize this, you might end up changing A[i+1] at the same time as you're trying to read its old value. But ideally vectorization shouldn't change the result of a process, only how fast it runs. This is why you need the TEMP array, to keep the result the same.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.