Actual source code: chaco.c

petsc-3.3-p7 2013-05-11
  2: #include <../src/mat/impls/adj/mpi/mpiadj.h>       /*I "petscmat.h" I*/

  4: #ifdef PETSC_HAVE_UNISTD_H
  5: #include <unistd.h>
  6: #endif

  8: #ifdef PETSC_HAVE_STDLIB_H
  9: #include <stdlib.h>
 10: #endif

 12: EXTERN_C_BEGIN
 13: /* Chaco does not have an include file */
 14: extern int interface(int nvtxs, int *start, int *adjacency, int *vwgts,
 15:     float *ewgts, float *x, float *y, float *z, char *outassignname,
 16:     char *outfilename, short *assignment, int architecture, int ndims_tot,
 17:     int mesh_dims[3], double *goal, int global_method, int local_method,
 18:     int rqi_flag, int vmax, int ndims, double eigtol, long seed);

 20: extern int FREE_GRAPH;

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

 45: EXTERN_C_END

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

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

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

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

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

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

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

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

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

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

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

161:   PetscMalloc((mat->rmap->N)*sizeof(PetscInt),&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(((PetscObject)part)->comm,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: }

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

192:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
193:   if (isascii) {
194:     PetscViewerASCIIPrintf(viewer,"  Global method: %s\n",MPChacoGlobalTypes[chaco->global_method]);
195:     PetscViewerASCIIPrintf(viewer,"  Local method: %s\n",MPChacoLocalTypes[chaco->local_method]);
196:     PetscViewerASCIIPrintf(viewer,"  Number of vertices for the coarse graph: %d\n",chaco->nbvtxcoarsed);
197:     PetscViewerASCIIPrintf(viewer,"  Eigensolver: %s\n",MPChacoEigenTypes[chaco->eigen_method]);
198:     PetscViewerASCIIPrintf(viewer,"  Tolerance for eigensolver: %g\n",chaco->eigtol);
199:     PetscViewerASCIIPrintf(viewer,"  Number of eigenvectors: %d\n",chaco->eignum);
200:   } else {
201:     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for Chaco partitioner",((PetscObject)viewer)->type_name);
202:   }
203:   return(0);
204: }

208: /*@
209:    MatPartitioningChacoSetGlobal - Set global method for Chaco partitioner.

211:    Collective on MatPartitioning

213:    Input Parameters:
214: +  part - the partitioning context
215: -  method - one of MP_CHACO_MULTILEVEL, MP_CHACO_SPECTRAL, MP_CHACO_LINEAR, 
216:             MP_CHACO_RANDOM or MP_CHACO_SCATTERED

218:    Options Database:
219: .  -mat_partitioning_chaco_global <method> - the global method

221:    Level: advanced

223:    Notes:
224:    The default is the multi-level method. See Chaco documentation for
225:    additional details.

227: .seealso: MatPartitioningChacoSetLocal(),MatPartitioningChacoGetGlobal()
228: @*/
229: PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning part,MPChacoGlobalType method)
230: {

236:   PetscTryMethod(part,"MatPartitioningChacoSetGlobal_C",(MatPartitioning,MPChacoGlobalType),(part,method));
237:   return(0);
238: }

240: EXTERN_C_BEGIN
243: PetscErrorCode MatPartitioningChacoSetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType method)
244: {
245:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

248:   if (method==PETSC_DEFAULT) chaco->global_method = MP_CHACO_MULTILEVEL;
249:   else switch (method) {
250:     case MP_CHACO_MULTILEVEL:
251:     case MP_CHACO_SPECTRAL:
252:     case MP_CHACO_LINEAR:
253:     case MP_CHACO_RANDOM:
254:     case MP_CHACO_SCATTERED:
255:       chaco->global_method = method; break;
256:     default:
257:       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
258:   }
259:   return(0);
260: }
261: EXTERN_C_END

265: /*@
266:    MatPartitioningChacoGetGlobal - Get global method for Chaco partitioner.

268:    Not Collective

270:    Input Parameter:
271: .  part - the partitioning context

273:    Output Parameter:
274: .  method - the method

276:    Level: advanced

278: .seealso: MatPartitioningChacoSetGlobal()
279: @*/
280: PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning part,MPChacoGlobalType *method)
281: {

287:   PetscTryMethod(part,"MatPartitioningChacoGetGlobal_C",(MatPartitioning,MPChacoGlobalType*),(part,method));
288:   return(0);
289: }

