Actual source code: misk.c

  1: #include <petsc/private/matimpl.h>
  2: #include <../src/mat/impls/aij/seq/aij.h>
  3: #include <../src/mat/impls/aij/mpi/mpiaij.h>
  4: #include <petscsf.h>

  6: #define MIS_NOT_DONE       -2
  7: #define MIS_DELETED        -1
  8: #define MIS_REMOVED        -3
  9: #define MIS_IS_SELECTED(s) (s >= 0)

 11: /* edge for priority queue */
 12: typedef struct edge_tag {
 13:   PetscReal weight;
 14:   PetscInt  lid0, gid1, cpid1;
 15: } Edge;

 17: static PetscErrorCode PetscCoarsenDataView_private(PetscCoarsenData *agg_lists, PetscViewer viewer)
 18: {
 19:   PetscCDIntNd *pos, *pos2;

 21:   PetscFunctionBegin;
 22:   for (PetscInt kk = 0; kk < agg_lists->size; kk++) {
 23:     PetscCall(PetscCDGetHeadPos(agg_lists, kk, &pos));
 24:     if ((pos2 = pos)) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "selected local %" PetscInt_FMT ": ", kk));
 25:     while (pos) {
 26:       PetscInt gid1;
 27:       PetscCall(PetscCDIntNdGetID(pos, &gid1));
 28:       PetscCall(PetscCDGetNextPos(agg_lists, kk, &pos));
 29:       PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, " %" PetscInt_FMT " ", gid1));
 30:     }
 31:     if (pos2) PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "\n"));
 32:   }
 33:   PetscFunctionReturn(PETSC_SUCCESS);
 34: }

 36: /*
 37:   MatCoarsenApply_MISK_private - parallel heavy edge matching

 39:   Input Parameter:
 40:    . perm - permutation
 41:    . Gmat - global matrix of graph (data not defined)

 43:   Output Parameter:
 44:    . a_locals_llist - array of list of local nodes rooted at local node
 45: */
 46: static PetscErrorCode MatCoarsenApply_MISK_private(IS perm, const PetscInt misk, Mat Gmat, PetscCoarsenData **a_locals_llist)
 47: {
 48:   PetscBool   isMPI;
 49:   MPI_Comm    comm;
 50:   PetscMPIInt rank, size;
 51:   Mat         cMat, Prols[5], Rtot;
 52:   PetscScalar one = 1;

 54:   PetscFunctionBegin;
 57:   PetscAssertPointer(a_locals_llist, 4);
 58:   PetscCheck(misk < 5 && misk > 0, PETSC_COMM_SELF, PETSC_ERR_SUP, "too many/few levels: %" PetscInt_FMT, misk);
 59:   PetscCall(PetscObjectBaseTypeCompare((PetscObject)Gmat, MATMPIAIJ, &isMPI));
 60:   PetscCall(PetscObjectGetComm((PetscObject)Gmat, &comm));
 61:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
 62:   PetscCallMPI(MPI_Comm_size(comm, &size));
 63:   PetscCall(PetscInfo(Gmat, "misk %" PetscInt_FMT "\n", misk));
 64:   /* make a copy of the graph, this gets destroyed in iterates */
 65:   if (misk > 1) PetscCall(MatDuplicate(Gmat, MAT_COPY_VALUES, &cMat));
 66:   else cMat = Gmat;
 67:   for (PetscInt iterIdx = 0; iterIdx < misk; iterIdx++) {
 68:     Mat_SeqAIJ       *matA, *matB = NULL;
 69:     Mat_MPIAIJ       *mpimat = NULL;
 70:     const PetscInt   *perm_ix;
 71:     const PetscInt    nloc_inner = cMat->rmap->n;
 72:     PetscCoarsenData *agg_lists;
 73:     PetscInt         *cpcol_gid = NULL, *cpcol_state, *lid_cprowID, *lid_state, *lid_parent_gid = NULL;
 74:     PetscInt          num_fine_ghosts, kk, n, ix, j, *idx, *ai, Iend, my0, nremoved, gid, cpid, lidj, sgid, t1, t2, slid, nDone, nselected = 0, state;
 75:     PetscBool        *lid_removed, isOK;
 76:     PetscSF           sf;

 78:     if (isMPI) {
 79:       mpimat = (Mat_MPIAIJ *)cMat->data;
 80:       matA   = (Mat_SeqAIJ *)mpimat->A->data;
 81:       matB   = (Mat_SeqAIJ *)mpimat->B->data;
 82:       /* force compressed storage of B */
 83:       PetscCall(MatCheckCompressedRow(mpimat->B, matB->nonzerorowcnt, &matB->compressedrow, matB->i, cMat->rmap->n, -1.0));
 84:     } else {
 85:       PetscBool isAIJ;

 87:       matA = (Mat_SeqAIJ *)cMat->data;
 88:       PetscCall(PetscObjectBaseTypeCompare((PetscObject)cMat, MATSEQAIJ, &isAIJ));
 89:       PetscCheck(isAIJ, PETSC_COMM_SELF, PETSC_ERR_USER, "Require AIJ matrix.");
 90:     }
 91:     PetscCall(MatGetOwnershipRange(cMat, &my0, &Iend));
 92:     if (isMPI) {
 93:       PetscInt *lid_gid;

 95:       PetscCall(PetscMalloc1(nloc_inner, &lid_gid)); /* explicit array needed */
 96:       for (kk = 0, gid = my0; kk < nloc_inner; kk++, gid++) lid_gid[kk] = gid;
 97:       PetscCall(VecGetLocalSize(mpimat->lvec, &num_fine_ghosts));
 98:       PetscCall(PetscMalloc2(num_fine_ghosts, &cpcol_gid, num_fine_ghosts, &cpcol_state));
 99:       PetscCall(MatGetMultPetscSF(cMat, &sf));
100:       PetscCall(PetscSFBcastBegin(sf, MPIU_INT, lid_gid, cpcol_gid, MPI_REPLACE));
101:       PetscCall(PetscSFBcastEnd(sf, MPIU_INT, lid_gid, cpcol_gid, MPI_REPLACE));
102:       for (kk = 0; kk < num_fine_ghosts; kk++) cpcol_state[kk] = MIS_NOT_DONE;
103:       PetscCall(PetscFree(lid_gid));
104:     } else num_fine_ghosts = 0;

106:     PetscCall(PetscMalloc4(nloc_inner, &lid_cprowID, nloc_inner, &lid_removed, nloc_inner, &lid_parent_gid, nloc_inner, &lid_state));
107:     PetscCall(PetscCDCreate(nloc_inner, &agg_lists));
108:     /* need an inverse map - locals */
109:     for (kk = 0; kk < nloc_inner; kk++) {
110:       lid_cprowID[kk]    = -1;
111:       lid_removed[kk]    = PETSC_FALSE;
112:       lid_parent_gid[kk] = -1.0;
113:       lid_state[kk]      = MIS_NOT_DONE;
114:     }
115:     /* set index into cmpressed row 'lid_cprowID' */
116:     if (matB) {
117:       for (ix = 0; ix < matB->compressedrow.nrows; ix++) {
118:         const PetscInt lid = matB->compressedrow.rindex[ix];
119:         if (lid >= 0) lid_cprowID[lid] = ix;
120:       }
121:     }
122:     /* MIS */
123:     nremoved = nDone = 0;
124:     if (!iterIdx) PetscCall(ISGetIndices(perm, &perm_ix)); // use permutation on first MIS
125:     else perm_ix = NULL;
126:     while (nDone < nloc_inner || PETSC_TRUE) { /* asynchronous not implemented */
127:       /* check all vertices */
128:       for (kk = 0; kk < nloc_inner; kk++) {
129:         const PetscInt lid = perm_ix ? perm_ix[kk] : kk;
130:         state              = lid_state[lid];
131:         if (iterIdx == 0 && lid_removed[lid]) continue;
132:         if (state == MIS_NOT_DONE) {
133:           /* parallel test, delete if selected ghost */
134:           isOK = PETSC_TRUE;
135:           /* parallel test */
136:           if ((ix = lid_cprowID[lid]) != -1) { /* if I have any ghost neighbors */
137:             ai  = matB->compressedrow.i;
138:             n   = ai[ix + 1] - ai[ix];
139:             idx = matB->j + ai[ix];
140:             for (j = 0; j < n; j++) {
141:               cpid = idx[j]; /* compressed row ID in B mat */
142:               gid  = cpcol_gid[cpid];
143:               if (cpcol_state[cpid] == MIS_NOT_DONE && gid >= Iend) { /* or pe>rank */
144:                 isOK = PETSC_FALSE;                                   /* can not delete */
145:                 break;
146:               }
147:             }
148:           }
149:           if (isOK) { /* select or remove this vertex if it is a true singleton like a BC */
150:             nDone++;
151:             /* check for singleton */
152:             ai = matA->i;
153:             n  = ai[lid + 1] - ai[lid];
154:             if (n < 2) {
155:               /* if I have any ghost adj then not a singleton */
156:               ix = lid_cprowID[lid];
157:               if (ix == -1 || !(matB->compressedrow.i[ix + 1] - matB->compressedrow.i[ix])) {
158:                 if (iterIdx == 0) {
159:                   lid_removed[lid] = PETSC_TRUE;
160:                   nremoved++; // let it get selected
161:                 }
162:                 // PetscCall(PetscCDAppendID(agg_lists, lid, lid + my0));
163:                 // lid_state[lid] = nselected; // >= 0  is selected, cache for ordering coarse grid
164:                 /* should select this because it is technically in the MIS but lets not */
165:                 continue; /* one local adj (me) and no ghost - singleton */
166:               }
167:             }
168:             /* SELECTED state encoded with global index */
169:             lid_state[lid] = nselected; // >= 0  is selected, cache for ordering coarse grid
170:             nselected++;
171:             PetscCall(PetscCDAppendID(agg_lists, lid, lid + my0));
172:             /* delete local adj */
173:             idx = matA->j + ai[lid];
174:             for (j = 0; j < n; j++) {
175:               lidj = idx[j];
176:               if (lid_state[lidj] == MIS_NOT_DONE) {
177:                 nDone++;
178:                 PetscCall(PetscCDAppendID(agg_lists, lid, lidj + my0));
179:                 lid_state[lidj] = MIS_DELETED; /* delete this */
180:               }
181:             }
182:           } /* selected */
183:         } /* not done vertex */
184:       } /* vertex loop */

186:       /* update ghost states and count todos */
187:       if (isMPI) {
188:         /* scatter states, check for done */
189:         PetscCall(PetscSFBcastBegin(sf, MPIU_INT, lid_state, cpcol_state, MPI_REPLACE));
190:         PetscCall(PetscSFBcastEnd(sf, MPIU_INT, lid_state, cpcol_state, MPI_REPLACE));
191:         ai = matB->compressedrow.i;
192:         for (ix = 0; ix < matB->compressedrow.nrows; ix++) {
193:           const PetscInt lidj = matB->compressedrow.rindex[ix]; /* local boundary node */
194:           state               = lid_state[lidj];
195:           if (state == MIS_NOT_DONE) {
196:             /* look at ghosts */
197:             n   = ai[ix + 1] - ai[ix];
198:             idx = matB->j + ai[ix];
199:             for (j = 0; j < n; j++) {
200:               cpid = idx[j];                            /* compressed row ID in B mat */
201:               if (MIS_IS_SELECTED(cpcol_state[cpid])) { /* lid is now deleted by ghost */
202:                 nDone++;
203:                 lid_state[lidj]      = MIS_DELETED; /* delete this */
204:                 sgid                 = cpcol_gid[cpid];
205:                 lid_parent_gid[lidj] = sgid; /* keep track of proc that I belong to */
206:                 break;
207:               }
208:             }
209:           }
210:         }
211:         /* all done? */
212:         t1 = nloc_inner - nDone;
213:         PetscCallMPI(MPIU_Allreduce(&t1, &t2, 1, MPIU_INT, MPI_SUM, comm)); /* synchronous version */
214:         if (!t2) break;
215:       } else break; /* no mpi - all done */
216:     } /* outer parallel MIS loop */
217:     if (!iterIdx) PetscCall(ISRestoreIndices(perm, &perm_ix));
218:     PetscCall(PetscInfo(Gmat, "\t removed %" PetscInt_FMT " of %" PetscInt_FMT " vertices.  %" PetscInt_FMT " selected.\n", nremoved, nloc_inner, nselected));

220:     /* tell adj who my lid_parent_gid vertices belong to - fill in agg_lists selected ghost lists */
221:     if (matB) {
222:       PetscInt *cpcol_sel_gid, *icpcol_gid;

224:       /* need to copy this to free buffer -- should do this globally */
225:       PetscCall(PetscMalloc2(num_fine_ghosts, &icpcol_gid, num_fine_ghosts, &cpcol_sel_gid));
226:       for (cpid = 0; cpid < num_fine_ghosts; cpid++) icpcol_gid[cpid] = cpcol_gid[cpid];
227:       /* get proc of deleted ghost */
228:       PetscCall(PetscSFBcastBegin(sf, MPIU_INT, lid_parent_gid, cpcol_sel_gid, MPI_REPLACE));
229:       PetscCall(PetscSFBcastEnd(sf, MPIU_INT, lid_parent_gid, cpcol_sel_gid, MPI_REPLACE));
230:       for (cpid = 0; cpid < num_fine_ghosts; cpid++) {
231:         sgid = cpcol_sel_gid[cpid];
232:         gid  = icpcol_gid[cpid];
233:         if (sgid >= my0 && sgid < Iend) { /* I own this deleted */
234:           slid = sgid - my0;
235:           PetscCall(PetscCDAppendID(agg_lists, slid, gid));
236:         }
237:       }
238:       // done - cleanup
239:       PetscCall(PetscFree2(icpcol_gid, cpcol_sel_gid));
240:       PetscCall(PetscFree2(cpcol_gid, cpcol_state));
241:     }
242:     PetscCall(PetscFree4(lid_cprowID, lid_removed, lid_parent_gid, lid_state));

244:     /* MIS done - make projection matrix - P */
245:     MatType jtype;
246:     PetscCall(MatGetType(Gmat, &jtype));
247:     PetscCall(MatCreate(comm, &Prols[iterIdx]));
248:     PetscCall(MatSetType(Prols[iterIdx], jtype));
249:     PetscCall(MatSetSizes(Prols[iterIdx], nloc_inner, nselected, PETSC_DETERMINE, PETSC_DETERMINE));
250:     PetscCall(MatSeqAIJSetPreallocation(Prols[iterIdx], 1, NULL));
251:     PetscCall(MatMPIAIJSetPreallocation(Prols[iterIdx], 1, NULL, 1, NULL));
252:     {
253:       PetscCDIntNd *pos, *pos2;
254:       PetscInt      colIndex, Iend, fgid;

256:       PetscCall(MatGetOwnershipRangeColumn(Prols[iterIdx], &colIndex, &Iend));
257:       // TODO - order with permutation in lid_selected (reversed)
258:       for (PetscInt lid = 0; lid < agg_lists->size; lid++) {
259:         PetscCall(PetscCDGetHeadPos(agg_lists, lid, &pos));
260:         pos2 = pos;
261:         while (pos) {
262:           PetscCall(PetscCDIntNdGetID(pos, &fgid));
263:           PetscCall(PetscCDGetNextPos(agg_lists, lid, &pos));
264:           PetscCall(MatSetValues(Prols[iterIdx], 1, &fgid, 1, &colIndex, &one, INSERT_VALUES));
265:         }
266:         if (pos2) colIndex++;
267:       }
268:       PetscCheck(Iend == colIndex, PETSC_COMM_SELF, PETSC_ERR_SUP, "Iend!=colIndex: %" PetscInt_FMT " %" PetscInt_FMT, Iend, colIndex);
269:     }
270:     PetscCall(MatAssemblyBegin(Prols[iterIdx], MAT_FINAL_ASSEMBLY));
271:     PetscCall(MatAssemblyEnd(Prols[iterIdx], MAT_FINAL_ASSEMBLY));
272:     /* project to make new graph for next MIS, skip if last */
273:     if (iterIdx < misk - 1) {
274:       Mat new_mat;
275:       PetscCall(MatPtAP(cMat, Prols[iterIdx], MAT_INITIAL_MATRIX, PETSC_DETERMINE, &new_mat));
276:       PetscCall(MatDestroy(&cMat));
277:       cMat = new_mat; // next iter
278:     } else if (cMat != Gmat) PetscCall(MatDestroy(&cMat));
279:     // cleanup
280:     PetscCall(PetscCDDestroy(agg_lists));
281:   } /* MIS-k iteration */
282:   /* make total prolongator Rtot = P_0 * P_1 * ... */
283:   Rtot = Prols[misk - 1]; // compose P then transpose to get R
284:   for (PetscInt iterIdx = misk - 1; iterIdx > 0; iterIdx--) {
285:     Mat P;

287:     PetscCall(MatMatMult(Prols[iterIdx - 1], Rtot, MAT_INITIAL_MATRIX, PETSC_CURRENT, &P));
288:     PetscCall(MatDestroy(&Prols[iterIdx - 1]));
289:     PetscCall(MatDestroy(&Rtot));
290:     Rtot = P;
291:   }
292:   PetscCall(MatTranspose(Rtot, MAT_INPLACE_MATRIX, &Rtot)); // R now
293:   PetscCall(MatViewFromOptions(Rtot, NULL, "-misk_aggregation_view"));
294:   /* make aggregates with Rtot - could use Rtot directly in theory but have to go through the aggregate list data structure */
295:   {
296:     PetscInt          Istart, Iend, ncols, NN, MM, jj = 0, max_osz = 0;
297:     const PetscInt    nloc = Gmat->rmap->n;
298:     PetscCoarsenData *agg_lists;
299:     Mat               mat;

301:     PetscCall(PetscCDCreate(nloc, &agg_lists));
302:     *a_locals_llist = agg_lists; // return
303:     PetscCall(MatGetOwnershipRange(Rtot, &Istart, &Iend));
304:     for (PetscInt grow = Istart, lid = 0; grow < Iend; grow++, lid++) {
305:       const PetscInt *idx;

307:       PetscCall(MatGetRow(Rtot, grow, &ncols, &idx, NULL));
308:       for (PetscInt jj = 0; jj < ncols; jj++) {
309:         PetscInt gcol = idx[jj];

311:         PetscCall(PetscCDAppendID(agg_lists, lid, gcol)); // local row, global column
312:       }
313:       PetscCall(MatRestoreRow(Rtot, grow, &ncols, &idx, NULL));
314:     }
315:     PetscCall(MatDestroy(&Rtot));

317:     /* make fake matrix, get largest nnz */
318:     for (PetscInt lid = 0; lid < nloc; lid++) {
319:       PetscCall(PetscCDCountAt(agg_lists, lid, &jj));
320:       if (jj > max_osz) max_osz = jj;
321:     }
322:     PetscCall(MatGetSize(Gmat, &MM, &NN));
323:     if (max_osz > MM - nloc) max_osz = MM - nloc;
324:     PetscCall(MatGetOwnershipRange(Gmat, &Istart, NULL));
325:     /* matrix of ghost adj for square graph */
326:     PetscCall(MatCreateAIJ(comm, nloc, nloc, PETSC_DETERMINE, PETSC_DETERMINE, 0, NULL, max_osz, NULL, &mat));
327:     for (PetscInt lid = 0, gidi = Istart; lid < nloc; lid++, gidi++) {
328:       PetscCDIntNd *pos;

330:       PetscCall(PetscCDGetHeadPos(agg_lists, lid, &pos));
331:       while (pos) {
332:         PetscInt gidj;

334:         PetscCall(PetscCDIntNdGetID(pos, &gidj));
335:         PetscCall(PetscCDGetNextPos(agg_lists, lid, &pos));
336:         if (gidj < Istart || gidj >= Istart + nloc) PetscCall(MatSetValues(mat, 1, &gidi, 1, &gidj, &one, ADD_VALUES));
337:       }
338:     }
339:     PetscCall(MatAssemblyBegin(mat, MAT_FINAL_ASSEMBLY));
340:     PetscCall(MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY));
341:     PetscCall(PetscCDSetMat(agg_lists, mat));
342:   }
343:   PetscFunctionReturn(PETSC_SUCCESS);
344: }

