Actual source code: patch.c

  1: #include <petsc/private/dmpatchimpl.h>
  2: #include <petscdmda.h>
  3: #include <petscsf.h>

  5: /*
  6: Solver loop to update \tau:

  8:   DMZoom(dmc, &dmz)
  9:   DMRefine(dmz, &dmf),
 10:   Scatter Xcoarse -> Xzoom,
 11:   Interpolate Xzoom -> Xfine (note that this may be on subcomms),
 12:   Smooth Xfine using two-step smoother
 13:     normal smoother plus Kaczmarz---moves back and forth from dmzoom to dmfine
 14:   Compute residual Rfine
 15:   Restrict Rfine to Rzoom_restricted
 16:   Scatter Rzoom_restricted -> Rcoarse_restricted
 17:   Compute global residual Rcoarse
 18:   TauCoarse = Rcoarse - Rcoarse_restricted
 19: */

 21: /*@
 22:   DMPatchZoom - Create patches of a `DMDA` on subsets of processes, indicated by `commz`

 24:   Collective

 26:   Input Parameters:
 27: + dm    - the `DM`
 28: . lower - the lower left corner of the requested patch
 29: . upper - the upper right corner of the requested patch
 30: - commz - the new communicator for the patch, `MPI_COMM_NULL` indicates that the given rank will not own a patch

 32:   Output Parameters:
 33: + dmz  - the patch `DM`
 34: . sfz  - the `PetscSF` mapping the patch+halo to the zoomed version (optional)
 35: - sfzr - the `PetscSF` mapping the patch to the restricted zoomed version

 37:   Level: intermediate

 39: .seealso: `DMPATCH`, `DMPatchSolve()`, `DMDACreatePatchIS()`
 40: @*/
 41: PetscErrorCode DMPatchZoom(DM dm, MatStencil lower, MatStencil upper, MPI_Comm commz, DM *dmz, PeOp PetscSF *sfz, PeOp PetscSF *sfzr)
 42: {
 43:   DMDAStencilType st;
 44:   MatStencil      blower, bupper, loclower, locupper;
 45:   IS              is;
 46:   const PetscInt *ranges, *indices;
 47:   PetscInt       *localPoints  = NULL;
 48:   PetscSFNode    *remotePoints = NULL;
 49:   PetscInt        dim, dof;
 50:   PetscInt        M, N, P, rM, rN, rP, halo = 1, sxb, syb, szb, sxr, syr, szr, exr, eyr, ezr, mxb, myb, mzb, i, j, k, l, q;
 51:   PetscMPIInt     size;
 52:   PetscBool       patchis_offproc = PETSC_TRUE;
 53:   Vec             X;

 55:   PetscFunctionBegin;
 56:   if (!sfz) halo = 0;
 57:   PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)dm), &size));
 58:   /* Create patch DM */
 59:   PetscCall(DMDAGetInfo(dm, &dim, &M, &N, &P, NULL, NULL, NULL, &dof, NULL, NULL, NULL, NULL, &st));

 61:   /* Get piece for rank r, expanded by halo */
 62:   bupper.i = PetscMin(M, upper.i + halo);
 63:   blower.i = PetscMax(lower.i - halo, 0);
 64:   bupper.j = PetscMin(N, upper.j + halo);
 65:   blower.j = PetscMax(lower.j - halo, 0);
 66:   bupper.k = PetscMin(P, upper.k + halo);
 67:   blower.k = PetscMax(lower.k - halo, 0);
 68:   rM       = bupper.i - blower.i;
 69:   rN       = bupper.j - blower.j;
 70:   rP       = bupper.k - blower.k;

 72:   if (commz != MPI_COMM_NULL) {
 73:     PetscCall(DMDACreate(commz, dmz));
 74:     PetscCall(DMSetDimension(*dmz, dim));
 75:     PetscCall(DMDASetSizes(*dmz, rM, rN, rP));
 76:     PetscCall(DMDASetNumProcs(*dmz, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE));
 77:     PetscCall(DMDASetBoundaryType(*dmz, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE));
 78:     PetscCall(DMDASetDof(*dmz, dof));
 79:     PetscCall(DMDASetStencilType(*dmz, st));
 80:     PetscCall(DMDASetStencilWidth(*dmz, 0));
 81:     PetscCall(DMDASetOwnershipRanges(*dmz, NULL, NULL, NULL));
 82:     PetscCall(DMSetFromOptions(*dmz));
 83:     PetscCall(DMSetUp(*dmz));
 84:     PetscCall(DMDAGetCorners(*dmz, &sxb, &syb, &szb, &mxb, &myb, &mzb));
 85:     sxr = PetscMax(sxb, lower.i - blower.i);
 86:     syr = PetscMax(syb, lower.j - blower.j);
 87:     szr = PetscMax(szb, lower.k - blower.k);
 88:     exr = PetscMin(sxb + mxb, upper.i - blower.i);
 89:     eyr = PetscMin(syb + myb, upper.j - blower.j);
 90:     ezr = PetscMin(szb + mzb, upper.k - blower.k);
 91:     PetscCall(PetscMalloc2(dof * rM * rN * PetscMax(rP, 1), &localPoints, dof * rM * rN * PetscMax(rP, 1), &remotePoints));
 92:   } else {
 93:     sxr = syr = szr = exr = eyr = ezr = sxb = syb = szb = mxb = myb = mzb = 0;
 94:   }

 96:   /* Create SF for restricted map */
 97:   PetscCall(DMCreateGlobalVector(dm, &X));
 98:   PetscCall(VecGetOwnershipRanges(X, &ranges));

