Actual source code: ex138.c
2: static char help[] = "Tests MatGetColumnNorms()/Sums()/Means() for matrix read from file.";
4: #include <petscmat.h>
6: int main(int argc, char **args)
7: {
8: Mat A;
9: PetscReal *reductions_real;
10: PetscScalar *reductions_scalar;
11: char file[PETSC_MAX_PATH_LEN];
12: PetscBool flg;
13: PetscViewer fd;
14: PetscInt n;
15: PetscMPIInt rank;
18: PetscInitialize(&argc, &args, (char *)0, help);
19: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
20: PetscOptionsGetString(NULL, NULL, "-f", file, sizeof(file), &flg);
22: PetscViewerBinaryOpen(PETSC_COMM_WORLD, file, FILE_MODE_READ, &fd);
23: MatCreate(PETSC_COMM_WORLD, &A);
24: MatSetFromOptions(A);
25: MatLoad(A, fd);
26: PetscViewerDestroy(&fd);
28: MatGetSize(A, NULL, &n);
29: PetscMalloc1(n, &reductions_real);
30: PetscMalloc1(n, &reductions_scalar);
32: MatGetColumnNorms(A, NORM_2, reductions_real);
33: if (rank == 0) {
34: PetscPrintf(PETSC_COMM_SELF, "NORM_2:\n");
35: PetscRealView(n, reductions_real, PETSC_VIEWER_STDOUT_SELF);
36: }
38: MatGetColumnNorms(A, NORM_1, reductions_real);
39: if (rank == 0) {
40: PetscPrintf(PETSC_COMM_SELF, "NORM_1:\n");
41: PetscRealView(n, reductions_real, PETSC_VIEWER_STDOUT_SELF);
42: }
44: MatGetColumnNorms(A, NORM_INFINITY, reductions_real);
45: if (rank == 0) {
46: PetscPrintf(PETSC_COMM_SELF, "NORM_INFINITY:\n");
47: PetscRealView(n, reductions_real, PETSC_VIEWER_STDOUT_SELF);
48: }
50: MatGetColumnSums(A, reductions_scalar);
51: if (rank == 0) {
52: PetscPrintf(PETSC_COMM_SELF, "REDUCTION_SUM:\n");
53: PetscScalarView(n, reductions_scalar, PETSC_VIEWER_STDOUT_SELF);
54: }
56: MatGetColumnMeans(A, reductions_scalar);
57: if (rank == 0) {
58: PetscPrintf(PETSC_COMM_SELF, "REDUCTION_MEAN:\n");
59: PetscScalarView(n, reductions_scalar, PETSC_VIEWER_STDOUT_SELF);
60: }
62: PetscFree(reductions_real);
63: PetscFree(reductions_scalar);
64: MatDestroy(&A);
65: PetscFinalize();
66: return 0;
67: }
69: /*TEST
71: test:
72: suffix: 1
73: nsize: 2
74: requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
75: args: -f ${DATAFILESPATH}/matrices/small -mat_type aij
76: output_file: output/ex138.out
78: test:
79: suffix: 2
80: nsize: {{1 2}}
81: requires: datafilespath !complex double !defined(PETSC_USE_64BIT_INDICES)
82: args: -f ${DATAFILESPATH}/matrices/small -mat_type baij -matload_block_size {{2 3}}
83: output_file: output/ex138.out
85: test:
86: suffix: complex
87: nsize: 2
88: requires: datafilespath complex double !defined(PETSC_USE_64BIT_INDICES)
89: args: -f ${DATAFILESPATH}/matrices/nimrod/small_112905 -mat_type aij
90: output_file: output/ex138_complex.out
91: filter: grep -E "\ 0:|1340:|1344:"
93: TEST*/