/* gets no. of points from the user, initialize the points and roots of unity lookup table * and lets fft go. finally bit-reverses the results and outputs them into a file. * n should be a power of 2. */ int main(int argc, char *argv[]) { int n; double *A_re, *A_im, *W_re, *W_im; long long start, end; struct timespec ts; if (argc <= 2) { fprintf(stderr, "Usage: ./fft n outfile\n"); exit(-1); } n = atoi(argv[1]); A_re = (double*)_mm_malloc(sizeof(double)*n, 32); A_im = (double*)_mm_malloc(sizeof(double)*n, 32); W_re = (double*)_mm_malloc(sizeof(double)*n/2, 32); W_im = (double*)_mm_malloc(sizeof(double)*n/2, 32); assert(A_re != NULL && A_im != NULL && W_re != NULL && W_im != NULL); init_array(n, A_re, A_im); compute_W(n, W_re, W_im); clock_gettime(CLOCK_MONOTONIC, &ts); start = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000; fft(n, A_re, A_im, W_re, W_im); clock_gettime(CLOCK_MONOTONIC, &ts); end = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000; permute_bitrev(n, A_re, A_im); // output_array(n, A_re, A_im, argv[2]); printf ("The total CPU time of FFT is: %lld microseconds.\n", end - start); printf ("The number of errors is %lld \n.", errors); _mm_free(A_re); _mm_free(A_im); _mm_free(W_re); _mm_free(W_im); }
void begin() { int i; float *A, *W_re, *W_im; A = (float*)malloc(sizeof(float)*2*n); W_re = (float*)malloc(sizeof(float)*n/2); W_im = (float*)malloc(sizeof(float)*n/2); /* assert(A_re != NULL && A_im != NULL && W_re != NULL && W_im != NULL); */ compute_W(W_re, W_im); while (numiters == -1 || numiters-- > 0) { init_array(A); fft(A, W_re, W_im); #ifdef FFT2 permute_bitrev(A); #endif output_array(A); } free(A); free(W_re); free(W_im); }