Actual source code: chaco.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

  2:  #include <../src/mat/impls/adj/mpi/mpiadj.h>

  4: #if defined(PETSC_HAVE_UNISTD_H)
  5: #include <unistd.h>
  6: #endif

  8: #if defined(PETSC_HAVE_CHACO_INT_ASSIGNMENT)
  9: #include <chaco.h>
 10: #else
 11: /* Older versions of Chaco do not have an include file */
 12: PETSC_EXTERN int interface(int nvtxs, int *start, int *adjacency, int *vwgts,
 13:                      float *ewgts, float *x, float *y, float *z, char *outassignname,
 14:                      char *outfilename, short *assignment, int architecture, int ndims_tot,
 15:                      int mesh_dims[3], double *goal, int global_method, int local_method,
 16:                      int rqi_flag, int vmax, int ndims, double eigtol, long seed);
 17: #endif

 19: extern int FREE_GRAPH;

 21: /*
 22: int       nvtxs;                number of vertices in full graph
 23: int      *start;                start of edge list for each vertex
 24: int      *adjacency;            edge list data
 25: int      *vwgts;                weights for all vertices
 26: float    *ewgts;                weights for all edges
 27: float    *x, *y, *z;            coordinates for inertial method
 28: char     *outassignname;        name of assignment output file
 29: char     *outfilename;          output file name
 30: short    *assignment;           set number of each vtx (length n)
 31: int       architecture;         0 => hypercube, d => d-dimensional mesh
 32: int       ndims_tot;            total number of cube dimensions to divide
 33: int       mesh_dims[3];         dimensions of mesh of processors
 34: double   *goal;                 desired set sizes for each set
 35: int       global_method;        global partitioning algorithm
 36: int       local_method;         local partitioning algorithm
 37: int       rqi_flag;             should I use RQI/Symmlq eigensolver?
 38: int       vmax;                 how many vertices to coarsen down to?
 39: int       ndims;                number of eigenvectors (2^d sets)
 40: double    eigtol;               tolerance on eigenvectors
 41: long      seed;                 for random graph mutations
 42: */

 44: typedef struct {
 45:   PetscBool         verbose;
 46:   PetscInt          eignum;
 47:   PetscReal         eigtol;
 48:   MPChacoGlobalType global_method;          /* global method */
 49:   MPChacoLocalType  local_method;           /* local method */
 50:   MPChacoEigenType  eigen_method;           /* eigensolver */
 51:   PetscInt          nbvtxcoarsed;           /* number of vertices for the coarse graph */
 52: } MatPartitioning_Chaco;

 54: #define SIZE_LOG 10000          /* size of buffer for mesg_log */

 56: static PetscErrorCode MatPartitioningApply_Chaco(MatPartitioning part,IS *partitioning)
 57: {
 58:   PetscErrorCode        ierr;
 59:   PetscInt              *parttab,*locals,i,nb_locals,M,N;
 60:   PetscMPIInt           size,rank;
 61:   Mat                   mat = part->adj,matAdj,matSeq,*A;
 62:   Mat_MPIAdj            *adj;
 63:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;
 64:   PetscBool             flg;
 65:   IS                    isrow, iscol;
 66:   int                   nvtxs,*start,*adjacency,*vwgts,architecture,ndims_tot;
 67:   int                   mesh_dims[3],global_method,local_method,rqi_flag,vmax,ndims;
 68: #if defined(PETSC_HAVE_CHACO_INT_ASSIGNMENT)
 69:   int                   *assignment;
 70: #else
 71:   short                 *assignment;
 72: #endif
 73:   double                eigtol;
 74:   long                  seed;
 75:   char                  *mesg_log;
 76: #if defined(PETSC_HAVE_UNISTD_H)
 77:   int                   fd_stdout,fd_pipe[2],count,err;
 78: #endif

 81:   FREE_GRAPH = 0; /* otherwise Chaco will attempt to free memory for adjacency graph */
 82:   MPI_Comm_size(PetscObjectComm((PetscObject)mat),&size);
 83:   MPI_Comm_rank(PetscObjectComm((PetscObject)mat),&rank);
 84:   PetscObjectTypeCompare((PetscObject)mat,MATMPIADJ,&flg);
 85:   if (size>1) {
 86:     if (flg) SETERRQ(PetscObjectComm((PetscObject)mat),PETSC_ERR_SUP,"Distributed matrix format MPIAdj is not supported for sequential partitioners");
 87:     PetscInfo(part,"Converting distributed matrix to sequential: this could be a performance loss\n");
 88:     MatGetSize(mat,&M,&N);
 89:     ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);
 90:     ISCreateStride(PETSC_COMM_SELF,N,0,1,&iscol);
 91:     MatCreateSubMatrices(mat,1,&isrow,&iscol,MAT_INITIAL_MATRIX,&A);
 92:     ISDestroy(&isrow);
 93:     ISDestroy(&iscol);
 94:     matSeq = *A;
 95:     PetscFree(A);
 96:   } else {
 97:     PetscObjectReference((PetscObject)mat);
 98:     matSeq = mat;
 99:   }

