Actual source code: ex1f.F

  1: !
  2: !  "$Id: ex1f.F,v 1.24 2001/01/15 21:44:33 bsmith Exp $";
  3: !
  4: !/*T
  5: !    Concepts: index sets^manipulating a general index set;
  6: !T*/
  7: !
  8: !  Comment: Creates an index set based on a set of integers. Views that index set
  9: !  and then destroys it.
 10: !
 11: !  The following include statements are required for Fortran programs
 12: !  that use PETSc index sets:
 13: !     petsc.h  - base PETSc routines
 14: !     petscis.h     - index sets (IS objects)
 15: !
 16:       program main
 17:       implicit none

 19:  #include include/finclude/petsc.h
 20:  #include include/finclude/petscis.h

 22:       integer     ierr,indices(5),rank,n,index1,index5
 23:       PetscOffset ix
 24:       IS          is

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

 29: !  Create an index set with 5 entries. Each processor creates
 30: !  its own index set with its own list of integers.
 31: 
 32:       indices(1) = rank + 1
 33:       indices(2) = rank + 2
 34:       indices(3) = rank + 3
 35:       indices(4) = rank + 4
 36:       indices(5) = rank + 5
 37:       call ISCreateGeneral(PETSC_COMM_SELF,5,indices,is,ierr)

 39: !  Print the index set to stdout

 41:       call ISView(is,PETSC_VIEWER_STDOUT_SELF,ierr)

 43: !  Get the number of indices in the set

 45:       call ISGetLocalSize(is,n,ierr)

 47: !   Get the indices in the index set

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

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

 54: !
 55: !      Bug in IRIX64-F90 libraries - write/format cannot handle integer(integer*8 + integer)
 56: !

 58:       index1 = indices(ix+1)
 59:       index5 = indices(ix+5)
 60:       write(6,100) rank,index1,index5
 61:  100  format('[',i5,'] First index = ',i5,' fifth index = ',i5)
 62: 
 63: !   Once we no longer need access to the indices they should
 64: !   returned to the system

 66:       call ISRestoreIndices(is,indices,ix,ierr)
 67: 
 68: !   All PETSc objects should be destroyed once they are
 69: !   no longer needed

 71:       call ISDestroy(is,ierr)
 72:       call PetscFinalize(ierr)
 73:       end

 75: