PstreamCombineReduceOps.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 InClass
25  Foam
26 
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
32 
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef PstreamCombineReduceOps_H
37 #define PstreamCombineReduceOps_H
38 
39 #include "UPstream.H"
40 #include "Pstream.H"
41 #include "ops.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 template<class T, class CombineOp>
51 void combineReduce
52 (
53  const List<UPstream::commsStruct>& comms,
54  T& Value,
55  const CombineOp& cop,
56  const int tag,
57  const label comm
58 )
59 {
60  Pstream::combineGather(comms, Value, cop, tag, comm);
61  Pstream::combineScatter(comms, Value, tag, comm);
62 }
63 
64 
65 template<class T, class CombineOp>
66 void combineReduce
67 (
68  T& Value,
69  const CombineOp& cop,
70  const int tag = Pstream::msgType(),
71  const label comm = Pstream::worldComm
72 )
73 {
75  {
77  (
79  Value,
80  cop,
81  tag,
82  comm
83  );
85  (
87  Value,
88  tag,
89  comm
90  );
91  }
92  else
93  {
95  (
97  Value,
98  cop,
99  tag,
100  comm
101  );
103  (
105  Value,
106  tag,
107  comm
108  );
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 } // End namespace Foam
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 #endif
120 
121 // ************************************************************************* //
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
Definition: UPstream.H:269
Combination-Reduction operation for a parallel run.
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:278
static const List< commsStruct > & linearCommunication(const label communicator=0)
Communication schedule for linear all-to-master (proc 0)
Definition: UPstream.H:459
static const List< commsStruct > & treeCommunication(const label communicator=0)
Communication schedule for tree all-to-master (proc 0)
Definition: UPstream.H:468
static void combineGather(const List< commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
static void combineScatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Namespace for OpenFOAM.