101:   if (!flg) { /* convert regular matrix to MPIADJ */
102:     MatConvert(matSeq,MATMPIADJ,MAT_INITIAL_MATRIX,&matAdj);
103:   } else {
104:     PetscObjectReference((PetscObject)matSeq);
105:     matAdj = matSeq;
106:   }

108:   adj = (Mat_MPIAdj*)matAdj->data;  /* finaly adj contains adjacency graph */

110:   /* arguments for Chaco library */
111:   nvtxs         = mat->rmap->N;           /* number of vertices in full graph */
112:   start         = adj->i;                 /* start of edge list for each vertex */
113:   vwgts         = part->vertex_weights;   /* weights for all vertices */
114:   architecture  = 1;                      /* 0 => hypercube, d => d-dimensional mesh */
115:   ndims_tot     = 0;                      /* total number of cube dimensions to divide */
116:   mesh_dims[0]  = part->n;                /* dimensions of mesh of processors */
117:   global_method = chaco->global_method;   /* global partitioning algorithm */
118:   local_method  = chaco->local_method;    /* local partitioning algorithm */
119:   rqi_flag      = chaco->eigen_method;    /* should I use RQI/Symmlq eigensolver? */
120:   vmax          = chaco->nbvtxcoarsed;    /* how many vertices to coarsen down to? */
121:   ndims         = chaco->eignum;          /* number of eigenvectors (2^d sets) */
122:   eigtol        = chaco->eigtol;          /* tolerance on eigenvectors */
123:   seed          = 123636512;              /* for random graph mutations */

125:   PetscMalloc1(mat->rmap->N,&assignment);
126:   PetscMalloc1(start[nvtxs],&adjacency);
127:   for (i=0; i<start[nvtxs]; i++) adjacency[i] = (adj->j)[i] + 1; /* 1-based indexing */

129:   /* redirect output to buffer */
130: #if defined(PETSC_HAVE_UNISTD_H)
131:   fd_stdout = dup(1);
132:   if (pipe(fd_pipe)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"Could not open pipe");
133:   close(1);
134:   dup2(fd_pipe[1],1);
135:   PetscMalloc1(SIZE_LOG,&mesg_log);
136: #endif

138:   /* library call */
139:   interface(nvtxs,start,adjacency,vwgts,NULL,NULL,NULL,NULL,
140:                    NULL,NULL,assignment,architecture,ndims_tot,mesh_dims,
141:                    NULL,global_method,local_method,rqi_flag,vmax,ndims,eigtol,seed);

143: #if defined(PETSC_HAVE_UNISTD_H)
144:   err = fflush(stdout);
145:   if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on stdout");
146:   count = read(fd_pipe[0],mesg_log,(SIZE_LOG-1)*sizeof(char));
147:   if (count<0) count = 0;
148:   mesg_log[count] = 0;
149:   close(1);
150:   dup2(fd_stdout,1);
151:   close(fd_stdout);
152:   close(fd_pipe[0]);
153:   close(fd_pipe[1]);
154:   if (chaco->verbose) {
155:     PetscPrintf(PetscObjectComm((PetscObject)mat),mesg_log);
156:   }
157:   PetscFree(mesg_log);
158: #endif
159:   if (ierr) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Chaco failed");

