OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

ParSortableList.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::ParSortableList
00027 
00028 Description
00029     Implementation of PSRS parallel sorting routine.
00030 
00031     From "On the Versatility of Parallel Sorting by Regular Sampling"
00032     Xiaobo Li et. all.
00033 
00034     Construct from list of things to sort (uses SortableList, 'thing' should
00035     implement >, ==).
00036 
00037     Will contain sorted data and in
00038         - indices() the original indices
00039         - procs() the original processor id.
00040 
00041     Can also be constructed from size, filled at ease and then sort()'ed.
00042 
00043 SourceFiles
00044     ParSortableList.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef ParSortableList_H
00049 #define ParSortableList_H
00050 
00051 #include "labelList.H"
00052 
00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00054 
00055 namespace Foam
00056 {
00057 
00058 
00059 /*---------------------------------------------------------------------------*\
00060                         Class ParSortableListName Declaration
00061 \*---------------------------------------------------------------------------*/
00062 
00063 TemplateName(ParSortableList);
00064 
00065 
00066 /*---------------------------------------------------------------------------*\
00067                            Class ParSortableList Declaration
00068 \*---------------------------------------------------------------------------*/
00069 
00070 template <class Type>
00071 class ParSortableList
00072 :
00073     public ParSortableListName,
00074     public List<Type>
00075 {
00076     // Private data
00077 
00078         //- Original indices
00079         labelList indices_;
00080 
00081         //- Processor numbers
00082         labelList procs_;
00083 
00084 
00085     // Private class
00086 
00087         //- Private class for sorting. Sorts on value_.
00088         class taggedValue
00089         {
00090             // Private data
00091 
00092                 //- Value
00093                 Type value_;
00094 
00095                 //- Index
00096                 label index_;
00097 
00098                 //- Proc
00099                 label procID_;
00100 
00101 
00102         public:
00103 
00104             // Constructors
00105 
00106                 taggedValue()
00107                 {}
00108 
00109             // Member Functions
00110 
00111                 const Type& value() const
00112                 {
00113                     return value_;
00114                 }
00115 
00116                 Type& value()
00117                 {
00118                     return value_;
00119                 }
00120 
00121                 label index() const
00122                 {
00123                     return index_;
00124                 }
00125 
00126                 label& index()
00127                 {
00128                     return index_;
00129                 }
00130 
00131                 label procID() const
00132                 {
00133                     return procID_;
00134                 }
00135 
00136                 label& procID()
00137                 {
00138                     return procID_;
00139                 }
00140         };
00141 
00142 
00143     // Private Member Functions
00144 
00145         //- Write for debugging
00146         void write(const List<Type>& elems, Ostream& os) const;
00147 
00148         //- Copy into dest, setting indices and processor no.
00149         void copyInto
00150         (
00151             const List<Type>& values,
00152             const labelList& indices,
00153             const label fromProcNo,
00154             label& destI,
00155             List<taggedValue>& dest
00156         ) const;
00157 
00158         //- Calculate pivots.
00159         void getPivots(const List<Type>& elems, List<Type>& pivots) const;
00160 
00161         //- If destProc != myProcNo send & clear values and indices
00162         void checkAndSend
00163         (
00164             List<Type>& values,
00165             labelList& indices,
00166             const label bufSize,
00167             const label destProcI
00168         ) const;
00169 
00170 
00171 public:
00172 
00173     // Constructors
00174 
00175         //- Construct from List, sorting the elements.
00176         ParSortableList(const UList<Type>&);
00177 
00178         //- Construct given size. Sort later on.
00179         ParSortableList(const label size);
00180 
00181 
00182     // Member Functions
00183 
00184         //- (stable) sort the list (if changed after construction time)
00185         void sort();
00186 
00187         //- Return the list of sorted point indices
00188         const labelList& indices() const
00189         {
00190             return indices_;
00191         }
00192 
00193         //- Return the list of processor number
00194         const labelList& procs() const
00195         {
00196             return procs_;
00197         }
00198 };
00199 
00200 
00201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00202 
00203 } // End namespace Foam
00204 
00205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00206 
00207 #ifdef NoRepository
00208 #   include "ParSortableList.C"
00209 #endif
00210 
00211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00212 
00213 #endif
00214 
00215 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd