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 "ProcessorTopology_.H"
00027 #include <OpenFOAM/ListOps.H>
00028 #include <OpenFOAM/Pstream.H>
00029 #include "commSchedule.H"
00030
00031
00032
00033 template<class Patch, class ProcPatch>
00034 Foam::labelList Foam::ProcessorTopology<Patch, ProcPatch>::procNeighbours
00035 (
00036 const PtrList<Patch>& patches
00037 )
00038 {
00039
00040
00041 label nNeighbours = 0;
00042
00043 label maxNb = 0;
00044
00045 forAll(patches, patchi)
00046 {
00047 const Patch& patch = patches[patchi];
00048
00049 if (isA<ProcPatch>(patch))
00050 {
00051 const ProcPatch& procPatch =
00052 refCast<const ProcPatch>(patch);
00053
00054 nNeighbours++;
00055
00056 maxNb = max(maxNb, procPatch.neighbProcNo());
00057 }
00058 }
00059
00060 labelList neighbours(nNeighbours);
00061
00062 procPatchMap_.setSize(maxNb + 1);
00063 procPatchMap_ = -1;
00064
00065 nNeighbours = 0;
00066
00067 forAll(patches, patchi)
00068 {
00069 const Patch& patch = patches[patchi];
00070
00071 if (isA<ProcPatch>(patch))
00072 {
00073 const ProcPatch& procPatch =
00074 refCast<const ProcPatch>(patch);
00075
00076 neighbours[nNeighbours++] = procPatch.neighbProcNo();
00077
00078
00079 procPatchMap_[procPatch.neighbProcNo()] = patchi;
00080 }
00081 }
00082
00083 return neighbours;
00084 }
00085
00086
00087
00088
00089
00090 template<class Patch, class ProcPatch>
00091 Foam::ProcessorTopology<Patch, ProcPatch>::ProcessorTopology
00092 (
00093 const PtrList<Patch>& patches
00094 )
00095 :
00096 labelListList(Pstream::nProcs()),
00097 patchSchedule_(2*patches.size())
00098 {
00099 if (Pstream::parRun())
00100 {
00101
00102 operator[](Pstream::myProcNo()) = procNeighbours(patches);
00103
00104
00105 Pstream::gatherList(*this);
00106 Pstream::scatterList(*this);
00107 }
00108
00109 if (Pstream::parRun() && Pstream::defaultCommsType == Pstream::scheduled)
00110 {
00111 label patchEvali = 0;
00112
00113
00114
00115
00116 forAll(patches, patchi)
00117 {
00118 if (!isA<ProcPatch>(patches[patchi]))
00119 {
00120 patchSchedule_[patchEvali].patch = patchi;
00121 patchSchedule_[patchEvali++].init = true;
00122 patchSchedule_[patchEvali].patch = patchi;
00123 patchSchedule_[patchEvali++].init = false;
00124 }
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 label nComms = 0;
00134 forAll(*this, procI)
00135 {
00136 nComms += operator[](procI).size();
00137 }
00138 DynamicList<labelPair> comms(nComms);
00139
00140 forAll(*this, procI)
00141 {
00142 const labelList& nbrs = operator[](procI);
00143
00144 forAll(nbrs, i)
00145 {
00146 if (procI < nbrs[i])
00147 {
00148 comms.append(labelPair(procI, nbrs[i]));
00149 }
00150 }
00151 }
00152 comms.shrink();
00153
00154
00155 labelList mySchedule
00156 (
00157 commSchedule
00158 (
00159 Pstream::nProcs(),
00160 comms
00161 ).procSchedule()[Pstream::myProcNo()]
00162 );
00163
00164 forAll(mySchedule, iter)
00165 {
00166 label commI = mySchedule[iter];
00167
00168
00169 label nb = comms[commI][0];
00170 if (nb == Pstream::myProcNo())
00171 {
00172 nb = comms[commI][1];
00173 }
00174 label patchi = procPatchMap_[nb];
00175
00176 if (Pstream::myProcNo() > nb)
00177 {
00178 patchSchedule_[patchEvali].patch = patchi;
00179 patchSchedule_[patchEvali++].init = true;
00180 patchSchedule_[patchEvali].patch = patchi;
00181 patchSchedule_[patchEvali++].init = false;
00182 }
00183 else
00184 {
00185 patchSchedule_[patchEvali].patch = patchi;
00186 patchSchedule_[patchEvali++].init = false;
00187 patchSchedule_[patchEvali].patch = patchi;
00188 patchSchedule_[patchEvali++].init = true;
00189 }
00190 }
00191 }
00192 else
00193 {
00194 label patchEvali = 0;
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 forAll(patches, patchi)
00205 {
00206 if (!isA<ProcPatch>(patches[patchi]))
00207 {
00208 patchSchedule_[patchEvali].patch = patchi;
00209 patchSchedule_[patchEvali++].init = true;
00210 patchSchedule_[patchEvali].patch = patchi;
00211 patchSchedule_[patchEvali++].init = false;
00212 }
00213 }
00214
00215
00216
00217
00218
00219 forAll(patches, patchi)
00220 {
00221 if (isA<ProcPatch>(patches[patchi]))
00222 {
00223 patchSchedule_[patchEvali].patch = patchi;
00224 patchSchedule_[patchEvali++].init = true;
00225 }
00226 }
00227
00228
00229 forAll(patches, patchi)
00230 {
00231 if (isA<ProcPatch>(patches[patchi]))
00232 {
00233 patchSchedule_[patchEvali].patch = patchi;
00234 patchSchedule_[patchEvali++].init = false;
00235 }
00236 }
00237 }
00238 }
00239
00240
00241