100:   loclower.i = blower.i + sxr;
101:   locupper.i = blower.i + exr;
102:   loclower.j = blower.j + syr;
103:   locupper.j = blower.j + eyr;
104:   loclower.k = blower.k + szr;
105:   locupper.k = blower.k + ezr;

107:   PetscCall(DMDACreatePatchIS(dm, &loclower, &locupper, &is, patchis_offproc));
108:   PetscCall(ISGetIndices(is, &indices));

110:   if (dim < 3) {
111:     mzb = 1;
112:     ezr = 1;
113:   }
114:   q = 0;
115:   for (k = szb; k < szb + mzb; ++k) {
116:     if (k < szr || k >= ezr) continue;
117:     for (j = syb; j < syb + myb; ++j) {
118:       if (j < syr || j >= eyr) continue;
119:       for (i = sxb; i < sxb + mxb; ++i) {
120:         for (l = 0; l < dof; l++) {
121:           const PetscInt lp = l + dof * (((k - szb) * rN + (j - syb)) * rM + i - sxb);
122:           PetscMPIInt    r;
123:           PetscInt       ir;

125:           if (i < sxr || i >= exr) continue;
126:           localPoints[q] = lp;
127:           PetscCall(PetscFindInt(indices[q], size + 1, ranges, &ir));
128:           PetscCall(PetscMPIIntCast(ir, &r));

130:           remotePoints[q].rank  = r < 0 ? -(r + 1) - 1 : r;
131:           remotePoints[q].index = indices[q] - ranges[remotePoints[q].rank];
132:           ++q;
133:         }
134:       }
135:     }
136:   }
137:   PetscCall(ISRestoreIndices(is, &indices));
138:   PetscCall(ISDestroy(&is));
139:   PetscCall(PetscSFCreate(PetscObjectComm((PetscObject)dm), sfzr));
140:   PetscCall(PetscObjectSetName((PetscObject)*sfzr, "Restricted Map"));
141:   PetscCall(PetscSFSetGraph(*sfzr, dof * M * N * P, q, localPoints, PETSC_COPY_VALUES, remotePoints, PETSC_COPY_VALUES));

143:   if (sfz) {
144:     /* Create SF for buffered map */
145:     loclower.i = blower.i + sxb;
146:     locupper.i = blower.i + sxb + mxb;
147:     loclower.j = blower.j + syb;
148:     locupper.j = blower.j + syb + myb;
149:     loclower.k = blower.k + szb;
150:     locupper.k = blower.k + szb + mzb;

152:     PetscCall(DMDACreatePatchIS(dm, &loclower, &locupper, &is, patchis_offproc));
153:     PetscCall(ISGetIndices(is, &indices));

155:     q = 0;
156:     for (k = szb; k < szb + mzb; ++k) {
157:       for (j = syb; j < syb + myb; ++j) {
158:         for (i = sxb; i < sxb + mxb; ++i, ++q) {
159:           PetscInt    ir;
160:           PetscMPIInt r;

162:           localPoints[q] = q;
163:           PetscCall(PetscFindInt(indices[q], size + 1, ranges, &ir));
164:           PetscCall(PetscMPIIntCast(ir, &r));
165:           remotePoints[q].rank  = r < 0 ? -(r + 1) - 1 : r;
166:           remotePoints[q].index = indices[q] - ranges[remotePoints[q].rank];
167:         }
168:       }
169:     }
170:     PetscCall(ISRestoreIndices(is, &indices));
171:     PetscCall(ISDestroy(&is));
172:     PetscCall(PetscSFCreate(PetscObjectComm((PetscObject)dm), sfz));
173:     PetscCall(PetscObjectSetName((PetscObject)*sfz, "Buffered Map"));
174:     PetscCall(PetscSFSetGraph(*sfz, M * N * P, q, localPoints, PETSC_COPY_VALUES, remotePoints, PETSC_COPY_VALUES));
175:   }

