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