Actual source code: ex12.c


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

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

  7: int main(int argc, char **argv)
  8: {
  9:   const char  filename[] = "ex12.h5";
 10:   const char  objname[]  = "is0";
 11:   IS          is0, is1;
 12:   PetscLayout map;
 13:   PetscViewer viewer;
 14:   PetscMPIInt size, rank;
 15:   MPI_Comm    comm;

 17:   PetscFunctionBeginUser;
 18:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
 19:   comm = PETSC_COMM_WORLD;
 20:   PetscCallMPI(MPI_Comm_size(comm, &size));
 21:   PetscCallMPI(MPI_Comm_rank(comm, &rank));

 23:   {
 24:     PetscInt *idx, i, n, start, end;

 26:     n = rank + 2;
 27:     PetscCall(PetscCalloc1(n, &idx));
 28:     PetscCall(ISCreateGeneral(comm, n, idx, PETSC_OWN_POINTER, &is0));
 29:     PetscCall(PetscObjectSetName((PetscObject)is0, objname));
 30:     PetscCall(ISGetLayout(is0, &map));
 31:     PetscCall(PetscLayoutGetRange(map, &start, &end));
 32:     PetscCheck(end - start == n, PETSC_COMM_SELF, PETSC_ERR_PLIB, "end - start == n");
 33:     for (i = 0; i < n; i++) idx[i] = i + start;
 34:   }

 36:   PetscCall(PetscViewerHDF5Open(comm, filename, FILE_MODE_WRITE, &viewer));
 37:   PetscCall(ISView(is0, viewer));

 39:   PetscCall(ISCreate(comm, &is1));
 40:   PetscCall(PetscObjectSetName((PetscObject)is1, objname));
 41:   PetscCall(ISSetLayout(is1, map));
 42:   PetscCall(ISLoad(is1, viewer));

 44:   {
 45:     PetscBool flg;

 47:     PetscCall(ISEqual(is0, is1, &flg));
 48:     PetscCheck(flg, comm, PETSC_ERR_PLIB, "is0 and is1 differ");
 49:   }

 51:   PetscCall(ISDestroy(&is0));
 52:   PetscCall(ISDestroy(&is1));
 53:   PetscCall(PetscViewerDestroy(&viewer));
 54:   PetscCall(PetscFinalize());
 55:   return 0;
 56: }

 58: /*TEST

 60:    build:
 61:       requires: hdf5
 62:    test:
 63:       nsize: {{1 3}}

 65: TEST*/