Actual source code: ex12.c

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

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

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

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

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

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

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

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

 43:   {
 44:     PetscBool flg;

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

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

 57: /*TEST

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

 64: TEST*/