Ice Sheet System Model  4.18
Code documentation
Macros | Functions
Chacox.h File Reference
#include <stdio.h>
#include <string.h>
#include "../../classes/classes.h"

Go to the source code of this file.

Macros

#define __FUNCT__   "Chacox"
 

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)
 
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)
 
double chaco_seconds (void)
 

Macro Definition Documentation

◆ __FUNCT__

#define __FUNCT__   "Chacox"

Definition at line 43 of file Chacox.h.

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 }

◆ 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 at line 10 of file input_parse.cpp.

25 {
26 
27  #ifdef _HAVE_CHACO_ //only works if Chaco library has been compiled in.
28 
29  extern int SEQUENCE; /* sequence instead of partition graph? */
30  extern int ARCHITECTURE; /* 0=> hypercube, d=> d-dimensional mesh */
31  extern int OUTPUT_ASSIGN; /* write assignments to file? */
32  extern int ECHO; /* copy input to screen? results to file? */
33  extern int DEBUG_TRACE; /* trace main execution path */
34  extern int PROMPT; /* prompt for input? */
35  extern int MATCH_TYPE; /* max-matching routine to call */
36  int eigensolver; /* which kind of eigensolver to use */
37 
38  if (DEBUG_TRACE > 0) {
39  _printf_("<Entering input_parse>\n");
40  }
41 
42  if (PROMPT) {
43  _printf_("Parallel machine architecture:\n");
44  _printf_(" (0) Hypercube\n");
45  _printf_(" (1) One-dimensional mesh\n");
46  _printf_(" (2) Two-dimensional mesh\n");
47  _printf_(" (3) Three-dimensional mesh\n");
48  }
49  *architecture = (int)options[OPT_ARCH];
50  if (*architecture < 0 || *architecture > 3) {
51  printf("%s -- Architecture %d must be between 0 and 3.\n",__FUNCT__,*architecture);
52  return(-1);
53  }
54 
55  /* Name output assignment file. */
56  if (PROMPT)
57  _printf_("Assignment output file: ");
58  outassignname = NULL;
59 
60  /* Name output results file. */
61  if (PROMPT)
62  _printf_("File name for saving run results: ");
63  outfilename = NULL;
64 
65  /* Initialize the method flags */
66  *rqi_flag = 0;
67  *global_method = 0;
68 
69  /* Get global method, if any. */
70  if (SEQUENCE) {
71  *global_method = 2;
72  }
73  else {
74  if (PROMPT) {
75  _printf_("Global partitioning method:\n");
76  _printf_(" (1) Multilevel-KL\n");
77  _printf_(" (2) Spectral\n");
78  _printf_(" (3) Inertial\n");
79  _printf_(" (4) Linear\n");
80  _printf_(" (5) Random\n");
81  _printf_(" (6) Scattered\n");
82  _printf_(" (7) Read-from-file\n");
83  }
84  *global_method = (int)options[OPT_GLOBAL];
85  if (*global_method < 1 || *global_method > 7) {
86  printf("%s -- Global method %d must be between 1 and 7.\n",__FUNCT__,*global_method);
87  return(-1);
88  }
89  }
90 
91  if (*global_method == 7) { /* Name and open input assignment file. */
92  if (PROMPT)
93  _printf_("Assignment input file: ");
94  }
95 
96  else if (*global_method == 3) {
97  if (PROMPT)
98  _printf_("Geometry input file name: ");
99  }
100 
101  else if (*global_method == 2) {
102  if (PROMPT) {
103  _printf_("Eigensolver:\n");
104  _printf_(" (1) Multilevel RQI/Symmlq\n");
105  _printf_(" (2) Lanczos\n");
106  }
107  eigensolver = (int)options[OPT_RQI];
108  if (eigensolver < 0 || eigensolver > 2) {
109  printf("%s -- RQI/Symmlq flag %d must be between 0 and 2.\n",__FUNCT__,eigensolver);
110  return(-1);
111  }
112  if (eigensolver == 1) {
113  if (MATCH_TYPE == 5) { /* geometric matching */
114  if (PROMPT)
115  _printf_("Geometry input file name: ");
116  }
117  *rqi_flag = 1;
118  if (PROMPT)
119  _printf_("Number of vertices to coarsen down to: ");
120  *vmax = (int)options[OPT_VMAX];
121  if (*vmax <= 0) {
122  printf("%s -- Vmax %d must be greater then 0.\n",__FUNCT__,*vmax);
123  return(-1);
124  }
125  }
126  else if (eigensolver == 0 || eigensolver == 2) {
127  *rqi_flag = 0;
128  }
129  }
130 
131  else if (*global_method == 1) {
132  if (MATCH_TYPE == 5) { /* geometric matching */
133  if (PROMPT)
134  _printf_("Geometry input file name: ");
135  }
136  if (PROMPT)
137  _printf_("Number of vertices to coarsen down to: ");
138  *vmax = (int)options[OPT_VMAX];
139  if (*vmax <= 0) {
140  printf("%s -- Vmax %d must be greater then 0.\n",__FUNCT__,*vmax);
141  return(-1);
142  }
143  }
144 
145  if (SEQUENCE) {
146  *local_method = 2;
147  if (*architecture == 0) {
148  *ndims_tot = 1;
149  }
150  else if (*architecture > 0) {
151  mesh_dims[0] = 2;
152  mesh_dims[1] = mesh_dims[2] = 1;
153  }
154  *ndims = 1;
155  goto End_Label;
156  }
157 
158  /* Get local method, if any */
159  *local_method = 0;
160  if (*global_method == 1)
161  *local_method = 1;
162  else {
163  if (PROMPT) {
164  _printf_("Local refinement method:\n");
165  _printf_(" (1) Kernighan-Lin\n");
166  _printf_(" (2) None\n");
167  }
168  *local_method = (int)options[OPT_LOCAL];
169  if (*local_method < 1 || *local_method > 2) {
170  printf("%s -- Local method %d must be 1 and 2.\n",__FUNCT__,*local_method);
171  return(-1);
172  }
173  }
174 
175  /* Now learn about the parallel architecture. */
176  if (*architecture == 0) {
177  /* Get total number of hypercube dimensions in which to partition. */
178  *ndims_tot = 0;
179  if (PROMPT)
180  _printf_("Total number of target hypercube dimensions: ");
181  *ndims_tot = nparts[0];
182  if (*ndims_tot < 1) {
183  _printf_(" Number of divisions must be at least 1\n");
184  printf("%s -- Number of divisions %d must be at least 1.\n",
185  __FUNCT__,nparts[0]);
186  return(-1);
187  }
188  *nprocs = 1 << (*ndims_tot);
189  }
190 
191  else { /* Get dimensions of mesh. */
192  mesh_dims[1] = mesh_dims[2] = 1;
193  if (*architecture == 2) {
194  if (PROMPT)
195  _printf_("X and Y extent of of 2-D mesh: ");
196  mesh_dims[0] = nparts[0];
197  mesh_dims[1] = nparts[1];
198  }
199  else if (*architecture == 3) {
200  if (PROMPT)
201  _printf_("X, Y and Z extent of 3-D mesh: ");
202  mesh_dims[0] = nparts[0];
203  mesh_dims[1] = nparts[1];
204  mesh_dims[2] = nparts[2];
205  }
206  else { /* Anything else => 1-D mesh */
207  if (PROMPT)
208  _printf_("Size of 1-D mesh: ");
209  mesh_dims[0] = nparts[0];
210  *architecture = 1;
211  }
212  *nprocs = mesh_dims[0] * mesh_dims[1] * mesh_dims[2];
213  }
214 
215  /* Get number of dimensions in which to partition at each level. */
216  *ndims = 0;
217  if (*nprocs <= 3) {
218  *ndims = 1;
219  }
220  else if (*nprocs <= 7) {
221  if (PROMPT) {
222  _printf_("Partitioning dimension: \n");
223  _printf_(" (1) Bisection\n");
224  _printf_(" (2) Quadrisection\n");
225  }
226  *ndims = (int)options[OPT_NDIMS];
227  if (*ndims < 1 || *ndims > 2) {
228  printf("%s -- Ndims %d must be 1 or 2 for %d processors.\n",__FUNCT__,*ndims,*nprocs);
229  return(-1);
230  }
231  }
232  else {
233  if (PROMPT) {
234  _printf_("Partitioning dimension: \n");
235  _printf_(" (1) Bisection\n");
236  _printf_(" (2) Quadrisection\n");
237  _printf_(" (3) Octasection\n");
238  }
239  *ndims = (int)options[OPT_NDIMS];
240  if (*ndims < 1 || *ndims > 3) {
241  printf("%s -- Ndims %d must be between 1 and 3 for %d processors.\n",__FUNCT__,*ndims,*nprocs);
242  return(-1);
243  }
244  }
245 End_Label:
246 
247  if (*global_method == 1 || *rqi_flag) {
248  if (*vmax < 2 * (1 << *ndims)) {
249  *vmax = 2 * (1 << *ndims);
250  }
251  }
252 
253  return(0);
254 
255  #else //#ifdef _HAVE_CHACO_
256  return(0);
257  #endif
258 }

