Pstream.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 #include "Pstream.H"
00028 #include "debug.H"
00029 #include "dictionary.H"
00030
00031
00032
00033 defineTypeNameAndDebug(Foam::Pstream, 0);
00034
00035 template<>
00036 const char* Foam::NamedEnum<Foam::Pstream::commsTypes, 3>::names[] =
00037 {
00038 "blocking",
00039 "scheduled",
00040 "nonBlocking"
00041 };
00042
00043 const Foam::NamedEnum<Foam::Pstream::commsTypes, 3>
00044 Foam::Pstream::commsTypeNames;
00045
00046
00047
00048
00049 void Foam::Pstream::setParRun()
00050 {
00051 parRun_ = true;
00052
00053 Pout.prefix() = '[' + name(myProcNo()) + "] ";
00054 Perr.prefix() = '[' + name(myProcNo()) + "] ";
00055 }
00056
00057
00058 void Foam::Pstream::calcLinearComm(const label nProcs)
00059 {
00060 linearCommunication_.setSize(nProcs);
00061
00062
00063 labelList belowIDs(nProcs - 1);
00064 forAll(belowIDs, i)
00065 {
00066 belowIDs[i] = i + 1;
00067 }
00068
00069 linearCommunication_[0] = commsStruct
00070 (
00071 nProcs,
00072 0,
00073 -1,
00074 belowIDs,
00075 labelList(0)
00076 );
00077
00078
00079 for (label procID = 1; procID < nProcs; procID++)
00080 {
00081 linearCommunication_[procID] = commsStruct
00082 (
00083 nProcs,
00084 procID,
00085 0,
00086 labelList(0),
00087 labelList(0)
00088 );
00089 }
00090 }
00091
00092
00093
00094 void Foam::Pstream::collectReceives
00095 (
00096 const label procID,
00097 const List<DynamicList<label> >& receives,
00098 DynamicList<label>& allReceives
00099 )
00100 {
00101 const DynamicList<label>& myChildren = receives[procID];
00102
00103 forAll(myChildren, childI)
00104 {
00105 allReceives.append(myChildren[childI]);
00106 collectReceives(myChildren[childI], receives, allReceives);
00107 }
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void Foam::Pstream::calcTreeComm(label nProcs)
00138 {
00139 label nLevels = 1;
00140 while ((1 << nLevels) < nProcs)
00141 {
00142 nLevels++;
00143 }
00144
00145 List<DynamicList<label> > receives(nProcs);
00146 labelList sends(nProcs, -1);
00147
00148
00149
00150 label offset = 2;
00151 label childOffset = offset/2;
00152
00153 for (label level = 0; level < nLevels; level++)
00154 {
00155 label receiveID = 0;
00156 while (receiveID < nProcs)
00157 {
00158
00159 label sendID = receiveID + childOffset;
00160
00161 if (sendID < nProcs)
00162 {
00163 receives[receiveID].append(sendID);
00164 sends[sendID] = receiveID;
00165 }
00166
00167 receiveID += offset;
00168 }
00169
00170 offset <<= 1;
00171 childOffset <<= 1;
00172 }
00173
00174
00175
00176 List<DynamicList<label> > allReceives(nProcs);
00177 for (label procID = 0; procID < nProcs; procID++)
00178 {
00179 collectReceives(procID, receives, allReceives[procID]);
00180 }
00181
00182
00183 treeCommunication_.setSize(nProcs);
00184
00185 for (label procID = 0; procID < nProcs; procID++)
00186 {
00187 treeCommunication_[procID] = commsStruct
00188 (
00189 nProcs,
00190 procID,
00191 sends[procID],
00192 receives[procID].shrink(),
00193 allReceives[procID].shrink()
00194 );
00195 }
00196 }
00197
00198
00199
00200
00201 void Foam::Pstream::initCommunicationSchedule()
00202 {
00203 calcLinearComm(nProcs());
00204 calcTreeComm(nProcs());
00205 }
00206
00207
00208
00209
00210
00211 int Foam::Pstream::myProcNo_(0);
00212
00213
00214 bool Foam::Pstream::parRun_(false);
00215
00216
00217 Foam::List<int> Foam::Pstream::procIDs_(1, 0);
00218
00219
00220 const int Foam::Pstream::msgType_(1);
00221
00222
00223 Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::linearCommunication_(0);
00224
00225
00226 Foam::List<Foam::Pstream::commsStruct> Foam::Pstream::treeCommunication_(0);
00227
00228
00229
00230
00231 bool Foam::Pstream::floatTransfer
00232 (
00233 debug::optimisationSwitch("floatTransfer", 0)
00234 );
00235
00236
00237
00238 int Foam::Pstream::nProcsSimpleSum
00239 (
00240 debug::optimisationSwitch("nProcsSimpleSum", 16)
00241 );
00242
00243
00244 Foam::Pstream::commsTypes Foam::Pstream::defaultCommsType
00245 (
00246 commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
00247 );
00248
00249
00250
Copyright © 2000-2009 OpenCFD Ltd