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);
16 int main(
int argc,
char *argv[]) {
35 if (stat(
"OUT", &st) == -1) {
39 if (!(fstats = fopen(
"OUT/LapPSI.out",
"w"))) {
40 printf(
" failed in opening output file in OUT/\n");
43 int n, nx, ny, nz, i, j, npts, nslices, nvec, Mdeg, nev,
44 max_its, sl, flg, ierr;
47 double a, b, lmax, lmin, ecount, tol, *sli, *mu;
64 flg =
findarg(
"help",
NA, NULL, argc, argv);
66 printf(
"Usage: ./testL.ex -nx [int] -ny [int] -nz [int] -a [double] -b [double] -nslices [int]\n");
75 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d",nx,ny,nz);
76 fprintf(fstats,
" [ a = %4.2f b= %4.2f], nslices=%2d \n",a,b,nslices);
79 lmax = nz == 1 ? 8.0 : 12.0;
88 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
89 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d\n", nx, ny, nz, n);
90 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 bound s for A: [%.15e, %.15e]\n", lmin, lmax);
108 mu = malloc((Mdeg+1)*
sizeof(
double));
110 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
113 printf(
"kpmdos error %d\n", ierr);
116 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
117 fprintf(fstats,
" estimated eig count in interval: %10.2e \n",ecount);
120 sli = malloc((nslices+1)*
sizeof(
double));
122 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
124 printf(
"spslicer error %d\n", ierr);
127 printf(
"==================== SLICES FOUND ====================\n");
128 for (j=0; j<nslices;j++)
129 printf(
" %2d: [% .15e , % .15e]\n", j+1, sli[j],sli[j+1]);
133 vinit = (
double *) malloc(n*
sizeof(
double));
140 for (sl=0; sl<nslices; sl++){
141 printf(
"======================================================\n");
143 double *lam, *Y, *res;
150 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
154 nev = (int) (1 + ecount / ((
double) nslices));
155 nev = (int)(fac*nev);
158 xintv[0] = a; xintv[1] = b;
159 xintv[2] = lmin; xintv[3] = lmax;
171 fprintf(fstats,
" polynomial [type = %d], deg %d, bar %e gam %e\n",
176 V0 = (
double *) malloc(n*nev*
sizeof(
double));
179 ierr =
ChebSI(nev, xintv, max_its, tol, V0, &pol, &nevOut,
180 &lam, &Y, &res, fstats);
182 printf(
"ChebSI error %d\n", ierr);
189 ind = (
int *) malloc(nevOut*
sizeof(
int));
192 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
193 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nevOut);
196 fprintf(fstats,
" Eigenvalues in [a, b]\n");
197 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]",
199 if (nevOut == nev_ex) {
200 fprintf(fstats,
" Err");
202 fprintf(fstats,
"\n");
203 for (i=0; i<
max(nevOut, nev_ex); i++) {
205 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
207 fprintf(fstats,
" ");
210 fprintf(fstats,
" % .15e", lam_ex[i]);
212 if (nevOut == nev_ex) {
213 fprintf(fstats,
" % .1e", lam[i]-lam_ex[i]);
215 fprintf(fstats,
"\n");
217 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 SetAMatrix(csrMat *A)
Set the matrix A.
void rand_double(int n, double *v)
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
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)
int EVSLStart()
Initialize evslData.
int ChebSI(int nev, double *intv, int maxit, double tol, double *vinit, polparams *pol, int *nevo, double **lamo, double **Yo, double **reso, FILE *fstats)
Chebyshev polynomial filtering Subspace Iteration.
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].
int main(int argc, char *argv[])
void set_pol_def(polparams *pol)
set default values for polparams struct.
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 lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.