9 #include <sys/utsname.h>
16 int exDOS(
double *vals,
int n,
int npts,
double *x,
double *y,
double *intv);
20 #define max(a, b) ((a) > (b) ? (a) : (b))
21 #define min(a, b) ((a) < (b) ? (a) : (b))
31 int readVec(
const char *filename,
int *npts,
double **vec) {
33 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]));
52 int main(
int argc,
char *argv[]) {
54 const int msteps = 40;
63 FILE *flog = stdout, *fmat = NULL, *fstats = NULL;
65 int numat, mat, ierr, n=0, graph_exact_dos = 0;
68 findarg(
"graph_exact_dos",
INT, &graph_exact_dos, argc, argv);
74 if (NULL == (fmat = fopen(
"matfile",
"r"))) {
75 fprintf(flog,
"Can't open matfile...\n");
80 if (NULL == fgets(line,
MAX_LINE, fmat)) {
81 fprintf(flog,
"error in reading matfile...\n");
84 if ((numat = atoi(line)) <= 0) {
85 fprintf(flog,
"Invalid count of matrices...\n");
89 for (mat = 1; mat <= numat; mat++) {
91 fprintf(flog,
"Invalid format in matfile ...\n");
95 fprintf(flog,
"MATRIX: %s...\n", io.
MatNam);
99 strcpy(path,
"OUT/LanDos_");
101 strcat(path,
".log");
102 fstats = fopen(path,
"w");
104 printf(
" failed in opening output file in OUT/\n");
107 fprintf(fstats,
"MATRIX: %s...\n", io.
MatNam);
112 fprintf(fstats,
"matrix read successfully\n");
116 fprintf(flog,
"read_coo error = %d\n", ierr);
123 fprintf(flog,
"HB FORMAT not supported (yet) * \n");
135 double *xHist = NULL;
136 double *yHist = NULL;
137 if (graph_exact_dos) {
138 xHist = (
double *)malloc(npts *
sizeof(
double));
139 yHist = (
double *)malloc(npts *
sizeof(
double));
142 (
double *)malloc(npts *
sizeof(
double));
144 (
double *)malloc(npts *
sizeof(
double));
149 double *vinit = (
double *)malloc(n *
sizeof(
double));
151 double lmin = 0.0, lmax = 0.0;
152 ierr =
LanTrbounds(50, 200, 1e-8, vinit, 1, &lmin, &lmax, fstats);
162 if (graph_exact_dos) {
163 readVec(
"NM1AB_eigenvalues.dat", &numev, &ev);
167 ret =
LanDos(nvec, msteps, npts, xdos, ydos, &neig, intv);
168 fprintf(stdout,
" LanDos ret %d \n", ret);
171 if (graph_exact_dos) {
172 ret =
exDOS(Acoo.
vv, Acoo.
ncols, npts, xHist, yHist, intv);
173 fprintf(stdout,
" exDOS ret %d \n", ret);
179 struct stat st = {0};
180 if (stat(
"OUT", &st) == -1) {
185 char computed_path[1024];
186 strcpy(computed_path,
"OUT/LanDos_Approx_DOS_");
187 strcat(computed_path, io.
MatNam);
188 FILE *ofp = fopen(computed_path,
"w");
189 for (i = 0; i < npts; i++) {
190 fprintf(ofp,
" %10.4f %10.4f\n", xdos[i], ydos[i]);
194 if (graph_exact_dos) {
196 strcpy(path,
"OUT/LanDosG_Exact_DOS_");
198 ofp = fopen(path,
"w");
199 for (i = 0; i < npts; i++)
200 fprintf(ofp,
" %10.4f %10.4f\n", xHist[i], yHist[i]);
203 printf(
"The data output is located in OUT/ \n");
204 struct utsname buffer;
206 if (uname(&buffer) != 0) {
211 strcpy(command,
"gnuplot ");
212 strcat(command,
" -e \"filename='");
213 strcat(command, computed_path);
215 if (graph_exact_dos) {
216 strcat(command,
"';exact_dos='");
217 strcat(command, path);
218 strcat(command,
"'\" tester_ex.gnuplot");
219 ierr = system(command);
221 strcat(command,
"'\" tester.gnuplot");
222 ierr = system(command);
227 "Error using 'gnuplot < tester.gnuplot', \n"
228 "postscript plot could not be generated \n");
230 printf(
"A postscript graph has been placed in %s%s\n", computed_path,
233 if (!strcmp(buffer.sysname,
"Linux")) {
234 strcpy(command,
"gv ");
235 strcat(command, computed_path);
236 strcat(command,
".eps &");
237 ierr = system(command);
239 fprintf(stderr,
"Error using 'gv %s' \n", command);
241 "To view the postscript graph use a postcript viewer such as "
246 "To view the postscript graph use a postcript viewer such as "
251 if (graph_exact_dos) {
void free_coo(cooMat *coo)
memory deallocation for coo matrix
int main(int argc, char *argv[])
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 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 exDOS(double *vals, int n, int npts, double *x, double *y, double *intv)
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
int SetStdEig()
Set the problem to standard eigenvalue problem.
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 read_coo_MM(const char *matfile, int idxin, int idxout, cooMat *Acoo)
int readVec(const char *filename, int *npts, double **vec)
int get_matrix_info(FILE *fmat, io_t *pio)
sparse matrix format: the coordinate (COO) format, 0-based