Hi I am trying to write a code for Vector-Scalar multiplication using AVX
on Sandy Bridge processor i7-3720QM (~2012)
.
The code is a C
code compiled with GNU gcc
on Mac OSX 10.8
.
gcc -mavx -Wa,-q -o bb5 code1.c -lm
I am getting Segmentation fault: 11
. Please help.
Output:
3.000000 6.000000 9.000000 12.000000
Segmentation fault: 11
So, it looks like the store
command is not working correctly ? Thanks. Eventually I want to do something like
A = A + x*B
where x
is a scalar and A
and B
are vector. The function void matsca(const double* a, double c, double *b)
will be called again and again to operate on a double
vector of large dimension with stride of 8
since AVX
can take 4
double elements (256 bits)
. Thanks for your help.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <immintrin.h>
void matsca(const double* a, double c, double *b)
{
__m256d a0 = _mm256_loadu_pd(a+0);
__m256d a1 = _mm256_set1_pd(c);
__m256d a2 = _mm256_mul_pd(a0,a1);
double* f = (double*)&a2;
printf("%f %f %f %f \n",f[0],f[1],f[2],f[3]);
_mm256_store_pd(b,a2);
}
int main()
{
double m1[11]={1,2,3,4,5,6,7,8,9,10,11};
double *m3;
double m2=3;
int i;
matsca(&m1[0],m2,&m3[0]);
for (i=0; i<3; i=i+1)
{
printf("%d %f \n",i,m3[i]);
}
return 0;
}