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