Actual source code: ex182.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

  2: static char help[] = "Tests using MatShift() to create a constant diagonal matrix\n\n";

  4:  #include <petscmat.h>

  6: int main(int argc,char **argv)
  7: {
  8:   Mat            A,F;
  9:   MatFactorInfo  info;
 11:   PetscInt       m = 10;
 12:   IS             perm;
 13:   PetscMPIInt    size;
 14:   PetscBool      issbaij;

 16:   PetscInitialize(&argc,&argv,(char*) 0,help);if (ierr) return ierr;
 17:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 19:   MatCreate(PETSC_COMM_WORLD,&A);
 20:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,m);
 21:   MatSetFromOptions(A);
 22:   MatSetUp(A);
 23:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 24:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 26:   MatShift(A,1.0);

 28:   PetscObjectTypeCompare((PetscObject)A,MATSEQSBAIJ,&issbaij);
 29:   if (size == 1 && !issbaij) {
 30:     MatGetFactor(A,MATSOLVERPETSC,MAT_FACTOR_LU,&F);
 31:     MatFactorInfoInitialize(&info);
 32:     ISCreateStride(PETSC_COMM_SELF,m,0,1,&perm);
 33:     MatLUFactorSymbolic(F,A,perm,perm,&info);
 34:     MatLUFactorNumeric(F,A,&info);
 35:     MatDestroy(&F);
 36:     ISDestroy(&perm);
 37:   }
 38:   MatDestroy(&A);
 39:   PetscFinalize();
 40:   return ierr;
 41: }