177:   PetscCall(VecDestroy(&X));
178:   PetscCall(PetscFree2(localPoints, remotePoints));
179:   PetscFunctionReturn(PETSC_SUCCESS);
180: }

182: typedef enum {
183:   PATCH_COMM_TYPE_WORLD = 0,
184:   PATCH_COMM_TYPE_SELF  = 1
185: } PatchCommType;

187: /*@
188:   DMPatchSolve - Iterate over all patches of a `DMPATCH`, zooming the coarse `DM` onto each patch and scattering data between the coarse and zoomed representations

190:   Collective

192:   Input Parameter:
193: . dm - the `DMPATCH`

195:   Level: developer

197:   Note:
198:   This code is a work in progress and is not currently used by other parts of PETSc.
199:   It implements the outer loop of the FAS/multigrid-like patch solver sketched at the top of the source file.

201: .seealso: `DMPATCH`, `DMPatchZoom()`, `DMPatchGetCoarse()`, `DMPatchGetPatchSize()`, `DMPatchGetCommSize()`
202: @*/
203: PetscErrorCode DMPatchSolve(DM dm)
204: {
205:   MPI_Comm    comm, commz;
206:   DM          dmc;
207:   PetscSF     sfz, sfzr;
208:   Vec         XC;
209:   MatStencil  patchSize, commSize, gridRank, lower, upper;
210:   PetscInt    M, N, P, i, j, k, l, m, n, p = 0;
211:   PetscMPIInt rank, size;
212:   PetscInt    debug = 0;

214:   PetscFunctionBegin;
215:   PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
216:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
217:   PetscCallMPI(MPI_Comm_size(comm, &size));
218:   PetscCall(DMPatchGetCoarse(dm, &dmc));
219:   PetscCall(DMPatchGetPatchSize(dm, &patchSize));
220:   PetscCall(DMPatchGetCommSize(dm, &commSize));
221:   PetscCall(DMPatchGetCommSize(dm, &commSize));
222:   PetscCall(DMGetGlobalVector(dmc, &XC));
223:   PetscCall(DMDAGetInfo(dmc, NULL, &M, &N, &P, &l, &m, &n, NULL, NULL, NULL, NULL, NULL, NULL));
224:   M = PetscMax(M, 1);
225:   l = PetscMax(l, 1);
226:   N = PetscMax(N, 1);
227:   m = PetscMax(m, 1);
228:   P = PetscMax(P, 1);
229:   n = PetscMax(n, 1);

231:   gridRank.i = rank % l;
232:   gridRank.j = rank / l % m;
233:   gridRank.k = rank / (l * m) % n;

235:   if (commSize.i * commSize.j * commSize.k == size || commSize.i * commSize.j * commSize.k == 0) {
236:     commSize.i = l;
237:     commSize.j = m;
238:     commSize.k = n;
239:     commz      = comm;
240:   } else if (commSize.i * commSize.j * commSize.k == 1) {
241:     commz = PETSC_COMM_SELF;
242:   } else {
243:     PetscInt    newComm = ((gridRank.k / commSize.k) * (m / commSize.j) + gridRank.j / commSize.j) * (l / commSize.i) + gridRank.i / commSize.i;
244:     PetscInt    newRank = ((gridRank.k % commSize.k) * commSize.j + gridRank.j % commSize.j) * commSize.i + gridRank.i % commSize.i;
245:     PetscMPIInt newCommi;
246:     PetscMPIInt newRanki;

248:     PetscCall(PetscMPIIntCast(newComm, &newCommi));
249:     PetscCall(PetscMPIIntCast(newRank, &newRanki));
250:     PetscCallMPI(MPI_Comm_split(comm, newCommi, newRanki, &commz));
251:     if (debug) PetscCall(PetscPrintf(PETSC_COMM_SELF, "Rank %d color %d key %d commz %p\n", rank, newCommi, newRanki, (void *)(MPI_Aint)commz));
252:   }
253:   /*
254:    Assumptions:
255:      - patchSize divides gridSize
256:      - commSize divides gridSize
257:      - commSize divides l,m,n
258:    Ignore multiple patches per rank for now

260:    Multiple ranks per patch:
261:      - l,m,n divides patchSize
262:      - commSize divides patchSize
263:    */
264:   for (k = 0; k < P; k += PetscMax(patchSize.k, 1)) {
265:     for (j = 0; j < N; j += PetscMax(patchSize.j, 1)) {
266:       for (i = 0; i < M; i += PetscMax(patchSize.i, 1), ++p) {
267:         MPI_Comm commp = MPI_COMM_NULL;
268:         DM       dmz   = NULL;
269: #if 0
270:         DM          dmf     = NULL;
271:         Mat         interpz = NULL;
272: #endif
273:         Vec          XZ      = NULL;
274:         PetscScalar *xcarray = NULL;
275:         PetscScalar *xzarray = NULL;

277:         if ((gridRank.k / commSize.k == p / (l / commSize.i * m / commSize.j) % n / commSize.k) && (gridRank.j / commSize.j == p / (l / commSize.i) % m / commSize.j) && (gridRank.i / commSize.i == p % l / commSize.i)) {
278:           if (debug) PetscCall(PetscPrintf(PETSC_COMM_SELF, "Rank %d is accepting Patch %" PetscInt_FMT "\n", rank, p));
279:           commp = commz;
280:         }
281:         /* Zoom to coarse patch */
282:         lower.i = i;
283:         lower.j = j;
284:         lower.k = k;
285:         upper.i = i + patchSize.i;
286:         upper.j = j + patchSize.j;
287:         upper.k = k + patchSize.k;
288:         PetscCall(DMPatchZoom(dmc, lower, upper, commp, &dmz, &sfz, &sfzr));
289:         lower.c = 0; /* initialize member, otherwise compiler issues warnings */
290:         upper.c = 0; /* initialize member, otherwise compiler issues warnings */
291:         if (debug)
292:           PetscCall(PetscPrintf(comm, "Patch %" PetscInt_FMT ": (%" PetscInt_FMT ", %" PetscInt_FMT ", %" PetscInt_FMT ")--(%" PetscInt_FMT ", %" PetscInt_FMT ", %" PetscInt_FMT ")\n", p, lower.i, lower.j, lower.k, upper.i, upper.j, upper.k));
293:         if (dmz) PetscCall(DMView(dmz, PETSC_VIEWER_STDOUT_(commz)));
294:         PetscCall(PetscSFView(sfz, PETSC_VIEWER_STDOUT_(comm)));
295:         PetscCall(PetscSFView(sfzr, PETSC_VIEWER_STDOUT_(comm)));
296:         /* Scatter Xcoarse -> Xzoom */
297:         if (dmz) PetscCall(DMGetGlobalVector(dmz, &XZ));
298:         if (XZ) PetscCall(VecGetArray(XZ, &xzarray));
299:         PetscCall(VecGetArray(XC, &xcarray));
300:         PetscCall(PetscSFBcastBegin(sfz, MPIU_SCALAR, xcarray, xzarray, MPI_REPLACE));
301:         PetscCall(PetscSFBcastEnd(sfz, MPIU_SCALAR, xcarray, xzarray, MPI_REPLACE));
302:         PetscCall(VecRestoreArray(XC, &xcarray));
303:         if (XZ) PetscCall(VecRestoreArray(XZ, &xzarray));
304: #if 0
305:         /* Interpolate Xzoom -> Xfine, note that this may be on subcomms */
306:         PetscCall(DMRefine(dmz, MPI_COMM_NULL, &dmf));
307:         PetscCall(DMCreateInterpolation(dmz, dmf, &interpz, NULL));
308:         PetscCall(DMInterpolate(dmz, interpz, dmf));
309:         /* Smooth Xfine using two-step smoother, normal smoother plus Kaczmarz---moves back and forth from dmzoom to dmfine */
310:         /* Compute residual Rfine */
311:         /* Restrict Rfine to Rzoom_restricted */
312: #endif
313:         /* Scatter Rzoom_restricted -> Rcoarse_restricted */
314:         if (XZ) PetscCall(VecGetArray(XZ, &xzarray));
315:         PetscCall(VecGetArray(XC, &xcarray));
316:         PetscCall(PetscSFReduceBegin(sfzr, MPIU_SCALAR, xzarray, xcarray, MPIU_SUM));
317:         PetscCall(PetscSFReduceEnd(sfzr, MPIU_SCALAR, xzarray, xcarray, MPIU_SUM));
318:         PetscCall(VecRestoreArray(XC, &xcarray));
319:         if (XZ) PetscCall(VecRestoreArray(XZ, &xzarray));
320:         if (dmz) PetscCall(DMRestoreGlobalVector(dmz, &XZ));
321:         /* Compute global residual Rcoarse */
322:         /* TauCoarse = Rcoarse - Rcoarse_restricted */

324:         PetscCall(PetscSFDestroy(&sfz));
325:         PetscCall(PetscSFDestroy(&sfzr));
326:         PetscCall(DMDestroy(&dmz));
327:       }
328:     }
329:   }
330:   PetscCall(DMRestoreGlobalVector(dmc, &XC));
331:   PetscFunctionReturn(PETSC_SUCCESS);
332: }

334: static PetscErrorCode DMPatchView_ASCII(DM dm, PetscViewer viewer)
335: {
336:   DM_Patch         *mesh = (DM_Patch *)dm->data;
337:   PetscViewerFormat format;
338:   const char       *name;

340:   PetscFunctionBegin;
341:   PetscCall(PetscViewerGetFormat(viewer, &format));
342:   /* if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) */
343:   PetscCall(PetscObjectGetName((PetscObject)dm, &name));
344:   PetscCall(PetscViewerASCIIPrintf(viewer, "Patch DM %s\n", name));
345:   PetscCall(PetscViewerASCIIPushTab(viewer));
346:   PetscCall(PetscViewerASCIIPrintf(viewer, "Coarse DM\n"));
347:   PetscCall(DMView(mesh->dmCoarse, viewer));
348:   PetscCall(PetscViewerASCIIPopTab(viewer));
349:   PetscFunctionReturn(PETSC_SUCCESS);
350: }

352: PetscErrorCode DMView_Patch(DM dm, PetscViewer viewer)
353: {
354:   PetscBool isascii, isbinary;

356:   PetscFunctionBegin;
359:   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
360:   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERBINARY, &isbinary));
361:   if (isascii) PetscCall(DMPatchView_ASCII(dm, viewer));
362:   PetscFunctionReturn(PETSC_SUCCESS);
363: }

