<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 31, 2015 at 11:33 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jul 31, 2015, at 11:34 AM, Gautam Bisht <<a href="mailto:gbisht@lbl.gov">gbisht@lbl.gov</a>> wrote:<br>
><br>
> I have a followup question on this topic regarding memory usage.<br>
><br>
> For the Jacobian matrix in src/snes/examples/tutorials/ex28.c of problem_type 2,  MAT_NEW_NONZERO_LOCATION_ERR and MAT_NEW_NONZERO_ALLOCATION_ERR are set PETSC_FALSE. If the problem_type 2 is solved multiple times (see the git difference below), would the memory usage keep on increasing? Or, since the non-zero pattern isn't changing over time, there would only be an increase in memory on the first SNESSolve?<br>
<br>
</span>  Only the first time through. In fact after your first matrix assembly you could turn those flags back on to generate errors if you start adding new locations the second time (just as a double check that there is not some mistake in your code the generates matrix entries).<br></blockquote><div><br></div><div>Thanks. That works perfectly.</div><div><br></div><div>-Gautam.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
  Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
> >git diff ex28.c<br>
> diff --git a/src/snes/examples/tutorials/ex28.c b/src/snes/examples/tutorials/ex28.c<br>
> index 98dd6b9..40f94d1 100644<br>
> --- a/src/snes/examples/tutorials/ex28.c<br>
> +++ b/src/snes/examples/tutorials/ex28.c<br>
> @@ -342,6 +342,7 @@ int main(int argc, char *argv[])<br>
>    Mat            B;<br>
>    IS             *isg;<br>
>    PetscBool      view_draw,pass_dm;<br>
> +  PetscInt iter;<br>
><br>
>    PetscInitialize(&argc,&argv,0,help);<br>
>    ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,-10,1,1,NULL,&dau);CHKERRQ(ierr);<br>
> @@ -434,7 +435,10 @@ int main(int argc, char *argv[])<br>
>         * of splits, but it requires using a DM (perhaps your own implementation). */<br>
>        ierr = SNESSetDM(snes,pack);CHKERRQ(ierr);<br>
>      }<br>
> +    for (iter=1; iter<10000; iter++)  {<br>
>      ierr = SNESSolve(snes,NULL,X);CHKERRQ(ierr);<br>
> +    ierr = FormInitial_Coupled(user,X);CHKERRQ(ierr);<br>
> +    }<br>
>      break;<br>
>    }<br>
>    if (view_draw) {ierr = VecView(X,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);}<br>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
><br>
><br>
> -Gautam.<br>
><br>
> On Wed, Jul 29, 2015 at 11:25 AM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> > On Jul 29, 2015, at 12:58 PM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com">gideon.simpson@gmail.com</a>> wrote:<br>
> ><br>
> > That fixed it, thanks.  Given that I the nonzero pattern will not change throughout the solve, would it still be unreasonable to use this for larger problems?<br>
><br>
>    Eventually it will kill you in the first time you assemble the matrix.<br>
><br>
>   Barry<br>
><br>
> ><br>
> > -gideon<br>
> ><br>
> >> On Jul 29, 2015, at 1:52 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> >><br>
> >><br>
> >>   To start, immediately after you have created the matrix do what it says call<br>
> >><br>
> >>> MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE)<br>
> >><br>
> >>  this will allow you to build your matrix and work fine for modest size problems. For larger problems (only when you have your code running and solving the problem you want) you need to add in more preallocation information. But to do it now would be premature optimization.<br>
> >><br>
> >>   Barry<br>
> >><br>
> >><br>
> >><br>
> >>> On Jul 29, 2015, at 11:51 AM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com">gideon.simpson@gmail.com</a>> wrote:<br>
> >>><br>
> >>> That’s generating malloc errors:<br>
> >>><br>
> >>> [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
> >>> [0]PETSC ERROR: Argument out of range<br>
> >>> [0]PETSC ERROR: New nonzero at (10,0) caused a malloc<br>
> >>> Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check<br>
> >>><br>
> >>> I suspect this is because DMCreateMatrix is picking a sparsity pattern which is not consistent with what I need.<br>
> >>><br>
> >>> -gideon<br>
> >>><br>
> >>>> On Jul 28, 2015, at 10:10 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> >>>><br>
> >>>><br>
> >>>> DMCreateMatrix() ?<br>
> >>>><br>
> >>>><br>
> >>>>> On Jul 28, 2015, at 9:02 PM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com">gideon.simpson@gmail.com</a>> wrote:<br>
> >>>>><br>
> >>>>> I’m working with a DMComposite where I have a DMRedundant with 2 parameters, and then a standard DMDACreate with some number of entires that I would like to have distributed.  For concreteness, suppose it is<br>
> >>>>><br>
> >>>>> DMCompositeCreate(PETSC_COMM_WORLD, &packer);<br>
> >>>>> DMRedundantCreate(PETSC_COMM_WORLD, 0, 2, &p_dm);<br>
> >>>>> DMCompositeAddDM(packer,p_dm);<br>
> >>>>> DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE, nx, 1, 1, NULL,&u_dm);<br>
> >>>>> DMCompositeAddDM(packer,u_dm);<br>
> >>>>> DMCreateGlobalVector(packer,&U);<br>
> >>>>><br>
> >>>>> Now, I would like to construct a matrix for this problem that can be used for computing Jacobians in a nonlinear solve.  Is there a way to get the matrix size to layout in a “useful” way, in the sense that the first process, which owns the two degrees of freedom of p_dm and the first N0 number of the rows of u_dm, controls the corresponding N0+2 rows of the matrix, and analgously for the second process has the next N1 rows of the u_dm vector, and has the next N1 rows of the matrix?<br>
> >>>>><br>
> >>>>> -gideon<br>
> >>>>><br>
> >>>><br>
> >>><br>
> >><br>
> ><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>