1 #define PETSCKSP_DLL 2 3 /* 4 Defines the multigrid preconditioner interface. 5 */ 6 #include "src/ksp/pc/impls/mg/mgimpl.h" /*I "petscmg.h" I*/ 7 8 9 #undef __FUNCT__ 10 #define __FUNCT__ "PCMGMCycle_Private" 11 PetscErrorCode PCMGMCycle_Private(PC pc,PC_MG **mglevels,PetscTruth *converged) 12 { 13 PC_MG *mg = *mglevels,*mgc; 14 PetscErrorCode ierr; 15 PetscInt cycles = (PetscInt) mg->cycles; 16 17 PetscFunctionBegin; 18 if (converged) *converged = PETSC_FALSE; 19 20 if (mg->eventsmoothsolve) {ierr = PetscLogEventBegin(mg->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);} 21 ierr = KSPSolve(mg->smoothd,mg->b,mg->x);CHKERRQ(ierr); /* pre-smooth */ 22 if (mg->eventsmoothsolve) {ierr = PetscLogEventEnd(mg->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);} 23 if (mg->level) { /* not the coarsest grid */ 24 if (mg->eventresidual) {ierr = PetscLogEventBegin(mg->eventresidual,0,0,0,0);CHKERRQ(ierr);} 25 ierr = (*mg->residual)(mg->A,mg->b,mg->x,mg->r);CHKERRQ(ierr); 26 if (mg->eventresidual) {ierr = PetscLogEventEnd(mg->eventresidual,0,0,0,0);CHKERRQ(ierr);} 27 28 /* if on finest level and have convergence criteria set */ 29 if (mg->level == mg->levels-1 && mg->ttol) { 30 PetscReal rnorm; 31 ierr = VecNorm(mg->r,NORM_2,&rnorm);CHKERRQ(ierr); 32 if (rnorm <= mg->ttol) { 33 *converged = PETSC_TRUE; 34 if (rnorm < mg->abstol) { 35 ierr = PetscInfo2(pc,"Linear solver has converged. Residual norm %G is less than absolute tolerance %G\n",rnorm,mg->abstol);CHKERRQ(ierr); 36 } else { 37 ierr = PetscInfo2(pc,"Linear solver has converged. Residual norm %G is less than relative tolerance times initial residual norm %G\n",rnorm,mg->ttol);CHKERRQ(ierr); 38 } 39 PetscFunctionReturn(0); 40 } 41 } 42 43 mgc = *(mglevels - 1); 44 if (mg->eventinterprestrict) {ierr = PetscLogEventBegin(mg->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);} 45 ierr = MatRestrict(mg->restrct,mg->r,mgc->b);CHKERRQ(ierr); 46 if (mg->eventinterprestrict) {ierr = PetscLogEventEnd(mg->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);} 47 ierr = VecSet(mgc->x,0.0);CHKERRQ(ierr); 48 while (cycles--) { 49 ierr = PCMGMCycle_Private(pc,mglevels-1,converged);CHKERRQ(ierr); 50 } 51 if (mg->eventinterprestrict) {ierr = PetscLogEventBegin(mg->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);} 52 ierr = MatInterpolateAdd(mg->interpolate,mgc->x,mg->x,mg->x);CHKERRQ(ierr); 53 if (mg->eventinterprestrict) {ierr = PetscLogEventEnd(mg->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);} 54 if (mg->eventsmoothsolve) {ierr = PetscLogEventBegin(mg->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);} 55 ierr = KSPSolve(mg->smoothu,mg->b,mg->x);CHKERRQ(ierr); /* post smooth */ 56 if (mg->eventsmoothsolve) {ierr = PetscLogEventEnd(mg->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);} 57 } 58 PetscFunctionReturn(0); 59 } 60 61 /* 62 PCMGCreate_Private - Creates a PC_MG structure for use with the 63 multigrid code. Level 0 is the coarsest. (But the 64 finest level is stored first in the array). 65 66 */ 67 #undef __FUNCT__ 68 #define __FUNCT__ "PCMGCreate_Private" 69 static PetscErrorCode PCMGCreate_Private(MPI_Comm comm,PetscInt levels,PC pc,MPI_Comm *comms,PC_MG ***result) 70 { 71 PC_MG **mg; 72 PetscErrorCode ierr; 73 PetscInt i; 74 PetscMPIInt size; 75 const char *prefix; 76 PC ipc; 77 78 PetscFunctionBegin; 79 ierr = PetscMalloc(levels*sizeof(PC_MG*),&mg);CHKERRQ(ierr); 80 ierr = PetscLogObjectMemory(pc,levels*(sizeof(PC_MG*)));CHKERRQ(ierr); 81 82 ierr = PCGetOptionsPrefix(pc,&prefix);CHKERRQ(ierr); 83 84 for (i=0; i<levels; i++) { 85 ierr = PetscNewLog(pc,PC_MG,&mg[i]);CHKERRQ(ierr); 86 mg[i]->level = i; 87 mg[i]->levels = levels; 88 mg[i]->cycles = PC_MG_CYCLE_V; 89 mg[i]->galerkin = PETSC_FALSE; 90 mg[i]->galerkinused = PETSC_FALSE; 91 mg[i]->default_smoothu = 1; 92 mg[i]->default_smoothd = 1; 93 94 if (comms) comm = comms[i]; 95 ierr = KSPCreate(comm,&mg[i]->smoothd);CHKERRQ(ierr); 96 ierr = KSPSetTolerances(mg[i]->smoothd,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT, mg[i]->default_smoothd);CHKERRQ(ierr); 97 ierr = KSPSetOptionsPrefix(mg[i]->smoothd,prefix);CHKERRQ(ierr); 98 99 /* do special stuff for coarse grid */ 100 if (!i && levels > 1) { 101 ierr = KSPAppendOptionsPrefix(mg[0]->smoothd,"mg_coarse_");CHKERRQ(ierr); 102 103 /* coarse solve is (redundant) LU by default */ 104 ierr = KSPSetType(mg[0]->smoothd,KSPPREONLY);CHKERRQ(ierr); 105 ierr = KSPGetPC(mg[0]->smoothd,&ipc);CHKERRQ(ierr); 106 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 107 if (size > 1) { 108 ierr = PCSetType(ipc,PCREDUNDANT);CHKERRQ(ierr); 109 } else { 110 ierr = PCSetType(ipc,PCLU);CHKERRQ(ierr); 111 } 112 113 } else { 114 char tprefix[128]; 115 sprintf(tprefix,"mg_levels_%d_",(int)i); 116 ierr = KSPAppendOptionsPrefix(mg[i]->smoothd,tprefix);CHKERRQ(ierr); 117 } 118 ierr = PetscLogObjectParent(pc,mg[i]->smoothd);CHKERRQ(ierr); 119 mg[i]->smoothu = mg[i]->smoothd; 120 mg[i]->rtol = 0.0; 121 mg[i]->abstol = 0.0; 122 mg[i]->dtol = 0.0; 123 mg[i]->ttol = 0.0; 124 mg[i]->eventsmoothsetup = 0; 125 mg[i]->eventsmoothsolve = 0; 126 mg[i]->eventresidual = 0; 127 mg[i]->eventinterprestrict = 0; 128 mg[i]->cyclesperpcapply = 1; 129 } 130 *result = mg; 131 PetscFunctionReturn(0); 132 } 133 134 #undef __FUNCT__ 135 #define __FUNCT__ "PCDestroy_MG" 136 static PetscErrorCode PCDestroy_MG(PC pc) 137 { 138 PC_MG **mg = (PC_MG**)pc->data; 139 PetscErrorCode ierr; 140 PetscInt i,n; 141 142 PetscFunctionBegin; 143 if (!mg) PetscFunctionReturn(0); 144 n = mg[0]->levels; 145 for (i=0; i<n-1; i++) { 146 if (mg[i+1]->r) {ierr = VecDestroy(mg[i+1]->r);CHKERRQ(ierr);} 147 if (mg[i]->b) {ierr = VecDestroy(mg[i]->b);CHKERRQ(ierr);} 148 if (mg[i]->x) {ierr = VecDestroy(mg[i]->x);CHKERRQ(ierr);} 149 if (mg[i+1]->restrct) {ierr = MatDestroy(mg[i+1]->restrct);CHKERRQ(ierr);} 150 if (mg[i+1]->interpolate) {ierr = MatDestroy(mg[i+1]->interpolate);CHKERRQ(ierr);} 151 } 152 153 for (i=0; i<n; i++) { 154 if (mg[i]->smoothd != mg[i]->smoothu) { 155 ierr = KSPDestroy(mg[i]->smoothd);CHKERRQ(ierr); 156 } 157 ierr = KSPDestroy(mg[i]->smoothu);CHKERRQ(ierr); 158 ierr = PetscFree(mg[i]);CHKERRQ(ierr); 159 } 160 ierr = PetscFree(mg);CHKERRQ(ierr); 161 PetscFunctionReturn(0); 162 } 163 164 165 166 EXTERN PetscErrorCode PCMGACycle_Private(PC_MG**); 167 EXTERN PetscErrorCode PCMGFCycle_Private(PC,PC_MG**); 168 EXTERN PetscErrorCode PCMGKCycle_Private(PC_MG**); 169 170 /* 171 PCApply_MG - Runs either an additive, multiplicative, Kaskadic 172 or full cycle of multigrid. 173 174 Note: 175 A simple wrapper which calls PCMGMCycle(),PCMGACycle(), or PCMGFCycle(). 176 */ 177 #undef __FUNCT__ 178 #define __FUNCT__ "PCApply_MG" 179 static PetscErrorCode PCApply_MG(PC pc,Vec b,Vec x) 180 { 181 PC_MG **mg = (PC_MG**)pc->data; 182 PetscErrorCode ierr; 183 PetscInt levels = mg[0]->levels,i; 184 185 PetscFunctionBegin; 186 mg[levels-1]->b = b; 187 mg[levels-1]->x = x; 188 if (!mg[levels-1]->r && mg[0]->am != PC_MG_ADDITIVE && levels > 1) { 189 Vec tvec; 190 ierr = VecDuplicate(mg[levels-1]->b,&tvec);CHKERRQ(ierr); 191 ierr = PCMGSetR(pc,levels-1,tvec);CHKERRQ(ierr); 192 ierr = VecDestroy(tvec);CHKERRQ(ierr); 193 } 194 if (mg[0]->am == PC_MG_MULTIPLICATIVE) { 195 ierr = VecSet(x,0.0);CHKERRQ(ierr); 196 for (i=0; i<mg[0]->cyclesperpcapply; i++) { 197 ierr = PCMGMCycle_Private(pc,mg+levels-1,PETSC_NULL);CHKERRQ(ierr); 198 } 199 } 200 else if (mg[0]->am == PC_MG_ADDITIVE) { 201 ierr = PCMGACycle_Private(mg);CHKERRQ(ierr); 202 } 203 else if (mg[0]->am == PC_MG_KASKADE) { 204 ierr = PCMGKCycle_Private(mg);CHKERRQ(ierr); 205 } 206 else { 207 ierr = PCMGFCycle_Private(pc,mg);CHKERRQ(ierr); 208 } 209 PetscFunctionReturn(0); 210 } 211 212 #undef __FUNCT__ 213 #define __FUNCT__ "PCApplyRichardson_MG" 214 static PetscErrorCode PCApplyRichardson_MG(PC pc,Vec b,Vec x,Vec w,PetscReal rtol,PetscReal abstol, PetscReal dtol,PetscInt its) 215 { 216 PC_MG **mg = (PC_MG**)pc->data; 217 PetscErrorCode ierr; 218 PetscInt levels = mg[0]->levels; 219 PetscTruth converged = PETSC_FALSE; 220 221 PetscFunctionBegin; 222 mg[levels-1]->b = b; 223 mg[levels-1]->x = x; 224 225 mg[levels-1]->rtol = rtol; 226 mg[levels-1]->abstol = abstol; 227 mg[levels-1]->dtol = dtol; 228 if (rtol) { 229 /* compute initial residual norm for relative convergence test */ 230 PetscReal rnorm; 231 ierr = (*mg[levels-1]->residual)(mg[levels-1]->A,b,x,w);CHKERRQ(ierr); 232 ierr = VecNorm(w,NORM_2,&rnorm);CHKERRQ(ierr); 233 mg[levels-1]->ttol = PetscMax(rtol*rnorm,abstol); 234 } else if (abstol) { 235 mg[levels-1]->ttol = abstol; 236 } else { 237 mg[levels-1]->ttol = 0.0; 238 } 239 240 while (its-- && !converged) { 241 ierr = PCMGMCycle_Private(pc,mg+levels-1,&converged);CHKERRQ(ierr); 242 } 243 PetscFunctionReturn(0); 244 } 245 246 #undef __FUNCT__ 247 #define __FUNCT__ "PCSetFromOptions_MG" 248 PetscErrorCode PCSetFromOptions_MG(PC pc) 249 { 250 PetscErrorCode ierr; 251 PetscInt m,levels = 1,cycles; 252 PetscTruth flg; 253 PC_MG **mg = (PC_MG**)pc->data; 254 PCMGType mgtype = PC_MG_ADDITIVE; 255 PCMGCycleType mgctype; 256 257 PetscFunctionBegin; 258 ierr = PetscOptionsHead("Multigrid options");CHKERRQ(ierr); 259 if (!pc->data) { 260 ierr = PetscOptionsInt("-pc_mg_levels","Number of Levels","PCMGSetLevels",levels,&levels,&flg);CHKERRQ(ierr); 261 ierr = PCMGSetLevels(pc,levels,PETSC_NULL);CHKERRQ(ierr); 262 mg = (PC_MG**)pc->data; 263 } 264 mgctype = (PCMGCycleType) mg[0]->cycles; 265 ierr = PetscOptionsEnum("-pc_mg_cycle_type","V cycle or for W-cycle","PCMGSetCycleType",PCMGCycleTypes,(PetscEnum)mgctype,(PetscEnum*)&mgctype,&flg);CHKERRQ(ierr); 266 if (flg) { 267 ierr = PCMGSetCycleType(pc,mgctype);CHKERRQ(ierr); 268 }; 269 ierr = PetscOptionsName("-pc_mg_galerkin","Use Galerkin process to compute coarser operators","PCMGSetGalerkin",&flg);CHKERRQ(ierr); 270 if (flg) { 271 ierr = PCMGSetGalerkin(pc);CHKERRQ(ierr); 272 } 273 ierr = PetscOptionsInt("-pc_mg_smoothup","Number of post-smoothing steps","PCMGSetNumberSmoothUp",1,&m,&flg);CHKERRQ(ierr); 274 if (flg) { 275 ierr = PCMGSetNumberSmoothUp(pc,m);CHKERRQ(ierr); 276 } 277 ierr = PetscOptionsInt("-pc_mg_smoothdown","Number of pre-smoothing steps","PCMGSetNumberSmoothDown",1,&m,&flg);CHKERRQ(ierr); 278 if (flg) { 279 ierr = PCMGSetNumberSmoothDown(pc,m);CHKERRQ(ierr); 280 } 281 ierr = PetscOptionsEnum("-pc_mg_type","Multigrid type","PCMGSetType",PCMGTypes,(PetscEnum)mgtype,(PetscEnum*)&mgtype,&flg);CHKERRQ(ierr); 282 if (flg) { 283 ierr = PCMGSetType(pc,mgtype);CHKERRQ(ierr); 284 } 285 if (mg[0]->am == PC_MG_MULTIPLICATIVE) { 286 ierr = PetscOptionsInt("-pc_mg_multiplicative_cycles","Number of cycles for each preconditioner step","PCMGSetLevels",mg[0]->cyclesperpcapply,&cycles,&flg);CHKERRQ(ierr); 287 if (flg) { 288 ierr = PCMGMultiplicativeSetCycles(pc,cycles);CHKERRQ(ierr); 289 } 290 } 291 ierr = PetscOptionsName("-pc_mg_log","Log times for each multigrid level","None",&flg);CHKERRQ(ierr); 292 if (flg) { 293 PetscInt i; 294 char eventname[128]; 295 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 296 levels = mg[0]->levels; 297 for (i=0; i<levels; i++) { 298 sprintf(eventname,"MGSetup Level %d",(int)i); 299 ierr = PetscLogEventRegister(eventname,((PetscObject)pc)->cookie,&mg[i]->eventsmoothsetup);CHKERRQ(ierr); 300 sprintf(eventname,"MGSmooth Level %d",(int)i); 301 ierr = PetscLogEventRegister(eventname,((PetscObject)pc)->cookie,&mg[i]->eventsmoothsolve);CHKERRQ(ierr); 302 if (i) { 303 sprintf(eventname,"MGResid Level %d",(int)i); 304 ierr = PetscLogEventRegister(eventname,((PetscObject)pc)->cookie,&mg[i]->eventresidual);CHKERRQ(ierr); 305 sprintf(eventname,"MGInterp Level %d",(int)i); 306 ierr = PetscLogEventRegister(eventname,((PetscObject)pc)->cookie,&mg[i]->eventinterprestrict);CHKERRQ(ierr); 307 } 308 } 309 } 310 ierr = PetscOptionsTail();CHKERRQ(ierr); 311 PetscFunctionReturn(0); 312 } 313 314 const char *PCMGTypes[] = {"MULTIPLICATIVE","ADDITIVE","FULL","KASKADE","PCMGType","PC_MG",0}; 315 const char *PCMGCycleTypes[] = {"invalid","v","w","PCMGCycleType","PC_MG_CYCLE",0}; 316 317 #undef __FUNCT__ 318 #define __FUNCT__ "PCView_MG" 319 static PetscErrorCode PCView_MG(PC pc,PetscViewer viewer) 320 { 321 PC_MG **mg = (PC_MG**)pc->data; 322 PetscErrorCode ierr; 323 PetscInt levels = mg[0]->levels,i; 324 PetscTruth iascii; 325 326 PetscFunctionBegin; 327 ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); 328 if (iascii) { 329 ierr = PetscViewerASCIIPrintf(viewer," MG: type is %s, levels=%D cycles=%s\n", PCMGTypes[mg[0]->am],levels,(mg[0]->cycles == PC_MG_CYCLE_V) ? "v" : "w");CHKERRQ(ierr); 330 if (mg[0]->am == PC_MG_MULTIPLICATIVE) { 331 ierr = PetscViewerASCIIPrintf(viewer," Cycles per PCApply=%d\n",mg[0]->cyclesperpcapply);CHKERRQ(ierr); 332 } 333 if (mg[0]->galerkin) { 334 ierr = PetscViewerASCIIPrintf(viewer," Using Galerkin computed coarse grid matrices\n");CHKERRQ(ierr); 335 } 336 for (i=0; i<levels; i++) { 337 if (!i) { 338 ierr = PetscViewerASCIIPrintf(viewer,"Coarse gride solver -- level %D presmooths=%D postsmooths=%D -----\n",i,mg[0]->default_smoothd,mg[0]->default_smoothu);CHKERRQ(ierr); 339 } else { 340 ierr = PetscViewerASCIIPrintf(viewer,"Down solver (pre-smoother) on level %D smooths=%D --------------------\n",i,mg[i]->default_smoothd);CHKERRQ(ierr); 341 } 342 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 343 ierr = KSPView(mg[i]->smoothd,viewer);CHKERRQ(ierr); 344 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 345 if (i && mg[i]->smoothd == mg[i]->smoothu) { 346 ierr = PetscViewerASCIIPrintf(viewer,"Up solver (post-smoother) same as down solver (pre-smoother)\n");CHKERRQ(ierr); 347 } else if (i){ 348 ierr = PetscViewerASCIIPrintf(viewer,"Up solver (post-smoother) on level %D smooths=%D --------------------\n",i,mg[i]->default_smoothu);CHKERRQ(ierr); 349 ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 350 ierr = KSPView(mg[i]->smoothu,viewer);CHKERRQ(ierr); 351 ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 352 } 353 } 354 } else { 355 SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for PCMG",((PetscObject)viewer)->type_name); 356 } 357 PetscFunctionReturn(0); 358 } 359 360 /* 361 Calls setup for the KSP on each level 362 */ 363 #undef __FUNCT__ 364 #define __FUNCT__ "PCSetUp_MG" 365 static PetscErrorCode PCSetUp_MG(PC pc) 366 { 367 PC_MG **mg = (PC_MG**)pc->data; 368 PetscErrorCode ierr; 369 PetscInt i,n = mg[0]->levels; 370 PC cpc,mpc; 371 PetscTruth preonly,lu,redundant,cholesky,monitor = PETSC_FALSE,dump,opsset; 372 PetscViewerASCIIMonitor ascii; 373 PetscViewer viewer = PETSC_NULL; 374 MPI_Comm comm; 375 Mat dA,dB; 376 MatStructure uflag; 377 Vec tvec; 378 379 PetscFunctionBegin; 380 381 /* If user did not provide fine grid operators OR operator was not updated since last global KSPSetOperators() */ 382 /* so use those from global PC */ 383 /* Is this what we always want? What if user wants to keep old one? */ 384 ierr = KSPGetOperatorsSet(mg[n-1]->smoothd,PETSC_NULL,&opsset);CHKERRQ(ierr); 385 ierr = KSPGetPC(mg[0]->smoothd,&cpc);CHKERRQ(ierr); 386 ierr = KSPGetPC(mg[n-1]->smoothd,&mpc);CHKERRQ(ierr); 387 if (!opsset || ((cpc->setupcalled == 1) && (mpc->setupcalled == 2))) { 388 ierr = PetscInfo(pc,"Using outer operators to define finest grid operator \n because PCMGGetSmoother(pc,nlevels-1,&ksp);KSPSetOperators(ksp,...); was not called.\n");CHKERRQ(ierr); 389 ierr = KSPSetOperators(mg[n-1]->smoothd,pc->mat,pc->pmat,pc->flag);CHKERRQ(ierr); 390 } 391 392 if (mg[0]->galerkin) { 393 Mat B; 394 mg[0]->galerkinused = PETSC_TRUE; 395 /* currently only handle case where mat and pmat are the same on coarser levels */ 396 ierr = KSPGetOperators(mg[n-1]->smoothd,&dA,&dB,&uflag);CHKERRQ(ierr); 397 if (!pc->setupcalled) { 398 for (i=n-2; i>-1; i--) { 399 ierr = MatPtAP(dB,mg[i+1]->interpolate,MAT_INITIAL_MATRIX,1.0,&B);CHKERRQ(ierr); 400 ierr = KSPSetOperators(mg[i]->smoothd,B,B,uflag);CHKERRQ(ierr); 401 if (i != n-2) {ierr = PetscObjectDereference((PetscObject)dB);CHKERRQ(ierr);} 402 dB = B; 403 } 404 ierr = PetscObjectDereference((PetscObject)dB);CHKERRQ(ierr); 405 } else { 406 for (i=n-2; i>-1; i--) { 407 ierr = KSPGetOperators(mg[i]->smoothd,PETSC_NULL,&B,PETSC_NULL);CHKERRQ(ierr); 408 ierr = MatPtAP(dB,mg[i+1]->interpolate,MAT_REUSE_MATRIX,1.0,&B);CHKERRQ(ierr); 409 ierr = KSPSetOperators(mg[i]->smoothd,B,B,uflag);CHKERRQ(ierr); 410 dB = B; 411 } 412 } 413 } 414 415 if (!pc->setupcalled) { 416 ierr = PetscOptionsHasName(0,"-pc_mg_monitor",&monitor);CHKERRQ(ierr); 417 418 for (i=0; i<n; i++) { 419 if (monitor) { 420 ierr = PetscObjectGetComm((PetscObject)mg[i]->smoothd,&comm);CHKERRQ(ierr); 421 ierr = PetscViewerASCIIMonitorCreate(comm,"stdout",n-i,&ascii);CHKERRQ(ierr); 422 ierr = KSPMonitorSet(mg[i]->smoothd,KSPMonitorDefault,ascii,(PetscErrorCode(*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr); 423 } 424 ierr = KSPSetFromOptions(mg[i]->smoothd);CHKERRQ(ierr); 425 } 426 for (i=1; i<n; i++) { 427 if (mg[i]->smoothu && (mg[i]->smoothu != mg[i]->smoothd)) { 428 if (monitor) { 429 ierr = PetscObjectGetComm((PetscObject)mg[i]->smoothu,&comm);CHKERRQ(ierr); 430 ierr = PetscViewerASCIIMonitorCreate(comm,"stdout",n-i,&ascii);CHKERRQ(ierr); 431 ierr = KSPMonitorSet(mg[i]->smoothu,KSPMonitorDefault,ascii,(PetscErrorCode(*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr); 432 } 433 ierr = KSPSetFromOptions(mg[i]->smoothu);CHKERRQ(ierr); 434 } 435 } 436 for (i=1; i<n; i++) { 437 if (!mg[i]->residual) { 438 Mat mat; 439 ierr = KSPGetOperators(mg[i]->smoothd,PETSC_NULL,&mat,PETSC_NULL);CHKERRQ(ierr); 440 ierr = PCMGSetResidual(pc,i,PCMGDefaultResidual,mat);CHKERRQ(ierr); 441 } 442 if (mg[i]->restrct && !mg[i]->interpolate) { 443 ierr = PCMGSetInterpolation(pc,i,mg[i]->restrct);CHKERRQ(ierr); 444 } 445 if (!mg[i]->restrct && mg[i]->interpolate) { 446 ierr = PCMGSetRestriction(pc,i,mg[i]->interpolate);CHKERRQ(ierr); 447 } 448 #if defined(PETSC_USE_DEBUG) 449 if (!mg[i]->restrct || !mg[i]->interpolate) { 450 SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Need to set restriction or interpolation on level %d",(int)i); 451 } 452 #endif 453 } 454 for (i=0; i<n-1; i++) { 455 if (!mg[i]->b) { 456 Vec *vec; 457 ierr = KSPGetVecs(mg[i]->smoothd,1,&vec,0,PETSC_NULL);CHKERRQ(ierr); 458 ierr = PCMGSetRhs(pc,i,*vec);CHKERRQ(ierr); 459 ierr = VecDestroy(*vec);CHKERRQ(ierr); 460 ierr = PetscFree(vec);CHKERRQ(ierr); 461 } 462 if (!mg[i]->r && i) { 463 ierr = VecDuplicate(mg[i]->b,&tvec);CHKERRQ(ierr); 464 ierr = PCMGSetR(pc,i,tvec);CHKERRQ(ierr); 465 ierr = VecDestroy(tvec);CHKERRQ(ierr); 466 } 467 if (!mg[i]->x) { 468 ierr = VecDuplicate(mg[i]->b,&tvec);CHKERRQ(ierr); 469 ierr = PCMGSetX(pc,i,tvec);CHKERRQ(ierr); 470 ierr = VecDestroy(tvec);CHKERRQ(ierr); 471 } 472 } 473 if (n != 1 && !mg[n-1]->r) { 474 /* PCMGSetR() on the finest level if user did not supply it */ 475 Vec *vec; 476 ierr = KSPGetVecs(mg[n-1]->smoothd,1,&vec,0,PETSC_NULL);CHKERRQ(ierr); 477 ierr = PCMGSetR(pc,n-1,*vec);CHKERRQ(ierr); 478 ierr = VecDestroy(*vec);CHKERRQ(ierr); 479 ierr = PetscFree(vec);CHKERRQ(ierr); 480 } 481 } 482 483 484 for (i=1; i<n; i++) { 485 if (mg[i]->smoothu == mg[i]->smoothd) { 486 /* if doing only down then initial guess is zero */ 487 ierr = KSPSetInitialGuessNonzero(mg[i]->smoothd,PETSC_TRUE);CHKERRQ(ierr); 488 } 489 if (mg[i]->eventsmoothsetup) {ierr = PetscLogEventBegin(mg[i]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 490 ierr = KSPSetUp(mg[i]->smoothd);CHKERRQ(ierr); 491 if (mg[i]->eventsmoothsetup) {ierr = PetscLogEventEnd(mg[i]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 492 } 493 for (i=1; i<n; i++) { 494 if (mg[i]->smoothu && mg[i]->smoothu != mg[i]->smoothd) { 495 Mat downmat,downpmat; 496 MatStructure matflag; 497 PetscTruth opsset; 498 499 /* check if operators have been set for up, if not use down operators to set them */ 500 ierr = KSPGetOperatorsSet(mg[i]->smoothu,&opsset,PETSC_NULL);CHKERRQ(ierr); 501 if (!opsset) { 502 ierr = KSPGetOperators(mg[i]->smoothd,&downmat,&downpmat,&matflag);CHKERRQ(ierr); 503 ierr = KSPSetOperators(mg[i]->smoothu,downmat,downpmat,matflag);CHKERRQ(ierr); 504 } 505 506 ierr = KSPSetInitialGuessNonzero(mg[i]->smoothu,PETSC_TRUE);CHKERRQ(ierr); 507 if (mg[i]->eventsmoothsetup) {ierr = PetscLogEventBegin(mg[i]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 508 ierr = KSPSetUp(mg[i]->smoothu);CHKERRQ(ierr); 509 if (mg[i]->eventsmoothsetup) {ierr = PetscLogEventEnd(mg[i]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 510 } 511 } 512 513 /* 514 If coarse solver is not direct method then DO NOT USE preonly 515 */ 516 ierr = PetscTypeCompare((PetscObject)mg[0]->smoothd,KSPPREONLY,&preonly);CHKERRQ(ierr); 517 if (preonly) { 518 ierr = PetscTypeCompare((PetscObject)cpc,PCLU,&lu);CHKERRQ(ierr); 519 ierr = PetscTypeCompare((PetscObject)cpc,PCREDUNDANT,&redundant);CHKERRQ(ierr); 520 ierr = PetscTypeCompare((PetscObject)cpc,PCCHOLESKY,&cholesky);CHKERRQ(ierr); 521 if (!lu && !redundant && !cholesky) { 522 ierr = KSPSetType(mg[0]->smoothd,KSPGMRES);CHKERRQ(ierr); 523 } 524 } 525 526 if (!pc->setupcalled) { 527 if (monitor) { 528 ierr = PetscObjectGetComm((PetscObject)mg[0]->smoothd,&comm);CHKERRQ(ierr); 529 ierr = PetscViewerASCIIMonitorCreate(comm,"stdout",n,&ascii);CHKERRQ(ierr); 530 ierr = KSPMonitorSet(mg[0]->smoothd,KSPMonitorDefault,ascii,(PetscErrorCode(*)(void*))PetscViewerASCIIMonitorDestroy);CHKERRQ(ierr); 531 } 532 ierr = KSPSetFromOptions(mg[0]->smoothd);CHKERRQ(ierr); 533 } 534 535 if (mg[0]->eventsmoothsetup) {ierr = PetscLogEventBegin(mg[0]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 536 ierr = KSPSetUp(mg[0]->smoothd);CHKERRQ(ierr); 537 if (mg[0]->eventsmoothsetup) {ierr = PetscLogEventEnd(mg[0]->eventsmoothsetup,0,0,0,0);CHKERRQ(ierr);} 538 539 /* 540 Dump the interpolation/restriction matrices plus the 541 Jacobian/stiffness on each level. This allows Matlab users to 542 easily check if the Galerkin condition A_c = R A_f R^T is satisfied. 543 544 Only support one or the other at the same time. 545 */ 546 #if defined(PETSC_USE_SOCKET_VIEWER) 547 ierr = PetscOptionsHasName(((PetscObject)pc)->prefix,"-pc_mg_dump_matlab",&dump);CHKERRQ(ierr); 548 if (dump) { 549 viewer = PETSC_VIEWER_SOCKET_(((PetscObject)pc)->comm); 550 } 551 #endif 552 ierr = PetscOptionsHasName(((PetscObject)pc)->prefix,"-pc_mg_dump_binary",&dump);CHKERRQ(ierr); 553 if (dump) { 554 viewer = PETSC_VIEWER_BINARY_(((PetscObject)pc)->comm); 555 } 556 557 if (viewer) { 558 for (i=1; i<n; i++) { 559 ierr = MatView(mg[i]->restrct,viewer);CHKERRQ(ierr); 560 } 561 for (i=0; i<n; i++) { 562 ierr = KSPGetPC(mg[i]->smoothd,&pc);CHKERRQ(ierr); 563 ierr = MatView(pc->mat,viewer);CHKERRQ(ierr); 564 } 565 } 566 PetscFunctionReturn(0); 567 } 568 569 /* -------------------------------------------------------------------------------------*/ 570 571 #undef __FUNCT__ 572 #define __FUNCT__ "PCMGSetLevels" 573 /*@C 574 PCMGSetLevels - Sets the number of levels to use with MG. 575 Must be called before any other MG routine. 576 577 Collective on PC 578 579 Input Parameters: 580 + pc - the preconditioner context 581 . levels - the number of levels 582 - comms - optional communicators for each level; this is to allow solving the coarser problems 583 on smaller sets of processors. Use PETSC_NULL_OBJECT for default in Fortran 584 585 Level: intermediate 586 587 Notes: 588 If the number of levels is one then the multigrid uses the -mg_levels prefix 589 for setting the level options rather than the -mg_coarse prefix. 590 591 .keywords: MG, set, levels, multigrid 592 593 .seealso: PCMGSetType(), PCMGGetLevels() 594 @*/ 595 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetLevels(PC pc,PetscInt levels,MPI_Comm *comms) 596 { 597 PetscErrorCode ierr; 598 PC_MG **mg=0; 599 600 PetscFunctionBegin; 601 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 602 603 if (pc->data) { 604 SETERRQ(PETSC_ERR_ORDER,"Number levels already set for MG\n\ 605 make sure that you call PCMGSetLevels() before KSPSetFromOptions()"); 606 } 607 ierr = PCMGCreate_Private(((PetscObject)pc)->comm,levels,pc,comms,&mg);CHKERRQ(ierr); 608 mg[0]->am = PC_MG_MULTIPLICATIVE; 609 pc->data = (void*)mg; 610 pc->ops->applyrichardson = PCApplyRichardson_MG; 611 PetscFunctionReturn(0); 612 } 613 614 #undef __FUNCT__ 615 #define __FUNCT__ "PCMGGetLevels" 616 /*@ 617 PCMGGetLevels - Gets the number of levels to use with MG. 618 619 Not Collective 620 621 Input Parameter: 622 . pc - the preconditioner context 623 624 Output parameter: 625 . levels - the number of levels 626 627 Level: advanced 628 629 .keywords: MG, get, levels, multigrid 630 631 .seealso: PCMGSetLevels() 632 @*/ 633 PetscErrorCode PETSCKSP_DLLEXPORT PCMGGetLevels(PC pc,PetscInt *levels) 634 { 635 PC_MG **mg; 636 637 PetscFunctionBegin; 638 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 639 PetscValidIntPointer(levels,2); 640 641 mg = (PC_MG**)pc->data; 642 *levels = mg[0]->levels; 643 PetscFunctionReturn(0); 644 } 645 646 #undef __FUNCT__ 647 #define __FUNCT__ "PCMGSetType" 648 /*@ 649 PCMGSetType - Determines the form of multigrid to use: 650 multiplicative, additive, full, or the Kaskade algorithm. 651 652 Collective on PC 653 654 Input Parameters: 655 + pc - the preconditioner context 656 - form - multigrid form, one of PC_MG_MULTIPLICATIVE, PC_MG_ADDITIVE, 657 PC_MG_FULL, PC_MG_KASKADE 658 659 Options Database Key: 660 . -pc_mg_type <form> - Sets <form>, one of multiplicative, 661 additive, full, kaskade 662 663 Level: advanced 664 665 .keywords: MG, set, method, multiplicative, additive, full, Kaskade, multigrid 666 667 .seealso: PCMGSetLevels() 668 @*/ 669 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetType(PC pc,PCMGType form) 670 { 671 PC_MG **mg; 672 673 PetscFunctionBegin; 674 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 675 mg = (PC_MG**)pc->data; 676 677 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 678 mg[0]->am = form; 679 if (form == PC_MG_MULTIPLICATIVE) pc->ops->applyrichardson = PCApplyRichardson_MG; 680 else pc->ops->applyrichardson = 0; 681 PetscFunctionReturn(0); 682 } 683 684 #undef __FUNCT__ 685 #define __FUNCT__ "PCMGSetCycleType" 686 /*@ 687 PCMGSetCycleType - Sets the type cycles to use. Use PCMGSetCycleTypeOnLevel() for more 688 complicated cycling. 689 690 Collective on PC 691 692 Input Parameters: 693 + pc - the multigrid context 694 - PC_MG_CYCLE_V or PC_MG_CYCLE_W 695 696 Options Database Key: 697 $ -pc_mg_cycle_type v or w 698 699 Level: advanced 700 701 .keywords: MG, set, cycles, V-cycle, W-cycle, multigrid 702 703 .seealso: PCMGSetCycleTypeOnLevel() 704 @*/ 705 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetCycleType(PC pc,PCMGCycleType n) 706 { 707 PC_MG **mg; 708 PetscInt i,levels; 709 710 PetscFunctionBegin; 711 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 712 mg = (PC_MG**)pc->data; 713 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 714 levels = mg[0]->levels; 715 716 for (i=0; i<levels; i++) { 717 mg[i]->cycles = n; 718 } 719 PetscFunctionReturn(0); 720 } 721 722 #undef __FUNCT__ 723 #define __FUNCT__ "PCMGMultiplicativeSetCycles" 724 /*@ 725 PCMGMultiplicativeSetCycles - Sets the number of cycles to use for each preconditioner step 726 of multigrid when PCMGType of PC_MG_MULTIPLICATIVE is used 727 728 Collective on PC 729 730 Input Parameters: 731 + pc - the multigrid context 732 - n - number of cycles (default is 1) 733 734 Options Database Key: 735 $ -pc_mg_multiplicative_cycles n 736 737 Level: advanced 738 739 Notes: This is not associated with setting a v or w cycle, that is set with PCMGSetCycleType() 740 741 .keywords: MG, set, cycles, V-cycle, W-cycle, multigrid 742 743 .seealso: PCMGSetCycleTypeOnLevel(), PCMGSetCycleType() 744 @*/ 745 PetscErrorCode PETSCKSP_DLLEXPORT PCMGMultiplicativeSetCycles(PC pc,PetscInt n) 746 { 747 PC_MG **mg; 748 PetscInt i,levels; 749 750 PetscFunctionBegin; 751 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 752 mg = (PC_MG**)pc->data; 753 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 754 levels = mg[0]->levels; 755 756 for (i=0; i<levels; i++) { 757 mg[i]->cyclesperpcapply = n; 758 } 759 PetscFunctionReturn(0); 760 } 761 762 #undef __FUNCT__ 763 #define __FUNCT__ "PCMGSetGalerkin" 764 /*@ 765 PCMGSetGalerkin - Causes the coarser grid matrices to be computed from the 766 finest grid via the Galerkin process: A_i-1 = r_i * A_i * r_i^t 767 768 Collective on PC 769 770 Input Parameters: 771 . pc - the multigrid context 772 773 Options Database Key: 774 $ -pc_mg_galerkin 775 776 Level: intermediate 777 778 .keywords: MG, set, Galerkin 779 780 .seealso: PCMGGetGalerkin() 781 782 @*/ 783 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetGalerkin(PC pc) 784 { 785 PC_MG **mg; 786 PetscInt i,levels; 787 788 PetscFunctionBegin; 789 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 790 mg = (PC_MG**)pc->data; 791 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 792 levels = mg[0]->levels; 793 794 for (i=0; i<levels; i++) { 795 mg[i]->galerkin = PETSC_TRUE; 796 } 797 PetscFunctionReturn(0); 798 } 799 800 #undef __FUNCT__ 801 #define __FUNCT__ "PCMGGetGalerkin" 802 /*@ 803 PCMGGetGalerkin - Checks if Galerkin multigrid is being used, i.e. 804 A_i-1 = r_i * A_i * r_i^t 805 806 Not Collective 807 808 Input Parameter: 809 . pc - the multigrid context 810 811 Output Parameter: 812 . gelerkin - PETSC_TRUE or PETSC_FALSE 813 814 Options Database Key: 815 $ -pc_mg_galerkin 816 817 Level: intermediate 818 819 .keywords: MG, set, Galerkin 820 821 .seealso: PCMGSetGalerkin() 822 823 @*/ 824 PetscErrorCode PETSCKSP_DLLEXPORT PCMGGetGalerkin(PC pc,PetscTruth *galerkin) 825 { 826 PC_MG **mg; 827 828 PetscFunctionBegin; 829 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 830 mg = (PC_MG**)pc->data; 831 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 832 *galerkin = mg[0]->galerkin; 833 PetscFunctionReturn(0); 834 } 835 836 #undef __FUNCT__ 837 #define __FUNCT__ "PCMGSetNumberSmoothDown" 838 /*@ 839 PCMGSetNumberSmoothDown - Sets the number of pre-smoothing steps to 840 use on all levels. Use PCMGGetSmootherDown() to set different 841 pre-smoothing steps on different levels. 842 843 Collective on PC 844 845 Input Parameters: 846 + mg - the multigrid context 847 - n - the number of smoothing steps 848 849 Options Database Key: 850 . -pc_mg_smoothdown <n> - Sets number of pre-smoothing steps 851 852 Level: advanced 853 854 .keywords: MG, smooth, down, pre-smoothing, steps, multigrid 855 856 .seealso: PCMGSetNumberSmoothUp() 857 @*/ 858 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetNumberSmoothDown(PC pc,PetscInt n) 859 { 860 PC_MG **mg; 861 PetscErrorCode ierr; 862 PetscInt i,levels; 863 864 PetscFunctionBegin; 865 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 866 mg = (PC_MG**)pc->data; 867 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 868 levels = mg[0]->levels; 869 870 for (i=1; i<levels; i++) { 871 /* make sure smoother up and down are different */ 872 ierr = PCMGGetSmootherUp(pc,i,PETSC_NULL);CHKERRQ(ierr); 873 ierr = KSPSetTolerances(mg[i]->smoothd,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT,n);CHKERRQ(ierr); 874 mg[i]->default_smoothd = n; 875 } 876 PetscFunctionReturn(0); 877 } 878 879 #undef __FUNCT__ 880 #define __FUNCT__ "PCMGSetNumberSmoothUp" 881 /*@ 882 PCMGSetNumberSmoothUp - Sets the number of post-smoothing steps to use 883 on all levels. Use PCMGGetSmootherUp() to set different numbers of 884 post-smoothing steps on different levels. 885 886 Collective on PC 887 888 Input Parameters: 889 + mg - the multigrid context 890 - n - the number of smoothing steps 891 892 Options Database Key: 893 . -pc_mg_smoothup <n> - Sets number of post-smoothing steps 894 895 Level: advanced 896 897 Note: this does not set a value on the coarsest grid, since we assume that 898 there is no separate smooth up on the coarsest grid. 899 900 .keywords: MG, smooth, up, post-smoothing, steps, multigrid 901 902 .seealso: PCMGSetNumberSmoothDown() 903 @*/ 904 PetscErrorCode PETSCKSP_DLLEXPORT PCMGSetNumberSmoothUp(PC pc,PetscInt n) 905 { 906 PC_MG **mg; 907 PetscErrorCode ierr; 908 PetscInt i,levels; 909 910 PetscFunctionBegin; 911 PetscValidHeaderSpecific(pc,PC_COOKIE,1); 912 mg = (PC_MG**)pc->data; 913 if (!mg) SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must set MG levels before calling"); 914 levels = mg[0]->levels; 915 916 for (i=1; i<levels; i++) { 917 /* make sure smoother up and down are different */ 918 ierr = PCMGGetSmootherUp(pc,i,PETSC_NULL);CHKERRQ(ierr); 919 ierr = KSPSetTolerances(mg[i]->smoothu,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT,n);CHKERRQ(ierr); 920 mg[i]->default_smoothu = n; 921 } 922 PetscFunctionReturn(0); 923 } 924 925 /* ----------------------------------------------------------------------------------------*/ 926 927 /*MC 928 PCMG - Use multigrid preconditioning. This preconditioner requires you provide additional 929 information about the coarser grid matrices and restriction/interpolation operators. 930 931 Options Database Keys: 932 + -pc_mg_levels <nlevels> - number of levels including finest 933 . -pc_mg_cycles v or w 934 . -pc_mg_smoothup <n> - number of smoothing steps after interpolation 935 . -pc_mg_smoothdown <n> - number of smoothing steps before applying restriction operator 936 . -pc_mg_type <additive,multiplicative,full,cascade> - multiplicative is the default 937 . -pc_mg_log - log information about time spent on each level of the solver 938 . -pc_mg_monitor - print information on the multigrid convergence 939 . -pc_mg_galerkin - use Galerkin process to compute coarser operators 940 - -pc_mg_dump_matlab - dumps the matrices for each level and the restriction/interpolation matrices 941 to the Socket viewer for reading from Matlab. 942 943 Notes: 944 945 Level: intermediate 946 947 Concepts: multigrid/multilevel 948 949 .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, PCMGType, 950 PCMGSetLevels(), PCMGGetLevels(), PCMGSetType(), PCMGSetCycleType(), PCMGSetNumberSmoothDown(), 951 PCMGSetNumberSmoothUp(), PCMGGetCoarseSolve(), PCMGSetResidual(), PCMGSetInterpolation(), 952 PCMGSetRestriction(), PCMGGetSmoother(), PCMGGetSmootherUp(), PCMGGetSmootherDown(), 953 PCMGSetCycleTypeOnLevel(), PCMGSetRhs(), PCMGSetX(), PCMGSetR() 954 M*/ 955 956 EXTERN_C_BEGIN 957 #undef __FUNCT__ 958 #define __FUNCT__ "PCCreate_MG" 959 PetscErrorCode PETSCKSP_DLLEXPORT PCCreate_MG(PC pc) 960 { 961 PetscFunctionBegin; 962 pc->ops->apply = PCApply_MG; 963 pc->ops->setup = PCSetUp_MG; 964 pc->ops->destroy = PCDestroy_MG; 965 pc->ops->setfromoptions = PCSetFromOptions_MG; 966 pc->ops->view = PCView_MG; 967 968 pc->data = (void*)0; 969 PetscFunctionReturn(0); 970 } 971 EXTERN_C_END 972