int main(int argc, char* argv[]) { clock_t start, stop; start = clock(); int v = atoi(argv[1]); printf("The random seed is: %d \n", v); srand(v); uint32_t gen = v; uint32_t *Pgen= &gen; int i; struct Lev ls[100]; int lenLS=0; for (i=0; i<100; i++) { struct Room rs[100]; int lenrs=0; int *Plenrs = &lenrs; int ii; for (ii=0;ii<50000;ii++){ MakeRoom(rs,Plenrs,Pgen); if(lenrs==99){ break; } } struct Tile ts[2500]; for (ii=0;ii<2500;ii++){ ts[ii].X=ii%TileDim; ts[ii].Y=ii/TileDim; ts[ii].T=0; } for (ii=0;ii<lenrs;ii++){ Room2Tiles(&(rs[ii]),ts); } struct Lev l; memcpy(l.rs,rs,sizeof(rs)); memcpy(l.ts,ts,sizeof(ts)); l.lenrs=lenrs; ls[lenLS]=l; lenLS++; } struct Lev templ; templ.lenrs=0; for(i=0;i<100;i++){ if(ls[i].lenrs>templ.lenrs) templ=ls[i]; } PrintLev(&templ); stop = clock(); long clocks_per_ms = CLOCKS_PER_SEC/1000; printf("%ld\n", (stop - start)/clocks_per_ms); return 0; }
int main(int argc, char* argv[]) { clock_t start, stop; start = clock(); int v = atoi(argv[1]); printf("The random *gen is: %d \n", v); srand(v); uint32_t gen = v; pthread_t threads[NumThreads]; int i; for (i=0;i<NumThreads;i++){ pthread_t thread; threads[i] = thread; gens[i] = gen * (i+1)*(i+1); printf("The *gen of thread %d is:%d \n",i+1,gens[i]); } int constints[NumThreads]; for (i=0;i<NumThreads;i++){ constints[i]=i; } for (i=0;i<NumThreads;i++){ if(pthread_create(&threads[i], NULL, MakeLevs, &constints[i])) { fprintf(stderr, "Error creating thread\n"); return 1; } } for (i=0;i<NumThreads;i++){ if(pthread_join(threads[i], NULL)) { fprintf(stderr, "Error joining thread\n"); return 2; } } struct Lev templ; templ.lenrs=0; for(i=0;i<100;i++){ if(ls[i].lenrs>templ.lenrs) templ=ls[i]; } PrintLev(&templ); stop = clock(); long clocks_per_ms = CLOCKS_PER_SEC/1000; printf("%ld\n", ((stop - start)/clocks_per_ms)/NUM_THREADS); return 0; }