1 2 #include <petsc/private/matimpl.h> 3 #include <petsc/private/pcimpl.h> 4 #include <petsc/private/dmimpl.h> 5 #include <petscksp.h> /*I "petscksp.h" I*/ 6 #include <petscdm.h> 7 #include <petscdmda.h> 8 #include <petscdmshell.h> 9 10 #include "../src/ksp/pc/impls/telescope/telescope.h" 11 12 static PetscBool cited = PETSC_FALSE; 13 static const char citation[] = 14 "@inproceedings{MaySananRuppKnepleySmith2016,\n" 15 " title = {Extreme-Scale Multigrid Components within PETSc},\n" 16 " author = {Dave A. May and Patrick Sanan and Karl Rupp and Matthew G. Knepley and Barry F. Smith},\n" 17 " booktitle = {Proceedings of the Platform for Advanced Scientific Computing Conference},\n" 18 " series = {PASC '16},\n" 19 " isbn = {978-1-4503-4126-4},\n" 20 " location = {Lausanne, Switzerland},\n" 21 " pages = {5:1--5:12},\n" 22 " articleno = {5},\n" 23 " numpages = {12},\n" 24 " url = {http://doi.acm.org/10.1145/2929908.2929913},\n" 25 " doi = {10.1145/2929908.2929913},\n" 26 " acmid = {2929913},\n" 27 " publisher = {ACM},\n" 28 " address = {New York, NY, USA},\n" 29 " keywords = {GPU, HPC, agglomeration, coarse-level solver, multigrid, parallel computing, preconditioning},\n" 30 " year = {2016}\n" 31 "}\n"; 32 33 typedef struct { 34 DM dm_fine,dm_coarse; /* these DM's should be topologically identical but use different communicators */ 35 Mat permutation; 36 Vec xp; 37 PetscErrorCode (*fp_dm_field_scatter)(DM,Vec,ScatterMode,DM,Vec); 38 PetscErrorCode (*fp_dm_state_scatter)(DM,ScatterMode,DM); 39 void *dmksp_context_determined; 40 void *dmksp_context_user; 41 } PC_Telescope_CoarseDMCtx; 42 43 44 PetscErrorCode PCTelescopeSetUp_scatters_CoarseDM(PC pc,PC_Telescope sred,PC_Telescope_CoarseDMCtx *ctx) 45 { 46 PetscErrorCode ierr; 47 Vec xred,yred,xtmp,x,xp; 48 VecScatter scatter; 49 IS isin; 50 Mat B; 51 PetscInt m,bs,st,ed; 52 MPI_Comm comm; 53 54 PetscFunctionBegin; 55 ierr = PetscObjectGetComm((PetscObject)pc,&comm);CHKERRQ(ierr); 56 ierr = PCGetOperators(pc,NULL,&B);CHKERRQ(ierr); 57 ierr = MatCreateVecs(B,&x,NULL);CHKERRQ(ierr); 58 ierr = MatGetBlockSize(B,&bs);CHKERRQ(ierr); 59 ierr = VecDuplicate(x,&xp);CHKERRQ(ierr); 60 m = 0; 61 xred = NULL; 62 yred = NULL; 63 if (isActiveRank(sred)) { 64 ierr = DMCreateGlobalVector(ctx->dm_coarse,&xred);CHKERRQ(ierr); 65 ierr = VecDuplicate(xred,&yred);CHKERRQ(ierr); 66 ierr = VecGetOwnershipRange(xred,&st,&ed);CHKERRQ(ierr); 67 ierr = ISCreateStride(comm,ed-st,st,1,&isin);CHKERRQ(ierr); 68 ierr = VecGetLocalSize(xred,&m);CHKERRQ(ierr); 69 } else { 70 ierr = VecGetOwnershipRange(x,&st,&ed);CHKERRQ(ierr); 71 ierr = ISCreateStride(comm,0,st,1,&isin);CHKERRQ(ierr); 72 } 73 ierr = ISSetBlockSize(isin,bs);CHKERRQ(ierr); 74 ierr = VecCreate(comm,&xtmp);CHKERRQ(ierr); 75 ierr = VecSetSizes(xtmp,m,PETSC_DECIDE);CHKERRQ(ierr); 76 ierr = VecSetBlockSize(xtmp,bs);CHKERRQ(ierr); 77 ierr = VecSetType(xtmp,((PetscObject)x)->type_name);CHKERRQ(ierr); 78 ierr = VecScatterCreateWithData(x,isin,xtmp,NULL,&scatter);CHKERRQ(ierr); 79 sred->xred = xred; 80 sred->yred = yred; 81 sred->isin = isin; 82 sred->scatter = scatter; 83 sred->xtmp = xtmp; 84 85 ctx->xp = xp; 86 ierr = VecDestroy(&x);CHKERRQ(ierr); 87 PetscFunctionReturn(0); 88 } 89 90 PetscErrorCode PCTelescopeSetUp_CoarseDM(PC pc,PC_Telescope sred) 91 { 92 PC_Telescope_CoarseDMCtx *ctx; 93 DM dm,dm_coarse = NULL; 94 MPI_Comm comm; 95 PetscBool has_perm,has_kspcomputeoperators,using_kspcomputeoperators; 96 PetscErrorCode ierr; 97 98 PetscFunctionBegin; 99 ierr = PetscInfo(pc,"PCTelescope: setup (CoarseDM)\n");CHKERRQ(ierr); 100 ierr = PetscMalloc1(1,&ctx);CHKERRQ(ierr); 101 ierr = PetscMemzero(ctx,sizeof(PC_Telescope_CoarseDMCtx));CHKERRQ(ierr); 102 sred->dm_ctx = (void*)ctx; 103 104 ierr = PetscObjectGetComm((PetscObject)pc,&comm);CHKERRQ(ierr); 105 ierr = PCGetDM(pc,&dm);CHKERRQ(ierr); 106 107 ierr = PCGetDM(pc,&dm);CHKERRQ(ierr); 108 ierr = DMGetCoarseDM(dm,&dm_coarse);CHKERRQ(ierr); 109 ctx->dm_fine = dm; 110 ctx->dm_coarse = dm_coarse; 111 112 /* attach coarse dm to ksp on sub communicator */ 113 if (isActiveRank(sred)) { 114 ierr = KSPSetDM(sred->ksp,ctx->dm_coarse);CHKERRQ(ierr); 115 if (sred->ignore_kspcomputeoperators) { 116 ierr = KSPSetDMActive(sred->ksp,PETSC_FALSE);CHKERRQ(ierr); 117 } 118 } 119 120 /* check if there is a method to provide a permutation */ 121 has_perm = PETSC_FALSE; 122 has_kspcomputeoperators = PETSC_FALSE; 123 using_kspcomputeoperators = PETSC_FALSE; 124 125 /* if no permutation is provided, we must rely on KSPSetComputeOperators */ 126 { 127 PetscErrorCode (*dmfine_kspfunc)(KSP,Mat,Mat,void*); 128 void *dmfine_kspctx = NULL,*dmcoarse_kspctx = NULL; 129 void *dmfine_appctx = NULL,*dmcoarse_appctx = NULL; 130 void *dmfine_shellctx = NULL,*dmcoarse_shellctx = NULL; 131 132 ierr = DMKSPGetComputeOperators(dm,&dmfine_kspfunc,&dmfine_kspctx);CHKERRQ(ierr); 133 if (dmfine_kspfunc) { has_kspcomputeoperators = PETSC_TRUE; } 134 135 ierr = DMGetApplicationContext(ctx->dm_fine,&dmfine_appctx);CHKERRQ(ierr); 136 ierr = DMShellGetContext(ctx->dm_fine,&dmfine_shellctx);CHKERRQ(ierr); 137 138 /* need to define dmcoarse_kspctx */ 139 if (dmfine_kspfunc && !sred->ignore_kspcomputeoperators) { 140 141 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators fetched from parent DM\n");CHKERRQ(ierr); 142 if (isActiveRank(sred)) { 143 ierr = DMGetApplicationContext(ctx->dm_coarse,&dmcoarse_appctx);CHKERRQ(ierr); 144 ierr = DMShellGetContext(ctx->dm_coarse,&dmcoarse_shellctx);CHKERRQ(ierr); 145 } 146 147 /* Assume that if the fine operator didn't require any context, neither will the coarse */ 148 if (!dmfine_kspctx) { 149 dmcoarse_kspctx = NULL; 150 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using NULL context\n");CHKERRQ(ierr); 151 } else { 152 153 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators detected non-NULL context from parent DM \n");CHKERRQ(ierr); 154 if (isActiveRank(sred)) { 155 156 if (dmfine_kspctx == dmfine_appctx) { 157 dmcoarse_kspctx = dmcoarse_appctx; 158 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using context from DM->ApplicationContext\n");CHKERRQ(ierr); 159 if (!dmcoarse_kspctx) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Non NULL dmfine->kspctx == dmfine->appctx. NULL dmcoarse->appctx found. Likely this is an error"); 160 } else if (dmfine_kspctx == dmfine_shellctx) { 161 dmcoarse_kspctx = dmcoarse_shellctx; 162 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using context from DMShell->Context\n");CHKERRQ(ierr); 163 if (!dmcoarse_kspctx) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Non NULL dmfine->kspctx == dmfine.shell->ctx. NULL dmcoarse.shell->ctx found. Likely this is an error"); 164 } 165 ctx->dmksp_context_determined = dmcoarse_kspctx; 166 167 /* look for user provided method to fetch the context */ 168 { 169 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 170 void *dmcoarse_context_user = NULL; 171 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 172 173 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMKSPContext");CHKERRQ(ierr); 174 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 175 if (fp_get_coarsedm_context) { 176 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeGetCoarseDMKSPContext from coarse DM\n");CHKERRQ(ierr); 177 ierr = fp_get_coarsedm_context(ctx->dm_coarse,&dmcoarse_context_user);CHKERRQ(ierr); 178 ctx->dmksp_context_user = dmcoarse_context_user; 179 dmcoarse_kspctx = dmcoarse_context_user; 180 } else { 181 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeGetCoarseDMKSPContext from coarse DM\n");CHKERRQ(ierr); 182 } 183 } 184 185 if (!dmcoarse_kspctx) { 186 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators failed to determine the context to use on sub-communicator\n");CHKERRQ(ierr); 187 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Cannot determine which context with use for KSPSetComputeOperators() on sub-communicator"); 188 } 189 } 190 } 191 } 192 193 if (dmfine_kspfunc && !sred->ignore_kspcomputeoperators) { 194 using_kspcomputeoperators = PETSC_TRUE; 195 196 if (isActiveRank(sred)) { 197 /* sub ksp inherits dmksp_func and context provided by user */ 198 ierr = KSPSetComputeOperators(sred->ksp,dmfine_kspfunc,dmcoarse_kspctx);CHKERRQ(ierr); 199 /*ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)ctx->dmrepart);CHKERRQ(ierr);*/ 200 ierr = KSPSetDMActive(sred->ksp,PETSC_TRUE);CHKERRQ(ierr); 201 } 202 } 203 } 204 205 if (!has_perm && has_kspcomputeoperators && !using_kspcomputeoperators) SETERRQ(comm,PETSC_ERR_SUP,"No method to permute an operator was found on the parent DM. A method for KSPSetComputeOperators() was provided but it was requested to be ignored. Telescope setup cannot proceed"); 206 if (!has_perm && !has_kspcomputeoperators) SETERRQ(comm,PETSC_ERR_SUP,"No method to permute an operator was found on the parent DM. No method for KSPSetComputeOperators() was provided. Telescope setup cannot proceed"); 207 208 { 209 char dmfine_method[PETSC_MAX_PATH_LEN]; 210 211 ierr = PetscSNPrintf(dmfine_method,sizeof(dmfine_method),"PCTelescopeFieldScatter");CHKERRQ(ierr); 212 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_fine,dmfine_method,&ctx->fp_dm_field_scatter);CHKERRQ(ierr); 213 214 ierr = PetscSNPrintf(dmfine_method,sizeof(dmfine_method),"PCTelescopeStateScatter");CHKERRQ(ierr); 215 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_fine,dmfine_method,&ctx->fp_dm_state_scatter);CHKERRQ(ierr); 216 } 217 218 if (ctx->fp_dm_state_scatter) { 219 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeStateScatter from parent DM\n");CHKERRQ(ierr); 220 } else { 221 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeStateScatter from parent DM\n");CHKERRQ(ierr); 222 } 223 224 if (ctx->fp_dm_field_scatter) { 225 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeFieldScatter from parent DM\n");CHKERRQ(ierr); 226 } else { 227 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeFieldScatter from parent DM\n");CHKERRQ(ierr); 228 SETERRQ(comm,PETSC_ERR_SUP,"No method to scatter fields between the parent DM and coarse DM was found. Must call PetscObjectComposeFunction() with the parent DM. Telescope setup cannot proceed"); 229 } 230 231 /*ierr = PCTelescopeSetUp_permutation_CoarseDM(pc,sred,ctx);CHKERRQ(ierr);*/ 232 233 ierr = PCTelescopeSetUp_scatters_CoarseDM(pc,sred,ctx);CHKERRQ(ierr); 234 235 PetscFunctionReturn(0); 236 } 237 238 PetscErrorCode PCApply_Telescope_CoarseDM(PC pc,Vec x,Vec y) 239 { 240 PC_Telescope sred = (PC_Telescope)pc->data; 241 PetscErrorCode ierr; 242 Vec xred,yred; 243 PC_Telescope_CoarseDMCtx *ctx; 244 245 PetscFunctionBegin; 246 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 247 xred = sred->xred; 248 yred = sred->yred; 249 250 ierr = PetscCitationsRegister(citation,&cited);CHKERRQ(ierr); 251 252 if (ctx->fp_dm_state_scatter) { 253 ierr = ctx->fp_dm_state_scatter(ctx->dm_fine,SCATTER_FORWARD,ctx->dm_coarse);CHKERRQ(ierr); 254 } 255 256 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,x,SCATTER_FORWARD,ctx->dm_coarse,xred);CHKERRQ(ierr); 257 258 /* solve */ 259 if (isActiveRank(sred)) { 260 ierr = KSPSolve(sred->ksp,xred,yred);CHKERRQ(ierr); 261 } 262 263 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,y,SCATTER_REVERSE,ctx->dm_coarse,yred);CHKERRQ(ierr); 264 265 PetscFunctionReturn(0); 266 } 267 268 PetscErrorCode PCTelescopeSubNullSpaceCreate_CoarseDM(PC pc,PC_Telescope sred,MatNullSpace nullspace,MatNullSpace *sub_nullspace) 269 { 270 PetscErrorCode ierr; 271 PetscBool has_const; 272 PetscInt k,n = 0; 273 const Vec *vecs; 274 Vec *sub_vecs = NULL; 275 MPI_Comm subcomm; 276 PC_Telescope_CoarseDMCtx *ctx; 277 278 PetscFunctionBegin; 279 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 280 subcomm = sred->subcomm; 281 ierr = MatNullSpaceGetVecs(nullspace,&has_const,&n,&vecs);CHKERRQ(ierr); 282 283 if (isActiveRank(sred)) { 284 /* create new vectors */ 285 if (n) { 286 ierr = VecDuplicateVecs(sred->xred,n,&sub_vecs);CHKERRQ(ierr); 287 } 288 } 289 290 /* copy entries */ 291 for (k=0; k<n; k++) { 292 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,vecs[k],SCATTER_FORWARD,ctx->dm_coarse,sub_vecs[k]);CHKERRQ(ierr); 293 } 294 295 if (isActiveRank(sred)) { 296 /* create new (near) nullspace for redundant object */ 297 ierr = MatNullSpaceCreate(subcomm,has_const,n,sub_vecs,sub_nullspace);CHKERRQ(ierr); 298 ierr = VecDestroyVecs(n,&sub_vecs);CHKERRQ(ierr); 299 } 300 301 PetscFunctionReturn(0); 302 } 303 304 PetscErrorCode PCTelescopeMatNullSpaceCreate_CoarseDM(PC pc,PC_Telescope sred,Mat sub_mat) 305 { 306 PetscErrorCode ierr; 307 Mat B; 308 PC_Telescope_CoarseDMCtx *ctx; 309 310 PetscFunctionBegin; 311 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 312 ierr = PCGetOperators(pc,NULL,&B);CHKERRQ(ierr); 313 314 { 315 MatNullSpace nullspace,sub_nullspace; 316 ierr = MatGetNullSpace(B,&nullspace);CHKERRQ(ierr); 317 if (nullspace) { 318 ierr = PetscInfo(pc,"PCTelescope: generating nullspace (CoarseDM)\n");CHKERRQ(ierr); 319 ierr = PCTelescopeSubNullSpaceCreate_CoarseDM(pc,sred,nullspace,&sub_nullspace);CHKERRQ(ierr); 320 321 /* attach any user nullspace removal methods and contexts */ 322 if (isActiveRank(sred)) { 323 void *context = NULL; 324 if (nullspace->remove && !nullspace->rmctx){ 325 ierr = MatNullSpaceSetFunction(sub_nullspace,nullspace->remove,context);CHKERRQ(ierr); 326 } else if (nullspace->remove && nullspace->rmctx) { 327 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 328 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 329 330 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMNullSpaceUserContext");CHKERRQ(ierr); 331 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 332 333 if (!context) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Propagation of user null-space removal method with non-NULL context requires the coarse DM be composed with a function named \"%s\"",dmcoarse_method); 334 335 ierr = MatNullSpaceSetFunction(sub_nullspace,nullspace->remove,context);CHKERRQ(ierr); 336 } 337 } 338 339 if (isActiveRank(sred)) { 340 ierr = MatSetNullSpace(sub_mat,sub_nullspace);CHKERRQ(ierr); 341 ierr = MatNullSpaceDestroy(&sub_nullspace);CHKERRQ(ierr); 342 } 343 } 344 } 345 346 { 347 MatNullSpace nearnullspace,sub_nearnullspace; 348 ierr = MatGetNearNullSpace(B,&nearnullspace);CHKERRQ(ierr); 349 if (nearnullspace) { 350 ierr = PetscInfo(pc,"PCTelescope: generating near nullspace (CoarseDM)\n");CHKERRQ(ierr); 351 ierr = PCTelescopeSubNullSpaceCreate_CoarseDM(pc,sred,nearnullspace,&sub_nearnullspace);CHKERRQ(ierr); 352 353 /* attach any user nullspace removal methods and contexts */ 354 if (isActiveRank(sred)) { 355 void *context = NULL; 356 if (nearnullspace->remove && !nearnullspace->rmctx){ 357 ierr = MatNullSpaceSetFunction(sub_nearnullspace,nearnullspace->remove,context);CHKERRQ(ierr); 358 } else if (nearnullspace->remove && nearnullspace->rmctx) { 359 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 360 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 361 362 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMNearNullSpaceUserContext");CHKERRQ(ierr); 363 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 364 365 if (!context) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Propagation of user near null-space removal method with non-NULL context requires the coarse DM be composed with a function named \"%s\"",dmcoarse_method); 366 367 ierr = MatNullSpaceSetFunction(sub_nearnullspace,nearnullspace->remove,context);CHKERRQ(ierr); 368 } 369 } 370 371 if (isActiveRank(sred)) { 372 ierr = MatSetNearNullSpace(sub_mat,sub_nearnullspace);CHKERRQ(ierr); 373 ierr = MatNullSpaceDestroy(&sub_nearnullspace);CHKERRQ(ierr); 374 } 375 } 376 } 377 PetscFunctionReturn(0); 378 } 379 380 PetscErrorCode PCReset_Telescope_CoarseDM(PC pc) 381 { 382 PetscErrorCode ierr; 383 PC_Telescope sred = (PC_Telescope)pc->data; 384 PC_Telescope_CoarseDMCtx *ctx; 385 386 PetscFunctionBegin; 387 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 388 ctx->dm_fine = NULL; /* since I did not increment the ref counter we set these to NULL */ 389 ctx->dm_coarse = NULL; /* since I did not increment the ref counter we set these to NULL */ 390 ctx->permutation = NULL; /* this will be fetched from the dm so no need to call destroy */ 391 ierr = VecDestroy(&ctx->xp);CHKERRQ(ierr); 392 ctx->fp_dm_field_scatter = NULL; 393 ctx->fp_dm_state_scatter = NULL; 394 ctx->dmksp_context_determined = NULL; 395 ctx->dmksp_context_user = NULL; 396 PetscFunctionReturn(0); 397 } 398 399 PetscErrorCode PCApplyRichardson_Telescope_CoarseDM(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt its,PetscBool zeroguess,PetscInt *outits,PCRichardsonConvergedReason *reason) 400 { 401 PC_Telescope sred = (PC_Telescope)pc->data; 402 PetscErrorCode ierr; 403 Vec yred = NULL; 404 PetscBool default_init_guess_value = PETSC_FALSE; 405 PC_Telescope_CoarseDMCtx *ctx; 406 407 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 408 yred = sred->yred; 409 410 if (its > 1) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"PCApplyRichardson_Telescope_CoarseDM only supports max_it = 1"); 411 *reason = (PCRichardsonConvergedReason)0; 412 413 if (!zeroguess) { 414 ierr = PetscInfo(pc,"PCTelescopeCoarseDM: Scattering y for non-zero-initial guess\n");CHKERRQ(ierr); 415 416 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,y,SCATTER_FORWARD,ctx->dm_coarse,yred);CHKERRQ(ierr); 417 } 418 419 if (isActiveRank(sred)) { 420 ierr = KSPGetInitialGuessNonzero(sred->ksp,&default_init_guess_value);CHKERRQ(ierr); 421 if (!zeroguess) ierr = KSPSetInitialGuessNonzero(sred->ksp,PETSC_TRUE);CHKERRQ(ierr); 422 } 423 424 ierr = PCApply_Telescope_CoarseDM(pc,x,y);CHKERRQ(ierr); 425 426 if (isActiveRank(sred)) { 427 ierr = KSPSetInitialGuessNonzero(sred->ksp,default_init_guess_value);CHKERRQ(ierr); 428 } 429 430 if (!*reason) *reason = PCRICHARDSON_CONVERGED_ITS; 431 *outits = 1; 432 PetscFunctionReturn(0); 433 } 434