[petsc-users] [slepc] nan output for eigenvectors

Jose E. Roman jroman at dsic.upv.es
Fri Sep 9 02:21:47 CDT 2022

First, I would suggest that you add preallocation for SeqAIJ matrices, in this way you can run the program with 1 process:
  MatSeqAIJSetPreallocation(A, 0, d_nnz);
  MatSeqAIJSetPreallocation(B, 0, d_nnz);

With 1 process, the output files are correct. But with more than one process the eigenvector file is wrong because you are writing only the local part of the vector at process 0, and the rest of values are uninitialized - this is probably causing the NaN's.

To write a parallel vector to a file, you have to first gather the local parts in a sequential vector, see for instance VecScatterCreateToZero(). An easier way is to use PETSc/SLEPc functionality for writing the EPS solution (see section 2.5.4 of the SLEPc manual). For instance, the option
  -eps_view_vectors :evecs.m:ascii_matlab
will write a script evecs.m that you can run in Matlab to load the vectors. You can also write it in binary format
  -eps_view_vectors binary:evecs.bin
and then load the file with PetscBinaryRead.m (from $PETSC_DIR/share/petsc/matlab).


> El 9 sept 2022, a las 8:09, Patrick Alken <patrick.alken at geomag.info> escribió:
> I have attached a minimal example, although it does have a dependency on the GSL library (sorry for this). The script mwe.sh shows how I am running the program with the various command line arguments. The program will write the computed eigenvectors to an output file called 'evec' in GNU octave / matlab format.
> I tried running it on 3 different systems with 3 different GCC versions. I am using the latest petsc downloaded from git, and SLEPc 3.17.2. Here are the results:
> GCC 7.5.0: produces nan values in the eigenvector output file, as well as extremely large and small values. In addition, the petsc/slepc 'make check' tests fail on this system.
> GCC 10.2.0: produces nan values in the eigenvector output file, as well as extremely large and small values. On this system, the petsc/slepc 'make check' tests pass.
> GCC 11.2.0: does not produce nan values, and the eigenvector values are all between about -0.01 and +0.01. On this system, the petsc/slepc 'make check' tests pass.
> At first I thought it was a compiler bug in the old GCC 7.5 version, but 10.2 also seems to have the same problem. I need to do more testing with 11.2.
> Any advice is appreciated!
> Patrick
> On 9/7/22 01:20, Jose E. Roman wrote:
>>> El 7 sept 2022, a las 6:18, Patrick Alken <patrick.alken at geomag.info> escribió:
>>> I sometimes get Nan output values in computed eigenvectors for the generalized symmetric eigenvalue problem produced by slepc. Is this a known issue, and is it related to the conditioning of the matrix pair (A,B)? Is there some way to compute a "condition number" of the matrix pair ahead of time to see if i have a good chance of getting stable eigenvectors out?
>> You should never get NaN. Can you send a reproducible example?
>>> In a possibly related issue, i am finding that petsc/slepc compiled with debugging vs optimization can produce very different eigenvectors for the same problem, while the eigenvalues are the same. The eigenvectors seem more accurate when I use the debugging version of the libraries. Could this be also a conditioning problem with the matrix pair?
>> What do you mean more accurate? The residual norm computed with EPSComputeError() should be below the tolerance in both debugging and optimized versions.
>> Jose
> <Makefile.txt><mwe.c><mwe.sh><oct.c>

More information about the petsc-users mailing list