Actual source code: ex61.c

petsc-3.14.6 2021-03-30
Report Typos and Errors

  2: static char help[] = "Tests MatSeq(B)AIJSetColumnIndices().\n\n";

  4: #include <petscmat.h>

  6: /*
  7:       Generate the following matrix:

  9:          1 0 3
 10:          1 2 3
 11:          0 0 3
 12: */
 13: int main(int argc,char **args)
 14: {
 15:   Mat            A;
 16:   PetscScalar    v;
 18:   PetscInt       i,j,rowlens[] = {2,3,1},cols[] = {0,2,0,1,2,2};
 19:   PetscBool      flg;

 21:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 22:   PetscOptionsHasName(NULL,NULL,"-baij",&flg);
 23:   if (flg) {
 24:     MatCreateSeqBAIJ(PETSC_COMM_WORLD,1,3,3,0,rowlens,&A);
 25:     MatSeqBAIJSetColumnIndices(A,cols);
 26:   } else {
 27:     MatCreateSeqAIJ(PETSC_COMM_WORLD,3,3,0,rowlens,&A);
 28:     MatSeqAIJSetColumnIndices(A,cols);
 29:   }

 31:   i    = 0; j = 0; v = 1.0;
 32:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 33:   i    = 0; j = 2; v = 3.0;
 34:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);

 36:   i    = 1; j = 0; v = 1.0;
 37:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 38:   i    = 1; j = 1; v = 2.0;
 39:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 40:   i    = 1; j = 2; v = 3.0;
 41:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);

 43:   i    = 2; j = 2; v = 3.0;
 44:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);

 46:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 47:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 48:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

 50:   MatDestroy(&A);
 51:   PetscFinalize();
 52:   return ierr;
 53: }


 56: /*TEST

 58:    test:

 60:    test:
 61:       suffix: 2
 62:       args: -baij

 64: TEST*/