// This uses several cpus to do 2D square fft. #include #include #include #include #include #define cpus 1 // cpus is a flexible integer parameter > 0. typedef struct{int first; int last; int j;} blkmsg; typedef _Complex float c; typedef double R; typedef void * thnk(void *); void fft(const int, c *); #define sz 4096 // sz is a flexible parameter but must be a power of 2. #define wave 1 // wave is 0 or 1 depending on the test you want R scale; int mc[cpus]; // .... count little fft's c a[sz][sz]; // The data to be transformed. static int min(int a, int b){return a j, x->first, x->last); {int l = x->last; for(int n = x->first; n<= l; ++n) { c ta[sz]; for(int m=0; mj]; for(int m=0; mfirst, x->last); {int l = x->last; for(int n = x->first; n<= l; ++n) { c ta[sz]; for(int m=0; mj]; for(int m=0; m0); blkmsg bm[cpus]; pthread_t thrds[cpus]; for(int n = 0; n < cpus; ++n) {bm[n] = (blkmsg){n*b, min((n+1)*b, sz)-1, n}; thrds[n] = mt(&bm[n], fab);} for(int n = 0; n < cpus; ++n) {int rc = pthread_join(thrds[n], NULL); if(rc) {printf("ERROR; return code from pthread_join() is %d\n", rc); exit(-1);}}} static void d2Dft(void){ static int tcnt = 0; printf("Transform %d:\n", ++tcnt); db(doRows); db(doCols); {int sm=0; for(int j = 0; j1.e-8) printf( "%4d %4d %13.8f %13.8f %13.8f\n", j, k, creal(z), cimag(z), sqrt(m));} static void psam(int m){printf("sample %d\n", m); for(int j=81; j<85; ++j) for(int k=384; k<387; ++k) pp(j, k);} static void fp(R th, char * m){R mx = 0, te = 0; int J=-1, K=-1; for(int j=0; jmx) {J=j; K=k; mx=M2;} te += M2;} printf("%s: th=%9.6f, peak at %d %d, max = %9.6f, te=%e\n", m, th, J, K, sqrt(mx), te); {R t = th*mx; for(int j=0; j t) pp(j, k);}} int main(){scale = 1./sqrt(sz); for(int j=0; j