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/>.
25 Gather data from all processors onto single processor according to some
26 communication schedule (usually linear-to-master or tree-to-master).
27 The gathered data will be a single value constructed from the values
28 on individual processors using a user-specified operator.
30 \*---------------------------------------------------------------------------*/
32 #include "UOPstream.H"
34 #include "UIPstream.H"
36 #include "contiguous.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 template <class T, class BinaryOp>
48 const List<UPstream::commsStruct>& comms,
53 if (UPstream::parRun())
55 // Get my communication order
56 const commsStruct& myComm = comms[UPstream::myProcNo()];
58 // Receive from my downstairs neighbours
59 forAll(myComm.below(), belowI)
68 myComm.below()[belowI],
69 reinterpret_cast<char*>(&value),
75 IPstream fromBelow(UPstream::scheduled, myComm.below()[belowI]);
79 Value = bop(Value, value);
83 if (myComm.above() != -1)
91 reinterpret_cast<const char*>(&Value),
97 OPstream toAbove(UPstream::scheduled, myComm.above());
105 template <class T, class BinaryOp>
106 void Pstream::gather(T& Value, const BinaryOp& bop)
108 if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
110 gather(UPstream::linearCommunication(), Value, bop);
114 gather(UPstream::treeCommunication(), Value, bop);
120 void Pstream::scatter(const List<UPstream::commsStruct>& comms, T& Value)
122 if (UPstream::parRun())
124 // Get my communication order
125 const commsStruct& myComm = comms[UPstream::myProcNo()];
128 if (myComm.above() != -1)
136 reinterpret_cast<char*>(&Value),
142 IPstream fromAbove(UPstream::scheduled, myComm.above());
147 // Send to my downstairs neighbours
148 forAll(myComm.below(), belowI)
155 myComm.below()[belowI],
156 reinterpret_cast<const char*>(&Value),
162 OPstream toBelow(UPstream::scheduled,myComm.below()[belowI]);
171 void Pstream::scatter(T& Value)
173 if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
175 scatter(UPstream::linearCommunication(), Value);
179 scatter(UPstream::treeCommunication(), Value);
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 } // End namespace Foam
188 // ************************************************************************* //