Actual source code: ex191.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  1: static char help[] = "Tests MatLoad() for dense matrix with uneven dimensions set in program\n\n";

  3: #include <petscmat.h>

  7: int main(int argc,char **args)
  8: {
  9:   Mat            A;
 10:   PetscViewer    fd;
 12:   PetscMPIInt    rank;
 13:   PetscScalar    *Av;
 14:   PetscInt       i;

 16:   PetscInitialize(&argc,&args,(char*)0,help);
 17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

 19:   MatCreateDense(PETSC_COMM_WORLD,6,6,12,12,NULL,&A);
 20:   MatDenseGetArray(A,&Av);
 21:   for (i=0; i<6*12; i++) Av[i] = (PetscScalar) i;
 22:   MatDenseRestoreArray(A,&Av);

 24:   /* Load matrices */
 25:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"ex191matrix",FILE_MODE_WRITE,&fd);
 26:   PetscViewerPushFormat(fd,PETSC_VIEWER_NATIVE);
 27:   MatView(A,fd);
 28:   MatDestroy(&A);
 29:   PetscViewerPopFormat(fd);
 30:   PetscViewerDestroy(&fd);

 32:   MatCreate(PETSC_COMM_WORLD,&A);
 33:   MatSetType(A,MATDENSE);
 34:   if (!rank) {
 35:     MatSetSizes(A, 4, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);
 36:   } else {
 37:     MatSetSizes(A, 8, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);
 38:   }
 39:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"ex191matrix",FILE_MODE_READ,&fd);
 40:   MatLoad(A,fd);
 41:   PetscViewerDestroy(&fd);
 42:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);
 43:   PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_INFO_DETAIL);
 44:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);
 45:   PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);
 46:   MatDestroy(&A);
 47:   PetscFinalize();
 48:   return 0;
 49: }