| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "chaco.h" |
| 10 |
#include "defs.h" |
| 11 |
#include "params.h" |
| 12 |
#include "smalloc.h" |
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
int main(void) |
| 16 |
{ |
| 17 |
extern int Using_Main; /* is main routine being called? */ |
| 18 |
extern char *Graph_File_Name; /* name of graph input file */ |
| 19 |
extern char *Geometry_File_Name; /* name of coordinate input file */ |
| 20 |
extern char *Assign_In_File_Name; /* name of assignment input input file */ |
| 21 |
extern char *PARAMS_FILENAME; /* name of file with parameter updates */ |
| 22 |
extern double EIGEN_TOLERANCE; /* tolerance for eigen calculations */ |
| 23 |
extern int OUTPUT_ASSIGN; /* whether to write assignment to file */ |
| 24 |
extern int DEBUG_MEMORY; /* debug memory allocation and freeing? */ |
| 25 |
extern int DEBUG_TRACE; /* trace main execution path */ |
| 26 |
extern int DEBUG_PARAMS; /* debug flag for reading parameters */ |
| 27 |
extern long RANDOM_SEED; /* seed for random number generators */ |
| 28 |
extern int ECHO; /* controls amount of output */ |
| 29 |
extern int PROMPT; /* prompt for input or not? */ |
| 30 |
extern int PRINT_HEADERS; /* print lines for output sections? */ |
| 31 |
extern int MATCH_TYPE; /* matching routine to call */ |
| 32 |
extern double input_time; /* times data file input */ |
| 33 |
extern double start_time; /* time partitioning starts */ |
| 34 |
FILE *fin; /* input file */ |
| 35 |
FILE *fingeom; /* geometry input file (for inertial method) */ |
| 36 |
FILE *finassign; /* assignment file if reading in */ |
| 37 |
FILE *params_file; /* file with parameter value updates */ |
| 38 |
double *goal; /* desired set sizes */ |
| 39 |
float *x, *y, *z; /* coordinates for inertial method */ |
| 40 |
int *start; /* start of edge list for each vertex */ |
| 41 |
int *adjacency; /* edge list data */ |
| 42 |
float *ewgts; /* weights for all edges */ |
| 43 |
int *vwgts; /* weights for all vertices */ |
| 44 |
int global_method; /* global partitioning method */ |
| 45 |
int local_method; /* local partitioning method */ |
| 46 |
int *assignment; /* set number of each vtx (length nvtxs+1) */ |
| 47 |
double eigtol; /* tolerance in eigenvector calculation */ |
| 48 |
int nvtxs; /* number of vertices in graph */ |
| 49 |
int ndims; /* dimension of recursive partitioning */ |
| 50 |
int architecture; /* 0 => hypercube, d => d-dimensional mesh */ |
| 51 |
int ndims_tot; /* total number of cube dimensions to divide */ |
| 52 |
int mesh_dims[3]; /* dimensions of mesh of processors */ |
| 53 |
long seed; /* for random graph mutations */ |
| 54 |
int rqi_flag; /* use RQI/Symmlq eigensolver? */ |
| 55 |
int vmax; /* if so, how many vertices to coarsen down to? */ |
| 56 |
int igeom; /* geometry dimension if inertial method */ |
| 57 |
char graphname[NAME_LENGTH]; /* name of graph input file */ |
| 58 |
char geomname[NAME_LENGTH]; /* name of geometry input file */ |
| 59 |
char inassignname[NAME_LENGTH]; /* assignment input file name */ |
| 60 |
char outassignname[NAME_LENGTH]; /* assignment output file name */ |
| 61 |
char outfilename[NAME_LENGTH]; /* name of output file */ |
| 62 |
char *outassignptr; /* name or null pointer for output assignment */ |
| 63 |
char *outfileptr; /* name or null pointer for output file */ |
| 64 |
int another; /* run another problem? */ |
| 65 |
double time; /* timing marker */ |
| 66 |
int flag; /* return code from input routines */ |
| 67 |
double seconds(void); /* returns elapsed time in seconds */ |
| 68 |
int affirm(); |
| 69 |
int input_graph(), input_geom(); |
| 70 |
void input_queries(), read_params(), clear_timing(); |
| 71 |
|
| 72 |
/*malloc_debug(2);*/ |
| 73 |
|
| 74 |
if (DEBUG_TRACE > 0) { |
| 75 |
printf("<Entering main>\n"); |
| 76 |
} |
| 77 |
|
| 78 |
if (PRINT_HEADERS) { |
| 79 |
printf("\n Chaco 2.0\n"); |
| 80 |
printf(" Sandia National Laboratories\n\n"); |
| 81 |
} |
| 82 |
|
| 83 |
Using_Main = TRUE; |
| 84 |
another = TRUE; |
| 85 |
params_file = fopen(PARAMS_FILENAME, "r"); |
| 86 |
if (params_file == NULL && DEBUG_PARAMS > 1) { |
| 87 |
printf("Parameter file `%s' not found; using default parameters.\n", PARAMS_FILENAME); |
| 88 |
} |
| 89 |
|
| 90 |
while (another) { |
| 91 |
|
| 92 |
start_time = time = seconds(void); |
| 93 |
|
| 94 |
x = y = z = NULL; |
| 95 |
goal = NULL; |
| 96 |
assignment = NULL; |
| 97 |
|
| 98 |
read_params(params_file); |
| 99 |
|
| 100 |
input_queries(&fin, &fingeom, &finassign, graphname, geomname, inassignname, outassignname, |
| 101 |
outfilename, &architecture, &ndims_tot, mesh_dims, &global_method, &local_method, |
| 102 |
&rqi_flag, &vmax, &ndims); |
| 103 |
|
| 104 |
if (global_method == 7) |
| 105 |
Assign_In_File_Name = inassignname; |
| 106 |
else |
| 107 |
Assign_In_File_Name = NULL; |
| 108 |
|
| 109 |
if (OUTPUT_ASSIGN > 0) |
| 110 |
outassignptr = outassignname; |
| 111 |
else |
| 112 |
outassignptr = NULL; |
| 113 |
|
| 114 |
if (ECHO < 0) |
| 115 |
outfileptr = outfilename; |
| 116 |
else |
| 117 |
outfileptr = NULL; |
| 118 |
|
| 119 |
flag = input_graph(fin, graphname, &start, &adjacency, &nvtxs, &vwgts, &ewgts); |
| 120 |
if (flag) { |
| 121 |
sfree(ewgts); |
| 122 |
sfree(vwgts); |
| 123 |
sfree(adjacency); |
| 124 |
sfree(start); |
| 125 |
goto skip; |
| 126 |
} |
| 127 |
|
| 128 |
Graph_File_Name = graphname; |
| 129 |
|
| 130 |
assignment = smalloc(nvtxs * sizeof(int)); |
| 131 |
if (global_method == 7) { |
| 132 |
flag = input_assign(finassign, inassignname, nvtxs, assignment); |
| 133 |
if (flag) |
| 134 |
goto skip; |
| 135 |
Assign_In_File_Name = inassignname; |
| 136 |
} |
| 137 |
|
| 138 |
if (global_method == 3 || |
| 139 |
(MATCH_TYPE == 5 && (global_method == 1 || (global_method == 2 && rqi_flag)))) { |
| 140 |
/* Read in geometry data. */ |
| 141 |
flag = input_geom(fingeom, geomname, nvtxs, &igeom, &x, &y, &z); |
| 142 |
if (flag) |
| 143 |
goto skip; |
| 144 |
Geometry_File_Name = geomname; |
| 145 |
} |
| 146 |
else { |
| 147 |
x = y = z = NULL; |
| 148 |
} |
| 149 |
|
| 150 |
input_time += seconds() - time; |
| 151 |
|
| 152 |
eigtol = EIGEN_TOLERANCE; |
| 153 |
seed = RANDOM_SEED; |
| 154 |
|
| 155 |
INTER_FACE(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, outassignptr, outfileptr, assignment, |
| 156 |
architecture, ndims_tot, mesh_dims, goal, global_method, local_method, rqi_flag, |
| 157 |
vmax, ndims, eigtol, seed); |
| 158 |
|
| 159 |
skip: |
| 160 |
if (global_method == 3) { |
| 161 |
if (z != NULL) |
| 162 |
sfree(z); |
| 163 |
if (y != NULL) |
| 164 |
sfree(y); |
| 165 |
if (x != NULL) |
| 166 |
sfree(x); |
| 167 |
} |
| 168 |
sfree(assignment); |
| 169 |
|
| 170 |
if (DEBUG_MEMORY > 0) { |
| 171 |
printf("\n"); |
| 172 |
} |
| 173 |
|
| 174 |
if (PROMPT) { |
| 175 |
another = affirm("\nRun Another Problem"); |
| 176 |
} |
| 177 |
else { |
| 178 |
another = affirm(""); |
| 179 |
} |
| 180 |
if (another) { |
| 181 |
clear_timing(); |
| 182 |
printf("\n------------------------------------------------\n\n"); |
| 183 |
fflush(stdout); |
| 184 |
} |
| 185 |
} |
| 186 |
if (params_file != NULL) |
| 187 |
fclose(params_file); |
| 188 |
|
| 189 |
if (DEBUG_TRACE > 1) { |
| 190 |
printf("<Leaving main>\n"); |
| 191 |
} |
| 192 |
|
| 193 |
return (0); |
| 194 |
} |