Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 211 lines (184 sloc) 5.739 kb
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
1 /*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
a9d0f04 ENH: Merging some updates from the internal development line
andy authored
5 \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
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 Description
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.
29
30 \*---------------------------------------------------------------------------*/
31
32 #include "UOPstream.H"
33 #include "OPstream.H"
34 #include "UIPstream.H"
35 #include "IPstream.H"
36 #include "contiguous.H"
37
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39
40 namespace Foam
41 {
42
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44
a9d0f04 ENH: Merging some updates from the internal development line
andy authored
45 template<class T, class BinaryOp>
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
46 void Pstream::gather
47 (
48 const List<UPstream::commsStruct>& comms,
49 T& Value,
50 const BinaryOp& bop,
51 const int tag
52 )
53 {
54 if (UPstream::parRun())
55 {
56 // Get my communication order
57 const commsStruct& myComm = comms[UPstream::myProcNo()];
58
59 // Receive from my downstairs neighbours
60 forAll(myComm.below(), belowI)
61 {
62 T value;
63
64 if (contiguous<T>())
65 {
66 UIPstream::read
67 (
68 UPstream::scheduled,
69 myComm.below()[belowI],
70 reinterpret_cast<char*>(&value),
71 sizeof(T),
72 tag
73 );
74 }
75 else
76 {
77 IPstream fromBelow
78 (
79 UPstream::scheduled,
80 myComm.below()[belowI],
81 0,
82 tag
83 );
84 fromBelow >> value;
85 }
86
87 Value = bop(Value, value);
88 }
89
90 // Send up Value
91 if (myComm.above() != -1)
92 {
93 if (contiguous<T>())
94 {
95 UOPstream::write
96 (
97 UPstream::scheduled,
98 myComm.above(),
99 reinterpret_cast<const char*>(&Value),
100 sizeof(T),
101 tag
102 );
103 }
104 else
105 {
106 OPstream toAbove(UPstream::scheduled, myComm.above(), 0, tag);
107 toAbove << Value;
108 }
109 }
110 }
111 }
112
113
a9d0f04 ENH: Merging some updates from the internal development line
andy authored
114 template<class T, class BinaryOp>
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
115 void Pstream::gather(T& Value, const BinaryOp& bop, const int tag)
116 {
117 if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
118 {
119 gather(UPstream::linearCommunication(), Value, bop, tag);
120 }
121 else
122 {
123 gather(UPstream::treeCommunication(), Value, bop, tag);
124 }
125 }
126
127
a9d0f04 ENH: Merging some updates from the internal development line
andy authored
128 template<class T>
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
129 void Pstream::scatter
130 (
131 const List<UPstream::commsStruct>& comms,
132 T& Value,
133 const int tag
134 )
135 {
136 if (UPstream::parRun())
137 {
138 // Get my communication order
139 const commsStruct& myComm = comms[UPstream::myProcNo()];
140
141 // Reveive from up
142 if (myComm.above() != -1)
143 {
144 if (contiguous<T>())
145 {
146 UIPstream::read
147 (
148 UPstream::scheduled,
149 myComm.above(),
150 reinterpret_cast<char*>(&Value),
151 sizeof(T),
152 tag
153 );
154 }
155 else
156 {
157 IPstream fromAbove(UPstream::scheduled, myComm.above(), 0, tag);
158 fromAbove >> Value;
159 }
160 }
161
162 // Send to my downstairs neighbours
163 forAll(myComm.below(), belowI)
164 {
165 if (contiguous<T>())
166 {
167 UOPstream::write
168 (
169 UPstream::scheduled,
170 myComm.below()[belowI],
171 reinterpret_cast<const char*>(&Value),
172 sizeof(T),
173 tag
174 );
175 }
176 else
177 {
178 OPstream toBelow
179 (
180 UPstream::scheduled,
181 myComm.below()[belowI],
182 0,
183 tag
184 );
185 toBelow << Value;
186 }
187 }
188 }
189 }
190
191
a9d0f04 ENH: Merging some updates from the internal development line
andy authored
192 template<class T>
a3c0017 Initial commit for version 2.2.x
OpenFOAM-admin authored
193 void Pstream::scatter(T& Value, const int tag)
194 {
195 if (UPstream::nProcs() < UPstream::nProcsSimpleSum)
196 {
197 scatter(UPstream::linearCommunication(), Value, tag);
198 }
199 else
200 {
201 scatter(UPstream::treeCommunication(), Value, tag);
202 }
203 }
204
205
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207
208 } // End namespace Foam
209
210 // ************************************************************************* //
Something went wrong with that request. Please try again.