1 /* createETree.c */
2
3 #include "../ETree.h"
4 #include "../../Perm.h"
5 #include "../../timings.h"
6
7 /*--------------------------------------------------------------------*/
8 int
main(int argc,char * argv[])9 main ( int argc, char *argv[] )
10 /*
11 ---------------------------------------------
12 read in a Graph and a Perm object.
13 create the ETree object and fill an IV object
14 with the compids of the two-set partition
15
16 created -- 96may02, cca
17 ---------------------------------------------
18 */
19 {
20 char *inGraphFileName, *inPermFileName,
21 *outETreeFileName, *outIVfileName ;
22 double t1, t2 ;
23 int msglvl, rc ;
24 ETree *etree, *fsETree ;
25 IV *fsMapIV ;
26 FILE *msgFile ;
27 Graph *graph ;
28 Perm *perm ;
29
30 if ( argc != 7 ) {
31 fprintf(stdout,
32 "\n\n usage : %s msglvl msgFile inGraphFile inPermFile "
33 "\n outIVfile outETreeFile"
34 "\n msglvl -- message level"
35 "\n msgFile -- message file"
36 "\n inGraphFile -- input file, must be *.graphf or *.graphb"
37 "\n inPermFile -- input file, must be *.permf or *.permb"
38 "\n outIVfile -- output file for compids[]"
39 "\n must be *.ivf or *.ivf"
40 "\n outETreeFile -- output file, must be *.etreef or *.etreeb"
41 "\n", argv[0]) ;
42 return(0) ;
43 }
44 msglvl = atoi(argv[1]) ;
45 if ( strcmp(argv[2], "stdout") == 0 ) {
46 msgFile = stdout ;
47 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
48 fprintf(stderr, "\n fatal error in %s"
49 "\n unable to open file %s\n",
50 argv[0], argv[2]) ;
51 return(-1) ;
52 }
53 inGraphFileName = argv[3] ;
54 inPermFileName = argv[4] ;
55 outIVfileName = argv[5] ;
56 outETreeFileName = argv[6] ;
57 fprintf(msgFile,
58 "\n %s "
59 "\n msglvl -- %d"
60 "\n msgFile -- %s"
61 "\n inGraphFile -- %s"
62 "\n inPermFile -- %s"
63 "\n outIVfile -- %s"
64 "\n outETreeFile -- %s"
65 "\n",
66 argv[0], msglvl, argv[2],
67 inGraphFileName, inPermFileName,
68 outIVfileName, outETreeFileName) ;
69 fflush(msgFile) ;
70 /*
71 ------------------------
72 read in the Graph object
73 ------------------------
74 */
75 if ( strcmp(inGraphFileName, "none") == 0 ) {
76 fprintf(msgFile, "\n no file to read from") ;
77 exit(0) ;
78 }
79 graph = Graph_new() ;
80 MARKTIME(t1) ;
81 rc = Graph_readFromFile(graph, inGraphFileName) ;
82 MARKTIME(t2) ;
83 fprintf(msgFile, "\n CPU %9.5f : read in graph from file %s",
84 t2 - t1, inGraphFileName) ;
85 if ( rc != 1 ) {
86 fprintf(msgFile, "\n return value %d from Graph_readFromFile(%p,%s)",
87 rc, graph, inGraphFileName) ;
88 exit(-1) ;
89 }
90 fprintf(msgFile, "\n\n after reading Graph object from file %s",
91 inGraphFileName) ;
92 if ( msglvl > 2 ) {
93 Graph_writeForHumanEye(graph, msgFile) ;
94 } else {
95 Graph_writeStats(graph, msgFile) ;
96 }
97 fflush(msgFile) ;
98 /*
99 ------------------------
100 read in the Perm object
101 ------------------------
102 */
103 if ( strcmp(inPermFileName, "none") == 0 ) {
104 fprintf(msgFile, "\n no file to read from") ;
105 /*
106 exit(0) ;
107 */
108 perm = NULL ;
109 } else {
110 perm = Perm_new() ;
111 MARKTIME(t1) ;
112 rc = Perm_readFromFile(perm, inPermFileName) ;
113 Perm_fillOldToNew(perm) ;
114 Perm_fillNewToOld(perm) ;
115 MARKTIME(t2) ;
116 fprintf(msgFile, "\n CPU %9.5f : read in perm from file %s",
117 t2 - t1, inPermFileName) ;
118 if ( rc != 1 ) {
119 fprintf(msgFile,
120 "\n return value %d from Perm_readFromFile(%p,%s)",
121 rc, perm, inPermFileName) ;
122 exit(-1) ;
123 }
124 rc = Perm_checkPerm(perm) ;
125 if ( rc != 1 ) {
126 fprintf(stderr, "\n fatal error, Perm not valid") ;
127 Perm_writeForHumanEye(perm, stderr) ;
128 exit(0) ;
129 }
130 fprintf(msgFile, "\n\n after reading Perm object from file %s",
131 inPermFileName) ;
132 if ( msglvl > 0 ) {
133 Perm_writeForHumanEye(perm, msgFile) ;
134 } else {
135 Perm_writeStats(perm, msgFile) ;
136 }
137 fflush(msgFile) ;
138 }
139 fprintf(msgFile, "\n newToOld") ;
140 IVfprintf(msgFile, perm->size, perm->newToOld) ;
141 fprintf(msgFile, "\n oldToNew") ;
142 IVfprintf(msgFile, perm->size, perm->oldToNew) ;
143 /*
144 -----------------------
145 create the ETree object
146 -----------------------
147 */
148 etree = ETree_new() ;
149 if ( perm == NULL ) {
150 ETree_initFromGraph(etree, graph) ;
151 } else {
152 ETree_initFromGraphWithPerms(etree, graph, perm->newToOld,
153 perm->oldToNew) ;
154 }
155 fprintf(msgFile, "\n\n vertex etree") ;
156 fprintf(msgFile, "\n %d factor indices",
157 ETree_nFactorIndices(etree)) ;
158 fprintf(msgFile, "\n symmetric: %d factor entries",
159 ETree_nFactorEntries(etree, SPOOLES_SYMMETRIC)) ;
160 fprintf(msgFile, "\n nonsymmetric: %d factor entries",
161 ETree_nFactorEntries(etree, SPOOLES_NONSYMMETRIC)) ;
162 fprintf(msgFile, "\n real symmetric : %.0f factor operations",
163 ETree_nFactorOps(etree, SPOOLES_REAL, SPOOLES_SYMMETRIC)) ;
164 fprintf(msgFile, "\n real nonsymmetric : %.0f factor operations",
165 ETree_nFactorOps(etree, SPOOLES_REAL, SPOOLES_NONSYMMETRIC)) ;
166 fprintf(msgFile, "\n complex symmetric : %.0f factor operations",
167 ETree_nFactorOps(etree, SPOOLES_COMPLEX, SPOOLES_SYMMETRIC)) ;
168 fprintf(msgFile, "\n complex nonsymmetric : %.0f factor operations",
169 ETree_nFactorOps(etree, SPOOLES_COMPLEX, SPOOLES_NONSYMMETRIC));
170 fsMapIV = ETree_fundSupernodeMap(etree) ;
171 fsETree = ETree_compress(etree, fsMapIV) ;
172 fprintf(msgFile, "\n\n fundamental supernode etree") ;
173 fprintf(msgFile, "\n %d factor indices",
174 ETree_nFactorIndices(fsETree)) ;
175 fprintf(msgFile, "\n symmetric: %d factor entries",
176 ETree_nFactorEntries(fsETree, SPOOLES_SYMMETRIC)) ;
177 fprintf(msgFile, "\n nonsymmetric: %d factor entries",
178 ETree_nFactorEntries(fsETree, SPOOLES_NONSYMMETRIC)) ;
179 fprintf(msgFile, "\n real symmetric : %.0f factor operations",
180 ETree_nFactorOps(fsETree, SPOOLES_REAL, SPOOLES_SYMMETRIC)) ;
181 fprintf(msgFile, "\n real nonsymmetric : %.0f factor operations",
182 ETree_nFactorOps(fsETree, SPOOLES_REAL, SPOOLES_NONSYMMETRIC)) ;
183 fprintf(msgFile, "\n complex symmetric : %.0f factor operations",
184 ETree_nFactorOps(fsETree, SPOOLES_COMPLEX, SPOOLES_SYMMETRIC)) ;
185 fprintf(msgFile, "\n complex nonsymmetric : %.0f factor operations",
186 ETree_nFactorOps(fsETree, SPOOLES_COMPLEX, SPOOLES_NONSYMMETRIC));
187 fprintf(msgFile, "\n %.0f factor operations",
188 ETree_nFactorOps(fsETree, SPOOLES_REAL, SPOOLES_SYMMETRIC)) ;
189 if ( msglvl > 2 ) {
190 ETree_writeForHumanEye(fsETree, msgFile) ;
191 } else {
192 ETree_writeStats(fsETree, msgFile) ;
193 }
194 fflush(msgFile) ;
195 /*
196 --------------------------
197 write out the ETree object
198 --------------------------
199 */
200 if ( strcmp(outETreeFileName, "none") != 0 ) {
201 MARKTIME(t1) ;
202 rc = ETree_writeToFile(fsETree, outETreeFileName) ;
203 MARKTIME(t2) ;
204 fprintf(msgFile, "\n CPU %9.5f : write etree to file %s",
205 t2 - t1, outETreeFileName) ;
206 }
207 if ( rc != 1 ) {
208 fprintf(msgFile, "\n return value %d from ETree_writeToFile(%p,%s)",
209 rc, fsETree, outETreeFileName) ;
210 }
211 /*
212 -------------------------------
213 write out the compids IV object
214 -------------------------------
215 */
216 if ( strcmp(outIVfileName, "none") != 0 ) {
217 MARKTIME(t1) ;
218 rc = IV_writeToFile(fsETree->vtxToFrontIV, outIVfileName) ;
219 MARKTIME(t2) ;
220 fprintf(msgFile, "\n CPU %9.5f : write etree to file %s",
221 t2 - t1, outIVfileName) ;
222 }
223 if ( rc != 1 ) {
224 fprintf(msgFile, "\n return value %d from IV_writeToFile(%p,%s)",
225 rc, fsETree->vtxToFrontIV, outIVfileName) ;
226 }
227 /*
228 ----------------
229 free the objects
230 ----------------
231 */
232 Graph_free(graph) ;
233 Perm_free(perm) ;
234 ETree_free(etree) ;
235 ETree_free(fsETree) ;
236
237 fprintf(msgFile, "\n") ;
238 fclose(msgFile) ;
239
240 return(1) ; }
241
242 /*--------------------------------------------------------------------*/
243