[petsc-users] Matvecs and KSPSolves with multiple vectors

Sreeram R Venkat srvenkat at utexas.edu
Thu Dec 7 12:17:02 CST 2023


I have 2 sequential matrices M and R (both MATSEQAIJCUSPARSE of size n x n)
and a vector v of size n*m. v = [v_1 , v_2 ,... , v_m] where v_i has size
n. The data for v can be stored either in column-major or row-major order.
Now, I want to do 2 types of operations:

1. Matvecs of the form M*v_i = w_i, for i = 1..m.
2. KSPSolves of the form R*x_i = v_i, for i = 1..m.

>From what I have read on the documentation, I can think of 2 approaches.

1. Get the pointer to the data in v (column-major) and use it to create a
dense matrix V. Then do a MatMatMult with M*V = W, and take the data
pointer of W to create the vector w. For KSPSolves, use KSPMatSolve with R
and V.

2. Create a MATMAIJ using M/R and use that for matvecs directly with the
vector v. I don't know if KSPSolve with the MATMAIJ will know that it is a
multiple RHS system and act accordingly.

Which would be the more efficient option?

As a side-note, I am also wondering if there is a way to use row-major
storage of the vector v. The reason is that this could allow for more
coalesced memory access when doing matvecs.

Thanks,
Sreeram
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20231207/23c4c94b/attachment.html>


More information about the petsc-users mailing list