1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 \*---------------------------------------------------------------------------*/
34 #include "contiguous.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43 template <class T, class BinaryOp>
46 const List<Pstream::commsStruct>& comms,
51 if (Pstream::parRun())
53 // Get my communication order
54 const commsStruct& myComm = comms[Pstream::myProcNo()];
56 // Receive from my downstairs neighbours
57 forAll(myComm.below(), belowI)
66 myComm.below()[belowI],
67 reinterpret_cast<char*>(&value),
73 IPstream fromBelow(Pstream::scheduled, myComm.below()[belowI]);
77 Value = bop(Value, value);
81 if (myComm.above() != -1)
89 reinterpret_cast<const char*>(&Value),
95 OPstream toAbove(Pstream::scheduled, myComm.above());
103 template <class T, class BinaryOp>
104 void Pstream::gather(T& Value, const BinaryOp& bop)
106 if (Pstream::nProcs() < Pstream::nProcsSimpleSum())
108 gather(Pstream::linearCommunication(), Value, bop);
112 gather(Pstream::treeCommunication(), Value, bop);
118 void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
120 if (Pstream::parRun())
122 // Get my communication order
123 const commsStruct& myComm = comms[Pstream::myProcNo()];
126 if (myComm.above() != -1)
134 reinterpret_cast<char*>(&Value),
140 IPstream fromAbove(Pstream::scheduled, myComm.above());
145 // Send to my downstairs neighbours
146 forAll(myComm.below(), belowI)
153 myComm.below()[belowI],
154 reinterpret_cast<const char*>(&Value),
160 OPstream toBelow(Pstream::scheduled,myComm.below()[belowI]);
169 void Pstream::scatter(T& Value)
171 if (Pstream::nProcs() < Pstream::nProcsSimpleSum())
173 scatter(Pstream::linearCommunication(), Value);
177 scatter(Pstream::treeCommunication(), Value);
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //