-
Notifications
You must be signed in to change notification settings - Fork 0
/
metis_adapter.c
273 lines (232 loc) · 6.63 KB
/
metis_adapter.c
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* Copyright (C) 2020 COIN-OR
* All Rights Reserved.
* This file is distributed under the Eclipse Public License.
*/
#include "CoinHslConfig.h"
#ifndef COINHSL_HAS_METIS
/* provide dummy implementations of the method metis_nodend as expected by the HSL codes if Metis is not available
* as in Metis, we implement the method in several naming variants to copy with C and fortran naming style conventions
* Not defining COINMETIS_NODEND, as the renaming metis -> coinmetis only happens if Metis is available
*/
typedef int idxtype;
void METIS_NODEND(int * a, idxtype * b, idxtype * c, int * d, int * e, idxtype * f, idxtype * perm)
{
perm[0] = -1;
}
void metis_nodend(int * a, idxtype * b, idxtype * c, int * d, int * e, idxtype * f, idxtype * perm)
{
perm[0] = -1;
}
void metis_nodend_(int * a, idxtype * b, idxtype * c, int * d, int * e, idxtype * f, idxtype * perm)
{
perm[0] = -1;
}
void metis_nodend__(int * a, idxtype * b, idxtype * c, int * d, int * e, idxtype * f, idxtype * perm)
{
perm[0] = -1;
}
void METIS_NodeND(int * a, idxtype * b, idxtype * c, int * d, int * e, idxtype * f, idxtype * perm)
{
perm[0] = -1;
}
#else /* COINHSL_HAS_METIS */
#include "metis.h"
#ifndef METIS_VER_MAJOR
#define METIS_VER_MAJOR 4
#endif
/* wrapper to map COINMETIS_NODEND to METIS_NODEND from Metis 4 or 5 */
typedef int idxtype;
extern void COINMETIS_NODEND(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *);
extern void coinmetis_nodend(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *);
extern void coinmetis_nodend_(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *);
extern void coinmetis_nodend__(int *, idxtype *, idxtype *, int *, int *, idxtype *, idxtype *);
#if METIS_VER_MAJOR < 5
void COINMETIS_NODEND(
int* nvtxs,
idxtype* xadj,
idxtype* adjncy,
int* numflag,
int* options,
idxtype* perm,
idxtype* iperm)
{
METIS_NODEND(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend(
int* nvtxs,
idxtype* xadj,
idxtype* adjncy,
int* numflag,
int* options,
idxtype* perm,
idxtype* iperm)
{
metis_nodend(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend_(
int* nvtxs,
idxtype* xadj,
idxtype* adjncy,
int* numflag,
int* options,
idxtype* perm,
idxtype* iperm)
{
metis_nodend_(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend__(
int* nvtxs,
idxtype* xadj,
idxtype* adjncy,
int* numflag,
int* options,
idxtype* perm,
idxtype* iperm)
{
metis_nodend__(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
#else /* METIS_VER_MAJOR >= 5 */
#if 0
#include <stdio.h>
#endif
static
void COINMETIS_NodeND(
int* nvtxs,
idx_t* xadj,
idx_t* adjncy,
int* numflag,
int* options,
idx_t* perm,
idx_t* iperm)
{
idx_t options5[METIS_NOPTIONS];
#if 0
{
int i;
printf("METIS_NodeND called with nvtxs = %d numflag=%d\n", *nvtxs, *numflag);
printf("xadj:");
for( i = 0; i < *nvtxs; ++i )
printf(" %d", xadj[i]);
printf("\nadjncy:");
for( i = 0; i < xadj[*nvtxs] - *numflag; ++i )
printf(" %d", adjncy[i]);
printf("\n");
printf("options:");
if( options[0] == 0 )
printf(" default\n");
else
{
for( i = 0; i < 8; ++i )
printf(" %d", options[i]);
printf("\n");
}
}
#endif
if( *nvtxs == 1 )
{
/* MA57 seems to call metis with a graph containing 1 vertex and a self-loop
* Metis5 prints an error for this
*/
perm[0] = *numflag;
iperm[0] = *numflag;
return;
}
METIS_SetDefaultOptions(options5);
options5[METIS_OPTION_NUMBERING] = *numflag;
if( options[0] != 0 )
{
if( options[1] == 1 ) /* random matching */
options5[METIS_OPTION_CTYPE] = METIS_CTYPE_RM;
else /* heavy-edge or sorted heavy-edge matching; map both to shem, as heave-edge matching not available in metis5 */
options5[METIS_OPTION_CTYPE] = METIS_CTYPE_SHEM;
if( options[2] == 1 ) /* edge-based region-growing */
options5[METIS_OPTION_IPTYPE] = METIS_IPTYPE_GROW; /* ?? */
else /* node-based region-growing */
options5[METIS_OPTION_IPTYPE] = METIS_IPTYPE_NODE;
if( options[3] == 1 ) /* two-sided node FM refinement */
options5[METIS_OPTION_RTYPE] = METIS_RTYPE_SEP2SIDED;
else /* one-sided node FM refinement */
options5[METIS_OPTION_RTYPE] = METIS_RTYPE_SEP1SIDED;
/* options[4] to options5[METIS_OPTION_DBGLV] ? */
switch( options[5] )
{
case 0: /* do not try to compress or order connected components */
options5[METIS_OPTION_COMPRESS] = 0;
options5[METIS_OPTION_CCORDER] = 0;
break;
case 1: /* try to compress graph */
options5[METIS_OPTION_COMPRESS] = 1;
options5[METIS_OPTION_CCORDER] = 0;
break;
case 2: /* order each component separately */
options5[METIS_OPTION_COMPRESS] = 0;
options5[METIS_OPTION_CCORDER] = 1;
break;
case 3: /* try to compress and order components */
options5[METIS_OPTION_COMPRESS] = 1;
options5[METIS_OPTION_CCORDER] = 1;
break;
}
options5[METIS_OPTION_PFACTOR] = options[6];
options5[METIS_OPTION_NSEPS] = options[7];
}
METIS_NodeND(nvtxs, xadj, adjncy, (void*)0, options5, perm, iperm);
#if 0
{
int i;
printf("perm:");
for( i = 0; i < *nvtxs; ++i )
printf(" %d", perm[i]);
printf("\niperm");
for( i = 0; i < *nvtxs; ++i )
printf(" %d", iperm[i]);
printf("\n");
}
#endif
}
void COINMETIS_NODEND(
int* nvtxs,
idx_t* xadj,
idx_t* adjncy,
int* numflag,
int* options,
idx_t* perm,
idx_t* iperm)
{
COINMETIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend(
int* nvtxs,
idx_t* xadj,
idx_t* adjncy,
int* numflag,
int* options,
idx_t* perm,
idx_t* iperm)
{
COINMETIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend_(
int* nvtxs,
idx_t* xadj,
idx_t* adjncy,
int* numflag,
int* options,
idx_t* perm,
idx_t* iperm)
{
COINMETIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
void coinmetis_nodend__(
int* nvtxs,
idx_t* xadj,
idx_t* adjncy,
int* numflag,
int* options,
idx_t* perm,
idx_t* iperm)
{
COINMETIS_NodeND(nvtxs, xadj, adjncy, numflag, options, perm, iperm);
}
#endif /* METIS_VER_MAJOR */
#endif /* COINHSL_HAS_METIS */