346: /*
347:    Distance k MIS. k is in 'subctx'
348: */
349: static PetscErrorCode MatCoarsenApply_MISK(MatCoarsen coarse)
350: {
351:   Mat      mat = coarse->graph;
352:   PetscInt k;

354:   PetscFunctionBegin;
355:   PetscCall(MatCoarsenMISKGetDistance(coarse, &k));
356:   PetscCheck(k > 0, PETSC_COMM_SELF, PETSC_ERR_SUP, "too few levels: %" PetscInt_FMT, k);
357:   if (!coarse->perm) {
358:     IS       perm;
359:     PetscInt n, m;

361:     PetscCall(MatGetLocalSize(mat, &m, &n));
362:     PetscCall(ISCreateStride(PetscObjectComm((PetscObject)mat), m, 0, 1, &perm));
363:     PetscCall(MatCoarsenApply_MISK_private(perm, k, mat, &coarse->agg_lists));
364:     PetscCall(ISDestroy(&perm));
365:   } else {
366:     PetscCall(MatCoarsenApply_MISK_private(coarse->perm, k, mat, &coarse->agg_lists));
367:   }
368:   PetscFunctionReturn(PETSC_SUCCESS);
369: }

371: static PetscErrorCode MatCoarsenView_MISK(MatCoarsen coarse, PetscViewer viewer)
372: {
373:   PetscMPIInt       rank;
374:   PetscBool         isascii;
375:   PetscViewerFormat format;

377:   PetscFunctionBegin;
378:   PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)coarse), &rank));
379:   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
380:   PetscCall(PetscViewerGetFormat(viewer, &format));
381:   if (isascii && format == PETSC_VIEWER_ASCII_INFO_DETAIL && coarse->agg_lists) {
382:     PetscCall(PetscViewerASCIIPushSynchronized(viewer));
383:     PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "  [%d] MISK aggregator\n", rank));
384:     if (!rank) PetscCall(PetscCoarsenDataView_private(coarse->agg_lists, viewer));
385:     PetscCall(PetscViewerFlush(viewer));
386:     PetscCall(PetscViewerASCIIPopSynchronized(viewer));
387:   }
388:   PetscFunctionReturn(PETSC_SUCCESS);
389: }

