// This uses several cpus to do 2D rectangular fft. #include #include #include #include #include #include "h.h" #define cpus 2 // cpus is a flexible integer parameter > 0. typedef struct{int first; int last;} blkmsg; typedef unsigned char uchar; typedef void * thnk(void *); void fft(c *, const int); #define wave 1 // wave is 0 or 1 depending on the test you want static R scalex, scaley; c * a; // The data to be transformed. static pthread_t mt(void * msg, thnk rtn){ pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_t zz; int rc = pthread_create(&zz, &attr, rtn, msg); if(rc) exit(printf("ERROR; return code from pthread_create() is %d\n", rc)); pthread_attr_destroy(&attr); return zz;} static int X, Y; static short LX, LY; static void * doRows(void * ptm){blkmsg * x = ptm; if(1) printf("Kilroy R %d thru %d\n", x->first, x->last); {int l = x->last, n; for(n=x->first; n<= l; ++n) { c ta[1<first, x->last); {int l = x->last, n; for(n=x->first; n<= l; ++n) { c ta[1<mx) {J=j; K=k; mx=M2;} te += M2;}}} R my = sqrt(mx); int jm = J< t) { if(1) pp(j, k); if(!(top--)) return jm;}}} return jm;} static void d2Dft(void){ static int tcnt = 0; printf("Transform %d:\n", ++tcnt); db(doRows, 1<>(8*y), out);} static int li(int j){if((int)(0.5+cpus*((R)j/cpus)) != j) exit(printf("Oops!\n")); int k=1, z = j-1; while(z>>=1) ++k; return k;} int main(int argc, char * * args){ if(argc < 5) exit(printf("Usage:\n%s n infile outfile dotSize\n", args[0])); FILE * in = fopen(args[2], "r"); if(!in) exit(printf("no such file: %s\n", args[2])); X = ri(in); Y = ri(in); printf("X=%d, Y=%d\n", X, Y); LX = li(X), LY = li(Y); int L2=LX+LY; scalex = 1/sqrt(1<>LX, j&((1<