Given an example function (example is given below), the for loop can either be parallelized using OpenMP or be vectorized using vectorization (assuming that compiler does the vectorization).
Example
void function(float* a, float* b, float* c, int n)
{
for(int i = 0; i < n; i++)
{
c[i] = a[i] * b[i];
}
}
I would like to know
Note: I didn't give a though about the different SSE versions, number of processors/cores (as number of threads scales up in OpenMP), etc... My question is in general. The answers can also be more specific as well.
OpenMP and vectorisation are not competing technologies but rather they augment one another. Vectorisation can improve the serial performance of CPU cores that have vector capabilities (SSE/3DNow!/Altivec/etc.) and thus make each thread run faster, while OpenMP can employ more than one of the available cores in order to run multiple threads in order to solve a larger problem in parallel.
In summary:
Vectorisation is only data parallel (apply the same operation to multiple data items) and works on the lowest hardware level possible (core/ALU), while OpenMP can be both data and/or task parallel and is an abstraction on much higher level.
As always there is the "it depends" argument, since the performance of vectorisation or OpenMP or vectorisation+OpenMP could depend on the hardware, memory bandwidth, cache usage, etc., etc., etc...
Concerning your case function, it depends on how large the vectors are. If they are too small, using OpenMP would give no benefit, and even lead to slower execution because of the overhead. Vectorisation is likely to improve the execution time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With