int commandlineseed(char **seeds) { unsigned int seed2; seed2 = atoi(seeds[0]); printf("\n%u\n", seed2); dsfmt_gv_init_gen_rand(seed2); return 1; }
void random_open(uint32_t seed, int set_rand_array_size) { dsfmt_gv_init_gen_rand(seed); int min_rand_array_size = dsfmt_get_min_array_size(); rand_array_size = fmax(min_rand_array_size, set_rand_array_size); rand_array = (double*) malloc(sizeof(double)*rand_array_size); random_update_array(); }
int main(int ac, char *av[]) { if (ac == 1) { printf("Usage: randmtzig <n>\n"); return (-1); } int n = atoi(av[1]); time_t t1; dsfmt_gv_init_gen_rand(0); double *p; posix_memalign((void **)&p, 16, n*sizeof(double)); uint32_t *u; posix_memalign((void **)&u, 16, 2*n*sizeof(uint32_t)); t1 = clock(); dsfmt_gv_fill_array_close_open(p, n); printf("Uniform fill (n): %f\n", (clock() - t1) / (double) CLOCKS_PER_SEC); t1 = clock(); for (int i = 0; i < n; i++) p[i] = dsfmt_gv_genrand_close_open(); printf("Uniform (n): %f\n", (clock() - t1) / (double) CLOCKS_PER_SEC); t1 = clock(); for (int i = 0; i < 2*n; i++) u[i] = dsfmt_gv_genrand_uint32(); printf("Uniform 32-bit ints (2*n): %f\n", (clock() - t1) / (double) CLOCKS_PER_SEC); memset((void *)p, 0, n*sizeof(double)); t1 = clock(); for (int i = 0; i < n; i++) p[i] = randmtzig_gv_randn(); printf("Normal (n): %f\n", (clock() - t1) / (double) CLOCKS_PER_SEC); for (int i = 0; i < 10; i++) printf("%lf\n", p[i]); return 0; }
void rand_seed(ru32 s, void *d) { // get time seed if( s == 0 ) { s = rand_time_seed(d); } // set seed if( d == NULL ) { dsfmt_gv_init_gen_rand(s); } else { dsfmt_t *p = (dsfmt_t*) d; dsfmt_init_gen_rand(p, s); } }
void seedit(const char *flag) { FILE *pfseed; unsigned int seed2; if (flag[0] == 's') { pfseed = fopen("/dev/urandom", "rb"); if (pfseed) { fread(&seed2, sizeof(seed2), 1, pfseed); fclose(pfseed); } else { printf("Cannot open /dev/urandom\n"); exit(1); } /*seed2 = time(NULL);*/ dsfmt_gv_init_gen_rand(seed2); printf("\n%u\n", seed2); } }
int main(int argc, char *argv[]) { // 乱数初期化 dsfmt_init_gen_rand(&dsfmt, 0); dsfmt_gv_init_gen_rand(0); // 周りの環境でクリップする Polygon_2 world; world.push_back(Polygon_2::Point_2(1, 1)); world.push_back(Polygon_2::Point_2(2400, 1)); world.push_back(Polygon_2::Point_2(2400, 2400)); world.push_back(Polygon_2::Point_2(1, 2400)); #include "treedata.inc" /* world.push_back(Polygon_2::Point_2(500.0, 0.0)); world.push_back(Polygon_2::Point_2(1000.0, 1000.0)); world.push_back(Polygon_2::Point_2(0.0, 1000.0)); TreeNode tn1("tn1", 500); TreeNode tn2("tn2", 100); TreeNode tn3("tn3", 300); TreeNode tn4("tn4", 400); TreeNode tn5("tn5", 800); TreeNode tn6("tn6", 400); TreeNode tnroot("root", 0); tnroot.add_child(tn1); tnroot.add_child(tn2); tnroot.add_child(tn3); tnroot.add_child(tn4); tnroot.add_child(tn5); tnroot.add_child(tn6); #define ROOT_TREE_NODE tnroot */ ROOT_TREE_NODE.region = world; voronoi_treemap(ROOT_TREE_NODE); ROOT_TREE_NODE.draw(); }
int main() { // Initialize RNG dsfmt_gv_init_gen_rand(0); double t, tmin; // fib(20) assert(fib(20) == 6765); int f = 0; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); f += fib(20); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("fib", tmin); // parse_bin tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); char s[11]; for (int k=0; k<1000; ++k) { uint32_t n = dsfmt_gv_genrand_uint32(); sprintf(s, "%x", n); uint32_t m = (uint32_t)parse_int(s, 16); assert(m == n); } t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("parse_int", tmin); // // array constructor // tmin = INFINITY; // for (int i=0; i<NITER; ++i) { // t = clock_now(); // double *a = ones(200,200); // free(a); // t = clock_now()-t; // if (t < tmin) tmin = t; // } // print_perf("ones", tmin); // // // A*A' // //SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC) // double *b = ones(200, 200); // tmin = INFINITY; // for (int i=0; i<NITER; ++i) { // t = clock_now(); // double *c = matmul_aat(200, b); // free(c); // t = clock_now()-t; // if (t < tmin) tmin = t; // } // free(b); // print_perf("AtA", tmin); // mandel int mandel_sum; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); mandel_sum = mandelperf(); t = clock_now()-t; if (t < tmin) tmin = t; } assert(mandel_sum == 14719); print_perf("mandel", tmin); // sort tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); double *d = myrand(5000); quicksort(d, 0, 5000-1); free(d); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("quicksort", tmin); // pi sum double pi; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); pi = pisum(); t = clock_now()-t; if (t < tmin) tmin = t; } assert(fabs(pi-1.644834071848065) < 1e-12); print_perf("pi_sum", tmin); // rand mat stat struct double_pair r; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); r = randmatstat(1000); t = clock_now()-t; if (t < tmin) tmin = t; } // assert(0.5 < r.s1 && r.s1 < 1.0 && 0.5 < r.s2 && r.s2 < 1.0); print_perf("rand_mat_stat", tmin); // rand mat mul tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); double *C = randmatmul(1000); assert(0 <= C[0]); free(C); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("rand_mat_mul", tmin); // printfd tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); printfd(100000); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("printfd", tmin); return 0; }
int main() { // Initialize RNG dsfmt_gv_init_gen_rand(0); double t, tmin; // fib(20) assert(fib(20) == 6765); int f = 0; tmin = INFINITY; volatile int fibarg = 20; // prevent constant propagation for (int i=0; i<NITER; ++i) { t = clock_now(); for (int j = 0; j < 1000; j++) f += fib(fibarg); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("fib", tmin / 1000); // parse_bin tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); char s[11]; for (int k=0; k<1000 * 100; ++k) { uint32_t n = dsfmt_gv_genrand_uint32(); sprintf(s, "%x", n); uint32_t m = (uint32_t)parse_int(s, 16); assert(m == n); } t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("parse_int", tmin / 100); // // array constructor // tmin = INFINITY; // for (int i=0; i<NITER; ++i) { // t = clock_now(); // double *a = ones(200,200); // free(a); // t = clock_now()-t; // if (t < tmin) tmin = t; // } // print_perf("ones", tmin); // // // A*A' // //SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC) // double *b = ones(200, 200); // tmin = INFINITY; // for (int i=0; i<NITER; ++i) { // t = clock_now(); // double *c = matmul_aat(200, b); // free(c); // t = clock_now()-t; // if (t < tmin) tmin = t; // } // free(b); // print_perf("AtA", tmin); // mandel /* The initialization on the next line is deliberately volatile to * prevent gcc from optimizing away the entire loop. * (First observed in gcc 4.9.2) */ static volatile int mandel_sum_init = 0; int mandel_sum2 = mandel_sum_init; tmin = INFINITY; for (int i=0; i<NITER; ++i) { int *M; t = clock_now(); for (int j = 0; j < 100; j++) { M = mandelperf(); if (j == 0) { int mandel_sum = 0; // for (int ii = 0; ii < 21; ii++) { // for (int jj = 0; jj < 26; jj++) { // printf("%4d", M[26*ii + jj]); // } // printf("\n"); // } for (int k = 0; k < 21*26; k++) { mandel_sum += M[k]; } assert(mandel_sum == 14791); mandel_sum2 += mandel_sum; } free(M); } t = clock_now()-t; if (t < tmin) tmin = t; } assert(mandel_sum2 == 14791 * NITER); print_perf("mandel", tmin / 100); // sort tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); double *d = myrand(5000); quicksort(d, 0, 5000-1); free(d); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("quicksort", tmin); // pi sum double pi; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); pi = pisum(); t = clock_now()-t; if (t < tmin) tmin = t; } assert(fabs(pi-1.644834071848065) < 1e-12); print_perf("pi_sum", tmin); // rand mat stat struct double_pair r; tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); r = randmatstat(1000); t = clock_now()-t; if (t < tmin) tmin = t; } // assert(0.5 < r.s1 && r.s1 < 1.0 && 0.5 < r.s2 && r.s2 < 1.0); print_perf("rand_mat_stat", tmin); // rand mat mul tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); double *C = randmatmul(1000); assert(0 <= C[0]); free(C); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("rand_mat_mul", tmin); // printfd tmin = INFINITY; for (int i=0; i<NITER; ++i) { t = clock_now(); printfd(100000); t = clock_now()-t; if (t < tmin) tmin = t; } print_perf("printfd", tmin); return 0; }