[petsc-users] Block matrix vector products?

Smith, Barry F. bsmith at mcs.anl.gov
Tue Jul 16 01:45:31 CDT 2019



> On Jul 15, 2019, at 11:54 PM, Jed Brown via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> You can use MatCreateMAIJ(A,2,&M) and a single MatMult(A,xy) where xy
> contains the vectors x and y interlaced [x_0, y_0, x_1, y_1, ...].
> 
> There is also MatMatMult(A,X,...,&Y) where X is a MATDENSE with two
> columns, but I would prefer the MAIJ variant above in most cases.

  If you are "stuck" with using non-interlaced vectors and don't want the added memcpy() of moving the vector entries from regular vectors into the dense matrix before and after the product you can use MatDenseGetArray() and VecPlaceArray() to allow the vectors to "share" the column memory of the matrix with the vectors. Using this approach the dense matrix allows one to think of the two vectors as one "block" vector.

 Note that though there is some speed advantage to combining the two products it is not as dramatic as one would dream about. 

  Barry



> 
> Tyler Chen via petsc-users <petsc-users at mcs.anl.gov> writes:
> 
>> Hello,
>> 
>> I am looking for a way to compute two matrix vector products
>> simultaneously, where the matrix is the same for both products (i.e. Ax and
>> Ay). I know some numerical libraries have the concept of "block vectors" or
>> "basis vectors" and was wondering if there is anything similar in PETSc.
>> Right now I am just using two MatMults sequentially, but I'm hoping there
>> are probably better ways to do this. My matrices are MPIAIJ if that makes
>> any difference.
>> 
>> Best,
>> Tyler



More information about the petsc-users mailing list