File: setup.c

package info (click to toggle)
spooles 2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 19,012 kB
  • sloc: ansic: 146,834; csh: 3,615; makefile: 2,040; perl: 74
file content (258 lines) | stat: -rw-r--r-- 6,964 bytes parent folder | download | duplicates (7)
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
/*  Setup.c  */

#include "../Bridge.h"

/*--------------------------------------------------------------------*/
/*
   -------------------------------------------------------------------
   purpose --

   given an InpMtx object that contains the structure of A, initialize 
     the bridge data structure for the serial factor's and solve's.

   return value --
      1 -- normal return
     -1 -- bridge is NULL
     -2 -- mtxA is NULL

   created -- 98sep17, cca
   -------------------------------------------------------------------
*/
int
Bridge_setup (
   Bridge   *bridge,
   InpMtx   *mtxA
) {
double   t0, t1, t2 ;
ETree    *frontETree ;
FILE     *msgFile ;
Graph    *graph ;
int      compressed, msglvl, nedges, neqns, Neqns ;
IV       *eqmapIV ;
IVL      *adjIVL, *symbfacIVL ;

MARKTIME(t0) ;
/*
   --------------------
   check the input data
   --------------------
*/
if ( bridge == NULL ) {
   fprintf(stderr, "\n fatal error in Bridge_setup()"
           "\n data is NULL\n") ;
   return(-1) ;
}
if ( mtxA == NULL ) {
   fprintf(stderr, "\n fatal error in Bridge_setup()"
           "\n A is NULL\n") ;
   return(-2) ;
}
msglvl  = bridge->msglvl ;
msgFile = bridge->msgFile ;
neqns   = bridge->neqns ;
if ( ! (INPMTX_IS_BY_ROWS(mtxA) || INPMTX_IS_BY_COLUMNS(mtxA)) ) {
/*
   ------------------------------
   change coordinate type to rows
   ------------------------------
*/
   InpMtx_changeCoordType(mtxA, INPMTX_BY_ROWS) ;
}
if ( ! INPMTX_IS_BY_VECTORS(mtxA) ) {
/*
   ------------------------------
   change storage mode to vectors
   ------------------------------
*/
   InpMtx_changeStorageMode(mtxA, INPMTX_BY_VECTORS) ;
}
/*
   ---------------------------
   create a Graph object for A
   ---------------------------
*/
MARKTIME(t1) ;
graph  = Graph_new() ;
adjIVL = InpMtx_fullAdjacency(mtxA);
nedges = bridge->nedges = IVL_tsize(adjIVL),
Graph_init2(graph, 0, neqns, 0, nedges,
            neqns, nedges, adjIVL, NULL, NULL) ;
MARKTIME(t2) ;
bridge->cpus[0] += t2 - t1 ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n CPU %8.3f : time to create Graph", t2 - t1) ;
   fflush(msgFile) ;
}
if ( msglvl > 3 ) {
   fprintf(msgFile, "\n\n graph of the input matrix") ;
   Graph_writeForHumanEye(graph, msgFile) ;
   fflush(msgFile) ;
}
/*
   -----------------------
   get the equivalence map
   -----------------------
*/
MARKTIME(t1) ;
eqmapIV = Graph_equivMap(graph) ;
Neqns = bridge->Neqns = 1 + IV_max(eqmapIV) ;
if ( msglvl > 2 ) {
   fprintf(msgFile, "\n\n graph's equivalence map") ;
   IV_writeForHumanEye(eqmapIV, msgFile) ;
   fflush(msgFile) ;
}
if ( Neqns < bridge->compressCutoff * neqns ) {
   Graph   *cgraph ;
/*
   ------------------
   compress the graph
   ------------------
*/
   cgraph = Graph_compress2(graph, eqmapIV, 1) ;
   Graph_free(graph) ;
   graph = cgraph ;
   compressed = 1 ;
   bridge->Nedges = graph->nedges ;
} else {
   compressed = 0 ;
}
MARKTIME(t2) ;
bridge->cpus[1] += t2 - t1 ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n CPU %8.3f : time to create compressed graph", 
           t2 - t1) ;
   fflush(msgFile) ;
}
if ( msglvl > 3 ) {
   fprintf(msgFile, "\n\n graph to order") ;
   Graph_writeForHumanEye(graph, msgFile) ;
   fflush(msgFile) ;
}
/*
   ---------------
   order the graph
   ---------------
*/
MARKTIME(t1) ;
if ( bridge->maxdomainsize <= 0 ) {
   bridge->maxdomainsize = neqns/32 ;
}
if ( bridge->maxdomainsize <= 0 ) {
   bridge->maxdomainsize = 1 ;
}
if ( bridge->maxnzeros < 0 ) {
   bridge->maxnzeros = 0.01*neqns ;
}
if ( bridge->maxsize < 0 ) {
   bridge->maxsize = neqns ;
}
frontETree = orderViaBestOfNDandMS(graph, bridge->maxdomainsize,
                                   bridge->maxnzeros, bridge->maxsize, 
                                   bridge->seed, msglvl, msgFile) ;
