I was trying the Intel Intrinsic AVX2
datatype and functions.Unlike most codes found on the web which concentrate on looping on 256-bit segments of data on arrays,I tried to create an array of __m256d
data.
The code works for trying to load all array data to __m256
registers(in here array of these types). but when trying to retrieve or do other work with them I receive a segmentation fault 11 error.
I tried searching the web for any other answers but I couldn't find anything.
This is the load function:
__m256d* load_pd(double *a,int size)
{
int length = size / 4;
__m256d * out= new __m256d[length];
int cnt=0;
for(int i=0;i<size;i+=4)
{
out[cnt++] = _mm256_load_pd(&a[i]);
}
return out;
}
and I used the function in main:
double a[256]={256};
double b[256] = {256};
__m256d* a_vec = load_pd(a,256);
__m256d* b_vec = load_pd(b,256);
The next function however:
__m256d* add_pd(__m256d* a, __m256d* b,int size)
{
__m256d* res = new __m256d[size];
for(int i=0;i<size;i++)
{
res[i] = _mm256_add_pd(a[i],b[i]);
}
return res;
}
and when I invoke add_pd like this:
double c[256] = {256};
__m256d* res = _mm256_store_pd(a_vec,b_vec,256/4);
I get the Segmentation fault: 11
What is the problem here? Aren't other pointers allowed to point to already allocated pointer of __m256d
?