/* param 1 = size of the matrices at the beginning param 2 = incrementation param 3 = size of the matrices at the end param 4 = number of iteration gcc -O2 -o cmult mult.c time ./cmult 600 2 602 1 real 0m3.800s user 0m3.764s sys 0m0.020s */ #include #include #include typedef struct Complexe {double re; double img;} complexe; complexe zero; /* version generic */ __inline__ void* add(void *x, void *y) { complexe a=((complexe*) x)[0]; complexe b=((complexe*) y)[0]; return (void *) &((complexe){a.re+b.re, a.img+b.img}); } __inline__ void* mult(void *x, void *y) { complexe a=((complexe*) x)[0]; complexe b=((complexe*) y)[0]; return (void *) &((complexe){a.re*b.re-a.img*b.img, a.re*b.img+a.img*b.re}); } complexe random_complexe(void) { complexe c = {c.re=(double)(rand()%1000), c.img=(double)(rand()%1000)}; return c; } void multiply_generic(int n, void *zero, void* (*add)(void *a, void *b), void* (*mult)(void *a, void *b), void *a, void *b, void *c) { register int i,j,k; void *tmp; void *cc; for (i=0; i