1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Class containing processor-to-processor mapping information.
31 We store mapping from the bits-to-send to the complete starting list
32 (subXXXMap) and from the received bits to their location in the new
33 list (constructXXXMap).
36 Schedule is a list of processor pairs (one send, one receive. One of
37 them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
38 See distribute on how to use it.
39 Note2: number of items send on one processor have to equal the number
40 of items received on the other processor.
46 \*---------------------------------------------------------------------------*/
48 #ifndef mapDistribute_H
49 #define mapDistribute_H
51 #include "labelList.H"
52 #include "labelPair.H"
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 /*---------------------------------------------------------------------------*\
64 Class mapDistribute Declaration
65 \*---------------------------------------------------------------------------*/
71 //- Size of reconstructed data
74 //- Maps from subsetted data back to original data
75 labelListList subMap_;
77 //- Maps from subsetted data to new reconstructed data
78 labelListList constructMap_;
81 mutable autoPtr<List<labelPair> > schedulePtr_;
88 //- Construct from components
91 const label constructSize,
92 const labelListList& subMap,
93 const labelListList& constructMap
96 //- (optionally destructively) construct from components
99 const label constructSize,
100 labelListList& subMap,
101 labelListList& constructMap,
102 const bool reUse // clone or reuse
105 //- Construct from reverse addressing: per data item the send
106 // processor and the receive processor. All processors get same data.
109 const labelList& sendProcs,
110 const labelList& recvProcs
114 mapDistribute(const mapDistribute&);
121 //- Constructed data size
122 label constructSize() const
124 return constructSize_;
127 //- Constructed data size
128 label& constructSize()
130 return constructSize_;
133 //- From subsetted data back to original data
134 const labelListList& subMap() const
139 //- From subsetted data back to original data
140 labelListList& subMap()
145 //- From subsetted data to new reconstructed data
146 const labelListList& constructMap() const
148 return constructMap_;
151 //- From subsetted data to new reconstructed data
152 labelListList& constructMap()
154 return constructMap_;
157 //- Calculate a schedule. See above.
158 static List<labelPair> schedule
160 const labelListList& subMap,
161 const labelListList& constructMap
164 //- Return a schedule. Demand driven. See above.
165 const List<labelPair>& schedule() const;
170 //- Compact maps. Gets per field a bool whether it is used (locally)
171 // and works out itself what this side and sender side can remove
173 void compact(const boolList& elemIsUsed);
176 //- Distribute data. Note:schedule only used for Pstream::scheduled
177 // for now, all others just use send-to-all, receive-from-all.
179 static void distribute
181 const Pstream::commsTypes commsType,
182 const List<labelPair>& schedule,
183 const label constructSize,
184 const labelListList& subMap,
185 const labelListList& constructMap,
189 //- Distribute data. If multiple processors writing to same
190 // position adds contributions using cop.
191 template<class T, class CombineOp>
192 static void distribute
194 const Pstream::commsTypes commsType,
195 const List<labelPair>& schedule,
196 const label constructSize,
197 const labelListList& subMap,
198 const labelListList& constructMap,
200 const CombineOp& cop,
204 //- Distribute data using default commsType.
206 void distribute(List<T>& fld) const
210 Pstream::defaultCommsType == Pstream::nonBlocking
216 Pstream::nonBlocking,
224 else if (Pstream::defaultCommsType == Pstream::scheduled)
250 //- Correct for topo change.
251 void updateMesh(const mapPolyMesh&)
255 "mapDistribute::updateMesh(const mapPolyMesh&)"
261 void operator=(const mapDistribute&);
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 } // End namespace Foam
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 # include "mapDistributeTemplates.C"
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 // ************************************************************************* //