Date: 2013-07-02T14:44:05+00:00

Actual source code: ex61.c
petsc-3.4.2 2013-07-02

      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: */
     15: int main(int argc,char **args)
     16: {
     17:   Mat            A;
     18:   PetscScalar    v;
     20:   PetscInt       i,j,rowlens[] = {2,3,1},cols[] = {0,2,0,1,2,2};
     21:   PetscBool      flg;

     23:   PetscInitialize(&argc,&args,(char*)0,help);

     25:   PetscOptionsHasName(NULL,"-baij",&flg);
     26:   if (flg) {
     27:     MatCreateSeqBAIJ(PETSC_COMM_WORLD,1,3,3,0,rowlens,&A);
     28:     MatSeqBAIJSetColumnIndices(A,cols);
     29:   } else {
     30:     MatCreateSeqAIJ(PETSC_COMM_WORLD,3,3,0,rowlens,&A);
     31:     MatSeqAIJSetColumnIndices(A,cols);
     32:   }

     34:   i    = 0; j = 0; v = 1.0;
     35:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
     36:   i    = 0; j = 2; v = 3.0;
     37:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);

     39:   i    = 1; j = 0; v = 1.0;
     40:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
     41:   i    = 1; j = 1; v = 2.0;
     42:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
     43:   i    = 1; j = 2; v = 3.0;
     44:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);

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

     49:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
     50:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
     51:   MatView(A,PETSC_VIEWER_STDOUT_WORLD);

     53:   MatDestroy(&A);
     54:   PetscFinalize();
     55:   return 0;
     56: }