[petsc-users] multigrid implementation problem
Jed Brown
jedbrown at mcs.anl.gov
Sun Jun 10 16:33:28 CDT 2012
On Sun, Jun 10, 2012 at 4:20 PM, Nakib Haider Protik <nprot048 at uottawa.ca>wrote:
> Reason for two ksp objects:
>
> Multigrid and Domain Decomposition in PETSc
> Barry Smith
> PETSc Developer
>
> pg 28:
>
> //Use same pre and post smoother
> MGGetSmoother(pc,int level,KSP *ksp);
>
>
> //Use different pre and post smoother
> MGGetSmootherDown(pc,int level,KSP *dksp);
> MGGetSmootherUp(pc,int level,KSP *uksp);
>
> I was trying to use the second in my code.
>
But you created two outer-level KSP objects, then leaked their memory when
you overwrote their value when accessing the smoother on levels.
> I would be greatly helped if
> you could tell me where exactly my code goes wrong.
>
The problem is that you are using the same local variable for every ksp
arising in the code. When you get access to levels, you are overwriting the
local variable. Since you did this so many times in various places where it
was clearly not intended, I had assumed that you were not familiar with
local variables in C. Everything that was incorrect with your code had to
do with overwriting the local variable and later using it as though its
original value was still intact. It would be better to explain what you are
trying to achieve instead of posting code with nonsensical handling of
local variables.
You should read through the code you posted and fix all these places
(declare new variables of type KSP so you don't overwrite the outer ones).
If you still have trouble, run in valgrind. It will tell you when you lose
the reference to the outer objects.
>
> As for the "accidental" correctness of the 1d code, here's where I found
> the prototype:
>
> http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008793.html
>
> If my question does not abide by the regulations of this mailing list, or
> if you are not obliged to answers questions of this kind, please let me
> know. I am not looking for free lessons on c, but thanks for the link.
> Despite the rude reply, thank you for taking the time.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120610/03fec72d/attachment.html>
More information about the petsc-users
mailing list