<div dir="ltr"><div><div><div>Dave, <br><br>Thx a lot for your very clear answer. My last question about modules could be reformulated like this :<br><br></div>Why
would I put anything in a ctx while I could simply use modules ? Maybe
it has something to do with the fact that PETSc is initially written for
C ?<br><br></div>Best<br><br></div>Timothee </div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-18 17:59 GMT+09:00 Dave May <span dir="ltr"><<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On 18 August 2015 at 10:42, Timothée Nicolas <span dir="ltr"><<a href="mailto:timothee.nicolas@gmail.com" target="_blank">timothee.nicolas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>Hi all,<br><br></div>I am in the process of writing an implicit solver for a set of PDEs (namely MHD equations), in FORTRAN. When setting the non-linear function to solve via Newton-Krylov, I use a "user defined context", namely the thing denoted by "ctx" on the doc page about SNESFunction :<br> <br><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESFunction.html#SNESFunction" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/SNESFunction.html#SNESFunction</a><br><br></div>In practice ctx is a user defined type which contains everything I need in the local routine which sets the function on the local part of the grid, FormFunctionLocal. That is, some local/global geometrical information on the grid, the physical parameter, and possibly any other thing. <br><br></div>In my case it so happens that due to the scheme I have chosen, when I compute my function, I need the full solution of the problem at the last two time steps (which are in Vec format). So my ctx contains two Vec elements. Since I will work in 3D and intend to use a lot of points in the future, I am concerned about memory problems which could occur.<br></div></div></div></div></blockquote><div><br></div></span><div>In the grand scheme of things, the two vectors in your context aren't likely to significantly add to the total memory footprint of your code. A couple of things to note:<br>* If you run in parallel, only the local part of the vector will be stored on each MPI process. <br>* All the KSP methods will allocate auxiliary vectors. Most methods require more than 2 auxiliary vectors.<br></div><div>* SNES also requires auxiliary vectors. If you use JFNK, that method will also need some additional temporary vectors.<br></div><div>* If you assemble a Jacobian, this matrix will likely require much more memory per MPI process than two vectors<br></div><span class=""><div> <br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><br></div>Is there a limit to the size occupied by ctx ? </div></div></div></blockquote><div><br></div></span><div>The only limit is defined by the available memory per MPI process you have on your target machine.<br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Would this be better if instead I was declaring global variables in a module and using this module inside FormFunctionLocal ? Is this allowed ?<br></div></div></div></blockquote><div><br></div></span><div>What would be the difference in doing that - the memory usage will be identical.<br><br></div><div>Cheers<br></div><div> Dave<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br></div>Best regards<br><br></div>Timothee NICOLAS<br></div>
</blockquote></div><br></div></div>
</blockquote></div><br></div>