xref: /petsc/src/mat/tests/ex175.c (revision 66af8762ec03dbef0e079729eb2a1734a35ed7ff)
1 static char help[] = "Tests MatCreateHermitianTranspose().\n\n";
2 
3 #include <petscmat.h>
4 
5 int main(int argc, char **args)
6 {
7   Mat         C, C_htransposed, Cht, C_empty;
8   PetscInt    i, j, m = 10, n = 10;
9   PetscScalar v;
10 
11   PetscFunctionBeginUser;
12   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
13   /* Create a complex non-hermitian matrix */
14   PetscCall(MatCreate(PETSC_COMM_SELF, &C));
15   PetscCall(MatSetSizes(C, PETSC_DECIDE, PETSC_DECIDE, m, n));
16   PetscCall(MatSetFromOptions(C));
17   PetscCall(MatSetUp(C));
18   for (i = 0; i < m; i++) {
19     for (j = 0; j < n; j++) {
20       v = 0.0 - 1.0 * PETSC_i;
21       if (i > j && i - j < 2) PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
22     }
23   }
24   PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY));
25   PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY));
26 
27   PetscCall(MatCreateHermitianTranspose(C, &C_htransposed));
28 
29   PetscCall(MatView(C, PETSC_VIEWER_STDOUT_SELF));
30   PetscCall(MatDuplicate(C_htransposed, MAT_COPY_VALUES, &Cht));
31   PetscCall(MatView(Cht, PETSC_VIEWER_STDOUT_SELF));
32   PetscCall(MatDuplicate(C_htransposed, MAT_DO_NOT_COPY_VALUES, &C_empty));
33   PetscCall(MatView(C_empty, PETSC_VIEWER_STDOUT_SELF));
34 
35   PetscCall(MatDestroy(&C));
36   PetscCall(MatDestroy(&C_htransposed));
37   PetscCall(MatDestroy(&Cht));
38   PetscCall(MatDestroy(&C_empty));
39   PetscCall(PetscFinalize());
40   return 0;
41 }
42 
43 /*TEST
44 
45    build:
46      requires: complex
47 
48    test:
49      output_file: output/ex175.out
50 
51 TEST*/
52