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
00038
00039
00040
00041
00042 #ifndef Pstream_H
00043 #define Pstream_H
00044
00045 #include "labelList.H"
00046 #include "DynamicList.H"
00047 #include "HashTable.H"
00048 #include "string.H"
00049
00050
00051
00052 namespace Foam
00053 {
00054
00055
00056
00057
00058
00059 class Pstream
00060 {
00061
00062 public:
00063
00064 class commsStruct
00065 {
00066
00067
00068
00069 label above_;
00070
00071
00072 labelList below_;
00073
00074
00075 labelList allBelow_;
00076
00077
00078
00079 labelList allNotBelow_;
00080
00081
00082 public:
00083
00084
00085
00086
00087 commsStruct();
00088
00089
00090 commsStruct
00091 (
00092 const label,
00093 const labelList&,
00094 const labelList&,
00095 const labelList&
00096 );
00097
00098
00099 commsStruct
00100 (
00101 const label nProcs,
00102 const label myProcID,
00103 const label,
00104 const labelList&,
00105 const labelList&
00106 );
00107
00108
00109
00110
00111
00112
00113 label above() const
00114 {
00115 return above_;
00116 }
00117
00118 const labelList& below() const
00119 {
00120 return below_;
00121 }
00122
00123 const labelList& allBelow() const
00124 {
00125 return allBelow_;
00126 }
00127
00128 const labelList& allNotBelow() const
00129 {
00130 return allNotBelow_;
00131 }
00132
00133
00134
00135
00136 bool operator==(const commsStruct&) const;
00137
00138 bool operator!=(const commsStruct&) const;
00139
00140
00141
00142
00143 friend Ostream& operator<<(Ostream&, const commsStruct&);
00144 };
00145
00146
00147 private:
00148
00149
00150
00151 static int myProcNo_;
00152 static bool parRun_;
00153
00154 static List<int> procIDs_;
00155 static const int msgType_;
00156
00157 static List<commsStruct> linearCommunication_;
00158 static List<commsStruct> treeCommunication_;
00159
00160
00161
00162
00163
00164 static void setParRun();
00165
00166
00167 static void calcLinearComm(const label nProcs);
00168
00169
00170 static void calcTreeComm(const label nProcs);
00171
00172
00173
00174 static void collectReceives
00175 (
00176 const label procID,
00177 const List<DynamicList<label> >& receives,
00178 DynamicList<label>& allReceives
00179 );
00180
00181
00182
00183 static void initCommunicationSchedule();
00184
00185
00186 protected:
00187
00188
00189
00190
00191 List<char> buf_;
00192
00193
00194 int bufPosition_;
00195
00196
00197
00198
00199
00200 inline void enlargeBuffer(size_t count);
00201
00202
00203 public:
00204
00205
00206 ClassName("Pstream");
00207
00208
00209
00210
00211
00212
00213
00214 static bool floatTransfer;
00215
00216
00217
00218 static int nProcsSimpleSum;
00219
00220
00221 static bool scheduledTransfer;
00222
00223
00224
00225
00226
00227 Pstream(const label bufSize = 0)
00228 :
00229 bufPosition_(0)
00230 {
00231 if (bufSize)
00232 {
00233 buf_.setSize(bufSize + 2*sizeof(scalar) + 1);
00234 }
00235 }
00236
00237
00238
00239
00240
00241
00242 static void addValidParOptions(HashTable<string>& validParOptions);
00243
00244
00245
00246 static bool init(int& argc, char**& argv);
00247
00248
00249 static bool parRun()
00250 {
00251 return parRun_;
00252 }
00253
00254
00255 static label nProcs()
00256 {
00257 return procIDs_.size();
00258 }
00259
00260
00261 static bool master()
00262 {
00263 return myProcNo_ == 0;
00264 }
00265
00266
00267 static int masterNo()
00268 {
00269 return 0;
00270 }
00271
00272
00273 static int myProcNo()
00274 {
00275 return myProcNo_;
00276 }
00277
00278
00279 static const List<int>& procIDs()
00280 {
00281 return procIDs_;
00282 }
00283
00284
00285 static int procID(int procNo)
00286 {
00287 return procIDs_[procNo];
00288 }
00289
00290
00291 static int firstSlave()
00292 {
00293 return 1;
00294 }
00295
00296
00297 static int lastSlave()
00298 {
00299 return nProcs() - 1;
00300 }
00301
00302
00303 static const List<commsStruct>& linearCommunication()
00304 {
00305 return linearCommunication_;
00306 }
00307
00308
00309 static const List<commsStruct>& treeCommunication()
00310 {
00311 return treeCommunication_;
00312 }
00313
00314
00315 static int msgType()
00316 {
00317 return msgType_;
00318 }
00319
00320
00321 static void exit(int errnum = 1);
00322
00323
00324 static void abort();
00325
00326
00327
00328
00329
00330
00331 template <class T, class BinaryOp>
00332 static void gather
00333 (
00334 const List<commsStruct>& comms,
00335 T& Value,
00336 const BinaryOp& bop
00337 );
00338
00339
00340 template <class T, class BinaryOp>
00341 static void gather(T& Value, const BinaryOp& bop);
00342
00343
00344 template <class T>
00345 static void scatter(const List<commsStruct>& comms, T& Value);
00346
00347
00348 template <class T>
00349 static void scatter(T& Value);
00350
00351
00352
00353
00354
00355 template <class T, class CombineOp>
00356 static void combineGather
00357 (
00358 const List<commsStruct>& comms,
00359 T& Value,
00360 const CombineOp& cop
00361 );
00362
00363
00364 template <class T, class CombineOp>
00365 static void combineGather(T& Value, const CombineOp& cop);
00366
00367
00368 template <class T>
00369 static void combineScatter
00370 (
00371 const List<commsStruct>& comms,
00372 T& Value
00373 );
00374
00375
00376 template <class T>
00377 static void combineScatter(T& Value);
00378
00379
00380
00381 template <class T, class CombineOp>
00382 static void listCombineGather
00383 (
00384 const List<commsStruct>& comms,
00385 List<T>& Value,
00386 const CombineOp& cop
00387 );
00388
00389
00390 template <class T, class CombineOp>
00391 static void listCombineGather(List<T>& Value, const CombineOp& cop);
00392
00393
00394 template <class T>
00395 static void listCombineScatter
00396 (
00397 const List<commsStruct>& comms,
00398 List<T>& Value
00399 );
00400
00401
00402 template <class T>
00403 static void listCombineScatter(List<T>& Value);
00404
00405
00406
00407
00408
00409
00410
00411 template <class T>
00412 static void gatherList
00413 (
00414 const List<commsStruct>& comms,
00415 List<T>& Values
00416 );
00417
00418
00419 template <class T>
00420 static void gatherList(List<T>& Values);
00421
00422
00423 template <class T>
00424 static void scatterList
00425 (
00426 const List<commsStruct>& comms,
00427 List<T>& Values
00428 );
00429
00430
00431 template <class T>
00432 static void scatterList(List<T>& Values);
00433 };
00434
00435
00436 inline void Pstream::enlargeBuffer(size_t count)
00437 {
00438 buf_.setSize(max(int(buf_.size() + count), 2*buf_.size()));
00439 }
00440
00441
00442
00443
00444 }
00445
00446
00447
00448 #ifdef NoRepository
00449 # include "gatherScatter.C"
00450 # include "combineGatherScatter.C"
00451 # include "gatherScatterList.C"
00452 #endif
00453
00454
00455
00456
00457 #endif
00458
00459
Copyright © 2000-2007 OpenCFD Ltd