Actual source code: ex1f.F90
1: !
2: !
3: ! Formatted test for IS general routines
4: !
5: program main
6: #include <petsc/finclude/petscis.h>
7: use petscis
8: implicit none
10: PetscErrorCode ierr
11: PetscInt i,n,indices(1004),ii(1)
12: PetscMPIInt size,rank
13: PetscOffset iis
14: IS is,newis
15: PetscBool flag,compute,permanent
17: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
18: if (ierr .ne. 0) then
19: print*,'Unable to initialize PETSc'
20: stop
21: endif
22: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
23: call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr)
25: ! Test IS of size 0
27: n = 0
28: call ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,is,ierr);CHKERRA(ierr)
29: call ISGetLocalSize(is,n,ierr);CHKERRA(ierr)
30: if (n .ne. 0) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error getting size of zero IS'); endif
31: call ISDestroy(is,ierr)
33: ! Create large IS and test ISGetIndices(,ierr)
34: ! fortran indices start from 1 - but IS indices start from 0
35: n = 1000 + rank
36: do 10, i=1,n
37: indices(i) = rank + i-1
38: 10 continue
39: call ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,is,ierr);CHKERRA(ierr)
40: call ISGetIndices(is,ii,iis,ierr);CHKERRA(ierr)
41: do 20, i=1,n
42: if (ii(i+iis) .ne. indices(i)) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error getting indices'); endif
43: 20 continue
44: call ISRestoreIndices(is,ii,iis,ierr);CHKERRA(ierr)
46: ! Check identity and permutation
48: compute = PETSC_TRUE
49: permanent = PETSC_FALSE
50: call ISPermutation(is,flag,ierr);CHKERRA(ierr)
51: if (flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking permutation'); endif
52: call ISGetInfo(is,IS_PERMUTATION,IS_LOCAL,compute,flag,ierr);CHKERRA(ierr)
53: !if ((rank .eq. 0) .and. (.not. flag)) SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,"ISGetInfo(IS_PERMUTATION,IS_LOCAL)")
54: !if (rank .eq. 0 .and. flag) SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,"ISGetInfo(IS_PERMUTATION,IS_LOCAL)")
55: call ISIdentity(is,flag,ierr);CHKERRA(ierr)
56: if ((rank .eq. 0) .and. (.not. flag)) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking identity'); endif
57: if ((rank .ne. 0) .and. flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking identity'); endif
58: call ISSetInfo(is,IS_PERMUTATION,IS_LOCAL,permanent,PETSC_TRUE,ierr);CHKERRA(ierr)
59: call ISSetInfo(is,IS_IDENTITY,IS_LOCAL,permanent,PETSC_TRUE,ierr);CHKERRA(ierr)
60: call ISGetInfo(is,IS_PERMUTATION,IS_LOCAL,compute,flag,ierr);CHKERRA(ierr)
61: if (.not. flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking permutation second time'); endif
62: call ISGetInfo(is,IS_IDENTITY,IS_LOCAL,compute,flag,ierr);CHKERRA(ierr)
63: if (.not. flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking identity second time'); endif
64: call ISClearInfoCache(is,PETSC_TRUE,ierr);CHKERRA(ierr)
66: ! Check equality of index sets
68: call ISEqual(is,is,flag,ierr);CHKERRA(ierr)
69: if (.not. flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking equal'); endif
71: ! Sorting
73: call ISSort(is,ierr);CHKERRA(ierr)
74: call ISSorted(is,flag,ierr);CHKERRA(ierr)
75: if (.not. flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking sorted'); endif
77: ! Thinks it is a different type?
79: call PetscObjectTypeCompare(is,ISSTRIDE,flag,ierr);CHKERRA(ierr)
80: if (flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking stride'); endif
81: call PetscObjectTypeCompare(is,ISBLOCK,flag,ierr);CHKERRA(ierr)
82: if (flag) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error checking block'); endif
84: call ISDestroy(is,ierr);CHKERRA(ierr)
86: ! Inverting permutation
88: do 30, i=1,n
89: indices(i) = n - i
90: 30 continue
92: call ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,is,ierr);CHKERRA(ierr)
93: call ISSetPermutation(is,ierr);CHKERRA(ierr)
94: call ISInvertPermutation(is,PETSC_DECIDE,newis,ierr);CHKERRA(ierr)
95: call ISGetIndices(newis,ii,iis,ierr);CHKERRA(ierr)
96: do 40, i=1,n
97: if (ii(iis+i) .ne. n - i) then; SETERRA(PETSC_COMM_SELF,PETSC_ERR_PLIB,'Error getting permutation indices'); endif
98: 40 continue
99: call ISRestoreIndices(newis,ii,iis,ierr);CHKERRA(ierr)
100: call ISDestroy(newis,ierr);CHKERRA(ierr)
101: call ISDestroy(is,ierr);CHKERRA(ierr)
102: call PetscFinalize(ierr)
103: end
105: !/*TEST
106: !
107: ! test:
108: ! nsize: {{1 2 3 4 5}}
109: ! output_file: output/ex1_1.out
110: !
111: !TEST*/