Actual source code: ex190.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1: static char help[] = "Tests MatLoad() with uneven dimensions set in program\n\n";

  3:  #include <petscmat.h>

  5: int main(int argc,char **args)
  6: {
  7:   Mat            A;
  8:   PetscViewer    fd;
  9:   char           file[PETSC_MAX_PATH_LEN];
 11:   PetscBool      flg;
 12:   PetscMPIInt    rank;

 14:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 15:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

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

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