<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Dec 7, 2023, at 1:17 PM, Sreeram R Venkat <srvenkat@utexas.edu> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(34,34,34)">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:</div><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">1. Matvecs of the form M*v_i = w_i, for i = 1..m. </div><div style="color:rgb(34,34,34)">2. KSPSolves of the form R*x_i = v_i, for i = 1..m.</div><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">From what I have read on the documentation, I can think of 2 approaches. </div><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">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.</div><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">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.</div><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">Which would be the more efficient option?</div></div></div></div></div></blockquote><div><br></div>Use 1. <br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">As a side-note, I am also wondering if there is a way to use row-major storage of the vector v.</div></div></div></div></div></blockquote><div><br></div>No</div><div><br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(34,34,34)"> The reason is that this could allow for more coalesced memory access when doing matvecs.</div></div></div></div></div></blockquote><div><br></div> PETSc matrix-vector products use BLAS GMEV matrix-vector products for the computation so in theory they should already be well-optimized</div><div><br><blockquote type="cite"><div><div dir="ltr"><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="color:rgb(34,34,34)"><br></div><div style="color:rgb(34,34,34)">Thanks,</div><div style="color:rgb(34,34,34)">Sreeram</div></div></div></div>
</div></blockquote></div><br></body></html>