EVSL  1.1.0
EigenValues Slicing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
evsl_f90.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdint.h>
3 #include "def.h"
4 #include "struct.h"
5 #include "internal_proto.h"
6 
16 
19  EVSLStart();
20 }
21 
24  EVSLFinish();
25 }
26 
34 void EVSLFORT(evsl_coo2csr)(int *n, int *nnz, int *ir, int *jc,
35  double *vv, uintptr_t *csrf90) {
36  cooMat coo;
37  coo.nrows = *n;
38  coo.ncols = *n;
39  coo.nnz = *nnz;
40  coo.ir = ir;
41  coo.jc = jc;
42  coo.vv = vv;
43  csrMat *csr;
44  Malloc(csr, 1, csrMat);
45  cooMat_to_csrMat(1, &coo, csr);
46  *csrf90 = (uintptr_t) csr;
47 }
48 
56 void EVSLFORT(evsl_arr2csr)(int *n, int *ia, int *ja,
57  double *a, uintptr_t *csrf90) {
58  csrMat *csr;
59  Malloc(csr, 1, csrMat);
60  /* does not own the data */
61  csr->owndata = 0;
62  csr->nrows = *n;
63  csr->ncols = *n;
64  csr->ia = ia;
65  csr->ja = ja;
66  csr->a = a;
67  *csrf90 = (uintptr_t) csr;
68 }
69 
73 void EVSLFORT(evsl_free_csr)(uintptr_t *csrf90) {
74  csrMat *csr = (csrMat *) (*csrf90);
75  free_csr(csr);
76  free(csr);
77 }
78 
82 void EVSLFORT(evsl_seta_csr)(uintptr_t *Af90) {
83  csrMat *A = (csrMat *) (*Af90);
84  SetAMatrix(A);
85 }
86 
90 void EVSLFORT(evsl_setb_csr)(uintptr_t *Bf90) {
91  csrMat *B = (csrMat *) (*Bf90);
92  SetBMatrix(B);
93 }
94 
100 void EVSLFORT(evsl_setamv)(int *n, void *func, void *data) {
101  SetAMatvec(*n, (MVFunc) func, data);
102 }
103 
109 void EVSLFORT(evsl_setbmv)(int *n, void *func, void *data) {
110  SetBMatvec(*n, (MVFunc) func, data);
111 }
112 
117 void EVSLFORT(evsl_setbsol)(void *func, void *data) {
118  SetBSol((SolFuncR) func, data);
119 }
120 
125 void EVSLFORT(evsl_setltsol)(void *func, void *data) {
126  SetLTSol((SolFuncR) func, data);
127 }
128 
131  SetGenEig();
132 }
133 
139 void EVSLFORT(evsl_lanbounds)(int *nsteps, double *lmin, double *lmax) {
140  int n = evsldata.n;
141  double *vinit;
142  Malloc(vinit, n, double);
143  rand_double(n, vinit);
144  LanTrbounds(50, *nsteps, 1e-10, vinit, 1, lmin, lmax, NULL);
145  //LanBounds(*nsteps, vinit, lmin, lmax);
146  free(vinit);
147 }
148 
161 void EVSLFORT(evsl_kpm_spslicer)(int *Mdeg, int *nvec, double *xintv,
162  int *nslices, double *sli, int *evint) {
163  int npts;
164  double *mu, ecount;
165  Malloc(mu, *Mdeg+1, double);
166  kpmdos(*Mdeg, 1, *nvec, xintv, mu, &ecount);
167  fprintf(stdout, " estimated eig count in interval: %.15e \n",ecount);
168 
169  npts = 10 *ecount;
170  int ierr = spslicer(sli, mu, *Mdeg, xintv, *nslices, npts);
171  if (ierr) {
172  printf("spslicer error %d\n", ierr);
173  exit(1);
174  }
175  *evint = (int) (1 + ecount / (*nslices));
176  free(mu);
177 }
178 
190 void EVSLFORT(evsl_find_pol)(double *xintv, double *thresh_int,
191  double *thresh_ext, uintptr_t *polf90) {
192  polparams *pol;
193  Malloc(pol, 1, polparams);
194  set_pol_def(pol);
195  pol->damping = 2;
196  pol->thresh_int = *thresh_int;
197  pol->thresh_ext = *thresh_ext;
198  pol->max_deg = 300;
199  find_pol(xintv, pol);
200 
201  fprintf(stdout, " polynomial deg %d, bar %e gam %e\n",
202  pol->deg,pol->bar, pol->gam);
203 
204  *polf90 = (uintptr_t) pol;
205 }
206 
211 void EVSLFORT(evsl_free_pol)(uintptr_t *polf90) {
212  /* cast pointer */
213  polparams *pol = (polparams *) (*polf90);
214  free_pol(pol);
215  free(pol);
216 }
217 
227 void EVSLFORT(evsl_find_rat)(double *intv, uintptr_t *ratf90) {
228  int pow = 2;
229  int num = 1;
230  double beta = 0.01;
231  ratparams *rat;
232  Malloc(rat, 1, ratparams);
233  set_ratf_def(rat);
234  rat->pw = pow;
235  rat->num = num;
236  rat->beta = beta;
237  find_ratf(intv, rat);
238 
239  *ratf90 = (uintptr_t) rat;
240 }
241 
243 void EVSLFORT(evsl_free_rat)(uintptr_t *ratf90) {
244  ratparams *rat = (ratparams *) (*ratf90);
245  free_rat(rat);
246  free(rat);
247 }
248 
252 void EVSLFORT(evsl_cheblantr)(int *mlan, int *nev, double *xintv, int *max_its,
253  double *tol, uintptr_t *polf90) {
254  int n, nev2, ierr;
255  double *lam, *Y, *res;
256  FILE *fstats = stdout;
257  double *vinit;
258 
259  n = evsldata.n;
260  Malloc(vinit, n, double);
261  rand_double(n, vinit);
262 
263  /* cast pointer */
264  polparams *pol = (polparams *) (*polf90);
265 
266  ierr = ChebLanTr(*mlan, *nev, xintv, *max_its, *tol, vinit,
267  pol, &nev2, &lam, &Y, &res, fstats);
268 
269  if (ierr) {
270  printf("ChebLanTr error %d\n", ierr);
271  }
272 
273  free(vinit);
274  if (res) {
275  free(res);
276  }
277  /* save pointers to the global variables */
278  evsl_nev_computed = nev2;
279  evsl_n = n;
280  evsl_eigval_computed = lam;
282 }
283 
287 void EVSLFORT(evsl_cheblannr)(double *xintv, int *max_its, double *tol,
288  uintptr_t *polf90) {
289  int n, nev2, ierr;
290  double *lam, *Y, *res;
291  FILE *fstats = stdout;
292  double *vinit;
293 
294  n = evsldata.n;
295  Malloc(vinit, n, double);
296  rand_double(n, vinit);
297 
298  /* cast pointer */
299  polparams *pol = (polparams *) (*polf90);
300 
301  ierr = ChebLanNr(xintv, *max_its, *tol, vinit,
302  pol, &nev2, &lam, &Y, &res, fstats);
303 
304  if (ierr) {
305  printf("ChebLanNr error %d\n", ierr);
306  }
307 
308  free(vinit);
309  if (res) {
310  free(res);
311  }
312  /* save pointers to the global variables */
313  evsl_nev_computed = nev2;
314  evsl_n = n;
315  evsl_eigval_computed = lam;
317 }
318 
322 void EVSLFORT(evsl_ratlannr)(double *xintv, int *max_its, double *tol,
323  uintptr_t *ratf90) {
324  int n, nev2, ierr;
325  double *lam, *Y, *res;
326  FILE *fstats = stdout;
327  double *vinit;
328 
329  n = evsldata.n;
330  Malloc(vinit, n, double);
331  rand_double(n, vinit);
332 
333  /* cast pointer */
334  ratparams *rat = (ratparams *) (*ratf90);
335 
336  ierr = RatLanNr(xintv, *max_its, *tol, vinit,
337  rat, &nev2, &lam, &Y, &res, fstats);
338 
339  if (ierr) {
340  printf("RatLanNr error %d\n", ierr);
341  }
342 
343  free(vinit);
344  if (res) {
345  free(res);
346  }
347  /* save pointers to the global variables */
348  evsl_nev_computed = nev2;
349  evsl_n = n;
350  evsl_eigval_computed = lam;
352 }
353 
357 void EVSLFORT(evsl_ratlantr)(int * lanm, int * nev, double *xintv,
358  int *max_its, double *tol, uintptr_t *ratf90) {
359  int n, nev2, ierr;
360  double *lam, *Y, *res;
361  FILE *fstats = stdout;
362  double *vinit;
363 
364  n = evsldata.n;
365  Malloc(vinit, n, double);
366  rand_double(n, vinit);
367 
368  /* cast pointer */
369  ratparams *rat = (ratparams *) (*ratf90);
370 
371  ierr = RatLanTr(*lanm, *nev, xintv, *max_its, *tol, vinit,
372  rat, &nev2, &lam, &Y, &res, fstats);
373 
374  if (ierr) {
375  printf("RatLanNr error %d\n", ierr);
376  }
377 
378  free(vinit);
379  if (res) {
380  free(res);
381  }
382  /* save pointers to the global variables */
383  evsl_nev_computed = nev2;
384  evsl_n = n;
385  evsl_eigval_computed = lam;
387 }
388 
391 void EVSLFORT(evsl_get_nev)(int *nev) {
392  *nev = evsl_nev_computed;
393 }
394 
398 void EVSLFORT(evsl_copy_result)(double *val, double *vec) {
399  memcpy(val, evsl_eigval_computed, evsl_nev_computed*sizeof(double));
400  memcpy(vec, evsl_eigvec_computed, evsl_nev_computed*evsl_n*sizeof(double));
401  /* reset global variables */
402  evsl_nev_computed = 0;
403  evsl_n = 0;
404  free(evsl_eigval_computed);
405  free(evsl_eigvec_computed);
406  evsl_eigval_computed = NULL;
407  evsl_eigvec_computed = NULL;
408 }
409 
410 
411 
412 
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...
Definition: spslice.c:32
void EVSLFORT() evsl_find_pol(double *xintv, double *thresh_int, double *thresh_ext, uintptr_t *polf90)
Fortran interface for find_pol.
Definition: evsl_f90.c:190
int deg
Definition: struct.h:70
void free_pol(polparams *pol)
Definition: chebpoly.c:488
void EVSLFORT() evsl_cheblannr(double *xintv, int *max_its, double *tol, uintptr_t *polf90)
Fortran interface for ChebLanNr the results will be saved in the internal variables.
Definition: evsl_f90.c:287
void EVSLFORT() evsl_copy_result(double *val, double *vec)
copy the computed eigenvalues and vectors
Definition: evsl_f90.c:398
int num
Definition: struct.h:114
void free_rat(ratparams *rat)
Definition: ratfilter.c:424
void(* MVFunc)(double *x, double *y, void *data)
matvec function prototype
Definition: struct.h:96
defs in EVSL
int SetGenEig()
Set the problem to generalized eigenvalue problem.
Definition: evsl.c:158
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].
Definition: cheblanTr.c:62
int ncols
Definition: struct.h:32
int nnz
Definition: struct.h:17
double * vv
Definition: struct.h:22
int SetAMatrix(csrMat *A)
Set the matrix A.
Definition: evsl.c:68
void EVSLFORT() evsl_setbsol(void *func, void *data)
Fortran interface for SetBSol.
Definition: evsl_f90.c:117
void EVSLFORT() evsl_setb_csr(uintptr_t *Bf90)
Fortran interface to set matrix B from a CSR matrix.
Definition: evsl_f90.c:90
void rand_double(int n, double *v)
Definition: vect.c:11
void EVSLFORT() evsl_setbmv(int *n, void *func, void *data)
Fortran interface for SetBMatvec.
Definition: evsl_f90.c:109
int cooMat_to_csrMat(int cooidx, cooMat *coo, csrMat *csr)
convert coo to csr
Definition: spmat.c:135
#define EVSLFORT(name)
Definition: def.h:66
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].
Definition: lanTrbounds.c:38
double * evsl_eigvec_computed
Definition: evsl_f90.c:15
int * jc
Definition: struct.h:17
int find_pol(double *intv, polparams *pol)
Sets the values in pol.
Definition: chebpoly.c:361
double gam
Definition: struct.h:64
void EVSLFORT() evsl_find_rat(double *intv, uintptr_t *ratf90)
Fortran interface for find_rat.
Definition: evsl_f90.c:227
int SetBMatvec(int n, MVFunc func, void *data)
Set the user-input matvec routine and the associated data for B. Save them in evsldata.
Definition: evsl.c:117
int SetBMatrix(csrMat *B)
Set the B matrix.
Definition: evsl.c:83
int * ir
Definition: struct.h:17
void EVSLFORT() evsl_setamv(int *n, void *func, void *data)
Fortran interface for SetAMatvec.
Definition: evsl_f90.c:100
void EVSLFORT() evsl_free_pol(uintptr_t *polf90)
Fortran interface for free_pol.
Definition: evsl_f90.c:211
void EVSLFORT() evsl_setltsol(void *func, void *data)
Fortran interface for SetLTSol.
Definition: evsl_f90.c:125
int EVSLStart()
Initialize evslData.
Definition: evsl.c:27
void EVSLFORT() evsl_kpm_spslicer(int *Mdeg, int *nvec, double *xintv, int *nslices, double *sli, int *evint)
Fortran interface for kpmdos and spslicer.
Definition: evsl_f90.c:161
int evsl_nev_computed
Definition: evsl_f90.c:14
int n
Definition: struct.h:165
int pw
Definition: struct.h:115
void free_csr(csrMat *csr)
memory deallocation for csr matrix
Definition: spmat.c:91
This file contains function prototypes and constant definitions internally used in EVSL...
void EVSLFORT() evsl_free_rat(uintptr_t *ratf90)
Fortran interface for free_rat.
Definition: evsl_f90.c:243
void EVSLFORT() evsl_coo2csr(int *n, int *nnz, int *ir, int *jc, double *vv, uintptr_t *csrf90)
Fortran interface to convert a COO matrix to CSR the pointer of CSR will be returned.
Definition: evsl_f90.c:34
double thresh_ext
Definition: struct.h:51
void set_pol_def(polparams *pol)
set default values for polparams struct.
Definition: chebpoly.c:18
#define Malloc(base, nmem, type)
Definition: def.h:22
double thresh_int
Definition: struct.h:52
void EVSLFORT() evsl_lanbounds(int *nsteps, double *lmin, double *lmax)
Fortran interface for evsl_lanbounds.
Definition: evsl_f90.c:139
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].
Definition: ratlanNr.c:54
structs used in evsl
int SetLTSol(SolFuncR func, void *data)
Set the solve routine for LT.
Definition: evsl.c:185
void(* SolFuncR)(double *b, double *x, void *data)
function prototype for applying the solve B x = b
Definition: struct.h:91
sparse matrix format: the compressed sparse row (CSR) format, 0-based
Definition: struct.h:31
double * a
Definition: struct.h:37
int ncols
Definition: struct.h:17
int max_deg
Definition: struct.h:48
int EVSLFinish()
Finish EVSL.
Definition: evsl.c:48
void EVSLFORT() evsl_ratlantr(int *lanm, int *nev, double *xintv, int *max_its, double *tol, uintptr_t *ratf90)
Fortran interface for RatLanNr the results will be saved in the internal variables.
Definition: evsl_f90.c:357
int * ia
Definition: struct.h:32
void EVSLFORT() evsl_cheblantr(int *mlan, int *nev, double *xintv, int *max_its, double *tol, uintptr_t *polf90)
Fortran interface for ChebLanTr the results will be saved in the internal variables.
Definition: evsl_f90.c:252
int ChebLanNr(double *intv, int maxit, double tol, double *vinit, polparams *pol, int *nevOut, double **lamo, double **Wo, double **reso, FILE *fstats)
Definition: cheblanNr.c:60
int SetBSol(SolFuncR func, void *data)
Set the solve routine and the associated data for B.
Definition: evsl.c:132
void EVSLFORT() evsl_seta_csr(uintptr_t *Af90)
Fortran interface to set matrix A from a CSR matrix.
Definition: evsl_f90.c:82
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...
Definition: spslice.c:204
int RatLanTr(int lanm, int nev, double *intv, int maxit, double tol, double *vinit, ratparams *rat, int *nev2, double **vals, double **W, double **resW, FILE *fstats)
RatLanTR filtering Lanczos process [Thick restart version].
Definition: ratlanTr.c:61
void EVSLFORT() evsl_free_csr(uintptr_t *csrf90)
Fortran interface to free a CSR matrix.
Definition: evsl_f90.c:73
void EVSLFORT() evsl_get_nev(int *nev)
Get the number of last computed eigenvalues.
Definition: evsl_f90.c:391
void EVSLFORT() evsl_start()
Fortran interface for EVSLStart.
Definition: evsl_f90.c:18
int damping
Definition: struct.h:50
int * ja
Definition: struct.h:32
void EVSLFORT() evsl_ratlannr(double *xintv, int *max_its, double *tol, uintptr_t *ratf90)
Fortran interface for RatLanNr the results will be saved in the internal variables.
Definition: evsl_f90.c:322
int owndata
Definition: struct.h:32
int nrows
Definition: struct.h:17
void EVSLFORT() evsl_set_geneig()
Fortran interface for SetGenEig.
Definition: evsl_f90.c:130
evslData evsldata
global variable of EVSL
Definition: evsl.c:15
void EVSLFORT() evsl_finish()
Fortran interface for EVSLFinish.
Definition: evsl_f90.c:23
parameters for polynomial filter
Definition: struct.h:45
double beta
Definition: struct.h:117
void set_ratf_def(ratparams *rat)
Sets default values for ratparams struct.
Definition: ratfilter.c:345
int evsl_n
Definition: evsl_f90.c:14
int find_ratf(double *intv, ratparams *rat)
Definition: ratfilter.c:375
int nrows
Definition: struct.h:32
void EVSLFORT() evsl_arr2csr(int *n, int *ia, int *ja, double *a, uintptr_t *csrf90)
Fortran interface to return a CSR struct from (ia,ja,a) the pointer of CSR will be returned...
Definition: evsl_f90.c:56
sparse matrix format: the coordinate (COO) format, 0-based
Definition: struct.h:16
double * evsl_eigval_computed
Definition: evsl_f90.c:15
int SetAMatvec(int n, MVFunc func, void *data)
Set the user-input matvec routine and the associated data for A. Save them in evsldata.
Definition: evsl.c:100
double bar
Definition: struct.h:65
parameters for rational filter
Definition: struct.h:112