MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
chacowrap.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/chacowrap.cc,v 1.8 2011/05/19 11:24:38 masarati Exp $ */
2 /* A simple interface to the Chaco graph partioning library. It does
3  * some small conversions so that it is easy to substitute for Metis.
4  *
5  * MBDyn (C) is a multibody analysis code.
6  * http://www.mbdyn.org
7  *
8  * Copyright (C) 2003 Mississippi State University
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation (version 2 of the License).
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
25 
26 #include <vector>
27 #include <iostream>
28 
29 #include "chacowrap.h"
30 
31 extern "C" {
32 /*
33  * NOTE: the name "interface" has been reported (by Patrick Rix)
34  * to cause issues with gcc 4.10
35  */
36 int interface(
37  int nvtxs, /* number of vertices in full graph */
38  int *start, /* start of edge list for each vertex */
39  int *adjacency, /* edge list data */
40  int *vwgts, /* weights for all vertices */
41  float *ewgts, /* weights for all edges */
42  float *x, float *y, float *z,/* coordinates for inertial method */
43  char *outassignname, /* name of assignment output file */
44  char *outfilename, /* output file name */
45  short *assignment, /* set number of each vtx (length n) */
46  int architecture, /* 0 => hypercube, d => d-dimensional mesh */
47  int ndims_tot, /* total number of cube dimensions to divide */
48  int mesh_dims[3], /* dimensions of mesh of processors */
49  double *goal, /* desired set sizes for each set */
50  int global_method, /* global partitioning algorithm */
51  int local_method, /* local partitioning algorithm */
52  int rqi_flag, /* should I use RQI/Symmlq eigensolver? */
53  int vmax, /* how many vertices to coarsen down to? */
54  int ndims, /* number of eigenvectors (2^d sets) */
55  double eigtol, /* tolerance on eigenvectors */
56  long seed /* for random graph mutations */
57  );
58 }
59 
60 extern "C" int FREE_GRAPH;
61 
62 void
64  const int iTotVertices,
65  int *start,
66  int *adjacency,
67  int *vertex_weights,
68  int *comm_weights, /* unsupported */
69  int *edge_weights,
70  const int num_processors,
71  int *pParAmgProcs
72  )
73 {
74  std::vector<short> set_assignment(iTotVertices);
75 
76  const int architecture(1), /* The computers are connected as a
77  * simple one-dimensional mesh
78  * 0 => hypercube, d => d-dimensional mesh */
79  global_method(2), /* Use Spectral decomposition */
80  local_method(1), /* With KL local refinement */
81  rqi_flag(0), /* Use Lanczos for solving the
82  * eigenvalue problem for spectral
83  * decomposition */
84  vmax(100), /* When to stop coarsening. Not used */
85  seed(7654321); /* A random number seed */
86  int mesh_dims[] = { /* if architecture > 0, mesh size goes here */
87  num_processors, 1, 1
88  };
89  double eigtol(1.e-3); /* */
90 
91  /* Chaco vertices are base 1 */
92  for (int i = 0; i < start[iTotVertices]; i++) {
93  adjacency[i]++;
94  }
95 
96  /* weights = 0 are not allowed */
97  std::vector<int> ivertex_weights(iTotVertices);
98  if (vertex_weights) {
99  for (int i = 0; i < iTotVertices; i++) {
100  /* trying to emulate communication weights? */
101  if (comm_weights) {
102  vertex_weights[i] += comm_weights[i];
103  }
104 
105  if (vertex_weights[i] == 0) {
106  ivertex_weights[i] = 1;
107  } else {
108  ivertex_weights[i] = vertex_weights[i];
109  }
110  }
111  }
112 
113  /* Chaco uses floats for the communication weights */
114  std::vector<float> fedge_weights(2*start[iTotVertices]);
115  if (edge_weights) {
116  for (int i = 0; i < iTotVertices; i++) {
117  fedge_weights[i] = edge_weights[i];
118  fedge_weights[start[iTotVertices] + i] = edge_weights[i];
119  }
120  }
121 
122  /* NOTE: don't free() adjacency !!! (default in Chaco 2.2) */
123  if (FREE_GRAPH) {
124  FREE_GRAPH = 0;
125  }
126 
127  int rc = interface(
128  iTotVertices, /* number of vertices in full graph */
129  start, /* start of edge list for each vertex */
130  adjacency, /* edge list data */
131  vertex_weights ? &ivertex_weights[0] : 0, /* weights for all vertices */
132  edge_weights ? &fedge_weights[0] : 0, /* weights for all edges */
133  NULL, /* coordinates for inertial method */
134  NULL, /* ... */
135  NULL, /* ... */
136  NULL, /* name of assignment output file */
137  NULL, /* output file name */
138  &set_assignment[0], /* set number of each vtx (length n) */
139  architecture, /* 0 => hypercube, d => d-dimensional mesh */
140  num_processors, /* total number of cube dimensions to divide */
141  mesh_dims, /* dimensions of mesh of processors */
142  NULL, /* desired set sizes for each set */
143  global_method, /* global partitioning algorithm */
144  local_method, /* local partitioning algorithm */
145  rqi_flag, /* should I use RQI/Symmlq eigensolver? */
146  vmax, /* how many vertices to coarsen down to? */
147  1, /* number of eigenvectors (2^d sets) */
148  eigtol, /* tolerance on eigenvectors */
149  seed /* for random graph mutations */
150  );
151 
152  /* Chaco vertices are base 1 */
153  for (int i = 0; i < start[iTotVertices]; i++) {
154  adjacency[i]--;
155  }
156 
157  if (rc != 0) {
158  silent_cerr("chaco_interface(): partition failed" << std::endl);
159  }
160 
161  for (int i = 0; i < iTotVertices; i++) {
162  pParAmgProcs[i] = set_assignment[i];
163  }
164 }
165 
int interface(int nvtxs, int *start, int *adjacency, int *vwgts, float *ewgts, float *x, float *y, float *z, char *outassignname, char *outfilename, short *assignment, int architecture, int ndims_tot, int mesh_dims[3], double *goal, int global_method, int local_method, int rqi_flag, int vmax, int ndims, double eigtol, long seed)
int FREE_GRAPH
Definition: chacowrap.cc:60
void chaco_interface(const int iTotVertices, int *start, int *adjacency, int *vertex_weights, int *comm_weights, int *edge_weights, const int num_processors, int *pParAmgProcs)
Definition: chacowrap.cc:63