Actual source code: chaco.c

petsc-3.9.2 2018-05-20
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) {
 87:       MatMPIAdjToSeq(mat,&matSeq);
 88:     } else {
 89:       PetscInfo(part,"Converting distributed matrix to sequential: this could be a performance loss\n");
 90:       MatGetSize(mat,&M,&N);
 91:       ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);
 92:       ISCreateStride(PETSC_COMM_SELF,N,0,1,&iscol);
 93:       MatCreateSubMatrices(mat,1,&isrow,&iscol,MAT_INITIAL_MATRIX,&A);
 94:       ISDestroy(&isrow);
 95:       ISDestroy(&iscol);
 96:       matSeq = *A;
 97:       PetscFree(A);
 98:     }
 99:   } else {
100:     PetscObjectReference((PetscObject)mat);
101:     matSeq = mat;
102:   }

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

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

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

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

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

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

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

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

167:   /* creation of the index set */
168:   nb_locals = mat->rmap->n;
169:   locals    = parttab + mat->rmap->rstart;
170:   ISCreateGeneral(PetscObjectComm((PetscObject)part),nb_locals,locals,PETSC_COPY_VALUES,partitioning);

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

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

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

200: /*@
201:    MatPartitioningChacoSetGlobal - Set global method for Chaco partitioner.

203:    Collective on MatPartitioning

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

210:    Options Database:
211: .  -mat_partitioning_chaco_global <method> - the global method

213:    Level: advanced

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

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

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

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

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

250: /*@
251:    MatPartitioningChacoGetGlobal - Get global method for Chaco partitioner.

253:    Not Collective

255:    Input Parameter:
256: .  part - the partitioning context

258:    Output Parameter:
259: .  method - the method

261:    Level: advanced

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

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

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

281:   *method = chaco->global_method;
282:   return(0);
283: }

285: /*@
286:    MatPartitioningChacoSetLocal - Set local method for Chaco partitioner.

288:    Collective on MatPartitioning

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

294:    Options Database:
295: .  -mat_partitioning_chaco_local <method> - the local method

297:    Level: advanced

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

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

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

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

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

331: /*@
332:    MatPartitioningChacoGetLocal - Get local method for Chaco partitioner.

334:    Not Collective

336:    Input Parameter:
337: .  part - the partitioning context

339:    Output Parameter:
340: .  method - the method

342:    Level: advanced

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

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

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

362:   *method = chaco->local_method;
363:   return(0);
364: }

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

370:    Collective on MatPartitioning

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

376:    Options Database:
377: .  -mat_partitioning_chaco_coarse <l> - Coarse level

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

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

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

397:   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]");
398:   chaco->nbvtxcoarsed = (PetscInt)(part->adj->cmap->N * level);
399:   if (chaco->nbvtxcoarsed < 20) chaco->nbvtxcoarsed = 20;
400:   return(0);
401: }

403: /*@
404:    MatPartitioningChacoSetEigenSolver - Set eigensolver method for Chaco partitioner.

406:    Collective on MatPartitioning

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

412:    Options Database:
413: .  -mat_partitioning_chaco_eigen_solver <method> - the eigensolver

415:    Level: advanced

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

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

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

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

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

449: /*@
450:    MatPartitioningChacoGetEigenSolver - Get local method for Chaco partitioner.

452:    Not Collective

454:    Input Parameter:
455: .  part - the partitioning context

457:    Output Parameter:
458: .  method - the method

460:    Level: advanced

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

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

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

480:   *method = chaco->eigen_method;
481:   return(0);
482: }

484: /*@
485:    MatPartitioningChacoSetEigenTol - Sets the tolerance for the eigensolver.

487:    Collective on MatPartitioning

489:    Input Parameters:
490: +  part - the partitioning context
491: -  tol  - the tolerance

493:    Options Database:
494: .  -mat_partitioning_chaco_eigen_tol <tol>: Tolerance for eigensolver

496:    Note:
497:    Must be positive. The default value is 0.001.

499:    Level: advanced

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

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

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

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

527: /*@
528:    MatPartitioningChacoGetEigenTol - Gets the eigensolver tolerance.

530:    Not Collective

532:    Input Parameter:
533: .  part - the partitioning context

535:    Output Parameter:
536: .  tol  - the tolerance

538:    Level: advanced

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

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

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

558:   *tol = chaco->eigtol;
559:   return(0);
560: }

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

566:    Collective on MatPartitioning

568:    Input Parameters:
569: +  part - the partitioning context
570: -  num  - the number of eigenvectors

572:    Options Database:
573: .  -mat_partitioning_chaco_eigen_number <n>: Number of eigenvectors

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

579:    Level: advanced

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

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

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

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

607: /*@
608:    MatPartitioningChacoGetEigenNumber - Gets the number of eigenvectors used by Chaco.

610:    Not Collective

612:    Input Parameter:
613: .  part - the partitioning context

615:    Output Parameter:
616: .  num  - number of eigenvectors

618:    Level: advanced

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

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

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

638:   *num = chaco->eignum;
639:   return(0);
640: }

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

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

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

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

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

697:    Level: beginner

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

701: .keywords: Partitioning, create, context

703: .seealso: MatPartitioningSetType(), MatPartitioningType
704: M*/

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

712:   PetscNewLog(part,&chaco);
713:   part->data = (void*)chaco;

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

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

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