int main(int argc, char *argv[]) { int ret, fd; ret = MPI_Init(&argc, &argv); if (ret != MPI_SUCCESS) { fprintf(stderr, "MPI_Init failed: %d\n", ret); exit(1); } if (parse_opts(argc, argv)) usage(); if (gethostname(hostname, HOSTNAME_SIZE) < 0) { fprintf(stderr, "gethostname failed: %s\n", strerror(errno)); exit(1); } ret = MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (ret != MPI_SUCCESS) abort_printf("MPI_Comm_rank failed: %d\n", ret); ret = MPI_Comm_size(MPI_COMM_WORLD, &num_procs); if (ret != MPI_SUCCESS) abort_printf("MPI_Comm_size failed: %d\n", ret); if (num_procs > 20 || num_procs < 2) abort_printf("Process count should be between 2 and 20\n"); printf("%s: rank: %d, procs: %d, filename \"%s\"\n", hostname, rank, num_procs, filename); num_blocks = num_procs; local_pattern = calloc(1, blocksize); tmpblock = calloc(1, blocksize); if (!local_pattern || !tmpblock) abort_printf("No memory to allocate pattern!\n"); srand(getpid()); fd = prep_file(); for (this_pass = 0; this_pass < max_passes; this_pass++) { write_verify_blocks(fd); if ((startchar + num_procs) > 'z') startchar = 'a'; else startchar++; } end_test(fd); MPI_Finalize(); return 0; }
int main(int argc, char *argv[]) { int ret = 0; ret = parse_opts(argc, argv); if (ret) { usage(); return ret; } ret = prep_file(filename, filesize, chunksize, keep); return ret; }
void PROCout( Procedure p ) { prep_file(); PROC_out( p, 0 ); finish_file(); }
void RULEout( Rule r ) { prep_file(); RULE_out( r, 0 ); finish_file(); }
void SCHEMAref_out( Schema s ) { prep_file(); REFout( s->u.schema->usedict, s->u.schema->use_schemas, "USE", 0 ); REFout( s->u.schema->refdict, s->u.schema->ref_schemas, "REFERENCE", 0 ); finish_file(); }
void STMTout( Statement s ) { prep_file(); STMT_out( s, 0 ); finish_file(); }
// calculates all the stats void calc_stat(int k, int r) { double xm, pm, dxim, dsim, pun_im, pun_jm; int h, g; double *xsum, *pisum, *dxisum, *dsisum, *pun_isum, *pun_jsum; #if ALLDATAFILE int j; static FILE **fp = NULL; // file pointers for individual run double spi_g = 0; // sum of payoffs for individual run if(k < 0){ for (h = 7; h--; fclose(fp[h])); free(fp); return; } if(!k){ char ixdata[200], ifdata[200], ipi_gdata[200], idxidata[200], idsidata[200], ipun_idata[200], ipun_jdata[200], tstr[100]; fp = malloc(7*sizeof(FILE *)); sprintf(tstr, "e%d.dat", r); prep_file(ixdata, tstr); sprintf(tstr, "f%d.dat", r); prep_file(ifdata, tstr); sprintf(tstr, "dxi%d.dat", r); prep_file(idxidata, tstr); sprintf(tstr, "dsi%d.dat", r); prep_file(idsidata, tstr); sprintf(tstr, "pi_g%d.dat", r); prep_file(ipi_gdata, tstr); sprintf(tstr, "pun_i%d.dat", r); prep_file(ipun_idata, tstr); sprintf(tstr, "pun_j%d.dat", r); prep_file(ipun_jdata, tstr); fp[0] = fopen(ixdata, "w"); fp[1] = fopen(ifdata, "w"); fp[2] = fopen(idxidata, "w"); fp[3] = fopen(idsidata, "w"); fp[4] = fopen(ipun_idata, "w"); fp[5] = fopen(ipun_jdata, "w"); fp[6] = fopen(ipi_gdata, "w"); } // write headers if( k == 0){ for( j = 0; j < 6; j++){ fprintf(fp[j], "%d\t", 0); for(h = 0; h < N; h++) fprintf(fp[j], "%d\t", h + 1); if(j == 1) fprintf(fp[j], "avg "); // fp[1] used for pi and avg needs to be shown fprintf(fp[j], "\n"); } } for( j = 0; j < 7; j++) fprintf(fp[j], "%d\t", (int)(k*SKIP)); // write time units #endif // calculate average effort per rank over all groups in each generation xsum = calloc( N,sizeof(double)); pisum = calloc( N,sizeof(double)); dxisum = calloc( N,sizeof(double)); dsisum = calloc( N,sizeof(double)); pun_isum = calloc( N,sizeof(double)); pun_jsum = calloc( N,sizeof(double)); for(g = G; g--; ){ // through each group pun_g[g] = 0; for(h = 0; h < GS[g]; h++){ // through each individual xsum[h] += x[g][h]; // sum of efforts for each rank pisum[h] += Api[g][h]; // sum of payoffs for each rank dxisum[h] += dxi[g][h]; // sum of thresholds for each rank dsisum[h] += dsi[g][h]; // sum of aggressivenes for each rank pun_isum[h] += pun_i[g][h]; pun_jsum[h] += pun_j[g][h]; pun_g[g] += (pun_i[g][h]+pun_j[g][h]); // sum of punishment accrued by individuals in a group } } for(h = 0; h < N; h++){ pm = pisum[h] /(double)(G); // average pay off for each role xm = xsum[h] /(double)(G); // average effort for each role dxim = dxisum[h] /(double)(G); // average threshodl for each role dsim = dsisum[h] /(double)(G); // average aggressiveness for each role pun_im = pun_isum[h] / (double)G; pun_jm = pun_jsum[h] / (double)G; xmean[k][h] += xm; // average effort per role over all groups in addition for no. of runs pimean[k][h] += pm; dximean[k][h] += dxim; // average threshold per role over all groups in addition for no. of runs dsimean[k][h] += dsim; pun_imean[k][h] += pun_im; pun_jmean[k][h] += pun_jm; pi_gmean[k] += pm; // average group payoffs over runs #if ALLDATAFILE spi_g += pm; // average group payoffs over each run // write data for individual runs fprintf(fp[0], "%.4lf ", xm); fprintf(fp[1], "%.4lf ", pm); fprintf(fp[2], "%.4lf ", dxim); fprintf(fp[3], "%.4lf ", dsim); fprintf(fp[4], "%.4lf ", pun_im); fprintf(fp[5], "%.4lf ", pun_jm); #endif } #if ALLDATAFILE fprintf(fp[6], "%.4lf \n", spi_g/N); fprintf(fp[0], "\n"); fprintf(fp[1], "\n"); fprintf(fp[2], "\n"); fprintf(fp[3], "\n"); fprintf(fp[4], "\n"); fprintf(fp[5], "\n"); #endif free(xsum); free(pisum); free(dxisum); free(dsisum); free(pun_isum); free(pun_jsum); }
int main(int argc, char **argv) { #if DEBUG feenableexcept(FE_DIVBYZERO| FE_INVALID|FE_OVERFLOW); // enable exceptions #endif if(argc ^ 2){ printf("Usage: ./sa sa.config\n"); exit(1); } if(read_config(argv[1])){ // read config printf("READDATA: Can't process %s \n", argv[1]); return 1; } T = T+SKIP; // increase T by SKIP to go from 0 to T all the way in time units // precomputing I_Gamma = 1.0/Gamma; I_Alpha = 1.0/Alpha; Bo = B; X0_Be = pow(X0, Beta); GaBe = Gamma * Beta; // event probabilites scaling by G; PE[0] = PE[0]*(double)G; PE[1] = PE[1]*(double)G; PE[2] = PE[2]*(double)G; initrand(Seed); init(); // note: method is in init.c // allocate memory at initial int i, j, ev, k = 0; // m; unsigned long seed; double dt, ct, tt; // tt: time of simulation; dt: delta time after which next event occurs; ct: counter time to check with skip time for stat calculation time_t now; for( i = 0; i < Runs; i++){ tt = 0.0, ct = 0.0; k = 0; //m = 0; if(Seed == 0){ now = time(0); seed = ((unsigned long)now); seed = 1454011037; initrand(seed); printf("\n run: %d rand seed: %lu\n",i+1, seed); } set_init_xrvpi(); // sets initial strategies vector, roles, valuations and payoffs calc_stat(0, i); for( j = 0; j < N; j++) printf("%.4lf ", V[0][j]); printf("\n"); // Gillespie's stochastic simulation while(tt < T){ // calc lambda; lambda = summation of P[j]s for(Lambda = 0, j = EVENTS; j--;) Lambda += PE[j]; // select time for next event dt = randexp(Lambda); //printf("dt: %.4lf\n", dt); // select next event ev = select_event(); // play the event play_event(ev); // update time tt += dt; // calc stat ct += dt; if(ct >= SKIP){ calc_stat(++k, i); // calculates all the stats ct = 0.0; } // update events associated probabilites if necessary } #if ALLDATAFILE calc_stat(-1, -1); // free file pointers for individual run data files #if !CLUSTER plotallIndividualRun(i, 0); // note: method is in dataplot.c #if GRAPHS plotallIndividualRun(i, 1); // note: method is in dataplot.c #endif #endif // write traits of final state { int m, n; char tstr[200], str[100]; sprintf(str, "traits%d.dat", i); sprintf(str, "traits%d.dat", i); prep_file(tstr, str); FILE *fp = fopen(tstr, "w"); for(m = 0; m < G; m++){ for( n = 0; n < GS[m]; n++){ fprintf(fp, "%.4lf %.4lf ", dxi[m][n], dsi[m][n]); } fprintf(fp, "\n"); } fclose(fp); } #if PUNISH #if DISP_MATRIX plotTraits(i, 0); // note: method is in dataplot.c #endif #if GRAPHS plotTraits(i, 1); // note: method is in dataplot.c #endif #endif #endif } // write effort and payoff data writefile_effort_fertility(); // note: method is in dataplot.c writefile_threshold_aggressiveness(); // note: method is in dataplot.c // plot data with graphics using gnuplot if(!CLUSTER){ plotall(0); // note: method is in dataplot.c #if GRAPHS plotall(1); // note: method is in dataplot.c #endif } #if PUNISH #if DISP_MATRIX displayMatrix(); #endif #endif cleanup(); // note: method is in init.c return 0; }