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-2022 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
200  respective \c bin folder from the Scotch installation, namely by running
201  the following commands:
202  \verbatim
203  source $(foamEtcFile config.sh/scotch)
204  export PATH=$PATH:$SCOTCH_ARCH_PATH/bin
205  \endverbatim
206 
207 SourceFiles
208  scotchDecomp.C
209 
210 \*---------------------------------------------------------------------------*/
211 
212 #ifndef scotchDecomp_H
213 #define scotchDecomp_H
214 
215 #include "decompositionMethod.H"
216 
217 namespace Foam
218 {
219 
220 /*---------------------------------------------------------------------------*\
221  Class scotchDecomp Declaration
222 \*---------------------------------------------------------------------------*/
224 class scotchDecomp
225 :
226  public decompositionMethod
227 {
228  // Private Member Functions
229 
230  //- Check and print error message
231  static void check(const int, const char*);
232 
233  label decompose
234  (
235  const fileName& meshPath,
236  const List<label>& adjncy,
237  const List<label>& xadj,
238  const scalarField& cWeights,
239  List<label>& finalDecomp
240  );
241 
242  //- Decompose non-parallel
243  label decomposeOneProc
244  (
245  const fileName& meshPath,
246  const List<label>& adjncy,
247  const List<label>& xadj,
248  const scalarField& cWeights,
249  List<label>& finalDecomp
250  );
251 
252 
253 public:
254 
255  //- Runtime type information
256  TypeName("scotch");
257 
258 
259  // Constructors
260 
261  //- Construct given the decomposition dictionary and mesh
262  scotchDecomp(const dictionary& decompositionDict);
263 
264  //- Disallow default bitwise copy construction
265  scotchDecomp(const scotchDecomp&) = delete;
266 
267 
268  //- Destructor
269  virtual ~scotchDecomp()
270  {}
271 
272 
273  // Member Functions
274 
275  //- Inherit decompose from decompositionMethod
277 
278  //- Return for every coordinate the wanted processor number. Use the
279  // mesh connectivity (if needed)
280  // Weights get normalised with minimum weight and truncated to
281  // convert into integer so e.g. 3.5 is seen as 3. The overall sum
282  // of weights might otherwise overflow.
283  virtual labelList decompose
284  (
285  const polyMesh& mesh,
286  const pointField& points,
287  const scalarField& pointWeights
288  );
289 
290  //- Return for every coordinate the wanted processor number. Gets
291  // passed agglomeration map (from fine to coarse cells) and coarse cell
292  // location. Can be overridden by decomposers that provide this
293  // functionality natively.
294  // See note on weights above.
295  virtual labelList decompose
296  (
297  const polyMesh& mesh,
298  const labelList& agglom,
299  const pointField& regionPoints,
300  const scalarField& regionWeights
301  );
302 
303  //- Return for every coordinate the wanted processor number. Explicitly
304  // provided mesh connectivity.
305  // The connectivity is equal to mesh.cellCells() except for
306  // - in parallel the cell numbers are global cell numbers (starting
307  // from 0 at processor0 and then incrementing all through the
308  // processors)
309  // - the connections are across coupled patches
310  // See note on weights above.
311  virtual labelList decompose
312  (
313  const labelListList& globalCellCells,
314  const pointField& cc,
315  const scalarField& cWeights
316  );
317 
318 
319  // Member Operators
320 
321  //- Disallow default bitwise assignment
322  void operator=(const scotchDecomp&) = delete;
323 };
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace Foam
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #endif
333 
334 // ************************************************************************* //
virtual labelList decompose(const pointField &points, const scalarField &pointWeights)
Return for every coordinate the wanted processor number.
TypeName("scotch")
Runtime type information.
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
fvMesh & mesh
const pointField & points
virtual ~scotchDecomp()
Destructor.
Definition: scotchDecomp.H:268
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:76
Scotch domain decomposition. When run in parallel will collect the whole graph on to the master...
Definition: scotchDecomp.H:223
Namespace for OpenFOAM.