All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scotchDecomp.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::scotchDecomp
26 
27 Description
28  Scotch domain decomposition.
29  When run in parallel will collect the whole graph on to the master,
30  decompose and send back. Use ptscotchDecomp for proper distributed
31  decomposition.
32 
33  Quoting from the Scotch forum, on the 2008-08-22 10:09, Francois
34  PELLEGRINI posted the following details:
35  \verbatim
36  RE: Graph mapping 'strategy' string
37 
38  Strategy handling in Scotch is a bit tricky. In order
39  not to be confused, you must have a clear view of how they are built.
40  Here are some rules:
41 
42  1- Strategies are made up of "methods" which are combined by means of
43  "operators".
44 
45  2- A method is of the form "m{param=value,param=value,...}", where "m"
46  is a single character (this is your first error: "f" is a method name,
47  not a parameter name).
48 
49  3- There exist different sort of strategies : bipartitioning strategies,
50  mapping strategies, ordering strategies, which cannot be mixed. For
51  instance, you cannot build a bipartitioning strategy and feed it to a
52  mapping method (this is your second error).
53 
54  To use the "mapCompute" routine, you must create a mapping strategy, not
55  a bipartitioning one, and so use stratGraphMap() and not
56  stratGraphBipart(). Your mapping strategy should however be based on the
57  "recursive bipartitioning" method ("b"). For instance, a simple (and
58  hence not very efficient) mapping strategy can be :
59 
60  "b{sep=f}"
61 
62  which computes mappings with the recursive bipartitioning method "b",
63  this latter using the Fiduccia-Mattheyses method "f" to compute its
64  separators.
65 
66  If you want an exact partition (see your previous post), try
67  "b{sep=fx}".
68 
69  However, these strategies are not the most efficient, as they do not
70  make use of the multi-level framework.
71 
72  To use the multi-level framework, try for instance:
73 
74  "b{sep=m{vert=100,low=h,asc=f}x}"
75 
76  The current default mapping strategy in Scotch can be seen by using the
77  "-vs" option of program gmap. It is, to date:
78 
79  r
80  {
81  job=t,
82  map=t,
83  poli=S,
84  sep=
85  (
86  m
87  {
88  asc=b
89  {
90  bnd=
91  (
92  d{pass=40,dif=1,rem=1}
93  |
94  )
95  f{move=80,pass=-1,bal=0.002491},
96  org=f{move=80,pass=-1,bal=0.002491},
97  width=3
98  },
99  low=h{pass=10}
100  f{move=80,pass=-1,bal=0.002491},
101  type=h,
102  vert=80,
103  rat=0.8
104  }
105  | m
106  {
107  asc=b
108  {
109  bnd=
110  (
111  d{pass=40,dif=1,rem=1}
112  |
113  )
114  f{move=80,pass=-1,bal=0.002491},
115  org=f{move=80,pass=-1,bal=0.002491},
116  width=3
117  },
118  low=h{pass=10}
119  f{move=80,pass=-1,bal=0.002491},
120  type=h,
121  vert=80,
122  rat=0.8
123  }
124  )
125  }
126  \endverbatim
127 
128  Given that this information was written in 2008, this example strategy will
129  unlikely work as-is with the more recent Scotch versions. Therefore, the
130  steps for getting the current default strategy from within Scotch, is to do
131  the following steps:
132 
133  <ol>
134  <li> Edit the file <tt>system/decomposeParDict</tt> and use the following
135  settings:
136 
137  \verbatim
138  method scotch;
139 
140  scotchCoeffs
141  {
142  writeGraph true;
143  }
144  \endverbatim
145  </li>
146 
147  <li> Run \c decomposePar. For example, it will write a file named
148  <tt>region0.grf</tt>.
149  </li>
150 
151  <li> Now, instead of using \c gmap, run \c gpart with the following
152  command structure to get the default strategy:
153 
154  \verbatim
155  gpart <nProcs> -vs <grfFile>
156  \endverbatim
157 
158  where:
159 
160  <ul>
161  <li> <grfFile> is the file that was obtained with the option
162  <tt>writeGraph=true</tt>, namely <tt>region0.grf</tt>.
163  </li>
164  <li> <nProcs> is the \c numberOfSubdomains defined in the dictionary
165  file.
166  </li>
167  </ul>
168  </li>
169 
170  <li> At the end of the execution will be shown a long string, similar to
171  the following example (complete line was cropped at <tt>[...]</tt>):
172 
173  \verbatim
174  S Strat=m{asc=b{width=3,bnd=d{pass=40,dif=1,rem=0}[...],type=h}
175  \endverbatim
176  </li>
177 
178  <li> Edit the file <tt>system/decomposeParDict</tt> once again and add
179  the \c strategy entry as exemplified:
180 
181  \verbatim
182  method scotch;
183 
184  scotchCoeffs
185  {
186  // writeGraph true;
187  strategy "m{asc=b{width=3,bnd=d{pass=40,dif=1,rem=0}[...],type=h}";
188  }
189  \endverbatim
190  </li>
191 
192  <li> Finally, run \c decomposePar once again, to at least test if it
193  works as intended.
194  </li>
195 
196  </ol>
197 
198 Note
199  \c gpart can be found in the current search path by adding the respective
200  \c bin folder from the Scotch installation, namely by running the following
201  commands:
202 
203  \verbatim
204  source $(foamEtcFile config.sh/scotch)
205  export PATH=$PATH:$SCOTCH_ARCH_PATH/bin
206  \endverbatim
207 
208 SourceFiles
209  scotchDecomp.C
210 
211 \*---------------------------------------------------------------------------*/
212 
213 #ifndef scotchDecomp_H
214 #define scotchDecomp_H
215 
216 #include "decompositionMethod.H"
217 
218 namespace Foam
219 {
220 
221 /*---------------------------------------------------------------------------*\
222  Class scotchDecomp Declaration
223 \*---------------------------------------------------------------------------*/
225 class scotchDecomp
226 :
227  public decompositionMethod
228 {
229  // Private Member Functions
230 
231  //- Check and print error message
232  static void check(const int, const char*);
233 
234  label decompose
235  (
236  const fileName& meshPath,
237  const List<label>& adjncy,
238  const List<label>& xadj,
239  const scalarField& cWeights,
240  List<label>& finalDecomp
241  );
242 
243  //- Decompose non-parallel
244  label decomposeOneProc
245  (
246  const fileName& meshPath,
247  const List<label>& adjncy,
248  const List<label>& xadj,
249  const scalarField& cWeights,
250  List<label>& finalDecomp
251  );
252 
253 
254 public:
255 
256  //- Runtime type information
257  TypeName("scotch");
258 
259 
260  // Constructors
261 
262  //- Construct given the decomposition dictionary and mesh
263  scotchDecomp(const dictionary& decompositionDict);
264 
265  //- Disallow default bitwise copy construction
266  scotchDecomp(const scotchDecomp&) = delete;
267 
268 
269  //- Destructor
270  virtual ~scotchDecomp()
271  {}
272 
273 
274  // Member Functions
276  virtual bool parallelAware() const
277  {
278  // Knows about coupled boundaries
279  return true;
280  }
281 
282  //- Inherit decompose from decompositionMethod
284 
285  //- Return for every coordinate the wanted processor number. Use the
286  // mesh connectivity (if needed)
287  // Weights get normalised with minimum weight and truncated to
288  // convert into integer so e.g. 3.5 is seen as 3. The overall sum
289  // of weights might otherwise overflow.
290  virtual labelList decompose
291  (
292  const polyMesh& mesh,
293  const pointField& points,
294  const scalarField& pointWeights
295  );
296 
297  //- Return for every coordinate the wanted processor number. Gets
298  // passed agglomeration map (from fine to coarse cells) and coarse cell
299  // location. Can be overridden by decomposers that provide this
300  // functionality natively.
301  // See note on weights above.
302  virtual labelList decompose
303  (
304  const polyMesh& mesh,
305  const labelList& agglom,
306  const pointField& regionPoints,
307  const scalarField& regionWeights
308  );
309 
310  //- Return for every coordinate the wanted processor number. Explicitly
311  // provided mesh connectivity.
312  // The connectivity is equal to mesh.cellCells() except for
313  // - in parallel the cell numbers are global cell numbers (starting
314  // from 0 at processor0 and then incrementing all through the
315  // processors)
316  // - the connections are across coupled patches
317  // See note on weights above.
318  virtual labelList decompose
319  (
320  const labelListList& globalCellCells,
321  const pointField& cc,
322  const scalarField& cWeights
323  );
324 
325 
326  // Member Operators
327 
328  //- Disallow default bitwise assignment
329  void operator=(const scotchDecomp&) = delete;
330 };
331 
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 } // End namespace Foam
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 #endif
340 
341 // ************************************************************************* //
virtual labelList decompose(const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number.
TypeName("scotch")
Runtime type information.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dynamicFvMesh & mesh
const pointField & points
virtual bool parallelAware() const
Is method parallel aware (i.e. does it synchronise domains across.
Definition: scotchDecomp.H:275
virtual ~scotchDecomp()
Destructor.
Definition: scotchDecomp.H:269
Abstract base class for decomposition.
scotchDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary and mesh.
void operator=(const scotchDecomp &)=delete
Disallow default bitwise assignment.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Scotch domain decomposition. When run in parallel will collect the whole graph on to the master...
Definition: scotchDecomp.H:224
Namespace for OpenFOAM.