391: static PetscErrorCode MatCoarsenSetFromOptions_MISK(MatCoarsen coarse, PetscOptionItems PetscOptionsObject)
392: {
393:   PetscInt  k = 1;
394:   PetscBool flg;

396:   PetscFunctionBegin;
397:   PetscOptionsHeadBegin(PetscOptionsObject, "MatCoarsen-MISk options");
398:   PetscCall(PetscOptionsInt("-mat_coarsen_misk_distance", "k distance for MIS", "", k, &k, &flg));
399:   if (flg) coarse->subctx = (void *)(size_t)k;
400:   PetscOptionsHeadEnd();
401:   PetscFunctionReturn(PETSC_SUCCESS);
402: }

404: /*MC
405:    MATCOARSENMISK - A coarsener that uses MISK, a simple greedy coarsener

407:    Level: beginner

409:    Options Database Key:
410: .   -mat_coarsen_misk_distance k - distance for MIS

412:    Note:
413:    When the coarsening is used inside `PCGAMG` then the options database key is `-pc_gamg_mat_coarsen_misk_distance`

415: .seealso: `MatCoarsen`, `MatCoarsenMISKSetDistance()`, `MatCoarsenApply()`, `MatCoarsenSetType()`, `MatCoarsenType`, `MatCoarsenCreate()`, `MATCOARSENHEM`, `MATCOARSENMIS`
416: M*/

