Actual source code: ex190.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  1: static char help[] = "Tests MatLoad() 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;
 11:   char           file[PETSC_MAX_PATH_LEN];
 13:   PetscBool      flg;
 14:   PetscMPIInt    rank;

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

 19:   /* Determine files from which we read the matrix */
 20:   PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
 21:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f");

 23:   /* Load matrices */
 24:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 25:   MatCreate(PETSC_COMM_WORLD,&A);
 26:   MatSetFromOptions(A);
 27:   MatSetBlockSize(A,2);
 28:   if (!rank) {
 29:     MatSetSizes(A, 4, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);
 30:   } else {
 31:     MatSetSizes(A, 8, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);
 32:   }
 33:   MatLoad(A,fd);
 34:   PetscViewerDestroy(&fd);
 35:   MatDestroy(&A);
 36:   PetscFinalize();
 37:   return 0;
 38: }