Actual source code: ex2.c
petsc-3.7.3 2016-08-01
2: static char help[]= "Tests ISView() and ISLoad() \n\n";
4: #include <petscis.h>
5: #include <petscviewer.h>
9: int main(int argc,char **argv)
10: {
11: PetscErrorCode ierr;
12: PetscInt n = 3,ix[2][3] = {{3,5,4},{1,7,9}};
13: IS isx,il;
14: PetscMPIInt size,rank;
15: PetscViewer vx,vl;
16: PetscBool equal;
18: PetscInitialize(&argc,&argv,(char*)0,help);
19: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
20: MPI_Comm_size(PETSC_COMM_WORLD,&size);
21: if (size > 2) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_SIZ,"Example only works with one or two processes");
22: ISCreateGeneral(PETSC_COMM_WORLD,n,ix[rank],PETSC_COPY_VALUES,&isx);
23: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"testfile",FILE_MODE_WRITE,&vx);
24: ISView(isx,vx);
25: PetscViewerDestroy(&vx);
27: ISCreate(PETSC_COMM_WORLD,&il);
28: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"testfile",FILE_MODE_READ,&vl);
29: ISLoad(il,vl);
30: PetscViewerDestroy(&vl);
32: ISEqual(il,isx,&equal);
33: if (!equal) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"Index set loaded from file does not match index set to file");
34: ISDestroy(&il);
35: ISDestroy(&isx);
36: PetscFinalize();
37: return ierr;
38: }