Your application calls scalar instead of vectorized versions of math functions. To fix: Do all of the following:
- Upgrade the Glibc library to version 2.22 or higher. It supports SIMD directives in OpenMP* 4.0 or higher.
- Upgrade the GNU* gcc compiler to version 4.9 or higher. It supports vectorized math function options.
- Use the -fopenmp and -ffast-math compiler options to enable vector math functions.
- Use appropriate OpenMP SIMD directives to enable vectorization.
Note : Also use the -I/path/to/glibc/install/include and -L/path/to/glibc/install/lib compiler options if you have multiple Glibc libraries installed on the host.
gcc program.c -O2 -fopenmp -ffast-math -lrt -lm -mavx2 -I/opt/glibc-2.22/include -L/opt/glibc-2.22/lib -Wl,--dynamic-linker=/opt/glibc-2.22/lib/ld-linux-x86-64.so.2...
#pragma omp simd
for (i = 0; i < N; i++)
...gcc program.c -O2 -fopenmp -ffast-math -lrt -lm -mavx2 -I/opt/glibc-2.22/include -L/opt/glibc-2.22/lib -Wl,--dynamic-linker=/opt/glibc-2.22/lib/ld-linux-x86-64.so.2#include "math.h"
#include "stdio.h"
#define N 100000
int main()
{
double angles[N], results[N];
int i;
srand(86456);
for (i = 0; i < N; i++)
{
angles[i] = rand();
}
#pragma omp simd
for (i = 0; i < N; i++)
{
results[i] = cos(angles[i]);
}
return 0;
}