Actual source code: ex1f.F90

  1: !
  2: !  Description: Creates an index set based on a set of integers. Views that index set
  3: !  and then destroys it.
  4: !
  5: #include <petsc/finclude/petscis.h>
  6: program main
  7:   use petscis
  8:   implicit none

 10:   PetscErrorCode ierr
 11:   PetscInt, parameter :: n = 5
 12:   PetscInt indices(n), i, n_out
 13:   PetscMPIInt rank
 14:   IS is
 15:   PetscInt, pointer :: indices2(:)

 17:   PetscCallA(PetscInitialize(ierr))
 18:   PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr))

 20: ! Create an index set with 5 entries. Each processor creates
 21: ! its own index set with its own list of integers.
 22:   indices = rank + [(i, i=1, n)]
 23:   PetscCallA(ISCreateGeneral(PETSC_COMM_SELF, n, indices, PETSC_COPY_VALUES, is, ierr))

 25: ! Print the index set to stdout
 26:   PetscCallA(ISView(is, PETSC_VIEWER_STDOUT_SELF, ierr))

 28: ! Get the number of indices in the set
 29:   PetscCallA(ISGetLocalSize(is, n_out, ierr))

 31: !  Get the indices in the index set
 32:   PetscCallA(ISGetIndices(is, indices2, ierr))

 34: ! Now any code that needs access to the list of integers
 35: ! has access to it here
 36:   write (6, 100) rank, indices(1), indices(n_out)
 37: 100 format('[', i5, '] First index = ', i5, ' fifth index = ', i5)

 39: ! Once we no longer need access to the indices they should
 40: ! returned to the system
 41:   PetscCallA(ISRestoreIndices(is, indices2, ierr))

 43: ! All PETSc objects should be destroyed once they are
 44: ! no longer needed
 45:   PetscCallA(ISDestroy(is, ierr))
 46:   PetscCallA(PetscFinalize(ierr))
 47: end

 49: !/*TEST
 50: !
 51: !   test:
 52: !      filter: sort -b
 53: !      filter_output: sort -b
 54: !
 55: !TEST*/