◆ chaco_seconds()

double chaco_seconds ( void  )

Definition at line 10 of file chaco_seconds.cpp.

10  {
11 
12  double curtime;
13 
14 #ifdef RUSAGE_SELF
15 
16 /* This timer is faster and more robust (if it exists). */
17  struct rusage rusage;
18  /*int getrusage(); commenting this out. not sure why it's there anymore
19  *as it clobbers the prototype int getrusag(int target,rusage* results) which
20  *is defined in the <sys/time.h> and <sys/resource.h> header files. Leaving it
21  *for reference in case we have a problem here in the future*/
22 
23  getrusage(RUSAGE_SELF, &rusage);
24  curtime = ((rusage.ru_utime.tv_sec + rusage.ru_stime.tv_sec) +
25  1.0e-6 * (rusage.ru_utime.tv_usec + rusage.ru_stime.tv_usec));
26 
27 #else
28 
29 /* ANSI timer, but lower resolution & wraps around after ~36 minutes. */
30 
31  curtime = clock()/((double) CLOCKS_PER_SEC);
32 
33 #endif
34 
35  return (curtime);
36 }
chaco_seconds
double chaco_seconds(void)
Definition: chaco_seconds.cpp:10
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
__FUNCT__
#define __FUNCT__
Definition: input_parse.cpp:8
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