Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
db
IOstreams
Pstreams
PstreamReduceOps.H
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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
\*---------------------------------------------------------------------------*/
25
26
#ifndef PstreamReduceOps_H
27
#define PstreamReduceOps_H
28
29
#include "
Pstream.H
"
30
#include <
OpenFOAM/ops.H
>
31
32
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34
namespace
Foam
35
{
36
37
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39
// Reduce operation with user specified communication schedule
40
template
<
class
T,
class
BinaryOp>
41
void
reduce
42
(
43
const
List<Pstream::commsStruct>
& comms,
44
T
& Value,
45
const
BinaryOp& bop
46
)
47
{
48
Pstream::gather
(comms, Value, bop);
49
Pstream::scatter
(comms, Value);
50
}
51
52
53
// Reduce using either linear or tree communication schedule
54
template
<
class
T,
class
BinaryOp>
55
void
reduce
56
(
57
T
& Value,
58
const
BinaryOp& bop
59
)
60
{
61
if
(
Pstream::nProcs
() <
Pstream::nProcsSimpleSum
)
62
{
63
reduce
(
Pstream::linearCommunication
(), Value, bop);
64
}
65
else
66
{
67
reduce
(
Pstream::treeCommunication
(), Value, bop);
68
}
69
}
70
71
72
// Reduce using either linear or tree communication schedule
73
template
<
class
T,
class
BinaryOp>
74
T
returnReduce
75
(
76
const
T
& Value,
77
const
BinaryOp& bop
78
)
79
{
80
T
WorkValue(Value);
81
82
if
(
Pstream::nProcs
() <
Pstream::nProcsSimpleSum
)
83
{
84
reduce
(
Pstream::linearCommunication
(), WorkValue, bop);
85
}
86
else
87
{
88
reduce
(
Pstream::treeCommunication
(), WorkValue, bop);
89
}
90
91
return
WorkValue;
92
}
93
94
95
// Insist there is a specialisation for the reduction of a scalar
96
// and implement it in PstreamImpl
97
inline
void
reduce
(scalar& Value,
const
sumOp<scalar>
& bop)
98
{
99
Pstream::impl()->reduce(Value, bop);
100
}
101
102
103
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104
105
}
// End namespace Foam
106
107
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108
109
#endif
110
111
// ************************ vim: set sw=4 sts=4 et: ************************ //