Looking for an IPP function

Looking for an IPP function

I have the following loop that I would like to optimize. Are there any IPP function for each of these statements in the for loop?

double fast_product_sum(int n, double *a, int* indexes, double* b, double* c)
{

    double sum = 0.0;
    for (int i = 0; i < n; i++)
    {
        c[i] = a[i] + b[indexes[i]];
        sum += a[i] + b[indexes[i]];
    }

    return sum;
}

I apprieciate any help in this matter.

Regards

Chris

3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Please look at a subset of IPP functions called as Vector Math functions. These functions allow to do add, subtract and multiply operations for every element of the source vector and highly optimized.

Chris, you're calculating the sum of a[i] + b[ indexes[i] ] twice:
...
for (int i = 0; i < n; i++)
{
c[i] = a[i] + b[ indexes[i] ];
sum += a[i] + b[ indexes[i] ];
}
...
and if input arrays are very large ( for example, greater than 4MB ), indexes array has unordered/random values and all input arrays don't fit into L3 cache line then a performance of calculations will be affected.

登陆并发表评论。