Actual source code: ex175.c
1: static char help[] = "Tests MatCreateHermitianTranspose().\n\n";
3: #include <petscmat.h>
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;
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));
27: PetscCall(MatCreateHermitianTranspose(C, &C_htransposed));
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));
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: }
43: /*TEST
45: build:
46: requires: complex
48: test:
49: output_file: output/ex175.out
51: TEST*/