1 2 static char help[] = "MatLoad test for loading matrices that are created by DMCreateMatrix() and\n\ 3 stored in binary via MatView_MPI_DA.MatView_MPI_DA stores the matrix\n\ 4 in natural ordering. Hence MatLoad() has to read the matrix first in\n\ 5 natural ordering and then permute it back to the application ordering.This\n\ 6 example is used for testing the subroutine MatLoad_MPI_DA\n\n"; 7 8 #include <petscdm.h> 9 #include <petscdmda.h> 10 11 int main(int argc,char **argv) 12 { 13 PetscInt X = 10,Y = 8,Z=8; 14 DM da; 15 PetscViewer viewer; 16 Mat A; 17 18 CHKERRQ(PetscInitialize(&argc,&argv,(char*)0,help)); 19 CHKERRQ(PetscViewerBinaryOpen(PETSC_COMM_WORLD,"temp.dat",FILE_MODE_WRITE,&viewer)); 20 21 /* Read options */ 22 CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-X",&X,NULL)); 23 CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-Y",&Y,NULL)); 24 CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-Z",&Z,NULL)); 25 26 /* Create distributed array and get vectors */ 27 CHKERRQ(DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,X,Y,Z,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,NULL,&da)); 28 CHKERRQ(DMSetFromOptions(da)); 29 CHKERRQ(DMSetUp(da)); 30 CHKERRQ(DMSetMatType(da,MATMPIAIJ)); 31 CHKERRQ(DMCreateMatrix(da,&A)); 32 CHKERRQ(MatShift(A,X)); 33 CHKERRQ(MatView(A,viewer)); 34 CHKERRQ(MatDestroy(&A)); 35 CHKERRQ(PetscViewerDestroy(&viewer)); 36 37 CHKERRQ(PetscViewerBinaryOpen(PETSC_COMM_WORLD,"temp.dat",FILE_MODE_READ,&viewer)); 38 CHKERRQ(DMCreateMatrix(da,&A)); 39 CHKERRQ(MatLoad(A,viewer)); 40 41 /* Free memory */ 42 CHKERRQ(MatDestroy(&A)); 43 CHKERRQ(PetscViewerDestroy(&viewer)); 44 CHKERRQ(DMDestroy(&da)); 45 CHKERRQ(PetscFinalize()); 46 return 0; 47 } 48