1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
27 \*---------------------------------------------------------------------------*/
30 #include "contiguous.H"
31 #include "PstreamCombineReduceOps.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 //template <template<class> class ListType, class T>
42 template <class Container, class T>
43 void Pstream::exchange
45 const List<Container >& sendBufs,
46 List<Container >& recvBufs,
56 "Pstream::exchange(..)"
57 ) << "Continuous data only." << Foam::abort(FatalError);
60 if (sendBufs.size() != UPstream::nProcs())
64 "Pstream::exchange(..)"
65 ) << "Size of list:" << sendBufs.size()
66 << " does not equal the number of processors:"
68 << Foam::abort(FatalError);
71 sizes.setSize(UPstream::nProcs());
72 labelList& nsTransPs = sizes[UPstream::myProcNo()];
73 nsTransPs.setSize(UPstream::nProcs());
75 forAll(sendBufs, procI)
77 nsTransPs[procI] = sendBufs[procI].size();
81 int oldTag = UPstream::msgType();
82 UPstream::msgType() = tag;
83 combineReduce(sizes, UPstream::listEq());
84 UPstream::msgType() = oldTag;
86 if (Pstream::parRun())
91 recvBufs.setSize(sendBufs.size());
94 label nRecv = sizes[procI][UPstream::myProcNo()];
96 if (procI != Pstream::myProcNo() && nRecv > 0)
98 recvBufs[procI].setSize(nRecv);
101 UPstream::nonBlocking,
103 reinterpret_cast<char*>(recvBufs[procI].begin()),
114 forAll(sendBufs, procI)
116 if (procI != Pstream::myProcNo() && sendBufs[procI].size() > 0)
122 UPstream::nonBlocking,
124 reinterpret_cast<const char*>(sendBufs[procI].begin()),
125 sendBufs[procI].size()*sizeof(T),
130 FatalErrorIn("Pstream::exchange(..)")
131 << "Cannot send outgoing message. "
132 << "to:" << procI << " nBytes:"
133 << label(sendBufs[procI].size()*sizeof(T))
134 << Foam::abort(FatalError);
140 // Wait for all to finish
141 // ~~~~~~~~~~~~~~~~~~~~~~
145 Pstream::waitRequests();
150 recvBufs[Pstream::myProcNo()] = sendBufs[Pstream::myProcNo()];
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // ************************************************************************* //