7e4e55e57c15d6c172c048e63b2bd40c26ddc4cc
[alexxy/gromacs.git] / src / gromacs / linearalgebra / gmx_arpack.h
1 /*
2  *
3  * This file is part of Gromacs        Copyright (c) 1991-2004
4  * David van der Spoel, Erik Lindahl, University of Groningen.
5  *
6  * This file contains a subset of ARPACK functions to perform
7  * diagonalization and SVD for sparse matrices in Gromacs.
8  *
9  * The code has been translated to C to avoid being dependent on
10  * a Fotran compiler, and it has been made threadsafe by using
11  * additional workspace arrays to store data during reverse communication.
12  *
13  * You might prefer the original ARPACK library for general use, but
14  * in case you want to this version can be redistributed freely, just
15  * as the original library. However, please make clear that it is the
16  * hacked version from Gromacs so any bugs are blamed on us and not
17  * the original authors. You should also be aware that the double
18  * precision work array workd needs to be of size (3*N+4) here
19  * (4 more than the general library), and there is an extra argument
20  * iwork, which should be an integer work array of length 80.
21  *
22  * ARPACK was written by
23  *
24  *     Danny Sorensen               Phuong Vu
25  *    Riconst chard Lehoucq              CRPC / Rice University
26  *    Dept. of Computational &     Houston, Texas
27  *    Applied Mathematics
28  *    Rice University
29  *    Houston, Texas
30  */
31 /*! \internal \file
32  * \brief
33  * Selected routines from ARPACK
34  *
35  * This file contains a subset of ARPACK functions to perform
36  * diagonalization and SVD for sparse matrices in Gromacs.
37  *
38  * Consult the main ARPACK site for detailed documentation:
39  * http://www.caam.rice.edu/software/ARPACK/
40  *
41  * Below, we just list the options and any specific differences
42  * from ARPACK. The code is essentially the same, but the routines
43  * have been made thread-safe by using extra workspace arrays.
44  */
45 #ifndef GMX_ARPACK_H
46 #define GMX_ARPACK_H
47
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /*! \brief Implicitly Restarted Arnoldi Iteration, double precision.
56  *
57  *  Reverse communication interface for the Implicitly Restarted Arnoldi
58  *  Iteration.  For symmetric problems this reduces to a variant of the
59  *  Lanczos method. See the ARPACK site for details.
60  *
61  *  \param ido     Reverse communication flag. Set to 0 first time.
62  *                 Upon return with ido=-1 or ido=1 you should calculate
63  *                 Y=A*X and recall the routine. Return with ido=2 means
64  *                 Y=B*X should be calculated. ipntr[0] is the pointer in
65  *                 workd for X, ipntr[1] is the index for Y.
66  *                 Return with ido=99 means it finished.
67  *  \param bmat    'I' for standard eigenproblem, 'G' for generalized.
68  *  \param n       Order of eigenproblem.
69  *  \param which   Which eigenvalues to calculate. 'LA' for largest
70  *                 algebraic, 'SA' for smallest algebraic, 'LM' for largest
71  *                 magnitude, 'SM' for smallest magnitude, and finally
72  *                 'BE' (both ends) to calculate half from each end of
73  *                 the spectrum.
74  *  \param nev     Number of eigenvalues to calculate. 0<nev<n.
75  *  \param tol     Tolerance. Machine precision of it is 0.
76  *  \param resid   Optional starting residual vector at input if info=1,
77  *                 otherwise a random one is used. Final residual vector on
78  *                 return.
79  *  \param ncv     Number of columns in matrix v.
80  *  \param v       N*NCV matrix. V contain the Lanczos basis vectors.
81  *  \param ldv     Leading dimension of v.
82  *  \param iparam  Integer array, size 11. Same contents as arpack.
83  *  \param ipntr   Integer array, size 11. Points to starting locations
84  *                 in the workd/workl arrays. Same contents as arpack.
85  *  \param workd   Double precision work array, length 3*n+4.
86  *                 Provide the same array for all calls, and don't touch it.
87  *                 IMPORTANT: This is 4 units larger than standard ARPACK!
88  *  \param iwork   Integer work array, size 80.
89  *                 Provide the same array for all calls, and don't touch it.
90  *                 IMPORTANT: New argument compared to standard ARPACK!
91  *  \param workl   Double precision work array, length lwork.
92  *  \param lworkl  Length of the work array workl. Must be at least ncv*(ncv+8)
93  *  \param info    Set info to 0 to use random initial residual vector,
94  *                 or to 1 if you provide a one. On output, info=0 means
95  *                 normal exit, 1 that max number of iterations was reached,
96  *                 and 3 that no shifts could be applied. Negative numbers
97  *                 correspond to errors in the arguments provided.
98  */
99 void
100     F77_FUNC(dsaupd, DSAUPD) (int *     ido,
101                               const char *    bmat,
102                               int *     n,
103                               const char *      which,
104                               int *     nev,
105                               double *  tol,
106                               double *  resid,
107                               int *     ncv,
108                               double *  v,
109                               int *     ldv,
110                               int *     iparam,
111                               int *     ipntr,
112                               double *  workd,
113                               int *     iwork,
114                               double *  workl,
115                               int *     lworkl,
116                               int *     info);
117
118
119
120 /*! \brief Get eigenvalues/vectors after Arnoldi iteration, double prec.
121  *
122  *  See the ARPACK site for details. You must have finished the interative
123  *  part with dsaupd() before calling this function.
124  *
125  *  \param rvec    1 if you want eigenvectors, 0 if not.
126  *  \param howmny  'A' if you want all nvec vectors, 'S' if you
127  *                 provide a subset selection in select[].
128  *  \param select  Integer array, dimension nev. Indices of the
129  *                 eigenvectors to calculate. Fortran code means we
130  *                 start counting on 1. This array must be given even in
131  *                 howmny is 'A'. (Arpack documentation is wrong on this).
132  *  \param d       Double precision array, length nev. Eigenvalues.
133  *  \param z       Double precision array, n*nev. Eigenvectors.
134  *  \param ldz     Leading dimension of z. Normally n.
135  *  \param sigma   Shift if iparam[6] is 3,4, or 5. Ignored otherwise.
136  *  \param bmat    Provide the same argument as you did to dsaupd()
137  *  \param n       Provide the same argument as you did to dsaupd()
138  *  \param which   Provide the same argument as you did to dsaupd()
139  *  \param nev     Provide the same argument as you did to dsaupd()
140  *  \param tol     Provide the same argument as you did to dsaupd()
141  *  \param resid   Provide the same argument as you did to dsaupd()
142  *                 The array must not be touched between the two function calls!
143  *  \param ncv     Provide the same argument as you did to dsaupd()
144  *  \param v       Provide the same argument as you did to dsaupd()
145  *                 The array must not be touched between the two function calls!
146  *  \param ldv     Provide the same argument as you did to dsaupd()
147  *  \param iparam  Provide the same argument as you did to dsaupd()
148  *                 The array must not be touched between the two function calls!
149  *  \param ipntr   Provide the same argument as you did to dsaupd()
150  *                 The array must not be touched between the two function calls!
151  *  \param workd   Provide the same argument as you did to dsaupd()
152  *                 The array must not be touched between the two function calls!
153  *  \param workl   Double precision work array, length lwork.
154  *                 The array must not be touched between the two function calls!
155  *  \param lworkl  Provide the same argument as you did to dsaupd()
156  *  \param info    Provide the same argument as you did to dsaupd()
157  */
158 void
159     F77_FUNC(dseupd, DSEUPD) (int *     rvec,
160                               const char *    howmny,
161                               int *     select,
162                               double *  d,
163                               double *  z,
164                               int *     ldz,
165                               double *  sigma,
166                               const char *    bmat,
167                               int *     n,
168                               const char *    which,
169                               int *     nev,
170                               double *  tol,
171                               double *  resid,
172                               int *     ncv,
173                               double *  v,
174                               int *     ldv,
175                               int *     iparam,
176                               int *     ipntr,
177                               double *  workd,
178                               double *  workl,
179                               int *     lworkl,
180                               int *     info);
181
182
183
184
185
186 /*! \brief Implicitly Restarted Arnoldi Iteration, single precision.
187  *
188  *  Reverse communication interface for the Implicitly Restarted Arnoldi
189  *  Iteration.  For symmetric problems this reduces to a variant of the
190  *  Lanczos method. See the ARPACK site for details.
191  *
192  *  \param ido     Reverse communication flag. Set to 0 first time.
193  *                 Upon return with ido=-1 or ido=1 you should calculate
194  *                 Y=A*X and recall the routine. Return with ido=2 means
195  *                 Y=B*X should be calculated. ipntr[0] is the pointer in
196  *                 workd for X, ipntr[1] is the index for Y.
197  *                 Return with ido=99 means it finished.
198  *  \param bmat    'I' for standard eigenproblem, 'G' for generalized.
199  *  \param n       Order of eigenproblem.
200  *  \param which   Which eigenvalues to calculate. 'LA' for largest
201  *                 algebraic, 'SA' for smallest algebraic, 'LM' for largest
202  *                 magnitude, 'SM' for smallest magnitude, and finally
203  *                 'BE' (both ends) to calculate half from each end of
204  *                 the spectrum.
205  *  \param nev     Number of eigenvalues to calculate. 0<nev<n.
206  *  \param tol     Tolerance. Machine precision of it is 0.
207  *  \param resid   Optional starting residual vector at input if info=1,
208  *                 otherwise a random one is used. Final residual vector on
209  *                 return.
210  *  \param ncv     Number of columns in matrix v.
211  *  \param v       N*NCV matrix. V contain the Lanczos basis vectors.
212  *  \param ldv     Leading dimension of v.
213  *  \param iparam  Integer array, size 11. Same contents as arpack.
214  *  \param ipntr   Integer array, size 11. Points to starting locations
215  *                 in the workd/workl arrays. Same contents as arpack.
216  *  \param workd   Single precision work array, length 3*n+4.
217  *                 Provide the same array for all calls, and don't touch it.
218  *                 IMPORTANT: This is 4 units larger than standard ARPACK!
219  *  \param iwork   Integer work array, size 80.
220  *                 Provide the same array for all calls, and don't touch it.
221  *                 IMPORTANT: New argument compared to standard ARPACK!
222  *  \param workl   Single precision work array, length lwork.
223  *  \param lworkl  Length of the work array workl. Must be at least ncv*(ncv+8)
224  *  \param info    Set info to 0 to use random initial residual vector,
225  *                 or to 1 if you provide a one. On output, info=0 means
226  *                 normal exit, 1 that max number of iterations was reached,
227  *                 and 3 that no shifts could be applied. Negative numbers
228  *                 correspond to errors in the arguments provided.
229  */
230 void
231     F77_FUNC(ssaupd, SSAUPD) (int *     ido,
232                               const char *    bmat,
233                               int *     n,
234                               const char *    which,
235                               int *     nev,
236                               float *   tol,
237                               float *   resid,
238                               int *     ncv,
239                               float *   v,
240                               int *     ldv,
241                               int *     iparam,
242                               int *     ipntr,
243                               float *   workd,
244                               int *     iwork,
245                               float *   workl,
246                               int *     lworkl,
247                               int *     info);
248
249
250
251
252
253 /*! \brief Get eigenvalues/vectors after Arnoldi iteration, single prec.
254  *
255  *  See the ARPACK site for details. You must have finished the interative
256  *  part with ssaupd() before calling this function.
257  *
258  *  \param rvec    1 if you want eigenvectors, 0 if not.
259  *  \param howmny  'A' if you want all nvec vectors, 'S' if you
260  *                 provide a subset selection in select[].
261  *  \param select  Integer array, dimension nev. Indices of the
262  *                 eigenvectors to calculate. Fortran code means we
263  *                 start counting on 1. This array must be given even in
264  *                 howmny is 'A'. (Arpack documentation is wrong on this).
265  *  \param d       Single precision array, length nev. Eigenvalues.
266  *  \param z       Single precision array, n*nev. Eigenvectors.
267  *  \param ldz     Leading dimension of z. Normally n.
268  *  \param sigma   Shift if iparam[6] is 3,4, or 5. Ignored otherwise.
269  *  \param bmat    Provide the same argument as you did to ssaupd()
270  *  \param n       Provide the same argument as you did to ssaupd()
271  *  \param which   Provide the same argument as you did to ssaupd()
272  *  \param nev     Provide the same argument as you did to ssaupd()
273  *  \param tol     Provide the same argument as you did to ssaupd()
274  *  \param resid   Provide the same argument as you did to ssaupd()
275  *                 The array must not be touched between the two function calls!
276  *  \param ncv     Provide the same argument as you did to ssaupd()
277  *  \param v       Provide the same argument as you did to ssaupd()
278  *                 The array must not be touched between the two function calls!
279  *  \param ldv     Provide the same argument as you did to ssaupd()
280  *  \param iparam  Provide the same argument as you did to ssaupd()
281  *                 The array must not be touched between the two function calls!
282  *  \param ipntr   Provide the same argument as you did to ssaupd()
283  *                 The array must not be touched between the two function calls!
284  *  \param workd   Provide the same argument as you did to ssaupd()
285  *                 The array must not be touched between the two function calls!
286  *  \param workl   Single precision work array, length lwork.
287  *                 The array must not be touched between the two function calls!
288  *  \param lworkl  Provide the same argument as you did to ssaupd()
289  *  \param info    Provide the same argument as you did to ssaupd()
290  */
291 void
292     F77_FUNC(sseupd, SSEUPD) (int *     rvec,
293                               const char *    howmny,
294                               int *     select,
295                               float *   d,
296                               float *   z,
297                               int *     ldz,
298                               float *   sigma,
299                               const char *    bmat,
300                               int *     n,
301                               const char *    which,
302                               int *     nev,
303                               float *   tol,
304                               float *   resid,
305                               int *     ncv,
306                               float *   v,
307                               int *     ldv,
308                               int *     iparam,
309                               int *     ipntr,
310                               float *   workd,
311                               float *   workl,
312                               int *     lworkl,
313                               int *     info);
314
315 #ifdef __cplusplus
316 }
317 #endif
318
319 #endif