Actual source code: ex182.c

petsc-3.6.1 2015-08-06
Report Typos and Errors
  2: static char help[] = "Tests using MatShift() to create a constant diagonal matrix\n\n";

  4: #include <petscmat.h>

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

 18:   PetscInitialize(&argc,&argv,(char*) 0,help);
 19:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

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

 28:   MatShift(A,1.0);

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