9 #include <sys/utsname.h>
16 int exDOS(
double *vals,
int n,
int npts,
double *x,
double *y,
double *intv);
22 #define max(a, b) ((a) > (b) ? (a) : (b))
23 #define min(a, b) ((a) < (b) ? (a) : (b))
32 int readVec(
const char *filename,
int *npts,
double **vec) {
34 FILE *ifp = fopen(filename,
"r");
35 fscanf(ifp,
"%i", npts);
36 *vec = (
double *)malloc(
sizeof(
double) * *npts);
37 for (i = 0; i < (*npts); i++) {
38 fscanf(ifp,
"%lf", (&(*vec)[i]));
53 int main(
int argc,
char *argv[]) {
55 const int msteps = 30;
59 const double tau = 1e-4;
69 double *sqrtdiag = NULL;
71 FILE *flog = stdout, *fmat = NULL;
76 int graph_exact_dos = 0;
77 findarg(
"graph_exact_dos",
INT, &graph_exact_dos, argc, argv);
81 if (NULL == (fmat = fopen(
"matfileG",
"r"))) {
82 fprintf(flog,
"Can't open matfileG...\n");
85 printf(
"Read matfileG \n");
89 if (NULL == fgets(line,
MAX_LINE, fmat)) {
90 fprintf(flog,
"error in reading matfile...\n");
93 if ((numat = atoi(line)) <= 0) {
94 fprintf(flog,
"Invalid count of matrices...\n");
97 for (mat = 1; mat <= numat; mat++) {
99 fprintf(flog,
"Invalid format in matfile ...\n");
103 fprintf(flog,
"MATRIX A: %s...\n", io.
MatNam1);
104 fprintf(flog,
"MATRIX B: %s...\n", io.
MatNam2);
106 strcpy(path,
"OUT/LanDosG_");
108 strcat(path,
".log");
109 fstats = fopen(path,
"w");
111 printf(
" failed in opening output file in OUT/\n");
114 fprintf(fstats,
"MATRIX A: %s...\n", io.
MatNam1);
115 fprintf(fstats,
"MATRIX B: %s...\n", io.
MatNam2);
120 fprintf(fstats,
"matrix read successfully\n");
124 fprintf(stderr,
"non-positive number of rows");
131 fprintf(flog,
"read_coo error for A = %d\n", ierr);
136 fprintf(fstats,
"matrix read successfully\n");
137 if (Bcoo.
nrows != n) {
141 fprintf(flog,
"read_coo error for B = %d\n", ierr);
145 sqrtdiag = (
double *)calloc(n,
sizeof(
double));
149 fprintf(flog,
"Could not convert matrix to csr: %i", ierr);
154 fprintf(flog,
"Could not convert matrix to csr: %i", ierr);
157 }
else if (io.
Fmt ==
HB) {
158 fprintf(flog,
"HB FORMAT not supported (yet) * \n");
167 for (i = 0; i < n; i++) {
168 sqrtdiag[i] = sqrt(sqrtdiag[i]);
177 double *vinit = (
double *)malloc(n *
sizeof(
double));
179 double lmin = 0.0, lmax = 0.0;
180 ierr =
LanTrbounds(50, 200, 1e-8, vinit, 1, &lmin, &lmax, fstats);
182 fprintf(flog,
"Could not run LanTrBounds: %i", ierr);
193 "The degree for LS polynomial approximations to B^{-1} and B^{-1/2} "
204 ierr =
LanTrbounds(40, 200, 1e-10, vinit, 1, &lmin, &lmax, fstats);
206 fprintf(flog,
"Could not run LanTrBounds: %i", ierr);
218 if (graph_exact_dos) {
219 readVec(
"NM1AB_eigenvalues.dat", &numev, &ev);
224 double *xHist = NULL;
225 double *yHist = NULL;
227 if (graph_exact_dos) {
228 xHist = (
double *)malloc(npts *
sizeof(
double));
229 yHist = (
double *)malloc(npts *
sizeof(
double));
231 double *xdos = (
double *)malloc(npts *
sizeof(
double));
232 double *ydos = (
double *)malloc(npts *
sizeof(
double));
236 ret =
LanDosG(nvec, msteps, npts, xdos, ydos, &neig, intv);
238 fprintf(stdout,
" LanDos ret %d in %0.04fs\n", ret, t1 - t0);
241 if (graph_exact_dos) {
242 ret =
exDOS(ev, numev, npts, xHist, yHist, intv);
243 fprintf(stdout,
" exDOS ret %d \n", ret);
255 struct stat st = {0};
256 if (stat(
"OUT", &st) == -1) {
261 char computed_path[1024];
262 strcpy(computed_path,
"OUT/LanDosG_Approx_DOS_");
263 strcat(computed_path, io.
MatNam1);
264 FILE *ofp = fopen(computed_path,
"w");
265 for (i = 0; i < npts; i++)
266 fprintf(ofp,
" %10.4f %10.4f\n", xdos[i], ydos[i]);
268 printf(
"Wrote to:%s \n", computed_path);
270 if (graph_exact_dos) {
272 strcpy(path,
"OUT/LanDosG_Exact_DOS_");
274 ofp = fopen(path,
"w");
275 for (i = 0; i < npts; i++)
276 fprintf(ofp,
" %10.4f %10.4f\n", xHist[i], yHist[i]);
280 printf(
"The data output is located in OUT/ \n");
281 struct utsname buffer;
283 if (uname(&buffer) != 0) {
290 strcpy(command,
"gnuplot ");
291 strcat(command,
" -e \"filename='");
292 strcat(command, computed_path);
294 if (graph_exact_dos) {
295 strcat(command,
"';exact_dos='");
296 strcat(command, path);
297 strcat(command,
"'\" testerG_ex.gnuplot");
298 ierr = system(command);
300 strcat(command,
"'\" testerG.gnuplot");
301 ierr = system(command);
306 "Error using 'gnuplot < testerG.gnuplot', \n"
307 "postscript plot could not be generated \n");
309 printf(
"A postscript graph has been placed in %s%s\n", computed_path,
312 if (!strcmp(buffer.sysname,
"Linux")) {
313 strcpy(command,
"gv ");
314 strcat(command, computed_path);
315 strcat(command,
".eps &");
316 ierr = system(command);
318 fprintf(stderr,
"Error using 'gv %s' \n", command);
320 "To view the postscript graph use a postcript viewer such as "
325 "To view the postscript graph use a postcript viewer such as "
329 if (graph_exact_dos) {
int get_matrix_info(FILE *fmat, io_t *pio)
void free_coo(cooMat *coo)
memory deallocation for coo matrix
void extrDiagCsr(csrMat *B, double *d)
int SetGenEig()
Set the problem to generalized eigenvalue problem.
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 read_coo_MM(const char *matfile, int idxin, int idxout, cooMat *Acoo)
int SetBMatrix(csrMat *B)
Set the B matrix.
int EVSLStart()
Initialize evslData.
void free_csr(csrMat *csr)
memory deallocation for csr matrix
int readVec(const char *filename, int *npts, double **vec)
void diagScalCsr(csrMat *A, double *d)
void SetupPolSqrt(int n, int max_deg, double tol, double lmin, double lmax, BSolDataPol *data)
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
int LanDosG(const int nvec, const int msteps, int npts, double *xdos, double *ydos, double *neig, const double *const intv)
int main(int argc, char *argv[])
int SetLTSol(SolFuncR func, void *data)
Set the solve routine for LT.
int SetStdEig()
Set the problem to standard eigenvalue problem.
sparse matrix format: the compressed sparse row (CSR) format, 0-based
int exDOS(double *vals, int n, int npts, double *x, double *y, double *intv)
This file contains function prototypes and constant definitions for EVSL.
int EVSLFinish()
Finish EVSL.
int SetBSol(SolFuncR func, void *data)
Set the solve routine and the associated data for B.
void BSolPol(double *b, double *x, void *data)
void SetupPolRec(int n, int max_deg, double tol, double lmin, double lmax, BSolDataPol *data)
void FreeBSolPolData(BSolDataPol *data)
sparse matrix format: the coordinate (COO) format, 0-based
double evsl_timer()
evsl timer for mac