Ice Sheet System Model  4.18
Code documentation
Functions
Chacox.cpp File Reference
#include "./Chacox.h"

Go to the source code of this file.

Functions

int Chacox (int nvtxs, int *start, int *adjacency, int *vwgts, float *ewgts, float *x, float *y, float *z, short *assignment, double options[10], int *nparts, double *goal)
 

Function Documentation

◆ Chacox()

int Chacox ( int  nvtxs,
int *  start,
int *  adjacency,
int *  vwgts,
float *  ewgts,
float *  x,
float *  y,
float *  z,
short *  assignment,
double  options[10],
int *  nparts,
double *  goal 
)

Definition at line 7 of file Chacox.cpp.

21 {
22  #ifdef _HAVE_CHACO_ //only works if Chaco library has been compiled in.
23 
24  extern int Using_Main; /* is main routine being called? */
25  extern char *PARAMS_FILENAME; /* name of file with parameter updates */
26  extern double EIGEN_TOLERANCE; /* tolerance for eigen calculations */
27  extern int OUTPUT_ASSIGN; /* whether to write assignment to file */
28  extern int DEBUG_MEMORY; /* debug memory allocation and freeing? */
29  extern int DEBUG_TRACE; /* trace main execution path */
30  extern int DEBUG_PARAMS; /* debug flag for reading parameters */
31  extern long RANDOM_SEED; /* seed for random number generators */
32  extern int ECHO; /* controls amount of output */
33  extern int PROMPT; /* prompt for input or not? */
34  extern int PRINT_HEADERS; /* print lines for output sections? */
35  extern int MATCH_TYPE; /* matching routine to call */
36  extern double input_time; /* times data file input */
37  extern double start_time; /* time partitioning starts */
38  FILE *params_file; /* file with parameter value updates */
39  int global_method; /* global partitioning method */
40  int local_method; /* local partitioning method */
41  double eigtol; /* tolerance in eigenvector calculation */
42  int ndims; /* dimension of recursive partitioning */
43  int architecture; /* 0 => hypercube, d => d-dimensional mesh */
44  int ndims_tot; /* total number of cube dimensions to divide */
45  int mesh_dims[3]; /* dimensions of mesh of processors */
46  long seed; /* for random graph mutations */
47  int rqi_flag; /* use RQI/Symmlq eigensolver? */
48  int vmax; /* if so, how many vertices to coarsen down to? */
49  char outassignname[NAME_LENGTH]; /* assignment output file name */
50  char outfilename[NAME_LENGTH]; /* name of output file */
51  char *outassignptr; /* name or null pointer for output assignment */
52  char *outfileptr; /* name or null pointer for output file */
53  int nprocs; /* number of processors being divided into */
54  double time; /* timing marker */
55  int flag; /* return code from input routines */
56  double *smalloc(); /* safe version of malloc */
57  //double seconds(); /* returns elapsed time in seconds */
58  /*int sfree(), interface(), affirm();
59  void input_queries() , smalloc_stats(), read_params(), clear_timing(); */
60 
61  int i,tvwgt;
62  double tgoal;
63 
64  if (DEBUG_TRACE > 0) {
65  _printf_("<Entering main>\n");
66  }
67 
68  if (PRINT_HEADERS) {
69  _printf_("\n Chaco 2.0\n");
70  _printf_(" Sandia National Laboratories\n\n");
71  }
72 
73  Using_Main = TRUE;
74  params_file = fopen(PARAMS_FILENAME, "r");
75  if (params_file == NULL && DEBUG_PARAMS > 1) {
76  printf("Parameter file `%s' not found; using default parameters.\n",PARAMS_FILENAME);
77  }
78 
79  start_time = time = chaco_seconds();
80 
81  read_params(params_file);
82 
83  flag = input_parse(outassignname, outfilename,
84  &architecture, &ndims_tot, mesh_dims,
85  &global_method, &local_method, &rqi_flag, &vmax, &ndims, &nprocs,
86  options, nparts);
87  if (flag)
88  return(flag);
89 
90  if (OUTPUT_ASSIGN > 0)
91  outassignptr = outassignname;
92  else
93  outassignptr = NULL;
94 
95  if (ECHO < 0)
96  outfileptr = outfilename;
97  else
98  outfileptr = NULL;
99 
100  if ((int)options[OPT_VWGTS] && vwgts) {
101  printf("%s -- Applying weights for %d vertices.\n",__FUNCT__,nvtxs);
102  tvwgt = 0;
103  for (i=0; i<nvtxs; i++)
104  tvwgt += vwgts[i];
105  }
106  else {
107  tvwgt = nvtxs;
108  if ( (int)options[OPT_VWGTS] && !vwgts)
109  printf("%s -- Vertex weight flag=%d, but no vertex weights specified.\n",__FUNCT__,(int)options[OPT_VWGTS]);
110  else if (!(int)options[OPT_VWGTS] && vwgts)
111  printf("%s -- Vertex weight flag=%d, so specified vertex weights ignored.\n",__FUNCT__,(int)options[OPT_VWGTS]);
112  }
113 
114  if ((int)options[OPT_EWGTS] && ewgts) {
115  printf("%s -- Applying weights for %d edges.\n",
116  __FUNCT__,start[nvtxs]/2);
117  }
118  else {
119  if ( (int)options[OPT_EWGTS] && !ewgts)
120  printf("%s -- Edge weight flag=%d, but no edge weights specified.\n",__FUNCT__,(int)options[OPT_EWGTS]);
121  else if (!(int)options[OPT_EWGTS] && ewgts)
122  printf("%s -- Edge weight flag=%d, so specified edge weights ignored.\n",__FUNCT__,(int)options[OPT_EWGTS]);
123  }
124 
125  if (goal) {
126  printf("%s -- Applying goals for %d sets.\n",
127  __FUNCT__,nprocs);
128  tgoal = 0.;
129  for (i=0; i<nprocs; i++)
130  tgoal += goal[i];
131  for (i=0; i<nprocs; i++)
132  goal[i] *= (double)tvwgt/tgoal;
133  }
134 
135  input_time += chaco_seconds() - time;
136 
137  if (options[OPT_EIGTOL] > 0)
138  eigtol = options[OPT_EIGTOL];
139  else
140  eigtol = EIGEN_TOLERANCE;
141  if ((int)options[OPT_SEED] > 0)
142  seed = (int)options[OPT_SEED];
143  else
144  seed = RANDOM_SEED;
145 
146 /* Chaco numbers vertices from 1 and the Matlab sparse data structure
147  numbers rows from 0, so increment the row indices for each column. */
148 
149  for (i=0; i<start[nvtxs]; adjacency[i++]++);
150 
151  printf("\n%s -- Calling Chaco interface:\n\n",__FUNCT__);
152  flag = interface(nvtxs, start, adjacency,
153  ((int)options[OPT_VWGTS] && vwgts ? vwgts : NULL),
154  ((int)options[OPT_EWGTS] && ewgts ? ewgts : NULL),
155  x, y, z,
156  outassignptr, outfileptr,
157  assignment,
158  architecture, ndims_tot, mesh_dims, goal,
159  global_method, local_method, rqi_flag, vmax, ndims,
160  eigtol, seed);
161  printf("\n%s -- Chaco interface returning flag=%d.\n",__FUNCT__,flag);
162 
163 /* Reset adjacency matrix in case calling function needs it. */
164 
165  for (i=0; i<start[nvtxs]; adjacency[i++]--);
166 
167  if (DEBUG_MEMORY > 0) {
168  _printf_("\n");
169  smalloc_stats();
170  }
171 
172  if (params_file != NULL)
173  fclose(params_file);
174 
175  if (DEBUG_TRACE > 1) {
176  _printf_("<Leaving main>\n");
177  }
178 
179  return(0);
180 
181  #else //ifdef _HAVE_CHACO_
182  return (0);
183  #endif
184 }
chaco_seconds
double chaco_seconds(void)
Definition: chaco_seconds.cpp:10
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
input_parse
int input_parse(char *outassignname, char *outfilename, int *architecture, int *ndims_tot, int mesh_dims[3], int *global_method, int *local_method, int *rqi_flag, int *vmax, int *ndims, int *nprocs, double options[10], int *nparts)
Definition: input_parse.cpp:10
__FUNCT__
#define __FUNCT__
Definition: Chacox.h:43