11 #define max(a, b) ((a) > (b) ? (a) : (b))
12 #define min(a, b) ((a) < (b) ? (a) : (b))
17 int exeiglap3(
int nx,
int ny,
int nz,
double a,
double b,
int *m,
double **vo);
19 int main(
int argc,
char *argv[]) {
34 int n, nx, ny, nz, i, j, npts, nslices, nvec, Mdeg, nev, mlan, max_its,
35 ev_int, sl, flg, ierr;
37 double a, b, lmax, lmin, ecount, tol, *sli, *mu;
47 if (stat(
"OUT", &st) == -1) {
52 if (!(fstats = fopen(
"OUT/LapRLanR.out",
"w"))) {
53 printf(
" failed in opening output file in OUT/\n");
60 printf(
"-----------------------------------------\n");
62 "Note: You are using CXSparse for the direct solver. \n We recommend a "
63 "more performance based direct solver for anything more than basic "
64 "tests. \n SuiteSparse is supported with a makefile change. \n Using "
65 "SuiteSparse can result in magnitudes faster times. \n\n ");
66 printf(
"-----------------------------------------\n");
78 flg =
findarg(
"help",
NA, NULL, argc, argv);
81 "Usage: ./testL.ex -nx [int] -ny [int] -nz [int] -a [double] -b "
82 "[double] -nslices [int]\n");
91 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d", nx, ny, nz);
92 fprintf(fstats,
" [a = %4.2f b= %4.2f], nslices=%2d \n", a, b, nslices);
95 lmax = nz == 1 ? 8.0 : 12.0;
104 ierr =
lapgen(nx, ny, nz, &Acoo);
109 "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
110 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d, nnz = %d\n", nx, ny, nz, n,
112 fprintf(fstats,
"Interval: [%20.15f, %20.15f] -- %d slices \n", a, b,
114 fprintf(fstats,
"Step 0: Eigenvalue bound s for A: [%.15e, %.15e]\n", lmin,
125 mu = malloc((Mdeg + 1) *
sizeof(
double));
127 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
130 printf(
"kpmdos error %d\n", ierr);
133 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n", t);
134 fprintf(fstats,
" estimated eig count in interval: %10.2e \n", ecount);
137 sli = malloc((nslices + 1) *
sizeof(
double));
138 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
140 printf(
"spslicer error %d\n", ierr);
143 printf(
"==================== SLICES FOUND ====================\n");
144 for (j = 0; j < nslices; j++) {
145 printf(
" %2d: [% .15e , % .15e]\n", j + 1, sli[j], sli[j + 1]);
148 ev_int = (int)(1 + ecount / ((
double)nslices));
150 vinit = (
double *)malloc(n *
sizeof(
double));
153 for (sl = 0; sl < nslices; sl++) {
154 printf(
"======================================================\n");
156 double *lam, *Y, *res;
163 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
180 void **solshiftdata = (
void **)malloc(num *
sizeof(
void *));
188 mlan =
max(4 * nev, 300);
192 ierr =
RatLanTr(mlan, nev, intv, max_its, tol, vinit, &rat, &nev2, &lam, &Y,
195 printf(
"RatLanTr error %d\n", ierr);
201 ind = (
int *)malloc(nev2 *
sizeof(
int));
204 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
205 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nev2);
208 " Eigenvalues in [a, b]\n");
209 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]",
211 if (nev2 == nev_ex) {
212 fprintf(fstats,
" Err");
214 fprintf(fstats,
"\n");
215 for (i = 0; i <
max(nev2, nev_ex); i++) {
217 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
219 fprintf(fstats,
" ");
222 fprintf(fstats,
" % .15e", lam_ex[i]);
224 if (nev2 == nev_ex) {
225 fprintf(fstats,
" % .1e", lam[i] - lam_ex[i]);
227 fprintf(fstats,
"\n");
229 fprintf(fstats,
" -- More not shown --\n");
int kpmdos(int Mdeg, int damping, int nvec, double *intv, double *mu, double *ecnt)
This function computes the coefficients of the density of states in the chebyshev basis...
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 main(int argc, char *argv[])
void free_rat(ratparams *rat)
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
void FreeASIGMABSolDirect(int num, void **data)
free the data needed by CXSparse
void sort_double(int n, double *v, int *ind)
int lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.
int EVSLStart()
Initialize evslData.
void free_csr(csrMat *csr)
memory deallocation for csr matrix
int exeiglap3(int nx, int ny, int nz, double a, double b, int *m, double **vo)
Exact eigenvalues of Laplacean in interval [a b].
sparse matrix format: the compressed sparse row (CSR) format, 0-based
This file contains function prototypes and constant definitions for EVSL.
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
int EVSLFinish()
Finish EVSL.
int spslicer(double *sli, double *mu, int Mdeg, double *intv, int n_int, int npts)
given the dos function defined by mu find a partitioning of sub-interval [a,b] of the spectrum so eac...
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.
int find_ratf(double *intv, ratparams *rat)
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac
parameters for rational filter