Date: 2025-03-29T05:58:31+00:00

Actual source code: sp1wd.c

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

      4: /*
      5:     MatGetOrdering_1WD - Find the 1-way dissection ordering of a given matrix.
      6: */
      7: PETSC_INTERN PetscErrorCode MatGetOrdering_1WD(Mat mat, MatOrderingType type, IS *row, IS *col)
      8: {
      9:   PetscInt        i, *mask, *xls, nblks, *xblk, *ls, nrow, *perm;
     10:   const PetscInt *ia, *ja;
     11:   PetscBool       done;

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

     17:   PetscCall(PetscMalloc5(nrow, &mask, nrow + 1, &xls, nrow, &ls, nrow + 1, &xblk, nrow, &perm));
     18:   PetscCall(SPARSEPACKgen1wd(&nrow, ia, ja, mask, &nblks, xblk, perm, xls, ls));
     19:   PetscCall(MatRestoreRowIJ(mat, 1, PETSC_TRUE, PETSC_TRUE, NULL, &ia, &ja, &done));

     21:   for (i = 0; i < nrow; i++) perm[i]--;

     23:   PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_COPY_VALUES, row));
     24:   PetscCall(ISCreateGeneral(PETSC_COMM_SELF, nrow, perm, PETSC_COPY_VALUES, col));
     25:   PetscCall(PetscFree5(mask, xls, ls, xblk, perm));
     26:   PetscFunctionReturn(PETSC_SUCCESS);
     27: }