[petsc-users] multigrid implementation problem

Nakib Haider Protik nprot048 at uottawa.ca
Sun Jun 10 19:32:46 CDT 2012


Okay. But if I understood correctly, doing the following would also be
wrong since I will have made three extra outer KSP objects. I am not sure
I understand what these functions want.

  KSP cksp, uksp, dksp;
  PCMGGetCoarseSolve(pc, &cksp);/**/
  PCMGGetSmootherDown(pc, 0, &dksp);/**/
  PCMGGetSmootherUp(pc, 1, &uksp);/**/

Thanks.


> On Sun, Jun 10, 2012 at 7:05 PM, Nakib Haider Protik
> <nprot048 at uottawa.ca>wrote:
>
>> Hello again
>>
>> Here I am trying to declare three different local KSP objects for the
>> coarse solver, up smoother and down smoother respectively. The code
>> fails
>> to compile with the error:
>>
>> expected expression before ‘KSP’
>>
>> for each of the /**/ lines. Both the v3.0.0
>
>
> This is unrelated, but please upgrade to petsc-3.3
>
>
>> user manual and the online
>> documentation suggests usage of this kind. I am totally at loss here and
>> any suggestion will be greatly appreciated.
>>
>> ////////////////////MG Solver Stuff////////////////////
>>    KSP solver;
>>    PC pc;
>>    Mat A, P;
>>    //
>>    .
>>    .
>>    . Here the A matrix forming function is called
>>    .
>>    .
>>    //
>>    KSPCreate(PETSC_COMM_WORLD, &solver);
>>    KSPSetType(solver, KSPGMRES);
>>    KSPGetPC(solver, &pc);
>>    KSPSetFromOptions(solver);
>>
>>    PCSetType(pc, PCMG);
>>    PCMGSetLevels(pc, 2, PETSC_NULL);
>>    PCMGSetType(pc, PC_MG_MULTIPLICATIVE);
>>    PCMGSetCycleType(pc, PC_MG_CYCLE_V);
>>    MatDuplicate(A, MAT_COPY_VALUES, &P);
>>    PCMGSetCyclesOnLevel(pc, 0, 1);
>>    PCMGSetCyclesOnLevel(pc, 1, 1);
>>    PCMGGetCoarseSolve(pc, KSP *cksp);/**/
>>
>
> 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.
>
> 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.
>
>
>>    PCMGGetSmootherDown(pc, 0, KSP *dksp);/**/
>>    PCMGGetSmootherUp(pc, 1, KSP *uksp);/**/
>>     PCMGSetInterpolation(pc, 1, P);
>>    PCMGSetRestriction(pc, 1, P);
>>    PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);
>>    PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);
>>
>>     KSPSetOperators(solver, A, P, SAME_NONZERO_PATTERN);
>>    KSPSolve(solver, breal, xreal_harm);
>>    KSPSolve(solver, bimag, ximag_harm);
>>    //////////////////////////////////////////////////////////
>>
>> Thanks
>>
>> > On Sun, Jun 10, 2012 at 4:54 PM, Nakib Haider Protik
>> > <nprot048 at uottawa.ca>wrote:
>> >
>> >> Sorry, I meant to refer to this:
>> >> http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008793.html
>> >
>> >
>> > As I've said in every message, this rampantly overwrites local
>> variables.
>> >
>> >> >   DAGetMatrix(da, MATAIJ, &M);
>> >> >
>> >> >   KSPCreate(PETSC_COMM_WORLD, &ksp);
>> >> >   KSPSetType(ksp, KSPGMRES);
>> >> >   KSPGetPC(ksp, &pcmg);
>> >> >   PCSetType(pcmg, PCMG);
>> >> >
>> >> >   PCMGSetLevels(pcmg, 2, &PETSC_COMM_WORLD);
>> >> >   PCMGSetType(pcmg, PC_MG_MULTIPLICATIVE);
>> >> >   PCMGSetCycleType(pcmg, PC_MG_CYCLE_W);
>> >> >   PCMGSetCyclesOnLevel(pcmg, 0, 1);
>> >> >   PCMGSetCyclesOnLevel(pcmg, 1, 1);
>> >> >
>> >> >   PCMGGetCoarseSolve(pcmg, &ksp);
>> >
>> > This overwrites ksp with the coarse solver.
>> >
>> >> >
>> >> >   PCMGGetSmoother(pcmg, 0, &ksp);
>> >
>> > This overwrites it again with the level 0 "smoother" (same as the
>> coarse
>> > solver).
>> >
>> >> >   PCMGGetSmoother(pcmg, 1, &ksp);
>> >
>> > This overwrites it again with the level 1 smoother.
>> >
>> >> >   PCMGSetInterpolation(pcmg, 1, M);
>> >> >   PCMGSetRestriction(pcmg, 1, M);
>> >> >
>> >> >   PCMGSetResidual(pcmg, 0, PCMGDefaultResidual, M);
>> >> >   PCMGSetResidual(pcmg, 1, PCMGDefaultResidual, M);
>> >
>> > So if you get down here and use "ksp" for something (as your code
>> did),
>> > your are actually working with the level 1 smoother. I also said this
>> in
>> > my
>> > first email, explaining why the problem was solved this way (the
>> smoother
>> > was as good as a direct solve). The original KSP has been lost forever
>> and
>> > has leaked its memory.
>> >
>>
>>
>> --
>> Nakib
>>
>


-- 
Nakib


More information about the petsc-users mailing list