Actual source code: ex1f.F

      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: !     petsc.h  - base PETSc routines
     13: !     petscis.h     - index sets (IS objects)
     14: !
     15:       program main
     16:       implicit none

     18:  #include include/finclude/petsc.h
     19:  #include 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.
     32:
     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,is,ierr)

     43: !  Print the index set to stdout

     45:       call ISView(is,PETSC_VIEWER_STDOUT_SELF,ierr)

     47: !  Get the number of indices in the set

     49:       call ISGetLocalSize(is,n,ierr)

     51: !   Get the indices in the index set

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

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

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

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

     70:       call ISRestoreIndices(is,indices,ix,ierr)
     71:
     72: !   All PETSc objects should be destroyed once they are
     73: !   no longer needed

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

     79: