2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "types/simple.h"
45 #include "gmx_fatal.h"
47 #include "sparsematrix.h"
48 #include "eigensolver.h"
50 #include "gmx_lapack.h"
51 #include "gmx_arpack.h"
76 /* Make jobz point to the character "V" if eigenvectors
77 * should be calculated, otherwise "N" (only eigenvalues).
79 jobz = (eigenvectors != NULL) ? "V" : "N";
81 /* allocate lapack stuff */
85 /* First time we ask the routine how much workspace it needs */
90 /* Convert indices to fortran standard */
94 /* Call LAPACK routine using fortran interface. Note that we use upper storage,
95 * but this corresponds to lower storage ("L") in Fortran.
98 F77_FUNC(dsyevr,DSYEVR)(jobz,"I","L",&n,a,&n,&vl,&vu,&index_lower,&index_upper,
99 &abstol,&m,eigenvalues,eigenvectors,&n,
100 isuppz,&w0,&lwork,&iw0,&liwork,&info);
102 F77_FUNC(ssyevr,SSYEVR)(jobz,"I","L",&n,a,&n,&vl,&vu,&index_lower,&index_upper,
103 &abstol,&m,eigenvalues,eigenvectors,&n,
104 isuppz,&w0,&lwork,&iw0,&liwork,&info);
110 gmx_fatal(FARGS,"Internal errror in LAPACK diagonalization.");
122 F77_FUNC(dsyevr,DSYEVR)(jobz,"I","L",&n,a,&n,&vl,&vu,&index_lower,&index_upper,
123 &abstol,&m,eigenvalues,eigenvectors,&n,
124 isuppz,work,&lwork,iwork,&liwork,&info);
126 F77_FUNC(ssyevr,SSYEVR)(jobz,"I","L",&n,a,&n,&vl,&vu,&index_lower,&index_upper,
127 &abstol,&m,eigenvalues,eigenvectors,&n,
128 isuppz,work,&lwork,iwork,&liwork,&info);
137 gmx_fatal(FARGS,"Internal errror in LAPACK diagonalization.");
145 sparse_parallel_eigensolver(gmx_sparsematrix_t * A,
159 int ido,info,lworkl,i,ncv,dovec;
165 MPI_Comm_size( MPI_COMM_WORLD, &nnodes );
166 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
168 if(eigenvectors != NULL)
180 iparam[i]=ipntr[i]=0;
182 iparam[0] = 1; /* Don't use explicit shifts */
183 iparam[2] = maxiter; /* Max number of iterations */
184 iparam[6] = 1; /* Standard symmetric eigenproblem */
186 lworkl = ncv*(8+ncv);
193 /* Use machine tolerance - roughly 1e-16 in double precision */
197 fprintf(stderr,"Calculation Ritz values and Lanczos vectors, max %d iterations...\n",maxiter);
202 F77_FUNC(pdsaupd,PDSAUPD)(&ido, "I", &n, "SA", &neig, &abstol,
203 resid, &ncv, v, &n, iparam, ipntr,
204 workd, iwork, workl, &lworkl, &info);
206 F77_FUNC(pssaupd,PSSAUPD)(&ido, "I", &n, "SA", &neig, &abstol,
207 resid, &ncv, v, &n, iparam, ipntr,
208 workd, iwork, workl, &lworkl, &info);
210 if(ido==-1 || ido==1)
211 gmx_sparsematrix_vector_multiply(A,workd+ipntr[0]-1, workd+ipntr[1]-1);
213 fprintf(stderr,"\rIteration %4d: %3d out of %3d Ritz values converged.",iter++,iparam[4],neig);
214 } while(info==0 && (ido==-1 || ido==1));
216 fprintf(stderr,"\n");
220 "Maximum number of iterations (%d) reached in Arnoldi\n"
221 "diagonalization, but only %d of %d eigenvectors converged.\n",
222 maxiter,iparam[4],neig);
226 gmx_fatal(FARGS,"Unspecified error from Arnoldi diagonalization:%d\n",info);
230 /* Extract eigenvalues and vectors from data */
231 fprintf(stderr,"Calculating eigenvalues and eigenvectors...\n");
234 F77_FUNC(pdseupd,PDSEUPD)(&dovec, "A", select, eigenvalues, eigenvectors,
235 &n, NULL, "I", &n, "SA", &neig, &abstol,
236 resid, &ncv, v, &n, iparam, ipntr,
237 workd, workl, &lworkl, &info);
239 F77_FUNC(psseupd,PSSEUPD)(&dovec, "A", select, eigenvalues, eigenvectors,
240 &n, NULL, "I", &n, "SA", &neig, &abstol,
241 resid, &ncv, v, &n, iparam, ipntr,
242 workd, workl, &lworkl, &info);
255 sparse_eigensolver(gmx_sparsematrix_t * A,
269 int ido,info,lworkl,i,ncv,dovec;
275 MPI_Comm_size( MPI_COMM_WORLD, &n );
278 sparse_parallel_eigensolver(A,neig,eigenvalues,eigenvectors,maxiter);
283 if(eigenvectors != NULL)
295 iparam[i]=ipntr[i]=0;
297 iparam[0] = 1; /* Don't use explicit shifts */
298 iparam[2] = maxiter; /* Max number of iterations */
299 iparam[6] = 1; /* Standard symmetric eigenproblem */
301 lworkl = ncv*(8+ncv);
308 /* Use machine tolerance - roughly 1e-16 in double precision */
312 fprintf(stderr,"Calculation Ritz values and Lanczos vectors, max %d iterations...\n",maxiter);
317 F77_FUNC(dsaupd,DSAUPD)(&ido, "I", &n, "SA", &neig, &abstol,
318 resid, &ncv, v, &n, iparam, ipntr,
319 workd, iwork, workl, &lworkl, &info);
321 F77_FUNC(ssaupd,SSAUPD)(&ido, "I", &n, "SA", &neig, &abstol,
322 resid, &ncv, v, &n, iparam, ipntr,
323 workd, iwork, workl, &lworkl, &info);
325 if(ido==-1 || ido==1)
326 gmx_sparsematrix_vector_multiply(A,workd+ipntr[0]-1, workd+ipntr[1]-1);
328 fprintf(stderr,"\rIteration %4d: %3d out of %3d Ritz values converged.",iter++,iparam[4],neig);
329 } while(info==0 && (ido==-1 || ido==1));
331 fprintf(stderr,"\n");
335 "Maximum number of iterations (%d) reached in Arnoldi\n"
336 "diagonalization, but only %d of %d eigenvectors converged.\n",
337 maxiter,iparam[4],neig);
341 gmx_fatal(FARGS,"Unspecified error from Arnoldi diagonalization:%d\n",info);
345 /* Extract eigenvalues and vectors from data */
346 fprintf(stderr,"Calculating eigenvalues and eigenvectors...\n");
349 F77_FUNC(dseupd,DSEUPD)(&dovec, "A", select, eigenvalues, eigenvectors,
350 &n, NULL, "I", &n, "SA", &neig, &abstol,
351 resid, &ncv, v, &n, iparam, ipntr,
352 workd, workl, &lworkl, &info);
354 F77_FUNC(sseupd,SSEUPD)(&dovec, "A", select, eigenvalues, eigenvectors,
355 &n, NULL, "I", &n, "SA", &neig, &abstol,
356 resid, &ncv, v, &n, iparam, ipntr,
357 workd, workl, &lworkl, &info);