Actual source code: ex191.c
1: static char help[] = "Tests MatLoad() for dense matrix with uneven dimensions set in program\n\n";
3: #include <petscmat.h>
5: int main(int argc, char **args)
6: {
7: Mat A;
8: PetscViewer fd;
9: PetscMPIInt rank;
10: PetscScalar *Av;
12: PetscFunctionBeginUser;
13: PetscCall(PetscInitialize(&argc, &args, NULL, help));
14: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
16: PetscCall(MatCreateDense(PETSC_COMM_WORLD, 6, 6, 12, 12, NULL, &A));
17: PetscCall(MatDenseGetArrayAndMemType(A, &Av, NULL));
18: for (PetscInt i = 0; i < 6 * 12; i++) Av[i] = (PetscScalar)i;
19: PetscCall(MatDenseRestoreArrayAndMemType(A, &Av));
21: /* Load matrices */
22: PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, "ex191matrix", FILE_MODE_WRITE, &fd));
23: PetscCall(PetscViewerPushFormat(fd, PETSC_VIEWER_NATIVE));
24: PetscCall(MatView(A, fd));
25: PetscCall(MatDestroy(&A));
26: PetscCall(PetscViewerPopFormat(fd));
27: PetscCall(PetscViewerDestroy(&fd));
29: PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
30: PetscCall(MatSetType(A, MATDENSE));
31: if (rank == 0) {
32: PetscCall(MatSetSizes(A, 4, PETSC_DETERMINE, PETSC_DETERMINE, PETSC_DETERMINE));
33: } else {
34: PetscCall(MatSetSizes(A, 8, PETSC_DETERMINE, PETSC_DETERMINE, PETSC_DETERMINE));
35: }
36: PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, "ex191matrix", FILE_MODE_READ, &fd));
37: PetscCall(MatLoad(A, fd));
38: PetscCall(PetscViewerDestroy(&fd));
39: PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD));
40: PetscCall(PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_INFO_DETAIL));
41: PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD));
42: PetscCall(PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD));
43: PetscCall(MatDestroy(&A));
44: PetscCall(PetscFinalize());
45: return 0;
46: }
48: /*TEST
50: test:
51: nsize: 2
52: filter: grep -v alloced
54: TEST*/