<div dir="ltr">Especially if the user has requested to keep their nonzero pattern, is there any harm in calling MatAssembly with FLUSH instead of FINAL? Are there users relying on MatZeroValues being their final assembly?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 15, 2021 at 8:51 AM Alexander Lindsay <<a href="mailto:alexlindsay239@gmail.com">alexlindsay239@gmail.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"><div dir="ltr">On Thu, Jul 15, 2021 at 8:46 AM Fande Kong <<a href="mailto:fdkong.jd@gmail.com" target="_blank">fdkong.jd@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><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">"if (a->keepnonzeropattern)" branch does not change ilen so that A->ops->assemblyend will be fine. It would help if you made sure that elements have been inserted for these rows before you call MatZeroRows.<br></div></blockquote><div><br></div><div>So this is the crux of the problem. In ex11 let's say that I had not insert a value at (0,5) but I know I'm going to later and I've preallocated the space for it. MatZeroValues will erase that preallocation with its call to MatAssemblyEnd with MAT_FINAL_ASSEMBLY regardless of the value of keepnonzeropattern.</div><div><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"><br>However, I am not sure it is necessary to call  A->ops->assemblyend if we already require a->keepnonzeropattern. That being said, we might have something like this<br><div><br></div><div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><b>diff --git a/src/mat/impls/aij/seq/aij.c b/src/mat/impls/aij/seq/aij.c</b></span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><b>index 42c93a82b1..3f20a599d6 100644</b></span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><b>--- a/src/mat/impls/aij/seq/aij.c</b></span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><b>+++ b/src/mat/impls/aij/seq/aij.c</b></span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(56,185,199)">@@ -2203,7 +2203,9 @@</span><span style="font-variant-ligatures:no-common-ligatures"> PetscErrorCode MatZeroRows_SeqAIJ(Mat A,PetscInt N,const PetscInt rows[],PetscSc</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span> </span>#if defined(PETSC_HAVE_DEVICE)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span>   </span>if (A->offloadmask != PETSC_OFFLOAD_UNALLOCATED) A->offloadmask = PETSC_OFFLOAD_CPU;</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span> </span>#endif</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(202,51,35)"><span style="font-variant-ligatures:no-common-ligatures">-<span>  </span>ierr = (*A->ops->assemblyend)(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><span style="font-variant-ligatures:no-common-ligatures">+<span>  </span>if (!a->keepnonzeropattern) {</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><span style="font-variant-ligatures:no-common-ligatures">+<span>    </span>ierr = (*A->ops->assemblyend)(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><span style="font-variant-ligatures:no-common-ligatures">+<span>  </span>}</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span>   </span>PetscFunctionReturn(0);</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><span> </span>}</span></p>
<br></div><div><br></div><div>Fande</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 15, 2021 at 9:30 AM Stefano Zampini <<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.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>Alexander<div><br></div><div>Do you have a small code to reproduce the issue?<div><br></div><div>Below is the output using a PETSc example (src/mat/tests/ex11). The pattern is kept. </div><div><br></div><div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">kl-18448:tests szampini$ ./ex11 </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">Mat Object: 1 MPI processes</span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">  type: seqaij</span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 0: (0, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 1: (0, -1.)  (1, 4.)  (2, -1.)  (6, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 2: (2, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 3: (2, -1.)  (3, 4.)  (4, -1.)  (8, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 4: (4, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 5: (0, -1.)  (5, 4.)  (6, -1.)  (10, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 6: (6, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 7: (2, -1.)  (6, -1.)  (7, 4.)  (8, -1.)  (12, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 8: (8, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 9: (4, -1.)  (8, -1.)  (9, 4.)  (14, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 10: (10, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 11: (6, -1.)  (10, -1.)  (11, 4.)  (12, -1.)  (16, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 12: (12, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 13: (8, -1.)  (12, -1.)  (13, 4.)  (14, -1.)  (18, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 14: (14, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 15: (10, -1.)  (15, 4.)  (16, -1.)  (20, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 16: (16, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 17: (12, -1.)  (16, -1.)  (17, 4.)  (18, -1.)  (22, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 18: (18, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 19: (14, -1.)  (18, -1.)  (19, 4.)  (24, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 20: (20, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 21: (16, -1.)  (20, -1.)  (21, 4.)  (22, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 22: (22, 5.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 23: (18, -1.)  (22, -1.)  (23, 4.)  (24, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 24: (19, -1.)  (23, -1.)  (24, 4.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">kl-18448:tests szampini$ ./ex11 -keep_nonzero_pattern</span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">Mat Object: 1 MPI processes</span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">  type: seqaij</span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 0: (0, 5.)  (1, 0.)  (5, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 1: (0, -1.)  (1, 4.)  (2, -1.)  (6, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 2: (1, 0.)  (2, 5.)  (3, 0.)  (7, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 3: (2, -1.)  (3, 4.)  (4, -1.)  (8, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 4: (3, 0.)  (4, 5.)  (9, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 5: (0, -1.)  (5, 4.)  (6, -1.)  (10, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 6: (1, 0.)  (5, 0.)  (6, 5.)  (7, 0.)  (11, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 7: (2, -1.)  (6, -1.)  (7, 4.)  (8, -1.)  (12, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 8: (3, 0.)  (7, 0.)  (8, 5.)  (9, 0.)  (13, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 9: (4, -1.)  (8, -1.)  (9, 4.)  (14, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 10: (5, 0.)  (10, 5.)  (11, 0.)  (15, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 11: (6, -1.)  (10, -1.)  (11, 4.)  (12, -1.)  (16, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 12: (7, 0.)  (11, 0.)  (12, 5.)  (13, 0.)  (17, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 13: (8, -1.)  (12, -1.)  (13, 4.)  (14, -1.)  (18, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 14: (9, 0.)  (13, 0.)  (14, 5.)  (19, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 15: (10, -1.)  (15, 4.)  (16, -1.)  (20, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 16: (11, 0.)  (15, 0.)  (16, 5.)  (17, 0.)  (21, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 17: (12, -1.)  (16, -1.)  (17, 4.)  (18, -1.)  (22, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 18: (13, 0.)  (17, 0.)  (18, 5.)  (19, 0.)  (23, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 19: (14, -1.)  (18, -1.)  (19, 4.)  (24, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 20: (15, 0.)  (20, 5.)  (21, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 21: (16, -1.)  (20, -1.)  (21, 4.)  (22, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 22: (17, 0.)  (21, 0.)  (22, 5.)  (23, 0.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 23: (18, -1.)  (22, -1.)  (23, 4.)  (24, -1.) </span></div><div style="margin:0px;font-stretch:normal;font-size:21px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">row 24: (19, -1.)  (23, -1.)  (24, 4.)</span></div><div><br><blockquote type="cite"><div>On Jul 15, 2021, at 4:41 PM, Alexander Lindsay <<a href="mailto:alexlindsay239@gmail.com" target="_blank">alexlindsay239@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>My interpretation of the documentation page of MatZeroRows is that if I've set MAT_KEEP_NONZERO_PATTERN to true, then my sparsity pattern shouldn't be changed by a call to it, e.g. a->imax should not change. However, at least for sequential matrices, MatAssemblyEnd is called with MAT_FINAL_ASSEMBLY at the end of MatZeroRows_SeqAIJ and that does indeed change my sparsity pattern. Is my interpretation of the documentation page wrong?</div><div><br></div><div>Alex<br></div></div>
</div></blockquote></div><br></div></div></div></blockquote></div>
</blockquote></div></div>
</blockquote></div>