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