Actual source code: ex133.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

  2: static char help[] = "Test saving SeqSBAIJ matrix that is missing diagonal entries.";

  4:  #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            A;
  9:   PetscInt       bs=3,m=4,i,j,val = 10,row[2],col[3],rstart;
 11:   PetscMPIInt    size;
 12:   PetscScalar    x[6][9];

 14:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 15:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 16:   if (size > 1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Test is only for seqeuntial");
 17:   MatCreateSeqSBAIJ(PETSC_COMM_SELF,bs,m*bs,m*bs,1,NULL,&A);
 18:   MatSetOption(A,MAT_IGNORE_LOWER_TRIANGULAR,PETSC_TRUE);
 19:   rstart = 0;

 21:   row[0] =rstart+0;  row[1] =rstart+2;
 22:   col[0] =rstart+0;  col[1] =rstart+1;  col[2] =rstart+3;
 23:   for (i=0; i<6; i++) {
 24:     for (j =0; j< 9; j++) x[i][j] = (PetscScalar)val++;
 25:   }
 26:   MatSetValuesBlocked(A,2,row,3,col,&x[0][0],INSERT_VALUES);
 27:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 28:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 29:   MatView(A,PETSC_VIEWER_BINARY_WORLD);

 31:   MatDestroy(&A);
 32:   PetscFinalize();
 33:   return ierr;
 34: }