static char help[] = "Tests reordering a matrix.\n\n"; #include int main(int argc, char **args) { Mat C; PetscInt i, j, m = 5, n = 5, Ii, J; PetscScalar v; IS perm, iperm; PetscFunctionBeginUser; PetscCall(PetscInitialize(&argc, &args, (char *)0, help)); PetscCall(MatCreate(PETSC_COMM_SELF, &C)); PetscCall(MatSetSizes(C, PETSC_DECIDE, PETSC_DECIDE, m * n, m * n)); PetscCall(MatSetFromOptions(C)); PetscCall(MatSetUp(C)); /* create the matrix for the five point stencil, YET AGAIN*/ for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { v = -1.0; Ii = j + n * i; if (i > 0) { J = Ii - n; PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES)); } if (i < m - 1) { J = Ii + n; PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES)); } if (j > 0) { J = Ii - 1; PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES)); } if (j < n - 1) { J = Ii + 1; PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES)); } v = 4.0; PetscCall(MatSetValues(C, 1, &Ii, 1, &Ii, &v, INSERT_VALUES)); } } PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY)); PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY)); PetscCall(MatGetOrdering(C, MATORDERINGND, &perm, &iperm)); PetscCall(ISView(perm, PETSC_VIEWER_STDOUT_SELF)); PetscCall(ISView(iperm, PETSC_VIEWER_STDOUT_SELF)); PetscCall(MatView(C, PETSC_VIEWER_STDOUT_SELF)); PetscCall(ISDestroy(&perm)); PetscCall(ISDestroy(&iperm)); PetscCall(MatDestroy(&C)); PetscCall(PetscFinalize()); return 0; } /*TEST test: TEST*/