Bug Summary

File:vec/is/is/utils/isblock.c
Warning:line 24, column 14
Division by zero

Annotated Source Code

[?] Use j/k keys for keyboard navigation

/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c

1/* Routines to be used by MatIncreaseOverlap() for BAIJ and SBAIJ matrices */
2#include <petscis.h> /*I "petscis.h" I*/
3#include <petscbt.h>
4#include <petscctable.h>
5
6/*@
7 ISCompressIndicesGeneral - convert the indices into block indices
8 Input Parameters:
9+ n - maximum possible length of the index set
10. nkeys - expected number of keys when PETSC_USE_CTABLE
11. bs - the size of block
12. imax - the number of index sets
13- is_in - the non-blocked array of index sets
14
15 Output Parameter:
16. is_out - the blocked new index set
17
18 Level: intermediate
19
20.seealso: ISExpandIndicesGeneral()
21@*/
22PetscErrorCode ISCompressIndicesGeneral(PetscInt n,PetscInt nkeys,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[])
23{
24 PetscErrorCode ierr;
25 PetscInt isz,len,i,j,ival,Nbs;
26 const PetscInt *idx;
27#if defined(PETSC_USE_CTABLE1)
28 PetscTable gid1_lid1;
29 PetscInt tt, gid1, *nidx,Nkbs;
30 PetscTablePosition tpos;
31#else
32 PetscInt *nidx;
33 PetscBT table;
34#endif
35
36 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
; petscstack->line[petscstack->currentsize] = 36; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
37 Nbs = n/bs;
38#if defined(PETSC_USE_CTABLE1)
39 Nkbs = nkeys/bs;
40 ierr = PetscTableCreate(Nkbs,Nbs,&gid1_lid1);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),40,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
41#else
42 ierr = PetscMalloc1(Nbs,&nidx)PetscMallocA(1,PETSC_FALSE,42,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,(size_t)(Nbs)*sizeof(**(&nidx)),(&nidx))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),42,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
43 ierr = PetscBTCreate(Nbs,&table);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),43,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
44#endif
45 for (i=0; i<imax; i++) {
1
Assuming 'i' is < 'imax'
2
Loop condition is true. Entering loop body
7
Assuming 'i' is < 'imax'
8
Loop condition is true. Entering loop body
13
Assuming 'i' is < 'imax'
14
Loop condition is true. Entering loop body
19
Assuming 'i' is < 'imax'
20
Loop condition is true. Entering loop body
46 isz = 0;
47#if defined(PETSC_USE_CTABLE1)
48 ierr = PetscTableRemoveAll(gid1_lid1);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),48,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
49#else
50 ierr = PetscBTMemzero(Nbs,table);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),50,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
51#endif
52 ierr = ISGetIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),52,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
53 ierr = ISGetLocalSize(is_in[i],&len);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),53,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
54 for (j=0; j<len; j++) {
3
Assuming 'j' is >= 'len'
4
Loop condition is false. Execution continues on line 67
9
Assuming 'j' is >= 'len'
10
Loop condition is false. Execution continues on line 67
15
Assuming 'j' is >= 'len'
16
Loop condition is false. Execution continues on line 67
21
Assuming 'j' is < 'len'
22
Loop condition is true. Entering loop body
55 ival = idx[j]/bs; /* convert the indices into block indices */
56#if defined(PETSC_USE_CTABLE1)
57 ierr = PetscTableFind(gid1_lid1,ival+1,&tt);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),57,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
58 if (!tt) {
23
Taking true branch
59 ierr = PetscTableAdd(gid1_lid1,ival+1,isz+1,INSERT_VALUES);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),59,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
24
Calling 'PetscTableAdd'
60 isz++;
61 }
62#else
63 if (ival>Nbs) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"index greater than mat-dim")return PetscError(((MPI_Comm)0x44000001),63,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,63,PETSC_ERROR_INITIAL,"index greater than mat-dim")
;
64 if (!PetscBTLookupSet(table,ival)) nidx[isz++] = ival;
65#endif
66 }
67 ierr = ISRestoreIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),67,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
68
69#if defined(PETSC_USE_CTABLE1)
70 ierr = PetscMalloc1(isz,&nidx)PetscMallocA(1,PETSC_FALSE,70,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,(size_t)(isz)*sizeof(**(&nidx)),(&nidx))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),70,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
71 ierr = PetscTableGetHeadPosition(gid1_lid1,&tpos);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),71,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
72 j = 0;
73 while (tpos) {
5
Loop condition is false. Execution continues on line 79
11
Loop condition is false. Execution continues on line 79
17
Loop condition is false. Execution continues on line 79
74 ierr = PetscTableGetNext(gid1_lid1,&tpos,&gid1,&tt);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),74,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
75 if (tt-- > isz) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"index greater than array-dim")return PetscError(((MPI_Comm)0x44000001),75,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,63,PETSC_ERROR_INITIAL,"index greater than array-dim")
;
76 nidx[tt] = gid1 - 1;
77 j++;
78 }
79 if (j != isz) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"table error: jj != isz")return PetscError(((MPI_Comm)0x44000001),79,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,63,PETSC_ERROR_INITIAL,"table error: jj != isz")
;
6
Taking false branch
12
Taking false branch
18
Taking false branch
80 ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is_in[i]),isz,nidx,PETSC_OWN_POINTER,(is_out+i));CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),80,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
81#else
82 ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is_in[i]),isz,nidx,PETSC_COPY_VALUES,(is_out+i));CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),82,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
83#endif
84 }
85#if defined(PETSC_USE_CTABLE1)
86 ierr = PetscTableDestroy(&gid1_lid1);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),86,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
87#else
88 ierr = PetscBTDestroy(&table);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),88,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
89 ierr = PetscFree(nidx)((*PetscTrFree)((void*)(nidx),89,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
) || ((nidx) = 0,0))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),89,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
90#endif
91 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
92}
93
94PetscErrorCode ISCompressIndicesSorted(PetscInt n,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[])
95{
96 PetscErrorCode ierr;
97 PetscInt i,j,k,val,len,*nidx,bbs;
98 const PetscInt *idx,*idx_local;
99 PetscBool flg,isblock;
100#if defined(PETSC_USE_CTABLE1)
101 PetscInt maxsz;
102#else
103 PetscInt Nbs=n/bs;
104#endif
105
106 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
; petscstack->line[petscstack->currentsize] = 106; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
107 for (i=0; i<imax; i++) {
108 ierr = ISSorted(is_in[i],&flg);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),108,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
109 if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Indices are not sorted")return PetscError(((MPI_Comm)0x44000001),109,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,73,PETSC_ERROR_INITIAL,"Indices are not sorted")
;
110 }
111
112#if defined(PETSC_USE_CTABLE1)
113 /* Now check max size */
114 for (i=0,maxsz=0; i<imax; i++) {
115 ierr = ISGetLocalSize(is_in[i],&len);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),115,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
116 if (len%bs !=0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Indices are not block ordered")return PetscError(((MPI_Comm)0x44000001),116,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,75,PETSC_ERROR_INITIAL,"Indices are not block ordered")
;
117 len = len/bs; /* The reduced index size */
118 if (len > maxsz) maxsz = len;
119 }
120 ierr = PetscMalloc1(maxsz,&nidx)PetscMallocA(1,PETSC_FALSE,120,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,(size_t)(maxsz)*sizeof(**(&nidx)),(&nidx))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),120,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
121#else
122 ierr = PetscMalloc1(Nbs,&nidx)PetscMallocA(1,PETSC_FALSE,122,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,(size_t)(Nbs)*sizeof(**(&nidx)),(&nidx))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),122,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
123#endif
124 /* Now check if the indices are in block order */
125 for (i=0; i<imax; i++) {
126 ierr = ISGetLocalSize(is_in[i],&len);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),126,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
127
128 /* special case where IS is already block IS of the correct size */
129 ierr = PetscObjectTypeCompare((PetscObject)is_in[i],ISBLOCK"block",&isblock);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),129,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
130 if (isblock) {
131 ierr = ISBlockGetLocalSize(is_in[i],&bbs);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),131,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
132 if (bs == bbs) {
133 len = len/bs;
134 ierr = ISBlockGetIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),134,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
135 ierr = ISCreateGeneral(PETSC_COMM_SELF((MPI_Comm)0x44000001),len,idx,PETSC_COPY_VALUES,(is_out+i));CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),135,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
136 ierr = ISBlockRestoreIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),136,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
137 continue;
138 }
139 }
140 ierr = ISGetIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),140,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
141 if (len%bs !=0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Indices are not block ordered")return PetscError(((MPI_Comm)0x44000001),141,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,75,PETSC_ERROR_INITIAL,"Indices are not block ordered")
;
142
143 len = len/bs; /* The reduced index size */
144 idx_local = idx;
145 for (j=0; j<len; j++) {
146 val = idx_local[0];
147 if (val%bs != 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Indices are not block ordered")return PetscError(((MPI_Comm)0x44000001),147,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,75,PETSC_ERROR_INITIAL,"Indices are not block ordered")
;
148 for (k=0; k<bs; k++) {
149 if (val+k != idx_local[k]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Indices are not block ordered")return PetscError(((MPI_Comm)0x44000001),149,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,75,PETSC_ERROR_INITIAL,"Indices are not block ordered")
;
150 }
151 nidx[j] = val/bs;
152 idx_local += bs;
153 }
154 ierr = ISRestoreIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),154,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
155 ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is_in[i]),len,nidx,PETSC_COPY_VALUES,(is_out+i));CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),155,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
156 }
157 ierr = PetscFree(nidx)((*PetscTrFree)((void*)(nidx),157,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
) || ((nidx) = 0,0))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),157,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
158 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
159}
160
161/*@C
162 ISExpandIndicesGeneral - convert the indices into non-block indices
163 Input Parameters:
164+ n - the length of the index set (not being used)
165. nkeys - expected number of keys when PETSC_USE_CTABLE (not being used)
166. bs - the size of block
167. imax - the number of index sets
168- is_in - the blocked array of index sets
169
170 Output Parameter:
171. is_out - the non-blocked new index set
172
173 Level: intermediate
174
175.seealso: ISCompressIndicesGeneral()
176@*/
177PetscErrorCode ISExpandIndicesGeneral(PetscInt n,PetscInt nkeys,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[])
178{
179 PetscErrorCode ierr;
180 PetscInt len,i,j,k,*nidx;
181 const PetscInt *idx;
182 PetscInt maxsz;
183
184 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
; petscstack->line[petscstack->currentsize] = 184; petscstack
->petscroutine[petscstack->currentsize] = PETSC_TRUE; petscstack
->currentsize++; } if (petscstack) { petscstack->hotdepth
+= (PETSC_FALSE || petscstack->hotdepth); } ; } while (0)
; ; } while (0)
;
185 /* Check max size of is_in[] */
186 maxsz = 0;
187 for (i=0; i<imax; i++) {
188 ierr = ISGetLocalSize(is_in[i],&len);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),188,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
189 if (len > maxsz) maxsz = len;
190 }
191 ierr = PetscMalloc1(maxsz*bs,&nidx)PetscMallocA(1,PETSC_FALSE,191,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,(size_t)(maxsz*bs)*sizeof(**(&nidx)),(&nidx))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),191,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
192
193 for (i=0; i<imax; i++) {
194 ierr = ISGetLocalSize(is_in[i],&len);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),194,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
195 ierr = ISGetIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),195,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
196 for (j=0; j<len ; ++j) {
197 for (k=0; k<bs; k++) nidx[j*bs+k] = idx[j]*bs+k;
198 }
199 ierr = ISRestoreIndices(is_in[i],&idx);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),199,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
200 ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is_in[i]),len*bs,nidx,PETSC_COPY_VALUES,is_out+i);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),200,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
201 }
202 ierr = PetscFree(nidx)((*PetscTrFree)((void*)(nidx),202,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
) || ((nidx) = 0,0))
;CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),202,__func__,"/sandbox/petsc/petsc.next-tmp/src/vec/is/is/utils/isblock.c"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
203 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
204}

