LIS_INT main(int argc, char* argv[]) { LIS_Comm comm; LIS_INT err; int nprocs,my_rank; LIS_INT nesol; LIS_MATRIX A,B; LIS_VECTOR x; LIS_SCALAR evalue0; LIS_ESOLVER esolver; LIS_REAL residual; LIS_INT iter; double time; double itime,ptime,p_c_time,p_i_time; char esolvername[128]; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); comm = LIS_COMM_WORLD; #ifdef USE_MPI MPI_Comm_size(comm,&nprocs); MPI_Comm_rank(comm,&my_rank); #else nprocs = 1; my_rank = 0; #endif if( argc < 5 ) { lis_printf(comm,"Usage: %s matrix_a_filename matrix_b_filename evector_filename rhistory_filename [options]\n", argv[0]); CHKERR(1); } lis_printf(comm,"\n"); lis_printf(comm,"number of processes = %d\n",nprocs); #ifdef _OPENMP lis_printf(comm,"max number of threads = %d\n",omp_get_num_procs()); lis_printf(comm,"number of threads = %d\n",omp_get_max_threads()); #endif /* create matrix and vectors */ lis_matrix_create(comm,&A); lis_matrix_create(comm,&B); lis_printf(comm,"\nmatrix A:\n"); lis_input_matrix(A,argv[1]); lis_printf(comm,"matrix B:\n"); lis_input_matrix(B,argv[2]); lis_vector_duplicate(A,&x); lis_esolver_create(&esolver); lis_esolver_set_option("-e gii -eprint mem",esolver); err = lis_esolver_set_optionC(esolver); CHKERR(err); err = lis_gesolve(A,B,x,&evalue0,esolver); CHKERR(err); lis_esolver_get_esolver(esolver,&nesol); lis_esolver_get_esolvername(nesol,esolvername); lis_esolver_get_residualnorm(esolver,&residual); lis_esolver_get_iter(esolver,&iter); lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time); lis_printf(comm,"%s: mode number = %d\n", esolvername, 0); #ifdef _COMPLEX lis_printf(comm,"%s: eigenvalue = (%e, %e)\n", esolvername, (double)creal(evalue0), (double)cimag(evalue0)); #else lis_printf(comm,"%s: eigenvalue = %e\n", esolvername, (double)evalue0); #endif lis_printf(comm,"%s: number of iterations = %D\n",esolvername, iter); lis_printf(comm,"%s: elapsed time = %e sec.\n", esolvername, time); lis_printf(comm,"%s: preconditioner = %e sec.\n", esolvername, ptime); lis_printf(comm,"%s: matrix creation = %e sec.\n", esolvername, p_c_time); lis_printf(comm,"%s: linear solver = %e sec.\n", esolvername, itime); lis_printf(comm,"%s: relative residual = %e\n\n",esolvername, (double)residual); /* write eigenvector */ lis_output_vector(x,LIS_FMT_MM,argv[3]); /* write residual history */ lis_esolver_output_rhistory(esolver,argv[4]); lis_esolver_destroy(esolver); lis_matrix_destroy(A); lis_matrix_destroy(B); lis_vector_destroy(x); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_INT i,n,gn,is,ie; LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT nesol; LIS_MATRIX A; LIS_VECTOR x; LIS_REAL evalue0; LIS_ESOLVER esolver; LIS_REAL residual; LIS_INT iter; double time; double itime,ptime,p_c_time,p_i_time; char esolvername[128]; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 2 ) { if( my_rank==0 ) { printf("Usage: %s n [eoptions]\n", argv[0]); } CHKERR(1); } if( my_rank==0 ) { printf("\n"); printf("number of processes = %d\n",nprocs); } #ifdef _OPENMP if( my_rank==0 ) { #ifdef _LONG__LONG printf("max number of threads = %lld\n",omp_get_num_procs()); printf("number of threads = %lld\n",omp_get_max_threads()); #else printf("max number of threads = %d\n",omp_get_num_procs()); printf("number of threads = %d\n",omp_get_max_threads()); #endif } #endif /* generate coefficient matrix for one dimensional Poisson equation */ n = atoi(argv[1]); lis_matrix_create(LIS_COMM_WORLD,&A); lis_matrix_set_size(A,0,n); lis_matrix_get_size(A,&n,&gn); lis_matrix_get_range(A,&is,&ie); for(i=is;i<ie;i++) { if( i>0 ) lis_matrix_set_value(LIS_INS_VALUE,i,i-1,-1.0,A); if( i<gn-1 ) lis_matrix_set_value(LIS_INS_VALUE,i,i+1,-1.0,A); lis_matrix_set_value(LIS_INS_VALUE,i,i,2.0,A); } lis_matrix_set_type(A,LIS_MATRIX_CSR); lis_matrix_assemble(A); lis_vector_duplicate(A,&x); lis_esolver_create(&esolver); lis_esolver_set_option("-eprint mem",esolver); lis_esolver_set_optionC(esolver); lis_esolve(A, x, &evalue0, esolver); lis_esolver_get_esolver(esolver,&nesol); lis_esolver_get_esolvername(nesol,esolvername); lis_esolver_get_residualnorm(esolver, &residual); lis_esolver_get_iter(esolver, &iter); lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time); if( my_rank==0 ) { printf("%s: mode number = %d\n", esolvername, 0); #ifdef _LONG__DOUBLE printf("%s: eigenvalue = %Le\n", esolvername, evalue0); #else printf("%s: eigenvalue = %e\n", esolvername, evalue0); #endif #ifdef _LONG__LONG printf("%s: number of iterations = %lld\n",esolvername, iter); #else printf("%s: number of iterations = %d\n",esolvername, iter); #endif printf("%s: elapsed time = %e sec.\n", esolvername, time); printf("%s: preconditioner = %e sec.\n", esolvername, ptime); printf("%s: matrix creation = %e sec.\n", esolvername, p_c_time); printf("%s: linear solver = %e sec.\n", esolvername, itime); #ifdef _LONG__DOUBLE printf("%s: relative residual = %Le\n\n",esolvername, residual); #else printf("%s: relative residual = %e\n\n",esolvername, residual); #endif } /* lis_vector_nrm2(x, &xnrm2); lis_vector_scale((1/xnrm2*sqrt(n)), x); lis_vector_print(x); */ /* lis_vector_create(LIS_COMM_WORLD,&y); lis_matrix_create(LIS_COMM_WORLD,&B); lis_esolver_get_evalues(esolver,y); lis_esolver_get_evectors(esolver,B); lis_output_vector(y,LIS_FMT_MM,"evalues.out"); lis_output_matrix(B,LIS_FMT_MM,"evectors.out"); lis_vector_destroy(y); lis_matrix_destroy(B); */ lis_esolver_destroy(esolver); lis_matrix_destroy(A); lis_vector_destroy(x); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }
LIS_INT main(LIS_INT argc, char* argv[]) { LIS_INT nprocs,my_rank; int int_nprocs,int_my_rank; LIS_INT nsol; LIS_MATRIX A,B; LIS_VECTOR x,y,z,w; LIS_SCALAR evalue0; LIS_ESOLVER esolver; LIS_REAL residual; LIS_INT iter; double time; double itime,ptime,p_c_time,p_i_time; char esolvername[128]; LIS_DEBUG_FUNC_IN; lis_initialize(&argc, &argv); #ifdef USE_MPI MPI_Comm_size(MPI_COMM_WORLD,&int_nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&int_my_rank); nprocs = int_nprocs; my_rank = int_my_rank; #else nprocs = 1; my_rank = 0; #endif if( argc < 6 ) { if( my_rank==0 ) { printf("Usage: %s matrix_filename evalues_filename evectors_filename residuals_filename iters_filename [options]\n", argv[0]); } CHKERR(1); } if( my_rank==0 ) { printf("\n"); printf("number of processes = %d\n",nprocs); } #ifdef _OPENMP if( my_rank==0 ) { printf("max number of threads = %d\n",omp_get_num_procs()); printf("number of threads = %d\n",omp_get_max_threads()); } #endif /* create matrix and vectors */ lis_matrix_create(LIS_COMM_WORLD,&A); lis_input_matrix(A,argv[1]); lis_vector_duplicate(A,&x); lis_esolver_create(&esolver); lis_esolver_set_option("-e si -ss 1 -eprint mem",esolver); lis_esolver_set_optionC(esolver); lis_esolve(A, x, &evalue0, esolver); lis_esolver_get_esolver(esolver,&nsol); lis_esolver_get_esolvername(nsol,esolvername); lis_esolver_get_residualnorm(esolver, &residual); lis_esolver_get_iter(esolver, &iter); lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time); if( my_rank==0 ) { printf("%s: mode number = %d\n", esolvername, 0); #ifdef _LONG__DOUBLE printf("%s: eigenvalue = %Le\n", esolvername, evalue0); #else printf("%s: eigenvalue = %e\n", esolvername, evalue0); #endif #ifdef _LONG__LONG printf("%s: number of iterations = %lld\n",esolvername, iter); #else printf("%s: number of iterations = %d\n",esolvername, iter); #endif printf("%s: elapsed time = %e sec.\n", esolvername, time); printf("%s: preconditioner = %e sec.\n", esolvername, ptime); printf("%s: matrix creation = %e sec.\n", esolvername, p_c_time); printf("%s: linear solver = %e sec.\n", esolvername, itime); #ifdef _LONG__DOUBLE printf("%s: relative residual = %Le\n\n",esolvername, residual); #else printf("%s: relative residual = %e\n\n",esolvername, residual); #endif } lis_vector_create(LIS_COMM_WORLD,&y); lis_vector_create(LIS_COMM_WORLD,&z); lis_vector_create(LIS_COMM_WORLD,&w); lis_matrix_create(LIS_COMM_WORLD,&B); lis_esolver_get_evalues(esolver,y); lis_esolver_get_residualnorms(esolver,z); lis_esolver_get_iters(esolver,w); lis_esolver_get_evectors(esolver,B); /* write eigenvalues */ lis_output_vector(y,LIS_FMT_MM,argv[2]); /* write eigenvectors */ lis_output_matrix(B,LIS_FMT_MM,argv[3]); /* write residual norms */ lis_output_vector(z,LIS_FMT_MM,argv[4]); /* write numbers of iterations */ lis_output_vector(w,LIS_FMT_MM,argv[5]); lis_esolver_destroy(esolver); lis_matrix_destroy(A); lis_vector_destroy(x); lis_matrix_destroy(B); lis_vector_destroy(y); lis_vector_destroy(z); lis_vector_destroy(w); lis_finalize(); LIS_DEBUG_FUNC_OUT; return 0; }