/* simple calling routines to test parallel_sort() routine In this one only the hypercube pre-sort is performed and the number of elements that are in their correct final position is determined */ #include #include #include #include #include "mimd.h" #if CAP && HOST #include #endif #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) #endif struct element { int i1, i2; }; int comparison1(struct element *e1,struct element *e2) { return(e1->i1 - e2->i1); } int comparison2(struct element *e1,struct element *e2) { return(e1->i2 - e2->i2); } int comparison3(struct element *e1,struct element *e2) { return(e2->i2 - e1->i2); } #if !HOST /******************************************************************* test the hypercube sorting ********************************************************************/ int sort_test(int N) { int loops = 1; struct element *d1, *d2; int i, j, same, nsum, cid, faraway, samecell; int sametot=0, samecelltot=0, farawaytot=0; d1 = (struct element *)malloc(N*sizeof(d1[0])); d2 = (struct element *)malloc(N*sizeof(d1[0])); if (!d1 || !d2) { fprintf(stderr,"out of memory in cell %d for %d elements\n", getcid(), N); return; } printf("allocated OK\n"); cid = getcid(); for (j=0;j 1) faraway++; } if (d1[i].i2 != d2[i].i2) { #if 0 printf("N=%d cid=%d i=%d i1=%d:%d i2=%d:%d\n", N, cid, i, d1[i].i1/N, d1[i].i1%N, d1[i].i2/N, d1[i].i2%N); #endif } } printf("counted\n"); MIMD_Sum_Int(same, &same); MIMD_Sum_Int(samecell, &samecell); MIMD_Sum_Int(faraway, &faraway); MIMD_Sum_Int(N, &nsum); printf("summed\n"); sametot += same; samecelltot += samecell; farawaytot += faraway; } sametot /= j; samecelltot /= j; farawaytot /= j; if (getcid() == 0) { printf("%d %d %d %d\n", nsum-sametot, nsum-samecelltot, farawaytot, nsum); } free(d1); free(d2); return 0; } #endif /******************************************************************* main routine ********************************************************************/ int main(int argc,char *argv[]) { int N=40; MIMD_Start(); #if HOST printf("sorting %d elements per node\n",N); waitexit(); #else srandom(getcid()); while (N < 4000000) { printf("N=%d\n", N); sort_test(N); N *= 1.5; } #endif return(0); }