1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Inter-processor communications stream
33 combineGatherScatter.C
37 \*---------------------------------------------------------------------------*/
43 #include "DynamicList.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 /*---------------------------------------------------------------------------*\
51 Class Pstream Declaration
52 \*---------------------------------------------------------------------------*/
64 DynamicList<char> buf_;
68 // Declare name of the class and its debug switch
74 //- Construct given optional buffer size
77 const commsTypes commsType,
78 const label bufSize = 0
86 buf_.setCapacity(bufSize + 2*sizeof(scalar) + 1);
93 //- Gather data. Apply bop to combine Value
94 // from different processors
95 template <class T, class BinaryOp>
98 const List<commsStruct>& comms,
103 //- Like above but switches between linear/tree communication
104 template <class T, class BinaryOp>
105 static void gather(T& Value, const BinaryOp& bop);
107 //- Scatter data. Distribute without modification. Reverse of gather
109 static void scatter(const List<commsStruct>& comms, T& Value);
111 //- Like above but switches between linear/tree communication
113 static void scatter(T& Value);
116 // Combine variants. Inplace combine values from processors.
117 // (Uses construct from Istream instead of <<)
119 template <class T, class CombineOp>
120 static void combineGather
122 const List<commsStruct>& comms,
127 //- Like above but switches between linear/tree communication
128 template <class T, class CombineOp>
129 static void combineGather(T& Value, const CombineOp& cop);
131 //- Scatter data. Reverse of combineGather
133 static void combineScatter
135 const List<commsStruct>& comms,
139 //- Like above but switches between linear/tree communication
141 static void combineScatter(T& Value);
143 // Combine variants working on whole List at a time.
145 template <class T, class CombineOp>
146 static void listCombineGather
148 const List<commsStruct>& comms,
153 //- Like above but switches between linear/tree communication
154 template <class T, class CombineOp>
155 static void listCombineGather(List<T>& Value, const CombineOp& cop);
157 //- Scatter data. Reverse of combineGather
159 static void listCombineScatter
161 const List<commsStruct>& comms,
165 //- Like above but switches between linear/tree communication
167 static void listCombineScatter(List<T>& Value);
169 // Combine variants working on whole map at a time. Container needs to
170 // have iterators and find() defined.
172 template <class Container, class CombineOp>
173 static void mapCombineGather
175 const List<commsStruct>& comms,
180 //- Like above but switches between linear/tree communication
181 template <class Container, class CombineOp>
182 static void mapCombineGather
188 //- Scatter data. Reverse of combineGather
189 template <class Container>
190 static void mapCombineScatter
192 const List<commsStruct>& comms,
196 //- Like above but switches between linear/tree communication
197 template <class Container>
198 static void mapCombineScatter(Container& Values);
202 // Gather/scatter keeping the individual processor data separate.
203 // Values is a List of size UPstream::nProcs() where
204 // Values[UPstream::myProcNo()] is the data for the current processor.
206 //- Gather data but keep individual values separate
208 static void gatherList
210 const List<commsStruct>& comms,
214 //- Like above but switches between linear/tree communication
216 static void gatherList(List<T>& Values);
218 //- Scatter data. Reverse of gatherList
220 static void scatterList
222 const List<commsStruct>& comms,
226 //- Like above but switches between linear/tree communication
228 static void scatterList(List<T>& Values);
233 //- Exchange data. Sends sendData, receives into recvData, sets
234 // sizes (not bytes). sizes[p0][p1] is what processor p0 has
235 // sent to p1. Continuous data only.
236 // If block=true will wait for all transfers to finish.
237 template <class Container, class T>
240 const List<Container >&,
242 labelListList& sizes,
243 const int tag = UPstream::msgType(),
244 const bool block = true
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 } // End namespace Foam
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 # include "gatherScatter.C"
258 # include "combineGatherScatter.C"
259 # include "gatherScatterList.C"
260 # include "exchange.C"
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 // ************************************************************************* //