365: PetscErrorCode DMDestroy_Patch(DM dm)
366: {
367:   DM_Patch *mesh = (DM_Patch *)dm->data;

369:   PetscFunctionBegin;
370:   if (--mesh->refct > 0) PetscFunctionReturn(PETSC_SUCCESS);
371:   PetscCall(DMDestroy(&mesh->dmCoarse));
372:   /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */
373:   PetscCall(PetscFree(mesh));
374:   PetscFunctionReturn(PETSC_SUCCESS);
375: }

377: PetscErrorCode DMSetUp_Patch(DM dm)
378: {
379:   DM_Patch *mesh = (DM_Patch *)dm->data;

381:   PetscFunctionBegin;
383:   PetscCall(DMSetUp(mesh->dmCoarse));
384:   PetscFunctionReturn(PETSC_SUCCESS);
385: }

387: PetscErrorCode DMCreateGlobalVector_Patch(DM dm, Vec *g)
388: {
389:   DM_Patch *mesh = (DM_Patch *)dm->data;

391:   PetscFunctionBegin;
393:   PetscCall(DMCreateGlobalVector(mesh->dmCoarse, g));
394:   PetscFunctionReturn(PETSC_SUCCESS);
395: }

397: PetscErrorCode DMCreateLocalVector_Patch(DM dm, Vec *l)
398: {
399:   DM_Patch *mesh = (DM_Patch *)dm->data;

401:   PetscFunctionBegin;
403:   PetscCall(DMCreateLocalVector(mesh->dmCoarse, l));
404:   PetscFunctionReturn(PETSC_SUCCESS);
405: }

407: PetscErrorCode DMCreateSubDM_Patch(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm)
408: {
409:   SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Tell me to code this");
410: }

