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