int main(int argc, char **argv) { preamble(stdout); body(stdin, stdout); postamble(stdout); exit(0); }
void dvimain() { postamble(); /* seek and process the postamble */ /* note that walkpages *must* immediately follow preamble */ preamble(); /* process preamble */ walkpages(); /* time to do the actual work! */ } /* dvimain */
jit_bnorm_t(const batch_normalization_pd_t *bdesc): bdesc_(bdesc) { static_assert(isa == avx2 || isa == avx512_core, "unsupported isa"); simd_w_ = cpu_isa_traits<isa>::vlen / sizeof(float); preamble(); compute_predefined_variables(); load_common_params(); if (isa == avx512_core) { prepare_tail_mask_avx512(); forward_avx512(); } else if (isa == avx2) { prepare_tail_mask_avx2(); forward_avx2(); } postamble(); ker = reinterpret_cast<decltype(ker)>(const_cast<uint8_t*>( this->getCode())); }
int main () { //global timing clock_t start_g=clock(), diff_g; //////////////////////////test function starts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ char buffer[1024]; FILE *fp = fopen("dist.in", "r"); int num, i; char comment[20]; char arr_data[800]; int fin_num; for(i=0; i<799; i++) { arr_data[i] = 'x'; } int run = 0; //read file into num of test, comments and number char array while (fgets(buffer, sizeof(buffer), fp) != NULL) { sscanf(buffer, "%i;%s %s", &num, comment, arr_data); printf( "\n%i: %s\n", num, arr_data ); int k = 0; //count the number of numbers in the char array int num_count = 1; //one comma less then numbers while(arr_data[k] != 0 ) { if(arr_data[k] == ',') { num_count++; } k++; } printf("Nums in the array: %i", num_count); //initialise double array int data[num_count]; // = {[0 ... num_coun] = 0}; //converting char array to int array int acc_len = 0; for(i=0; i<num_count; i++) { fin_num = 0; int num_len = 0; while(arr_data[acc_len+num_len] != ',' && arr_data[acc_len+num_len] != 0) { num_len++; } //printf("\n%i's num lenght is %i ,", i, num_len); acc_len = acc_len + num_len +1; //printf(" start of next number is %i", acc_len); int decim; for(decim = acc_len - num_len -1; decim < acc_len -1; decim++) { int d = arr_data[decim] - '0'; int pow_c; int out = 1; for(pow_c = 0; pow_c <acc_len-decim-2; pow_c++) { out = out*10; } //printf("\nNumber %i for %i", out*d, d); //(acc_len-decim-2) fin_num = fin_num + out*d; //printf("\nResulting number: \n%i on inter %i", fin_num, decim); if(decim == acc_len -2) { data[i] = fin_num; //printf("NUM FROM ARRAY: %i", data[i]); } } //printf("\n"); } printf("\nPrinting array as int array: "); for(i=0; i<num_count; i++) { printf("%i,", data[i]); } printf("\n"); //transferring data to X array int X[num_count]; for(i=0; i<num_count; i++) { X[i] = data[i]; } //////////////////////////test function ends\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ int x_n = (int)(sizeof(X)/sizeof(*X)); int depth = (int) ((log(x_n)+0.1)/log(2)); double tree[depth][x_n]; double cdf[x_n]; int histogram[sizeof(X)/sizeof(*X)] ; int ddd; for (ddd=0; ddd<x_n; ddd++) { histogram[ddd] =0; } int hist[sizeof(X)/sizeof(*X)] ; int step_size; int num_of_points; int position_num; int i, j; //pdf to cdf cdf[0] = X[0]; for (i = 1; i < x_n; i++) { cdf[i] = cdf[i - 1] + X[i]; } //normalised cdf for (i = 0; i < x_n; i++) { cdf[i] = cdf[i]/cdf[x_n-1]; } //print cdf printf("cdf: "); for(i = 0; i < x_n; i++) { printf("%g ", cdf[i]); } printf("\n"); // cdf to tree array printf("TREE OUTPUT:\n "); for(i = 0; i < depth; i++) { step_size = x_n/pow(2, i); num_of_points = pow(2, i); position_num; for(j = 0; j < num_of_points; j++) { if(j == 0) { position_num = step_size *(j + 1)* 0.5 - 1; } else { position_num = step_size *j + step_size * 0.5 - 1; } tree[i][j] = cdf[position_num]; printf(" %g |", tree[i][j]); } printf("\n"); } printf("\n"); //tree array check /* for ( i = 0; i < depth; i++ ) { printf("\n"); for ( j = 0; j < x_n; j++ ) { printf("T[%d][%d] = %f ", i,j, tree[i][j] ); } } */ // tree walk int err_count = 0; int jj; //global timing #if(MODE) sgenrand(5UL); clock_t diff_tr, start_tr = clock(); int curr_pos; for(jj=0; jj<RUNS; jj++) { size = 0; #if (1-MODE_BSF) #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if(lattice[DROP_LOCATION] == 0) { lattice[DROP_LOCATION] = 1; } else { PUSH(DROP_LOCATION); PUSH(DROP_LOCATION); lattice[DROP_LOCATION] = 0; size++; } /* If validated, optimse by turning stack operations into macros, * optime random number drawing (rather than having doubles in the tree * have integers there and draw an integer to compare against), * optimise the shuffling of particles. * * I have added MOMENT macros for size. */ while(stack_used != 0) { POP(curr_pos); /* This code with the "check" looks clumsy. I suppose * you are "following through" topplings? I would think * there is no point doing this later. Anyway, we validate * this code and take it from there. */ double test_num = genrand() * cdf[x_n - 1]; //tree walk int x_pos = 0, y_pos = 0; for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) { x_pos = (x_pos+1) * 2 - 1; } else { x_pos = x_pos * 2; } //printf("\nThe current position is : %i, %i", y_pos, x_pos); } //histogram[x_pos]++; curr_pos = curr_pos+ x_pos; //move_ball(curr_pos); if((curr_pos>=0) && (curr_pos<LENGTH)) { if(lattice[curr_pos] == 0) { lattice[curr_pos] = 1; } else { size++; lattice[curr_pos] = 0; PUSH(curr_pos); } } else { break; } } while( (lattice[curr_pos] != 1)); }/* end of while(stack_used != 0) look */ #endif diff_tr = clock() - start_tr;; int msec_tr = ((double)diff_tr)*((double)1000)/((double)CLOCKS_PER_SEC); printf("\nThe tree cycle timing: %d seconds and %d milsec", msec_tr/1000, msec_tr%1000); //printf("testnum %g\n", test_num); printf("\nTREE MODE"); MOMENTS(size,size); #endif // check using scan of the cdf array -- TEST #if(1-MODE) sgenrand(5UL); for(jj=0; jj<RUNS; jj++) { int cluster = 0; double test_num = genrand() * cdf[x_n - 1]; while(test_num > cdf[cluster]) { cluster++; } histogram[cluster]++; } printf("\nWHILE MODE"); #endif diff_g = clock()-start_g; int msec_g = ((double)diff_g)*((double)1000)/((double)CLOCKS_PER_SEC); printf("\nThe global cycle timing: %d seconds and %d milsec", msec_g/1000, msec_g%1000); //printf("testnum %g\n", test_num); printf("\nGLOBAL\n"); //printf("cluster: %i\n", cluster); /*if(0) if(cluster != x_pos) { printf("\nThe drawn number is: %f", test_num); printf("\nTree dislocation is: %i", x_pos ); printf("\nTest dislocation: %i \n", cluster ); err_count++; }*/ printf("\nERRORS: %i \n", err_count); for (i=0; i<x_n; i++) printf("histogram[%i] %i\n", i, histogram[i]); for(i=0; i<799; i++) { arr_data[i] = 'x'; //clean up the arr_data } printf("\n"); run++; } fclose(fp); MOMENTS_OUT(size); postamble(); } // MAIN END
int main(int argc, char *argv[]) { //global timing clock_t start_g=clock(), diff_g; //////////////////////////test function starts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ char buffer[1024]; FILE *fp = fopen("dist.in", "r"); int num, i; char comment[20]; char arr_data[800]; int fin_num; for(i=0; i<799; i++){arr_data[i] = 'x';} int run = 0; //read file into num of test, comments and number char array while (fgets(buffer, sizeof(buffer), fp) != NULL) { sscanf(buffer, "%i;%s %s", &num, comment, arr_data); printf( "\n%i: %s\n", num, arr_data ); int k = 0; //count the number of numbers in the char array int num_count = 1; //one comma less then numbers while(arr_data[k] != 0 ) { if(arr_data[k] == ',') {num_count++;} k++; } printf("Nums in the array: %i", num_count); //initialise double array int data[num_count]; // = {[0 ... num_coun] = 0}; //converting char array to int array int acc_len = 0; for(i=0; i<num_count; i++){ fin_num = 0; int num_len = 0; while(arr_data[acc_len+num_len] != ',' && arr_data[acc_len+num_len] != 0){num_len++;} //printf("\n%i's num lenght is %i ,", i, num_len); acc_len = acc_len + num_len +1; //printf(" start of next number is %i", acc_len); int decim; for(decim = acc_len - num_len -1; decim < acc_len -1; decim++){ int d = arr_data[decim] - '0'; int pow_c; int out = 1; for(pow_c = 0; pow_c <acc_len-decim-2; pow_c++) {out = out*10;} //printf("\nNumber %i for %i", out*d, d); //(acc_len-decim-2) fin_num = fin_num + out*d; //printf("\nResulting number: \n%i on inter %i", fin_num, decim); if(decim == acc_len -2) { data[i] = fin_num; //printf("NUM FROM ARRAY: %i", data[i]); } } //printf("\n"); } printf("\nPrinting array as int array: "); for(i=0; i<num_count; i++){ printf("%i,", data[i]);} printf("\n"); //transferring data to X array int X[num_count]; for(i=0; i<num_count; i++){ X[i] = data[i];} //////////////////////////end of file to array parsing\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ int x_n = (int)(sizeof(X)/sizeof(*X)); int depth = (int) ((log(x_n)+0.1)/log(2)); double tree[depth][x_n]; double cdf[x_n]; int histogram[sizeof(X)/sizeof(*X)] ; int ddd; for (ddd=0; ddd<x_n; ddd++) {histogram[ddd] =0;} int hist[sizeof(X)/sizeof(*X)] ; int step_size; int num_of_points; int position_num; int i, j; //pdf to cdf cdf[0] = X[0]; for (i = 1; i < x_n; i++) { cdf[i] = cdf[i - 1] + X[i]; } //normalised cdf for (i = 0; i < x_n; i++) { cdf[i] = cdf[i]/cdf[x_n-1]; } //print cdf printf("cdf: "); for(i = 0; i < x_n; i++) { printf("%g ", cdf[i]); } printf("\n"); // cdf to tree array printf("TREE OUTPUT:\n "); for(i = 0; i < depth; i++) { step_size = x_n/pow(2, i); num_of_points = pow(2, i); position_num; for(j = 0; j < num_of_points; j++) { if(j == 0) {position_num = step_size *(j + 1)* 0.5 - 1;} else {position_num = step_size *j + step_size * 0.5 - 1;} tree[i][j] = cdf[position_num]; printf(" %g |", tree[i][j]); } printf("\n"); } printf("\n"); //tree array check /* for ( i = 0; i < depth; i++ ) { printf("\n"); for ( j = 0; j < x_n; j++ ) { printf("T[%d][%d] = %f ", i,j, tree[i][j] ); } } */ // tree walk //int err_count = 0; int jj; //global timing //sgenrand(time(NULL)); int curr_pos, check; int chunk; /* Repeat experiment in chunks. */ srand(SEED); printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n"); preamble(argc, argv); PRINT_PARAM(SEED, "%lu"); PRINT_PARAM(LENGTH, "%lu"); PRINT_PARAM(DROP_LOCATION, "%lu"); PRINT_PARAM(total_malloced, "%lli"); printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n"); printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.); for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) { MOMENTS_INIT(size); for (drop = 0; drop < N_ROLLS; drop++) { // big droppping cycle long long int size=0; #if (0) #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if(lattice[DROP_LOCATION] == 0) { lattice[DROP_LOCATION] = 1; } else { PUSH(DROP_LOCATION); PUSH(DROP_LOCATION); lattice[DROP_LOCATION] = 0; size++; } /* If validated, optimse by turning stack operations into macros, * optime random number drawing (rather than having doubles in the tree * have integers there and draw an integer to compare against), * optimise the shuffling of particles. * * I have added MOMENT macros for size. */ while(stack_used != 0) { POP(curr_pos); /* This code with the "check" looks clumsy. I suppose * you are "following through" topplings? I would think * there is no point doing this later. Anyway, we validate * this code and take it from there. */ do { double test_num = ((double)rand())/((double)RAND_MAX); //tree walk int x_pos = 0, y_pos = 0; for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) {x_pos = (x_pos+1) * 2 - 1; } else {x_pos = x_pos * 2;} //printf("\nThe current position is : %i, %i", y_pos, x_pos); } curr_pos = curr_pos+ x_pos-1; //move_ball(curr_pos); //printf("\nshift: %i, RAND: %f", x_pos-1, test_num); if((curr_pos>=0) && (curr_pos<LENGTH)) { if(lattice[curr_pos] == 0) { lattice[curr_pos] = 1; } else { size++; lattice[curr_pos] = 0; PUSH(curr_pos); } } else {break;} }while( (lattice[curr_pos] != 1)); }/* end of while(stack_used != 0) look */ #endif #if (1) { int npos; #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if (lattice[DROP_LOCATION]++==1) { PUSH(DROP_LOCATION); while(stack_used) { POP(curr_pos); do { size++; lattice[curr_pos]-=2; double test_num = ((double)rand())/((double)RAND_MAX); // start of tree walk //tree walk int x_pos = 0, y_pos = 0; for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) {x_pos = (x_pos+1) * 2 - 1; } else {x_pos = x_pos * 2;} //printf("\nThe current position is : %i, %i", y_pos, x_pos); } npos = curr_pos+ x_pos-1; //move_ball(curr_pos); //end of tree walk if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } test_num = ((double)rand())/((double)RAND_MAX); // start of tree walk //tree walk x_pos = 0, y_pos = 0; for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) {x_pos = (x_pos+1) * 2 - 1; } else {x_pos = x_pos * 2;} //printf("\nThe current position is : %i, %i", y_pos, x_pos); } npos = curr_pos+ x_pos-1; //move_ball(curr_pos); //end of tree walk if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } } while (lattice[curr_pos]>1); } } } #endif //printf("size is %i\n", size); MOMENTS(size,size); } /* end of iterations loop */ MOMENTS_OUT(size); } /* chunk */ postamble(); } }
int main(int argc, char *argv[]) { //sgenrand(time(NULL)); int k, curr_pos, check; int chunk; /* Repeat experiment in chunks. */ srand(SEED); printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n"); preamble(argc, argv); PRINT_PARAM(SEED, "%lu"); PRINT_PARAM(LENGTH, "%lu"); PRINT_PARAM(DROP_LOCATION, "%lu"); PRINT_PARAM(total_malloced, "%lli"); printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n"); printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.); for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) { MOMENTS_INIT(size); for (drop = 0; drop < N_ROLLS; drop++) { // big droppping cycle size=0; /* printf("(%i.)", drop); for(k = 0; k<LENGTH; k++) { printf("\%i", lattice[k]); } printf("\n"); */ #if (1) if(check_cell(DROP_LOCATION) == 0) { lattice[DROP_LOCATION] = 1; } else { stack_push(DROP_LOCATION); stack_push(DROP_LOCATION); lattice[DROP_LOCATION] = 0; } /* If validated, optimse by turning stack operations into macros, * optime random number drawing (rather than having doubles in the tree * have integers there and draw an integer to compare against), * optimise the shuffling of particles. * * I have added MOMENT macros for size. */ while(stack_used != 0) { curr_pos = stack_pop(); /* This code with the "check" looks clumsy. I suppose * you are "following through" topplings? I would think * there is no point doing this later. Anyway, we validate * this code and take it from there. */ do { curr_pos = move_ball(curr_pos); if(curr_pos >= LENGTH || curr_pos < 0) { check = 0 ; } /* Why not just "else" instead of the "if"? */ if(curr_pos < LENGTH && curr_pos >= 0) { check = check_cell(curr_pos); if (check == 1) { stack_push(curr_pos); } else { check = 0; } } }while(check != 0); }/* end of while(stack_used != 0) look */ #endif #if (0) { int npos; #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if (lattice[DROP_LOCATION]++==1) { PUSH(DROP_LOCATION); while(stack_used) { size++; POP(curr_pos); do { lattice[curr_pos]-=2; npos=curr_pos+ ( (rand()>RAND_MAX/2) ? 1 : -1); if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } } while (lattice[curr_pos]>1); } } } #endif //printf("size is %i\n", size); MOMENTS(size,size); } /* end of iterations loop */ MOMENTS_OUT(size); } /* chunk */ postamble(); }
DgOutGeoJSONFile::~DgOutGeoJSONFile() { postamble(); close(); }
int main () { //////////////////////////test function starts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ char buffer[1024]; FILE *fp = fopen("test.dat", "r"); int num, i; char comment[20]; char arr_data[800]; int fin_num; for(i=0; i<799; i++){arr_data[i] = 'x';} int run = 0; //read file into num of test, comments and number char array while (fgets(buffer, sizeof(buffer), fp) != NULL) { sscanf(buffer, "%i;%s %s", &num, comment, arr_data); printf( "\n%i: %s\n", num, arr_data ); int k = 0; //count the number of numbers in the char array int num_count = 1; //one comma less then numbers while(arr_data[k] != 0 ) { if(arr_data[k] == ',') {num_count++;} k++; } printf("Nums in the array: %i", num_count); //initialise double array int data[num_count]; // = {[0 ... num_coun] = 0}; //converting char array to int array int acc_len = 0; for(i=0; i<num_count; i++){ fin_num = 0; int num_len = 0; while(arr_data[acc_len+num_len] != ',' && arr_data[acc_len+num_len] != 0){num_len++;} //printf("\n%i's num lenght is %i ,", i, num_len); acc_len = acc_len + num_len +1; //printf(" start of next number is %i", acc_len); int decim; for(decim = acc_len - num_len -1; decim < acc_len -1; decim++){ int d = arr_data[decim] - '0'; int pow_c; int out = 1; for(pow_c = 0; pow_c <acc_len-decim-2; pow_c++) {out = out*10;} //printf("\nNumber %i for %i", out*d, d); //(acc_len-decim-2) fin_num = fin_num + out*d; //printf("\nResulting number: \n%i on inter %i", fin_num, decim); if(decim == acc_len -2) { data[i] = fin_num; //printf("NUM FROM ARRAY: %i", data[i]); } } //printf("\n"); } printf("\nPrinting array as int array: "); for(i=0; i<num_count; i++){ printf("%i,", data[i]);} printf("\n"); //transferring data to X array int X[num_count]; for(i=0; i<num_count; i++){ X[i] = data[i];} //////////////////////////test function ends\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ int x_n = (int)(sizeof(X)/sizeof(*X)); int depth = (int) ((log(x_n)+0.1)/log(2)); double tree[depth][x_n]; double cdf[x_n]; int histogram[sizeof(X)/sizeof(*X)] ; //={0} int hist[sizeof(X)/sizeof(*X)] ; int step_size; int num_of_points; int position_num; int i, j; //pdf to cdf cdf[0] = X[0]; for (i = 1; i < x_n; i++) { cdf[i] = cdf[i - 1] + X[i]; } //print cdf printf("cdf: "); for(i = 0; i < x_n; i++) { printf("%g ", cdf[i]); } printf("\n"); // cdf to tree array for(i = 0; i < depth; i++) { step_size = x_n/pow(2, i); num_of_points = pow(2, i); position_num; for(j = 0; j < num_of_points; j++) { if(j == 0) {position_num = step_size *(j + 1)* 0.5 - 1;} else {position_num = step_size *j + step_size * 0.5 - 1;} tree[i][j] = cdf[position_num]; printf(" %g |", tree[i][j]); } printf("\n"); } printf("\n"); //tree array check /* for ( i = 0; i < depth; i++ ) { printf("\n"); for ( j = 0; j < x_n; j++ ) { printf("T[%d][%d] = %f ", i,j, tree[i][j] ); } } */ // tree walk int err_count = 0; int jj; sgenrand(5UL); for(jj=0; jj<RUNS; jj++) { //TEST START double test_num = genrand() * cdf[x_n - 1]; //tree walk int x_pos = 0, y_pos = 0; //if (0) { for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) {x_pos = (x_pos+1) * 2 - 1; } else {x_pos = x_pos * 2;} //printf("\nThe current position is : %i, %i", y_pos, x_pos); } //histogram[x_pos]++; //} int cluster = 0; //if (1) { while(test_num > cdf[cluster]) {cluster++;} //hist[cluster]++; //} if(cluster != (x_pos)) { /*printf("\nThe drawn number is: %f", test_num); printf("\nTree dislocation is: %i", x_pos ); printf("\nTest dislocation: %i \n", cluster );*/ err_count++; } } printf("\nERRORS: %i \n", err_count); // } for(i=0; i<799; i++){arr_data[i] = 'x';} //clean up the arr_data printf("\n"); run++; } //////////////////////////test function ends\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ fclose(fp); postamble(); } // MAIN END
int main(int argc, char *argv[]) { int c; int n = 100; int slow = 1; while (EOF != (c = getopt(argc, argv, "dn:s:"))) switch (c) { case 'd': debug = 0; break; case 'n': n = atoi(optarg); break; case 's': slow = atoi(optarg); break; } preamble(stdout); #if 0 /* from left to right */ for (int k = 1; k < n; k++) { func_t *r = rhs(n); flatten(r, k); func_t *s = solution(r, 0); for (int repeat = 0; repeat < slow; repeat++) { showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); } #endif #if 0 /* hierarchically */ int k = 2; while (k < 1024) { func_t *r = rhs(k - 1); func_t *s = solution(r, 0); for (int repeat = 0; repeat < slow; repeat++) { showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); k <<= 1; } #endif /* random addition of points */ int exponent = log2(n); int repeats = 1; n = 1 << (++exponent); // next larger power of 2 func_t *r0 = rhs(n); int *use = (int *)calloc(n, sizeof(int)); for (int k = 1; k <= n; k++) { /* adapt the repeats */ repeats = 32 * pow(2, -k/16.); if (repeats < slow) { repeats = slow; } /* add a new point to the graph */ int index; while (1) { index = random() % n; if (0 == use[index]) { use[index] = 1; r0->highlight = index; break; } } /* mask some of the points in a copy of r0 */ func_t *r = func_copy(r0); double scale = (1. + r->n) / (1. + k); for (int i = 0; i < r->n; i++) { r->f[i] *= scale; r->f[i] *= use[i]; } /* create the associated solution */ func_t *s = solution(r, k); scale = 1/scale; for (int i = 0; i < r->n; i++) { r->f[i] *= scale; } /* display as many copies as necessary */ for (int repeat = 0; (repeat < (slow * repeats)) && (repeat < 25); repeat++) { printf("%% n = %d, figure = %4d, iteration = %4d, " "repeats = %2d, index = %4d\n", n, figcounter, k, repeats, index); showfunctiongraph(stdout, r, s); } func_free(r); func_free(s); } func_free(r0); postamble(stdout); exit(EXIT_SUCCESS); }
int main() { preamble(); while(readline()); postamble(); return 0; }
int main () { //global timing clock_t start_g=clock(), diff_g; //////////////////////////test function starts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ char buffer[1024]; FILE *fp = fopen("dist.in", "r"); int num, i; char comment[20]; char arr_data[800]; int fin_num; for(i=0; i<799; i++){arr_data[i] = 'x';} int run = 0; //read file into num of test, comments and number char array while (fgets(buffer, sizeof(buffer), fp) != NULL) { sscanf(buffer, "%i;%s %s", &num, comment, arr_data); printf( "\n%i: %s\n", num, arr_data ); int k = 0; //count the number of numbers in the char array int num_count = 1; //one comma less then numbers while(arr_data[k] != 0 ) { if(arr_data[k] == ',') {num_count++;} k++; } printf("Nums in the array: %i", num_count); //initialise double array int data[num_count]; // = {[0 ... num_coun] = 0}; //converting char array to int array int acc_len = 0; for(i=0; i<num_count; i++){ fin_num = 0; int num_len = 0; while(arr_data[acc_len+num_len] != ',' && arr_data[acc_len+num_len] != 0){num_len++;} //printf("\n%i's num lenght is %i ,", i, num_len); acc_len = acc_len + num_len +1; //printf(" start of next number is %i", acc_len); int decim; for(decim = acc_len - num_len -1; decim < acc_len -1; decim++){ int d = arr_data[decim] - '0'; int pow_c; int out = 1; for(pow_c = 0; pow_c <acc_len-decim-2; pow_c++) {out = out*10;} //printf("\nNumber %i for %i", out*d, d); //(acc_len-decim-2) fin_num = fin_num + out*d; //printf("\nResulting number: \n%i on inter %i", fin_num, decim); if(decim == acc_len -2) { data[i] = fin_num; //printf("NUM FROM ARRAY: %i", data[i]); } } //printf("\n"); } printf("\nPrinting array as int array: "); for(i=0; i<num_count; i++){ printf("%i,", data[i]);} printf("\n"); //transferring data to X array int X[num_count]; for(i=0; i<num_count; i++){ X[i] = data[i];} //////////////////////////test function ends\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ int x_n = (int)(sizeof(X)/sizeof(*X)); int depth = (int) ((log(x_n)+0.1)/log(2)); double tree[depth][x_n]; double cdf[x_n]; int histogram[sizeof(X)/sizeof(*X)] ; int ddd; for (ddd=0; ddd<x_n; ddd++) {histogram[ddd] =0;} int hist[sizeof(X)/sizeof(*X)] ; int step_size; int num_of_points; int position_num; int i, j; //pdf to cdf cdf[0] = X[0]; for (i = 1; i < x_n; i++) { cdf[i] = cdf[i - 1] + X[i]; } //print cdf printf("cdf: "); for(i = 0; i < x_n; i++) { printf("%g ", cdf[i]); } printf("\n"); // cdf to tree array printf("TREE OUTPUT:\n "); for(i = 0; i < depth; i++) { step_size = x_n/pow(2, i); num_of_points = pow(2, i); position_num; for(j = 0; j < num_of_points; j++) { if(j == 0) {position_num = step_size *(j + 1)* 0.5 - 1;} else {position_num = step_size *j + step_size * 0.5 - 1;} tree[i][j] = cdf[position_num]; printf(" %g |", tree[i][j]); } printf("\n"); } printf("\n"); //tree array check /* for ( i = 0; i < depth; i++ ) { printf("\n"); for ( j = 0; j < x_n; j++ ) { printf("T[%d][%d] = %f ", i,j, tree[i][j] ); } } */ // tree walk int err_count = 0; int jj; //global timing #if(MODE) sgenrand(5UL); clock_t diff_tr, start_tr = clock(); for(jj=0; jj<RUNS; jj++) { double test_num = genrand() * cdf[x_n - 1]; //tree walk int x_pos = 0, y_pos = 0; for(y_pos = 0; y_pos < depth ; y_pos++) { if (test_num > tree[y_pos][x_pos]) {x_pos = (x_pos+1) * 2 - 1; } else {x_pos = x_pos * 2;} //printf("\nThe current position is : %i, %i", y_pos, x_pos); } histogram[x_pos]++; } diff_tr = clock() - start_tr;; int msec_tr = ((double)diff_tr)*((double)1000)/((double)CLOCKS_PER_SEC); printf("\nThe tree cycle timing: %d seconds and %d milsec", msec_tr/1000, msec_tr%1000); //printf("testnum %g\n", test_num); printf("\nTREE MODE"); #endif // check using scan of the cdf array -- TEST #if(1-MODE) sgenrand(5UL); for(jj=0; jj<RUNS; jj++) { int cluster = 0; double test_num = genrand() * cdf[x_n - 1]; while(test_num > cdf[cluster]) {cluster++;} histogram[cluster]++; } printf("\nWHILE MODE"); #endif diff_g = clock()-start_g; int msec_g = ((double)diff_g)*((double)1000)/((double)CLOCKS_PER_SEC); printf("\nThe global cycle timing: %d seconds and %d milsec", msec_g/1000, msec_g%1000); //printf("testnum %g\n", test_num); printf("\nGLOBAL\n"); //printf("cluster: %i\n", cluster); /*if(0) if(cluster != x_pos) { printf("\nThe drawn number is: %f", test_num); printf("\nTree dislocation is: %i", x_pos ); printf("\nTest dislocation: %i \n", cluster ); err_count++; }*/ printf("\nERRORS: %i \n", err_count); for (i=0; i<x_n; i++) printf("histogram[%i] %i\n", i, histogram[i]); for(i=0; i<799; i++){arr_data[i] = 'x';} //clean up the arr_data printf("\n"); run++; } fclose(fp); postamble(); } // MAIN END
rdata(void) { char c; char *xcp; char *cmdlinepart = ""; int s, pindex, ipin; long v; loop: s = symb(); if(s == EON) { (void) postamble(); return 1; } if(s == EXTERN) { if (extern_id && strlen(extern_id) > 0) { /* seen -t */ cmdlinepart = malloc(strlen(extern_id) + 1); strcpy(cmdlinepart, extern_id); } else extern_id = malloc(STRLEN); while(isspace(c = gchar())); xcp = extern_id; *xcp++ = toupper(c); while((c = gchar()) != '\n') *xcp++ = toupper(c); *xcp = '\0'; if (strlen(cmdlinepart) > 0) if (strcmp(cmdlinepart, extern_id) != 0) fprint(2, "warning: -t %s and .x %s don't agree\n", cmdlinepart, extern_id); else; else (void) rdlibrary(); goto loop; } if(s == ITER) { fprint(2, ".r"); for(;;) { c = gchar(); if(c < 0) goto loop; fprint(2, "%c", (char) c); if(c == '\n') goto loop; } } if(s != OUT) expect(".o"); if (!extern_id || (strlen(extern_id) == 0)) expect(".x"); s = symb(); if(s != NUMB) expect("output pin"); opin = numb; if (opin > MAXPIN) { fprint(2, "output pin %d > MAXPIN! Time to recompile!\n", opin); exit(1); } if (!(pin_array[opin].properties & OUTPUT_TYPE)) fprint(2, "output pin %d not found\n", opin); if (pin_array[opin].flags & USED_FLAG) fprint(2, "pin %d already used\n", opin); pin_array[opin].flags |= USED_FLAG; if (iflag) fprint(2, "\n.o %d", opin); for(pindex=0;;) { s = symb(); if(s != NUMB) break; /*??*/ if(s == NAME) { fprint(2, "name %s unexpected", name); continue; } ipin = numb; if (!(pin_array[ipin].properties & INPUT_TYPE)) { fprint(2, "pin %d isn't an input\n", ipin); continue; } if (pindex > NINPUTS) { fprint(2, "too many inputs (NINPUTS too small)\n"); exit(0); } input_pin[pindex++] = ipin; if (iflag) fprint(2, " %d", ipin); } input_pin[pindex] = 0; if (iflag) fprint(2, "\n"); if(s != LINE) expect("new line"); nimp = 0; for(;;) { s = symb(); if(s == LINE) continue; if(s != NUMB) break; v = numb; c = symb(); if(c != COLON && c != PERC) expect(":"); s = symb(); if(s != NUMB) expect("number"); if(c == PERC) { expect("code for %"); /* tee hee */ continue; } if(nimp >= NIMP) { fprint(2, "buffer[IMP] too small\n"); exit(1); } if (iflag) fprint(2, " %d:%d", v, numb); imp[nimp].val = v; imp[nimp].mask = numb; nimp++; } if (iflag) fprint(2, "\n"); peeks = s; return 0; }