291: EXTERN_C_BEGIN
294: PetscErrorCode MatPartitioningChacoGetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType *method)
295: {
296:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

299:   *method = chaco->global_method;
300:   return(0);
301: }
302: EXTERN_C_END

306: /*@
307:    MatPartitioningChacoSetLocal - Set local method for Chaco partitioner.

309:    Collective on MatPartitioning

311:    Input Parameters:
312: +  part - the partitioning context
313: -  method - one of MP_CHACO_KERNIGHAN or MP_CHACO_NONE

315:    Options Database:
316: .  -mat_partitioning_chaco_local <method> - the local method

318:    Level: advanced

320:    Notes:
321:    The default is to apply the Kernighan-Lin heuristic. See Chaco documentation
322:    for additional details.

324: .seealso: MatPartitioningChacoSetGlobal(),MatPartitioningChacoGetLocal()
325: @*/
326: PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning part,MPChacoLocalType method)
327: {

333:   PetscTryMethod(part,"MatPartitioningChacoSetLocal_C",(MatPartitioning,MPChacoLocalType),(part,method));
334:   return(0);
335: }

337: EXTERN_C_BEGIN
340: PetscErrorCode MatPartitioningChacoSetLocal_Chaco(MatPartitioning part,MPChacoLocalType method)
341: {
342:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

345:   if (method==PETSC_DEFAULT) chaco->local_method = MP_CHACO_KERNIGHAN;
346:   else switch (method) {
347:     case MP_CHACO_KERNIGHAN:
348:     case MP_CHACO_NONE:
349:       chaco->local_method = method; break;
350:     default:
351:       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
352:   }
353:   return(0);
354: }
355: EXTERN_C_END

359: /*@
360:    MatPartitioningChacoGetLocal - Get local method for Chaco partitioner.

362:    Not Collective

364:    Input Parameter:
365: .  part - the partitioning context

367:    Output Parameter:
368: .  method - the method

370:    Level: advanced

372: .seealso: MatPartitioningChacoSetLocal()
373: @*/
374: PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning part,MPChacoLocalType *method)
375: {

381:   PetscTryMethod(part,"MatPartitioningChacoGetLocal_C",(MatPartitioning,MPChacoLocalType*),(part,method));
382:   return(0);
383: }

385: EXTERN_C_BEGIN
388: PetscErrorCode MatPartitioningChacoGetLocal_Chaco(MatPartitioning part,MPChacoLocalType *method)
389: {
390:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

393:   *method = chaco->local_method;
394:   return(0);
395: }
396: EXTERN_C_END

400: /*@
401:    MatPartitioningChacoSetCoarseLevel - Set the coarse level parameter for the
402:    Chaco partitioner.
403:  
404:    Collective on MatPartitioning

406:    Input Parameters:
407: +  part - the partitioning context
408: -  level - the coarse level in range [0.0,1.0]

410:    Options Database:
411: .  -mat_partitioning_chaco_coarse <l> - Coarse level

413:    Level: advanced
414: @*/
415: PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning part,PetscReal level)
416: {

422:   PetscTryMethod(part,"MatPartitioningChacoSetCoarseLevel_C",(MatPartitioning,PetscReal),(part,level));
423:   return(0);
424: }

426: EXTERN_C_BEGIN
429: PetscErrorCode MatPartitioningChacoSetCoarseLevel_Chaco(MatPartitioning part,PetscReal level)
430: {
431:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

434:   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]");
435:   chaco->nbvtxcoarsed = (PetscInt)(part->adj->cmap->N * level);
436:   if (chaco->nbvtxcoarsed < 20) chaco->nbvtxcoarsed = 20;
437:   return(0);
438: }
439: EXTERN_C_END