/sandbox/petsc/petsc.next-tmp/include/petscctable.h

1#ifndef PETSCCTABLE_H
2#define PETSCCTABLE_H
3#include <petscsys.h>
4
5struct _n_PetscTable {
6 PetscInt *keytable;
7 PetscInt *table;
8 PetscInt count;
9 PetscInt tablesize;
10 PetscInt head;
11 PetscInt maxkey; /* largest key allowed */
12};
13
14typedef struct _n_PetscTable* PetscTable;
15typedef PetscInt* PetscTablePosition;
16
17PETSC_STATIC_INLINEstatic inline unsigned long PetscHash(PetscTable ta,unsigned long x)
18{
19 return(x%(unsigned long)ta->tablesize);
20}
21
22PETSC_STATIC_INLINEstatic inline unsigned long PetscHashStep(PetscTable ta,unsigned long x)
23{
24 return(1+(x%(unsigned long)(ta->tablesize-1)));
26
Division by zero
25}
26
27PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableCreate(const PetscInt,PetscInt,PetscTable*);
28PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableCreateCopy(const PetscTable,PetscTable*);
29PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableDestroy(PetscTable*);
30PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableGetCount(const PetscTable,PetscInt*);
31PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableIsEmpty(const PetscTable,PetscInt*);
32PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableAddExpand(PetscTable,PetscInt,PetscInt,InsertMode);
33PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableAddCountExpand(PetscTable,PetscInt);
34PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableGetHeadPosition(PetscTable,PetscTablePosition*);
35PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableGetNext(PetscTable,PetscTablePosition*,PetscInt*,PetscInt*);
36PETSC_EXTERNextern __attribute__((visibility ("default"))) PetscErrorCode PetscTableRemoveAll(PetscTable);
37
38PETSC_STATIC_INLINEstatic inline PetscErrorCode PetscTableAdd(PetscTable ta,PetscInt key,PetscInt data,InsertMode imode)
39{
40 PetscErrorCode ierr;
41 PetscInt i,hash = (PetscInt)PetscHash(ta,(unsigned long)key);
42 PetscInt hashstep = (PetscInt)PetscHashStep(ta,(unsigned long)key);
25
Calling 'PetscHashStep'
43
44 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/include/petscctable.h"; petscstack
->line[petscstack->currentsize] = 44; petscstack->petscroutine
[petscstack->currentsize] = PETSC_TRUE; petscstack->currentsize
++; } if (petscstack) { petscstack->hotdepth += (PETSC_FALSE
|| petscstack->hotdepth); } ; } while (0); ; } while (0)
;
45 if (key <= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"key <= 0")return PetscError(((MPI_Comm)0x44000001),45,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"key <= 0")
;
46 if (key > ta->maxkey) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"key %D is greater than largest key allowed %D",key,ta->maxkey)return PetscError(((MPI_Comm)0x44000001),46,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"key %D is greater than largest key allowed %D"
,key,ta->maxkey)
;
47 if (!data) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Null data")return PetscError(((MPI_Comm)0x44000001),47,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"Null data")
;
48
49 for (i=0; i<ta->tablesize; i++) {
50 if (ta->keytable[hash] == key) {
51 switch (imode) {
52 case INSERT_VALUES:
53 ta->table[hash] = data; /* over write */
54 break;
55 case ADD_VALUES:
56 ta->table[hash] += data;
57 break;
58 case MAX_VALUES:
59 ta->table[hash] = PetscMax(ta->table[hash],data)(((ta->table[hash])<(data)) ? (data) : (ta->table[hash
]))
;
60 break;
61 case NOT_SET_VALUES:
62 case INSERT_ALL_VALUES:
63 case ADD_ALL_VALUES:
64 case INSERT_BC_VALUES:
65 case ADD_BC_VALUES:
66 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported InsertMode")return PetscError(((MPI_Comm)0x44000001),66,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,56,PETSC_ERROR_INITIAL,"Unsupported InsertMode")
;
67 }
68 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
69 } else if (!ta->keytable[hash]) {
70 if (ta->count < 5*(ta->tablesize/6) - 1) {
71 ta->count++; /* add */
72 ta->keytable[hash] = key;
73 ta->table[hash] = data;
74 } else {
75 ierr = PetscTableAddExpand(ta,key,data,imode);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),75,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
76 }
77 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
78 }
79 hash = (hash + hashstep)%ta->tablesize;
80 }
81 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_COR,"Full table")return PetscError(((MPI_Comm)0x44000001),81,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,74,PETSC_ERROR_INITIAL,"Full table")
;
82 /* PetscFunctionReturn(0); */
83}
84
85PETSC_STATIC_INLINEstatic inline PetscErrorCode PetscTableAddCount(PetscTable ta,PetscInt key)
86{
87 PetscErrorCode ierr;
88 PetscInt i,hash = (PetscInt)PetscHash(ta,(unsigned long)key);
89 PetscInt hashstep = (PetscInt)PetscHashStep(ta,(unsigned long)key);
90
91 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/include/petscctable.h"; petscstack
->line[petscstack->currentsize] = 91; petscstack->petscroutine
[petscstack->currentsize] = PETSC_TRUE; petscstack->currentsize
++; } if (petscstack) { petscstack->hotdepth += (PETSC_FALSE
|| petscstack->hotdepth); } ; } while (0); ; } while (0)
;
92 if (key <= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"key <= 0")return PetscError(((MPI_Comm)0x44000001),92,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"key <= 0")
;
93 if (key > ta->maxkey) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"key %D is greater than largest key allowed %D",key,ta->maxkey)return PetscError(((MPI_Comm)0x44000001),93,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"key %D is greater than largest key allowed %D"
,key,ta->maxkey)
;
94
95 for (i=0; i<ta->tablesize; i++) {
96 if (ta->keytable[hash] == key) {
97 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
98 } else if (!ta->keytable[hash]) {
99 if (ta->count < 5*(ta->tablesize/6) - 1) {
100 ta->count++; /* add */
101 ta->keytable[hash] = key;
102 ta->table[hash] = ta->count;
103 } else {
104 ierr = PetscTableAddCountExpand(ta,key);CHKERRQ(ierr)do {if (__builtin_expect(!!(ierr),0)) return PetscError(((MPI_Comm
)0x44000001),104,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,ierr,PETSC_ERROR_REPEAT," ");} while (0)
;
105 }
106 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
107 }
108 hash = (hash + hashstep)%ta->tablesize;
109 }
110 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_COR,"Full table")return PetscError(((MPI_Comm)0x44000001),110,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,74,PETSC_ERROR_INITIAL,"Full table")
;
111 /* PetscFunctionReturn(0); */
112}
113
114/*
115 PetscTableFind - checks if a key is in the table
116
117 If data==0, then no table entry exists.
118
119*/
120PETSC_STATIC_INLINEstatic inline PetscErrorCode PetscTableFind(PetscTable ta,PetscInt key,PetscInt *data)
121{
122 PetscInt ii = 0;
123 PetscInt hash = (PetscInt)PetscHash(ta,(unsigned long)key);
124 PetscInt hashstep = (PetscInt)PetscHashStep(ta,(unsigned long)key);
125
126 PetscFunctionBegindo { do { ; if (petscstack && (petscstack->currentsize
< 64)) { petscstack->function[petscstack->currentsize
] = __func__; petscstack->file[petscstack->currentsize]
= "/sandbox/petsc/petsc.next-tmp/include/petscctable.h"; petscstack
->line[petscstack->currentsize] = 126; petscstack->petscroutine
[petscstack->currentsize] = PETSC_TRUE; petscstack->currentsize
++; } if (petscstack) { petscstack->hotdepth += (PETSC_FALSE
|| petscstack->hotdepth); } ; } while (0); ; } while (0)
;
127 *data = 0;
128 if (key <= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Key <= 0")return PetscError(((MPI_Comm)0x44000001),128,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"Key <= 0")
;
129 if (key > ta->maxkey) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"key %D is greater than largest key allowed %D",key,ta->maxkey)return PetscError(((MPI_Comm)0x44000001),129,__func__,"/sandbox/petsc/petsc.next-tmp/include/petscctable.h"
,63,PETSC_ERROR_INITIAL,"key %D is greater than largest key allowed %D"
,key,ta->maxkey)
;
130
131 while (ii++ < ta->tablesize) {
132 if (!ta->keytable[hash]) break;
133 else if (ta->keytable[hash] == key) {
134 *data = ta->table[hash];
135 break;
136 }
137 hash = (hash + hashstep)%ta->tablesize;
138 }
139 PetscFunctionReturn(0)do { do { ; if (petscstack && petscstack->currentsize
> 0) { petscstack->currentsize--; petscstack->function
[petscstack->currentsize] = 0; petscstack->file[petscstack
->currentsize] = 0; petscstack->line[petscstack->currentsize
] = 0; petscstack->petscroutine[petscstack->currentsize
] = PETSC_FALSE; } if (petscstack) { petscstack->hotdepth =
(((petscstack->hotdepth-1)<(0)) ? (0) : (petscstack->
hotdepth-1)); } ; } while (0); return(0);} while (0)
;
140}
141
142#endif