1*8be712e4SBarry Smith #include <petscmat.h>
2*8be712e4SBarry Smith #include <petsc/private/matorderimpl.h>
3*8be712e4SBarry Smith
4*8be712e4SBarry Smith /*
5*8be712e4SBarry Smith MatGetOrdering_RCM - Find the Reverse Cuthill-McKee ordering of a given matrix.
6*8be712e4SBarry Smith */
MatGetOrdering_RCM(Mat mat,MatOrderingType type,IS * row,IS * col)7*8be712e4SBarry Smith PETSC_INTERN PetscErrorCode MatGetOrdering_RCM(Mat mat, MatOrderingType type, IS *row, IS *col)
8*8be712e4SBarry Smith {
9*8be712e4SBarry Smith PetscInt i, *mask, *xls, nrow, *perm;
10*8be712e4SBarry Smith const PetscInt *ia, *ja;
11*8be712e4SBarry Smith PetscBool done;
12*8be712e4SBarry Smith
13*8be712e4SBarry Smith PetscFunctionBegin;
14*8be712e4SBarry Smith PetscCall(MatGetRowIJ(mat, 1, PETSC_TRUE, PETSC_TRUE, &nrow, &ia, &ja, &done));
15*8be712e4SBarry Smith PetscCheck(done, PetscObjectComm((PetscObject)mat), PETSC_ERR_SUP, "Cannot get rows for matrix");
16*8be712e4SBarry Smith
17*8be712e4SBarry Smith PetscCall(PetscMalloc3(nrow, &mask, nrow, &perm, 2 * nrow, &xls));
18*8be712e4SBarry Smith PetscCall(SPARSEPACKgenrcm(&nrow, ia, ja, perm, mask, xls));
19*8be712e4SBarry Smith PetscCall(MatRestoreRowIJ(mat, 1, PETSC_TRUE, PETSC_TRUE, NULL, &ia, &ja, &done));
20*8be712e4SBarry Smith
21*8be712e4SBarry Smith /* shift because Sparsepack indices start at one */
22*8be712e4SBarry Smith for (i = 0; i < nrow; i++) perm[i]--;
23*8be712e4SBarry Smith PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_COPY_VALUES, row));
24*8be712e4SBarry Smith PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_COPY_VALUES, col));
25*8be712e4SBarry Smith PetscCall(PetscFree3(mask, perm, xls));
26*8be712e4SBarry Smith PetscFunctionReturn(PETSC_SUCCESS);
27*8be712e4SBarry Smith }
28