automatic vectorization

L

Lynn McGuire

Do many of the prominent C++ compilers support automatic
vectorization, if at all ? I was wondering which of the
following code would get vectorized, if either ?

double x (1000);
for (int i = 0; i < 1000; i++)
x = 0;

-or-

double x (1000);
memset (x, 0, sizeof (x));

Thanks,
Lynn
 
V

Victor Bazarov

Do many of the prominent C++ compilers support automatic
vectorization, if at all ? I was wondering which of the
following code would get vectorized, if either ?

double x (1000);

You probably meant to declare 'x' as an array, not to initialize it to
1000, yes?

double x[1000];
for (int i = 0; i < 1000; i++)
x = 0;

-or-

double x (1000);
memset (x, 0, sizeof (x));


Regardless of the capabilities to vectorize anything, you should
probably consider initialization of an array using the language feature:

double x[1000] = {}; // initialized to "all zeros"

and let the compiler worry about speeding this up.

Unless, of course, your task is to micro-optimize your code, which is
usually compiler-specific, and as such is most likely OT here.

V
 
L

Lynn McGuire

double x (1000);
You probably meant to declare 'x' as an array, not to initialize it to 1000, yes?

double x[1000];

Sigh. Been doing too much fortran lately.
Regardless of the capabilities to vectorize anything, you should probably consider initialization of an array using the language
feature:

double x[1000] = {}; // initialized to "all zeros"

and let the compiler worry about speeding this up.

Cool ! I did not understand this. I will try to remember
this now.
Unless, of course, your task is to micro-optimize your code, which is usually compiler-specific, and as such is most likely OT here.

Not at all.

Thanks,
Lynn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top