int newton ( int mode, int verbose, PolySys& p, PolySolSet& s ) { double teval,tmgs; bool success; CT* sol = s.get_sol(0); CT alpha; CT *x_gpu; CPUInstHom cpu_inst_hom; Workspace workspace_cpu; Parameter path_parameter(N_PREDICTOR, MAX_STEP, MAX_IT, MAX_DELTA_T, \ MAX_DELTA_T_END, MIN_DELTA_T, ERR_MAX_RES, ERR_MAX_DELTA_X, \ ERR_MAX_FIRST_DELTA_X, ERR_MIN_ROUND_OFF, MAX_IT_REFINE, \ ERR_MIN_ROUND_OFF_REFINE, STEP_INCREASE, STEP_DECREASE); if(verbose > 0) { cout << "The first solution on input :" << endl; for(int k=0; k<p.dim; k++) { cout << k << " :"; cout << setw(72) << scientific << setprecision(64) << sol[k]; } } alpha = CT(1,0); cpu_inst_hom.init(p,p,p.dim,p.n_eq,1,alpha,verbose); cpu_inst_hom.init_workspace(workspace_cpu); if(mode == 0 || mode == 1) { workspace_cpu.init_x_t_idx(); workspace_cpu.update_x_t_value(sol,alpha); success = CPU_Newton (workspace_cpu,cpu_inst_hom,path_parameter,teval,tmgs); if(verbose > 0) { cout.precision(64); cout << "The first solution after CPU_Newton :" << endl; for(int k=0; k<p.dim; k++) cout << k << " :" << setw(72) << workspace_cpu.x[k]; } } if(mode == 0 || mode == 2) { alpha = CT(1,0); success = GPU_Newton(cpu_inst_hom,path_parameter,sol,alpha,x_gpu, 1,verbose); if(verbose > 0) { cout << "The first solution after GPU_Newton :" << endl; for(int k=0; k<p.dim; k++) cout << k << " :" << setw(72) << x_gpu[k]; } } if(mode == 1) s.change_sol(0,workspace_cpu.x); else s.change_sol(0,x_gpu); return 0; }
void ada_write_sols ( PolySolSet& sols ) { int fail = solcon_clear_dobldobl_solutions(); if(fail != 0) std::cout << "failed to clear the solutions" << std::endl; int dim = sols.dim; int nbsols = sols.n_sol; for(int sol_idx=0; sol_idx<nbsols; sol_idx++) { CT* sol = sols.get_sol(sol_idx); double csol[4*dim+10]; csol[0] = 0.0; csol[1] = 0.0; csol[2] = 0.0; csol[3] = 0.0; int idx = 4; for(int k=0; k<dim; k++) { csol[idx++] = sol[k].real.x[0]; csol[idx++] = sol[k].real.x[1]; csol[idx++] = sol[k].imag.x[0]; csol[idx++] = sol[k].imag.x[1]; } csol[4*dim+4] = 0.0; csol[4*dim+5] = 0.0; csol[4*dim+6] = 0.0; csol[4*dim+7] = 0.0; csol[4*dim+8] = 0.0; csol[4*dim+9] = 0.0; fail = solcon_append_dobldobl_solution(dim,1,csol); if(fail != 0) std::cout << "failed to append the solution" << std::endl; } }
void ada_read_sols ( PolySys& start_sys, PolySolSet& sols ) { int fail, len; fail = solcon_number_of_dobldobl_solutions(&len); // printf("Number of start solutions : %d\n",len); int dim=start_sys.dim; sols.dim = dim; double sol[4*dim+10]; for(int sol_idx=1; sol_idx<len+1; sol_idx++) { int mm,k,pos; T1 dd_sol[2*dim]; T1 t_real,t_imag,err,rco,res; solcon_retrieve_next_dobldobl_solution(dim,&k,&mm,sol); //solcon_retrieve_solution(dim,sol_idx,&mm,sol); /*std::cout << sol[0] << " " << sol[1] << std::endl; for(int var_idx=0; var_idx<4; var_idx++) std::cout << sol[2+2*var_idx] << " " << sol[2+2*var_idx] << std::endl; std::cout << sol[2+2*dim] << " " << sol[3+2*dim] << " " << sol[4+2*dim] << std::endl;*/ t_real.x[0] = sol[0]; t_real.x[1] = sol[1]; t_imag.x[0] = sol[2]; t_imag.x[1] = sol[3]; pos = 4; for(int dd_sol_idx=0; dd_sol_idx<2*dim; dd_sol_idx++) { T1 sol_real,sol_imag; sol_real.x[0] = sol[pos++]; sol_real.x[1] = sol[pos++]; sol_imag.x[0] = sol[pos++]; sol_imag.x[1] = sol[pos++]; dd_sol[dd_sol_idx++] = sol_real; dd_sol[dd_sol_idx] = sol_imag; } err.x[0] = sol[4*dim+4]; err.x[1] = sol[4*dim+5]; rco.x[0] = sol[4*dim+6]; rco.x[1] = sol[4*dim+7]; res.x[0] = sol[4*dim+8]; res.x[1] = sol[4*dim+9]; PolySol* tmp_sol = new PolySol(dim,t_real,t_imag,dd_sol,err,rco,res); //tmp_sol->print_info(start_sys.pos_var); sols.add_sol(tmp_sol); } // std::cout << "sol finished" << std::endl; }
void ada_read_sols ( PolySys& start_sys, PolySolSet& sols ) { int fail, len; fail = solcon_number_of_quaddobl_solutions(&len); // printf("Number of start solutions : %d\n",len); int dim=start_sys.dim; sols.dim = dim; double sol[8*dim+20]; for(int sol_idx=1; sol_idx<len+1; sol_idx++) { int mm,k,pos; // T1 qd_sol[4*dim]; T1* qd_sol; T1 t_real,t_imag,err,rco,res; qd_sol = (T1*)calloc(4*dim,sizeof(T1)); solcon_retrieve_next_quaddobl_solution(dim,&k,&mm,sol); //solcon_retrieve_solution(dim,sol_idx,&mm,sol); /*std::cout << sol[0] << " " << sol[1] << std::endl; for(int var_idx=0; var_idx<4; var_idx++) std::cout << sol[2+2*var_idx] << " " << sol[2+2*var_idx] << std::endl; std::cout << sol[2+2*dim] << " " << sol[3+2*dim] << " " << sol[4+2*dim] << std::endl;*/ t_real.x[0] = sol[0]; t_real.x[1] = sol[1]; t_real.x[2] = sol[2]; t_real.x[3] = sol[3]; t_imag.x[0] = sol[4]; t_imag.x[1] = sol[5]; t_imag.x[2] = sol[6]; t_imag.x[3] = sol[7]; pos = 8; for(int qd_sol_idx=0; qd_sol_idx<4*dim; qd_sol_idx++) { T1 sol_real,sol_imag; sol_real.x[0] = sol[pos++]; sol_real.x[1] = sol[pos++]; sol_real.x[2] = sol[pos++]; sol_real.x[3] = sol[pos++]; sol_imag.x[0] = sol[pos++]; sol_imag.x[1] = sol[pos++]; sol_imag.x[2] = sol[pos++]; sol_imag.x[3] = sol[pos++]; qd_sol[qd_sol_idx++] = sol_real; qd_sol[qd_sol_idx] = sol_imag; } err.x[0] = sol[8*dim+8]; err.x[1] = sol[8*dim+9]; err.x[2] = sol[8*dim+10]; err.x[3] = sol[8*dim+11]; rco.x[0] = sol[8*dim+12]; rco.x[1] = sol[8*dim+13]; rco.x[2] = sol[8*dim+14]; rco.x[3] = sol[8*dim+15]; res.x[0] = sol[8*dim+16]; res.x[1] = sol[8*dim+17]; res.x[2] = sol[8*dim+18]; res.x[3] = sol[8*dim+19]; PolySol* tmp_sol = new PolySol(dim,t_real,t_imag,qd_sol,err,rco,res); // tmp_sol->print_info(start_sys.pos_var); sols.add_sol(tmp_sol); } // sols.print_info(start_sys.pos_var); // std::cout << "sol finished" << std::endl; }
int manytrack ( int mode, int verbose, double regamma, double imgamma, PolySys& p, PolySys& q, PolySolSet& s ) { double tpred,teval,tmgs; bool success; CT* sol = s.get_sol(0); CT alpha,t; CT *x_gpu; CPUInstHom cpu_inst_hom; Workspace workspace_cpu; Parameter path_parameter(N_PREDICTOR, MAX_STEP, MAX_IT, MAX_DELTA_T, \ MAX_DELTA_T_END, MIN_DELTA_T, ERR_MAX_RES, ERR_MAX_DELTA_X, \ ERR_MAX_FIRST_DELTA_X, ERR_MIN_ROUND_OFF, MAX_IT_REFINE, \ ERR_MIN_ROUND_OFF_REFINE, STEP_INCREASE, STEP_DECREASE); if(verbose > 0) { cout << "The first solution on input :" << endl; for(int k=0; k<p.dim; k++) { cout << k << " :"; cout << setw(40) << scientific << setprecision(32) << sol[k]; } } int fail,n_path; fail = solcon_number_of_dobldobl_solutions(&n_path); alpha = CT(regamma,imgamma); cpu_inst_hom.init(p,q,p.dim,p.n_eq,1,alpha,verbose); cpu_inst_hom.init_workspace(workspace_cpu); if(mode == 0 || mode == 1) { for(int path_idx=0; path_idx<n_path; path_idx++) { if(verbose > 0) cout << "tracking path " << path_idx << endl; CT* sol0 = s.get_sol(path_idx); CT* sol_new = NULL; t = CT(0.0,0); workspace_cpu.init_x_t_idx(); workspace_cpu.update_x_t_value(sol0,t); workspace_cpu.update_x_t_idx(); workspace_cpu.path_idx = path_idx; tpred = 0.0; teval = 0.0; tmgs = 0.0; if(verbose > 0) cout << "calling path_tracker ..." << endl; success = path_tracker(workspace_cpu,cpu_inst_hom,path_parameter, tpred,teval,tmgs,0,verbose); if(verbose > 0) cout << "done with call to path_tracker." << endl; if(mode == 1) s.change_sol(path_idx,workspace_cpu.x_last); if(verbose > 0) { cout.precision(32); cout << "The solution " << path_idx << endl; for(int k=0; k<p.dim; k++) cout << k << " :" << setw(40) << workspace_cpu.x_last[k]; } } } if(mode == 0 || mode == 2) { CT* sol0 = new CT[n_path*cpu_inst_hom.dim]; CT* sol_tmp_mult = sol0; CT* tt = new CT[n_path]; CT** x_gpu = NULL; for(int path_idx=0; path_idx<n_path; path_idx++) { CT* sol_tmp = s.get_sol(path_idx); for(int sol_idx=0; sol_idx<cpu_inst_hom.dim; sol_idx++) { *sol_tmp_mult++ = sol_tmp[sol_idx]; } tt[path_idx] = CT(0.0,0.0); } success = GPU_Path_mult (cpu_inst_hom,path_parameter,sol0,tt,x_gpu,n_path,verbose); for(int path_idx=0; path_idx<n_path; path_idx++) { s.change_sol(path_idx,x_gpu[path_idx]); } if(verbose > 0) { cout << "The first solution after GPU path tracker :" << endl; cout.precision(32); for(int k=0; k<p.dim; k++) cout << k << " :" << setw(40) << x_gpu[0][k]; } delete[] tt; } return 0; }