forked from KarypisLab/METIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.h
258 lines (233 loc) · 8.17 KB
/
macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
* Copyright 1997, Regents of the University of Minnesota
*
* macros.h
*
* This file contains macros used in multilevel
*
* Started 9/25/94
* George
*
* $Id: macros.h 10060 2011-06-02 18:56:30Z karypis $
*
*/
#ifndef _LIBMETIS_MACROS_H_
#define _LIBMETIS_MACROS_H_
/*************************************************************************
* The following macro returns a random number in the specified range
**************************************************************************/
#define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b)))
#define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b)))
#define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b)))
//#define icopy(n, a, b) (idx_t *)memcpy((void *)(b), (void *)(a), sizeof(idx_t)*(n))
#define HASHFCT(key, size) ((key)%(size))
#define SWAP gk_SWAP
/* gets the appropriate option value */
#define GETOPTION(options, idx, defval) \
((options) == NULL || (options)[idx] == -1 ? defval : (options)[idx])
/* converts a user provided ufactor into a real ubfactor */
#define I2RUBFACTOR(ufactor) (1.0+0.001*(ufactor))
/* set/reset the current workspace core */
#define WCOREPUSH wspacepush(ctrl)
#define WCOREPOP wspacepop(ctrl)
/*************************************************************************
* These macros insert and remove nodes from a Direct Access list
**************************************************************************/
#define ListInsert(n, lind, lptr, i) \
do { \
ASSERT(lptr[i] == -1); \
lind[n] = i; \
lptr[i] = (n)++;\
} while(0)
#define ListDelete(n, lind, lptr, i) \
do { \
ASSERT(lptr[i] != -1); \
lind[lptr[i]] = lind[--(n)]; \
lptr[lind[n]] = lptr[i]; \
lptr[i] = -1; \
} while(0)
/*************************************************************************
* These macros insert and remove nodes from the boundary list
**************************************************************************/
#define BNDInsert(nbnd, bndind, bndptr, vtx) \
ListInsert(nbnd, bndind, bndptr, vtx)
#define BNDDelete(nbnd, bndind, bndptr, vtx) \
ListDelete(nbnd, bndind, bndptr, vtx)
/*************************************************************************
* These macros deal with id/ed updating during k-way refinement
**************************************************************************/
#define UpdateMovedVertexInfoAndBND(i, from, k, to, myrinfo, mynbrs, where, \
nbnd, bndptr, bndind, bndtype) \
do { \
where[i] = to; \
myrinfo->ed += myrinfo->id-mynbrs[k].ed; \
SWAP(myrinfo->id, mynbrs[k].ed, j); \
if (mynbrs[k].ed == 0) \
mynbrs[k] = mynbrs[--myrinfo->nnbrs]; \
else \
mynbrs[k].pid = from; \
\
/* Update the boundary information. Both deletion and addition is \
allowed as this routine can be used for moving arbitrary nodes. */ \
if (bndtype == BNDTYPE_REFINE) { \
if (bndptr[i] != -1 && myrinfo->ed - myrinfo->id < 0) \
BNDDelete(nbnd, bndind, bndptr, i); \
if (bndptr[i] == -1 && myrinfo->ed - myrinfo->id >= 0) \
BNDInsert(nbnd, bndind, bndptr, i); \
} \
else { \
if (bndptr[i] != -1 && myrinfo->ed <= 0) \
BNDDelete(nbnd, bndind, bndptr, i); \
if (bndptr[i] == -1 && myrinfo->ed > 0) \
BNDInsert(nbnd, bndind, bndptr, i); \
} \
} while(0)
#define UpdateAdjacentVertexInfoAndBND(ctrl, vid, adjlen, me, from, to, \
myrinfo, ewgt, nbnd, bndptr, bndind, bndtype) \
do { \
idx_t k; \
cnbr_t *mynbrs; \
\
if (myrinfo->inbr == -1) { \
myrinfo->inbr = cnbrpoolGetNext(ctrl, adjlen); \
myrinfo->nnbrs = 0; \
} \
ASSERT(CheckRInfo(ctrl, myrinfo)); \
\
mynbrs = ctrl->cnbrpool + myrinfo->inbr; \
\
/* Update global ID/ED and boundary */ \
if (me == from) { \
INC_DEC(myrinfo->ed, myrinfo->id, (ewgt)); \
if (bndtype == BNDTYPE_REFINE) { \
if (myrinfo->ed-myrinfo->id >= 0 && bndptr[(vid)] == -1) \
BNDInsert(nbnd, bndind, bndptr, (vid)); \
} \
else { \
if (myrinfo->ed > 0 && bndptr[(vid)] == -1) \
BNDInsert(nbnd, bndind, bndptr, (vid)); \
} \
} \
else if (me == to) { \
INC_DEC(myrinfo->id, myrinfo->ed, (ewgt)); \
if (bndtype == BNDTYPE_REFINE) { \
if (myrinfo->ed-myrinfo->id < 0 && bndptr[(vid)] != -1) \
BNDDelete(nbnd, bndind, bndptr, (vid)); \
} \
else { \
if (myrinfo->ed <= 0 && bndptr[(vid)] != -1) \
BNDDelete(nbnd, bndind, bndptr, (vid)); \
} \
} \
\
/* Remove contribution from the .ed of 'from' */ \
if (me != from) { \
for (k=0; k<myrinfo->nnbrs; k++) { \
if (mynbrs[k].pid == from) { \
if (mynbrs[k].ed == (ewgt)) \
mynbrs[k] = mynbrs[--myrinfo->nnbrs]; \
else \
mynbrs[k].ed -= (ewgt); \
break; \
} \
} \
} \
\
/* Add contribution to the .ed of 'to' */ \
if (me != to) { \
for (k=0; k<myrinfo->nnbrs; k++) { \
if (mynbrs[k].pid == to) { \
mynbrs[k].ed += (ewgt); \
break; \
} \
} \
if (k == myrinfo->nnbrs) { \
mynbrs[k].pid = to; \
mynbrs[k].ed = (ewgt); \
myrinfo->nnbrs++; \
} \
} \
\
ASSERT(CheckRInfo(ctrl, myrinfo));\
} while(0)
#define UpdateQueueInfo(queue, vstatus, vid, me, from, to, myrinfo, oldnnbrs, \
nupd, updptr, updind, bndtype) \
do { \
real_t rgain; \
\
if (me == to || me == from || oldnnbrs != myrinfo->nnbrs) { \
rgain = (myrinfo->nnbrs > 0 ? \
1.0*myrinfo->ed/sqrt(myrinfo->nnbrs) : 0.0) - myrinfo->id; \
\
if (bndtype == BNDTYPE_REFINE) { \
if (vstatus[(vid)] == VPQSTATUS_PRESENT) { \
if (myrinfo->ed-myrinfo->id >= 0) \
rpqUpdate(queue, (vid), rgain); \
else { \
rpqDelete(queue, (vid)); \
vstatus[(vid)] = VPQSTATUS_NOTPRESENT; \
ListDelete(nupd, updind, updptr, (vid)); \
} \
} \
else if (vstatus[(vid)] == VPQSTATUS_NOTPRESENT && myrinfo->ed-myrinfo->id >= 0) { \
rpqInsert(queue, (vid), rgain); \
vstatus[(vid)] = VPQSTATUS_PRESENT; \
ListInsert(nupd, updind, updptr, (vid)); \
} \
} \
else { \
if (vstatus[(vid)] == VPQSTATUS_PRESENT) { \
if (myrinfo->ed > 0) \
rpqUpdate(queue, (vid), rgain); \
else { \
rpqDelete(queue, (vid)); \
vstatus[(vid)] = VPQSTATUS_NOTPRESENT; \
ListDelete(nupd, updind, updptr, (vid)); \
} \
} \
else if (vstatus[(vid)] == VPQSTATUS_NOTPRESENT && myrinfo->ed > 0) { \
rpqInsert(queue, (vid), rgain); \
vstatus[(vid)] = VPQSTATUS_PRESENT; \
ListInsert(nupd, updind, updptr, (vid)); \
} \
} \
} \
} while(0)
/*************************************************************************/
/*! This macro determines the set of subdomains that a vertex can move to
without increasins the maxndoms. */
/*************************************************************************/
#define SelectSafeTargetSubdomains(myrinfo, mynbrs, nads, adids, maxndoms, safetos, vtmp) \
do { \
idx_t j, k, l, nadd, to; \
for (j=0; j<myrinfo->nnbrs; j++) { \
safetos[to = mynbrs[j].pid] = 0; \
\
/* uncompress the connectivity info for the 'to' subdomain */ \
for (k=0; k<nads[to]; k++) \
vtmp[adids[to][k]] = 1; \
\
for (nadd=0, k=0; k<myrinfo->nnbrs; k++) { \
if (k == j) \
continue; \
\
l = mynbrs[k].pid; \
if (vtmp[l] == 0) { \
if (nads[l] > maxndoms-1) { \
nadd = maxndoms; \
break; \
} \
nadd++; \
} \
} \
if (nads[to]+nadd <= maxndoms) \
safetos[to] = 1; \
if (nadd == 0) \
safetos[to] = 2; \
\
/* cleanup the connectivity info due to the 'to' subdomain */ \
for (k=0; k<nads[to]; k++) \
vtmp[adids[to][k]] = 0; \
} \
} while (0)
#endif