Actual source code: ex2.c

petsc-3.8.3 2017-12-09
Report Typos and Errors

  2: static char help[]= "Tests ISView() and ISLoad() \n\n";

  4:  #include <petscis.h>
  5:  #include <petscviewer.h>

  7: int main(int argc,char **argv)
  8: {
  9:   PetscErrorCode         ierr;
 10:   PetscInt               n = 3,ix[2][3] = {{3,5,4},{1,7,9}};
 11:   IS                     isx,il;
 12:   PetscMPIInt            size,rank;
 13:   PetscViewer            vx,vl;
 14:   PetscBool              equal;

 16:   PetscInitialize(&argc,&argv,(char*)0,help);
 17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 18:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 19:   if (size > 2) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_SIZ,"Example only works with one or two processes");
 20:   ISCreateGeneral(PETSC_COMM_WORLD,n,ix[rank],PETSC_COPY_VALUES,&isx);
 21:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"testfile",FILE_MODE_WRITE,&vx);
 22:   ISView(isx,vx);
 23:   PetscViewerDestroy(&vx);

 25:   ISCreate(PETSC_COMM_WORLD,&il);
 26:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,"testfile",FILE_MODE_READ,&vl);
 27:   ISLoad(il,vl);
 28:   PetscViewerDestroy(&vl);

 30:   ISEqual(il,isx,&equal);
 31:   if (!equal) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"Index set loaded from file does not match index set to file");
 32:   ISDestroy(&il);
 33:   ISDestroy(&isx);
 34:   PetscFinalize();
 35:   return ierr;
 36: }