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;

     10:   MatGetBlockSizes(mat,&rbs,&cbs);
     11:   PetscViewerBinaryGetInfoPointer(viewer,&info);
     12:   MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);
     13:   if (rank == 0 && info) {
     14:     if (rbs != cbs) PetscFPrintf(PETSC_COMM_SELF,info,"-matload_block_size %" PetscInt_FMT ",%" PetscInt_FMT "\n",rbs,cbs);
     15:     else            PetscFPrintf(PETSC_COMM_SELF,info,"-matload_block_size %" PetscInt_FMT "\n",rbs);
     16:   }
     17:   return 0;
     18: }

     20: PetscErrorCode MatLoad_Binary_BlockSizes(Mat mat,PetscViewer viewer)
     21: {
     22:   PetscInt       rbs,cbs,bs[2],n = 2;
     23:   PetscBool      set;

     26:   /* get current block sizes */
     27:   MatGetBlockSizes(mat,&rbs,&cbs);
     28:   bs[0] = rbs; 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:   PetscOptionsIntArray("-matload_block_size","Set the block size used to store the matrix","MatLoad",bs,&n,&set);
     32:   PetscOptionsEnd();
     33:   if (!set) return 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:   MatSetBlockSizes(mat,rbs,cbs);
     39:   return 0;
     40: }