412: /*@
413:   DMPatchGetCoarse - Get the coarse `DM` associated with a `DMPATCH`

415:   Not Collective

417:   Input Parameter:
418: . dm - the `DMPATCH`

420:   Output Parameter:
421: . dmCoarse - the coarse `DM`

423:   Level: intermediate

425: .seealso: `DMPATCH`, `DMPatchCreate()`, `DMPatchZoom()`
426: @*/
427: PetscErrorCode DMPatchGetCoarse(DM dm, DM *dmCoarse)
428: {
429:   DM_Patch *mesh = (DM_Patch *)dm->data;

431:   PetscFunctionBegin;
433:   *dmCoarse = mesh->dmCoarse;
434:   PetscFunctionReturn(PETSC_SUCCESS);
435: }

437: /*@
438:   DMPatchGetPatchSize - Get the size of a single patch of a `DMPATCH`, in grid cells

440:   Not Collective

442:   Input Parameter:
443: . dm - the `DMPATCH`

445:   Output Parameter:
446: . patchSize - a `MatStencil` whose `i`, `j`, `k`, `c` fields hold the patch extent in each dimension

448:   Level: intermediate

450: .seealso: `DMPATCH`, `DMPatchSetPatchSize()`, `DMPatchGetCommSize()`, `MatStencil`
451: @*/
452: PetscErrorCode DMPatchGetPatchSize(DM dm, MatStencil *patchSize)
453: {
454:   DM_Patch *mesh = (DM_Patch *)dm->data;

456:   PetscFunctionBegin;
458:   PetscAssertPointer(patchSize, 2);
459:   *patchSize = mesh->patchSize;
460:   PetscFunctionReturn(PETSC_SUCCESS);
461: }

463: /*@
464:   DMPatchSetPatchSize - Set the size of a single patch of a `DMPATCH`, in grid cells

466:   Logically Collective

468:   Input Parameters:
469: + dm        - the `DMPATCH`
470: - patchSize - a `MatStencil` whose `i`, `j`, `k`, `c` fields hold the patch extent in each dimension

472:   Level: intermediate

474: .seealso: `DMPATCH`, `DMPatchGetPatchSize()`, `DMPatchSetCommSize()`, `MatStencil`
475: @*/
476: PetscErrorCode DMPatchSetPatchSize(DM dm, MatStencil patchSize)
477: {
478:   DM_Patch *mesh = (DM_Patch *)dm->data;

480:   PetscFunctionBegin;
482:   mesh->patchSize = patchSize;
483:   PetscFunctionReturn(PETSC_SUCCESS);
484: }

486: /*@
487:   DMPatchGetCommSize - Get the process grid used for each patch of a `DMPATCH`

489:   Not Collective

491:   Input Parameter:
492: . dm - the `DMPATCH`

494:   Output Parameter:
495: . commSize - a `MatStencil` whose `i`, `j`, `k` fields hold the number of processes used per patch in each dimension

497:   Level: intermediate

499: .seealso: `DMPATCH`, `DMPatchSetCommSize()`, `DMPatchGetPatchSize()`, `MatStencil`
500: @*/
501: PetscErrorCode DMPatchGetCommSize(DM dm, MatStencil *commSize)
502: {
503:   DM_Patch *mesh = (DM_Patch *)dm->data;

505:   PetscFunctionBegin;
507:   PetscAssertPointer(commSize, 2);
508:   *commSize = mesh->commSize;
509:   PetscFunctionReturn(PETSC_SUCCESS);
510: }

512: /*@
513:   DMPatchSetCommSize - Set the process grid used for each patch of a `DMPATCH`

515:   Logically Collective

517:   Input Parameters:
518: + dm       - the `DMPATCH`
519: - commSize - a `MatStencil` whose `i`, `j`, `k` fields hold the number of processes to use per patch in each dimension

521:   Level: intermediate

523: .seealso: `DMPATCH`, `DMPatchGetCommSize()`, `DMPatchSetPatchSize()`, `MatStencil`
524: @*/
525: PetscErrorCode DMPatchSetCommSize(DM dm, MatStencil commSize)
526: {
527:   DM_Patch *mesh = (DM_Patch *)dm->data;

529:   PetscFunctionBegin;
531:   mesh->commSize = commSize;
532:   PetscFunctionReturn(PETSC_SUCCESS);
533: }