<div dir="ltr">Mark, thanks for the quick response. I am more interested in parallel implementation of MatMult for SBAIJ. I found following<div><pre width="80" style="color:rgb(0,0,0)"><a name="line1094">1094: </a><strong><font color="#4169E1"><a name="MatMult_MPISBAIJ"></a><a href="https://petsc.org/main/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> MatMult_MPISBAIJ(<a href="https://petsc.org/main/docs/manualpages/Mat/Mat.html#Mat">Mat</a> A,<a href="https://petsc.org/main/docs/manualpages/Vec/Vec.html#Vec">Vec</a> xx,<a href="https://petsc.org/main/docs/manualpages/Vec/Vec.html#Vec">Vec</a> yy)</font></strong>
<a name="line1095">1095: </a>{
<a name="line1096">1096: </a> Mat_MPISBAIJ *a = (Mat_MPISBAIJ*)A->data;
<a name="line1097">1097: </a> <a href="https://petsc.org/main/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> ierr;
<a name="line1098">1098: </a> <a href="https://petsc.org/main/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> mbs=a->mbs,bs=A->rmap->bs;
<a name="line1099">1099: </a> <a href="https://petsc.org/main/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *from;
<a name="line1100">1100: </a> const <a href="https://petsc.org/main/docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *x;
<a name="line1103">1103: </a> <font color="#B22222">/* diagonal part */</font>
<a name="line1104">1104: </a> (*a->A->ops->mult)(a->A,xx,a->slvec1a);
<a name="line1105">1105: </a> <a href="https://petsc.org/main/docs/manualpages/Vec/VecSet.html#VecSet">VecSet</a>(a->slvec1b,0.0);
<a name="line1107">1107: </a> <font color="#B22222">/* subdiagonal part */</font>
<a name="line1108">1108: </a> (*a->B->ops->multtranspose)(a->B,xx,a->slvec0b);
<a name="line1110">1110: </a> <font color="#B22222">/* copy x into the vec slvec0 */</font>
<a name="line1111">1111: </a> <a href="https://petsc.org/main/docs/manualpages/Vec/VecGetArray.html#VecGetArray">VecGetArray</a>(a->slvec0,&from);
<a name="line1112">1112: </a> <a href="https://petsc.org/main/docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead">VecGetArrayRead</a>(xx,&x);
<a name="line1114">1114: </a> <a href="https://petsc.org/main/docs/manualpages/Sys/PetscArraycpy.html#PetscArraycpy">PetscArraycpy</a>(from,x,bs*mbs);
<a name="line1115">1115: </a> <a href="https://petsc.org/main/docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray">VecRestoreArray</a>(a->slvec0,&from);
<a name="line1116">1116: </a> <a href="https://petsc.org/main/docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead">VecRestoreArrayRead</a>(xx,&x);
<a name="line1118">1118: </a> <a href="https://petsc.org/main/docs/manualpages/PetscSF/VecScatterBegin.html#VecScatterBegin">VecScatterBegin</a>(a->sMvctx,a->slvec0,a->slvec1,<a href="https://petsc.org/main/docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,<a href="https://petsc.org/main/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD">SCATTER_FORWARD</a>);
<a name="line1119">1119: </a> <a href="https://petsc.org/main/docs/manualpages/PetscSF/VecScatterEnd.html#VecScatterEnd">VecScatterEnd</a>(a->sMvctx,a->slvec0,a->slvec1,<a href="https://petsc.org/main/docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,<a href="https://petsc.org/main/docs/manualpages/Vec/SCATTER_FORWARD.html#SCATTER_FORWARD">SCATTER_FORWARD</a>);
<a name="line1120">1120: </a> <font color="#B22222">/* supperdiagonal part */</font>
<a name="line1121">1121: </a> (*a->B->ops->multadd)(a->B,a->slvec1b,a->slvec1a,yy);
<a name="line1122">1122: </a> <font color="#4169E1">return</font>(0);
<a name="line1123">1123: </a>}</pre><pre width="80" style="color:rgb(0,0,0)"> I try to understand the algorithm.</pre><pre width="80" style="color:rgb(0,0,0)"><br></pre><pre width="80" style="color:rgb(0,0,0)">Thanks,</pre><pre width="80" style="color:rgb(0,0,0)">Sam</pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 21, 2022 at 11:14 AM Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">This code looks fine to me and the code is in src/mat/impls/sbaij/seq/sbaij2.c</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 21, 2022 at 2:02 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Dear PETSc dev team,</span><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> The documentation about MatCreateSBAIJ has following</span></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">"It is recommended that one use the </span><a href="https://petsc.org/main/docs/manualpages/Mat/MatCreate.html#MatCreate" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatCreate</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">(), </span><a href="https://petsc.org/main/docs/manualpages/Mat/MatSetType.html#MatSetType" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatSetType</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">() and/or </span><a href="https://petsc.org/main/docs/manualpages/Mat/MatSetFromOptions.html#MatSetFromOptions" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatSetFromOptions</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">(), MatXXXXSetPreallocation() paradigm instead of this routine directly. [MatXXXXSetPreallocation() is, for example, </span><a href="https://petsc.org/main/docs/manualpages/Mat/MatSeqAIJSetPreallocation.html#MatSeqAIJSetPreallocation" style="font-family:"Times New Roman";font-size:medium" target="_blank">MatSeqAIJSetPreallocation</a><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">]"</span><br></div><div><span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"> I currently call </span>MatCreateSBAIJ directly as follows:</div><div>MatCreateSBAIJ (with d_nnz and o_nnz)<br>MatSetValues (to add row by row)</div><div>MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);</div><div>MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);<br>MatSetOption(A, MAT_SYMMETRIC, PETSC_TRUE);<span style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><br></span></div><div><br></div><div> Two questions:</div><div> (1) I am wondering whether what I am doing is the most efficient. </div><div><br></div><div> (2) I try to find out how the matrix vector multiplication is implemented in PETSc for SBAIJ storage.</div><div><br></div><div>Thanks,</div><div>Sam</div></div>
</blockquote></div>
</blockquote></div>