443: /*@
444:    MatPartitioningChacoSetEigenSolver - Set eigensolver method for Chaco partitioner.

446:    Collective on MatPartitioning

448:    Input Parameters:
449: +  part - the partitioning context
450: -  method - one of MP_CHACO_LANCZOS or MP_CHACO_RQI

452:    Options Database:
453: .  -mat_partitioning_chaco_eigen_solver <method> - the eigensolver

455:    Level: advanced

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

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

470:   PetscTryMethod(part,"MatPartitioningChacoSetEigenSolver_C",(MatPartitioning,MPChacoEigenType),(part,method));
471:   return(0);
472: }

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

482:   if (method==PETSC_DEFAULT) chaco->eigen_method = MP_CHACO_LANCZOS;
483:   else switch (method) {
484:     case MP_CHACO_LANCZOS:
485:     case MP_CHACO_RQI:
486:       chaco->eigen_method = method; break;
487:     default:
488:       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Chaco: Unknown or unsupported option");
489:   }
490:   return(0);
491: }
492: EXTERN_C_END

496: /*@
497:    MatPartitioningChacoGetEigenSolver - Get local method for Chaco partitioner.

499:    Not Collective

501:    Input Parameter:
502: .  part - the partitioning context

504:    Output Parameter:
505: .  method - the method

507:    Level: advanced

509: .seealso: MatPartitioningChacoSetEigenSolver()
510: @*/
511: PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning part,MPChacoEigenType *method)
512: {

518:   PetscTryMethod(part,"MatPartitioningChacoGetEigenSolver_C",(MatPartitioning,MPChacoEigenType*),(part,method));
519:   return(0);
520: }

522: EXTERN_C_BEGIN
525: PetscErrorCode MatPartitioningChacoGetEigenSolver_Chaco(MatPartitioning part,MPChacoEigenType *method)
526: {
527:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

530:   *method = chaco->eigen_method;
531:   return(0);
532: }
533: EXTERN_C_END

537: /*@
538:    MatPartitioningChacoSetEigenTol - Sets the tolerance for the eigensolver.

540:    Collective on MatPartitioning

542:    Input Parameters:
543: +  part - the partitioning context
544: -  tol  - the tolerance

546:    Options Database:
547: .  -mat_partitioning_chaco_eigen_tol <tol>: Tolerance for eigensolver

549:    Note:
550:    Must be positive. The default value is 0.001.

552:    Level: advanced

554: .seealso: MatPartitioningChacoSetEigenSolver(), MatPartitioningChacoGetEigenTol()
555: @*/
556: PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning part,PetscReal tol)
557: {

563:   PetscTryMethod(part,"MatPartitioningChacoSetEigenTol_C",(MatPartitioning,PetscReal),(part,tol));
564:   return(0);
565: }

567: EXTERN_C_BEGIN
570: PetscErrorCode MatPartitioningChacoSetEigenTol_Chaco(MatPartitioning part,PetscReal tol)
571: {
572:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

575:   if (tol==PETSC_DEFAULT) chaco->eigtol = 0.001;
576:   else {
577:     if (tol<=0.0) SETERRQ(((PetscObject)part)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Tolerance must be positive");
578:     chaco->eigtol = tol;
579:   }
580:   return(0);
581: }
582: EXTERN_C_END

586: /*@
587:    MatPartitioningChacoGetEigenTol - Gets the eigensolver tolerance.

589:    Not Collective

591:    Input Parameter:
592: .  part - the partitioning context

594:    Output Parameter:
595: .  tol  - the tolerance

597:    Level: advanced

599: .seealso: MatPartitioningChacoSetEigenTol()
600: @*/
601: PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning part,PetscReal *tol)
602: {

608:   PetscTryMethod(part,"MatPartitioningChacoGetEigenTol_C",(MatPartitioning,PetscReal*),(part,tol));
609:   return(0);
610: }

612: EXTERN_C_BEGIN
615: PetscErrorCode MatPartitioningChacoGetEigenTol_Chaco(MatPartitioning part,PetscReal *tol)
616: {
617:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

620:   *tol = chaco->eigtol;
621:   return(0);
622: }
623: EXTERN_C_END

