10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define min(a, b) ((a) < (b) ? (a) : (b))
24 int n = 0, i, j, npts, nslices, nvec, nev, mlan, max_its, ev_int, sl, ierr,
27 double a, b, lmax, lmin, ecount, tol, *sli;
39 csrMat Acsr, Bcsr, Acsr0, Bcsr0;
40 double *sqrtdiag = NULL;
45 FILE *flog = stdout, *fmat = NULL;
49 const double tau = 1e-4;
53 printf(
"-----------------------------------------\n");
54 printf(
"Note: You are using CXSparse for the direct solver. \n We recommend a more performance based direct solver for anything more than basic tests. \n SuiteSparse is supported with a makefile change. \n Using SuiteSparse can result in magnitudes faster times. \n\n");
55 printf(
"-----------------------------------------\n");
64 if (NULL == (fmat = fopen(
"matfile",
"r"))) {
65 fprintf(flog,
"Can't open matfile...\n");
70 if (NULL == fgets(line,
MAX_LINE, fmat)) {
71 fprintf(flog,
"error in reading matfile...\n");
74 if ((numat = atoi(line)) <= 0) {
75 fprintf(flog,
"Invalid count of matrices...\n");
78 for (mat = 1; mat <= numat; mat++) {
80 fprintf(flog,
"Invalid format in matfile ...\n");
84 fprintf(flog,
"MATRIX A: %s...\n", io.
MatNam1);
85 fprintf(flog,
"MATRIX B: %s...\n", io.
MatNam2);
91 if (stat(
"OUT", &st) == -1) {
96 strcpy(path,
"OUT/Lan_MMRLanR_");
98 fstats = fopen(path,
"w");
100 printf(
" failed in opening output file in OUT/\n");
103 fprintf(fstats,
"MATRIX A: %s...\n", io.
MatNam1);
104 fprintf(fstats,
"MATRIX B: %s...\n", io.
MatNam2);
105 fprintf(fstats,
"Partition the interval of interest [%f,%f] into %d slices\n",
107 counts = malloc(nslices *
sizeof(
int));
112 fprintf(fstats,
"matrix read successfully\n");
115 fprintf(flog,
"read_coo error for A = %d\n", ierr);
120 fprintf(fstats,
"matrix read successfully\n");
121 if (Bcoo.
nrows != n) {
125 fprintf(flog,
"read_coo error for B = %d\n", ierr);
129 sqrtdiag = (
double *)calloc(n,
sizeof(
double));
133 }
else if (io.
Fmt ==
HB) {
134 fprintf(flog,
"HB FORMAT not supported (yet) * \n");
143 for (i=0; i<n; i++) {
144 sqrtdiag[i] = sqrt(sqrtdiag[i]);
160 vinit = (
double *)malloc(n *
sizeof(
double));
162 ierr =
LanTrbounds(50, 200, 1e-10, vinit, 1, &lmin, &lmax, fstats);
169 printf(
"The degree for LS polynomial approximations to B^{-1} and B^{-1/2} "
170 "are %d and %d\n", Bsol.
deg, Bsqrtsol.
deg);
180 ierr =
LanTrbounds(50, 200, 1e-10, vinit, 1, &lmin, &lmax, fstats);
181 fprintf(fstats,
"Step 0: Eigenvalue bound s for B^{-1}*A: [%.15e, %.15e]\n",
192 double *xdos = (
double *)malloc(npts*
sizeof(
double));
193 double *ydos = (
double *)malloc(npts*
sizeof(
double));
194 ierr =
LanDosG(nvec, msteps, npts, xdos, ydos, &ecount, xintv);
197 printf(
"Landos error %d\n", ierr);
200 fprintf(fstats,
" Time to build DOS (Landos) was : %10.2f \n", t);
201 fprintf(fstats,
" estimated eig count in interval: %.15e \n", ecount);
203 sli = malloc((nslices + 1) *
sizeof(
double));
204 fprintf(fstats,
"DOS parameters: msteps = %d, nvec = %d, npnts = %d\n",
206 spslicer2(xdos, ydos, nslices, npts, sli);
207 printf(
"==================== SLICES FOUND ====================\n");
208 for (j = 0; j < nslices; j++) {
209 printf(
" %2d: [% .15e , % .15e]\n", j + 1, sli[j], sli[j + 1]);
216 ev_int = (int)(1 + ecount / ((
double)nslices));
218 alleigs = malloc(n *
sizeof(
double));
227 for (sl = 0; sl < nslices; sl++) {
228 printf(
"======================================================\n");
230 double *lam, *Y, *res;
235 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
252 void **solshiftdata = (
void **)malloc(num *
sizeof(
void *));
260 mlan =
max(4 * nev, 100);
264 ierr =
RatLanTr(mlan, nev, intv, max_its, tol, vinit, &rat, &nev2, &lam,
267 printf(
"RatLanNr error %d\n", ierr);
273 ind = (
int *)malloc(nev2 *
sizeof(
int));
275 printf(
" number of eigenvalues found: %d\n", nev2);
277 fprintf(fstats,
" Eigenvalues in [a, b]\n");
278 fprintf(fstats,
" Computed [%d] ||Res||\n", nev2);
279 for (i = 0; i < nev2; i++) {
280 fprintf(fstats,
"% .15e %.1e\n", lam[i], res[ind[i]]);
282 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - "
283 "- - - - - - - - - - - - - - - - - -\n");
284 memcpy(&alleigs[totcnt], lam, nev2 *
sizeof(
double));
300 fprintf(fstats,
" --> Total eigenvalues found = %d\n", totcnt);
301 sprintf(path,
"OUT/EigsOut_Lan_MMRLanR_(%s_%s)", io.
MatNam1, io.
MatNam2);
302 FILE *fmtout = fopen(path,
"w");
304 for (j = 0; j < totcnt; j++)
305 fprintf(fmtout,
"%.15e\n", alleigs[j]);
320 if (fstats != stdout) {
325 if (flog != stdout) {
void free_coo(cooMat *coo)
memory deallocation for coo matrix
void ASIGMABSolDirect(int n, double *br, double *bi, double *xr, double *xz, void *data)
complex linear solver routine passed to evsl
int get_matrix_info(FILE *fmat, io_t *pio)
void free_rat(ratparams *rat)
void extrDiagCsr(csrMat *B, double *d)
int SetGenEig()
Set the problem to generalized eigenvalue problem.
int SetupASIGMABSolDirect(csrMat *A, csrMat *BB, int num, complex double *zk, void **data)
setup CXsparse solver for A - SIGMA B
int SetAMatrix(csrMat *A)
Set the matrix A.
void rand_double(int n, double *v)
int cooMat_to_csrMat(int cooidx, cooMat *coo, csrMat *csr)
convert coo to csr
int LanTrbounds(int lanm, int maxit, double tol, double *vinit, int bndtype, double *lammin, double *lammax, FILE *fstats)
Lanczos process for eigenvalue bounds [Thick restart version].
void FreeASIGMABSolDirect(int num, void **data)
free the data needed by CXSparse
int SetBMatrix(csrMat *B)
Set the B matrix.
void sort_double(int n, double *v, int *ind)
void spslicer2(double *xi, double *yi, int n_int, int npts, double *sli)
int EVSLStart()
Initialize evslData.
void free_csr(csrMat *csr)
memory deallocation for csr matrix
void diagScalCsr(csrMat *A, double *d)
void SetupPolSqrt(int n, int max_deg, double tol, double lmin, double lmax, BSolDataPol *data)
int LanDosG(const int nvec, const int msteps, int npts, double *xdos, double *ydos, double *neig, const double *const intv)
int SetLTSol(SolFuncR func, void *data)
Set the solve routine for LT.
int SetStdEig()
Set the problem to standard eigenvalue problem.
sparse matrix format: the compressed sparse row (CSR) format, 0-based
int read_coo_MM(const char *matfile, int idxin, int idxout, cooMat *Acoo)
This file contains function prototypes and constant definitions for EVSL.
int EVSLFinish()
Finish EVSL.
int SetBSol(SolFuncR func, void *data)
Set the solve routine and the associated data for B.
int RatLanTr(int lanm, int nev, double *intv, int maxit, double tol, double *vinit, ratparams *rat, int *nev2, double **vals, double **W, double **resW, FILE *fstats)
RatLanTR filtering Lanczos process [Thick restart version].
void set_ratf_def(ratparams *rat)
Sets default values for ratparams struct.
int SetASigmaBSol(ratparams *rat, SolFuncC *func, SolFuncC allf, void **data)
Set the solve routine and the associated data for A-SIGMA*B if func == NULL, set all functions to be ...
Definitions used for direct solver interface.
void csr_copy(csrMat *A, csrMat *B, int allocB)
copy a csr matrix A into B alloB: 0: will not allocate memory for B (have been alloced outside) 1: wi...
void BSolPol(double *b, double *x, void *data)
int find_ratf(double *intv, ratparams *rat)
void SetupPolRec(int n, int max_deg, double tol, double lmin, double lmax, BSolDataPol *data)
void FreeBSolPolData(BSolDataPol *data)
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac
parameters for rational filter