// Set traits for individual by passing 1D vector void Strategy::set_traits(const double S[]) { if (p == NULL) { cerr << "sim_params not set for Strategy" << endl; exit(1); } for (int i = 0; i < TRAIT_DIM; i++) Traits[i] = S[i]; lma = pow(10, S[0]); hmat = pow(10, S[1]); rho = (*p).wood_dens; total_mass_at_birth = (*p).seed_mass; // Warning, in case someone tries to modify seed mass and wood density via trait vector const double eps = 1e-4; if (fabs(total_mass_at_birth / pow(10, S[3]) - 1) > eps) { cerr << "Value for seed mass is set in params object. You should use the same value in trait vector and params object." << total_mass_at_birth << "\t" << pow(10, S[3]) << "\t" << fabs(total_mass_at_birth / pow(10, S[3]) - 1) << endl; exit(1); } if (fabs(rho / pow(10, S[2]) - 1) > eps) { cerr << "Value for wood density is set in params object. You should use the same value in trait vector and params object." << rho << "\t" << pow(10, S[2]) << "\t" << fabs(rho / pow(10, S[2]) - 1) << endl; exit(1); } // Check for values outside reasonable bounds if (S[0] > 5.0) lma = pow(10, 5.0); // Limit max lma to prevent population crashes if (S[0] < -10.0) lma = pow(10, -10.0); // Limit min lma to prevent problems with root finding for offspring size // Calculate constants used for efficient calculation - must keep this set_constants(); set_depths(); }
void register_constants(JSContext* cx, JSObject* obj) #endif { std::map<std::string, int> enums; enums.clear(); enums.insert(std::make_pair("ShareStateNone", 0)); enums.insert(std::make_pair("ShareStateUnkonw", 1)); enums.insert(std::make_pair("ShareStateBegin", 2)); enums.insert(std::make_pair("ShareStateSuccess", 3)); enums.insert(std::make_pair("ShareStateFail", 4)); enums.insert(std::make_pair("ShareStateCancelled", 5)); set_constants(cx, obj, "ShareState", enums); }
ConstMethod::ConstMethod(int byte_code_size, InlineTableSizes* sizes, MethodType method_type, int size) { NoSafepointVerifier no_safepoint; init_fingerprint(); set_constants(NULL); set_stackmap_data(NULL); set_code_size(byte_code_size); set_constMethod_size(size); set_inlined_tables_length(sizes); // sets _flags set_method_type(method_type); assert(this->size() == size, "wrong size for object"); set_name_index(0); set_signature_index(0); set_constants(NULL); set_max_stack(0); set_max_locals(0); set_method_idnum(0); set_size_of_parameters(0); set_result_type(T_VOID); }
int test_prefix_operation() { int i, err, prev, res; int expected[2048]; int *result; int64_t t; n = 2048; prev = seed; expected[0] = seed; for (i = 1; i < n; i++) { t = (((int64_t)A)*((int64_t)prev) + (uint64_t) B) % (uint64_t) P; expected[i] = (int) t; prev = expected[i]; } set_constants(n, p, rank, A, B, P, seed); //err = generate_fake_random(n, &result); err = generate_random_series_gathered(n, &result); if (rank == 0) { if ((res = memcmp(expected, result, n)) == 0) { printf("%sSuccess!\n%s\n", GREEN, WHITE); } else { printf("%sFAILURE! \n%sExpected:\n", RED, WHITE); for (i = 0; i < n; i++) { printf("%d ", expected[i]); } printf("\nActual:\n"); for (i = 0; i < n; i++) { printf("%d ", result[i]); } putchar('\n'); } free(result); } return res; }
int main(int argc, char *argv[]) { int i, niter, step, n3; double mflops, t, tmax, trecs[t_last+1]; logical verified; char Class; char *t_names[t_last+1]; //--------------------------------------------------------------------- // Read input file (if it exists), else take // defaults from parameters //--------------------------------------------------------------------- FILE *fp; if ((fp = fopen("timer.flag", "r")) != NULL) { timeron = true; t_names[t_total] = "total"; t_names[t_rhsx] = "rhsx"; t_names[t_rhsy] = "rhsy"; t_names[t_rhsz] = "rhsz"; t_names[t_rhs] = "rhs"; t_names[t_xsolve] = "xsolve"; t_names[t_ysolve] = "ysolve"; t_names[t_zsolve] = "zsolve"; t_names[t_rdis1] = "redist1"; t_names[t_rdis2] = "redist2"; t_names[t_tzetar] = "tzetar"; t_names[t_ninvr] = "ninvr"; t_names[t_pinvr] = "pinvr"; t_names[t_txinvr] = "txinvr"; t_names[t_add] = "add"; fclose(fp); } else { timeron = false; } printf("\n\n NAS Parallel Benchmarks (NPB3.3-SER-C) - SP Benchmark\n\n"); if ((fp = fopen("inputsp.data", "r")) != NULL) { int result; printf(" Reading from input file inputsp.data\n"); result = fscanf(fp, "%d", &niter); while (fgetc(fp) != '\n'); result = fscanf(fp, "%lf", &dt); while (fgetc(fp) != '\n'); result = fscanf(fp, "%d%d%d", &grid_points[0], &grid_points[1], &grid_points[2]); fclose(fp); } else { printf(" No input file inputsp.data. Using compiled defaults\n"); niter = NITER_DEFAULT; dt = DT_DEFAULT; grid_points[0] = PROBLEM_SIZE; grid_points[1] = PROBLEM_SIZE; grid_points[2] = PROBLEM_SIZE; } printf(" Size: %4dx%4dx%4d\n", grid_points[0], grid_points[1], grid_points[2]); printf(" Iterations: %4d dt: %10.6f\n", niter, dt); printf("\n"); if ((grid_points[0] > IMAX) || (grid_points[1] > JMAX) || (grid_points[2] > KMAX) ) { printf(" %d, %d, %d\n", grid_points[0], grid_points[1], grid_points[2]); printf(" Problem size too big for compiled array sizes\n"); return 0; } nx2 = grid_points[0] - 2; ny2 = grid_points[1] - 2; nz2 = grid_points[2] - 2; set_constants(); for (i = 1; i <= t_last; i++) { timer_clear(i); } exact_rhs(); initialize(); //--------------------------------------------------------------------- // do one time step to touch all code, and reinitialize //--------------------------------------------------------------------- adi(); initialize(); for (i = 1; i <= t_last; i++) { timer_clear(i); } timer_start(1); for (step = 1; step <= niter; step++) { if ((step % 20) == 0 || step == 1) { printf(" Time step %4d\n", step); } adi(); } timer_stop(1); tmax = timer_read(1); verify(niter, &Class, &verified); if (tmax != 0.0) { n3 = grid_points[0]*grid_points[1]*grid_points[2]; t = (grid_points[0]+grid_points[1]+grid_points[2])/3.0; mflops = (881.174 * (double)n3 - 4683.91 * (t * t) + 11484.5 * t - 19272.4) * (double)niter / (tmax*1000000.0); } else { mflops = 0.0; } print_results("SP", Class, grid_points[0], grid_points[1], grid_points[2], niter, tmax, mflops, " floating point", verified, NPBVERSION,COMPILETIME, CS1, CS2, CS3, CS4, CS5, CS6, "(none)"); //--------------------------------------------------------------------- // More timers //--------------------------------------------------------------------- if (timeron) { for (i = 1; i <= t_last; i++) { trecs[i] = timer_read(i); } if (tmax == 0.0) tmax = 1.0; printf(" SECTION Time (secs)\n"); for (i = 1; i <= t_last; i++) { printf(" %-8s:%9.3f (%6.2f%%)\n", t_names[i], trecs[i], trecs[i]*100./tmax); if (i == t_rhs) { t = trecs[t_rhsx] + trecs[t_rhsy] + trecs[t_rhsz]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "sub-rhs", t, t*100./tmax); t = trecs[t_rhs] - t; printf(" --> %8s:%9.3f (%6.2f%%)\n", "rest-rhs", t, t*100./tmax); } else if (i == t_zsolve) { t = trecs[t_zsolve] - trecs[t_rdis1] - trecs[t_rdis2]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "sub-zsol", t, t*100./tmax); } else if (i == t_rdis2) { t = trecs[t_rdis1] + trecs[t_rdis2]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "redist", t, t*100./tmax); } } } return 0; }
int realMain(int argc, char * argv[]) { input_number = 0; ctu = 0; cts = 0; TestSetTimerName("Timer title"); if (argc != 3 && argc != 4) { printf( "Usage: dtest file.txt solve|calc|par|dealerpar|play [ncores]\n"); return 1; } char * fname = argv[1]; char * type = argv[2]; if (! strcmp(type, "solve")) input_number = SOLVE_SIZE; else if (! strcmp(type, "calc")) input_number = BOARD_SIZE; else if (! strcmp(type, "par")) input_number = PAR_REPEAT; else if (! strcmp(type, "dealerpar")) input_number = PAR_REPEAT; else if (! strcmp(type, "play")) input_number = TRACE_SIZE; set_constants(); main_identify(); #ifdef _WIN32 QueryPerformanceFrequency(&frequency); #endif boardsPBN bop; solvedBoards solvedbdp; ddTableDealsPBN dealsp; ddTablesRes resp; allParResults parp; playTracesPBN playsp; solvedPlays solvedplp; int * dealer_list; int * vul_list; dealPBN * deal_list; futureTricks * fut_list; ddTableResults * table_list; parResults * par_list; parResultsDealer * dealerpar_list; playTracePBN * play_list; solvedPlay * trace_list; int number; if (read_file(fname, &number, &dealer_list, &vul_list, &deal_list, &fut_list, &table_list, &par_list, &dealerpar_list, &play_list, &trace_list) == false) { printf("read_file failed.\n"); exit(0); } if (! strcmp(type, "solve")) { if (GIBmode) { printf("GIB file does not work with solve\n"); exit(0); } loop_solve(&bop, &solvedbdp, deal_list, fut_list, number); } else if (! strcmp(type, "calc")) { loop_calc(&dealsp, &resp, &parp, deal_list, table_list, number); } else if (! strcmp(type, "par")) { if (GIBmode) { printf("GIB file does not work with solve\n"); exit(0); } loop_par(vul_list, table_list, par_list, number); } else if (! strcmp(type, "dealerpar")) { if (GIBmode) { printf("GIB file does not work with solve\n"); exit(0); } loop_dealerpar(dealer_list, vul_list, table_list, dealerpar_list, number); } else if (! strcmp(type, "play")) { if (GIBmode) { printf("GIB file does not work with solve\n"); exit(0); } loop_play(&bop, &playsp, &solvedplp, deal_list, play_list, trace_list, number); } else { printf("Unknown type %s\n", type); exit(0); } print_times(number); TestPrintTimer(); TestPrintTimerList(); TestPrintCounter(); free(dealer_list); free(vul_list); free(deal_list); free(fut_list); free(table_list); free(par_list); free(dealerpar_list); free(play_list); free(trace_list); return (0); }
int main(int argc, char **argv) #endif { int i, niter, step; double mflops, t, tmax; logical verified; char class; double tsum[t_last+2], t1[t_last+2], tming[t_last+2], tmaxg[t_last+2]; char *t_recs[t_last+2] = { "total", "rhs", "xsolve", "ysolve", "zsolve", "bpack", "exch", "xcomm", "ycomm", "zcomm", " totcomp", " totcomm" }; //--------------------------------------------------------------------- // Root node reads input file (if it exists) else takes // defaults from parameters //--------------------------------------------------------------------- printf("\n\n NAS Parallel Benchmarks (NPB3.3-OCL-MD) - SP Benchmark\n\n"); FILE *fp; fp = fopen("timer.flag", "r"); timeron = false; if (fp != NULL) { timeron = true; fclose(fp); } if ((fp = fopen("inputsp.data", "r")) != NULL) { int result; printf(" Reading from input file inputsp.data\n"); result = fscanf(fp, "%d", &niter); while (fgetc(fp) != '\n'); result = fscanf(fp, "%*f"); while (fgetc(fp) != '\n'); result = fscanf(fp, "%d%d%d", &grid_points[0], &grid_points[1], &grid_points[2]); fclose(fp); } else { printf(" No input file inputsp.data. Using compiled defaults\n"); niter = NITER_DEFAULT; grid_points[0] = PROBLEM_SIZE; grid_points[1] = PROBLEM_SIZE; grid_points[2] = PROBLEM_SIZE; } setup_opencl(argc, argv); printf(" Size: %4dx%4dx%4d\n", grid_points[0], grid_points[1], grid_points[2]); printf(" Iterations: %4d", niter); if (num_devices != MAXCELLS*MAXCELLS) printf(" WARNING: compiled for %5d devices \n", MAXCELLS*MAXCELLS); printf(" Number of active devices: %5d\n\n", num_devices); make_set(); for (i = 0; i < t_last; i++) { timer_clear(i); } set_constants(); initialize(); lhsinit(); exact_rhs(); compute_buffer_size(5); set_kernel_args(); //--------------------------------------------------------------------- // do one time step to touch all code, and reinitialize //--------------------------------------------------------------------- #ifdef MINIMD_SNUCL_OPTIMIZATIONS // set cmd queue property for(i = 0; i < num_devices; i++) { clSetCommandQueueProperty(cmd_queue[i], CL_QUEUE_AUTO_DEVICE_SELECTION | //CL_QUEUE_ITERATIVE | CL_QUEUE_COMPUTE_INTENSIVE, true, NULL); } #endif adi(); #ifdef MINIMD_SNUCL_OPTIMIZATIONS for(i = 0; i < num_devices; i++) { clSetCommandQueueProperty(cmd_queue[i], 0, true, NULL); } #endif initialize(); //--------------------------------------------------------------------- // Synchronize before placing time stamp //--------------------------------------------------------------------- for (i = 0; i < t_last; i++) { timer_clear(i); } timer_clear(0); timer_start(0); for (step = 1; step <= niter; step++) { if ((step % 20) == 0 || step == 1) { printf(" Time step %4d\n", step); } adi(); } timer_stop(0); t = timer_read(0); verify(niter, &class, &verified); tmax = t; if( tmax != 0.0 ) { mflops = (881.174*(double)( PROBLEM_SIZE*PROBLEM_SIZE*PROBLEM_SIZE ) -4683.91*(double)( PROBLEM_SIZE*PROBLEM_SIZE ) +11484.5*(double)( PROBLEM_SIZE ) -19272.4) * (double)( niter ) / (tmax*1000000.0); } else { mflops = 0.0; } c_print_results("SP", class, grid_points[0], grid_points[1], grid_points[2], niter, tmax, mflops, " floating point", verified, NPBVERSION,COMPILETIME, CS1, CS2, CS3, CS4, CS5, CS6, CS7, clu_GetDeviceTypeName(device_type), device_name, num_devices); if (timeron) { /* for (i = 0; i < t_last; i++) { t1[i] = timer_read(i); } t1[t_xsolve] = t1[t_xsolve] - t1[t_xcomm]; t1[t_ysolve] = t1[t_ysolve] - t1[t_ycomm]; t1[t_zsolve] = t1[t_zsolve] - t1[t_zcomm]; t1[t_last+2] = t1[t_xcomm]+t1[t_ycomm]+t1[t_zcomm]+t1[t_exch]; t1[t_last+1] = t1[t_total] - t1[t_last+2]; MPI_Reduce(&t1, tsum, t_last+2, dp_type, MPI_SUM, 0, comm_setup); MPI_Reduce(&t1, tming, t_last+2, dp_type, MPI_MIN, 0, comm_setup); MPI_Reduce(&t1, tmaxg, t_last+2, dp_type, MPI_MAX, 0, comm_setup); if (node == 0) { printf(" nprocs =%6d minimum maximum average\n", total_nodes); for (i = 0; i < t_last+2; i++) { tsum[i] = tsum[i] / total_nodes; printf(" timer %2d(%8s) : %10.4f %10.4f %10.4f\n", i+1, t_recs[i], tming[i], tmaxg[i], tsum[i]); } } */ } release_opencl(); return 0; }
void read_climate_and_pc () { char fn [77], fnp [77], lfs [7]; int i, j, jj = 0, lf; if (global_monitor) monitor_leaf(1, "read_climate_and_pc"); read_esd(); open_files(1); printf(" Reading: Climate and Plant Community description. \n\n"); for (i = 0; i < n_lats; i++) { for (j = 0; j < n_lons; j++) { if (earth[i][j] == '1') { read_climate(); read_pc(); set_constants(jj); int2str(eco[jj].iflpn, (jj + 1), 6, 0); ++jj; } else skip_data(1); } skip_data(0); } close_files(0); printf(" Reading: LF FCs. \n"); strcpy(fnp, global_directory); strcat(fnp, "/lf_"); for (lf = 1; lf <= num_lf; lf++) { printf(" LF = %3d \n", lf); strcpy(fn, fnp); if (lf < 10) strcat(fn, "00"); else if (lf < 100) strcat(fn, "0"); int_to_ascii(lf, lfs); strcat(fn, lfs); read_lf(lf, fn); } printf("\n"); if (global_monitor) monitor_leaf(0, "read_climate_and_pc"); }
int main(int argc, char *argv[]) { int i, niter, step; double navg, mflops, n3; double tmax, t, trecs[t_last+1]; logical verified; char Class; char *t_names[t_last+1]; //--------------------------------------------------------------------- // Root node reads input file (if it exists) else takes // defaults from parameters //--------------------------------------------------------------------- FILE *fp; if ((fp = fopen("timer.flag", "r")) != NULL) { timeron = true; t_names[t_total] = "total"; t_names[t_rhsx] = "rhsx"; t_names[t_rhsy] = "rhsy"; t_names[t_rhsz] = "rhsz"; t_names[t_rhs] = "rhs"; t_names[t_xsolve] = "xsolve"; t_names[t_ysolve] = "ysolve"; t_names[t_zsolve] = "zsolve"; t_names[t_rdis1] = "redist1"; t_names[t_rdis2] = "redist2"; t_names[t_add] = "add"; fclose(fp); } else { timeron = false; } printf("\n\n NAS Parallel Benchmarks (NPB3.3-OMP-C) - BT Benchmark\n\n"); if ((fp = fopen("inputbt.data", "r")) != NULL) { int result; printf(" Reading from input file inputbt.data\n"); result = fscanf(fp, "%d", &niter); while (fgetc(fp) != '\n'); result = fscanf(fp, "%lf", &dt); while (fgetc(fp) != '\n'); result = fscanf(fp, "%d%d%d\n", &grid_points[0], &grid_points[1], &grid_points[2]); fclose(fp); } else { printf(" No input file inputbt.data. Using compiled defaults\n"); niter = NITER_DEFAULT; dt = DT_DEFAULT; grid_points[0] = PROBLEM_SIZE; grid_points[1] = PROBLEM_SIZE; grid_points[2] = PROBLEM_SIZE; } printf(" Size: %4dx%4dx%4d\n", grid_points[0], grid_points[1], grid_points[2]); printf(" Iterations: %4d dt: %11.7f\n", niter, dt); printf(" Number of available threads: %5d\n", omp_get_max_threads()); printf("\n"); if ( (grid_points[0] > IMAX) || (grid_points[1] > JMAX) || (grid_points[2] > KMAX) ) { printf(" %d, %d, %d\n", grid_points[0], grid_points[1], grid_points[2]); printf(" Problem size too big for compiled array sizes\n"); return 0; } set_constants(); for (i = 1; i <= t_last; i++) { timer_clear(i); } initialize(); exact_rhs(); //--------------------------------------------------------------------- // do one time step to touch all code, and reinitialize //--------------------------------------------------------------------- adi(); initialize(); for (i = 1; i <= t_last; i++) { timer_clear(i); } timer_start(1); // Do not do inlining, to avoid huge loops, scops are kept separate and are // distributed among files. //#pragma scop for (step = 1; step <= niter; step++) { adi(); } //#pragma endscop timer_stop(1); tmax = timer_read(1); verify(niter, &Class, &verified); n3 = 1.0*grid_points[0]*grid_points[1]*grid_points[2]; navg = (grid_points[0]+grid_points[1]+grid_points[2])/3.0; if(tmax != 0.0) { mflops = 1.0e-6 * (double)niter * (3478.8 * n3 - 17655.7 * (navg*navg) + 28023.7 * navg) / tmax; } else { mflops = 0.0; } print_results("BT", Class, grid_points[0], grid_points[1], grid_points[2], niter, tmax, mflops, " floating point", verified, NPBVERSION,COMPILETIME, CS1, CS2, CS3, CS4, CS5, CS6, "(none)"); //--------------------------------------------------------------------- // More timers //--------------------------------------------------------------------- if (timeron) { for (i = 1; i <= t_last; i++) { trecs[i] = timer_read(i); } if (tmax == 0.0) tmax = 1.0; printf(" SECTION Time (secs)\n"); for (i = 1; i <= t_last; i++) { printf(" %-8s:%9.3f (%6.2f%%)\n", t_names[i], trecs[i], trecs[i]*100./tmax); if (i == t_rhs) { t = trecs[t_rhsx] + trecs[t_rhsy] + trecs[t_rhsz]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "sub-rhs", t, t*100./tmax); t = trecs[t_rhs] - t; printf(" --> %8s:%9.3f (%6.2f%%)\n", "rest-rhs", t, t*100./tmax); } else if (i==t_zsolve) { t = trecs[t_zsolve] - trecs[t_rdis1] - trecs[t_rdis2]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "sub-zsol", t, t*100./tmax); } else if (i==t_rdis2) { t = trecs[t_rdis1] + trecs[t_rdis2]; printf(" --> %8s:%9.3f (%6.2f%%)\n", "redist", t, t*100./tmax); } } } return 0; }
PID(){ set_constants(0,0,0,0); }
PID(float p, float i, float d, float windup){ set_constants(p,i,d,windup); }