[petsc-users] Matrix Construction Question

Aron Ahmadia aron.ahmadia at kaust.edu.sa
Tue Jun 28 09:09:44 CDT 2011


Hi Adam,

It sounds like you are creating a 'blocked' matrix.  PETSc's format for this
is described briefly here:
http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Mat/MatCreateMPIBAIJ.html#MatCreateMPIBAIJ
You will also be interested in adding values blocked:
http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Mat/MatSetValuesBlocked.html

*Also, am I approaching this problem the correct way, or are there more
efficient ways of building this matrix with the ultimate goal of inverting
it?*

I will let somebody else on the list tell you why this is or isn't a good
idea.  Generally if you are going to go through the trouble of inverting a
matrix, you should use a direct solver and at least factor it first, then
construct the inverse from the decomposed matrix (though the situations
where you MUST construct the inverse are quite rare).

A

On Tue, Jun 28, 2011 at 4:55 PM, Adam Byrd <adam1.byrd at gmail.com> wrote:

> Hi,
>
> I'm rather new to PETSc and trying to work out the best way to create and
> fill a large sparse matrix distributed over many processors. Currently, my
> goal is to create a 3600x3600 matrix in units of 12x12 blocks with several
> blocks on any given node. I'd like to create the matrix in such a way that
> each node only holds the information in it's handful of blocks and not the
> entire matrix. Eventually, this matrix is to be inverted (I know, inversion
> should be avoided, but as this is a Hamiltonian matrix from which I need the
> Green's function, I'm unaware of a way to forgo carrying out the inversion).
> Additionally, the values will be changed slightly and the matrix will be
> repeatedly inverted. It's structure will remain the same. In order to learn
> how to do this is I am starting with a small 6x6 matrix broken into four 3x3
> blocks and distributed one block per node. I've been able to create a local
> 3x3 matrix on each node, with it's own values, and with the global
> row/column IDs correctly set to [0, 1, 2] or [3, 4, 5] depending on where
> the block is in the matrix. My problem manifests when I try to create the
> larger matrix from the individual smaller ones. When the matrix is
> constructed I'm trying to use MatSetValues and having each node pass in it's
> 3x3 block. I end up with an error that the sum of local lengths 12x12 does
> not match the global length 6x6. It appears as though this is from passing
> in four 3x3s and the program interpreting that as a 12x12 instead of as a
> 6x6 with the blocks in a grid.
>
> My question is then: is it possible to fill a matrix as a grid of blocks,
> or can I only fill it in groups of rows or columns? Also, am I approaching
> this problem the correct way, or are there more efficient ways of building
> this matrix with the ultimate goal of inverting it?
>
> I have included my copy of a modified example if it helps. I do apologize
> if this is answered somewhere in the documentation, I have been unable to
> find a solution.
>
> Respectfully,
> Adam
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110628/c6f5f87b/attachment.htm>


More information about the petsc-users mailing list