- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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] = tab[index] + tmp; // 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page