Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / db / IOstreams / Pstreams / PstreamCombineReduceOps.H
blob41e6a48e855e8c05da2c3305fb9c7a13efac8dbe
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 InClass
25     Foam::Pstream
27 Description
28     Combination-Reduction operation for a parallel run.  The
29     information from all nodes is collected on the master node,
30     combined using the given combination function and the result is
31     broadcast to all nodes
34 \*---------------------------------------------------------------------------*/
36 #ifndef PstreamCombineReduceOps_H
37 #define PstreamCombineReduceOps_H
39 #include "Pstream.H"
40 #include "ops.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 template <class T, class CombineOp>
50 void combineReduce
52     const List<Pstream::commsStruct>& comms,
53     T& Value,
54     const CombineOp& cop
57     Pstream::combineGather(comms, Value, cop);
58     Pstream::combineScatter(comms, Value);
62 template <class T, class CombineOp>
63 void combineReduce(T& Value, const CombineOp& cop)
65     if (Pstream::nProcs() < Pstream::nProcsSimpleSum())
66     {
67         Pstream::combineGather(Pstream::linearCommunication(), Value, cop);
68         Pstream::combineScatter(Pstream::linearCommunication(), Value);
69     }
70     else
71     {
72         Pstream::combineGather(Pstream::treeCommunication(), Value, cop);
73         Pstream::combineScatter(Pstream::treeCommunication(), Value);
74     }
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 } // End namespace Foam
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 #endif
86 // ************************************************************************* //