Actual source code: ex1f.F

petsc-3.5.2 2014-09-08
Report Typos and Errors
  1: !
  2: !  Description: Creates an index set based on a set of integers. Views that index set
  3: !  and then destroys it.
  4: !
  5: !/*T
  6: !    Concepts: index sets^manipulating a general index set;
  7: !T*/
  8: !
  9: !
 10: !  The following include statements are required for Fortran programs
 11: !  that use PETSc index sets:
 12: !     petscsys.h  - base PETSc routines
 13: !     petscis.h     - index sets (IS objects)
 14: !
 15:       program main
 16:       implicit none

 18: #include <finclude/petscsys.h>
 19: #include <finclude/petscis.h>

 21:       PetscErrorCode ierr
 22:       PetscInt indices(5),n,index1,index5
 23:       PetscMPIInt rank
 24:       PetscOffset ix
 25:       IS          is

 27:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 28:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

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

 33:       indices(1) = rank + 1
 34:       indices(2) = rank + 2
 35:       indices(3) = rank + 3
 36:       indices(4) = rank + 4
 37:       indices(5) = rank + 5

 39: !     if using 64bit integers cannot pass 5 into routine expecting an integer*8
 40:       n = 5
 41:       call ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,       &
 42:      &                     is,ierr)

 44: !  Print the index set to stdout

 46:       call ISView(is,PETSC_VIEWER_STDOUT_SELF,ierr)

 48: !  Get the number of indices in the set

 50:       call ISGetLocalSize(is,n,ierr)

 52: !   Get the indices in the index set

 54:       call ISGetIndices(is,indices,ix,ierr)

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

 59: !
 60: !      Bug in IRIX64-F90 libraries - write/format cannot handle integer(integer*8 + integer)
 61: !

 63:       index1 = indices(ix+1)
 64:       index5 = indices(ix+5)
 65:       write(6,100) rank,index1,index5
 66:  100  format('[',i5,'] First index = ',i5,' fifth index = ',i5)

 68: !   Once we no longer need access to the indices they should
 69: !   returned to the system

 71:       call ISRestoreIndices(is,indices,ix,ierr)

 73: !   All PETSc objects should be destroyed once they are
 74: !   no longer needed

 76:       call ISDestroy(is,ierr)
 77:       call PetscFinalize(ierr)
 78:       end