gatherScatterList.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "IPstream.H"
00038 #include "OPstream.H"
00039 #include "contiguous.H"
00040
00041
00042
00043 namespace Foam
00044 {
00045
00046
00047
00048 template <class T>
00049 void Pstream::gatherList
00050 (
00051 const List<Pstream::commsStruct>& comms,
00052 List<T>& Values
00053 )
00054 {
00055 if (Pstream::parRun())
00056 {
00057 if (Values.size() != Pstream::nProcs())
00058 {
00059 FatalErrorIn
00060 (
00061 "Pstream::gatherList(const List<Pstream::commsStruct>&"
00062 ", List<T>)"
00063 ) << "Size of list:" << Values.size()
00064 << " does not equal the number of processors:"
00065 << Pstream::nProcs()
00066 << Foam::abort(FatalError);
00067 }
00068
00069
00070 const commsStruct& myComm = comms[Pstream::myProcNo()];
00071
00072
00073 forAll(myComm.below(), belowI)
00074 {
00075 label belowID = myComm.below()[belowI];
00076 const labelList& belowLeaves = comms[belowID].allBelow();
00077
00078 if (contiguous<T>())
00079 {
00080 List<T> receivedValues(belowLeaves.size() + 1);
00081
00082 IPstream::read
00083 (
00084 Pstream::scheduled,
00085 belowID,
00086 reinterpret_cast<char*>(receivedValues.begin()),
00087 receivedValues.byteSize()
00088 );
00089
00090 Values[belowID] = receivedValues[0];
00091
00092 forAll(belowLeaves, leafI)
00093 {
00094 Values[belowLeaves[leafI]] = receivedValues[leafI + 1];
00095 }
00096 }
00097 else
00098 {
00099 IPstream fromBelow(Pstream::scheduled, belowID);
00100 fromBelow >> Values[belowID];
00101
00102 if (debug & 2)
00103 {
00104 Pout<< " received through "
00105 << belowID << " data from:" << belowID
00106 << " data:" << Values[belowID] << endl;
00107 }
00108
00109
00110 forAll(belowLeaves, leafI)
00111 {
00112 label leafID = belowLeaves[leafI];
00113 fromBelow >> Values[leafID];
00114
00115 if (debug & 2)
00116 {
00117 Pout<< " received through "
00118 << belowID << " data from:" << leafID
00119 << " data:" << Values[leafID] << endl;
00120 }
00121 }
00122 }
00123 }
00124
00125
00126
00127
00128 if (myComm.above() != -1)
00129 {
00130 const labelList& belowLeaves = myComm.allBelow();
00131
00132 if (debug & 2)
00133 {
00134 Pout<< " sending to " << myComm.above()
00135 << " data from me:" << Pstream::myProcNo()
00136 << " data:" << Values[Pstream::myProcNo()] << endl;
00137 }
00138
00139 if (contiguous<T>())
00140 {
00141 List<T> sendingValues(belowLeaves.size() + 1);
00142 sendingValues[0] = Values[Pstream::myProcNo()];
00143
00144 forAll(belowLeaves, leafI)
00145 {
00146 sendingValues[leafI + 1] = Values[belowLeaves[leafI]];
00147 }
00148
00149 OPstream::write
00150 (
00151 Pstream::scheduled,
00152 myComm.above(),
00153 reinterpret_cast<const char*>(sendingValues.begin()),
00154 sendingValues.byteSize()
00155 );
00156 }
00157 else
00158 {
00159 OPstream toAbove(Pstream::scheduled, myComm.above());
00160 toAbove << Values[Pstream::myProcNo()];
00161
00162 forAll(belowLeaves, leafI)
00163 {
00164 label leafID = belowLeaves[leafI];
00165
00166 if (debug & 2)
00167 {
00168 Pout<< " sending to "
00169 << myComm.above() << " data from:" << leafID
00170 << " data:" << Values[leafID] << endl;
00171 }
00172 toAbove << Values[leafID];
00173 }
00174 }
00175 }
00176 }
00177 }
00178
00179
00180 template <class T>
00181 void Pstream::gatherList(List<T>& Values)
00182 {
00183 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00184 {
00185 gatherList(Pstream::linearCommunication(), Values);
00186 }
00187 else
00188 {
00189 gatherList(Pstream::treeCommunication(), Values);
00190 }
00191 }
00192
00193
00194 template <class T>
00195 void Pstream::scatterList
00196 (
00197 const List<Pstream::commsStruct>& comms,
00198 List<T>& Values
00199 )
00200 {
00201 if (Pstream::parRun())
00202 {
00203 if (Values.size() != Pstream::nProcs())
00204 {
00205 FatalErrorIn
00206 (
00207 "Pstream::scatterList(const List<Pstream::commsStruct>&"
00208 ", List<T>)"
00209 ) << "Size of list:" << Values.size()
00210 << " does not equal the number of processors:"
00211 << Pstream::nProcs()
00212 << Foam::abort(FatalError);
00213 }
00214
00215
00216 const commsStruct& myComm = comms[Pstream::myProcNo()];
00217
00218
00219 if (myComm.above() != -1)
00220 {
00221 const labelList& notBelowLeaves = myComm.allNotBelow();
00222
00223 if (contiguous<T>())
00224 {
00225 List<T> receivedValues(notBelowLeaves.size());
00226
00227 IPstream::read
00228 (
00229 Pstream::scheduled,
00230 myComm.above(),
00231 reinterpret_cast<char*>(receivedValues.begin()),
00232 receivedValues.byteSize()
00233 );
00234
00235 forAll(notBelowLeaves, leafI)
00236 {
00237 Values[notBelowLeaves[leafI]] = receivedValues[leafI];
00238 }
00239 }
00240 else
00241 {
00242 IPstream fromAbove(Pstream::scheduled, myComm.above());
00243
00244 forAll(notBelowLeaves, leafI)
00245 {
00246 label leafID = notBelowLeaves[leafI];
00247 fromAbove >> Values[leafID];
00248
00249 if (debug)
00250 {
00251 Pout<< " received through "
00252 << myComm.above() << " data for:" << leafID
00253 << " data:" << Values[leafID] << endl;
00254 }
00255 }
00256 }
00257 }
00258
00259
00260 forAll(myComm.below(), belowI)
00261 {
00262 label belowID = myComm.below()[belowI];
00263 const labelList& notBelowLeaves = comms[belowID].allNotBelow();
00264
00265 if (contiguous<T>())
00266 {
00267 List<T> sendingValues(notBelowLeaves.size());
00268
00269 forAll(notBelowLeaves, leafI)
00270 {
00271 sendingValues[leafI] = Values[notBelowLeaves[leafI]];
00272 }
00273
00274 OPstream::write
00275 (
00276 Pstream::scheduled,
00277 belowID,
00278 reinterpret_cast<const char*>(sendingValues.begin()),
00279 sendingValues.byteSize()
00280 );
00281 }
00282 else
00283 {
00284 OPstream toBelow(Pstream::scheduled, belowID);
00285
00286
00287 forAll(notBelowLeaves, leafI)
00288 {
00289 label leafID = notBelowLeaves[leafI];
00290 toBelow << Values[leafID];
00291
00292 if (debug)
00293 {
00294 Pout<< " sent through "
00295 << belowID << " data for:" << leafID
00296 << " data:" << Values[leafID] << endl;
00297 }
00298 }
00299 }
00300 }
00301 }
00302 }
00303
00304
00305 template <class T>
00306 void Pstream::scatterList(List<T>& Values)
00307 {
00308 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00309 {
00310 scatterList(Pstream::linearCommunication(), Values);
00311 }
00312 else
00313 {
00314 scatterList(Pstream::treeCommunication(), Values);
00315 }
00316 }
00317
00318
00319
00320
00321 }
00322
00323
Copyright © 2000-2009 OpenCFD Ltd