10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define min(a, b) ((a) < (b) ? (a) : (b))
23 int n=0, sl, i, j, mlan, nev, totcnt;
25 double a, b, ecount, xintv[4];
42 int max_its, Mdeg, nvec;
44 FILE *flog = stdout, *fmat = NULL, *fstats = NULL;
57 double *mu = malloc((Mdeg+1)*
sizeof(
double));
61 if( NULL == ( fmat = fopen(
"matfile",
"r" ) ) ) {
62 fprintf( flog,
"Can't open matfile...\n" );
67 if (NULL == fgets( line,
MAX_LINE, fmat )) {
68 fprintf( flog,
"error in reading matfile...\n" );
71 if( ( numat = atoi( line ) ) <= 0 ) {
72 fprintf( flog,
"Invalid count of matrices...\n" );
76 for(mat = 1; mat <= numat; mat++) {
78 fprintf(flog,
"Invalid format in matfile ...\n");
82 fprintf(flog,
"MATRIX: %s...\n", io.
MatNam);
88 if (stat(
"OUT", &st) == -1) {
94 strcpy( path,
"OUT/MMPLanR_OMP_");
96 fstats = fopen(path,
"w");
98 printf(
" failed in opening output file in OUT/\n");
101 fprintf(fstats,
"MATRIX: %s...\n", io.
MatNam);
102 fprintf(fstats,
"Partition the interval of interest [%f,%f] into %d slices\n", a,b,n_intv);
103 counts = malloc(n_intv*
sizeof(
int));
104 sli = malloc((n_intv+1)*
sizeof(
double));
109 fprintf(fstats,
"matrix read successfully\n");
114 fprintf(flog,
"read_coo error = %d\n", ierr);
121 fprintf(flog,
"HB FORMAT not supported (yet) * \n");
127 alleigs = (
double *) malloc(n*
sizeof(
double));
128 vinit = (
double *) malloc(n*
sizeof(
double));
131 ierr =
LanTrbounds(50, 200, 1e-8, vinit, 1, &lmin, &lmax, fstats);
132 fprintf(fstats,
"Step 0: Eigenvalue bounds for A: [%.15e, %.15e]\n", lmin, lmax);
135 fprintf(fstats,
" --> interval: a %9.3e b %9.3e \n",a, b);
137 xintv[0] = a; xintv[1] = b;
138 xintv[2] = lmin; xintv[3] = lmax;
144 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
147 printf(
"kpmdos error %d\n", ierr);
150 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
151 fprintf(fstats,
"Step 1a: Estimated eig count in interval - %.15e \n",ecount);
152 if ((ecount <0) | (ecount > n)) {
153 printf(
" e-count estimate is incorrect \n ");
163 ierr =
spslicer(sli, mu, Mdeg, xintv, n_intv, npts);
165 printf(
"spslicer error %d\n", ierr);
169 fprintf(fstats,
"DOS parameters: Mdeg = %d, nvec = %d, npts = %d\n",
171 fprintf(fstats,
"Step 1b: Slices found: \n");
172 for (j=0; j<n_intv;j++) {
173 fprintf(fstats,
" %2d: [%.15e , %.15e]\n", j+1, sli[j],sli[j+1]);
178 nev = (int) (1 + ecount / ((
double) n_intv));
179 nev = (int)(fac*nev);
180 fprintf(fstats,
"Step 2: In each slice compute %d eigenvalues ... \n", nev);
184 mlan =
max(4*nev,300); mlan =
min(n, mlan);
187 double *lam_global, *res_global;
188 lam_global = (
double *) malloc(nev*n_intv*
sizeof(
double));
189 res_global = (
double *) malloc(nev*n_intv*
sizeof(
double));
191 #pragma omp parallel for private(sl)
192 for (sl=0; sl<n_intv; sl++) {
194 double *lam, *Y, *res;
214 fprintf(fstats,
" polynomial [type = %d], deg %d, bar %e gam %e\n",
217 ierr =
ChebLanTr(mlan, nev, intv, max_its, tol, vinit,
218 &pol, &nevOut, &lam, &Y, &res, NULL);
220 printf(
"ChebLanTr error %d\n", ierr);
224 ind = (
int *) malloc(nevOut*
sizeof(
int));
227 res_sorted = (
double *) malloc(nevOut*
sizeof(
double));
228 for (j=0; j<nevOut; j++){
229 res_sorted[j] = res[ind[j]];
233 memcpy(&lam_global[sl*nev],lam,nevOut*
sizeof(
double));
234 memcpy(&res_global[sl*nev],res_sorted,nevOut*
sizeof(
double));
249 for (sl=0; sl<n_intv; sl++) {
254 fprintf(fstats,
"======================================================\n");
255 fprintf(fstats,
" subinterval: [% 12.4e , % 12.4e ]\n", a, b);
256 fprintf(fstats,
"Thick Restarted Lanczos with dimension %d\n", mlan);
257 fprintf(fstats,
"Max Lanczos steps %d\n", max_its);
260 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
261 fprintf(fstats,
" Eigenvalues in [%f, %f]\n",a,b);
262 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
263 fprintf(fstats,
" Computed [%d out of %d estimated] ||Res|| ", counts[sl], nev);
264 fprintf(fstats,
"\n");
265 for (i=0; i<counts[sl]; i++) {
266 fprintf(fstats,
" % .15e %.1e",
267 lam_global[sl*nev+i], res_global[sl*nev+i]);
268 fprintf(fstats,
"\n");
270 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - -\n");
272 memcpy(&alleigs[totcnt],&lam_global[sl*nev],counts[sl]*
sizeof(
double));
273 totcnt += counts[sl];
275 fprintf(fstats,
"Solution time : %.2f\n", tsolve);
276 fprintf(fstats,
" --> Total eigenvalues found = %d\n",totcnt);
290 if (fstats != stdout) fclose(fstats);
295 if( flog != stdout ) fclose ( flog );
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 LanTrbounds(int lanm, int maxit, double tol, double *vinit, int bndtype, double *lammin, double *lammax, FILE *fstats)
Lanczos process for eigenvalue bounds [Thick restart version].
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
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...
int read_coo_MM(const char *matfile, int idxin, int idxout, cooMat *Acoo)
parameters for polynomial filter
void linspace(double a, double b, int num, double *arr)
int get_matrix_info(FILE *fmat, io_t *pio)
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac