gatherScatter.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
00028
00029
00030
00031
00032
00033 #include "OPstream.H"
00034 #include "IPstream.H"
00035 #include "contiguous.H"
00036
00037
00038
00039 namespace Foam
00040 {
00041
00042
00043
00044 template <class T, class BinaryOp>
00045 void Pstream::gather
00046 (
00047 const List<Pstream::commsStruct>& comms,
00048 T& Value,
00049 const BinaryOp& bop
00050 )
00051 {
00052 if (Pstream::parRun())
00053 {
00054
00055 const commsStruct& myComm = comms[Pstream::myProcNo()];
00056
00057
00058 forAll(myComm.below(), belowI)
00059 {
00060 T value;
00061
00062 if (contiguous<T>())
00063 {
00064 IPstream::read
00065 (
00066 Pstream::scheduled,
00067 myComm.below()[belowI],
00068 reinterpret_cast<char*>(&value),
00069 sizeof(T)
00070 );
00071 }
00072 else
00073 {
00074 IPstream fromBelow(Pstream::scheduled, myComm.below()[belowI]);
00075 fromBelow >> value;
00076 }
00077
00078 Value = bop(Value, value);
00079 }
00080
00081
00082 if (myComm.above() != -1)
00083 {
00084 if (contiguous<T>())
00085 {
00086 OPstream::write
00087 (
00088 Pstream::scheduled,
00089 myComm.above(),
00090 reinterpret_cast<const char*>(&Value),
00091 sizeof(T)
00092 );
00093 }
00094 else
00095 {
00096 OPstream toAbove(Pstream::scheduled, myComm.above());
00097 toAbove << Value;
00098 }
00099 }
00100 }
00101 }
00102
00103
00104 template <class T, class BinaryOp>
00105 void Pstream::gather(T& Value, const BinaryOp& bop)
00106 {
00107 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00108 {
00109 gather(Pstream::linearCommunication(), Value, bop);
00110 }
00111 else
00112 {
00113 gather(Pstream::treeCommunication(), Value, bop);
00114 }
00115 }
00116
00117
00118 template <class T>
00119 void Pstream::scatter(const List<Pstream::commsStruct>& comms, T& Value)
00120 {
00121 if (Pstream::parRun())
00122 {
00123
00124 const commsStruct& myComm = comms[Pstream::myProcNo()];
00125
00126
00127 if (myComm.above() != -1)
00128 {
00129 if (contiguous<T>())
00130 {
00131 IPstream::read
00132 (
00133 Pstream::scheduled,
00134 myComm.above(),
00135 reinterpret_cast<char*>(&Value),
00136 sizeof(T)
00137 );
00138 }
00139 else
00140 {
00141 IPstream fromAbove(Pstream::scheduled, myComm.above());
00142 fromAbove >> Value;
00143 }
00144 }
00145
00146
00147 forAll(myComm.below(), belowI)
00148 {
00149 if (contiguous<T>())
00150 {
00151 OPstream::write
00152 (
00153 Pstream::scheduled,
00154 myComm.below()[belowI],
00155 reinterpret_cast<const char*>(&Value),
00156 sizeof(T)
00157 );
00158 }
00159 else
00160 {
00161 OPstream toBelow(Pstream::scheduled,myComm.below()[belowI]);
00162 toBelow << Value;
00163 }
00164 }
00165 }
00166 }
00167
00168
00169 template <class T>
00170 void Pstream::scatter(T& Value)
00171 {
00172 if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00173 {
00174 scatter(Pstream::linearCommunication(), Value);
00175 }
00176 else
00177 {
00178 scatter(Pstream::treeCommunication(), Value);
00179 }
00180 }
00181
00182
00183
00184
00185 }
00186
00187
Copyright © 2000-2009 OpenCFD Ltd