Zhisong, It looks like you're using the same ksp object to define your solver/preconditioner, the smoother and the coarse-level solver. It looks like a recursive call to your solver. Perhaps you should use a different structure for the coarse-level solver:
PCMGGetCoarseSolve(pcmg, &coarseksp); and define coarseksp entirely for the coarse level. Similarly, you may need to define a specific ksp for the smoothers on each level. Cheers, Sylvain 2011/5/15 Li, Zhisong (lizs) <lizs at mail.uc.edu>: > ?Hi, Petsc Team, > > In my knowledge of Petsc, the PCMG object is the main tool for general > multigrid calculations, as DMMG only works for simple constant matrix and > RHS.? But it's difficult to find any example code for using PCMG.? I checked > out the petsc-user mail archive on this topic but still not find a good > description on it.? I encounter similar errors in the practice as some > previous question-raisers did. > > Here is my simple code implementing the PCMG based on my understanding from > the user manual and tutorial.? It is supposed to have multigrid of only two > levels (finest and coarsest grid).? The error message indicates SEGV > segmentation violation because of this part of code.? Anything wrong with > this implementation? > > > ? 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); > > ? PCMGGetSmoother(pcmg, 0, &ksp); > ? PCMGGetSmoother(pcmg, 1, &ksp); > ? PCMGSetInterpolation(pcmg, 1, M); > ? PCMGSetRestriction(pcmg, 1, M); > > ? PCMGSetResidual(pcmg, 0, PCMGDefaultResidual, M); > ? PCMGSetResidual(pcmg, 1, PCMGDefaultResidual, M); > > > ?The mandatory remaining PCMGSetRhs( ), PCMGSetX( ) and PCMGSetR( ) > functions should be generated by Petsc automatically. > > It is tough to learn some Petsc functions when no detailed example and few > guidance is provided.? I wish you can add some tutorials codes on PCMG usage > in the future version of Petsc. > > > Thank you very much. > > > Zhisong Li > > > >
