Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

I am new to the PETSc package.

I have a ~4000x4000 matrix A in matrix-market format and I want to get PETSc to solve this using multiple processors.

I know how to solve the system on a single processor, but I don't know how to distribute the matrix and vectors among different processors.

Is there a simple set of instructions to do this?

share|improve this question

1 Answer 1

Matrix Market is a terrible format for reading in parallel, therefore it is better to preprocess to a better parallel format. Your matrix size is extremely small so performance is not an issue, but the easiest and most general thing is to use Python or Matlab/Octave to write the Matrix Market file in PETSc binary format, which can be read efficiently in parallel using MatLoad(). For example, you can use this Python code for the preprocessing (add $PETSC_DIR/bin/pythonscripts to your PYTHONPATH)

import scipy.io, PetscBinaryIO
A = scipy.io.mmread('thematrix.mtx')
PetscBinaryIO.PetscBinaryIO().writeMatSciPy(open('petscmatrix','w'), A)

You can also write a vector to the file at this time. If you just want to read and solve the system, you can use src/ksp/ksp/examples/tutorials/ex10.c (with the option -f petscmatrix to read the binary file you just wrote).

In a real application, you should avoid a workflow that involves writing files to disk in any format. It is much better to assemble the matrix in parallel using a domain-decomposed representation of the problem. Most examples in PETSc are written this way.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.