1 /*  testDDviaFishnet.c  */
2 
3 #include "../GPart.h"
4 #include "../../DSTree.h"
5 #include "../../MSMD.h"
6 #include "../../BKL.h"
7 #include "../../ETree.h"
8 #include "../../Perm.h"
9 #include "../../IV.h"
10 #include "../../timings.h"
11 
12 /*--------------------------------------------------------------------*/
13 int
main(int argc,char * argv[])14 main ( int argc, char *argv[] )
15 /*
16    ---------------------------------------------------------------
17    read in a Graph and generate a domain decomposition via fishnet
18 
19    created -- 96oct21, cca
20    ---------------------------------------------------------------
21 */
22 {
23 char        *inGraphFileName, *msgFileName, *outIVfileName ;
24 double      t1, t2 ;
25 FILE        *msgFile ;
26 float       freeze ;
27 GPart       *gpart ;
28 Graph       *graph ;
29 int         maxweight, minweight, msglvl, nvtx, rc, seed ;
30 
31 if ( argc != 9 ) {
32    fprintf(stdout,
33       "\n\n usage : %s msglvl msgFile inGraphFile "
34       "\n           freeze minweight maxweight seed outIVfile"
35       "\n    msglvl      -- message level"
36       "\n    msgFile     -- message file"
37       "\n    inGraphFile -- input file, must be *.graphf or *.graphb"
38       "\n    freeze      -- freeze factor, try 4"
39       "\n    minweight   -- minimum domain weight"
40       "\n    maxweight   -- maximum domain weight"
41       "\n    seed        -- random number seed"
42       "\n    outIVfile   -- output file for vertex component ids,"
43       "\n                   must be *.ivf or *.ivb"
44       "\n", argv[0]) ;
45    return(0) ;
46 }
47 msglvl = atoi(argv[1]) ;
48 msgFileName = argv[2] ;
49 if ( strcmp(msgFileName, "stdout") == 0 ) {
50    msgFile = stdout ;
51 } else if ( (msgFile = fopen(msgFileName, "a")) == NULL ) {
52    fprintf(stderr, "\n fatal error in %s"
53            "\n unable to open file %s\n",
54            argv[0], msgFileName) ;
55    return(-1) ;
56 }
57 inGraphFileName = argv[3] ;
58 freeze          = atof(argv[4]) ;
59 minweight       = atoi(argv[5]) ;
60 maxweight       = atoi(argv[6]) ;
61 seed            = atoi(argv[7]) ;
62 outIVfileName   = argv[8] ;
63 fprintf(msgFile,
64         "\n %s : "
65         "\n msglvl      -- %d"
66         "\n msgFile     -- %s"
67         "\n inGraphFile -- %s"
68         "\n freeze      -- %f"
69         "\n minweight   -- %d"
70         "\n maxweight   -- %d"
71         "\n seed        -- %d"
72         "\n outIVfile   -- %s"
73         "\n", argv[0], msglvl, msgFileName, inGraphFileName, freeze,
74         minweight, maxweight, seed, outIVfileName) ;
75 fflush(msgFile) ;
76 /*
77    ------------------------
78    read in the Graph object
79    ------------------------
80 */
81 if ( strcmp(inGraphFileName, "none") == 0 ) {
82    fprintf(msgFile, "\n no file to read from") ;
83    exit(0) ;
84 }
85 MARKTIME(t1) ;
86 graph = Graph_new() ;
87 Graph_setDefaultFields(graph) ;
88 if ( (rc = Graph_readFromFile(graph, inGraphFileName)) != 1 ) {
89    fprintf(msgFile, "\n return value %d from Graph_readFromFile(%p,%s)",
90         rc, graph, inGraphFileName) ;
91    exit(-1) ;
92 }
93 MARKTIME(t2) ;
94 fprintf(msgFile, "\n CPU %9.5f : read in graph from file %s",
95         t2 - t1, inGraphFileName) ;
96 nvtx = graph->nvtx ;
97 if ( msglvl < 4 ) {
98    Graph_writeStats(graph, msgFile) ;
99    fflush(msgFile) ;
100 } else {
101    Graph_writeForHumanEye(graph, msgFile) ;
102    fflush(msgFile) ;
103 }
104 /*
105    -----------------------
106    create the GPart object
107    -----------------------
108 */
109 MARKTIME(t1) ;
110 gpart = GPart_new() ;
111 GPart_init(gpart, graph) ;
112 GPart_setMessageInfo(gpart, msglvl, msgFile) ;
113 MARKTIME(t2) ;
114 /*
115    ---------------------------------------------
116    generate the domain decomposition via Fishnet
117    ---------------------------------------------
118 */
119 MARKTIME(t1) ;
120 GPart_DDviaFishnet(gpart, freeze, minweight, maxweight, seed) ;
121 MARKTIME(t2) ;
122 fprintf(msgFile, "\n CPU %9.5f : generate domain decomposition",
123         t2 - t1) ;
124 /*
125    -------------------------------------------
126    check that we have a valid vertex separator
127    -------------------------------------------
128 */
129 if ( 1 != GPart_validVtxSep(gpart) ) {
130    fprintf(msgFile, "\n\n WHOA : multisector is not valid\n\n") ;
131    fflush(msgFile) ;
132 }
133 /*
134    ----------------------------------
135    get the boundary weights IV object
136    ----------------------------------
137 */
138 if ( msglvl > 1 ) {
139    int   icomp, ncomp ;
140    int   *bnd, *cweights ;
141    IV    *bndIV ;
142 
143    bndIV = GPart_bndWeightsIV(gpart) ;
144    bnd = IV_entries(bndIV) ;
145    ncomp = gpart->ncomp ;
146    cweights = IV_entries(&gpart->cweightsIV) ;
147    fprintf(stdout,
148            "\n %% component id, component weight, boundary weight"
149            "\n data = [ ...") ;
150    for ( icomp = 0 ; icomp <= ncomp ; icomp++ ) {
151       fprintf(stdout, "\n %8d %8d %8d",
152               icomp, cweights[icomp], bnd[icomp]) ;
153    }
154    fprintf(stdout, " ] ") ;
155    IV_free(bndIV) ;
156 }
157 /*
158    ------------------------------------------
159    optionally write out the compids IV object
160    ------------------------------------------
161 */
162 if ( strcmp(outIVfileName, "none") != 0 ) {
163    IV_writeToFile(&gpart->compidsIV, outIVfileName) ;
164 }
165 /*
166    ------------------------
167    free the data structures
168    ------------------------
169 */
170 GPart_free(gpart) ;
171 Graph_free(graph) ;
172 
173 fclose(msgFile) ;
174 
175 return(1) ; }
176 
177 /*--------------------------------------------------------------------*/
178