File: testStats.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 (354 lines) | stat: -rw-r--r-- 9,751 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*  testStats.c  */

#include "../../SymbFac.h"
#include "../../ETree.h"
#include "../../InpMtx.h"
#include "../../timings.h"

/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   -------------------------------------------
   (1) read in an ETree object.
   (2) read in a Graph object.
   (3) draw a tree picture of the distribution
       of some metric across the fronts
   
   created -- 99jan22, cca
   -------------------------------------------
*/
{
char     coordflag, heightflag ;
char     *inETreeFileName, *inGraphFileName, *outEPSfileName ;
double   fontscale, rmax, rscale, t1, t2 ;
double   bbox[4], frame[4] ;
double   *radius ;
DV       *radiusDV, *xDV, *yDV ;
Graph    *graph ;
int      J, labelflag, metricType, msglvl, nfront, nvtx, rc ;
int      *metric, *vwghts ;
IV       *metricIV ;
ETree    *etree ;
FILE     *msgFile ;
Tree     *tree ;

if ( argc != 12 ) {
   fprintf(stdout, 
"\n\n usage : %s msglvl msgFile inETreeFile inGraphFile outEPSfile "
"\n         metricType heightflag coordflag rscale labelflag fontscale"
"\n    msglvl       -- message level"
"\n    msgFile      -- message file"
"\n    inETreeFile  -- input file, must be *.etreef or *.etreeb"
"\n    inGraphFile  -- input file, must be *.graphf or *.graphb"
"\n    outEPSfile   -- output file for tree picture, must be *.eps"
"\n    metricType   -- metric type"
"\n       0 -- no metric"
"\n       1 -- # of nodes in front"
"\n       2 -- # of original matrix entries in front"
"\n       3 -- # of factor matrix entries in front"
"\n       4 -- # of forward factor ops in front"
"\n       5 -- # of backward factor ops in front"
"\n    heightflag   -- flag for type of height"
"\n      'D' -- nodes placed by depth in tree"
"\n      'H' -- nodes placed by height in tree"
"\n    coordflag    -- flag for type of coordinate"
"\n      'C' -- cartesian (x,y) placement"
"\n      'P' -- polar (r,theta) placement"
"\n    rmax      -- maximum radius in pts"
"\n    labelflag -- flag for type of labels"
"\n           1     -- draw labels"
"\n       otherwise -- do not draw labels"
"\n    fontscale -- scaling parameter for fonts when labels drawed"
"\n", argv[0]) ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
inETreeFileName  = argv[3] ;
inGraphFileName  = argv[4] ;
outEPSfileName   = argv[5] ;
metricType       = atoi(argv[6]) ;
heightflag       = *argv[7] ;
coordflag        = *argv[8] ;
rmax             = atof(argv[9]) ;
labelflag        = atoi(argv[10]) ;
fontscale        = atof(argv[11]) ;
fprintf(msgFile, 
        "\n %s "
        "\n msglvl        -- %d" 
        "\n msgFile       -- %s" 
        "\n inETreeFile   -- %s" 
        "\n inGraphFile   -- %s" 
        "\n outEPSfile    -- %s" 
        "\n metricType    -- %d" 
        "\n heightflag    -- %c" 
        "\n coordflag     -- %c" 
        "\n rmax          -- %f" 
        "\n labelflag     -- %d" 
        "\n fontscale     -- %f" 
        "\n",
        argv[0], msglvl, argv[2], inETreeFileName, inGraphFileName, 
        outEPSfileName, metricType, heightflag, coordflag, rmax, 
        labelflag, fontscale) ;
fflush(msgFile) ;
/*
   ------------------------
   read in the ETree object
   ------------------------
*/
if ( strcmp(inETreeFileName, "none") == 0 ) {
   fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
etree = ETree_new() ;
MARKTIME(t1) ;
rc = ETree_readFromFile(etree, inETreeFileName) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in etree from file %s",
        t2 - t1, inETreeFileName) ;
if ( rc != 1 ) {
   fprintf(msgFile, "\n return value %d from ETree_readFromFile(%p,%s)",
           rc, etree, inETreeFileName) ;
   exit(-1) ;
}
ETree_leftJustify(etree) ;
fprintf(msgFile, "\n\n after reading ETree object from file %s",
        inETreeFileName) ;
if ( msglvl > 2 ) {
   ETree_writeForHumanEye(etree, msgFile) ;
} else {
   ETree_writeStats(etree, msgFile) ;
}
fflush(msgFile) ;
nfront = ETree_nfront(etree) ;
tree   = ETree_tree(etree) ;
/*
   ------------------------
   read in the Graph object
   ------------------------
*/
if ( strcmp(inGraphFileName, "none") == 0 ) {
   fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
graph = Graph_new() ;
MARKTIME(t1) ;
rc = Graph_readFromFile(graph, inGraphFileName) ;
nvtx = graph->nvtx ;
vwghts = graph->vwghts ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in graph from file %s",
        t2 - t1, inGraphFileName) ;
if ( rc != 1 ) {
   fprintf(msgFile, "\n return value %d from Graph_readFromFile(%p,%s)",
           rc, graph, inGraphFileName) ;
   exit(-1) ;
}
fprintf(msgFile, "\n\n after reading Graph object from file %s",
        inGraphFileName) ;
if ( msglvl > 2 ) {
   Graph_writeForHumanEye(graph, msgFile) ;
} else {
   Graph_writeStats(graph, msgFile) ;
}
fflush(msgFile) ;
/*
   ----------------------
   compute the statistics
   ----------------------
*/
metricIV = IV_new() ;
IV_init(metricIV, nfront, NULL) ;
metric = IV_entries(metricIV) ;
switch ( metricType ) {
case 0 : {
/*
   ---------
   no metric
   ---------
*/
   IVfill(nfront, metric, 1) ;
   } break ;
case 1 : {
/*
   -----------
   front sizes
   -----------
*/
   IVcopy(nfront, metric, ETree_nodwghts(etree)) ;
   } break ;
case 2 : {
/*
   ----------------------------------------------
   number of original matrix entries in the front
   ----------------------------------------------
*/
   int   I, ii, J, v, vsize, w ;
   int   *vadj, *vtxToFront ;

   vtxToFront = ETree_vtxToFront(etree) ;
   for ( v = 0 ; v < nvtx ; v++ ) {
      I = vtxToFront[v] ;
      Graph_adjAndSize(graph, v, &vsize, &vadj) ;
      for ( ii = 0 ; ii < vsize ; ii++ ) {
         w = vadj[ii] ;
         J = vtxToFront[w] ;
         if ( I <= J ) {
            if ( vwghts == NULL ) {
               metric[I]++ ;
            } else {
               metric[I] += vwghts[v]*vwghts[w] ;
            }
         } else {
            if ( vwghts == NULL ) {
               metric[J]++ ;
            } else {
               metric[J] += vwghts[v]*vwghts[w] ;
            }
         }
      }
   }
   } break ;
case 3 : {
/*
   --------------------------------------------
   number of factor matrix entries in the front
   --------------------------------------------
*/
   int   *nzf ;
   IV    *nzfIV ;

   nzfIV = ETree_factorEntriesIV(etree, SPOOLES_SYMMETRIC) ;
   nzf   = IV_entries(nzfIV) ;
   for ( J = 0 ; J < nfront ; J++ ) {
      metric[J] = nzf[J] ;
   }
   IV_free(nzfIV) ;
   } break ;
case 4 : {
/*
   ------------------------------------------------
   number of forward factor operations in the front
   ------------------------------------------------
*/
   double   *ops ;
   DV       *opsDV ;

   opsDV = ETree_forwardOps(etree, SPOOLES_REAL, SPOOLES_SYMMETRIC) ;
   ops   = DV_entries(opsDV) ;
   for ( J = 0 ; J < nfront ; J++ ) {
      metric[J] = ops[J] ;
   }
   DV_free(opsDV) ;
   } break ;
case 5 : {
/*
   -------------------------------------------------
   number of backward factor operations in the front
   -------------------------------------------------
*/
   double   *ops ;
   DV       *opsDV ;
   IVL      *symbfacIVL ;

   symbfacIVL = SymbFac_initFromGraph(etree, graph) ;
   opsDV = ETree_backwardOps(etree, SPOOLES_REAL, SPOOLES_SYMMETRIC,
                             graph->vwghts, symbfacIVL) ;
   ops   = DV_entries(opsDV) ;
   for ( J = 0 ; J < nfront ; J++ ) {
      metric[J] = ops[J] ;
   }
   DV_free(opsDV) ;
   IVL_free(symbfacIVL) ;
   } break ;
default :
   fprintf(stderr, "\n error in testStats"
           "\n metricType %d not supported", metricType) ;
   exit(-1) ;
}
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n metric vector") ;
   IV_writeForHumanEye(metricIV, msgFile) ;
   fflush(msgFile) ;
}
/*
   ---------------------
   set the radius vector
   ---------------------
*/
radiusDV = DV_new() ;
DV_init(radiusDV, nfront, NULL) ;
radius = DV_entries(radiusDV) ;
for ( J = 0 ; J < nfront ; J++ ) {
   radius[J] = sqrt(0.318309886*metric[J]) ;
}
rscale = rmax / DVmax(nfront, radius, &J) ;
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n radius vector") ;
   DV_writeForHumanEye(radiusDV, msgFile) ;
   fflush(msgFile) ;
}
/*
   ------------------------
   get the tree coordinates
   ------------------------
*/
xDV = DV_new() ;
yDV = DV_new() ;
rc = Tree_getSimpleCoords(tree, heightflag, coordflag, xDV, yDV) ;
if ( rc != 1 ) {
   fprintf(stderr, "\n error return %d from Tree_getSimpleCoords()",rc);
   exit(-1) ;
}
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n x-coordinates") ;
   DV_writeForHumanEye(xDV, msgFile) ;
   fprintf(msgFile, "\n\n y-coordinates") ;
   DV_writeForHumanEye(yDV, msgFile) ;
   fprintf(msgFile, "\n\n radius") ;
   DV_writeForHumanEye(radiusDV, msgFile) ;
   fflush(msgFile) ;
}
/*
   -------------
   draw the tree
   -------------
*/
bbox[0]   =  50 ;
bbox[1]   =  50 ;
bbox[2]   = 550 ;
bbox[3]   = 550 ;
frame[0]  =  60 ;
frame[1]  =  60 ;
frame[2]  = 540 ;
frame[3]  = 540 ;
rc = Tree_drawToEPS(tree, outEPSfileName, xDV, yDV, rscale, radiusDV, 
                    labelflag, fontscale, NULL, bbox, frame, NULL) ;
if ( rc != 1 ) {
   fprintf(stderr, "\n error return %d from Tree_drawToEPSfile()", rc) ;
   exit(-1) ;
}
/*
   ----------------
   free the objects
   ----------------
*/
ETree_free(etree) ;
Graph_free(graph) ;
IV_free(metricIV) ;
DV_free(radiusDV) ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }

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