<div class="gmail_quote">On Sun, Jun 10, 2012 at 7:05 PM, Nakib Haider Protik <span dir="ltr"><<a href="mailto:nprot048@uottawa.ca" target="_blank">nprot048@uottawa.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello again<br>
<br>
Here I am trying to declare three different local KSP objects for the<br>
coarse solver, up smoother and down smoother respectively. The code fails<br>
to compile with the error:<br>
<br>
expected expression before ‘KSP’<br>
<br>
for each of the /**/ lines. Both the v3.0.0</blockquote><div><br></div><div>This is unrelated, but please upgrade to petsc-3.3</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
user manual and the online<br>
documentation suggests usage of this kind. I am totally at loss here and<br>
any suggestion will be greatly appreciated.<br>
<br>
////////////////////MG Solver Stuff////////////////////<br>
KSP solver;<br>
PC pc;<br>
Mat A, P;<br>
//<br>
.<br>
.<br>
. Here the A matrix forming function is called<br>
.<br>
.<br>
//<br>
KSPCreate(PETSC_COMM_WORLD, &solver);<br>
KSPSetType(solver, KSPGMRES);<br>
KSPGetPC(solver, &pc);<br>
KSPSetFromOptions(solver);<br>
<div class="im"><br>
PCSetType(pc, PCMG);<br>
PCMGSetLevels(pc, 2, PETSC_NULL);<br>
PCMGSetType(pc, PC_MG_MULTIPLICATIVE);<br>
PCMGSetCycleType(pc, PC_MG_CYCLE_V);<br>
MatDuplicate(A, MAT_COPY_VALUES, &P);<br>
PCMGSetCyclesOnLevel(pc, 0, 1);<br>
PCMGSetCyclesOnLevel(pc, 1, 1);<br>
</div> PCMGGetCoarseSolve(pc, KSP *cksp);/**/<br></blockquote><div><br></div><div>I'm sorry, this is not valid C. The API documentation in the user's manual shows you the types in the call, it is not valid code to call the routine.</div>
<div><br></div><div>I'm afraid that if you are going to write code in C, you will have to learn the C language. It is not a difficult language.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
PCMGGetSmootherDown(pc, 0, KSP *dksp);/**/<br>
PCMGGetSmootherUp(pc, 1, KSP *uksp);/**/<br>
<div class="im"> PCMGSetInterpolation(pc, 1, P);<br>
PCMGSetRestriction(pc, 1, P);<br>
PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);<br>
PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);<br>
<br>
</div> KSPSetOperators(solver, A, P, SAME_NONZERO_PATTERN);<br>
KSPSolve(solver, breal, xreal_harm);<br>
KSPSolve(solver, bimag, ximag_harm);<br>
//////////////////////////////////////////////////////////<br>
<br>
Thanks<br>
<div class="HOEnZb"><div class="h5"><br>
> On Sun, Jun 10, 2012 at 4:54 PM, Nakib Haider Protik<br>
> <<a href="mailto:nprot048@uottawa.ca">nprot048@uottawa.ca</a>>wrote:<br>
><br>
>> Sorry, I meant to refer to this:<br>
>> <a href="http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008793.html" target="_blank">http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008793.html</a><br>
><br>
><br>
> As I've said in every message, this rampantly overwrites local variables.<br>
><br>
>> > DAGetMatrix(da, MATAIJ, &M);<br>
>> ><br>
>> > KSPCreate(PETSC_COMM_WORLD, &ksp);<br>
>> > KSPSetType(ksp, KSPGMRES);<br>
>> > KSPGetPC(ksp, &pcmg);<br>
>> > PCSetType(pcmg, PCMG);<br>
>> ><br>
>> > PCMGSetLevels(pcmg, 2, &PETSC_COMM_WORLD);<br>
>> > PCMGSetType(pcmg, PC_MG_MULTIPLICATIVE);<br>
>> > PCMGSetCycleType(pcmg, PC_MG_CYCLE_W);<br>
>> > PCMGSetCyclesOnLevel(pcmg, 0, 1);<br>
>> > PCMGSetCyclesOnLevel(pcmg, 1, 1);<br>
>> ><br>
>> > PCMGGetCoarseSolve(pcmg, &ksp);<br>
><br>
> This overwrites ksp with the coarse solver.<br>
><br>
>> ><br>
>> > PCMGGetSmoother(pcmg, 0, &ksp);<br>
><br>
> This overwrites it again with the level 0 "smoother" (same as the coarse<br>
> solver).<br>
><br>
>> > PCMGGetSmoother(pcmg, 1, &ksp);<br>
><br>
> This overwrites it again with the level 1 smoother.<br>
><br>
>> > PCMGSetInterpolation(pcmg, 1, M);<br>
>> > PCMGSetRestriction(pcmg, 1, M);<br>
>> ><br>
>> > PCMGSetResidual(pcmg, 0, PCMGDefaultResidual, M);<br>
>> > PCMGSetResidual(pcmg, 1, PCMGDefaultResidual, M);<br>
><br>
> So if you get down here and use "ksp" for something (as your code did),<br>
> your are actually working with the level 1 smoother. I also said this in<br>
> my<br>
> first email, explaining why the problem was solved this way (the smoother<br>
> was as good as a direct solve). The original KSP has been lost forever and<br>
> has leaked its memory.<br>
><br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Nakib<br>
</font></span></blockquote></div><br>