1 static char help[] = "Tests MatLoad() for dense matrix with uneven dimensions set in program\n\n"; 2 3 #include <petscmat.h> 4 5 int main(int argc, char **args) { 6 Mat A; 7 PetscViewer fd; 8 PetscMPIInt rank; 9 PetscScalar *Av; 10 PetscInt i; 11 12 PetscFunctionBeginUser; 13 PetscCall(PetscInitialize(&argc, &args, (char *)0, help)); 14 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); 15 16 PetscCall(MatCreateDense(PETSC_COMM_WORLD, 6, 6, 12, 12, NULL, &A)); 17 PetscCall(MatDenseGetArray(A, &Av)); 18 for (i = 0; i < 6 * 12; i++) Av[i] = (PetscScalar)i; 19 PetscCall(MatDenseRestoreArray(A, &Av)); 20 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)); 28 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 } 47 48 /*TEST 49 50 test: 51 nsize: 2 52 filter: grep -v alloced 53 54 TEST*/ 55