0

I have recently started using SLEPc for diagonalizing large sparse matrices, taking advantage of MPI. Everything works fine, except at the end when I want to write the eigenvectors to a file. I do this:

PetscViewerASCIIOpen(PETSC_COMM_WORLD, "./data/eigvecs.txt", &viewer);
PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_PYTHON);
EPSVectorsView(eps, viewer);

I run my code with mpiexec -n 3 ./app. The generated file eigvecs.txt looks like this:

Vec Object: Xr0_EPS_0x84000004_0 3 MPI processes
 type: mpi
Process [0]
-0.909229
0.415619
Process [1]
-0.00206267
0.00410161
Process [2]
0.0145993
0.01813
Vec Object: Xi0_EPS_0x84000004_0 3 MPI processes
 type: mpi
Process [0]
0.
0.
Process [1]
0.
0.
Process [2]
0.
0.

So the components of each eigenvector are printed in parallel and different eigenvectors are separated by a string of 0s, also printed in parallel.

My question: Is there no better way to do this? Because later I would want to read this file in python or julia and do some computations. If not, what's the best way to read this file in python or julia?

Thanks!

1
  • Well, I figured it's better to use regex to extract the floating-point values from the file and store it as a matrix, rather than banging my head over finding another way to write the eigenvectors. So for me, the problem is solved! Commented Mar 22, 2023 at 11:04

1 Answer 1

1

Instead of dumping to ascii and parsing that on input, use PETSCVIEWERHDF5 to dump an hdf5 file, and use the hdf5 module of python to read the file. That will be faster, and not incur conversion losses.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi, I don't know about the HDF5 format. As I checked, PETSc by default doesn't have HDF5, and it needs to be configured with the installed package. On our supercomputer, we have hdf5_parallel/1.10.7 which I think is pretty old. So will it be ok to work with that? Because when I load this module the mpi compiler defaults to an older version!
You need to install petsc with hdf5 support. Ask your supercomputer administrator, or do it yourself. It's not hard.
Every programming language has a way of opening a file in binary mode. You need to specify that explicit.
Thanks for your comment! I realized that the problem was with endianness. Also, I tried the HDF5 formatting, and it's great! But the only problem is that the file size is much larger than the binary one! Is there any workaround?
Hdf5 is a binary format so it should be roughly the same size, with a little overhead added. I'm not sure why it would be "much" larger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.