Actual source code: ex197.c
petsc-3.13.6 2020-09-29
1: static char help[] = "Test MatMultHermitianTranspose() and MatMultHermitianTransposeAdd().\n\n";
3: #include <petscmat.h>
5: int main(int argc,char **args)
6: {
7: Mat A;
8: Vec x,y,ys;
10: PetscInt i,j;
11: PetscScalar v;
13: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
14: MatCreate(PETSC_COMM_WORLD,&A);
15: MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,2,2);
16: MatSetType(A,MATAIJ);
17: MatSetFromOptions(A);
18: MatSetUp(A);
20: i = 0; j = 0; v = 2.0;
21: MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
22: i = 0; j = 1; v = 3.0 + 4.0*PETSC_i;
23: MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
24: i = 1; j = 0; v = 5.0 + 6.0*PETSC_i;
25: MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
26: i = 1; j = 1; v = 7.0 + 8.0*PETSC_i;
27: MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
28: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
29: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
31: /* Create vectors */
32: VecCreate(PETSC_COMM_WORLD,&y);
33: VecSetSizes(y,PETSC_DECIDE,2);
34: VecSetFromOptions(y);
35: VecDuplicate(y,&ys);
36: VecDuplicate(y,&x);
38: i = 0; v = 10.0 + 11.0*PETSC_i;
39: VecSetValues(x,1,&i,&v,INSERT_VALUES);
40: i = 1; v = 100.0 + 120.0*PETSC_i;
41: VecSetValues(x,1,&i,&v,INSERT_VALUES);
42: VecAssemblyBegin(x);
43: VecAssemblyEnd(x);
45: MatMultHermitianTranspose(A,x,y);
46: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
47: MatMultHermitianTransposeAdd(A,x,y,ys);
48: VecView(ys,PETSC_VIEWER_STDOUT_WORLD);
49:
50: MatDestroy(&A);
52: VecDestroy(&x);
53: VecDestroy(&y);
54: VecDestroy(&ys);
55: PetscFinalize();
56: return ierr;
57: }
60: /*TEST
62: build:
63: requires: complex
64: test:
66: test:
67: suffix: 2
68: nsize: 2
70: TEST*/