On Mon, 02 Jul 2007 14:27:11 -0700, rameshk wrote:

> Hi,
> 
> I was trying to get gcc to vectorize a simple loop:
> 
> #include <vector>
> 
> int test(double *x , int size);

Don't know what this is for.

> int test(double *x, int size)
> {
> 
>         int ret = 1;
>         std::vector<double>     v;
>         v.resize(size);
>         double  *a = &v[0];
> 
>         for(int i = 0;i < size; ++i )
>         {
>                 a[i ] = 1/x[i];
>         }

Why not just:

        std::vector<double> v(size);

        for(int i = 0;i < size; ++i )
        {
                v[i] = 1/x[i];
        }
> 
> }
> 
> I get the following message:
> 
> test.cpp:13: note: not vectorized: can't determine dependence between
> *D.11390_169 and *D.11389_164
> test.cpp:13: note: vectorized 0 loops in function.

I think the problem is that x could be aliased to &v[0]. Try it with 
std::valarray<double> (which is guaranteed not to be aliased) and it 
should vectorise.

-- 
Lionel B
_______________________________________________
help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to