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