I've produced this kernel
struct csrFormat {
int M, N;
int *IRP;
int *JA;
double *AS;
};
struct vector {
int dim;
double *val;
};
double csrSIMDReduction(struct csrFormat *csr, struct vector *vec, struct vector *res, int nz){
int M = csr->M;
int nonzerosPerRow = nz/M;
int chunk_size = 10000/nonzerosPerRow;
double *val = res->val;
struct timeval start,end;
gettimeofday(&start, NULL);
//IRP is the row_pointer array
//JA is the column indices array
//AS is the values array
int i,j,tmp;
#pragma omp parallel
{
#pragma omp for private(i, j, tmp) schedule(dynamic, chunk_size)
for (i=0; i<M; i++)
{
double result = 0.0;
#pragma omp simd reduction(+ : result)
for (j = csr->IRP[i]; j < csr->IRP[i+1]; j++)
{
tmp = csr->JA[j];
result += csr->AS[j] * vec->val[tmp];
}
val[i] = result;
}
}
gettimeofday(&end, NULL);
res->dim = M;
//printf("%ld.%06ld\n", start.tv_sec, start.tv_usec);
//printf("%ld.%06ld\n", end.tv_sec, end.tv_usec);
long t = (end.tv_sec - start.tv_sec)*1000000.0 + end.tv_usec - start.tv_usec;
return (double) t;
}
but i'm having a doubt: how does the vectorization works?
I mean, from what i've understood, the inner cicle is runned running multiple iterations together, but how can a single thread do this?
EDIT: code updated.