I have an implementation of a digital bessel filter which is a performance bottleneck for my program. I would like to parallelize the main loop with OpenMP.
The function takes an input array paddedsignal
and arrays of filter coefficients dcof
and ccof
and produces a temporary array temp
which is filtered. The main loop of this process looks like this:
for (i=order; i<end; i++)
{
temp[i] = ccof[0]*paddedsignal[i];
for (p=1; p<=order; p++)
{
temp[i] += ccof[p]*paddedsignal[i-p] - dcof[p]*temp[i-p];
}
}
In particular, note that the value of temp[i]
depends on previous values of temp[i-p]
. This confounds a simple #pragma omp for
directive, since the value of temp[i]
near the boundaries between sections of the array which would be handled by different threads has race condition problems. Basically if thread one takes indices between 0-99 and thread 2 takes 100-199, the value at 100 will be wrong since it will be computed before the value at 99, on which it depends.
Is there a way to salvage this situation? I am despairing as to what I can do to parallelize this since the fact that filtered values depend on neighboring values makes it inherently a serial calculation. Is there any way around this?