418: PETSC_EXTERN PetscErrorCode MatCoarsenCreate_MISK(MatCoarsen coarse)
419: {
420:   PetscFunctionBegin;
421:   coarse->ops->apply          = MatCoarsenApply_MISK;
422:   coarse->ops->view           = MatCoarsenView_MISK;
423:   coarse->subctx              = (void *)(size_t)1;
424:   coarse->ops->setfromoptions = MatCoarsenSetFromOptions_MISK;
425:   PetscFunctionReturn(PETSC_SUCCESS);
426: }

428: /*@
429:   MatCoarsenMISKSetDistance - the distance to be used by MISK

431:   Collective

433:   Input Parameters:
434: + crs - the coarsen
435: - k   - the distance

437:   Options Database Key:
438: . -mat_coarsen_misk_distance k - distance for MIS

440:   Level: advanced

442:   Note:
443:   When the coarsening is used inside `PCGAMG` then the options database key is `-pc_gamg_mat_coarsen_misk_distance`

445: .seealso: `MATCOARSENMISK`, `MatCoarsen`, `MatCoarsenSetFromOptions()`, `MatCoarsenSetType()`, `MatCoarsenRegister()`, `MatCoarsenCreate()`,
446:           `MatCoarsenDestroy()`, `MatCoarsenSetAdjacency()`, `MatCoarsenMISKGetDistance()`,
447:           `MatCoarsenGetData()`
448: @*/
449: PetscErrorCode MatCoarsenMISKSetDistance(MatCoarsen crs, PetscInt k)
450: {
451:   PetscFunctionBegin;
452:   crs->subctx = (void *)(size_t)k;
453:   PetscFunctionReturn(PETSC_SUCCESS);
454: }

456: /*@
457:   MatCoarsenMISKGetDistance - gets the distance to be used by MISK

459:   Collective

461:   Input Parameter:
462: . crs - the coarsen

464:   Output Parameter:
465: . k - the distance

467:   Level: advanced

469: .seealso: `MATCOARSENMISK`, `MatCoarsen`, `MatCoarsenSetFromOptions()`, `MatCoarsenSetType()`,
470: `MatCoarsenRegister()`, `MatCoarsenCreate()`, `MatCoarsenDestroy()`,
471: `MatCoarsenSetAdjacency()`, `MatCoarsenGetData()`
472: @*/
473: PetscErrorCode MatCoarsenMISKGetDistance(MatCoarsen crs, PetscInt *k)
474: {
475:   PetscFunctionBegin;
476:   *k = (PetscInt)(size_t)crs->subctx;
477:   PetscFunctionReturn(PETSC_SUCCESS);
478: }