Actual source code: ex70.c
petsc-3.6.1 2015-08-06
2: static char help[] = "Tests Vec/MatSetValues() with negative row and column indices.\n\n";
4: #include <petscmat.h>
5: #include <petscpc.h>
9: int main(int argc,char **args)
10: {
11: Mat C;
12: PetscInt i[2],j[2];
14: PetscScalar v[] = {1.0,2.0,3.0,4.0};
15: Vec x;
17: PetscInitialize(&argc,&args,(char*)0,help);
19: MatCreate(PETSC_COMM_WORLD,&C);
20: MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,3,3);
21: MatSetFromOptions(C);
22: VecCreateSeq(PETSC_COMM_WORLD,3,&x);
24: i[0] = 1; i[1] = -1; j[0] = 1; j[1] = 2;
25: MatSetValues(C,2,i,2,j,v,INSERT_VALUES);
26: MatSetValues(C,2,j,2,i,v,INSERT_VALUES);
27: VecSetValues(x,2,i,v,INSERT_VALUES);
29: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
30: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
32: MatView(C,PETSC_VIEWER_STDOUT_WORLD);
33: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
35: VecDestroy(&x);
36: MatDestroy(&C);
38: PetscFinalize();
39: return 0;
40: }