scotchDecomp.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::scotchDecomp
29 
30 Description
31  Scotch domain decomposition.
32 
33  When run in parallel will collect the whole graph on to the master,
34  decompose and send back. Use ptscotchDecomp for proper distributed
35  decomposition.
36 
37  Coefficients dictionary: \a scotchCoeffs, \a coeffs.
38 
39  Quoting from the Scotch forum, on the 2008-08-22 10:09, Francois
40  PELLEGRINI posted the following details:
41  \verbatim
42  RE: Graph mapping 'strategy' string
43 
44  Strategy handling in Scotch is a bit tricky. In order
45  not to be confused, you must have a clear view of how they are built.
46  Here are some rules:
47 
48  1- Strategies are made up of "methods" which are combined by means of
49  "operators".
50 
51  2- A method is of the form "m{param=value,param=value,...}", where "m"
52  is a single character (this is your first error: "f" is a method name,
53  not a parameter name).
54 
55  3- There exist different sort of strategies : bipartitioning strategies,
56  mapping strategies, ordering strategies, which cannot be mixed. For
57  instance, you cannot build a bipartitioning strategy and feed it to a
58  mapping method (this is your second error).
59 
60  To use the "mapCompute" routine, you must create a mapping strategy, not
61  a bipartitioning one, and so use stratGraphMap() and not
62  stratGraphBipart(). Your mapping strategy should however be based on the
63  "recursive bipartitioning" method ("b"). For instance, a simple (and
64  hence not very efficient) mapping strategy can be :
65 
66  "b{sep=f}"
67 
68  which computes mappings with the recursive bipartitioning method "b",
69  this latter using the Fiduccia-Mattheyses method "f" to compute its
70  separators.
71 
72  If you want an exact partition (see your previous post), try
73  "b{sep=fx}".
74 
75  However, these strategies are not the most efficient, as they do not
76  make use of the multi-level framework.
77 
78  To use the multi-level framework, try for instance:
79 
80  "b{sep=m{vert=100,low=h,asc=f}x}"
81 
82  The current default mapping strategy in Scotch can be seen by using the
83  "-vs" option of program gmap. It is, to date:
84 
85  r
86  {
87  job=t,
88  map=t,
89  poli=S,
90  sep=
91  (
92  m
93  {
94  asc=b
95  {
96  bnd=
97  (
98  d{pass=40,dif=1,rem=1}
99  |
100  )
101  f{move=80,pass=-1,bal=0.002491},
102  org=f{move=80,pass=-1,bal=0.002491},
103  width=3
104  },
105  low=h{pass=10}
106  f{move=80,pass=-1,bal=0.002491},
107  type=h,
108  vert=80,
109  rat=0.8
110  }
111  | m
112  {
113  asc=b
114  {
115  bnd=
116  (
117  d{pass=40,dif=1,rem=1}
118  |
119  )
120  f{move=80,pass=-1,bal=0.002491},
121  org=f{move=80,pass=-1,bal=0.002491},
122  width=3
123  },
124  low=h{pass=10}
125  f{move=80,pass=-1,bal=0.002491},
126  type=h,
127  vert=80,
128  rat=0.8
129  }
130  )
131  }
132  \endverbatim
133 
134  Given that this information was written in 2008, this example strategy will
135  unlikely work as-is with the more recent Scotch versions. Therefore, the
136  steps for getting the current default strategy from within Scotch, is to do
137  the following steps:
138 
139  <ol>
140  <li> Edit the file <tt>system/decomposeParDict</tt> and use the following
141  settings:
142 
143  \verbatim
144  method scotch;
145 
146  scotchCoeffs
147  {
148  writeGraph true;
149  }
150  \endverbatim
151  </li>
152 
153  <li> Run \c decomposePar. For example, it will write a file named
154  <tt>region0.grf</tt>.
155  </li>
156 
157  <li> Now, instead of using \c gmap, run \c gpart with the following
158  command structure to get the default strategy:
159 
160  \verbatim
161  gpart <nProcs> -vs <grfFile>
162  \endverbatim
163 
164  where:
165 
166  <ul>
167  <li> <grfFile> is the file that was obtained with the option
168  <tt>writeGraph=true</tt>, namely <tt>region0.grf</tt>.
169  </li>
170  <li> <nProcs> is the \c numberOfSubdomains defined in the dictionary
171  file.
172  </li>
173  </ul>
174  </li>
175 
176  <li> At the end of the execution will be shown a long string, similar to
177  the following example (complete line was cropped at <tt>[...]</tt>):
178 
179  \verbatim
180  S Strat=m{asc=b{width=3,bnd=d{pass=40,dif=1,rem=0}[...],type=h}
181  \endverbatim
182  </li>
183 
184  <li> Edit the file <tt>system/decomposeParDict</tt> once again and add
185  the \c strategy entry as exemplified:
186 
187  \verbatim
188  method scotch;
189 
190  scotchCoeffs
191  {
192  //writeGraph true;
193  strategy "m{asc=b{width=3,bnd=d{pass=40,dif=1,rem=0}[...],type=h}";
194  }
195  \endverbatim
196  </li>
197 
198  <li> Finally, run \c decomposePar once again, to at least test if it
199  works as intended.
200  </li>
201 
202  </ol>
203 
204 
205  Also support for multi-level decomposition by specifying inter-level
206  communication weights:
207 
208  \verbatim
209  numberOfSubdomains 2048;
210  coeffs
211  {
212  // Divide into 64 clusters, each of 32 cores
213  domains (64 32);
214  // Inside a cluster the communication weight is 1% of that inbetween
215  // clusters
216  domainWeights (1 0.01);
217  }
218  \endverbatim
219 
220  Alternatively the first-level decomposition can be left out by assuming
221  weights are 1 for that level:
222 
223  \verbatim
224  numberOfSubdomains 2048;
225  coeffs
226  {
227  // Divide into 2048/32 clusters
228  domains (32);
229  // Inside a cluster the communication weight is 1% of that inbetween
230  // clusters
231  domainWeights (0.01);
232  }
233  \endverbatim
234 
235 
236 
237 Note
238  \c gpart can be found in the current search path by adding the respective
239  \c bin folder from the Scotch installation, namely by running the following
240  commands:
241 
242  \verbatim
243  source $(foamEtcFile config.sh/scotch)
244  export PATH=$PATH:$SCOTCH_ARCH_PATH/bin
245  \endverbatim
246 
247 SourceFiles
248  scotchDecomp.C
249 
250 \*---------------------------------------------------------------------------*/
251 
252 #ifndef Foam_scotchDecomp_H
253 #define Foam_scotchDecomp_H
254 
255 #include "metisLikeDecomp.H"
256 
257 namespace Foam
258 {
260 /*---------------------------------------------------------------------------*\
261  Class scotchDecomp Declaration
262 \*---------------------------------------------------------------------------*/
263 
264 class scotchDecomp
265 :
266  public metisLikeDecomp
267 {
268  // Private Data
269 
270  //- Output path and name for optional grf file.
271  mutable fileName graphPath_;
272 
273 
274 protected:
275 
276  // Protected Member Functions
277 
278  //- Decompose non-parallel
279  virtual label decomposeSerial
280  (
281  const labelList& adjncy,
282  const labelList& xadj,
283  const List<scalar>& cWeights,
284  labelList& decomp
285  ) const;
286 
287 public:
288 
289  // Generated Methods
290 
291  //- No copy construct
292  scotchDecomp(const scotchDecomp&) = delete;
293 
294  //- No copy assignment
295  void operator=(const scotchDecomp&) = delete;
296 
297 
298  //- Runtime type information
299  TypeName("scotch");
300 
301 
302  // Constructors
303 
304  //- Construct with number of domains (no coefficients or constraints)
305  explicit scotchDecomp(const label numDomains);
306 
307  //- Construct given decomposition dictionary and optional region name
308  explicit scotchDecomp
309  (
310  const dictionary& decompDict,
311  const word& regionName = ""
312  );
313 
314 
315  //- Destructor
316  virtual ~scotchDecomp() = default;
317 
318 
319  // Member Functions
320 
321  //- Knows about coupled boundaries
322  virtual bool parallelAware() const
323  {
324  return true;
325  }
326 
327  //- Inherit all decompose methods
329 
330  //- Return for every coordinate the wanted processor number.
331  virtual labelList decompose
332  (
333  const polyMesh& mesh,
335  const scalarField& pointWeights = scalarField::null()
336  ) const;
337 
338  //- Return for every coordinate the wanted processor number.
339  virtual labelList decompose
340  (
341  const polyMesh& mesh,
342  const labelList& agglom,
343  const pointField& agglomPoints,
344  const scalarField& agglomWeights = scalarField::null()
345  ) const;
346 
347  //- Return the wanted processor number for every cell.
348  virtual labelList decompose
349  (
350  const CompactListList<label>& globalCellCells,
351  const pointField& cc = pointField::null(),
352  const scalarField& cWeights = scalarField::null()
353  ) const;
354 
355  //- Return the wanted processor number for every cell.
356  virtual labelList decompose
357  (
358  const labelListList& globalCellCells,
359  const pointField& cc = pointField::null(),
360  const scalarField& cWeights = scalarField::null()
361  ) const;
362 };
363 
364 
365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 
367 } // End namespace Foam
368 
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 
371 #endif
372 
373 // ************************************************************************* //
TypeName("scotch")
Runtime type information.
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual ~scotchDecomp()=default
Destructor.
virtual labelList decompose(const polyMesh &mesh, const pointField &points=pointField::null(), const scalarField &pointWeights=scalarField::null()) const
Return for every coordinate the wanted processor number.
Definition: scotchDecomp.C:539
dynamicFvMesh & mesh
const pointField & points
virtual bool parallelAware() const
Knows about coupled boundaries.
Definition: scotchDecomp.H:335
A class for handling words, derived from Foam::string.
Definition: word.H:63
scotchDecomp(const scotchDecomp &)=delete
No copy construct.
Domain decomposition using METIS-like data structures.
A packed storage of objects of type <T> using an offset table for access.
void operator=(const scotchDecomp &)=delete
No copy assignment.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
static const Field< vector > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Scotch domain decomposition.
Definition: scotchDecomp.H:259
Namespace for OpenFOAM.
virtual label decomposeSerial(const labelList &adjncy, const labelList &xadj, const List< scalar > &cWeights, labelList &decomp) const
Decompose non-parallel.
Definition: scotchDecomp.C:102
virtual labelList decompose(const pointField &points, const scalarField &pointWeights=scalarField::null()) const
Return the wanted processor number for every coordinate, using uniform or specified point weights...