Actual source code: ex162.c

petsc-3.13.6 2020-09-29
Report Typos and Errors
  1: static char help[] = "Tests MatShift for SeqAIJ matrices with some missing diagonal entries\n\n";

  3:  #include <petscmat.h>

  5: int main(int argc,char **argv)
  6: {
  7:   Mat                  A;
  8:   PetscInt             coli[4],row;
  9:   PetscScalar          vali[4];
 10:   PetscErrorCode       ierr;
 11:   PetscMPIInt          size;

 13:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 14:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 15:   if (size != 1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"This is a uniprocessor example only!");

 17:   MatCreate(PETSC_COMM_SELF,&A);
 18:   MatSetSizes(A,4,4,4,4);
 19:   MatSetType(A,MATSEQAIJ);
 20:   MatSeqAIJSetPreallocation(A,4,NULL);

 22:   row = 0; coli[0] = 1; coli[1] = 3; vali[0] = 1.0; vali[1] = 2.0;
 23:   MatSetValues(A,1,&row,2,coli,vali,ADD_VALUES);

 25:   row = 1; coli[0] = 0; coli[1] = 1; coli[2] = 2; coli[3] = 3; vali[0] = 3.0; vali[1] = 4.0; vali[2] = 5.0; vali[3] = 6.0;
 26:   MatSetValues(A,1,&row,4,coli,vali,ADD_VALUES);

 28:   row = 2; coli[0] = 0; coli[1] = 3; vali[0] = 7.0; vali[1] = 8.0;
 29:   MatSetValues(A,1,&row,2,coli,vali,ADD_VALUES);

 31:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 32:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 33:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 35:   MatShift(A,0.0);
 36:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 38:   MatDestroy(&A);
 39:   PetscFinalize();
 40:   return ierr;
 41: }


 44: /*TEST

 46:    test:


 49: TEST*/