[petsc-users] converting scipy sparse CSR matrix to petcs matrix with mpi

Jed Brown jedbrown at mcs.anl.gov
Wed Aug 28 07:58:08 CDT 2013


John Travers <jtravs at gmail.com> writes:

> Hi,
>
> I currently generate PETSc matrices from scipy.sparse CSR format matrices as follows (where A is a scipy sparse CSR matrix):
>
> pA = PETSc.Mat().createAIJ(size=A.shape, csr=(A.indptr, A.indices, A.data)) 
>
> This work correctly on sequential runs, but if I run under MPI I get an error which I presume to be caused by the fact that all of my MPI processes try to simultaneously create this matrix, rather than splitting it? Eg. for 4 processes I get:

Yeah, the size of the passed CSR part doesn't match the local size of
the matrix.  I think that given a range [rstart,rend), you can pass

  csr=(A.indptr[rstart:rend] - A.indptr[rstart],
       A.indices[A.indptr[rstart]:A.indptr[rend]],
       A.data[A.indptr[rstart]:A.indptr[rend]])

More simply, you can just create the matrix and loop over rows calling
MatSetValues, but you have to do half of the spec above to set the
number of nonzeros per row if you want it to be fast.

Do you have to start with redundantly-computed scipy matrices?  (That'll
be a scalability bottleneck.  It's usually important to distribute
computation of the matrix entries unless you're only trying to use a few
cores.)

> ValueError: size(I) is 32769, expected 8193
>     csr=(A.indptr, A.indices, A.data))
>   File "Mat.pyx", line 256, in petsc4py.PETSc.Mat.createAIJ (src/petsc4py.PETSc.c:82905)
>
> What is the best/simplest/most efficient way to convert existing data in CSR format to a parallel sparse PETSc matrix for use by multiple MPI processes?

Do you know what partition you want to use?  Once you have a range of
rows, you should
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130828/1a6d4f3e/attachment.pgp>


More information about the petsc-users mailing list