xref: /petsc/src/mat/graphops/partition/impls/chaco/chaco.c (revision 6d8694c4fbab79f9439f1ad13c0386ba7ee1ca4b)
18be712e4SBarry Smith #include <../src/mat/impls/adj/mpi/mpiadj.h> /*I "petscmat.h" I*/
28be712e4SBarry Smith 
38be712e4SBarry Smith #if defined(PETSC_HAVE_UNISTD_H)
48be712e4SBarry Smith   #include <unistd.h>
58be712e4SBarry Smith #endif
68be712e4SBarry Smith 
78be712e4SBarry Smith #if defined(PETSC_HAVE_CHACO_INT_ASSIGNMENT)
88be712e4SBarry Smith   #include <chaco.h>
98be712e4SBarry Smith #else
108be712e4SBarry Smith /* Older versions of Chaco do not have an include file */
118be712e4SBarry Smith PETSC_EXTERN int interface(int nvtxs, int *start, int *adjacency, int *vwgts, float *ewgts, float *x, float *y, float *z, char *outassignname, char *outfilename, short *assignment, int architecture, int ndims_tot, int mesh_dims[3], double *goal, int global_method, int local_method, int rqi_flag, int vmax, int ndims, double eigtol, long seed);
128be712e4SBarry Smith #endif
138be712e4SBarry Smith 
148be712e4SBarry Smith extern int FREE_GRAPH;
158be712e4SBarry Smith 
168be712e4SBarry Smith /*
178be712e4SBarry Smith int       nvtxs;                number of vertices in full graph
188be712e4SBarry Smith int      *start;                start of edge list for each vertex
198be712e4SBarry Smith int      *adjacency;            edge list data
208be712e4SBarry Smith int      *vwgts;                weights for all vertices
218be712e4SBarry Smith float    *ewgts;                weights for all edges
228be712e4SBarry Smith float    *x, *y, *z;            coordinates for inertial method
238be712e4SBarry Smith char     *outassignname;        name of assignment output file
248be712e4SBarry Smith char     *outfilename;          output file name
258be712e4SBarry Smith short    *assignment;           set number of each vtx (length n)
268be712e4SBarry Smith int       architecture;         0 => hypercube, d => d-dimensional mesh
278be712e4SBarry Smith int       ndims_tot;            total number of cube dimensions to divide
288be712e4SBarry Smith int       mesh_dims[3];         dimensions of mesh of processors
298be712e4SBarry Smith double   *goal;                 desired set sizes for each set
308be712e4SBarry Smith int       global_method;        global partitioning algorithm
318be712e4SBarry Smith int       local_method;         local partitioning algorithm
328be712e4SBarry Smith int       rqi_flag;             should I use RQI/Symmlq eigensolver?
338be712e4SBarry Smith int       vmax;                 how many vertices to coarsen down to?
348be712e4SBarry Smith int       ndims;                number of eigenvectors (2^d sets)
358be712e4SBarry Smith double    eigtol;               tolerance on eigenvectors
368be712e4SBarry Smith long      seed;                 for random graph mutations
378be712e4SBarry Smith */
388be712e4SBarry Smith 
398be712e4SBarry Smith typedef struct {
408be712e4SBarry Smith   PetscBool         verbose;
418be712e4SBarry Smith   PetscInt          eignum;
428be712e4SBarry Smith   PetscReal         eigtol;
438be712e4SBarry Smith   MPChacoGlobalType global_method; /* global method */
448be712e4SBarry Smith   MPChacoLocalType  local_method;  /* local method */
458be712e4SBarry Smith   MPChacoEigenType  eigen_method;  /* eigensolver */
468be712e4SBarry Smith   PetscInt          nbvtxcoarsed;  /* number of vertices for the coarse graph */
478be712e4SBarry Smith } MatPartitioning_Chaco;
488be712e4SBarry Smith 
498be712e4SBarry Smith #define SIZE_LOG 10000 /* size of buffer for mesg_log */
508be712e4SBarry Smith 
MatPartitioningApply_Chaco(MatPartitioning part,IS * partitioning)518be712e4SBarry Smith static PetscErrorCode MatPartitioningApply_Chaco(MatPartitioning part, IS *partitioning)
528be712e4SBarry Smith {
538be712e4SBarry Smith   int                    cerr;
548be712e4SBarry Smith   PetscInt              *parttab, *locals, i, nb_locals, M, N;
558be712e4SBarry Smith   PetscMPIInt            size, rank;
568be712e4SBarry Smith   Mat                    mat = part->adj, matAdj, matSeq, *A;
578be712e4SBarry Smith   Mat_MPIAdj            *adj;
588be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
598be712e4SBarry Smith   PetscBool              flg;
608be712e4SBarry Smith   IS                     isrow, iscol;
618be712e4SBarry Smith   int                    nvtxs, *start, *adjacency, *vwgts, architecture, ndims_tot;
628be712e4SBarry Smith   int                    mesh_dims[3], global_method, local_method, rqi_flag, vmax, ndims;
638be712e4SBarry Smith #if defined(PETSC_HAVE_CHACO_INT_ASSIGNMENT)
648be712e4SBarry Smith   int *assignment;
658be712e4SBarry Smith #else
668be712e4SBarry Smith   short *assignment;
678be712e4SBarry Smith #endif
688be712e4SBarry Smith   double eigtol;
698be712e4SBarry Smith   long   seed;
708be712e4SBarry Smith   char  *mesg_log;
718be712e4SBarry Smith #if defined(PETSC_HAVE_UNISTD_H)
728be712e4SBarry Smith   int fd_stdout, fd_pipe[2], count;
738be712e4SBarry Smith #endif
748be712e4SBarry Smith 
758be712e4SBarry Smith   PetscFunctionBegin;
768be712e4SBarry Smith   PetscCheck(!part->use_edge_weights, PetscObjectComm((PetscObject)part), PETSC_ERR_SUP, "Chaco does not support edge weights");
778be712e4SBarry Smith   FREE_GRAPH = 0; /* otherwise Chaco will attempt to free memory for adjacency graph */
788be712e4SBarry Smith   PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)mat), &size));
798be712e4SBarry Smith   PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)mat), &rank));
808be712e4SBarry Smith   PetscCall(PetscObjectTypeCompare((PetscObject)mat, MATMPIADJ, &flg));
818be712e4SBarry Smith   if (size > 1) {
828be712e4SBarry Smith     if (flg) {
838be712e4SBarry Smith       PetscCall(MatMPIAdjToSeq(mat, &matSeq));
848be712e4SBarry Smith     } else {
858be712e4SBarry Smith       PetscCall(PetscInfo(part, "Converting distributed matrix to sequential: this could be a performance loss\n"));
868be712e4SBarry Smith       PetscCall(MatGetSize(mat, &M, &N));
878be712e4SBarry Smith       PetscCall(ISCreateStride(PETSC_COMM_SELF, M, 0, 1, &isrow));
888be712e4SBarry Smith       PetscCall(ISCreateStride(PETSC_COMM_SELF, N, 0, 1, &iscol));
898be712e4SBarry Smith       PetscCall(MatCreateSubMatrices(mat, 1, &isrow, &iscol, MAT_INITIAL_MATRIX, &A));
908be712e4SBarry Smith       PetscCall(ISDestroy(&isrow));
918be712e4SBarry Smith       PetscCall(ISDestroy(&iscol));
928be712e4SBarry Smith       matSeq = *A;
938be712e4SBarry Smith       PetscCall(PetscFree(A));
948be712e4SBarry Smith     }
958be712e4SBarry Smith   } else {
968be712e4SBarry Smith     PetscCall(PetscObjectReference((PetscObject)mat));
978be712e4SBarry Smith     matSeq = mat;
988be712e4SBarry Smith   }
998be712e4SBarry Smith 
1008be712e4SBarry Smith   if (!flg) { /* convert regular matrix to MPIADJ */
1018be712e4SBarry Smith     PetscCall(MatConvert(matSeq, MATMPIADJ, MAT_INITIAL_MATRIX, &matAdj));
1028be712e4SBarry Smith   } else {
1038be712e4SBarry Smith     PetscCall(PetscObjectReference((PetscObject)matSeq));
1048be712e4SBarry Smith     matAdj = matSeq;
1058be712e4SBarry Smith   }
1068be712e4SBarry Smith 
1078be712e4SBarry Smith   adj = (Mat_MPIAdj *)matAdj->data; /* finally adj contains adjacency graph */
1088be712e4SBarry Smith 
1098be712e4SBarry Smith   /* arguments for Chaco library */
1108be712e4SBarry Smith   nvtxs         = mat->rmap->N;         /* number of vertices in full graph */
1118be712e4SBarry Smith   start         = adj->i;               /* start of edge list for each vertex */
1128be712e4SBarry Smith   vwgts         = part->vertex_weights; /* weights for all vertices */
1138be712e4SBarry Smith   architecture  = 1;                    /* 0 => hypercube, d => d-dimensional mesh */
1148be712e4SBarry Smith   ndims_tot     = 0;                    /* total number of cube dimensions to divide */
1158be712e4SBarry Smith   mesh_dims[0]  = part->n;              /* dimensions of mesh of processors */
1168be712e4SBarry Smith   global_method = chaco->global_method; /* global partitioning algorithm */
1178be712e4SBarry Smith   local_method  = chaco->local_method;  /* local partitioning algorithm */
1188be712e4SBarry Smith   rqi_flag      = chaco->eigen_method;  /* should I use RQI/Symmlq eigensolver? */
1198be712e4SBarry Smith   vmax          = chaco->nbvtxcoarsed;  /* how many vertices to coarsen down to? */
1208be712e4SBarry Smith   ndims         = chaco->eignum;        /* number of eigenvectors (2^d sets) */
1218be712e4SBarry Smith   eigtol        = chaco->eigtol;        /* tolerance on eigenvectors */
1228be712e4SBarry Smith   seed          = 123636512;            /* for random graph mutations */
1238be712e4SBarry Smith 
1248be712e4SBarry Smith   PetscCall(PetscMalloc1(mat->rmap->N, &assignment));
1258be712e4SBarry Smith   PetscCall(PetscMalloc1(start[nvtxs], &adjacency));
1268be712e4SBarry Smith   for (i = 0; i < start[nvtxs]; i++) adjacency[i] = (adj->j)[i] + 1; /* 1-based indexing */
1278be712e4SBarry Smith 
1288be712e4SBarry Smith   /* redirect output to buffer */
1298be712e4SBarry Smith #if defined(PETSC_HAVE_UNISTD_H)
1308be712e4SBarry Smith   fd_stdout = dup(1);
1318be712e4SBarry Smith   PetscCheck(!pipe(fd_pipe), PETSC_COMM_SELF, PETSC_ERR_SYS, "Could not open pipe");
1328be712e4SBarry Smith   close(1);
1338be712e4SBarry Smith   dup2(fd_pipe[1], 1);
1348be712e4SBarry Smith   PetscCall(PetscMalloc1(SIZE_LOG, &mesg_log));
1358be712e4SBarry Smith #endif
1368be712e4SBarry Smith 
1378be712e4SBarry Smith   /* library call */
1388be712e4SBarry Smith   cerr = interface(nvtxs, start, adjacency, vwgts, NULL, NULL, NULL, NULL, NULL, NULL, assignment, architecture, ndims_tot, mesh_dims, NULL, global_method, local_method, rqi_flag, vmax, ndims, eigtol, seed);
1398be712e4SBarry Smith 
1408be712e4SBarry Smith #if defined(PETSC_HAVE_UNISTD_H)
1418be712e4SBarry Smith   PetscCall(PetscFFlush(stdout));
1426497c311SBarry Smith   count = (int)read(fd_pipe[0], mesg_log, (int)((SIZE_LOG - 1) * sizeof(char)));
1438be712e4SBarry Smith   if (count < 0) count = 0;
1448be712e4SBarry Smith   mesg_log[count] = 0;
1458be712e4SBarry Smith   close(1);
1468be712e4SBarry Smith   dup2(fd_stdout, 1);
1478be712e4SBarry Smith   close(fd_stdout);
1488be712e4SBarry Smith   close(fd_pipe[0]);
1498be712e4SBarry Smith   close(fd_pipe[1]);
1508be712e4SBarry Smith   if (chaco->verbose) PetscCall(PetscPrintf(PetscObjectComm((PetscObject)mat), "%s", mesg_log));
1518be712e4SBarry Smith   PetscCall(PetscFree(mesg_log));
1528be712e4SBarry Smith #endif
1538be712e4SBarry Smith   PetscCheck(!cerr, PETSC_COMM_SELF, PETSC_ERR_LIB, "Chaco failed");
1548be712e4SBarry Smith 
1558be712e4SBarry Smith   PetscCall(PetscMalloc1(mat->rmap->N, &parttab));
1568be712e4SBarry Smith   for (i = 0; i < nvtxs; i++) parttab[i] = assignment[i];
1578be712e4SBarry Smith 
1588be712e4SBarry Smith   /* creation of the index set */
1598be712e4SBarry Smith   nb_locals = mat->rmap->n;
1608be712e4SBarry Smith   locals    = parttab + mat->rmap->rstart;
1618be712e4SBarry Smith   PetscCall(ISCreateGeneral(PetscObjectComm((PetscObject)part), nb_locals, locals, PETSC_COPY_VALUES, partitioning));
1628be712e4SBarry Smith 
1638be712e4SBarry Smith   /* clean up */
1648be712e4SBarry Smith   PetscCall(PetscFree(parttab));
1658be712e4SBarry Smith   PetscCall(PetscFree(adjacency));
1668be712e4SBarry Smith   PetscCall(PetscFree(assignment));
1678be712e4SBarry Smith   PetscCall(MatDestroy(&matSeq));
1688be712e4SBarry Smith   PetscCall(MatDestroy(&matAdj));
1698be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
1708be712e4SBarry Smith }
1718be712e4SBarry Smith 
MatPartitioningView_Chaco(MatPartitioning part,PetscViewer viewer)1728be712e4SBarry Smith static PetscErrorCode MatPartitioningView_Chaco(MatPartitioning part, PetscViewer viewer)
1738be712e4SBarry Smith {
1748be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
1758be712e4SBarry Smith   PetscBool              isascii;
1768be712e4SBarry Smith 
1778be712e4SBarry Smith   PetscFunctionBegin;
1788be712e4SBarry Smith   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
1798be712e4SBarry Smith   if (isascii) {
1808be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Global method: %s\n", MPChacoGlobalTypes[chaco->global_method]));
1818be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Local method: %s\n", MPChacoLocalTypes[chaco->local_method]));
1828be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Number of vertices for the coarse graph: %" PetscInt_FMT "\n", chaco->nbvtxcoarsed));
1838be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Eigensolver: %s\n", MPChacoEigenTypes[chaco->eigen_method]));
1848be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Tolerance for eigensolver: %g\n", chaco->eigtol));
1858be712e4SBarry Smith     PetscCall(PetscViewerASCIIPrintf(viewer, "  Number of eigenvectors: %" PetscInt_FMT "\n", chaco->eignum));
1868be712e4SBarry Smith   }
1878be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
1888be712e4SBarry Smith }
1898be712e4SBarry Smith 
1908be712e4SBarry Smith /*@
1918be712e4SBarry Smith   MatPartitioningChacoSetGlobal - Set the global method for Chaco partitioner.
1928be712e4SBarry Smith 
1938be712e4SBarry Smith   Collective
1948be712e4SBarry Smith 
1958be712e4SBarry Smith   Input Parameters:
1968be712e4SBarry Smith + part   - the partitioning context
1978be712e4SBarry Smith - method - one of `MP_CHACO_MULTILEVEL`, `MP_CHACO_SPECTRAL`, `MP_CHACO_LINEAR`,
1988be712e4SBarry Smith             `MP_CHACO_RANDOM` or `MP_CHACO_SCATTERED`
1998be712e4SBarry Smith 
2008be712e4SBarry Smith   Options Database Key:
2018be712e4SBarry Smith . -mat_partitioning_chaco_global <method> - the global method
2028be712e4SBarry Smith 
2038be712e4SBarry Smith   Level: advanced
2048be712e4SBarry Smith 
2058be712e4SBarry Smith   Note:
2068be712e4SBarry Smith   The default is the multi-level method. See Chaco documentation for
2078be712e4SBarry Smith   additional details.
2088be712e4SBarry Smith 
2098be712e4SBarry Smith .seealso: `MatPartitioning`, `MatPartioningSetType()`, `MatPartitioningType`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetLocal()`, `MatPartitioningChacoGetGlobal()`
2108be712e4SBarry Smith @*/
MatPartitioningChacoSetGlobal(MatPartitioning part,MPChacoGlobalType method)2118be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetGlobal(MatPartitioning part, MPChacoGlobalType method)
2128be712e4SBarry Smith {
2138be712e4SBarry Smith   PetscFunctionBegin;
2148be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
2158be712e4SBarry Smith   PetscValidLogicalCollectiveEnum(part, method, 2);
2168be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetGlobal_C", (MatPartitioning, MPChacoGlobalType), (part, method));
2178be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2188be712e4SBarry Smith }
2198be712e4SBarry Smith 
MatPartitioningChacoSetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType method)2208be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetGlobal_Chaco(MatPartitioning part, MPChacoGlobalType method)
2218be712e4SBarry Smith {
2228be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
2238be712e4SBarry Smith 
2248be712e4SBarry Smith   PetscFunctionBegin;
2258be712e4SBarry Smith   switch (method) {
2268be712e4SBarry Smith   case MP_CHACO_MULTILEVEL:
2278be712e4SBarry Smith   case MP_CHACO_SPECTRAL:
2288be712e4SBarry Smith   case MP_CHACO_LINEAR:
2298be712e4SBarry Smith   case MP_CHACO_RANDOM:
2308be712e4SBarry Smith   case MP_CHACO_SCATTERED:
2318be712e4SBarry Smith     chaco->global_method = method;
2328be712e4SBarry Smith     break;
2338be712e4SBarry Smith   default:
2348be712e4SBarry Smith     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Chaco: Unknown or unsupported option");
2358be712e4SBarry Smith   }
2368be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2378be712e4SBarry Smith }
2388be712e4SBarry Smith 
2398be712e4SBarry Smith /*@
2408be712e4SBarry Smith   MatPartitioningChacoGetGlobal - Get the global method used by the Chaco partitioner.
2418be712e4SBarry Smith 
2428be712e4SBarry Smith   Not Collective
2438be712e4SBarry Smith 
2448be712e4SBarry Smith   Input Parameter:
2458be712e4SBarry Smith . part - the partitioning context
2468be712e4SBarry Smith 
2478be712e4SBarry Smith   Output Parameter:
2488be712e4SBarry Smith . method - the method
2498be712e4SBarry Smith 
2508be712e4SBarry Smith   Level: advanced
2518be712e4SBarry Smith 
2528be712e4SBarry Smith .seealso: `MatPartitioningType`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetGlobal()`
2538be712e4SBarry Smith @*/
MatPartitioningChacoGetGlobal(MatPartitioning part,MPChacoGlobalType * method)2548be712e4SBarry Smith PetscErrorCode MatPartitioningChacoGetGlobal(MatPartitioning part, MPChacoGlobalType *method)
2558be712e4SBarry Smith {
2568be712e4SBarry Smith   PetscFunctionBegin;
2578be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
2588be712e4SBarry Smith   PetscAssertPointer(method, 2);
2598be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoGetGlobal_C", (MatPartitioning, MPChacoGlobalType *), (part, method));
2608be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2618be712e4SBarry Smith }
2628be712e4SBarry Smith 
MatPartitioningChacoGetGlobal_Chaco(MatPartitioning part,MPChacoGlobalType * method)2638be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoGetGlobal_Chaco(MatPartitioning part, MPChacoGlobalType *method)
2648be712e4SBarry Smith {
2658be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
2668be712e4SBarry Smith 
2678be712e4SBarry Smith   PetscFunctionBegin;
2688be712e4SBarry Smith   *method = chaco->global_method;
2698be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2708be712e4SBarry Smith }
2718be712e4SBarry Smith 
2728be712e4SBarry Smith /*@
2738be712e4SBarry Smith   MatPartitioningChacoSetLocal - Set the local method for the Chaco partitioner.
2748be712e4SBarry Smith 
2758be712e4SBarry Smith   Collective
2768be712e4SBarry Smith 
2778be712e4SBarry Smith   Input Parameters:
2788be712e4SBarry Smith + part   - the partitioning context
2798be712e4SBarry Smith - method - one of `MP_CHACO_KERNIGHAN` or `MP_CHACO_NONE`
2808be712e4SBarry Smith 
2818be712e4SBarry Smith   Options Database Key:
2828be712e4SBarry Smith . -mat_partitioning_chaco_local <method> - the local method
2838be712e4SBarry Smith 
2848be712e4SBarry Smith   Level: advanced
2858be712e4SBarry Smith 
2868be712e4SBarry Smith   Note:
2878be712e4SBarry Smith   The default is to apply the Kernighan-Lin heuristic. See Chaco documentation
2888be712e4SBarry Smith   for additional details.
2898be712e4SBarry Smith 
2908be712e4SBarry Smith .seealso: `MatPartitioningType`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetGlobal()`, `MatPartitioningChacoGetLocal()`
2918be712e4SBarry Smith @*/
MatPartitioningChacoSetLocal(MatPartitioning part,MPChacoLocalType method)2928be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetLocal(MatPartitioning part, MPChacoLocalType method)
2938be712e4SBarry Smith {
2948be712e4SBarry Smith   PetscFunctionBegin;
2958be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
2968be712e4SBarry Smith   PetscValidLogicalCollectiveEnum(part, method, 2);
2978be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetLocal_C", (MatPartitioning, MPChacoLocalType), (part, method));
2988be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2998be712e4SBarry Smith }
3008be712e4SBarry Smith 
MatPartitioningChacoSetLocal_Chaco(MatPartitioning part,MPChacoLocalType method)3018be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetLocal_Chaco(MatPartitioning part, MPChacoLocalType method)
3028be712e4SBarry Smith {
3038be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
3048be712e4SBarry Smith 
3058be712e4SBarry Smith   PetscFunctionBegin;
3068be712e4SBarry Smith   switch (method) {
3078be712e4SBarry Smith   case MP_CHACO_KERNIGHAN:
3088be712e4SBarry Smith   case MP_CHACO_NONE:
3098be712e4SBarry Smith     chaco->local_method = method;
3108be712e4SBarry Smith     break;
3118be712e4SBarry Smith   default:
3128be712e4SBarry Smith     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Chaco: Unknown or unsupported option");
3138be712e4SBarry Smith   }
3148be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
3158be712e4SBarry Smith }
3168be712e4SBarry Smith 
3178be712e4SBarry Smith /*@
3188be712e4SBarry Smith   MatPartitioningChacoGetLocal - Get local method used by the Chaco partitioner.
3198be712e4SBarry Smith 
3208be712e4SBarry Smith   Not Collective
3218be712e4SBarry Smith 
3228be712e4SBarry Smith   Input Parameter:
3238be712e4SBarry Smith . part - the partitioning context
3248be712e4SBarry Smith 
3258be712e4SBarry Smith   Output Parameter:
3268be712e4SBarry Smith . method - the method
3278be712e4SBarry Smith 
3288be712e4SBarry Smith   Level: advanced
3298be712e4SBarry Smith 
3308be712e4SBarry Smith .seealso: `MatPartitioningType`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetLocal()`
3318be712e4SBarry Smith @*/
MatPartitioningChacoGetLocal(MatPartitioning part,MPChacoLocalType * method)3328be712e4SBarry Smith PetscErrorCode MatPartitioningChacoGetLocal(MatPartitioning part, MPChacoLocalType *method)
3338be712e4SBarry Smith {
3348be712e4SBarry Smith   PetscFunctionBegin;
3358be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
3368be712e4SBarry Smith   PetscAssertPointer(method, 2);
3378be712e4SBarry Smith   PetscUseMethod(part, "MatPartitioningChacoGetLocal_C", (MatPartitioning, MPChacoLocalType *), (part, method));
3388be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
3398be712e4SBarry Smith }
3408be712e4SBarry Smith 
MatPartitioningChacoGetLocal_Chaco(MatPartitioning part,MPChacoLocalType * method)3418be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoGetLocal_Chaco(MatPartitioning part, MPChacoLocalType *method)
3428be712e4SBarry Smith {
3438be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
3448be712e4SBarry Smith 
3458be712e4SBarry Smith   PetscFunctionBegin;
3468be712e4SBarry Smith   *method = chaco->local_method;
3478be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
3488be712e4SBarry Smith }
3498be712e4SBarry Smith 
3508be712e4SBarry Smith /*@
3518be712e4SBarry Smith   MatPartitioningChacoSetCoarseLevel - Set the coarse level parameter for the
3528be712e4SBarry Smith   Chaco partitioner.
3538be712e4SBarry Smith 
3548be712e4SBarry Smith   Collective
3558be712e4SBarry Smith 
3568be712e4SBarry Smith   Input Parameters:
3578be712e4SBarry Smith + part  - the partitioning context
3588be712e4SBarry Smith - level - the coarse level in range [0.0,1.0]
3598be712e4SBarry Smith 
3608be712e4SBarry Smith   Options Database Key:
3618be712e4SBarry Smith . -mat_partitioning_chaco_coarse <l> - Coarse level
3628be712e4SBarry Smith 
3638be712e4SBarry Smith   Level: advanced
3648be712e4SBarry Smith 
3658be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`
3668be712e4SBarry Smith @*/
MatPartitioningChacoSetCoarseLevel(MatPartitioning part,PetscReal level)3678be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetCoarseLevel(MatPartitioning part, PetscReal level)
3688be712e4SBarry Smith {
3698be712e4SBarry Smith   PetscFunctionBegin;
3708be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
3718be712e4SBarry Smith   PetscValidLogicalCollectiveReal(part, level, 2);
3728be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetCoarseLevel_C", (MatPartitioning, PetscReal), (part, level));
3738be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
3748be712e4SBarry Smith }
3758be712e4SBarry Smith 
MatPartitioningChacoSetCoarseLevel_Chaco(MatPartitioning part,PetscReal level)3768be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetCoarseLevel_Chaco(MatPartitioning part, PetscReal level)
3778be712e4SBarry Smith {
3788be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
3798be712e4SBarry Smith 
3808be712e4SBarry Smith   PetscFunctionBegin;
3818be712e4SBarry Smith   PetscCheck(level >= 0.0 && level < 1.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Chaco: level of coarsening out of range [0.0-1.0]");
3828be712e4SBarry Smith   chaco->nbvtxcoarsed = (PetscInt)(part->adj->cmap->N * level);
3838be712e4SBarry Smith   if (chaco->nbvtxcoarsed < 20) chaco->nbvtxcoarsed = 20;
3848be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
3858be712e4SBarry Smith }
3868be712e4SBarry Smith 
3878be712e4SBarry Smith /*@
3888be712e4SBarry Smith   MatPartitioningChacoSetEigenSolver - Set the eigensolver method for Chaco partitioner.
3898be712e4SBarry Smith 
3908be712e4SBarry Smith   Collective
3918be712e4SBarry Smith 
3928be712e4SBarry Smith   Input Parameters:
3938be712e4SBarry Smith + part   - the partitioning context
3948be712e4SBarry Smith - method - one of `MP_CHACO_LANCZOS` or `MP_CHACO_RQI`
3958be712e4SBarry Smith 
3968be712e4SBarry Smith   Options Database Key:
3978be712e4SBarry Smith . -mat_partitioning_chaco_eigen_solver <method> - the eigensolver
3988be712e4SBarry Smith 
3998be712e4SBarry Smith   Level: advanced
4008be712e4SBarry Smith 
4018be712e4SBarry Smith   Note:
4028be712e4SBarry Smith   The default is to use a Lanczos method. See Chaco documentation for details.
4038be712e4SBarry Smith 
4048be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenTol()`, `MatPartitioningChacoSetEigenNumber()`,
4058be712e4SBarry Smith           `MatPartitioningChacoGetEigenSolver()`
4068be712e4SBarry Smith @*/
MatPartitioningChacoSetEigenSolver(MatPartitioning part,MPChacoEigenType method)4078be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetEigenSolver(MatPartitioning part, MPChacoEigenType method)
4088be712e4SBarry Smith {
4098be712e4SBarry Smith   PetscFunctionBegin;
4108be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
4118be712e4SBarry Smith   PetscValidLogicalCollectiveEnum(part, method, 2);
4128be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetEigenSolver_C", (MatPartitioning, MPChacoEigenType), (part, method));
4138be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
4148be712e4SBarry Smith }
4158be712e4SBarry Smith 
MatPartitioningChacoSetEigenSolver_Chaco(MatPartitioning part,MPChacoEigenType method)4168be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetEigenSolver_Chaco(MatPartitioning part, MPChacoEigenType method)
4178be712e4SBarry Smith {
4188be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
4198be712e4SBarry Smith 
4208be712e4SBarry Smith   PetscFunctionBegin;
4218be712e4SBarry Smith   switch (method) {
4228be712e4SBarry Smith   case MP_CHACO_LANCZOS:
4238be712e4SBarry Smith   case MP_CHACO_RQI:
4248be712e4SBarry Smith     chaco->eigen_method = method;
4258be712e4SBarry Smith     break;
4268be712e4SBarry Smith   default:
4278be712e4SBarry Smith     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Chaco: Unknown or unsupported option");
4288be712e4SBarry Smith   }
4298be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
4308be712e4SBarry Smith }
4318be712e4SBarry Smith 
4328be712e4SBarry Smith /*@
4338be712e4SBarry Smith   MatPartitioningChacoGetEigenSolver - Get the eigensolver used by the Chaco partitioner.
4348be712e4SBarry Smith 
4358be712e4SBarry Smith   Not Collective
4368be712e4SBarry Smith 
4378be712e4SBarry Smith   Input Parameter:
4388be712e4SBarry Smith . part - the partitioning context
4398be712e4SBarry Smith 
4408be712e4SBarry Smith   Output Parameter:
4418be712e4SBarry Smith . method - the method
4428be712e4SBarry Smith 
4438be712e4SBarry Smith   Level: advanced
4448be712e4SBarry Smith 
4458be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenSolver()`
4468be712e4SBarry Smith @*/
MatPartitioningChacoGetEigenSolver(MatPartitioning part,MPChacoEigenType * method)4478be712e4SBarry Smith PetscErrorCode MatPartitioningChacoGetEigenSolver(MatPartitioning part, MPChacoEigenType *method)
4488be712e4SBarry Smith {
4498be712e4SBarry Smith   PetscFunctionBegin;
4508be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
4518be712e4SBarry Smith   PetscAssertPointer(method, 2);
4528be712e4SBarry Smith   PetscUseMethod(part, "MatPartitioningChacoGetEigenSolver_C", (MatPartitioning, MPChacoEigenType *), (part, method));
4538be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
4548be712e4SBarry Smith }
4558be712e4SBarry Smith 
MatPartitioningChacoGetEigenSolver_Chaco(MatPartitioning part,MPChacoEigenType * method)4568be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoGetEigenSolver_Chaco(MatPartitioning part, MPChacoEigenType *method)
4578be712e4SBarry Smith {
4588be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
4598be712e4SBarry Smith 
4608be712e4SBarry Smith   PetscFunctionBegin;
4618be712e4SBarry Smith   *method = chaco->eigen_method;
4628be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
4638be712e4SBarry Smith }
4648be712e4SBarry Smith 
4658be712e4SBarry Smith /*@
4668be712e4SBarry Smith   MatPartitioningChacoSetEigenTol - Sets the tolerance for the eigensolver used by Chaco
4678be712e4SBarry Smith 
4688be712e4SBarry Smith   Collective
4698be712e4SBarry Smith 
4708be712e4SBarry Smith   Input Parameters:
4718be712e4SBarry Smith + part - the partitioning context
4728be712e4SBarry Smith - tol  - the tolerance
4738be712e4SBarry Smith 
4748be712e4SBarry Smith   Options Database Key:
4758be712e4SBarry Smith . -mat_partitioning_chaco_eigen_tol <tol> - Tolerance for eigensolver
4768be712e4SBarry Smith 
4778be712e4SBarry Smith   Note:
4788be712e4SBarry Smith   Must be positive. The default value is 0.001.
4798be712e4SBarry Smith 
4808be712e4SBarry Smith   Level: advanced
4818be712e4SBarry Smith 
4828be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenSolver()`, `MatPartitioningChacoGetEigenTol()`
4838be712e4SBarry Smith @*/
MatPartitioningChacoSetEigenTol(MatPartitioning part,PetscReal tol)4848be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetEigenTol(MatPartitioning part, PetscReal tol)
4858be712e4SBarry Smith {
4868be712e4SBarry Smith   PetscFunctionBegin;
4878be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
4888be712e4SBarry Smith   PetscValidLogicalCollectiveReal(part, tol, 2);
4898be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetEigenTol_C", (MatPartitioning, PetscReal), (part, tol));
4908be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
4918be712e4SBarry Smith }
4928be712e4SBarry Smith 
MatPartitioningChacoSetEigenTol_Chaco(MatPartitioning part,PetscReal tol)4938be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetEigenTol_Chaco(MatPartitioning part, PetscReal tol)
4948be712e4SBarry Smith {
4958be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
4968be712e4SBarry Smith 
4978be712e4SBarry Smith   PetscFunctionBegin;
4988be712e4SBarry Smith   if (tol == PETSC_DEFAULT) chaco->eigtol = 0.001;
4998be712e4SBarry Smith   else {
5008be712e4SBarry Smith     PetscCheck(tol > 0.0, PetscObjectComm((PetscObject)part), PETSC_ERR_ARG_OUTOFRANGE, "Tolerance must be positive");
5018be712e4SBarry Smith     chaco->eigtol = tol;
5028be712e4SBarry Smith   }
5038be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
5048be712e4SBarry Smith }
5058be712e4SBarry Smith 
5068be712e4SBarry Smith /*@
5078be712e4SBarry Smith   MatPartitioningChacoGetEigenTol - Gets the eigensolver tolerance used by Chaco
5088be712e4SBarry Smith 
5098be712e4SBarry Smith   Not Collective
5108be712e4SBarry Smith 
5118be712e4SBarry Smith   Input Parameter:
5128be712e4SBarry Smith . part - the partitioning context
5138be712e4SBarry Smith 
5148be712e4SBarry Smith   Output Parameter:
5158be712e4SBarry Smith . tol - the tolerance
5168be712e4SBarry Smith 
5178be712e4SBarry Smith   Level: advanced
5188be712e4SBarry Smith 
5198be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenTol()`
5208be712e4SBarry Smith @*/
MatPartitioningChacoGetEigenTol(MatPartitioning part,PetscReal * tol)5218be712e4SBarry Smith PetscErrorCode MatPartitioningChacoGetEigenTol(MatPartitioning part, PetscReal *tol)
5228be712e4SBarry Smith {
5238be712e4SBarry Smith   PetscFunctionBegin;
5248be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
5258be712e4SBarry Smith   PetscAssertPointer(tol, 2);
5268be712e4SBarry Smith   PetscUseMethod(part, "MatPartitioningChacoGetEigenTol_C", (MatPartitioning, PetscReal *), (part, tol));
5278be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
5288be712e4SBarry Smith }
5298be712e4SBarry Smith 
MatPartitioningChacoGetEigenTol_Chaco(MatPartitioning part,PetscReal * tol)5308be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoGetEigenTol_Chaco(MatPartitioning part, PetscReal *tol)
5318be712e4SBarry Smith {
5328be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
5338be712e4SBarry Smith 
5348be712e4SBarry Smith   PetscFunctionBegin;
5358be712e4SBarry Smith   *tol = chaco->eigtol;
5368be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
5378be712e4SBarry Smith }
5388be712e4SBarry Smith 
5398be712e4SBarry Smith /*@
5408be712e4SBarry Smith   MatPartitioningChacoSetEigenNumber - Sets the number of eigenvectors to compute by Chaco during partitioning
5418be712e4SBarry Smith   during partitioning.
5428be712e4SBarry Smith 
5438be712e4SBarry Smith   Collective
5448be712e4SBarry Smith 
5458be712e4SBarry Smith   Input Parameters:
5468be712e4SBarry Smith + part - the partitioning context
5478be712e4SBarry Smith - num  - the number of eigenvectors
5488be712e4SBarry Smith 
5498be712e4SBarry Smith   Options Database Key:
5508be712e4SBarry Smith . -mat_partitioning_chaco_eigen_number <n> - Number of eigenvectors
5518be712e4SBarry Smith 
5528be712e4SBarry Smith   Note:
5538be712e4SBarry Smith   Accepted values are 1, 2 or 3, indicating partitioning by bisection,
5548be712e4SBarry Smith   quadrisection, or octosection.
5558be712e4SBarry Smith 
5568be712e4SBarry Smith   Level: advanced
5578be712e4SBarry Smith 
5588be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenSolver()`, `MatPartitioningChacoGetEigenTol()`
5598be712e4SBarry Smith @*/
MatPartitioningChacoSetEigenNumber(MatPartitioning part,PetscInt num)5608be712e4SBarry Smith PetscErrorCode MatPartitioningChacoSetEigenNumber(MatPartitioning part, PetscInt num)
5618be712e4SBarry Smith {
5628be712e4SBarry Smith   PetscFunctionBegin;
5638be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
5648be712e4SBarry Smith   PetscValidLogicalCollectiveInt(part, num, 2);
5658be712e4SBarry Smith   PetscTryMethod(part, "MatPartitioningChacoSetEigenNumber_C", (MatPartitioning, PetscInt), (part, num));
5668be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
5678be712e4SBarry Smith }
5688be712e4SBarry Smith 
MatPartitioningChacoSetEigenNumber_Chaco(MatPartitioning part,PetscInt num)5698be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoSetEigenNumber_Chaco(MatPartitioning part, PetscInt num)
5708be712e4SBarry Smith {
5718be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
5728be712e4SBarry Smith 
5738be712e4SBarry Smith   PetscFunctionBegin;
5748be712e4SBarry Smith   if (num == PETSC_DEFAULT) chaco->eignum = 1;
5758be712e4SBarry Smith   else {
5768be712e4SBarry Smith     PetscCheck(num >= 1 && num <= 3, PetscObjectComm((PetscObject)part), PETSC_ERR_ARG_OUTOFRANGE, "Can only specify 1, 2 or 3 eigenvectors");
5778be712e4SBarry Smith     chaco->eignum = num;
5788be712e4SBarry Smith   }
5798be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
5808be712e4SBarry Smith }
5818be712e4SBarry Smith 
5828be712e4SBarry Smith /*@
5838be712e4SBarry Smith   MatPartitioningChacoGetEigenNumber - Gets the number of eigenvectors used by Chaco.
5848be712e4SBarry Smith 
5858be712e4SBarry Smith   Not Collective
5868be712e4SBarry Smith 
5878be712e4SBarry Smith   Input Parameter:
5888be712e4SBarry Smith . part - the partitioning context
5898be712e4SBarry Smith 
5908be712e4SBarry Smith   Output Parameter:
5918be712e4SBarry Smith . num - number of eigenvectors
5928be712e4SBarry Smith 
5938be712e4SBarry Smith   Level: advanced
5948be712e4SBarry Smith 
5958be712e4SBarry Smith .seealso: `MatPartitioningType`, `MatPartitioning`, `MATPARTITIONINGCHACO`, `MatPartitioningChacoSetEigenNumber()`
5968be712e4SBarry Smith @*/
MatPartitioningChacoGetEigenNumber(MatPartitioning part,PetscInt * num)5978be712e4SBarry Smith PetscErrorCode MatPartitioningChacoGetEigenNumber(MatPartitioning part, PetscInt *num)
5988be712e4SBarry Smith {
5998be712e4SBarry Smith   PetscFunctionBegin;
6008be712e4SBarry Smith   PetscValidHeaderSpecific(part, MAT_PARTITIONING_CLASSID, 1);
6018be712e4SBarry Smith   PetscAssertPointer(num, 2);
6028be712e4SBarry Smith   PetscUseMethod(part, "MatPartitioningChacoGetEigenNumber_C", (MatPartitioning, PetscInt *), (part, num));
6038be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
6048be712e4SBarry Smith }
6058be712e4SBarry Smith 
MatPartitioningChacoGetEigenNumber_Chaco(MatPartitioning part,PetscInt * num)6068be712e4SBarry Smith static PetscErrorCode MatPartitioningChacoGetEigenNumber_Chaco(MatPartitioning part, PetscInt *num)
6078be712e4SBarry Smith {
6088be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
6098be712e4SBarry Smith 
6108be712e4SBarry Smith   PetscFunctionBegin;
6118be712e4SBarry Smith   *num = chaco->eignum;
6128be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
6138be712e4SBarry Smith }
6148be712e4SBarry Smith 
MatPartitioningSetFromOptions_Chaco(MatPartitioning part,PetscOptionItems PetscOptionsObject)615*ce78bad3SBarry Smith static PetscErrorCode MatPartitioningSetFromOptions_Chaco(MatPartitioning part, PetscOptionItems PetscOptionsObject)
6168be712e4SBarry Smith {
6178be712e4SBarry Smith   PetscInt               i;
6188be712e4SBarry Smith   PetscReal              r;
6198be712e4SBarry Smith   PetscBool              flag;
6208be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
6218be712e4SBarry Smith   MPChacoGlobalType      global;
6228be712e4SBarry Smith   MPChacoLocalType       local;
6238be712e4SBarry Smith   MPChacoEigenType       eigen;
6248be712e4SBarry Smith 
6258be712e4SBarry Smith   PetscFunctionBegin;
6268be712e4SBarry Smith   PetscOptionsHeadBegin(PetscOptionsObject, "Chaco partitioning options");
6278be712e4SBarry Smith   PetscCall(PetscOptionsEnum("-mat_partitioning_chaco_global", "Global method", "MatPartitioningChacoSetGlobal", MPChacoGlobalTypes, (PetscEnum)chaco->global_method, (PetscEnum *)&global, &flag));
6288be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetGlobal(part, global));
6298be712e4SBarry Smith   PetscCall(PetscOptionsEnum("-mat_partitioning_chaco_local", "Local method", "MatPartitioningChacoSetLocal", MPChacoLocalTypes, (PetscEnum)chaco->local_method, (PetscEnum *)&local, &flag));
6308be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetLocal(part, local));
6318be712e4SBarry Smith   PetscCall(PetscOptionsReal("-mat_partitioning_chaco_coarse", "Coarse level", "MatPartitioningChacoSetCoarseLevel", 0.0, &r, &flag));
6328be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetCoarseLevel(part, r));
6338be712e4SBarry Smith   PetscCall(PetscOptionsEnum("-mat_partitioning_chaco_eigen_solver", "Eigensolver method", "MatPartitioningChacoSetEigenSolver", MPChacoEigenTypes, (PetscEnum)chaco->eigen_method, (PetscEnum *)&eigen, &flag));
6348be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetEigenSolver(part, eigen));
6358be712e4SBarry Smith   PetscCall(PetscOptionsReal("-mat_partitioning_chaco_eigen_tol", "Eigensolver tolerance", "MatPartitioningChacoSetEigenTol", chaco->eigtol, &r, &flag));
6368be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetEigenTol(part, r));
6378be712e4SBarry Smith   PetscCall(PetscOptionsInt("-mat_partitioning_chaco_eigen_number", "Number of eigenvectors: 1, 2, or 3 (bi-, quadri-, or octosection)", "MatPartitioningChacoSetEigenNumber", chaco->eignum, &i, &flag));
6388be712e4SBarry Smith   if (flag) PetscCall(MatPartitioningChacoSetEigenNumber(part, i));
6398be712e4SBarry Smith   PetscCall(PetscOptionsBool("-mat_partitioning_chaco_verbose", "Show library output", "", chaco->verbose, &chaco->verbose, NULL));
6408be712e4SBarry Smith   PetscOptionsHeadEnd();
6418be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
6428be712e4SBarry Smith }
6438be712e4SBarry Smith 
MatPartitioningDestroy_Chaco(MatPartitioning part)6448be712e4SBarry Smith static PetscErrorCode MatPartitioningDestroy_Chaco(MatPartitioning part)
6458be712e4SBarry Smith {
6468be712e4SBarry Smith   MatPartitioning_Chaco *chaco = (MatPartitioning_Chaco *)part->data;
6478be712e4SBarry Smith 
6488be712e4SBarry Smith   PetscFunctionBegin;
6498be712e4SBarry Smith   PetscCall(PetscFree(chaco));
6508be712e4SBarry Smith   /* clear composed functions */
6518be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetGlobal_C", NULL));
6528be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetGlobal_C", NULL));
6538be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetLocal_C", NULL));
6548be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetLocal_C", NULL));
6558be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetCoarseLevel_C", NULL));
6568be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenSolver_C", NULL));
6578be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenSolver_C", NULL));
6588be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenTol_C", NULL));
6598be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenTol_C", NULL));
6608be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenNumber_C", NULL));
6618be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenNumber_C", NULL));
6628be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
6638be712e4SBarry Smith }
6648be712e4SBarry Smith 
6658be712e4SBarry Smith /*MC
666613ce9feSSatish Balay    MATPARTITIONINGCHACO - Creates a partitioning context that uses the external package Chaco {cite}`chaco95`
6678be712e4SBarry Smith 
6688be712e4SBarry Smith    Level: beginner
6698be712e4SBarry Smith 
6708be712e4SBarry Smith    Note:
6718be712e4SBarry Smith    Does not use the `MatPartitioningSetUseEdgeWeights()` option
6728be712e4SBarry Smith 
673613ce9feSSatish Balay .seealso: `MatPartitioning`, `MatPartitioningSetType()`, `MatPartitioningType`
6748be712e4SBarry Smith M*/
6758be712e4SBarry Smith 
MatPartitioningCreate_Chaco(MatPartitioning part)6768be712e4SBarry Smith PETSC_EXTERN PetscErrorCode MatPartitioningCreate_Chaco(MatPartitioning part)
6778be712e4SBarry Smith {
6788be712e4SBarry Smith   MatPartitioning_Chaco *chaco;
6798be712e4SBarry Smith 
6808be712e4SBarry Smith   PetscFunctionBegin;
6818be712e4SBarry Smith   PetscCall(PetscNew(&chaco));
6828be712e4SBarry Smith   part->data = (void *)chaco;
6838be712e4SBarry Smith 
6848be712e4SBarry Smith   chaco->global_method = MP_CHACO_MULTILEVEL;
6858be712e4SBarry Smith   chaco->local_method  = MP_CHACO_KERNIGHAN;
6868be712e4SBarry Smith   chaco->eigen_method  = MP_CHACO_LANCZOS;
6878be712e4SBarry Smith   chaco->nbvtxcoarsed  = 200;
6888be712e4SBarry Smith   chaco->eignum        = 1;
6898be712e4SBarry Smith   chaco->eigtol        = 0.001;
6908be712e4SBarry Smith   chaco->verbose       = PETSC_FALSE;
6918be712e4SBarry Smith 
6928be712e4SBarry Smith   part->ops->apply          = MatPartitioningApply_Chaco;
6938be712e4SBarry Smith   part->ops->view           = MatPartitioningView_Chaco;
6948be712e4SBarry Smith   part->ops->destroy        = MatPartitioningDestroy_Chaco;
6958be712e4SBarry Smith   part->ops->setfromoptions = MatPartitioningSetFromOptions_Chaco;
6968be712e4SBarry Smith 
6978be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetGlobal_C", MatPartitioningChacoSetGlobal_Chaco));
6988be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetGlobal_C", MatPartitioningChacoGetGlobal_Chaco));
6998be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetLocal_C", MatPartitioningChacoSetLocal_Chaco));
7008be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetLocal_C", MatPartitioningChacoGetLocal_Chaco));
7018be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetCoarseLevel_C", MatPartitioningChacoSetCoarseLevel_Chaco));
7028be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenSolver_C", MatPartitioningChacoSetEigenSolver_Chaco));
7038be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenSolver_C", MatPartitioningChacoGetEigenSolver_Chaco));
7048be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenTol_C", MatPartitioningChacoSetEigenTol_Chaco));
7058be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenTol_C", MatPartitioningChacoGetEigenTol_Chaco));
7068be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoSetEigenNumber_C", MatPartitioningChacoSetEigenNumber_Chaco));
7078be712e4SBarry Smith   PetscCall(PetscObjectComposeFunction((PetscObject)part, "MatPartitioningChacoGetEigenNumber_C", MatPartitioningChacoGetEigenNumber_Chaco));
7088be712e4SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
7098be712e4SBarry Smith }
710