Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Loop performance


I have a loop within fast Fourier transform function which takes in the values and computes the real and imaginary parts accordingly.

It is working well within the function. However, this loop is taking the maximum time which is quite concerning. Removing it is reducing the time by few seconds but this loop is needed within the function.

Previously, it was a nested loop and I modified it into a single for loop. Any idea on how to further reduce the processing time for the following loop would be much appreciated.

     for (unsigned int iter = 1; iter < N; iter <<=1)
           const unsigned int step = iter << 1;
           const double theta =  pi / double(iter);
           double wtemp = sin(theta * .5);
           double wreal = -2 * wtemp * wtemp;
           double wimag = sin(theta);
           //   Factors
           double wr = 1.0;
           double wi = 0.0;  
           for (unsigned int m = 0; m < iter; m++)
              for (unsigned int i = m; i < N; i += step)
                 const unsigned int j = i + iter;
                 double tempr= wr * real(data[j]) - wi * imag(data[j]);
                 double tempi= wr * imag(data[j]) + wi * real(data[j]);
                             complex<double> temp(tempr,tempi);
                             data[j]= data[i]- temp;
                             data[i] += temp;

where data is complex vector of type double.