161:   PetscMalloc1(mat->rmap->N,&parttab);
162:   for (i=0; i<nvtxs; i++) parttab[i] = assignment[i];

164:   /* creation of the index set */
165:   nb_locals = mat->rmap->N / size;
166:   locals    = parttab + rank*nb_locals;
167:   if (rank < mat->rmap->N % size) {
168:     nb_locals++;
169:     locals += rank;
170:   } else locals += mat->rmap->N % size;

172:   ISCreateGeneral(PetscObjectComm((PetscObject)part),nb_locals,locals,PETSC_COPY_VALUES,partitioning);

174:   /* clean up */
175:   PetscFree(parttab);
176:   PetscFree(adjacency);
177:   PetscFree(assignment);
178:   MatDestroy(&matSeq);
179:   MatDestroy(&matAdj);
180:   return(0);
181: }

183: PetscErrorCode MatPartitioningView_Chaco(MatPartitioning part, PetscViewer viewer)
184: {
185:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;
186:   PetscErrorCode        ierr;
187:   PetscBool             isascii;

190:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
191:   if (isascii) {
192:     PetscViewerASCIIPrintf(viewer,"  Global method: %s\n",MPChacoGlobalTypes[chaco->global_method]);
193:     PetscViewerASCIIPrintf(viewer,"  Local method: %s\n",MPChacoLocalTypes[chaco->local_method]);
194:     PetscViewerASCIIPrintf(viewer,"  Number of vertices for the coarse graph: %d\n",chaco->nbvtxcoarsed);
195:     PetscViewerASCIIPrintf(viewer,"  Eigensolver: %s\n",MPChacoEigenTypes[chaco->eigen_method]);
196:     PetscViewerASCIIPrintf(viewer,"  Tolerance for eigensolver: %g\n",chaco->eigtol);
197:     PetscViewerASCIIPrintf(viewer,"  Number of eigenvectors: %d\n",chaco->eignum);
198:   }
199:   return(0);
200: }

202: /*@
203:    MatPartitioningChacoSetGlobal - Set global method for Chaco partitioner.

205:    Collective on MatPartitioning

207:    Input Parameters:
208: +  part - the partitioning context
209: -  method - one of MP_CHACO_MULTILEVEL, MP_CHACO_SPECTRAL, MP_CHACO_LINEAR,
210:             MP_CHACO_RANDOM or MP_CHACO_SCATTERED

212:    Options Database:
213: .  -mat_partitioning_chaco_global <method> - the global method

215:    Level: advanced

217:    Notes:
218:    The default is the multi-level method. See Chaco documentation for
219:    additional details.

221: .seealso: MatPartitioningChacoSetLocal(),MatPartitioningChacoGetGlobal()
222: @*/
223: PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning part,MPChacoGlobalType method)
224: {

230:   PetscTryMethod(part,"MatPartitioningChacoSetGlobal_C",(MatPartitioning,MPChacoGlobalType),(part,method));
231:   return(0);
232: }

234: PetscErrorCode MatPartitioningChacoSetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType method)
235: {
236:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

239:   switch (method) {
240:   case MP_CHACO_MULTILEVEL:
241:   case MP_CHACO_SPECTRAL:
242:   case MP_CHACO_LINEAR:
243:   case MP_CHACO_RANDOM:
244:   case MP_CHACO_SCATTERED:
245:     chaco->global_method = method; break;
246:   default:
247:     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
248:   }
249:   return(0);
250: }

252: /*@
253:    MatPartitioningChacoGetGlobal - Get global method for Chaco partitioner.

255:    Not Collective

257:    Input Parameter:
258: .  part - the partitioning context

260:    Output Parameter:
261: .  method - the method

263:    Level: advanced

265: .seealso: MatPartitioningChacoSetGlobal()
266: @*/
267: PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning part,MPChacoGlobalType *method)
268: {

274:   PetscTryMethod(part,"MatPartitioningChacoGetGlobal_C",(MatPartitioning,MPChacoGlobalType*),(part,method));
275:   return(0);
276: }

278: PetscErrorCode MatPartitioningChacoGetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType *method)
279: {
280:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

283:   *method = chaco->global_method;
284:   return(0);
285: }

287: /*@
288:    MatPartitioningChacoSetLocal - Set local method for Chaco partitioner.

290:    Collective on MatPartitioning

292:    Input Parameters:
293: +  part - the partitioning context
294: -  method - one of MP_CHACO_KERNIGHAN or MP_CHACO_NONE

296:    Options Database:
297: .  -mat_partitioning_chaco_local <method> - the local method

299:    Level: advanced

301:    Notes:
302:    The default is to apply the Kernighan-Lin heuristic. See Chaco documentation
303:    for additional details.

305: .seealso: MatPartitioningChacoSetGlobal(),MatPartitioningChacoGetLocal()
306: @*/
307: PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning part,MPChacoLocalType method)
308: {

314:   PetscTryMethod(part,"MatPartitioningChacoSetLocal_C",(MatPartitioning,MPChacoLocalType),(part,method));
315:   return(0);
316: }

318: PetscErrorCode MatPartitioningChacoSetLocal_Chaco(MatPartitioning part,MPChacoLocalType method)
319: {
320:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

323:   switch (method) {
324:   case MP_CHACO_KERNIGHAN:
325:   case MP_CHACO_NONE:
326:     chaco->local_method = method; break;
327:   default:
328:     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
329:   }
330:   return(0);
331: }

333: /*@
334:    MatPartitioningChacoGetLocal - Get local method for Chaco partitioner.

336:    Not Collective

338:    Input Parameter:
339: .  part - the partitioning context

341:    Output Parameter:
342: .  method - the method

344:    Level: advanced

346: .seealso: MatPartitioningChacoSetLocal()
347: @*/
348: PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning part,MPChacoLocalType *method)
349: {

355:   PetscUseMethod(part,"MatPartitioningChacoGetLocal_C",(MatPartitioning,MPChacoLocalType*),(part,method));
356:   return(0);
357: }

359: PetscErrorCode MatPartitioningChacoGetLocal_Chaco(MatPartitioning part,MPChacoLocalType *method)
360: {
361:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

364:   *method = chaco->local_method;
365:   return(0);
366: }

368: /*@
369:    MatPartitioningChacoSetCoarseLevel - Set the coarse level parameter for the
370:    Chaco partitioner.

372:    Collective on MatPartitioning

374:    Input Parameters:
375: +  part - the partitioning context
376: -  level - the coarse level in range [0.0,1.0]

378:    Options Database:
379: .  -mat_partitioning_chaco_coarse <l> - Coarse level

381:    Level: advanced
382: @*/
383: PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning part,PetscReal level)
384: {

390:   PetscTryMethod(part,"MatPartitioningChacoSetCoarseLevel_C",(MatPartitioning,PetscReal),(part,level));
391:   return(0);
392: }

394: PetscErrorCode MatPartitioningChacoSetCoarseLevel_Chaco(MatPartitioning part,PetscReal level)
395: {
396:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

399:   if (level<0.0 || level>1.0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Chaco: level of coarsening out of range [0.0-1.0]");
400:   chaco->nbvtxcoarsed = (PetscInt)(part->adj->cmap->N * level);
401:   if (chaco->nbvtxcoarsed < 20) chaco->nbvtxcoarsed = 20;
402:   return(0);
403: }

405: /*@
406:    MatPartitioningChacoSetEigenSolver - Set eigensolver method for Chaco partitioner.

408:    Collective on MatPartitioning

410:    Input Parameters:
411: +  part - the partitioning context
412: -  method - one of MP_CHACO_LANCZOS or MP_CHACO_RQI

414:    Options Database:
415: .  -mat_partitioning_chaco_eigen_solver <method> - the eigensolver

417:    Level: advanced

419:    Notes:
420:    The default is to use a Lanczos method. See Chaco documentation for details.

422: .seealso: MatPartitioningChacoSetEigenTol(),MatPartitioningChacoSetEigenNumber(),
423:           MatPartitioningChacoGetEigenSolver()
424: @*/
425: PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning part,MPChacoEigenType method)
426: {

432:   PetscTryMethod(part,"MatPartitioningChacoSetEigenSolver_C",(MatPartitioning,MPChacoEigenType),(part,method));
433:   return(0);
434: }

