Wiki

Clone wiki

blopex / HypreIJTesting

Introduction

$Revision: 2.0 $ $Date: 21-Apr-2010 Tested in MATLAB 7.9.0.529 (R2009b) and Octave 3.2.3 and Hypre 2.6.0b.

Download http://www.mathworks.com/matlabcentral/fileexchange/27279-laplacian-in-1d-2d-or-3d and matlab2hypre package from http://www.mathworks.com/matlabcentral/fileexchange/27437-matlab2hypre-and-hypre2matlab

Install hypre.

Test 1: Reading in the matrix.

In Matlab or OCTAVE

% Construct a 3D Laplacian matrix and calculate the 20 smallest eigenvalues
% from an exact formula.
>> [A, lambda] = laplacian([20,30,40], {'DD','DN','P'}, 20);

Elapsed time is 0.139952 seconds.
Matrix is 2816008 bytes

% convert the matrix A to Hypre format.
>> matlab2hypreIJ(A,4,'matrixA','1.0d');
Generating file: matrixA.00000
Generating file: matrixA.00001
Generating file: matrixA.00002
Generating file: matrixA.00003

The input argument equal to 4 specifies the number of processors. The 1.0d input will write the matrix files with only one digit for each entry, which is OK for this specific matrix which only has integer values between -1 and 6.

Now, go into your local directory and copy the files matrixA.* to $HYPREDIR/src/test. You can also save the files directly to that directory by code similar to the following:

>> matlab2hypreIJ(A,4,'/home/hypre/src/test/matrixA','1.0d');

Go to that directory and execute the following to compute the 20 smallest eigenvalues:

$ mpirun -np 4 ./ij -lobpcg -fromfile matrixA -vrand 20

Computes the 20 smallest eigenvalues of matrixA using random initial vectors. These eigenvalues should be close to those computed from laplacian.m.

Test 2. Outputing Eigenvectors from Hypre.

In Matlab or OCTAVE

>> [A, lambda, V] = laplacian([20,30,40], {'DD','DN','P'}, 20);
>> matlab2hypreIJ(A,4,'matrixA','1.0d');

Go into your local directory and copy the files matrixA.* to $HYPREDIR/src/test. Go to that directory and execute:

$ mpirun -np 4 ./ij -lobpcg -fromfile matrixA -vrand 20 -vout 1

The -vout 1 command will output the eigenvectors into files calledvectors.. Then copyvectors.` to the local MATLAB directory, and in Matlab,

>> V2 = hypreParVectors2matlab('vectors');

You could also do this without copying the vectors files if you replace the input 'vectors' with the Hypre IJ directory. For example,

>> V2 = hypreParVectors2matlab('/home/hypre/src/test/vectors');

Test the eigenvectors by computing the product of V' and V2.

Test 3. Inputing Initial Vectors into Hypre from a file

You can also generate initial vectors in Matlab or OCTAVE and read them in the Hypre IJ driver. In the following example, I have used the eigenvectors generated by laplacian.m, so one can verify that convergence happens in just a few steps by using eigenvectors as initial vectors.

In Matlab or OCTAVE

>> [A, lambda, V] = laplacian([20,30,40], {'DD','DN','P'}, 20);
>> matlab2hypreParVectors(V,4,'/home/hypre/src/test/vectors');

Hypre can only input initial vectors with the filename prefix vectors.

In the Hypre directory, type the following:

$ mpirun -np 4 ./ij -lobpcg -fromfile matrixA -vfromfile

The -vfromfile argument will read initial vectors with filename prefix vectors contained in the local directory. If you use the eigenvectors generated by laplacian.m, you will see convergence in just a few steps.

Updated