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
26 Gather data from all processors onto single processor according to some
27 communication schedule (usually linear-to-master or tree-to-master).
28 The gathered data will be a single value constructed from the values
29 on individual processors using a user-specified operator.
31 \*---------------------------------------------------------------------------*/
35 #include "contiguous.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 template <class T, class BinaryOp>
47 const List<Pstream::commsStruct>& comms,
52 if (Pstream::parRun())
54 // Get my communication order
55 const commsStruct& myComm = comms[Pstream::myProcNo()];
57 // Receive from my downstairs neighbours
58 forAll(myComm.below(), belowI)
67 myComm.below()[belowI],
68 reinterpret_cast<char*>(&value),
74 IPstream fromBelow(Pstream::scheduled, myComm.below()[belowI]);
78 Value = bop(Value, value);
82 if (myComm.above() != -1)
90 reinterpret_cast<const char*>(&Value),
96 OPstream toAbove(Pstream::scheduled, myComm.above());
104 template <class T, class BinaryOp>
105 void Pstream::gather(T& Value, const BinaryOp& bop)
107 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
109 gather(Pstream::linearCommunication(), Value, bop);
113 gather(Pstream::treeCommunication(), Value, bop);
119 void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
121 if (Pstream::parRun())
123 // Get my communication order
124 const commsStruct& myComm = comms[Pstream::myProcNo()];
127 if (myComm.above() != -1)
135 reinterpret_cast<char*>(&Value),
141 IPstream fromAbove(Pstream::scheduled, myComm.above());
146 // Send to my downstairs neighbours
147 forAll(myComm.below(), belowI)
154 myComm.below()[belowI],
155 reinterpret_cast<const char*>(&Value),
161 OPstream toBelow(Pstream::scheduled,myComm.below()[belowI]);
170 void Pstream::scatter(T& Value)
172 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
174 scatter(Pstream::linearCommunication(), Value);
178 scatter(Pstream::treeCommunication(), Value);
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 } // End namespace Foam
187 // ************************************************************************* //