627: /*@
628:    MatPartitioningChacoSetEigenNumber - Sets the number of eigenvectors to compute
629:    during partitioning.

631:    Collective on MatPartitioning

633:    Input Parameters:
634: +  part - the partitioning context
635: -  num  - the number of eigenvectors

637:    Options Database:
638: .  -mat_partitioning_chaco_eigen_number <n>: Number of eigenvectors

640:    Note:
641:    Accepted values are 1, 2 or 3, indicating partitioning by bisection,
642:    quadrisection, or octosection.

644:    Level: advanced

646: .seealso: MatPartitioningChacoSetEigenSolver(), MatPartitioningChacoGetEigenTol()
647: @*/
648: PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning part,PetscInt num)
649: {

655:   PetscTryMethod(part,"MatPartitioningChacoSetEigenNumber_C",(MatPartitioning,PetscInt),(part,num));
656:   return(0);
657: }

659: EXTERN_C_BEGIN
662: PetscErrorCode MatPartitioningChacoSetEigenNumber_Chaco(MatPartitioning part,PetscInt num)
663: {
664:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

667:   if (num==PETSC_DEFAULT) chaco->eignum = 1;
668:   else {
669:     if (num<1 || num>3) SETERRQ(((PetscObject)part)->comm,PETSC_ERR_ARG_OUTOFRANGE,"Can only specify 1, 2 or 3 eigenvectors");
670:     chaco->eignum = num;
671:   }
672:   return(0);
673: }
674: EXTERN_C_END

678: /*@
679:    MatPartitioningChacoGetEigenNumber - Gets the number of eigenvectors used by Chaco.

681:    Not Collective

683:    Input Parameter:
684: .  part - the partitioning context

686:    Output Parameter:
687: .  num  - number of eigenvectors

689:    Level: advanced

691: .seealso: MatPartitioningChacoSetEigenNumber()
692: @*/
693: PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning part,PetscInt *num)
694: {

700:   PetscTryMethod(part,"MatPartitioningChacoGetEigenNumber_C",(MatPartitioning,PetscInt*),(part,num));
701:   return(0);
702: }

704: EXTERN_C_BEGIN
707: PetscErrorCode MatPartitioningChacoGetEigenNumber_Chaco(MatPartitioning part,PetscInt *num)
708: {
709:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;

712:   *num = chaco->eignum;
713:   return(0);
714: }
715: EXTERN_C_END

719: PetscErrorCode MatPartitioningSetFromOptions_Chaco(MatPartitioning part)
720: {
721:   PetscErrorCode        ierr;
722:   PetscInt              i;
723:   PetscReal             r;
724:   PetscBool             flag;
725:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco*)part->data;
726:   MPChacoGlobalType     global;
727:   MPChacoLocalType      local;
728:   MPChacoEigenType      eigen;

731:   PetscOptionsHead("Chaco partitioning options");
732:     PetscOptionsEnum("-mat_partitioning_chaco_global","Global method","MatPartitioningChacoSetGlobal",MPChacoGlobalTypes,(PetscEnum)chaco->global_method,(PetscEnum*)&global,&flag);
733:     if (flag) { MatPartitioningChacoSetGlobal(part,global); }
734:     PetscOptionsEnum("-mat_partitioning_chaco_local","Local method","MatPartitioningChacoSetLocal",MPChacoLocalTypes,(PetscEnum)chaco->local_method,(PetscEnum*)&local,&flag);
735:     if (flag) { MatPartitioningChacoSetLocal(part,local); }
736:     PetscOptionsReal("-mat_partitioning_chaco_coarse","Coarse level","MatPartitioningChacoSetCoarseLevel",0.0,&r,&flag);
737:     if (flag) { MatPartitioningChacoSetCoarseLevel(part,r); }
738:     PetscOptionsEnum("-mat_partitioning_chaco_eigen_solver","Eigensolver method","MatPartitioningChacoSetEigenSolver",MPChacoEigenTypes,(PetscEnum)chaco->eigen_method,(PetscEnum*)&eigen,&flag);
739:     if (flag) { MatPartitioningChacoSetEigenSolver(part,eigen); }
740:     PetscOptionsReal("-mat_partitioning_chaco_eigen_tol","Eigensolver tolerance","MatPartitioningChacoSetEigenTol",chaco->eigtol,&r,&flag);
741:     if (flag) { MatPartitioningChacoSetEigenTol(part,r); }
742:     PetscOptionsInt("-mat_partitioning_chaco_eigen_number","Number of eigenvectors: 1, 2, or 3 (bi-, quadri-, or octosection)","MatPartitioningChacoSetEigenNumber",chaco->eignum,&i,&flag);
743:     if (flag) { MatPartitioningChacoSetEigenNumber(part,i); }
744:     PetscOptionsBool("-mat_partitioning_chaco_verbose","Show library output","",chaco->verbose,&chaco->verbose,PETSC_NULL);
745:   PetscOptionsTail();
746:   return(0);
747: }

