主题:分享arpack使用方法
ARPACK can be used to solve standard or generalized eigenvalue problems of large scale matrix. It is based upon an algorithmic variant of the Arnoldi process called the Implicitly Restarted Arnoldi Method. When the matrix is symmetric it reduces to a variant of the Lanczos process called Implicitly Restarted Lanczos Method. For a large sparse matrix, the solver used during iterations is very important to the computational efficiency of ARPACK. Intel MKL sparse solver is quite suitable to this problem. MKL has parallel direct and iterative solvers which is very efficient to deal with sparse matrix. Hence, ARPACK integrated with MKL Solver can be used for solving eigenvalue problems of large sparse matrix.
Platform: win7
Compiler: Intel Fortran 11.0 with MKL
1. ARPACK
1.1 Download the ARPACK source files
http://www.caam.rice.edu/software/ARPACK
1.2 Compile ARPACK lib
ARPACK has a" makefile" in it. However, it doesn't work for Windows System. So, Microsoft Visual Studio with Intel Fortran is used to create a static library under Windows System.
Step 1, open a new static library project.
Open>New>Project>Intel Fortran>Library>Static Library, name it, select OK.
Step 2, add all of the source files into the project.
Project>Add Existing Item, select all source, and add them in the project.
Step 3, compile and create ARPACK lib.
In debug mode, there may be something wrong with the interface of one subroutine. In this case, you should turn off the compiler diagnostics to the interface block.
Project>Properties>Fortran> Diagnostics>Generate interface block, select no. It will be OK.
Please note: a lib compiled by one complier cannot be used in another compiler. For instance, a lib compiled by Compaq Fortran cannot be used in Intel Fortran compiler.
1.3 Use ARPACK lib
After compiling the lib, it's time to use it in a project. It's very easy. For example, if the lib is named "arpack.lib", put it in the project directory, and use the following codes, !dec$objcomment lib:'arpack.lib'
1.4 ARPACK subroutine DSAUPD
This subroutine can be used to solve a standard or a generalized eigenvalue problem. There are several modes which can be used to solve different problems. For instance, mode 3 is for the problem of K*x=lambda*M*x, in which K is symmetric and M is symmetric positive semi-definite. During the iterations, you need to provide a solver and a matrix and vector product subroutine. Several examples which can illustrate how this subroutine works can be found in the examples directory. For example, dsdrv4.f is an example to illustrate the idea of reverse communication in shift and invert mode for a generalized symmetric eigenvalue problem.
Please see the detail of this subroutine in arpack's guid.pdf.
2. MKL SPARSE SOLVER
In ARPACK iteration, linear equation need to be solved again and again. So the solver is very important to computational efficiency of ARPACK. MKL is an excellent choice, especially the sparse solver in MKL. Please see the MKL help documents, mklman.pdf and userguide.pdf.
2.1 Configuring the Microsoft Visual C/C++* Development System to Link with Intel MKL
1. Select View > Solution Explorer (and make sure this window is active).
2. Select Tools > Options > Projects > VC++ Directories > Show directories for:> Include Files. Add the directory for the Intel MKL include files, that is, <mkl directory>\include".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\include
3. Select Tools > Options > Projects > VC++ Directories > Show directories for:
> Library Files. Add the directory for the Intel MKL library files, for example, "<mkl directory>\ia32\lib".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\lib
4. Select Tools > Options > Projects > VC++ Directories > Show directories for:
> Executable Files. Add the directory for the Intel MKL executable files, for example,
"<mkl directory>\ia32\bin".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\bin
5. Select Project > Properties > Configuration Properties > Linker > Input >
Additional Dependencies. Add the libraries you require (for example, mkl_c.lib).
To learn how to choose the libraries, see Selecting Libraries to Link in chapter 5.
2.2 Configuring Intel® Visual Fortran to Link with Intel MKL
1. Select Project > Properties > Linker > General > Additional Library Directories. Add the architecture-specific lib folder, for example, <mkl directory>\ia32\lib.
Example: c:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\lib
2. Select Project > Properties > Linker > Input > Additional Dependencies. Insert
mkl_c.lib and libguide.lib.
Example: mkl_c.lib libiomp5md.lib mkl_solver.lib
2.3 Sparse Solver Routines
PARDISO and dss
The description and interface of these programs are included in mklman.pdf.
Several examples could be found in examples directory, C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\examples\solver\source
Subroutine dss is more appropriate for ARPACK. It can reorder and factor the matrix before ARPACK iteration. So, it just needs the solving step during iterations. The computational efficiency can be greatly improved.
2.4 Sparse Matrix Storage Formats
For sparse matrix, storage formats is also important because sparse matrix storage formats can not only save memory, but also improve the efficiency. In the subroutines of ARPACK, it doesn't need to transmit the matrix values to ARPACK subroutine. So, ARPACK doesn't limit the storage format. The matrix is just needed in the solver and matrix and vector multiplicative subroutines which are both provided by user. So, it's very convenient to choose the storage format as same as which is the solver need.
MKL uses a storage format called compressed sparse row storage. It stores all non-zero elements of the matrix into a linear array and provides auxiliary arrays to describe the locations of the nonzero elements in the original matrix. For a symmetric matrix, only nonzero elements from the upper triangle are stored.
Platform: win7
Compiler: Intel Fortran 11.0 with MKL
1. ARPACK
1.1 Download the ARPACK source files
http://www.caam.rice.edu/software/ARPACK
1.2 Compile ARPACK lib
ARPACK has a" makefile" in it. However, it doesn't work for Windows System. So, Microsoft Visual Studio with Intel Fortran is used to create a static library under Windows System.
Step 1, open a new static library project.
Open>New>Project>Intel Fortran>Library>Static Library, name it, select OK.
Step 2, add all of the source files into the project.
Project>Add Existing Item, select all source, and add them in the project.
Step 3, compile and create ARPACK lib.
In debug mode, there may be something wrong with the interface of one subroutine. In this case, you should turn off the compiler diagnostics to the interface block.
Project>Properties>Fortran> Diagnostics>Generate interface block, select no. It will be OK.
Please note: a lib compiled by one complier cannot be used in another compiler. For instance, a lib compiled by Compaq Fortran cannot be used in Intel Fortran compiler.
1.3 Use ARPACK lib
After compiling the lib, it's time to use it in a project. It's very easy. For example, if the lib is named "arpack.lib", put it in the project directory, and use the following codes, !dec$objcomment lib:'arpack.lib'
1.4 ARPACK subroutine DSAUPD
This subroutine can be used to solve a standard or a generalized eigenvalue problem. There are several modes which can be used to solve different problems. For instance, mode 3 is for the problem of K*x=lambda*M*x, in which K is symmetric and M is symmetric positive semi-definite. During the iterations, you need to provide a solver and a matrix and vector product subroutine. Several examples which can illustrate how this subroutine works can be found in the examples directory. For example, dsdrv4.f is an example to illustrate the idea of reverse communication in shift and invert mode for a generalized symmetric eigenvalue problem.
Please see the detail of this subroutine in arpack's guid.pdf.
2. MKL SPARSE SOLVER
In ARPACK iteration, linear equation need to be solved again and again. So the solver is very important to computational efficiency of ARPACK. MKL is an excellent choice, especially the sparse solver in MKL. Please see the MKL help documents, mklman.pdf and userguide.pdf.
2.1 Configuring the Microsoft Visual C/C++* Development System to Link with Intel MKL
1. Select View > Solution Explorer (and make sure this window is active).
2. Select Tools > Options > Projects > VC++ Directories > Show directories for:> Include Files. Add the directory for the Intel MKL include files, that is, <mkl directory>\include".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\include
3. Select Tools > Options > Projects > VC++ Directories > Show directories for:
> Library Files. Add the directory for the Intel MKL library files, for example, "<mkl directory>\ia32\lib".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\lib
4. Select Tools > Options > Projects > VC++ Directories > Show directories for:
> Executable Files. Add the directory for the Intel MKL executable files, for example,
"<mkl directory>\ia32\bin".
C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\bin
5. Select Project > Properties > Configuration Properties > Linker > Input >
Additional Dependencies. Add the libraries you require (for example, mkl_c.lib).
To learn how to choose the libraries, see Selecting Libraries to Link in chapter 5.
2.2 Configuring Intel® Visual Fortran to Link with Intel MKL
1. Select Project > Properties > Linker > General > Additional Library Directories. Add the architecture-specific lib folder, for example, <mkl directory>\ia32\lib.
Example: c:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\ia32\lib
2. Select Project > Properties > Linker > Input > Additional Dependencies. Insert
mkl_c.lib and libguide.lib.
Example: mkl_c.lib libiomp5md.lib mkl_solver.lib
2.3 Sparse Solver Routines
PARDISO and dss
The description and interface of these programs are included in mklman.pdf.
Several examples could be found in examples directory, C:\Program Files (x86)\Intel\Compiler\11.0\061\fortran\mkl\examples\solver\source
Subroutine dss is more appropriate for ARPACK. It can reorder and factor the matrix before ARPACK iteration. So, it just needs the solving step during iterations. The computational efficiency can be greatly improved.
2.4 Sparse Matrix Storage Formats
For sparse matrix, storage formats is also important because sparse matrix storage formats can not only save memory, but also improve the efficiency. In the subroutines of ARPACK, it doesn't need to transmit the matrix values to ARPACK subroutine. So, ARPACK doesn't limit the storage format. The matrix is just needed in the solver and matrix and vector multiplicative subroutines which are both provided by user. So, it's very convenient to choose the storage format as same as which is the solver need.
MKL uses a storage format called compressed sparse row storage. It stores all non-zero elements of the matrix into a linear array and provides auxiliary arrays to describe the locations of the nonzero elements in the original matrix. For a symmetric matrix, only nonzero elements from the upper triangle are stored.