11 #define max(a, b) ((a) > (b) ? (a) : (b))
12 #define min(a, b) ((a) < (b) ? (a) : (b))
14 int findarg(
const char *argname,
ARG_TYPE type,
void *val,
int argc,
char **argv);
16 int exeiglap3(
int nx,
int ny,
int nz,
double a,
double b,
int *m,
double **vo);
18 int main(
int argc,
char *argv[]) {
33 int n, nx, ny, nz, i, j, npts, nslices, nvec, Mdeg, nev,
34 max_its, ev_int, sl, flg, ierr;
36 double a, b, lmax, lmin, ecount, tol, *sli, *mu;
46 if (stat(
"OUT", &st) == -1) {
51 if (!(fstats = fopen(
"OUT/LapRLanN.out",
"w"))) {
52 printf(
" failed in opening output file in OUT/\n");
59 printf(
"-----------------------------------------\n");
60 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");
61 printf(
"-----------------------------------------\n");
73 flg =
findarg(
"help",
NA, NULL, argc, argv);
75 printf(
"Usage: ./testL.ex -nx [int] -ny [int] -nz [int] -a [double] -b [double] -nslices [int]\n");
84 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d",nx,ny,nz);
85 fprintf(fstats,
" [a = %4.2f b= %4.2f], nslices=%2d \n",a,b,nslices);
88 lmax = ((nz == 1)? 8.0 :12) ;
97 ierr =
lapgen(nx, ny, nz, &Acoo);
101 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
102 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d, nnz = %d\n", nx, ny, nz, n, Acoo.
nnz);
103 fprintf(fstats,
"Interval: [%20.15f, %20.15f] -- %d slices \n", a, b, nslices);
104 fprintf(fstats,
"Step 0: Eigenvalue bound s for A: [%.15e, %.15e]\n", lmin, lmax);
114 mu = malloc((Mdeg+1)*
sizeof(
double));
116 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
119 printf(
"kpmdos error %d\n", ierr);
122 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
123 fprintf(fstats,
" estimated eig count in interval: %10.2e \n",ecount);
126 sli = malloc((nslices+1)*
sizeof(
double));
127 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
129 printf(
"spslicer error %d\n", ierr);
132 printf(
"==================== SLICES FOUND ====================\n");
133 for (j=0; j<nslices;j++) {
134 printf(
" %2d: [% .15e , % .15e]\n", j+1, sli[j],sli[j+1]);
137 ev_int = (int) (1 + ecount / ((
double) nslices));
139 vinit = (
double*) malloc(n*
sizeof(
double));
142 for (sl=0; sl<nslices; sl++) {
143 printf(
"======================================================\n");
145 double *lam, *Y, *res;
153 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
170 void **solshiftdata = (
void **) malloc(rat.
num*
sizeof(
void *));
178 max_its =
max(4*nev,300); max_its =
min(max_its, n);
180 ierr =
RatLanNr(intv, max_its, tol, vinit, &rat, &nev2, &lam,
183 printf(
"RatLanNr error %d\n", ierr);
189 ind = (
int *) malloc(nev2*
sizeof(
int));
192 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
193 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nev2);
195 fprintf(fstats,
" Eigenvalues in [a, b]\n");
196 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]",
198 if (nev2 == nev_ex) {
199 fprintf(fstats,
" Err");
201 fprintf(fstats,
"\n");
202 for (i=0; i<
max(nev2, nev_ex); i++) {
204 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
206 fprintf(fstats,
" ");
209 fprintf(fstats,
" % .15e", lam_ex[i]);
211 if (nev2 == nev_ex) {
212 fprintf(fstats,
" % .1e", lam[i]-lam_ex[i]);
214 fprintf(fstats,
"\n");
216 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
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 StatsPrint(FILE *fstats)
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
int main(int argc, char *argv[])
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 sort_double(int n, double *v, int *ind)
int EVSLStart()
Initialize evslData.
void free_csr(csrMat *csr)
memory deallocation for csr matrix
int RatLanNr(double *intv, int maxit, double tol, double *vinit, ratparams *rat, int *nevOut, double **lamo, double **Wo, double **reso, FILE *fstats)
Rational filtering Lanczos process [NON-restarted version].
int lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.
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...
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 findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
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