Date: 2022-03-31T04:46:33+00:00

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:       program main
     11: #include <petsc/finclude/petscis.h>
     12:       use petscis
     13:       implicit none

     15:       PetscErrorCode ierr
     16:       PetscInt indices(5),n,index1,index5
     17:       PetscMPIInt rank
     18:       PetscOffset ix
     19:       IS          is

     21:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
     22:       if (ierr .ne. 0) then
     23:         print*,'Unable to initialize PETSc'
     24:         stop
     25:       endif
     26:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

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

     31:       indices(1) = rank + 1
     32:       indices(2) = rank + 2
     33:       indices(3) = rank + 3
     34:       indices(4) = rank + 4
     35:       indices(5) = rank + 5

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

     42: !  Print the index set to stdout

     44:       call ISView(is,PETSC_VIEWER_STDOUT_SELF,ierr)

     46: !  Get the number of indices in the set

     48:       call ISGetLocalSize(is,n,ierr)

     50: !   Get the indices in the index set

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

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

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

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

     66: !   Once we no longer need access to the indices they should
     67: !   returned to the system

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

     71: !   All PETSc objects should be destroyed once they are
     72: !   no longer needed

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

     78: !/*TEST
     79: !
     80: !   test:
     81: !      filter: sort -b
     82: !      filter_output: sort -b
     83: !
     84: !TEST*/