436: PetscErrorCode MatPartitioningChacoSetEigenSolver_Chaco(MatPartitioning part,MPChacoEigenType method)
437: {
438:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

441:   switch (method) {
442:   case MP_CHACO_LANCZOS:
443:   case MP_CHACO_RQI:
444:     chaco->eigen_method = method; break;
445:   default:
446:     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
447:   }
448:   return(0);
449: }

451: /*@
452:    MatPartitioningChacoGetEigenSolver - Get local method for Chaco partitioner.

454:    Not Collective

456:    Input Parameter:
457: .  part - the partitioning context

459:    Output Parameter:
460: .  method - the method

462:    Level: advanced

464: .seealso: MatPartitioningChacoSetEigenSolver()
465: @*/
466: PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning part,MPChacoEigenType *method)
467: {

473:   PetscUseMethod(part,"MatPartitioningChacoGetEigenSolver_C",(MatPartitioning,MPChacoEigenType*),(part,method));
474:   return(0);
475: }

477: PetscErrorCode MatPartitioningChacoGetEigenSolver_Chaco(MatPartitioning part,MPChacoEigenType *method)
478: {
479:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

482:   *method = chaco->eigen_method;
483:   return(0);
484: }

486: /*@
487:    MatPartitioningChacoSetEigenTol - Sets the tolerance for the eigensolver.

489:    Collective on MatPartitioning

491:    Input Parameters:
492: +  part - the partitioning context
493: -  tol  - the tolerance

495:    Options Database:
496: .  -mat_partitioning_chaco_eigen_tol <tol>: Tolerance for eigensolver

498:    Note:
499:    Must be positive. The default value is 0.001.

501:    Level: advanced

503: .seealso: MatPartitioningChacoSetEigenSolver(), MatPartitioningChacoGetEigenTol()
504: @*/
505: PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning part,PetscReal tol)
506: {

512:   PetscTryMethod(part,"MatPartitioningChacoSetEigenTol_C",(MatPartitioning,PetscReal),(part,tol));
513:   return(0);
514: }

516: PetscErrorCode MatPartitioningChacoSetEigenTol_Chaco(MatPartitioning part,PetscReal tol)
517: {
518:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

521:   if (tol==PETSC_DEFAULT) chaco->eigtol = 0.001;
522:   else {
523:     if (tol<=0.0) SETERRQ(PetscObjectComm((PetscObject)part),PETSC_ERR_ARG_OUTOFRANGE,"Tolerance must be positive");
524:     chaco->eigtol = tol;
525:   }
526:   return(0);
527: }

529: /*@
530:    MatPartitioningChacoGetEigenTol - Gets the eigensolver tolerance.

532:    Not Collective

534:    Input Parameter:
535: .  part - the partitioning context

537:    Output Parameter:
538: .  tol  - the tolerance

540:    Level: advanced

542: .seealso: MatPartitioningChacoSetEigenTol()
543: @*/
544: PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning part,PetscReal *tol)
545: {

551:   PetscUseMethod(part,"MatPartitioningChacoGetEigenTol_C",(MatPartitioning,PetscReal*),(part,tol));
552:   return(0);
553: }

555: PetscErrorCode MatPartitioningChacoGetEigenTol_Chaco(MatPartitioning part,PetscReal *tol)
556: {
557:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

560:   *tol = chaco->eigtol;
561:   return(0);
562: }

564: /*@
565:    MatPartitioningChacoSetEigenNumber - Sets the number of eigenvectors to compute
566:    during partitioning.

568:    Collective on MatPartitioning

570:    Input Parameters:
571: +  part - the partitioning context
572: -  num  - the number of eigenvectors

574:    Options Database:
575: .  -mat_partitioning_chaco_eigen_number <n>: Number of eigenvectors

577:    Note:
578:    Accepted values are 1, 2 or 3, indicating partitioning by bisection,
579:    quadrisection, or octosection.

581:    Level: advanced

583: .seealso: MatPartitioningChacoSetEigenSolver(), MatPartitioningChacoGetEigenTol()
584: @*/
585: PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning part,PetscInt num)
586: {

592:   PetscTryMethod(part,"MatPartitioningChacoSetEigenNumber_C",(MatPartitioning,PetscInt),(part,num));
593:   return(0);
594: }

596: PetscErrorCode MatPartitioningChacoSetEigenNumber_Chaco(MatPartitioning part,PetscInt num)
597: {
598:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

601:   if (num==PETSC_DEFAULT) chaco->eignum = 1;
602:   else {
603:     if (num<1 || num>3) SETERRQ(PetscObjectComm((PetscObject)part),PETSC_ERR_ARG_OUTOFRANGE,"Can only specify 1, 2 or 3 eigenvectors");
604:     chaco->eignum = num;
605:   }
606:   return(0);
607: }

609: /*@
610:    MatPartitioningChacoGetEigenNumber - Gets the number of eigenvectors used by Chaco.

612:    Not Collective

614:    Input Parameter:
615: .  part - the partitioning context

617:    Output Parameter:
618: .  num  - number of eigenvectors

620:    Level: advanced

622: .seealso: MatPartitioningChacoSetEigenNumber()
623: @*/
624: PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning part,PetscInt *num)
625: {

631:   PetscUseMethod(part,"MatPartitioningChacoGetEigenNumber_C",(MatPartitioning,PetscInt*),(part,num));
632:   return(0);
633: }

635: PetscErrorCode MatPartitioningChacoGetEigenNumber_Chaco(MatPartitioning part,PetscInt *num)
636: {
637:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

640:   *num = chaco->eignum;
641:   return(0);
642: }

644: PetscErrorCode MatPartitioningSetFromOptions_Chaco(PetscOptionItems *PetscOptionsObject,MatPartitioning part)
645: {
646:   PetscErrorCode        ierr;
647:   PetscInt              i;
648:   PetscReal             r;
649:   PetscBool             flag;
650:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;
651:   MPChacoGlobalType     global;
652:   MPChacoLocalType      local;
653:   MPChacoEigenType      eigen;

656:   PetscOptionsHead(PetscOptionsObject,"Chaco partitioning options");
657:   PetscOptionsEnum("-mat_partitioning_chaco_global","Global method","MatPartitioningChacoSetGlobal",MPChacoGlobalTypes,(PetscEnum)chaco->global_method,(PetscEnum*)&global,&flag);
658:   if (flag) { MatPartitioningChacoSetGlobal(part,global); }
659:   PetscOptionsEnum("-mat_partitioning_chaco_local","Local method","MatPartitioningChacoSetLocal",MPChacoLocalTypes,(PetscEnum)chaco->local_method,(PetscEnum*)&local,&flag);
660:   if (flag) { MatPartitioningChacoSetLocal(part,local); }
661:   PetscOptionsReal("-mat_partitioning_chaco_coarse","Coarse level","MatPartitioningChacoSetCoarseLevel",0.0,&r,&flag);
662:   if (flag) { MatPartitioningChacoSetCoarseLevel(part,r); }
663:   PetscOptionsEnum("-mat_partitioning_chaco_eigen_solver","Eigensolver method","MatPartitioningChacoSetEigenSolver",MPChacoEigenTypes,(PetscEnum)chaco->eigen_method,(PetscEnum*)&eigen,&flag);
664:   if (flag) { MatPartitioningChacoSetEigenSolver(part,eigen); }
665:   PetscOptionsReal("-mat_partitioning_chaco_eigen_tol","Eigensolver tolerance","MatPartitioningChacoSetEigenTol",chaco->eigtol,&r,&flag);
666:   if (flag) { MatPartitioningChacoSetEigenTol(part,r); }
667:   PetscOptionsInt("-mat_partitioning_chaco_eigen_number","Number of eigenvectors: 1, 2, or 3 (bi-, quadri-, or octosection)","MatPartitioningChacoSetEigenNumber",chaco->eignum,&i,&flag);
668:   if (flag) { MatPartitioningChacoSetEigenNumber(part,i); }
669:   PetscOptionsBool("-mat_partitioning_chaco_verbose","Show library output","",chaco->verbose,&chaco->verbose,NULL);
670:   PetscOptionsTail();
671:   return(0);
672: }

674: PetscErrorCode MatPartitioningDestroy_Chaco(MatPartitioning part)
675: {
676:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*) part->data;
677:   PetscErrorCode        ierr;

680:   PetscFree(chaco);
681:   /* clear composed functions */
682:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetGlobal_C",NULL);
683:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetGlobal_C",NULL);
684:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetLocal_C",NULL);
685:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetLocal_C",NULL);
686:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetCoarseLevel_C",NULL);
687:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenSolver_C",NULL);
688:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenSolver_C",NULL);
689:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenTol_C",NULL);
690:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenTol_C",NULL);
691:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenNumber_C",NULL);
692:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenNumber_C",NULL);
693:   return(0);
694: }

696: /*MC
697:    MATPARTITIONINGCHACO - Creates a partitioning context via the external package Chaco.

699:    Level: beginner

701:    Notes: See http://www.cs.sandia.gov/CRF/chac.html

703: .keywords: Partitioning, create, context

705: .seealso: MatPartitioningSetType(), MatPartitioningType
706: M*/

708: PETSC_EXTERN PetscErrorCode MatPartitioningCreate_Chaco(MatPartitioning part)
709: {
710:   PetscErrorCode        ierr;
711:   MatPartitioning_Chaco *chaco;

714:   PetscNewLog(part,&chaco);
715:   part->data = (void*)chaco;

717:   chaco->global_method = MP_CHACO_MULTILEVEL;
718:   chaco->local_method  = MP_CHACO_KERNIGHAN;
719:   chaco->eigen_method  = MP_CHACO_LANCZOS;
720:   chaco->nbvtxcoarsed  = 200;
721:   chaco->eignum        = 1;
722:   chaco->eigtol        = 0.001;
723:   chaco->verbose       = PETSC_FALSE;

725:   part->ops->apply          = MatPartitioningApply_Chaco;
726:   part->ops->view           = MatPartitioningView_Chaco;
727:   part->ops->destroy        = MatPartitioningDestroy_Chaco;
728:   part->ops->setfromoptions = MatPartitioningSetFromOptions_Chaco;

730:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetGlobal_C",MatPartitioningChacoSetGlobal_Chaco);
731:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetGlobal_C",MatPartitioningChacoGetGlobal_Chaco);
732:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetLocal_C",MatPartitioningChacoSetLocal_Chaco);
733:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetLocal_C",MatPartitioningChacoGetLocal_Chaco);
734:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetCoarseLevel_C",MatPartitioningChacoSetCoarseLevel_Chaco);
735:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenSolver_C",MatPartitioningChacoSetEigenSolver_Chaco);
736:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenSolver_C",MatPartitioningChacoGetEigenSolver_Chaco);
737:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenTol_C",MatPartitioningChacoSetEigenTol_Chaco);
738:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenTol_C",MatPartitioningChacoGetEigenTol_Chaco);
739:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoSetEigenNumber_C",MatPartitioningChacoSetEigenNumber_Chaco);
740:   PetscObjectComposeFunction((PetscObject)part,"MatPartitioningChacoGetEigenNumber_C",MatPartitioningChacoGetEigenNumber_Chaco);
741:   return(0);
742: }