meshOctreeModifierDistributeLeavesToProcessors.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "meshOctreeModifier.H"
29 
30 //#define DEBUGSearch
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
40 {
41  if( octree_.neiProcs().size() != 0 )
42  return;
43 
45  const label nLeavesPerProcessor = leaves.size() / Pstream::nProcs();
46 
47  Info << "Number of leaves per processor " << nLeavesPerProcessor << endl;
48 
49  if( nLeavesPerProcessor == 0 )
50  return;
51 
52  Info << "Distributing leaves to processors" << endl;
53  //- leaf boxes are sorted in Z-ordering
54  //- initial distribution is performed by decomposing the list of leaves
55  //- into the equal-size chunks and allocate them to processors
57  label balance = leaves.size() % Pstream::nProcs();
58  label start = leaves.size() - 1;
59  for(short procI=Pstream::nProcs()-1;procI>=0;--procI)
60  {
61  label end = start - nLeavesPerProcessor;
62  if( balance )
63  {
64  --balance;
65  --end;
66  }
67  else if( procI == 0 )
68  {
69  end = -1;
70  }
71 
72  procRange[procI].second() = leaves[start]->coordinates();
73  procRange[procI].first() = leaves[end+1]->coordinates();
74 
75  for(;start>end;--start)
76  leaves[start]->setProcNo(procI);
77  }
78 
79  # ifdef DEBUGSearch
80  forAll(leaves, leafI)
81  Info << "Leaf " << leafI << " is in proc "
82  << leaves[leafI]->procNo() << endl;
83  # endif
84 
85  //- find neighbouring processors of the current processor
86  DynList<label> neiProcs;
87 
88  forAll(leaves, leafI)
89  {
90  const meshOctreeCubeCoordinates& cc = leaves[leafI]->coordinates();
91 
92  forAll(procRange, procI)
93  {
94  if( procI == Pstream::myProcNo() )
95  continue;
96 
97  if(
98  (cc >= procRange[procI].first()) &&
99  (cc <= procRange[procI].second())
100  )
101  {
102  neiProcs.appendIfNotIn(procI);
103  break;
104  }
105  }
106  }
107 
108  # ifdef DEBUGSearch
109  Serr << "Neighbouring processors of the processor " << Pstream::myProcNo()
110  << " are " << neiProcs << endl;
111  # endif
112 
113  labelList& nProcs = octree_.neiProcs_;
114  nProcs.setSize(neiProcs.size());
115  forAll(nProcs, i)
116  nProcs[i] = neiProcs[i];
117  Foam::sort(nProcs);
118 
119  octree_.neiRange_.transfer(procRange);
120 
121  # ifdef DEBUGSearch
122  Info << "Nei procs " << octree_.neiProcs_ << endl;
123  Info << "Nei range " << octree_.neiRange_ << endl;
124  # endif
125 
126  //- delete cubes which are not local to the processor
128 
129  //- update the list of leaves
131 
132  Info << "Finished distributing leaves to processors" << endl;
133 }
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace Foam
138 
139 // ************************************************************************* //
Foam::meshOctree::neiRange_
List< Pair< meshOctreeCubeCoordinates > > neiRange_
Definition: meshOctree.H:68
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshOctreeCubeCoordinates
Definition: meshOctreeCubeCoordinates.H:55
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:387
Foam::meshOctreeModifier::distributeLeavesToProcessors
void distributeLeavesToProcessors()
Definition: meshOctreeModifierDistributeLeavesToProcessors.C:39
Foam::meshOctree::neiProcs
const labelList & neiProcs() const
neighbour processors of the current one
Definition: meshOctreeI.H:152
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
meshOctreeModifier.H
Foam::LongList
Definition: LongList.H:55
Foam::label
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
Foam::Info
messageStream Info
Foam::Serr
OSstream Serr(cerr, "Serr")
Definition: IOstreams.H:52
Foam::DynList::appendIfNotIn
void appendIfNotIn(const T &e)
Definition: DynListI.H:324
Foam::meshOctree::leaves_
LongList< meshOctreeCube * > leaves_
list of cubes which are leaves of the octree
Definition: meshOctree.H:89
Foam::meshOctreeCube::purgeProcessorCubes
bool purgeProcessorCubes(const short procNo)
delete boxes which are not local to the given processor
Definition: meshOctreeCubeRecursiveFunctions.C:247
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshOctree::neiProcs_
labelList neiProcs_
Definition: meshOctree.H:63
Foam::DynList< label >
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::meshOctree::initialCubePtr_
meshOctreeCube * initialCubePtr_
Root cube of the octree structure.
Definition: meshOctree.H:71
Foam::sort
void sort(UList< T > &)
Definition: UList.C:107
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::meshOctreeModifier::createListOfLeaves
void createListOfLeaves()
create leaves
Definition: meshOctreeModifierI.H:100
Foam::meshOctreeModifier::octree_
meshOctree & octree_
Reference to the octree.
Definition: meshOctreeModifier.H:52