Actual source code: ex1f90.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: !
  6: #include <petsc/finclude/petscis.h>
  7: program main
  8:   use petscis
  9:   implicit none

 11:   PetscErrorCode ierr
 12:   PetscInt indices(5), n
 13:   PetscInt five
 14:   PetscMPIInt rank
 15:   PetscInt, pointer :: idx(:)
 16:   IS is

 18:   five = 5
 19:   PetscCallA(PetscInitialize(ierr))
 20:   PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr))

 22: !  Create an index set with 5 entries. Each processor creates
 23: !  its own index set with its own list of integers.

 25:   indices(1) = rank + 1
 26:   indices(2) = rank + 2
 27:   indices(3) = rank + 3
 28:   indices(4) = rank + 4
 29:   indices(5) = rank + 5
 30:   PetscCallA(ISCreateGeneral(PETSC_COMM_SELF, five, indices, PETSC_COPY_VALUES, is, ierr))

 32: !  Print the index set to stdout

 34:   PetscCallA(ISView(is, PETSC_VIEWER_STDOUT_SELF, ierr))

 36: !  Get the number of indices in the set

 38:   PetscCallA(ISGetLocalSize(is, n, ierr))

 40: !   Get the indices in the index set

 42:   PetscCallA(ISGetIndices(is, idx, ierr))

 44:   if (associated(idx)) then
 45:     write (*, *) 'Association check passed'
 46:   else
 47:     write (*, *) 'Association check failed'
 48:   end if

 50: !   Now any code that needs access to the list of integers
 51: !   has access to it here

 53:   write (6, 50) idx
 54: 50 format(5I3)

 56:   write (6, 100) rank, idx(1), idx(5)
 57: 100 format('[', i5, '] First index = ', i5, ' fifth index = ', i5)

 59: !   Once we no longer need access to the indices they should
 60: !   returned to the system

 62:   PetscCallA(ISRestoreIndices(is, idx, ierr))

 64: !   All PETSc objects should be destroyed once they are
 65: !   no longer needed

 67:   PetscCallA(ISDestroy(is, ierr))
 68:   PetscCallA(PetscFinalize(ierr))
 69: end

 71: !/*TEST
 72: !
 73: !   test:
 74: !      filter: sort -b
 75: !      filter_output: sort -b
 76: !
 77: !TEST*/