int mmm1d_tune(char **log) { char buffer[32 + 2*ES_DOUBLE_SPACE + ES_INTEGER_SPACE]; double int_time, min_time=1e200, min_rad = -1; double maxrad = box_l[2]; /* N_psi = 2, theta=2/3 maximum for rho */ double switch_radius; if (mmm1d_params.far_switch_radius_2 < 0) { /* determine besselcutoff and optimal switching radius. Should be around 0.33 */ for (switch_radius = 0.2*maxrad; switch_radius < 0.4*maxrad; switch_radius += 0.025*maxrad) { if (switch_radius <= bessel_radii[MAXIMAL_B_CUT - 1]) { // this switching radius is too small for our Bessel series continue; } mmm1d_params.far_switch_radius_2 = SQR(switch_radius); coulomb.method = COULOMB_MMM1D; /* initialize mmm1d temporary structures */ mpi_bcast_coulomb_params(); /* perform force calculation test */ int_time = time_force_calc(TEST_INTEGRATIONS); /* exit on errors */ if (int_time < 0) return ES_ERROR; sprintf(buffer, "r= %f t= %f ms\n", switch_radius, int_time); *log = strcat_alloc(*log, buffer); if (int_time < min_time) { min_time = int_time; min_rad = switch_radius; } /* stop if all hope is vain... */ else if (int_time > 2*min_time) break; } switch_radius = min_rad; mmm1d_params.far_switch_radius_2 = SQR(switch_radius); } else { if (mmm1d_params.far_switch_radius_2 <= SQR(bessel_radii[MAXIMAL_B_CUT - 1])) { // this switching radius is too small for our Bessel series *log = strcat_alloc(*log, "could not find reasonable bessel cutoff"); return ES_ERROR; } } coulomb.method = COULOMB_MMM1D; mpi_bcast_coulomb_params(); return ES_OK; }
void repl() { char *input; while ((input = readline("> ")) != NULL) { int ss = stack_size; read_start:; #ifdef READLINE if (input && *input) add_history(input); #endif const char *p = input; error err; atom expr; err = read_expr(p, &p, &expr); if (err == ERROR_FILE) { /* read more lines */ char *line = readline(" "); if (!line) break; input = strcat_alloc(&input, "\n"); input = strcat_alloc(&input, line); free(line); goto read_start; } if (!err) { while (1) { atom result; error err = macex_eval(expr, &result); if (err) { print_error(err); printf("error in expression:\n"); print_expr(expr); putchar('\n'); break; } else { print_expr(result); puts(""); } err = read_expr(p, &p, &expr); if (err != ERROR_OK) { break; } } } else { print_error(err); } stack_restore(ss); free(input); } }
void repl() { char *input; while ((input = readline("> ")) != NULL) { int ss = stack_size; read_start: arc_reader_unclosed = 0; #ifdef READLINE if (input && *input) add_history(input); #endif char *buf = (char *)malloc(strlen(input) + 4); sprintf(buf, "(%s\n)", input); const char *p = buf; error err; atom result; atom code_expr; err = read_expr(p, &p, &code_expr); if (arc_reader_unclosed > 0) { /* read more lines */ char *line = readline(" "); if (!line) break; input = strcat_alloc(&input, "\n"); input = strcat_alloc(&input, line); goto read_start; } if (!err) { while (!no(code_expr)) { err = macex_eval(car(code_expr), &result); if (err) { print_error(err); break; } else { print_expr(result); putchar('\n'); } code_expr = cdr(code_expr); } } stack_restore(ss); free(buf); free(input); } }
static bool xml_grab_cheat(struct cheat *cht, xmlNodePtr ptr) { if (!ptr) return false; memset(cht, 0, sizeof(struct cheat)); bool first = true; for (; ptr; ptr = ptr->next) { if (strcmp((const char*)ptr->name, "description") == 0) { cht->desc = (char*)xmlNodeGetContent(ptr); } else if (strcmp((const char*)ptr->name, "code") == 0) { if (!first) { cht->code = strcat_alloc(cht->code, "+"); if (!cht->code) return false; } xmlChar *code = xmlNodeGetContent(ptr); if (!code) return false; cht->code = strcat_alloc(cht->code, (const char*)code); xmlFree(code); if (!cht->code) return false; first = false; } } return true; }
//Tuning int EwaldgpuForce::adaptive_tune(char **log,SystemInterface &s) { ewaldgpu_params.isTuned = false; int Kmax = ewaldgpu_params.K_max; double alpha_array[Kmax]; //All computed alpha in dependence of K double rcut_array[Kmax]; //All computed r_cut in dependence of all computed alpha //Squared charge Particle *particle; particle = (Particle*)malloc(n_part*sizeof(Particle)); mpi_get_particles(particle, NULL); double q_sqr = compute_q_sqare(particle); char b[3*ES_INTEGER_SPACE + 3*ES_DOUBLE_SPACE + 128]; if (skin == -1) { *log = strcat_alloc(*log, "ewaldgpu cannot be tuned, since the skin is not yet set"); return ES_ERROR; } //Compute alpha for all reciprocal k-sphere radius K for(int K = 0; K < Kmax ;K++) { alpha_array[K] = tune_alpha(ewaldgpu_params.accuracy/sqrt(2), ewaldgpu_params.precision, K+1, box_l[0]*box_l[1]*box_l[2], q_sqr, n_part); //printf("K:%i alpha:%f\n",K+1,alpha_array[K]); } //Compute r_cut for all computed alpha for(int K = 0; K < Kmax ;K++) { rcut_array[K] = tune_rcut(ewaldgpu_params.accuracy/sqrt(2), ewaldgpu_params.precision, alpha_array[K], box_l[0]*box_l[1]*box_l[2], q_sqr, n_part); //printf("K:%i rcut:%f \n",K+1,rcut_array[K]); } //Test if accuracy was reached if(rcut_array[Kmax-1]<0) { return ES_ERROR; } /*********************************************************************************** PERFORMANCE TIME ***********************************************************************************/ //Test performance time for the diverent (K, rcut, alpha) double int_time_best = 1E30; int K_best = Kmax; for(int K = 0; K < Kmax ;K++) { if(alpha_array[K]>0 and rcut_array[K]>0 and rcut_array[K]<(std::min(box_l[0],std::min(box_l[1],box_l[2])))/2.0-skin) { set_params(rcut_array[K], K+1, K+1, K+1, alpha_array[K]); mpi_bcast_coulomb_params(); double int_time = time_force_calc(ewaldgpu_params.time_calc_steps); if(int_time<int_time_best) { int_time_best = int_time; K_best = K; } //printf("TIME K:%i int_time:%f\n",K+1,int_time); } } set_params(rcut_array[K_best], K_best+1, K_best+1, K_best+1, alpha_array[K_best]); ewaldgpu_params.isTuned = true; mpi_bcast_coulomb_params(); //Print Status sprintf(b, "ewaldgpu tune parameters: Accuracy goal = %f\n", ewaldgpu_params.accuracy); *log = strcat_alloc(*log, b); sprintf(b, "ewaldgpu tune parameters: Alpha = %f\n", ewaldgpu_params.alpha); *log = strcat_alloc(*log, b); sprintf(b, "ewaldgpu tune parameters: r_cut = %f\n", ewaldgpu_params.rcut); *log = strcat_alloc(*log, b); sprintf(b, "ewaldgpu tune parameters: num_kx = %i\n", ewaldgpu_params.num_kx); *log = strcat_alloc(*log, b); sprintf(b, "ewaldgpu tune parameters: num_ky = %i\n", ewaldgpu_params.num_ky); *log = strcat_alloc(*log, b); sprintf(b, "ewaldgpu tune parameters: num_kz = %i\n", ewaldgpu_params.num_kz); *log = strcat_alloc(*log, b); return ES_OK; }
int mmm1d_tune(char **log) { char buffer[32 + 2*ES_DOUBLE_SPACE + ES_INTEGER_SPACE]; double int_time, min_time=1e200, min_rad = -1; double maxrad = box_l[2]; /* N_psi = 2, theta=2/3 maximum for rho */ double switch_radius; if (mmm1d_params.bessel_cutoff < 0 && mmm1d_params.far_switch_radius_2 < 0) { /* determine besselcutoff and optimal switching radius */ for (switch_radius = RAD_STEPPING*maxrad; switch_radius < maxrad; switch_radius += RAD_STEPPING*maxrad) { mmm1d_params.bessel_cutoff = determine_bessel_cutoff(switch_radius, mmm1d_params.maxPWerror, MAXIMAL_B_CUT); /* no reasonable cutoff possible */ if (mmm1d_params.bessel_cutoff == MAXIMAL_B_CUT) continue; mmm1d_params.far_switch_radius_2 = SQR(switch_radius); coulomb.method = COULOMB_MMM1D; /* initialize mmm1d temporary structures */ mpi_bcast_coulomb_params(); /* perform force calculation test */ int_time = time_force_calc(TEST_INTEGRATIONS); /* exit on errors */ if (int_time < 0) return ES_ERROR; sprintf(buffer, "r= %f c= %d t= %f ms\n", switch_radius, mmm1d_params.bessel_cutoff, int_time); *log = strcat_alloc(*log, buffer); if (int_time < min_time) { min_time = int_time; min_rad = switch_radius; } /* stop if all hope is vain... */ else if (int_time > 2*min_time) break; } switch_radius = min_rad; mmm1d_params.far_switch_radius_2 = SQR(switch_radius); mmm1d_params.bessel_cutoff = determine_bessel_cutoff(switch_radius, mmm1d_params.maxPWerror, MAXIMAL_B_CUT); mmm1d_params.bessel_calculated = 1; } else if (mmm1d_params.bessel_cutoff < 0) { /* determine besselcutoff to achieve at least the given pairwise error */ mmm1d_params.bessel_cutoff = determine_bessel_cutoff(sqrt(mmm1d_params.far_switch_radius_2), mmm1d_params.maxPWerror, MAXIMAL_B_CUT); if (mmm1d_params.bessel_cutoff == MAXIMAL_B_CUT) { *log = strcat_alloc(*log, "could not find reasonable bessel cutoff"); return ES_ERROR; } mmm1d_params.bessel_calculated = 1; } else mmm1d_params.bessel_calculated = 0; coulomb.method = COULOMB_MMM1D; mpi_bcast_coulomb_params(); return ES_OK; }