Actual source code: matio.c
1: #include <petscviewer.h>
2: #include <petsc/private/matimpl.h>
4: PetscErrorCode MatView_Binary_BlockSizes(Mat mat, PetscViewer viewer)
5: {
6: FILE *info;
7: PetscMPIInt rank;
8: PetscInt rbs, cbs;
9: PetscBool skip;
11: PetscFunctionBegin;
12: PetscCall(PetscViewerBinaryGetSkipInfo(viewer, &skip));
13: if (skip) PetscFunctionReturn(PETSC_SUCCESS);
14: PetscCall(MatGetBlockSizes(mat, &rbs, &cbs));
15: PetscCall(PetscViewerBinaryGetInfoPointer(viewer, &info));
16: PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank));
17: if (rank == 0 && info) {
18: if (rbs != cbs) PetscCall(PetscFPrintf(PETSC_COMM_SELF, info, "-matload_block_size %" PetscInt_FMT ",%" PetscInt_FMT "\n", rbs, cbs));
19: else PetscCall(PetscFPrintf(PETSC_COMM_SELF, info, "-matload_block_size %" PetscInt_FMT "\n", rbs));
20: }
21: PetscFunctionReturn(PETSC_SUCCESS);
22: }
24: PetscErrorCode MatLoad_Binary_BlockSizes(Mat mat, PetscViewer viewer)
25: {
26: PetscInt rbs, cbs, bs[2], n = 2;
27: PetscBool set;
29: PetscFunctionBegin;
30: /* get current block sizes */
31: PetscCall(MatGetBlockSizes(mat, &rbs, &cbs));
32: bs[0] = rbs;
33: bs[1] = cbs;
34: /* get block sizes from the options database */
35: PetscOptionsBegin(PetscObjectComm((PetscObject)viewer), NULL, "Options for loading matrix block size", "Mat");
36: PetscCall(PetscOptionsIntArray("-matload_block_size", "Set the block size used to store the matrix", "MatLoad", bs, &n, &set));
37: PetscOptionsEnd();
38: if (!set) PetscFunctionReturn(PETSC_SUCCESS);
39: if (n == 1) bs[1] = bs[0]; /* to support -matload_block_size <bs> */
40: /* set matrix block sizes */
41: if (bs[0] > 0) rbs = bs[0];
42: if (bs[1] > 0) cbs = bs[1];
43: PetscCall(MatSetBlockSizes(mat, rbs, cbs));
44: PetscFunctionReturn(PETSC_SUCCESS);
45: }