Actual source code: spqmd.c


  2: #include <petscmat.h>
  3: #include <petsc/private/matorderimpl.h>

  5: /*
  6:     MatGetOrdering_QMD - Find the Quotient Minimum Degree ordering of a given matrix.
  7: */
  8: PETSC_INTERN PetscErrorCode MatGetOrdering_QMD(Mat mat, MatOrderingType type, IS *row, IS *col)
  9: {
 10:   PetscInt        i, *deg, *marker, *rchset, *nbrhd, *qsize, *qlink, nofsub, *iperm, nrow, *perm;
 11:   const PetscInt *ia, *ja;
 12:   PetscBool       done;

 14:   PetscFunctionBegin;
 15:   PetscCall(MatGetRowIJ(mat, 1, PETSC_TRUE, PETSC_TRUE, &nrow, &ia, &ja, &done));
 16:   PetscCheck(done, PetscObjectComm((PetscObject)mat), PETSC_ERR_SUP, "Cannot get rows for matrix");

 18:   PetscCall(PetscMalloc1(nrow, &perm));
 19:   PetscCall(PetscMalloc5(nrow, &iperm, nrow, &deg, nrow, &marker, nrow, &rchset, nrow, &nbrhd));
 20:   PetscCall(PetscMalloc2(nrow, &qsize, nrow, &qlink));
 21:   /* WARNING - genqmd trashes ja */
 22:   PetscCall(SPARSEPACKgenqmd(&nrow, ia, ja, perm, iperm, deg, marker, rchset, nbrhd, qsize, qlink, &nofsub));
 23:   PetscCall(MatRestoreRowIJ(mat, 1, PETSC_TRUE, PETSC_TRUE, NULL, &ia, &ja, &done));

 25:   PetscCall(PetscFree2(qsize, qlink));
 26:   PetscCall(PetscFree5(iperm, deg, marker, rchset, nbrhd));
 27:   for (i = 0; i < nrow; i++) perm[i]--;
 28:   PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_COPY_VALUES, row));
 29:   PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_OWN_POINTER, col));
 30:   PetscFunctionReturn(PETSC_SUCCESS);
 31: }