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 (PCTelescope_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 ctx->xp = xp; 85 ierr = VecDestroy(&x);CHKERRQ(ierr); 86 PetscFunctionReturn(0); 87 } 88 89 PetscErrorCode PCTelescopeSetUp_CoarseDM(PC pc,PC_Telescope sred) 90 { 91 PC_Telescope_CoarseDMCtx *ctx; 92 DM dm,dm_coarse = NULL; 93 MPI_Comm comm; 94 PetscBool has_perm,has_kspcomputeoperators,using_kspcomputeoperators; 95 PetscErrorCode ierr; 96 97 PetscFunctionBegin; 98 ierr = PetscInfo(pc,"PCTelescope: setup (CoarseDM)\n");CHKERRQ(ierr); 99 ierr = PetscMalloc1(1,&ctx);CHKERRQ(ierr); 100 ierr = PetscMemzero(ctx,sizeof(PC_Telescope_CoarseDMCtx));CHKERRQ(ierr); 101 sred->dm_ctx = (void*)ctx; 102 103 ierr = PetscObjectGetComm((PetscObject)pc,&comm);CHKERRQ(ierr); 104 ierr = PCGetDM(pc,&dm);CHKERRQ(ierr); 105 106 ierr = PCGetDM(pc,&dm);CHKERRQ(ierr); 107 ierr = DMGetCoarseDM(dm,&dm_coarse);CHKERRQ(ierr); 108 ctx->dm_fine = dm; 109 ctx->dm_coarse = dm_coarse; 110 111 /* attach coarse dm to ksp on sub communicator */ 112 if (PCTelescope_isActiveRank(sred)) { 113 ierr = KSPSetDM(sred->ksp,ctx->dm_coarse);CHKERRQ(ierr); 114 if (sred->ignore_kspcomputeoperators) { 115 ierr = KSPSetDMActive(sred->ksp,PETSC_FALSE);CHKERRQ(ierr); 116 } 117 } 118 119 /* check if there is a method to provide a permutation */ 120 has_perm = PETSC_FALSE; 121 has_kspcomputeoperators = PETSC_FALSE; 122 using_kspcomputeoperators = PETSC_FALSE; 123 124 /* if no permutation is provided, we must rely on KSPSetComputeOperators */ 125 { 126 PetscErrorCode (*dmfine_kspfunc)(KSP,Mat,Mat,void*) = NULL; 127 void *dmfine_kspctx = NULL,*dmcoarse_kspctx = NULL; 128 void *dmfine_appctx = NULL,*dmcoarse_appctx = NULL; 129 void *dmfine_shellctx = NULL,*dmcoarse_shellctx = NULL; 130 131 ierr = DMKSPGetComputeOperators(dm,&dmfine_kspfunc,&dmfine_kspctx);CHKERRQ(ierr); 132 if (dmfine_kspfunc) { has_kspcomputeoperators = PETSC_TRUE; } 133 134 ierr = DMGetApplicationContext(ctx->dm_fine,&dmfine_appctx);CHKERRQ(ierr); 135 ierr = DMShellGetContext(ctx->dm_fine,&dmfine_shellctx);CHKERRQ(ierr); 136 137 /* need to define dmcoarse_kspctx */ 138 if (dmfine_kspfunc && !sred->ignore_kspcomputeoperators) { 139 140 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators fetched from parent DM\n");CHKERRQ(ierr); 141 if (PCTelescope_isActiveRank(sred)) { 142 ierr = DMGetApplicationContext(ctx->dm_coarse,&dmcoarse_appctx);CHKERRQ(ierr); 143 ierr = DMShellGetContext(ctx->dm_coarse,&dmcoarse_shellctx);CHKERRQ(ierr); 144 } 145 146 /* Assume that if the fine operator didn't require any context, neither will the coarse */ 147 if (!dmfine_kspctx) { 148 dmcoarse_kspctx = NULL; 149 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using NULL context\n");CHKERRQ(ierr); 150 } else { 151 152 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators detected non-NULL context from parent DM \n");CHKERRQ(ierr); 153 if (PCTelescope_isActiveRank(sred)) { 154 155 if (dmfine_kspctx == dmfine_appctx) { 156 dmcoarse_kspctx = dmcoarse_appctx; 157 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using context from DM->ApplicationContext\n");CHKERRQ(ierr); 158 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"); 159 } else if (dmfine_kspctx == dmfine_shellctx) { 160 dmcoarse_kspctx = dmcoarse_shellctx; 161 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators using context from DMShell->Context\n");CHKERRQ(ierr); 162 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"); 163 } 164 ctx->dmksp_context_determined = dmcoarse_kspctx; 165 166 /* look for user provided method to fetch the context */ 167 { 168 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 169 void *dmcoarse_context_user = NULL; 170 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 171 172 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMKSPContext");CHKERRQ(ierr); 173 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 174 if (fp_get_coarsedm_context) { 175 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeGetCoarseDMKSPContext from coarse DM\n");CHKERRQ(ierr); 176 ierr = fp_get_coarsedm_context(ctx->dm_coarse,&dmcoarse_context_user);CHKERRQ(ierr); 177 ctx->dmksp_context_user = dmcoarse_context_user; 178 dmcoarse_kspctx = dmcoarse_context_user; 179 } else { 180 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeGetCoarseDMKSPContext from coarse DM\n");CHKERRQ(ierr); 181 } 182 } 183 184 if (!dmcoarse_kspctx) { 185 ierr = PetscInfo(pc,"PCTelescope: KSPSetComputeOperators failed to determine the context to use on sub-communicator\n");CHKERRQ(ierr); 186 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Cannot determine which context with use for KSPSetComputeOperators() on sub-communicator"); 187 } 188 } 189 } 190 } 191 192 if (dmfine_kspfunc && !sred->ignore_kspcomputeoperators) { 193 using_kspcomputeoperators = PETSC_TRUE; 194 195 if (PCTelescope_isActiveRank(sred)) { 196 /* sub ksp inherits dmksp_func and context provided by user */ 197 ierr = KSPSetComputeOperators(sred->ksp,dmfine_kspfunc,dmcoarse_kspctx);CHKERRQ(ierr); 198 /*ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)ctx->dmrepart);CHKERRQ(ierr);*/ 199 ierr = KSPSetDMActive(sred->ksp,PETSC_TRUE);CHKERRQ(ierr); 200 } 201 } 202 } 203 204 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"); 205 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"); 206 207 { 208 char dmfine_method[PETSC_MAX_PATH_LEN]; 209 210 ierr = PetscSNPrintf(dmfine_method,sizeof(dmfine_method),"PCTelescopeFieldScatter");CHKERRQ(ierr); 211 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_fine,dmfine_method,&ctx->fp_dm_field_scatter);CHKERRQ(ierr); 212 213 ierr = PetscSNPrintf(dmfine_method,sizeof(dmfine_method),"PCTelescopeStateScatter");CHKERRQ(ierr); 214 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_fine,dmfine_method,&ctx->fp_dm_state_scatter);CHKERRQ(ierr); 215 } 216 217 if (ctx->fp_dm_state_scatter) { 218 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeStateScatter from parent DM\n");CHKERRQ(ierr); 219 } else { 220 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeStateScatter from parent DM\n");CHKERRQ(ierr); 221 } 222 223 if (ctx->fp_dm_field_scatter) { 224 ierr = PetscInfo(pc,"PCTelescope: Found composed method PCTelescopeFieldScatter from parent DM\n");CHKERRQ(ierr); 225 } else { 226 ierr = PetscInfo(pc,"PCTelescope: Failed to find composed method PCTelescopeFieldScatter from parent DM\n");CHKERRQ(ierr); 227 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"); 228 } 229 230 /*ierr = PCTelescopeSetUp_permutation_CoarseDM(pc,sred,ctx);CHKERRQ(ierr);*/ 231 ierr = PCTelescopeSetUp_scatters_CoarseDM(pc,sred,ctx);CHKERRQ(ierr); 232 PetscFunctionReturn(0); 233 } 234 235 PetscErrorCode PCApply_Telescope_CoarseDM(PC pc,Vec x,Vec y) 236 { 237 PC_Telescope sred = (PC_Telescope)pc->data; 238 PetscErrorCode ierr; 239 Vec xred,yred; 240 PC_Telescope_CoarseDMCtx *ctx; 241 242 PetscFunctionBegin; 243 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 244 xred = sred->xred; 245 yred = sred->yred; 246 247 ierr = PetscCitationsRegister(citation,&cited);CHKERRQ(ierr); 248 249 if (ctx->fp_dm_state_scatter) { 250 ierr = ctx->fp_dm_state_scatter(ctx->dm_fine,SCATTER_FORWARD,ctx->dm_coarse);CHKERRQ(ierr); 251 } 252 253 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,x,SCATTER_FORWARD,ctx->dm_coarse,xred);CHKERRQ(ierr); 254 255 /* solve */ 256 if (PCTelescope_isActiveRank(sred)) { 257 ierr = KSPSolve(sred->ksp,xred,yred);CHKERRQ(ierr); 258 } 259 260 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,y,SCATTER_REVERSE,ctx->dm_coarse,yred);CHKERRQ(ierr); 261 PetscFunctionReturn(0); 262 } 263 264 PetscErrorCode PCTelescopeSubNullSpaceCreate_CoarseDM(PC pc,PC_Telescope sred,MatNullSpace nullspace,MatNullSpace *sub_nullspace) 265 { 266 PetscErrorCode ierr; 267 PetscBool has_const; 268 PetscInt k,n = 0; 269 const Vec *vecs; 270 Vec *sub_vecs = NULL; 271 MPI_Comm subcomm; 272 PC_Telescope_CoarseDMCtx *ctx; 273 274 PetscFunctionBegin; 275 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 276 subcomm = sred->subcomm; 277 ierr = MatNullSpaceGetVecs(nullspace,&has_const,&n,&vecs);CHKERRQ(ierr); 278 279 if (PCTelescope_isActiveRank(sred)) { 280 /* create new vectors */ 281 if (n) { 282 ierr = VecDuplicateVecs(sred->xred,n,&sub_vecs);CHKERRQ(ierr); 283 } 284 } 285 286 /* copy entries */ 287 for (k=0; k<n; k++) { 288 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,vecs[k],SCATTER_FORWARD,ctx->dm_coarse,sub_vecs[k]);CHKERRQ(ierr); 289 } 290 291 if (PCTelescope_isActiveRank(sred)) { 292 /* create new (near) nullspace for redundant object */ 293 ierr = MatNullSpaceCreate(subcomm,has_const,n,sub_vecs,sub_nullspace);CHKERRQ(ierr); 294 ierr = VecDestroyVecs(n,&sub_vecs);CHKERRQ(ierr); 295 } 296 PetscFunctionReturn(0); 297 } 298 299 PetscErrorCode PCTelescopeMatNullSpaceCreate_CoarseDM(PC pc,PC_Telescope sred,Mat sub_mat) 300 { 301 PetscErrorCode ierr; 302 Mat B; 303 PC_Telescope_CoarseDMCtx *ctx; 304 305 PetscFunctionBegin; 306 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 307 ierr = PCGetOperators(pc,NULL,&B);CHKERRQ(ierr); 308 { 309 MatNullSpace nullspace,sub_nullspace; 310 ierr = MatGetNullSpace(B,&nullspace);CHKERRQ(ierr); 311 if (nullspace) { 312 ierr = PetscInfo(pc,"PCTelescope: generating nullspace (CoarseDM)\n");CHKERRQ(ierr); 313 ierr = PCTelescopeSubNullSpaceCreate_CoarseDM(pc,sred,nullspace,&sub_nullspace);CHKERRQ(ierr); 314 315 /* attach any user nullspace removal methods and contexts */ 316 if (PCTelescope_isActiveRank(sred)) { 317 void *context = NULL; 318 if (nullspace->remove && !nullspace->rmctx){ 319 ierr = MatNullSpaceSetFunction(sub_nullspace,nullspace->remove,context);CHKERRQ(ierr); 320 } else if (nullspace->remove && nullspace->rmctx) { 321 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 322 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 323 324 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMNullSpaceUserContext");CHKERRQ(ierr); 325 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 326 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); 327 ierr = MatNullSpaceSetFunction(sub_nullspace,nullspace->remove,context);CHKERRQ(ierr); 328 } 329 } 330 331 if (PCTelescope_isActiveRank(sred)) { 332 ierr = MatSetNullSpace(sub_mat,sub_nullspace);CHKERRQ(ierr); 333 ierr = MatNullSpaceDestroy(&sub_nullspace);CHKERRQ(ierr); 334 } 335 } 336 } 337 { 338 MatNullSpace nearnullspace,sub_nearnullspace; 339 ierr = MatGetNearNullSpace(B,&nearnullspace);CHKERRQ(ierr); 340 if (nearnullspace) { 341 ierr = PetscInfo(pc,"PCTelescope: generating near nullspace (CoarseDM)\n");CHKERRQ(ierr); 342 ierr = PCTelescopeSubNullSpaceCreate_CoarseDM(pc,sred,nearnullspace,&sub_nearnullspace);CHKERRQ(ierr); 343 344 /* attach any user nullspace removal methods and contexts */ 345 if (PCTelescope_isActiveRank(sred)) { 346 void *context = NULL; 347 if (nearnullspace->remove && !nearnullspace->rmctx){ 348 ierr = MatNullSpaceSetFunction(sub_nearnullspace,nearnullspace->remove,context);CHKERRQ(ierr); 349 } else if (nearnullspace->remove && nearnullspace->rmctx) { 350 char dmcoarse_method[PETSC_MAX_PATH_LEN]; 351 PetscErrorCode (*fp_get_coarsedm_context)(DM,void**) = NULL; 352 353 ierr = PetscSNPrintf(dmcoarse_method,sizeof(dmcoarse_method),"PCTelescopeGetCoarseDMNearNullSpaceUserContext");CHKERRQ(ierr); 354 ierr = PetscObjectQueryFunction((PetscObject)ctx->dm_coarse,dmcoarse_method,&fp_get_coarsedm_context);CHKERRQ(ierr); 355 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); 356 ierr = MatNullSpaceSetFunction(sub_nearnullspace,nearnullspace->remove,context);CHKERRQ(ierr); 357 } 358 } 359 360 if (PCTelescope_isActiveRank(sred)) { 361 ierr = MatSetNearNullSpace(sub_mat,sub_nearnullspace);CHKERRQ(ierr); 362 ierr = MatNullSpaceDestroy(&sub_nearnullspace);CHKERRQ(ierr); 363 } 364 } 365 } 366 PetscFunctionReturn(0); 367 } 368 369 PetscErrorCode PCReset_Telescope_CoarseDM(PC pc) 370 { 371 PetscErrorCode ierr; 372 PC_Telescope sred = (PC_Telescope)pc->data; 373 PC_Telescope_CoarseDMCtx *ctx; 374 375 PetscFunctionBegin; 376 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 377 ctx->dm_fine = NULL; /* since I did not increment the ref counter we set these to NULL */ 378 ctx->dm_coarse = NULL; /* since I did not increment the ref counter we set these to NULL */ 379 ctx->permutation = NULL; /* this will be fetched from the dm so no need to call destroy */ 380 ierr = VecDestroy(&ctx->xp);CHKERRQ(ierr); 381 ctx->fp_dm_field_scatter = NULL; 382 ctx->fp_dm_state_scatter = NULL; 383 ctx->dmksp_context_determined = NULL; 384 ctx->dmksp_context_user = NULL; 385 PetscFunctionReturn(0); 386 } 387 388 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) 389 { 390 PC_Telescope sred = (PC_Telescope)pc->data; 391 PetscErrorCode ierr; 392 Vec yred = NULL; 393 PetscBool default_init_guess_value = PETSC_FALSE; 394 PC_Telescope_CoarseDMCtx *ctx; 395 396 PetscFunctionBegin; 397 ctx = (PC_Telescope_CoarseDMCtx*)sred->dm_ctx; 398 yred = sred->yred; 399 400 if (its > 1) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"PCApplyRichardson_Telescope_CoarseDM only supports max_it = 1"); 401 *reason = (PCRichardsonConvergedReason)0; 402 403 if (!zeroguess) { 404 ierr = PetscInfo(pc,"PCTelescopeCoarseDM: Scattering y for non-zero-initial guess\n");CHKERRQ(ierr); 405 406 ierr = ctx->fp_dm_field_scatter(ctx->dm_fine,y,SCATTER_FORWARD,ctx->dm_coarse,yred);CHKERRQ(ierr); 407 } 408 409 if (PCTelescope_isActiveRank(sred)) { 410 ierr = KSPGetInitialGuessNonzero(sred->ksp,&default_init_guess_value);CHKERRQ(ierr); 411 if (!zeroguess) ierr = KSPSetInitialGuessNonzero(sred->ksp,PETSC_TRUE);CHKERRQ(ierr); 412 } 413 414 ierr = PCApply_Telescope_CoarseDM(pc,x,y);CHKERRQ(ierr); 415 416 if (PCTelescope_isActiveRank(sred)) { 417 ierr = KSPSetInitialGuessNonzero(sred->ksp,default_init_guess_value);CHKERRQ(ierr); 418 } 419 420 if (!*reason) *reason = PCRICHARDSON_CONVERGED_ITS; 421 *outits = 1; 422 PetscFunctionReturn(0); 423 } 424