Actual source code: ex2.c

petsc-3.10.5 2019-03-28
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[3][3] = {{3,5,4},{1,7,9},{0,2,8}};
 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 > 3) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_SIZ,"Example only works with up to three 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: }

 38: /*TEST

 40:    test:

 42:    test:
 43:       suffix: 2
 44:       nsize: 2
 45:       output_file: output/ex2_1.out

 47:    test:
 48:       suffix: 3
 49:       nsize: 3
 50:       output_file: output/ex2_1.out

 52:    testset:
 53:       requires: mpiio
 54:       args: -viewer_binary_mpiio
 55:       output_file: output/ex2_1.out
 56:       test:
 57:         suffix: mpiio_1
 58:         nsize: 1
 59:       test:
 60:         suffix: mpiio_2
 61:         nsize: 2
 62:       test:
 63:         suffix: mpiio_3
 64:         nsize: 3

 66: TEST*/