[petsc-users] Setting values of a matrix in a blockwise manner

Matthew Knepley knepley at gmail.com
Wed Jun 10 09:45:16 CDT 2015


On Wed, Jun 10, 2015 at 9:42 AM, Tim Steinhoff <kandanovian at gmail.com>
wrote:

> Hi all
>
> I want to use Petsc to solve some linear systems via the built-in Krylov
> subspace methods as well as by means of UMFPACK.
>
> The considered matrix is block sparse with blocks of size 6x6.
>
> Here is what I came up with after taking a look at some of the examples
>
> MPI_Comm comm;
> Mat A;
> PetscInt n = 10000; /* dimension of matrix */
> comm = PETSC_COMM_SELF;
> MatCreate(comm,&A);
> MatSetSizes(Amat,n,n,n,n);
> MatSetBlockSize(A,6);
> MatSetType(A,MATAIJ); /* UMFPACK compatible format due to comm =
> PETSC_COMM_SELF */
>
> Questions:
> 1.
> I work on a single node with 2-8 cores. Hence, comm = PETSC_COMM_SELF; I
> guess. Is it correct in this contect to set MatSetSizes(Amat,n,n,n,n); with
> 4-times n?
>

Yes.


> 2.
> After the above sequence of commands do I have to use something like
>   MatSeqAIJSetPreallocation(A,0,d_nnz); /* d_nnz <-> number of nonzeros
> per row */
> or is it possible to use
>   MatSeqBAIJSetPreallocation(A,6,0,db_nnz); /* db_nnz <-> number of block
> nonzeros per block row */
>

You should use this if using MATBAIJ.


> In any case, is something like
>   MatSetValuesBlocked(A,1,idx_r,1,idx_c,myblockvals,INSERT_VALUES);
> to fill values of one block into the matrix A ok?
>

Yes, however in order to get improved performance, you need type MATBAIJ.

  Thanks,

    Matt


> Regards
> Tim
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150610/f975e626/attachment-0001.html>


More information about the petsc-users mailing list