# Can this loop be vectorized?

Discussion in 'C++' started by Wolfgang Thomsen, Nov 28, 2008.

1. ### Wolfgang ThomsenGuest

Hello,

is there a way to convince the Intel compiler to (auto-)vectorize the
following?

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {
a = b[c[i*2]];
}

It does not vectorize presumably because c[] is a different data type than
a[] and b[].

Any help greatly appreciated!
Wolf

Wolfgang Thomsen, Nov 28, 2008

2. ### ÏÑíÏ ÚÈÏ ÇááåGuest

Or why don't you type:

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {

a = b[c[i*2]];

}

ÏÑíÏ ÚÈÏ Çááå, Nov 28, 2008

3. ### ÏÑíÏ ÚÈÏ ÇááåGuest

Sory For Mistake
Tyy To Type:

double a[N], b[N];
int c[2N];

for(int i=0; i<N; i++) {
tmp = c[i*2]; // All now are integers
a = b[tmp];

}
But for knowing
I tryed your code on turbo c++ 4.5 . It was running..

ÏÑíÏ ÚÈÏ Çááå, Nov 28, 2008
4. ### red floydGuest

Ø¯Ø±ÙŠØ¯ Ø¹Ø¨Ø¯ Ø§Ù„Ù„Ù‡ wrote:
> Sory For Mistake
> Tyy To Type:
>
> double a[N], b[N];
> int c[2N];
>
> for(int i=0; i<N; i++) {
> tmp = c[i*2]; // All now are integers
> a = b[tmp];
>
> }
> But for knowing
> I tryed your code on turbo c++ 4.5 . It was running..
>

That wasn't what OP was asking. To the OP, you're better off asking in
a group dedicated to your compiler -- ISO/IEC 14882:2003 doesn't discuss
vectorization at all.

red floyd, Nov 28, 2008