MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
metiswrap.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbwrap/metiswrap.cc,v 1.24 2017/01/12 14:44:25 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 /* libreria per il calcolo delle partizioni */
35 #include <metis.h>
36 #undef ASSERT /* kill annoying redefiniton message */
37 #include "mynewmem.h"
38 
39 int
40 mbdyn_METIS_PartGraph(int iTotVertices,
41  int *pXadj,
42  int *pAdjncy,
43  int *pVertexWgts,
44  int *pCommWgts,
45  int *pEdgeWgts,
46  int DataCommSize,
47  int *pParAmgProcs)
48 {
49  /* required by METIS_PartGraphVKway API, but otherwise ignored */
50  /* 0: C-style numbering [0..n-1]; 1: F77-style numbering (1..n) */
51  int numflag = 0;
52  /* if options[0] == 0, the rest is ignored */
53  int options[5] = { 0 };
54  /* total communication volume */
55  int volume = 0;
56  /* weiht flags */
57  int wgtflag;
58 
59  idxtype *xadj = 0,
60  *adjncy = 0,
61  *vwgt = 0,
62  *adjwgt = 0,
63  *part = 0;
64 
65  if (sizeof(idxtype) == sizeof(int)) {
66  xadj = pXadj;
67  adjncy = pAdjncy;
68  vwgt = pVertexWgts;
69  adjwgt = pCommWgts;
70  part = pParAmgProcs;
71 
72  } else {
73  SAFENEWARR(xadj, idxtype, iTotVertices);
74  SAFENEWARR(adjncy, idxtype, pXadj[iTotVertices]);
75  if (pVertexWgts) {
76  SAFENEWARR(vwgt, idxtype, iTotVertices);
77  }
78  if (pCommWgts) {
79  SAFENEWARR(adjwgt, idxtype, pXadj[iTotVertices]);
80  }
81  SAFENEWARR(part, idxtype, iTotVertices);
82 
83  for (int i = 0; i < iTotVertices; i++) {
84  xadj[i] = pXadj[i];
85  part[i] = pParAmgProcs[i];
86  }
87 
88  if (pVertexWgts) {
89  for (int i = 0; i < iTotVertices; i++) {
90  vwgt[i] = pVertexWgts[i];
91  }
92  }
93 
94  for (int i = 0; i < pXadj[iTotVertices]; i++) {
95  adjncy[i] = pAdjncy[i];
96  }
97 
98  if (pCommWgts) {
99  for (int i = 0; i < pXadj[iTotVertices]; i++) {
100  adjwgt[i] = pCommWgts[i];
101  }
102  }
103  }
104 
105  if (pVertexWgts && pCommWgts) {
106  wgtflag = 3;
107  } else if (pVertexWgts) {
108  wgtflag = 2;
109  } else if (pCommWgts) {
110  wgtflag = 1;
111  } else {
112  wgtflag = 0;
113  }
114 
115  METIS_PartGraphVKway(&iTotVertices,
116  xadj,
117  adjncy,
118  vwgt,
119  adjwgt,
120  &wgtflag,
121  &numflag,
122  &DataCommSize,
123  options,
124  &volume,
125  part);
126 
127 
128  if (sizeof(idxtype) != sizeof(int)) {
129  for (int i = 0; i < iTotVertices; i++) {
130  pParAmgProcs[i] = part[i];
131  }
132 
133  SAFEDELETEARR(xadj);
134  SAFEDELETEARR(adjncy);
135 
136  if (pVertexWgts) {
137  SAFEDELETEARR(vwgt);
138  }
139 
140  if (pCommWgts) {
141  SAFEDELETEARR(adjwgt);
142  }
143 
144  SAFEDELETEARR(part);
145  }
146 
147  /* NOTE: the manual suggests to use
148  * METIS_PartGraphRecursive if DataCommSize < 8 */
149 
150  return 0;
151 }
152 
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
int mbdyn_METIS_PartGraph(int iTotVertices, int *pXadj, int *pAdjncy, int *pVertexWgts, int *pCommWgts, int *pEdgeWgts, int DataCommSize, int *pParAmgProcs)
Definition: metiswrap.cc:40
struct option options[]
Definition: ann_in.c:46
#define SAFENEWARR(pnt, item, sz)
Definition: mynewmem.h:701