751: PetscErrorCode MatPartitioningDestroy_Chaco(MatPartitioning part)
752: {
753:   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *) part->data;
754:   PetscErrorCode        ierr;

757:   PetscFree(chaco);
758:   /* clear composed functions */
759:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetGlobal_C","",PETSC_NULL);
760:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetGlobal_C","",PETSC_NULL);
761:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetLocal_C","",PETSC_NULL);
762:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetLocal_C","",PETSC_NULL);
763:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetCoarseLevel_C","",PETSC_NULL);
764:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenSolver_C","",PETSC_NULL);
765:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenSolver_C","",PETSC_NULL);
766:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenTol_C","",PETSC_NULL);
767:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenTol_C","",PETSC_NULL);
768:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenNumber_C","",PETSC_NULL);
769:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenNumber_C","",PETSC_NULL);
770:   return(0);
771: }

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

776:    Level: beginner

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

780: .keywords: Partitioning, create, context

782: .seealso: MatPartitioningSetType(), MatPartitioningType
783: M*/

785: EXTERN_C_BEGIN
788: PetscErrorCode MatPartitioningCreate_Chaco(MatPartitioning part)
789: {
790:   PetscErrorCode        ierr;
791:   MatPartitioning_Chaco *chaco;

794:   PetscNewLog(part,MatPartitioning_Chaco,&chaco);
795:   part->data = (void*)chaco;

797:   chaco->global_method = MP_CHACO_MULTILEVEL;
798:   chaco->local_method  = MP_CHACO_KERNIGHAN;
799:   chaco->eigen_method  = MP_CHACO_LANCZOS;
800:   chaco->nbvtxcoarsed  = 200;
801:   chaco->eignum        = 1;
802:   chaco->eigtol        = 0.001;
803:   chaco->verbose       = PETSC_FALSE;

805:   part->ops->apply          = MatPartitioningApply_Chaco;
806:   part->ops->view           = MatPartitioningView_Chaco;
807:   part->ops->destroy        = MatPartitioningDestroy_Chaco;
808:   part->ops->setfromoptions = MatPartitioningSetFromOptions_Chaco;

810:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetGlobal_C","MatPartitioningChacoSetGlobal_Chaco",MatPartitioningChacoSetGlobal_Chaco);
811:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetGlobal_C","MatPartitioningChacoGetGlobal_Chaco",MatPartitioningChacoGetGlobal_Chaco);
812:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetLocal_C","MatPartitioningChacoSetLocal_Chaco",MatPartitioningChacoSetLocal_Chaco);
813:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetLocal_C","MatPartitioningChacoGetLocal_Chaco",MatPartitioningChacoGetLocal_Chaco);
814:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetCoarseLevel_C","MatPartitioningChacoSetCoarseLevel_Chaco",MatPartitioningChacoSetCoarseLevel_Chaco);
815:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenSolver_C","MatPartitioningChacoSetEigenSolver_Chaco",MatPartitioningChacoSetEigenSolver_Chaco);
816:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenSolver_C","MatPartitioningChacoGetEigenSolver_Chaco",MatPartitioningChacoGetEigenSolver_Chaco);
817:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenTol_C","MatPartitioningChacoSetEigenTol_Chaco",MatPartitioningChacoSetEigenTol_Chaco);
818:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenTol_C","MatPartitioningChacoGetEigenTol_Chaco",MatPartitioningChacoGetEigenTol_Chaco);
819:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoSetEigenNumber_C","MatPartitioningChacoSetEigenNumber_Chaco",MatPartitioningChacoSetEigenNumber_Chaco);
820:   PetscObjectComposeFunctionDynamic((PetscObject)part,"MatPartitioningChacoGetEigenNumber_C","MatPartitioningChacoGetEigenNumber_Chaco",MatPartitioningChacoGetEigenNumber_Chaco);
821:   return(0);
822: }
823: EXTERN_C_END