00001
00053 #include "apbscfg.h"
00054 #include "apbs/apbs.h"
00055 #include "apbs/vstring.h"
00056 #include "maloc/maloc.h"
00057
00058 #define ERRRC 13
00059
00060 #define F77READHBHEAD VF77_MANGLE(readhbhead, READHBHEAD)
00061 VEXTERNC void F77READHBHEAD(int *nrow, int *ncol, int *nnzero, char *path);
00062 #define F77READHB VF77_MANGLE(readhb, READHB)
00063 VEXTERNC void F77READHB(int *nrow, int *ncol, int *nnzero, double *values,
00064 int *rowind, int *colptr, char *path, char *title,
00065 char *key, char *mxtype);
00066 #define F77GETEIGS VF77_MANGLE(geteigs, GETEIGS)
00067 VEXTERNC void F77GETEIGS(int *nrow, int *ncol, int *nnzero, double *values,
00068 int *colptr, int *rowind, int *nev, int *ncv,
00069 int *key, double *v, double *workl, double *workd,
00070 double *d, double *resid, double *ax, int *select);
00071
00072 int main(int argc, char **argv) {
00073
00074 int key, nev, ncv, ncol, nrow, nnzero;
00075 int *colptr, *rowind, *select;
00076 double *values, *v, *workl, *workd, *d, *resid, *ax;
00077 char *keystr, *numstr, path[256], title[72], mxtype[3], hbkey[8];
00078
00079 char *usage = "\n\n"
00080 "This is a program which uses ARPACK to compute\n"
00081 "portions of the eigenvalue spectruc of operators.\n\n"
00082 "Usage: driver <key> <number> <path>\n\n"
00083 "Where <key> is the portion of the spec:\n"
00084 " lm => largest magnitude\n"
00085 " sm => smallest magnitude\n"
00086 " be => from both ends of spectrum\n"
00087 " <number> is the number of eigenvalues to compute\n"
00088 " <path> is the path to the matrix in Harwell-\n"
00089 " Boeing format.\n\n";
00090
00091 Vio_start();
00092
00093 if (argc != 4) {
00094 Vnm_print(2, "ERROR: Got %d arguments, expected 4!", argc);
00095 Vnm_print(1, "%s", usage);
00096 return ERRRC;
00097 }
00098
00099
00100 keystr = argv[1];
00101 if (Vstring_strcasecmp(keystr, "lm") == 0) {
00102 key = 0;
00103 Vnm_print(1, "Computing largest magnitude portion of spectrum.\n");
00104 } else if (Vstring_strcasecmp(keystr, "sm") == 0) {
00105 key = 1;
00106 Vnm_print(1, "Computing smallest magnitude portion of spectrum.\n");
00107 } else if (Vstring_strcasecmp(keystr, "be") == 0) {
00108 key = 2;
00109 Vnm_print(1, "Computing portions from both ends of spectrum.\n");
00110 } else {
00111 Vnm_print(2, "ERROR: Unrecognized key = %s\n", keystr);
00112 Vnm_print(2, "%s", usage);
00113 return ERRRC;
00114 }
00115
00116
00117 numstr = argv[2];
00118 if (sscanf(numstr, "%d", &nev) == 0) {
00119 Vnm_print(2, "ERROR: Unrecognized number of eigenvalues = %s\n",
00120 numstr);
00121 Vnm_print(2, "%s", usage);
00122 return ERRRC;
00123 }
00124 Vnm_print(1, "Computing %d eigenvalue(s).\n", nev);
00125
00126
00127 strncpy(path, argv[3], 255);
00128 Vnm_print(1, "Reading header from matrix file at %s...\n", path);
00129 F77READHBHEAD(&nrow, &ncol, &nnzero, path);
00130 Vnm_print(1, "Matrix %s contains %d rows, %d columns, and %d nonzeros.\n",
00131 path, nrow, ncol, nnzero);
00132 Vnm_print(1, "Allocating space for %d integers (colptr)...\n", (ncol+1));
00133 colptr = Vmem_malloc(VNULL, (ncol+1), sizeof(int));
00134 Vnm_print(1, "Allocating space for %d integers (rowind)...\n", nnzero);
00135 rowind = Vmem_malloc(VNULL, nnzero, sizeof(int));
00136 Vnm_print(1, "Allocating space for %d doubles (values)...\n", nnzero);
00137 values = Vmem_malloc(VNULL, nnzero, sizeof(double));
00138 Vnm_print(1, "Reading matrix from matrix file at %s...\n", path);
00139 F77READHB(&nrow, &ncol, &nnzero, values, rowind, colptr, path, title,
00140 hbkey, mxtype);
00141 Vnm_print(1, "Matrix %s (still) contains %d rows, %d columns, and %d \
00142 nonzeros.\n", path, nrow, ncol, nnzero);
00143 Vnm_print(1, "Harwell-Boeing matrix MX type = %c%c%c\n",
00144 mxtype[0], mxtype[1], mxtype[2]);
00145
00146
00147 ncv = VMIN2(nev*2, nrow/2);
00148 Vnm_print(1, "Using %d Lanczos vectors in calculation.\n", ncv);
00149 Vnm_print(1, "Allocating space for %d doubles (eigvecs)...\n",
00150 nrow*ncv);
00151 v = Vmem_malloc(VNULL, nrow*ncv, sizeof(double));
00152 Vnm_print(1, "Allocating space for %d doubles (work)...\n",
00153 ncv*(ncv+8));
00154 workl = Vmem_malloc(VNULL, ncv*(ncv+8), sizeof(double));
00155 Vnm_print(1, "Allocating space for %d doubles (work)...\n",
00156 3*ncol);
00157 workd = Vmem_malloc(VNULL, 3*ncol, sizeof(double));
00158 Vnm_print(1, "Allocating space for %d doubles (eigvals)...\n",
00159 2*ncv);
00160 d = Vmem_malloc(VNULL, 2*ncv, sizeof(double));
00161 Vnm_print(1, "Allocating space for %d doubles (residuals)...\n",
00162 nrow);
00163 resid = Vmem_malloc(VNULL, nrow, sizeof(double));
00164 Vnm_print(1, "Allocating space for %d doubles (work)...\n",
00165 nrow);
00166 ax = Vmem_malloc(VNULL, nrow, sizeof(double));
00167 Vnm_print(1, "Allocating space for %d integers (work)...\n",
00168 nrow);
00169 select = Vmem_malloc(VNULL, ncv, sizeof(int));
00170 Vnm_print(1, "CURRENTLY USING %4.3f MB MEMORY.\n",
00171 Vmem_bytesTotal()/1024./1024.);
00172
00173
00174 Vnm_print(1, "Calculating %d eigenvalues with ARPACK...\n", nev);
00175 F77GETEIGS(&nrow, &ncol, &nnzero, values, colptr, rowind, &nev, &ncv, &key,
00176 v, workl, workd , d, resid, ax, select);
00177
00178
00179
00180 return 0;
00181
00182 }