bridge->frontETree = frontETree ;
MARKTIME(t2) ;
bridge->cpus[2] += t2 - t1 ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n CPU %8.3f : time to order graph", t2 - t1) ;
   fflush(msgFile) ;
}
if ( msglvl > 3 ) {
   fprintf(msgFile, "\n\n front tree from ordering") ;
   ETree_writeForHumanEye(bridge->frontETree, msgFile) ;
   fflush(msgFile) ;
}
MARKTIME(t1) ;
if ( compressed == 1 ) {
   ETree   *etree ;
   IVL     *tempIVL ;
/*
   ----------------------------------------------------------
   compute the symbolic factorization of the compressed graph
   ----------------------------------------------------------
*/
   tempIVL = SymbFac_initFromGraph(frontETree, graph) ;
/*
   -------------------------------------------------------
   expand the symbolic factorization to the original graph
   -------------------------------------------------------
*/
   symbfacIVL = IVL_expand(tempIVL, eqmapIV) ;
   IVL_free(tempIVL) ;
/*
   ---------------------
   expand the front tree
   ---------------------
*/
   etree = ETree_expand(frontETree, eqmapIV) ;
   ETree_free(frontETree) ;
   frontETree = etree ;
} else {
/*
   --------------------------------------------------------
   compute the symbolic factorization of the original graph
   --------------------------------------------------------
*/
   symbfacIVL = SymbFac_initFromGraph(frontETree, graph) ;
}
MARKTIME(t2) ;
bridge->frontETree = frontETree ;
bridge->symbfacIVL = symbfacIVL ;
/*
   ----------------------------------------------
   get the old-to-new and new-to-old permutations
   ----------------------------------------------
*/
bridge->oldToNewIV = ETree_oldToNewVtxPerm(frontETree) ;
bridge->newToOldIV = ETree_newToOldVtxPerm(frontETree) ;
if ( msglvl > 2 ) {
   fprintf(msgFile, "\n\n old-to-new permutation") ;
   IV_writeForHumanEye(bridge->oldToNewIV, msgFile) ;
   fprintf(msgFile, "\n\n new-to-old permutation") ;
   IV_writeForHumanEye(bridge->newToOldIV, msgFile) ;
   fflush(msgFile) ;
}
/*
   ------------------------------------------------------
   overwrite the symbolic factorization with the permuted 
   indices and sort the lists into ascending order
   ------------------------------------------------------
*/
IVL_overwrite(symbfacIVL, bridge->oldToNewIV) ;
IVL_sortUp(symbfacIVL) ;
if ( msglvl > 2 ) {
   fprintf(msgFile, "\n\n symbolic factorization") ;
   IVL_writeForHumanEye(symbfacIVL, msgFile) ;
   fflush(msgFile) ;
}
/*
   --------------------------------------
   permute the vertices in the front tree
   --------------------------------------
*/
ETree_permuteVertices(frontETree, bridge->oldToNewIV) ;
if ( msglvl > 2 ) {
   fprintf(msgFile, "\n\n permuted front etree") ;
   ETree_writeForHumanEye(frontETree, msgFile) ;
   fflush(msgFile) ;
}
MARKTIME(t2) ;
bridge->cpus[3] += t2 - t1 ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n CPU %8.3f : time for symbolic factorization", 
           t2 - t1) ;
   fflush(msgFile) ;
}
/*
   ------------------------
   free the working storage
   ------------------------
*/
Graph_free(graph) ;
IV_free(eqmapIV) ;

MARKTIME(t2) ;
bridge->cpus[4] += t2 - t0 ;

return(1) ; }

/*--------------------------------------------------------------------*/