9 #define max(a, b) ((a) > (b) ? (a) : (b))
10 #define min(a, b) ((a) < (b) ? (a) : (b))
11 int findarg(
const char *argname,
ARG_TYPE type,
void *val,
int argc,
char **argv);
13 int exeiglap3(
int nx,
int ny,
int nz,
double a,
double b,
int *m,
double **vo);
15 int main(
int argc,
char *argv[]) {
30 int n, nx, ny, nz, i, j, npts, nslices, nvec, Mdeg, nev,
31 mlan, max_its, ev_int, sl, flg, ierr;
33 double a, b, lmax, lmin, ecount, tol, *sli, *mu;
39 if (stat(
"OUT", &st) == -1) {
44 if (!(fstats = fopen(
"OUT/LapPLanR.out",
"w"))) {
45 printf(
" failed in opening output file in OUT/\n");
61 flg =
findarg(
"help",
NA, NULL, argc, argv);
63 printf(
"Usage: ./testL.ex -nx [int] -ny [int] -nz [int] -a [double] -b [double] -nslices [int]\n");
72 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d",nx,ny,nz);
73 fprintf(fstats,
" [a = %4.2f b= %4.2f], nslices=%2d \n",a,b,nslices);
76 lmax = nz == 1 ? 8.0 : 12.0;
84 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
85 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d\n", nx, ny, nz, n);
86 fprintf(fstats,
"Interval: [%20.15f, %20.15f] -- %d slices \n", a, b, nslices);
89 ierr =
lapgen(nx, ny, nz, &Acoo);
93 fprintf(fstats,
"Step 0: Eigenvalue bound s for A: [%.15e, %.15e]\n", lmin, lmax);
103 mu = malloc((Mdeg+1)*
sizeof(
double));
105 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
108 printf(
"kpmdos error %d\n", ierr);
111 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
112 fprintf(fstats,
" estimated eig count in interval: %.15e \n",ecount);
115 sli = malloc((nslices+1)*
sizeof(
double));
117 fprintf(fstats,
"DOS parameters: Mdeg = %d, nvec = %d, npnts = %d\n",Mdeg, nvec, npts);
118 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
120 printf(
"spslicer error %d\n", ierr);
123 printf(
"==================== SLICES FOUND ====================\n");
124 for (j=0; j<nslices;j++) {
125 printf(
" %2d: [% .15e , % .15e]\n", j+1, sli[j],sli[j+1]);
128 ev_int = (int) (1 + ecount / ((
double) nslices));
130 vinit = (
double *) malloc(n*
sizeof(
double));
135 for (sl =0; sl<nslices; sl++){
136 printf(
"======================================================\n");
138 double *lam, *Y, *res;
145 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
149 mlan =
max(4*nev, 300);
153 xintv[0] = a; xintv[1] = b;
154 xintv[2] = lmin; xintv[3] = lmax;
170 fprintf(fstats,
" polynomial [type = %d], deg %d, bar %e gam %e\n",
173 ierr =
ChebLanTr(mlan, nev, xintv, max_its, tol, vinit,
174 &pol, &nev2, &lam, &Y, &res, fstats);
176 printf(
"ChebLanTr error %d\n", ierr);
182 ind = (
int *) malloc(nev2*
sizeof(
int));
185 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
186 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nev2);
189 fprintf(fstats,
" Eigenvalues in [a, b]\n");
190 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]", nev2, nev_ex);
191 if (nev2 == nev_ex) {
192 fprintf(fstats,
" Err");
194 fprintf(fstats,
"\n");
195 for (i=0; i<
max(nev2, nev_ex); i++) {
197 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
199 fprintf(fstats,
" ");
202 fprintf(fstats,
" % .15e", lam_ex[i]);
204 if (nev2 == nev_ex) {
205 fprintf(fstats,
" % .1e", lam[i]-lam_ex[i]);
207 fprintf(fstats,
"\n");
209 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_pol(polparams *pol)
void free_coo(cooMat *coo)
memory deallocation for coo matrix
int ChebLanTr(int lanm, int nev, double *intv, int maxit, double tol, double *vinit, polparams *pol, int *nev2, double **vals, double **W, double **resW, FILE *fstats)
Chebyshev polynomial filtering Lanczos process [Thick restart version].
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 lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.
int find_pol(double *intv, polparams *pol)
Sets the values in pol.
void sort_double(int n, double *v, int *ind)
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].
void set_pol_def(polparams *pol)
set default values for polparams struct.
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
sparse matrix format: the compressed sparse row (CSR) format, 0-based
This file contains function prototypes and constant definitions for EVSL.
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...
parameters for polynomial filter
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac
int main(int argc, char *argv[])