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 | Copyright (C) 2011-2013 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::ParSortableList
26 
27 Description
28  Implementation of PSRS parallel sorting routine.
29 
30  From "On the Versatility of Parallel Sorting by Regular Sampling"
31  Xiaobo Li et. all.
32 
33  Construct from list of things to sort (uses SortableList, 'thing' should
34  implement >, ==).
35 
36  Will contain sorted data and in
37  - indices() the original indices
38  - procs() the original processor id.
39 
40  Can also be constructed from size, filled at ease and then sort()'ed.
41 
42 SourceFiles
43  ParSortableList.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef ParSortableList_H
48 #define ParSortableList_H
49 
50 #include "labelList.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 
58 /*---------------------------------------------------------------------------*\
59  Class ParSortableListName Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 TemplateName(ParSortableList);
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class ParSortableList Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 template<class Type>
70 class ParSortableList
71 :
72  public ParSortableListName,
73  public List<Type>
74 {
75  // Private data
76 
77  //- Original indices
79 
80  //- Processor numbers
82 
83 
84  // Private class
85 
86  //- Private class for sorting. Sorts on value_.
87  class taggedValue
88  {
89  // Private data
90 
91  //- Value
92  Type value_;
93 
94  //- Index
95  label index_;
96 
97  //- Proc
98  label procID_;
99 
100 
101  public:
102 
103  // Constructors
104 
105  taggedValue()
106  {}
107 
108  // Member Functions
109 
110  const Type& value() const
111  {
112  return value_;
113  }
114 
115  Type& value()
116  {
117  return value_;
118  }
119 
120  label index() const
121  {
122  return index_;
123  }
124 
125  label& index()
126  {
127  return index_;
128  }
129 
130  label procID() const
131  {
132  return procID_;
133  }
134 
135  label& procID()
136  {
137  return procID_;
138  }
139  };
140 
141 
142  // Private Member Functions
143 
144  //- Write for debugging
145  void write(const List<Type>& elems, Ostream& os) const;
146 
147  //- Copy into dest, setting indices and processor no.
148  void copyInto
149  (
150  const List<Type>& values,
151  const labelList& indices,
152  const label fromProcNo,
153  label& destI,
154  List<taggedValue>& dest
155  ) const;
156 
157  //- Calculate pivots.
158  void getPivots(const List<Type>& elems, List<Type>& pivots) const;
159 
160  //- If destProc != myProcNo send & clear values and indices
161  void checkAndSend
162  (
163  List<Type>& values,
165  const label bufSize,
166  const label destProcI
167  ) const;
168 
169 
170 public:
171 
172  // Constructors
173 
174  //- Construct from List, sorting the elements.
176 
177  //- Construct given size. Sort later on.
178  ParSortableList(const label size);
179 
180 
181  // Member Functions
182 
183  //- (stable) sort the list (if changed after construction time)
184  void sort();
185 
186  //- Return the list of sorted point indices
187  const labelList& indices() const
188  {
189  return indices_;
190  }
191 
192  //- Return the list of processor number
193  const labelList& procs() const
194  {
195  return procs_;
196  }
197 };
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207 # include "ParSortableList.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
Foam::ParSortableList::checkAndSend
void checkAndSend(List< Type > &values, labelList &indices, const label bufSize, const label destProcI) const
If destProc != myProcNo send & clear values and indices.
Definition: ParSortableList.C:97
Foam::ParSortableList::taggedValue::index_
label index_
Index.
Definition: ParSortableList.H:94
Foam::ParSortableList::taggedValue::index
label & index()
Definition: ParSortableList.H:124
ParSortableList.C
Foam::ParSortableList::taggedValue
Private class for sorting. Sorts on value_.
Definition: ParSortableList.H:86
Foam::ParSortableList::taggedValue::index
label index() const
Definition: ParSortableList.H:119
Foam::ParSortableList::taggedValue::procID_
label procID_
Proc.
Definition: ParSortableList.H:97
Foam::ParSortableList::write
void write(const List< Type > &elems, Ostream &os) const
Write for debugging.
Definition: ParSortableList.C:36
Foam::ParSortableList::taggedValue::value_
Type value_
Value.
Definition: ParSortableList.H:91
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::ParSortableList::getPivots
void getPivots(const List< Type > &elems, List< Type > &pivots) const
Calculate pivots.
Definition: ParSortableList.C:77
labelList.H
Foam::ParSortableList::indices
const labelList & indices() const
Return the list of sorted point indices.
Definition: ParSortableList.H:186
Foam::ParSortableList::indices_
labelList indices_
Original indices.
Definition: ParSortableList.H:77
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::ParSortableList::sort
void sort()
(stable) sort the list (if changed after construction time)
Definition: ParSortableList.C:151
Foam::ParSortableList
Implementation of PSRS parallel sorting routine.
Definition: ParSortableList.H:69
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::ParSortableList::copyInto
void copyInto(const List< Type > &values, const labelList &indices, const label fromProcNo, label &destI, List< taggedValue > &dest) const
Copy into dest, setting indices and processor no.
Definition: ParSortableList.C:54
Foam::List< Type >::size
label size() const
Return the number of elements in the UList.
Foam::ParSortableList::taggedValue::value
Type & value()
Definition: ParSortableList.H:114
Foam::ParSortableList::ParSortableList
ParSortableList(const UList< Type > &)
Construct from List, sorting the elements.
Definition: ParSortableList.C:127
Foam::ParSortableList::taggedValue::taggedValue
taggedValue()
Definition: ParSortableList.H:104
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::ParSortableList::procs_
labelList procs_
Processor numbers.
Definition: ParSortableList.H:80
Foam::UList< Type >
Foam::ParSortableList::taggedValue::procID
label & procID()
Definition: ParSortableList.H:134
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ParSortableList::procs
const labelList & procs() const
Return the list of processor number.
Definition: ParSortableList.H:192
Foam::ParSortableList::taggedValue::procID
label procID() const
Definition: ParSortableList.H:129
Foam::ParSortableList::taggedValue::value
const Type & value() const
Definition: ParSortableList.H:109