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