00001 #ifndef COMLIB_STATS_H
00002 #define COMLIB_STATS_H
00003
00012 #include "charm++.h"
00013 #include "convcomlibmanager.h"
00014
00015 class ComlibLocalStats;
00016
00020 class ComlibComRec {
00021 int nmessages_sent;
00022 int totalbytes_sent;
00023 int nmessages_received;
00024 int totalbytes_received;
00025
00026 unsigned char *procMap;
00027 int npes;
00028
00029 int degree;
00030
00031 CmiBool recorded;
00032
00033 friend class ComlibLocalStats;
00034 public:
00035 ComlibComRec() {
00036 npes = CkNumPes();
00037 procMap = 0;
00038 totalbytes_sent = 0;
00039 totalbytes_received = 0;
00040 nmessages_sent = 0;
00041 nmessages_received = 0;
00042 degree = 0;
00043 recorded = CmiFalse;
00044 }
00045
00046 ComlibComRec(int _npes) {
00047 npes = _npes;
00048 procMap = 0;
00049 totalbytes_sent = 0;
00050 totalbytes_received = 0;
00051 nmessages_sent = 0;
00052 nmessages_received = 0;
00053 degree = 0;
00054 recorded = CmiFalse;
00055 }
00056
00057 ~ComlibComRec() {
00058 if(recorded && procMap)
00059 CmiFree(procMap);
00060
00061 procMap = 0;
00062 }
00063
00064 void setNpes(int _npes) {npes = _npes;}
00065 CmiBool isRecorded() { return recorded;}
00066
00067 int getTotalBytes() { return totalbytes_sent + totalbytes_received; }
00068 int getTotalMessages() { return nmessages_sent + nmessages_received;}
00069 int getDegree() { return degree;}
00070
00071 inline void recordSend(int size, int dest) {
00072 if(!recorded) {
00073 recorded = CmiTrue;
00074 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00075 procMap = (unsigned char*) CmiAlloc(mapsize);
00076 memset(procMap, 0, mapsize);
00077 }
00078
00079 nmessages_sent ++;
00080 totalbytes_sent += size;
00081 int pos = dest / (sizeof(char)*8);
00082 int off = dest % (sizeof(char)*8);
00083
00084 if((procMap[pos] & (1 << off)) == 0) {
00085 degree ++;
00086 procMap[pos] |= 1 << off;
00087 }
00088 }
00089
00090 inline void recordSendM(int size, int *dest_m, int ndest) {
00091
00092 if(!recorded) {
00093 recorded = CmiTrue;
00094 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00095 procMap = (unsigned char*) CmiAlloc(mapsize);
00096 memset(procMap, 0, mapsize);
00097 }
00098
00099 nmessages_sent += ndest;
00100 totalbytes_sent += size * ndest;
00101
00102 for(int count = 0; count < ndest; count ++) {
00103 int pos = dest_m[count] / (sizeof(char)*8);
00104 int off = dest_m[count] % (sizeof(char)*8);
00105
00106 if((procMap[pos] & (1 << off)) == 0) {
00107 degree ++;
00108
00109 procMap[pos] |= 1 << off;
00110 }
00111 }
00112 }
00113
00114 inline void recordRecv(int size, int src) {
00115 if(!recorded) {
00116 recorded = CmiTrue;
00117 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00118 procMap = (unsigned char*) CmiAlloc(mapsize);
00119 memset(procMap, 0, mapsize);
00120 }
00121
00122 nmessages_received ++;
00123 totalbytes_received += size;
00124 int pos = src / (sizeof(char) * 8);
00125 int off = src % (sizeof(char) * 8);
00126
00127 if((procMap[pos] & (1 << off)) == 0) {
00128 degree ++;
00129 procMap[pos] |= 1 << off;
00130 }
00131 }
00132
00133 inline void recordRecvM(int size, int *src_m, int nsrc) {
00134 if(!recorded) {
00135 recorded = CmiTrue;
00136 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00137 procMap = (unsigned char*) CmiAlloc(mapsize);
00138 memset(procMap, 0, mapsize);
00139 }
00140
00141 nmessages_received += nsrc;
00142 totalbytes_received += size * nsrc;
00143
00144 for(int count = 0; count < nsrc; count++) {
00145 int pos = src_m[count] / (sizeof(char) * 8);
00146 int off = src_m[count] % (sizeof(char) * 8);
00147
00148 if((procMap[pos] & (1 << off)) == 0) {
00149 degree ++;
00150
00151 procMap[pos] |= 1 << off;
00152 }
00153 }
00154 }
00155
00156 void reset () {
00157 if(procMap)
00158 CmiFree(procMap);
00159 procMap = 0;
00160 totalbytes_sent = 0;
00161 totalbytes_received = 0;
00162 nmessages_sent = 0;
00163 nmessages_received = 0;
00164 degree = 0;
00165 recorded = CmiFalse;
00166 }
00167
00168 void pup(PUP::er &p) {
00169 p | nmessages_sent;
00170 p | totalbytes_sent;
00171 p | nmessages_received;
00172 p | totalbytes_received;
00173 p | npes;
00174 p | degree;
00175 p | recorded;
00176
00177
00178 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00179 if(p.isUnpacking()) {
00180 if(recorded)
00181 procMap = (unsigned char*) CmiAlloc(mapsize);
00182 }
00183
00184 if(recorded)
00185 p(procMap, mapsize);
00186 }
00187 };
00188
00189
00193 class ComlibLocalStats {
00194 public:
00195 CkVec<ComlibComRec> cdata;
00196 int nstrats;
00197
00198 ComlibLocalStats(int _strats) : cdata(_strats) {
00199 nstrats = _strats;
00200 }
00201
00202 ComlibLocalStats() : cdata(1) {
00203 nstrats = 1;
00204 }
00205
00206 void setNstrats(int nst) {
00207 nstrats = nst;
00208 cdata.resize(nstrats);
00209 }
00210
00211 inline void recordSend(int sid, int size, int dest) {
00212 if(sid >= nstrats) {
00213 nstrats = sid + 1;
00214 cdata.resize(nstrats);
00215 }
00216
00217 cdata[sid].recordSend(size, dest);
00218
00219 }
00220
00221 inline void recordRecv(int sid, int size, int src) {
00222 if(sid >= nstrats) {
00223 nstrats = sid + 1;
00224 cdata.resize(nstrats);
00225 }
00226
00227 cdata[sid].recordRecv(size, src);
00228 }
00229
00230 inline void recordSendM(int sid, int size, int *dest_m, int ndest) {
00231 if(sid >= nstrats) {
00232 nstrats = sid + 1;
00233 cdata.resize(nstrats);
00234 }
00235
00236 cdata[sid].recordSendM(size, dest_m, ndest);
00237 }
00238
00239 inline void recordRecvM(int sid, int size, int *src_m, int nsrc) {
00240 if(sid >= nstrats) {
00241 nstrats = sid + 1;
00242 cdata.resize(nstrats);
00243 }
00244
00245 cdata[sid].recordRecvM(size, src_m, nsrc);
00246 }
00247
00248 inline void reset() {
00249 for(int count = 0; count < nstrats; count++)
00250 cdata[count].reset();
00251 }
00252
00253 void pup(PUP::er &p) {
00254 p | nstrats;
00255 p | cdata;
00256 }
00257
00258 ComlibLocalStats & operator=(ComlibLocalStats &in) {
00259 nstrats = in.nstrats;
00260
00261 cdata.resize(in.cdata.size());
00262 for(int count = 0; count < in.nstrats; count++) {
00263 if(in.cdata[count].isRecorded()) {
00264 memcpy(&cdata[count],&in.cdata[count], sizeof(ComlibComRec));
00265
00266 int npes = in.cdata[count].npes;
00267 int mapsize = (npes / (sizeof(char)*8) + 1) * sizeof(char);
00268 cdata[count].procMap = (unsigned char*) CmiAlloc(mapsize);
00269 memcpy(cdata[count].procMap, in.cdata[count].procMap, mapsize);
00270 }
00271 else
00272 cdata[count].reset();
00273 }
00274
00275 return *this;
00276 }
00277 };
00278
00279 class ComlibGlobalStats {
00280
00281 ComlibLocalStats *statsArr;
00282
00283 public:
00284
00285 ComlibGlobalStats();
00286 ~ComlibGlobalStats() {}
00287
00288 void updateStats(ComlibLocalStats &stats, int pe);
00289
00290
00291 void getAverageStats(int sid, double &, double &, double &, double &);
00292 };
00293
00295 #endif