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, 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/LapPLanN.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");
67 flg =
findarg(
"stdout",
NA, NULL, argc, argv);
77 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d",nx,ny,nz);
78 fprintf(fstats,
" [a = %f b = %f], nslices=%2d \n",a,b,nslices);
81 lmax = nz == 1 ? 8.0 : 12.0;
89 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
90 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d\n", nx, ny, nz, n);
91 fprintf(fstats,
"Interval: [%20.15f, %20.15f] -- %d slices \n", a, b, nslices);
94 ierr =
lapgen(nx, ny, nz, &Acoo);
98 fprintf(fstats,
"Step 0: Eigenvalue bounds for A: [%.15e, %.15e]\n", lmin, lmax);
108 mu = (
double *) malloc((Mdeg+1)*
sizeof(double));
114 xdos = (
double *) malloc((npts)*
sizeof(double));
115 ydos = (
double *) malloc((npts)*
sizeof(double));
118 LanDos(nvec, Mdeg, npts, xdos, ydos, &ecount, xintv);
126 fprintf(fstats,
" Time to build DOS (Landos) was : %10.2f \n",t);
127 fprintf(fstats,
" estimated eig count in interval: %.15e \n",ecount);
130 sli = malloc((nslices+1)*
sizeof(
double));
132 fprintf(fstats,
"DOS parameters: Mdeg = %d, nvec = %d, npnts = %d\n",
134 spslicer2(xdos, ydos, nslices, npts, sli);
138 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
141 printf(
"kpmdos error %d\n", ierr);
144 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
145 fprintf(fstats,
" estimated eig count in interval: %.15e \n",ecount);
146 fprintf(stdout,
" estimated eig count in interval: %.15e \n",ecount);
149 sli = malloc((nslices+1)*
sizeof(
double));
151 fprintf(fstats,
"DOS parameters: Mdeg = %d, nvec = %d, npnts = %d\n",Mdeg, nvec, npts);
152 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
156 printf(
"spslicer error %d\n", ierr);
159 printf(
"==================== SLICES FOUND ====================\n");
160 for (j=0; j<nslices;j++) {
161 printf(
" %2d: [% .15e , % .15e]\n", j+1, sli[j],sli[j+1]);
164 ev_int = (int) (1 + ecount / ((
double) nslices));
166 vinit = (
double *) malloc(n*
sizeof(
double));
171 for (sl=0; sl<nslices; sl++){
172 printf(
"======================================================\n");
174 double *lam, *Y, *res;
182 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
186 mlan =
max(5*nev, 300);
189 xintv[0] = a; xintv[1] = b;
190 xintv[2] = lmin; xintv[3] = lmax;
206 fprintf(fstats,
" polynomial [type = %d], deg %d, bar %e gam %e\n",
209 ierr =
ChebLanNr(xintv, mlan, tol, vinit, &pol, &nev2, &lam, &Y, &res, fstats);
211 printf(
"ChebLanNr error %d\n", ierr);
218 ind = (
int *) malloc(nev2*
sizeof(
int));
221 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
222 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nev2);
225 fprintf(fstats,
" Eigenvalues in [a, b]\n");
226 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]", nev2, nev_ex);
227 if (nev2 == nev_ex) {
228 fprintf(fstats,
" Err");
230 fprintf(fstats,
"\n");
231 for (i=0; i<
max(nev2, nev_ex); i++) {
233 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
235 fprintf(fstats,
" ");
238 fprintf(fstats,
" % .15e", lam_ex[i]);
240 if (nev2 == nev_ex) {
241 fprintf(fstats,
" % .1e", lam[i]-lam_ex[i]);
243 fprintf(fstats,
"\n");
245 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 LanDos(const int nvec, int msteps, int npts, double *xdos, double *ydos, double *neig, const double *const intv)
int SetAMatrix(csrMat *A)
Set the matrix A.
void StatsPrint(FILE *fstats)
void rand_double(int n, double *v)
int cooMat_to_csrMat(int cooidx, cooMat *coo, csrMat *csr)
convert coo to csr
int find_pol(double *intv, polparams *pol)
Sets the values in pol.
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.
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
void free_csr(csrMat *csr)
memory deallocation for csr matrix
void set_pol_def(polparams *pol)
set default values for polparams struct.
int main(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 ChebLanNr(double *intv, int maxit, double tol, double *vinit, polparams *pol, int *nevOut, double **lamo, double **Wo, double **reso, FILE *fstats)
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
int exeiglap3(int nx, int ny, int nz, double a, double b, int *m, double **vo)
Exact eigenvalues of Laplacean in interval [a b].
int lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac