static double Correction_expand_matrix_RAhV_VTAhV(dmatcsr *AL, dmatcsr *Ah, dmatcsr *AH, multigrid *amg, int current_level, int coarsest_level, int n, double **V) { double tb = Get_time(); int j, k; double ** AhV = (double**)malloc(n*sizeof(double*)); double ** RAhV = (double**)malloc(n*sizeof(double*)); double **VTAhV = (double**)malloc(n*sizeof(double*)); for(j=0; j<n; j++) AhV[j] = (double*)calloc(Ah->nr, sizeof(double)); for(j=0; j<n; j++) RAhV[j] = (double*)calloc(AH->nr, sizeof(double)); for(j=0; j<n; j++) VTAhV[j] = (double*)calloc(n, sizeof(double)); for(j=0; j<n; j++) Multi_dmatcsr_dvec(Ah, V[j], AhV[j]); for(j=0; j<n; j++) RestrictFine2Coarse(amg, current_level, coarsest_level, AhV[j], RAhV[j]); for(j=0; j<n; j++) for(k=0; k<n; k++) VTAhV[j][k] = Multi_dvec_dvec(V[j], AhV[k], Ah->nr); Expand_dmatcsr(AL, n, RAhV, VTAhV); for(j=0; j<n; j++) { free(VTAhV[j]); VTAhV[j] = NULL; } free(VTAhV); VTAhV = NULL; for(j=0; j<n; j++) { free( RAhV[j]); RAhV[j] = NULL; } free( RAhV); RAhV = NULL; for(j=0; j<n; j++) { free( AhV[j]); AhV[j] = NULL; } free( AhV); AhV = NULL; return Get_time() - tb; }
void CAML_INSTR_ATEXIT (void) { int i; struct CAML_INSTR_BLOCK *p, *prev, *next; FILE *f = NULL; char *fname; fname = caml_secure_getenv ("OCAML_INSTR_FILE"); if (fname != NULL){ char *mode = "a"; char buf [1000]; char *name = fname; if (name[0] == '@'){ snprintf (buf, sizeof(buf), "%s.%d", name + 1, getpid ()); name = buf; } if (name[0] == '+'){ mode = "a"; name = name + 1; }else if (name [0] == '>' || name[0] == '-'){ mode = "w"; name = name + 1; } f = fopen (name, mode); } if (f != NULL){ /* reverse the list */ prev = NULL; p = CAML_INSTR_LOG; while (p != NULL){ next = p->next; p->next = prev; prev = p; p = next; } CAML_INSTR_LOG = prev; fprintf (f, "==== OCAML INSTRUMENTATION DATA %s\n", OCAML_VERSION_STRING); for (p = CAML_INSTR_LOG; p != NULL; p = p->next){ for (i = 0; i < p->index; i++){ fprintf (f, "@@ %19ld %19ld %s\n", (long) Get_time (p, i), (long) Get_time(p, i+1), p->tag[i+1]); } if (p->tag[0][0] != '\000'){ fprintf (f, "@@ %19ld %19ld %s\n", (long) Get_time (p, 0), (long) Get_time(p, p->index), p->tag[0]); } } fclose (f); } }
static void Reset () { Trans_bytes = Total_bytes = 0; Prev_time = Get_time (); Cancelled = 0; Operation = STR_copy (Operation, ""); Hide (); }
static double Correction_get_new_evec(multigrid *amg, int current_level, int coarsest_level, int n, double **V, double **evec_expand, double **evec) { double tb = Get_time(); int j, k; int nr = amg->A[current_level]->nr; int nrc = amg->A[coarsest_level]->nr; double **PV = (double**)malloc(n* sizeof(double*)); for(j=0; j<n; j++) PV[j] = (double*) calloc(nr, sizeof(double)); for(j=0; j<n; j++) { memset(evec[j], 0, nr*sizeof(double)); ProlongCoarse2Fine(amg, coarsest_level, current_level, evec_expand[j], PV[j]); for(k=0; k<n; k++) Sumself_dvec_axpby(V[k], evec_expand[j][nrc+k], evec[j], 1.0, nr); Sumself_dvec_axpby(PV[j], 1.0, evec[j], 1.0, nr); Normalize_dvec(evec[j], nr); } for(j=0; j<n; j++) { free(PV[j]); PV[j] = NULL; } free(PV); PV = NULL; return Get_time() - tb; }
static int OnTransferEvent (rmt_transfer_event_t *event) { static int rpc_started = 0; static double last_update_time = 0.0; char sprintf_str[200]; double new_time, rate; if (event->event != RMT_DATA_SENT && event->event != RMT_DATA_RECEIVED) return(0); if (Cancelled) return (Cancelled); new_time = Get_time (); Trans_bytes += event->no_of_segment_bytes; if (event->no_of_bytes == 0) { if (!rpc_started) { Total_bytes += event->total_no_of_bytes; rpc_started = 1; } } else rpc_started = 0; if (new_time - last_update_time < .2) { SleepForSimulation (event); return (Cancelled); } last_update_time = new_time; Show (); if (Total_bytes > 0.) Bar_width = Trans_bytes * PROGRESS_BAR_WIDTH / Total_bytes; else Bar_width = 0; if (Bar_width > PROGRESS_BAR_WIDTH) Bar_width = PROGRESS_BAR_WIDTH; if (new_time - Prev_time > 0.0) rate = ((double)Trans_bytes / 1024.0) / (new_time - Prev_time); else rate = 0.0; sprintf (sprintf_str, "Transferred %d bytes in %1.2f seconds (%1.2f K/s)", Trans_bytes, new_time - Prev_time, rate); Transfer_rate_label_str = STR_copy (Transfer_rate_label_str, sprintf_str); if (event->event == RMT_DATA_RECEIVED) sprintf (sprintf_str, "Receiving %d bytes - (%d of %d received)", event->no_of_segment_bytes, event->no_of_bytes, event->total_no_of_bytes); else sprintf (sprintf_str, "Sending %d bytes - (%d of %d sent)", event->no_of_segment_bytes, event->no_of_bytes, event->total_no_of_bytes); Transfer_op_label_str = STR_copy (Transfer_op_label_str, sprintf_str); RefreshAppearance (); /* Refresh the appearance */ if (Cancelled) { Hide (); return (Cancelled); } SleepForSimulation (event); return (Cancelled); }
/* cg convergence factor \sigma = \frac{\sqrt(k)-1}{\sqrt(k)+1} k = \frac{\lamda_{max}}{\lambda_{min}} */ int main(int argc, char* argv[]) { dmatcsr *A; amg_param param; int i; double tb_ini = Get_time(); Init_amg_param_argv(argc, argv, ¶m, &A, NULL, NULL); //Remove_zero_dmatcsr(A); Print_dmatcsr(A); int size = A->nr; Print_amg_param(param); double *sol = (double*)calloc(size, sizeof(double)); double *b = (double*)calloc(size, sizeof(double)); double *x_ini = (double*)calloc(size, sizeof(double)); srand((unsigned)time(0)); for(i=0; i<size; i++) sol[i] = 1.0;//((double)rand())/((double)RAND_MAX); Multi_dmatcsr_dvec(A, sol, b); double te_ini = Get_time(); printf("Initial and read time = %f\n", te_ini-tb_ini); //Write_dmatcsr_fasp(A, "../output/csrmat_FE.dat"); //Write_dvec(b, size, "../output/rhs_FE.dat"); #if cg /*------------------ cg ------------------*/ printf("\ncalling cg method...\n"); double *x_cg = (double*)calloc(size, sizeof(double)); memcpy(x_cg, x_ini, size*sizeof(double)); double tol_cg = param.cg_tol; int max_iter_cg = param.cg_max_iter; double resi_norm_cg = 9999.9; int niter_cg = -1; double tb_cg = Get_time(); Linear_solver_cg(A, b, x_cg, tol_cg, max_iter_cg, NULL, &resi_norm_cg, &niter_cg, 0); double te_cg = Get_time(); Get_residual(A, b, x_cg, NULL, &resi_norm_cg); printf("CG method: resi = %18.15f, niter = %3d, time = %f\n", resi_norm_cg, niter_cg, te_cg-tb_cg); free(x_cg); /*----------------------------------------*/ #endif #if umfpack /*------------------ UMFPACK ------------------*/ printf("\ncalling UMFPACK direct method...\n"); double *x_umfpack = (double*)calloc(size, sizeof(double)); memcpy(x_umfpack, x_ini, size*sizeof(double)); double rn_umfpack; double tb_umfpack = Get_time(); Linear_solver_direct(A, b, x_umfpack); double te_umfpack = Get_time(); Get_residual(A, b, x_umfpack, NULL, &rn_umfpack); printf("umfpack method: rn = %18.15f, time = %f\n", rn_umfpack, te_umfpack-tb_umfpack); free(x_umfpack); /*---------------------------------------------*/ #endif #if fasp /*------------------ FASP AMG ------------------*/ printf("\ncalling FASP AMG method...\n"); double *x_faspamg = (double*)calloc(size, sizeof(double)); memcpy(x_faspamg, x_ini, size*sizeof(double)); double resi_norm_faspamg = 9999.9; int ncycle_fasp = -1; amg_param param_fasp = param; param_fasp.amgsolver_tol = 1e-08; double tb_faspsetup = Get_time(); multigrid *faspamg = Build_amg(A, NULL, param_fasp.max_level); Setup_phase_fasp(faspamg); double te_faspsetup = Get_time(); Print_amg(faspamg); double tb_faspamg = Get_time(); Linear_solver_amg(faspamg, 0, b, x_faspamg, param_fasp, &resi_norm_faspamg, &ncycle_fasp); double te_faspamg = Get_time(); printf("faspamg method: \nresi = %18.15f, ncycle = %3d, \ntime = %f, setup time = %f\n", resi_norm_faspamg, ncycle_fasp, te_faspamg-tb_faspamg, te_faspsetup-tb_faspsetup); Free_multigrid(faspamg); free(x_faspamg); /*-----------------------------------------*/ #endif #if amgcycle /*------------------ MYAMG ------------------*/ printf("\ncalling AMG method...\n"); double *x_amg = (double*)calloc(size, sizeof(double)); memcpy(x_amg, x_ini, size*sizeof(double)); double resi_norm_amg = 9999.9; int ncycle_amg = -1; amg_param param_myamg = param; param_myamg.amgsolver_tol = 1e-08; multigrid *amg = Build_amg(A, NULL, param_myamg.max_level); double tb_setup = Get_time(); Setup_phase(amg, param_myamg); double te_setup = Get_time(); Print_amg(amg); printf("setup phase time: %f\n", te_setup-tb_setup); Write_dmatcsr_csr(amg->A[0], "../output/A0.dmatcsr"); Write_dmatcsr_csr(amg->P[0], "../output/P0.dmatcsr"); Write_dmatcsr_csr(amg->R[0], "../output/R0.dmatcsr"); Write_dmatcsr_csr(amg->A[1], "../output/A1.dmatcsr"); double tb_amg = Get_time(); Linear_solver_amg(amg, 0, b, x_amg, param_myamg, &resi_norm_amg, &ncycle_amg); double te_amg = Get_time(); printf("amg method: \nresi = %18.15f, ncycle = %3d, \ntime = %f, setup time = %f\n", resi_norm_amg, ncycle_amg, te_amg-tb_amg, te_setup-tb_setup); Free_multigrid(amg); free(x_amg); /*-----------------------------------------*/ #endif #if amgpcg /*------------------ PCG+AMG ------------------*/ printf("\ncalling pcg amg method...\n"); double *x_pcg_amg = (double*)calloc(size, sizeof(double)); memcpy(x_pcg_amg, x_ini, size*sizeof(double)); double resi_norm_pcg_amg = 9999.9; int niter_pcg = -1; int ncycle = -1; amg_param param_pcg = param; param_pcg.amgsolver_max_cycle = 5; double tb_pcg_amg_setup = Get_time(); multigrid *pcg_amg = Build_amg(A, NULL, param_pcg.max_level); Setup_phase(pcg_amg, param_pcg); double te_pcg_amg_setup = Get_time(); Print_amg(pcg_amg); double tb_pcg_amg = Get_time(); Linear_solver_pcg_amg(pcg_amg, 0, b, x_pcg_amg, param_pcg, NULL, &resi_norm_pcg_amg, &niter_pcg, &ncycle); double te_pcg_amg = Get_time(); printf("*************** pcg amg method ***************\n"); printf("resi = %g\n", resi_norm_pcg_amg); printf("pcg iter = %d\n", niter_pcg); printf("amg cycle = %d\n", ncycle); printf("time = %g\n", te_pcg_amg-tb_pcg_amg); printf("setup time = %g\n", te_pcg_amg_setup-tb_pcg_amg_setup); printf("**********************************************\n"); Free_multigrid(pcg_amg); free(x_pcg_amg); /*-----------------------------------------*/ #endif free(b); free(x_ini); free(sol); Free_dmatcsr(A); return 0; }
//Problem: when already have a finer result such as 0-level approximation, but //want to correct it from a coarser level, there maybe some problem //----20160301 void Eigen_solver_shift_amg(multigrid *amg, int nev, double *eval, double **evec, int init_approx_level, int is_init_approx_level_correction, int is_shift, double *shift, amg_param param) { double t1, t2, t3, t4; double eigen_time = 0; double linear_time = 0; double expand_time = 0; double new_evec_time = 0; t1 = Get_time(); int status = 0; int i, j, m; int nlevel = amg->actual_level; int niter_outer = param.amgeigen_nouter_iter; int finest_level = 0; int coarsest_level = param.amgeigen_coarsest_level; if(coarsest_level <= 0) coarsest_level += nlevel-1; dmatcsr *matA; dmatcsr *matM; dmatcsr *matP; dmatcsr *A = amg->A[finest_level]; dmatcsr *AH = amg->A[coarsest_level]; dmatcsr *MH = amg->M[coarsest_level]; //===================================================================== int amg_correction_begin_level; if(init_approx_level < 0) { t3 = Get_time(); Eigen_solver_arpack_dn(AH, MH, nev, eval, evec); for(j=0; j<nev; j++) Normalize_dvec(evec[j], AH->nr); t4 = Get_time(); eigen_time += t4-t3; if(1) { printf("Solving eigenvalue problem by Eigen_solver_arpack_dn() on the coarest level...\n"); printf("========= coarest eigenvalue on level %d =========\n", coarsest_level); for(i=0; i<nev; i++) printf("%d: %15.12f\n", i, eval[i]); printf("==================================================\n"); } } //amg_correction_begin_level = (init_approx_level < 0) ? coarsest_level-1 : init_approx_level; if(init_approx_level < 0) amg_correction_begin_level = coarsest_level -1; else if(is_init_approx_level_correction > 0) amg_correction_begin_level = init_approx_level; else amg_correction_begin_level = init_approx_level - 1; /*排除:在第0层上给定初值,但是不需要矫正。以后可以改成这种情况直接返回。*/ assert(init_approx_level!=0 || is_init_approx_level_correction > 0); dmatcsr *Alarge = Expand_dmatcsr_struct(AH, nev); dmatcsr *Mlarge = Expand_dmatcsr_struct(MH, nev); double **dvec_amg = (double**)malloc(nev * sizeof(double*)); double **evec_expand = (double**)malloc(nev * sizeof(double*)); for(i=0; i<nev; i++) dvec_amg[i] = (double*)calloc( A->nr, sizeof(double)); for(i=0; i<nev; i++) evec_expand[i] = (double*)calloc(Alarge->nr, sizeof(double)); //================= amg method for eigenvalue problem ================= if(status) printf("Begin amg cycle...\n"); for(i=amg_correction_begin_level; i>=finest_level; i--) { if(status) printf("level = %d, nlevel = %d, coarsest_level = %d\n", i, nlevel, coarsest_level); matA = amg->A[i]; matM = amg->M[i]; matP = amg->P[i]; for( m=0; m<niter_outer; m++ ) { if(status) printf("correction: m = %d\n", m); if(status) printf("Solving linear system on current level %d ...\n", i); for( j=0; j<nev; j++ ) { if(m == 0) { if(init_approx_level < 0) { Multi_dmatcsr_dvec(matP, evec[j], dvec_amg[j]); } else { if(i==amg_correction_begin_level && is_init_approx_level_correction>0) memcpy(dvec_amg[j], evec[j], matA->nr*sizeof(double)); else Multi_dmatcsr_dvec(matP, evec[j], dvec_amg[j]); } } else { memcpy(dvec_amg[j], evec[j], matA->nr*sizeof(double)); } } linear_time += Correction_solve_linear_shift(amg, i, nev, eval, dvec_amg, is_shift, shift, param); expand_time += Correction_expand_matrix_RAhV_VTAhV(Alarge, matA, AH, amg, i, coarsest_level, nev, dvec_amg); expand_time += Correction_expand_matrix_RAhV_VTAhV(Mlarge, matM, MH, amg, i, coarsest_level, nev, dvec_amg); //Write_dmatcsr_csr(Mlarge, "../output/Mlarge.dat"); if(status) printf("Solving corrected eigenvalue problem...\n"); t3 = Get_time(); memset(eval, 0, nev*sizeof(double)); for(j=0; j<nev; j++) memset(evec_expand[j], 0, Alarge->nr*sizeof(double)); Eigen_solver_arpack_dn(Alarge, Mlarge, nev, eval, evec_expand); Insertion_ascend_sort_dvec_dvecvec(eval, evec_expand, 0, nev-1); t4 = Get_time(); eigen_time += t4-t3; if(status) { printf("========= corrected eigenvalue on level %d ===========\n", i); for(j=0; j<nev; j++) printf("%15.12f\n", eval[j]); printf("\n"); printf("======================================================\n"); } new_evec_time += Correction_get_new_evec(amg, i, coarsest_level, nev, dvec_amg, evec_expand, evec); } } if(status) printf("amg cycle end.\n"); //===================================================================== for(i=0; i<nev; i++) { free(evec_expand[i]); evec_expand[i] = NULL; } for(i=0; i<nev; i++) { free(dvec_amg[i]); dvec_amg[i] = NULL; } free(evec_expand); evec_expand = NULL; free(dvec_amg); dvec_amg = NULL; Free_dmatcsr(Alarge); Alarge = NULL; Free_dmatcsr(Mlarge); Mlarge = NULL; t2 = Get_time(); if(param.amgeigen_print_level > 0) { printf("direct eigen time = %f\n", eigen_time); printf("amg linear solve time = %f\n", linear_time); printf("expand matrix time = %f\n", expand_time); printf("get new evec time = %f\n", new_evec_time); printf("correction total time = %f\n", t2-t1); } }
static double Correction_solve_linear_shift(multigrid *amg, int current_level, int n, double *dval, double **dvec, int is_shift, double *shift, amg_param param) { double tb = Get_time(); #if amg_eigen_shift_linear_solver == 1 double resi_norm_amg = -1; int ncycle = 0; printf(".............. Eigen -- linear solver amg .............\n"); printf("level j amgcycle rn time \n"); #elif amg_eigen_shift_linear_solver == 2 double resi_norm_pcg = -1; int ncycle = 0; int niter = 0; printf(".................. Eigen -- linear solver pcg ..................\n"); printf("level j pcgiter amgcycle rn time \n"); #endif dmatcsr *A = amg->A[current_level]; dmatcsr *M = amg->M[current_level]; double *rhs = (double*)calloc(A->nr, sizeof(double)); double t1, t2; int j; for(j=0; j<n; j++) { t1 = Get_time(); memset(rhs, 0, M->nr*sizeof(double)); Multi_dmatcsr_dvec(M, dvec[j], rhs); #if 0 Scale_dvec(rhs, dval[j], M->nr); #else if(MABS(dval[j]) > EPS) Scale_dvec(dvec[j], 1.0/dval[j], M->nr); #endif #if amg_eigen_shift_linear_solver == 1 if((is_shift > 0) && (NULL != shift)) { printf("shift[%d] = %f\n", j, shift[j]); Linear_solver_shift_amg(amg, shift[j], current_level, rhs, dvec[j], param, &resi_norm_amg, &ncycle); } else { Linear_solver_amg(amg, current_level, rhs, dvec[j], param, &resi_norm_amg, &ncycle); } t2 = Get_time(); printf(" %2d %2d %3d %18.15f %f\n", current_level, j, ncycle, resi_norm_amg, t2-t1); #elif amg_eigen_shift_linear_solver == 2 if((is_shift > 0) && (NULL != shift)) { printf("shift[%d] = %f\n", j, shift[j]); Linear_solver_shift_pcg_amg(amg, shift[j], current_level, rhs, dvec[j], param, NULL, &resi_norm_pcg, &niter, &ncycle); } else { Linear_solver_shift_pcg_amg(amg, shift[j], current_level, rhs, dvec[j], param, NULL, &resi_norm_pcg, &niter, &ncycle); } t2 = Get_time(); printf(" %2d %2d %3d %3d %18.15f %f\n", current_level, j, niter, ncycle, resi_norm_pcg, t2-t1); #endif } #if amg_eigen_shift_linear_solver == 1 printf(".......................................................\n"); #elif amg_eigen_shift_linear_solver == 2 printf("................................................................\n"); #endif free(rhs); rhs = NULL; return Get_time() - tb; }
int main(int argc, char* argv[]) { int nev = 0; int error_nev_b = 0; int error_nev_e = 0; Init_nev_argv(argc, argv, &nev, &error_nev_b, &error_nev_e); printf("nev = %d, nb = %d, ne = %d\n", nev, error_nev_b, error_nev_e); #if !(eigenpair_given || direct_method_all || direct_method_amg) #undef direct_method_amg #define direct_method_amg 1 printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); printf("!! Using direct_method_amg by force. !!\n"); printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); #endif if(argc < 2) { printf("too few arguments!\n"); exit(0); } double tb_init = Get_time(); dmatcsr *A; dmatcsr *M; amg_param param; Init_amg_param_argv(argc, argv, ¶m, &A, &M, NULL); Print_dmatcsr(A); Print_dmatcsr(M); //Remove_zero_dmatcsr(A); //Remove_zero_dmatcsr(M); //Print_dmatcsr(A); //Print_dmatcsr(M); #if precondition double *diag = (double*)calloc(A->nr, sizeof(double)); Get_diag_dmatcsr(A, diag); //Write_dvec(diag, A->nr, "../output/diag.dat"); Zoom_dmatcsr(A, diag); Zoom_dmatcsr(M, diag); //Write_dmatcsr_csr(A, "../output/zoomA.dmatcsr"); //Write_dmatcsr_csr(M, "../output/zoomM.dmatcsr"); #endif Print_amg_param(param); double te_init = Get_time(); printf("\ninit time: %f\n", te_init-tb_init); int i; #if eigenpair_given double eval_given[direct_nev] = { #if 1 19.742181652312645, 49.360802349344354, 49.367944185094970, 79.004391701675800, 98.754512911503582, 98.754533209293612, 128.394168556935057, 128.454367342076466, 167.940430957700670, 167.944318594906093, 177.893344633664498, 197.653679181721998, 197.654155507479231, 247.074076746614253, #endif #if 0 10.857195080016409, 17.335104047922837, 26.671610677454293, 28.505230862366687, 41.804525628594597, 43.820240665791161, 52.515200028290948, 54.115874724164939, 64.824306320110182, 71.379471726937822, 79.380690379853291, 81.126795449851784, 90.502801250074597, 94.221835539270273, #endif #if 0 19.739351152446577, 49.348398772994052, 49.348426661655587, 78.957543954641395, 98.696926072478092, 98.696926072787591, 128.306055963593963, 128.306290898228610, 167.784999753374791, 167.785014924843836, 177.654996436879685, 197.394417265854258, 197.394417273111628, 246.743050204326266, 246.743972243036808, 256.612819086151660, 256.612819086431614, 286.222396771513957, 286.222479299660563, 315.832405282174534, 335.571880346205262, 335.571880413890710, 365.180563509384399, 365.180577155566198, 394.790444748240247, 394.790444752357189, 404.659991649028711, 404.662532642826989, 444.140187371669356, 444.140438372226185, 493.488516543021433, 493.488516544614299, #endif }; #endif #if !eigenpair_given && direct_method_all double tb_direct_all = Get_time(); double *eval_direct_all = (double*) calloc(direct_nev, sizeof(double)); double **evec_direct_all = (double**)malloc(direct_nev* sizeof(double*)); for(i=0; i<direct_nev; i++) evec_direct_all[i] = (double*)calloc(A->nc, sizeof(double)); printf("\ncalling direct method all...\n"); Eigen_solver_arpack_dn(A, M, direct_nev, eval_direct_all, evec_direct_all); printf("================= direct all result ===================\n"); for(i=0; i<direct_nev; i++) printf("%2d: %20.15f\n", i, eval_direct_all[i]); printf("===================================================\n"); double te_direct_all = Get_time(); printf("direct eigen time: %f\n", te_direct_all - tb_direct_all); #endif #if amg_method multigrid *amg = Build_amg(A, M, param.max_level); double tb_setup = Get_time(); Setup_phase(amg, param); double te_setup = Get_time(); Print_amg(amg); printf("setup phase time: %f\n", te_setup-tb_setup); double *total_error = (double*)calloc(nmax_correction, sizeof(double)); double *corre_time = (double*)calloc(nmax_correction, sizeof(double)); #if !eigenpair_given && direct_method_amg double tb_direct_amg = Get_time(); double *eval_direct_amg = (double*) calloc(direct_nev, sizeof(double)); double **evec_direct_amg = (double**)malloc(direct_nev* sizeof(double*)); for(i=0; i<direct_nev; i++) evec_direct_amg[i] = (double*)calloc(A->nc, sizeof(double)); printf("calling direct method amg...\n"); Eigen_solver_arpack_dn_amg(amg, 0, direct_nev, eval_direct_amg, evec_direct_amg, param); printf("================= direct amg result ===================\n"); for(i=0; i<direct_nev; i++) printf("%2d: %20.15f\n", i, eval_direct_amg[i]); printf("===================================================\n"); double te_direct_amg = Get_time(); printf("direct eigen amg time: %f\n", te_direct_amg - tb_direct_amg); #endif exit(-1); /* solve eigenvalue problem */ double tb_correction_amg = Get_time(); double *eval_amg = (double*) calloc(nev, sizeof(double)); double **evec_amg = (double**)malloc(nev* sizeof(double*)); for(i=0; i<nev; i++) evec_amg[i] = (double*)calloc(A->nc, sizeof(double)); double tb_amg, te_amg; printf("=============== 0 ===============\n"); tb_amg = Get_time(); amg_param param_eigen = param; param_eigen.amgeigen_nouter_iter = 1; param_eigen.amgsolver_max_cycle = 1; param_eigen.pcg_amg_max_iter = 1; Eigen_solver_amg_nested(amg, nev, eval_amg, evec_amg, param_eigen); te_amg = Get_time(); printf("* 0 * approximate eigenvalue: \n");/* show the result */ for(i=0; i<nev; i++) printf("%2d: %20.15f\n", i, eval_amg[i]); printf("correction %2d time : %20.15f\n", 0, te_amg - tb_amg); corre_time[0] = te_amg - tb_amg; #if eigenpair_given for(i=error_nev_b; i<=error_nev_e; i++) total_error[0] += fabs(eval_amg[i] - eval_given[i]); #elif direct_method_all for(i=error_nev_b; i<=error_nev_e; i++) total_error[0] += fabs(eval_amg[i] - eval_direct_all[i]); #elif direct_method_amg for(i=error_nev_b; i<=error_nev_e; i++) total_error[0] += fabs(eval_amg[i] - eval_direct_amg[i]); #endif printf("correction %2d error: %20.15f\n", 0, total_error[0]); printf("***************************************************\n"); printf("***************************************************\n"); printf("begin to correct eigenpair on the finest level...\n"); int ncorrection = 0; for(i=1; i<nmax_correction; i++) { printf("=============== %d ===============\n", i); int j; tb_amg = Get_time(); param_eigen.amgsolver_max_cycle = 10; param_eigen.pcg_amg_max_iter = 10; param_eigen.amgeigen_nouter_iter = 4; //Eigen_solver_amg(amg, nev, eval_amg, evec_amg, 0, 1, param_eigen); //int is_shift = 1; double *shift = (double*)calloc(nev, sizeof(double)); shift[0] = - 9.54; shift[1] = -10.06; shift[2] = -10.06; //Eigen_solver_shift_amg(amg, nev, eval_amg, evec_amg, 0, 1, is_shift, shift, param_eigen); //Eigen_solver_amg_multistep(amg, nev, eval_amg, evec_amg, 0, 1, 2, param_eigen); Eigen_solver_amg_multistep2(amg, nev, eval_amg, evec_amg, param_eigen); te_amg = Get_time(); free(shift); for(j=0; j<nev; j++) printf("%2d: %20.15f\n", j, eval_amg[j]); printf("correction %2d time : %20.15f\n", i, te_amg - tb_amg); corre_time[i] = te_amg - tb_amg; #if eigenpair_given for(j=error_nev_b; j<=error_nev_e; j++) total_error[i] += fabs(eval_amg[j] - eval_given[j]); #elif direct_method_all for(j=error_nev_b; j<=error_nev_e; j++) total_error[i] += fabs(eval_amg[j] - eval_direct_all[j]); #elif direct_method_amg for(j=error_nev_b; j<=error_nev_e; j++) total_error[i] += fabs(eval_amg[j] - eval_direct_amg[j]); #endif printf("correction %2d error: %20.15f\n", i, total_error[i]); ncorrection++; if(total_error[i] < tol_correction) break; } double te_correction_amg = Get_time(); printf("==================================\n"); printf("=============== correction information ===============\n"); printf("correction error ratio time\n"); printf(" %2d %20.15f %s %f\n", 0, total_error[0], "--------", corre_time[0]); for(i=1; i<=ncorrection; i++) printf(" %2d %20.15f %f %f\n", i, total_error[i], total_error[i]/total_error[i-1], corre_time[i]); printf("======================================================\n"); printf("***************************************************\n"); printf("******** whole correction time: %f *********\n", te_correction_amg - tb_correction_amg); printf("***************************************************\n"); free(corre_time); free(total_error); for(i=0; i<nev; i++) free(evec_amg[i]); free(evec_amg); free(eval_amg); #if !eigenpair_given && direct_method_amg for(i=0; i<direct_nev; i++) free(evec_direct_amg[i]); free(evec_direct_amg); free(eval_direct_amg); #endif Free_multigrid(amg); #endif //amg method #if !eigenpair_given && direct_method_all for(i=0; i<direct_nev; i++) free(evec_direct_all[i]); free(evec_direct_all); free(eval_direct_all); #endif #if precondition free(diag); #endif Free_dmatcsr(M); Free_dmatcsr(A); return 0; }
int main(int argc, char *argv[]) { int ret = 0; struct sockaddr_in sa; int sd; char *buf; double start_time; double used_time; double avg_time; double us_rate; int max_len, lenbuf; int j,ok; /* * info */ if (argc != 2) { printf("Use: client <max_len> \n"); exit(1); } printf("CLIENT is up \n"); /* * malloc */ max_len =atoi(argv[1]); if ( (max_len <= 0) || (max_len >= 4*1024*1024) ) max_len = 512*1024; buf = (char *) malloc((unsigned) max_len); if (buf == NULL) { perror("Error en malloc"); exit(1); } /* * connect */ ok = X_SOCKET_ln2address((struct sockaddr_in *)&sa, SERVER_HOST,SERVER_PORT) ; if (ok == FALSE) { perror("Error en X_SOCKET_ln2address"); exit(1); } ok = X_SOCKET_connect(&sd, (struct sockaddr_in *)&sa) ; if (ok == FALSE) { perror("Error en X_SOCKET_connect"); exit(1); } /* * test */ lenbuf = 1; while (lenbuf <= max_len) { avg_time = 0.0; for(j = 0; j < PRUEBAS; j++) { start_time = Get_time(); ret = X_SOCKET_write(sd,buf,lenbuf) ; if (ret != lenbuf) perror("Error en write"); ret = X_SOCKET_read(sd,buf,lenbuf) ; if (ret != lenbuf) perror("Error en read"); used_time = (Get_time() - start_time); avg_time = avg_time + used_time; } avg_time = avg_time / (float) PRUEBAS; if (avg_time > 0) /* rate is megabytes per second */ us_rate = (double) ((2.0 * lenbuf)/(avg_time*(double)1000000)); else us_rate = 0.0; printf("len=%d bytes, used= %f sec., rate=%f Mbytes/sec\n", lenbuf, used_time, us_rate); lenbuf *= 2; } /* * free resources */ free(buf); close (sd); /* * end */ return (0); }