Issue with gather & scatter operations

Issue with gather & scatter operations

Hi,

I read on the doc that array notation can be used for array indicies in both cases :

C[:] = A[B[:]] and A[B[:]] = C[:]

I try to use this notation for left & right operands at the same time but it gives me wrong results.

Here is my problem:

double tmp[VEC_SIZE]; // Already initialized
int index[VEC_SIZE];  // Already initialized

tab[index[:]] = tab[index[:]] + tmp[:];       // This line gives wrong result

for (int i = 0; i < VEC_SIZE; i++) {
    tab[index[i]] = tab[index[i]] + tmp[i];   // While this loop gives the correct result
}

To me, these two versions of the code are supposed to be equivalent, am I wrong ?

Can we use array notation for array indicies in left & right operands at the same time ?

Thanks

3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Best Reply

The CilkPlus Array Notation statement
          tab[index[:]] = tab[index[:]] + tmp[:]
says that the right hand side of assignment
          tab[index[:]] + tmp[:]
can be computed "entirely for all elements" before any stores to tab[index[:]] occurs.

If index[] array has any duplicated index values, that does not work and as such
the use of CilkPlus Array Notation is incorrect (i.e., programmer error) ---- if
the programmer is expecting the same result as sequential execution
of the loop form.

In other words, the CilkPlus Array Notation statement
          tab[index[:]] = tab[index[:]] + tmp[:]
is correct if the programmer knows that index values in index[:] are all distinct.
Compiler will not perform any static/runtime checks to determine the validity
of such assumption.

Hope this helps.

Thanks for your reply,

All values of the index[] array were theoritically supposed to be distinct. However, when I checked, I figured out that it was not always the case.

Sorry for that and thanks again for your remark.

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi