Actual source code: ex70.c

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

  2: static char help[] = "Tests Vec/MatSetValues() with negative row and column indices.\n\n";

  4:  #include <petscmat.h>
  5:  #include <petscpc.h>

  7: int main(int argc,char **args)
  8: {
  9:   Mat            C;
 10:   PetscInt       i[2],j[2];
 12:   PetscScalar    v[] = {1.0,2.0,3.0,4.0};
 13:   Vec            x;

 15:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 16:   MatCreate(PETSC_COMM_WORLD,&C);
 17:   MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,3,3);
 18:   MatSetFromOptions(C);
 19:   VecCreateSeq(PETSC_COMM_WORLD,3,&x);

 21:   i[0] = 1; i[1] = -1; j[0] = 1; j[1] = 2;
 22:   MatSetValues(C,2,i,2,j,v,INSERT_VALUES);
 23:   MatSetValues(C,2,j,2,i,v,INSERT_VALUES);
 24:   VecSetValues(x,2,i,v,INSERT_VALUES);

 26:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 27:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);

 29:   MatView(C,PETSC_VIEWER_STDOUT_WORLD);
 30:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 32:   VecDestroy(&x);
 33:   MatDestroy(&C);

 35:   PetscFinalize();
 36:   return ierr;
 37: }