PstreamGlobals.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 "PstreamGlobals.H"
00028 #include "IOstreams.H"
00029 #include "Pstream.H"
00030
00031 extern "C" {
00032
00033 #include <linux/gamma/libgamma.h>
00034
00035 }
00036
00037
00038
00039 namespace Foam
00040 {
00041
00042
00043
00044
00045 FixedList<List<List<char> >, 4> PstreamGlobals::recvBuf;
00046
00047
00048 FixedList<labelList, 4> PstreamGlobals::recvBufLen;
00049
00050 labelList PstreamGlobals::recvIndex;
00051 labelList PstreamGlobals::consumeIndex;
00052
00053
00054
00055 uint64_t PstreamGlobals::resizeMessage[PstreamGlobals::resizeMessageLen] =
00056 {
00057 0x7ff7ffffffffffABllu,
00058 0x7ff7ffffffffffCDllu,
00059 0x7ff7ffffffffff12llu,
00060 0x7ff7ffffffffff30llu,
00061 0x7ff7ffffffffff19llu,
00062 0x0000000000000000llu
00063 };
00064
00065
00066
00067 void PstreamGlobals::gammaWait(const label procNo)
00068 {
00069
00070 gamma_wait(procNo, 1);
00071
00072
00073 label ready = PstreamGlobals::consumeIndex[procNo];
00074
00075
00076 if (PstreamGlobals::recvBufLen[ready][procNo] == -2)
00077 {
00078
00079
00080
00081 if (Pstream::debug)
00082 {
00083 Pout<< "PstreamGlobals::gammaWait : "
00084 << "Resize event. consumeIndex:" << ready
00085 << " Restarting receive from " << procNo << endl;
00086 }
00087
00088 PstreamGlobals::recvBufLen[ready][procNo] = -1;
00089 PstreamGlobals::consumeIndex[procNo] =
00090 PstreamGlobals::recvBuf.fcIndex(ready);
00091
00092 gamma_wait(procNo, 1);
00093 }
00094 }
00095
00096
00097
00098 label PstreamGlobals::copyReceive
00099 (
00100 const label procNo,
00101 char* buf,
00102 const label bufSize
00103 )
00104 {
00105
00106 label ready = consumeIndex[procNo];
00107
00108
00109 label receivedLen = recvBufLen[ready][procNo];
00110
00111 if (Pstream::debug)
00112 {
00113 Pout<< "copyReceive : for proc " << procNo
00114 << " copying " << receivedLen << " bytes out of buffer " << ready
00115 << endl;
00116 }
00117
00118 if (receivedLen < 0)
00119 {
00120 FatalErrorIn
00121 (
00122 "Pstream::copyReceive(const label, char*, const label)"
00123 ) << "Illegal message length "
00124 << receivedLen
00125 << " received from proc " << procNo << " into buffer " << ready
00126 << endl
00127 << "This is probably caused by receiving more than is actually"
00128 << " sent (e.g. gather without scatter)." << endl
00129 << abort(FatalError);
00130 }
00131
00132 if (receivedLen > bufSize)
00133 {
00134 FatalErrorIn
00135 (
00136 "Pstream::copyReceive(const label, char*, const label)"
00137 ) << "buffer ("
00138 << bufSize
00139 << ") not large enough for incomming message ("
00140 << receivedLen << ')'
00141 << " received from proc " << procNo << " into buffer " << ready
00142 << abort(FatalError);
00143 }
00144
00145
00146 memcpy
00147 (
00148 buf,
00149 recvBuf[ready][procNo].begin(),
00150 receivedLen
00151 );
00152
00153 recvBufLen[ready][procNo] = -1;
00154
00155 consumeIndex[procNo] = recvBuf.fcIndex(ready);
00156
00157 return receivedLen;
00158 }
00159
00160
00161
00162
00163 label PstreamGlobals::getSizeFromHeader(const char* buf, const label len)
00164 {
00165 if (len != resizeMessageLen*sizeof(uint64_t))
00166 {
00167 return -1;
00168 }
00169
00170 const uint64_t* dPtr = reinterpret_cast<const uint64_t*>(buf);
00171
00172
00173 for (label i = 0; i < resizeMessageLen-1; i++)
00174 {
00175 if (*dPtr++ != resizeMessage[i])
00176 {
00177 return -1;
00178 }
00179 }
00180
00181 return *reinterpret_cast<const label*>(dPtr);
00182 }
00183
00184
00185 void PstreamGlobals::setResizeMessage(const label len)
00186 {
00187 reinterpret_cast<label&>(resizeMessage[resizeMessageLen-1]) = len;
00188 }
00189
00190
00191 label PstreamGlobals::getMaxBufSize(const int procNo)
00192 {
00193 label maxSz = 0;
00194
00195 forAll(recvBuf, i)
00196 {
00197 maxSz = max(maxSz, recvBuf[i][procNo].size());
00198 }
00199 return maxSz;
00200 }
00201
00202
00203
00204
00205 }
00206
00207
Copyright © 2000-2009 OpenCFD Ltd