ParSortableList.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::ParSortableList
28 
29 Description
30  Implementation of PSRS parallel sorting routine.
31 
32  From "On the Versatility of Parallel Sorting by Regular Sampling"
33  Xiaobo Li et. all.
34 
35  Construct from list of things to sort (uses SortableList, 'thing' should
36  implement >, ==).
37 
38  Will contain sorted data and in
39  - indices() the original indices
40  - procs() the original processor id.
41 
42  Can also be constructed from size, filled at ease and then sort()'ed.
43 
44 SourceFiles
45  ParSortableList.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef ParSortableList_H
50 #define ParSortableList_H
51 
52 #include "labelList.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class ParSortableListName Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 TemplateName(ParSortableList);
65 
66 
67 /*---------------------------------------------------------------------------*\
68  Class ParSortableList Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class Type>
72 class ParSortableList
73 :
74  public ParSortableListName,
75  public List<Type>
76 {
77  // Private data
78 
79  //- Original indices
80  labelList indices_;
81 
82  //- Processor numbers
83  labelList procs_;
84 
85 
86  // Private class
87 
88  //- Private class for sorting. Sorts on value_.
89  class taggedValue
90  {
91  // Private data
92 
93  //- Value
94  Type value_;
95 
96  //- Index
97  label index_;
98 
99  //- Proc
100  label procID_;
101 
102 
103  public:
104 
105  // Constructors
106 
107  taggedValue()
108  {}
109 
110  // Member Functions
111 
112  const Type& value() const
113  {
114  return value_;
115  }
116 
117  Type& value()
118  {
119  return value_;
120  }
121 
122  label index() const
123  {
124  return index_;
125  }
126 
127  label& index()
128  {
129  return index_;
130  }
131 
132  label procID() const
133  {
134  return procID_;
135  }
136 
137  label& procID()
138  {
139  return procID_;
140  }
141  };
142 
143 
144  // Private Member Functions
145 
146  //- Write for debugging
147  void write(const List<Type>& elems, Ostream& os) const;
148 
149  //- Copy into dest, setting indices and processor no.
150  void copyInto
151  (
152  const List<Type>& values,
153  const labelList& indices,
154  const label fromProcNo,
155  label& destI,
156  List<taggedValue>& dest
157  ) const;
158 
159  //- Calculate pivots.
160  void getPivots(const List<Type>& elems, List<Type>& pivots) const;
161 
162  //- If destProc != myProcNo send & clear values and indices
163  void checkAndSend
164  (
167  const label bufSize,
168  const label destProci
169  ) const;
170 
171 
172 public:
173 
174  // Constructors
175 
176  //- Construct from List, sorting the elements.
178 
179  //- Construct given size. Sort later on.
180  ParSortableList(const label size);
181 
182 
183  // Member Functions
184 
185  //- (stable) sort the list (if changed after construction time)
186  void sort();
187 
188  //- Return the list of sorted point indices
189  const labelList& indices() const
190  {
191  return indices_;
192  }
193 
194  //- Return the list of processor number
195  const labelList& procs() const
196  {
197  return procs_;
198  }
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #ifdef NoRepository
209  #include "ParSortableList.C"
210 #endif
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
ParSortableList.C
labelList.H
Foam::ParSortableList::indices
const labelList & indices() const
Return the list of sorted point indices.
Definition: ParSortableList.H:188
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::ParSortableList::sort
void sort()
(stable) sort the list (if changed after construction time)
Definition: ParSortableList.C:150
Foam::ParSortableList
Implementation of PSRS parallel sorting routine.
Definition: ParSortableList.H:71
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ParSortableList::ParSortableList
ParSortableList(const UList< Type > &)
Construct from List, sorting the elements.
Definition: ParSortableList.C:128
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList< Type >
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ParSortableList::procs
const labelList & procs() const
Return the list of processor number.
Definition: ParSortableList.H:194