Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arrays optimization

2 views
Skip to first unread message

mattia

unread,
Dec 30, 2009, 12:43:59 AM12/30/09
to
Given that v[i] is equal to *(v + i), and given a function that uses v1
[n] and v2[m], is there a way to tell the compiler to optimize the code
providing the strong guarantee that the two arrays are totally different
(so can perform parallelization or vectorization)?
Is there any special identifier in the C++ language that a priori say
that the two variables will not be referencing to the same location?

Thanks, Mattia

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

John H.

unread,
Jan 1, 2010, 10:54:18 AM1/1/10
to
On Dec 29, 11:43 pm, mattia <ger...@gmail.com> wrote:
> parallelization or vectorization

std::valarray was created with something sounding like this in mind,
although the critics of it are many.

> Is there any special identifier in the C++ language that a priori say
> that the two variables will not be referencing to the same location?

C99 introduces the restrict keyword which does something like this.
Since some C++ compilers also try to be C compilers, you may find a C+
+ compiler that uses the restrict keyword (or some variant, like
__restrict__) in a similar manner.

Mathias Gaunard

unread,
Jan 1, 2010, 10:58:00 AM1/1/10
to
On 30 d�c 2009, 05:43, mattia <ger...@gmail.com> wrote:
> Given that v[i] is equal to *(v + i), and given a function that uses v1
> [n] and v2[m], is there a way to tell the compiler to optimize the code
> providing the strong guarantee that the two arrays are totally different
> (so can perform parallelization or vectorization)?
> Is there any special identifier in the C++ language that a priori say
> that the two variables will not be referencing to the same location?

There is no equivalent of restrict, albeit there are compiler-specific
extensions.

What you could do, however, is taking a reference to each array, which
would inform the compiler that the memory is distinct.

0 new messages