00001
00013 #ifndef __PATH_HISTORY_H__
00014 #define __PATH_HISTORY_H__
00015
00016
00017 #if CMK_WITH_CONTROLPOINT
00018
00019
00020 #include <vector>
00021 #include <map>
00022 #include <utility>
00023 #include <cmath>
00024 #include "PathHistory.decl.h"
00025 #include "envelope.h"
00026
00027 #include <pup_stl.h>
00028
00029
00030
00031 void initializeCriticalPath(void);
00032
00033 void useThisCriticalPathForPriorities();
00034 void automaticallySetMessagePriority(envelope *env);
00035
00036
00037 class pathHistoryManager : public CBase_pathHistoryManager {
00038 private:
00039 std::map< std::pair<int,int>, int> criticalPathForPriorityCounts;
00040
00041 pathInformationMsg *pathForUser;
00042
00043 public:
00044
00045 pathHistoryManager();
00046
00047 pathHistoryManager(CkMigrateMessage *m){
00048 CkAbort("pathHistoryManager does not have a working migration constructor.");
00049 }
00050
00051 void pup(PUP::er &p) {
00052 CkAbort("pathHistoryManager cannot be pupped.");
00053 }
00054
00055
00056
00069 void traceCriticalPathBackStepByStep(pathInformationMsg *msg);
00070
00071
00072
00073 void broadcastCriticalPathProjections(pathInformationMsg *msg);
00074 void criticalPathProjectionsDone(CkReductionMsg *msg);
00075
00076 void saveCriticalPathForPriorities(pathInformationMsg *msg);
00077
00078
00080 void useCriticalPathForPriories();
00081
00082 const std::map< std::pair<int,int>, int> & getCriticalPathForPriorityCounts() const {
00083 return criticalPathForPriorityCounts;
00084 }
00085
00086 };
00087
00088
00089
00105 class MergeablePathHistory {
00106 public:
00107 double timeEntryMethodStarted;
00108
00109 double preceding_path_time;
00110
00111 int sender_pe;
00112 int sender_history_table_idx;
00113
00114 int local_ep;
00115 int local_arr;
00116
00117 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00118 MergeablePathHistory(const envelope *env)
00119 : sender_pe(env->getSrcPe()),
00120 sender_history_table_idx(env->pathHistory.get_sender_history_table_idx()),
00121 local_ep(env->getEpIdx()),
00122 local_arr(env->getArrayMgrIdx()),
00123 preceding_path_time(env->pathHistory.getTime()),
00124 timeEntryMethodStarted(0.0)
00125 {
00126
00127 }
00128 #else
00129 MergeablePathHistory(const envelope *env)
00130 : sender_pe(env->getSrcPe()),
00131 local_ep(env->getEpIdx()),
00132 local_arr(env->getArrayMgrIdx()),
00133 timeEntryMethodStarted(0.0)
00134 {
00135
00136 }
00137 #endif
00138
00139 MergeablePathHistory() {
00140 reset();
00141 }
00142
00143 void reset(){
00144 sender_pe = -1;
00145 sender_history_table_idx = -1;
00146 local_ep = -1;
00147 preceding_path_time = 0.0;
00148 timeEntryMethodStarted = 0.0;
00149 }
00150
00151 void sanity_check(){
00152 if(sender_history_table_idx > -1){
00153 CkAssert(sender_pe < CkNumPes());
00154 CkAssert(sender_pe >= -1);
00155 }
00156
00157
00158
00159
00160
00161
00162 }
00163
00164 void updateMax(const MergeablePathHistory& other){
00165 if(preceding_path_time < other.preceding_path_time)
00166 *this = other;
00167 }
00168
00169
00170 void updateMax(const envelope* env){
00171 updateMax(MergeablePathHistory(env));
00172 }
00173
00174 double getTotalTime() const{
00175 return preceding_path_time;
00176 }
00177
00179 void printHTMLToString(char* buf) const{
00180 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00181 buf[0] = '\0';
00182 sprintf(buf+strlen(buf), "MergeablePathHistory time=%lf send pe=%d idx=%d timeEntryStarted=%lf", (double)preceding_path_time, (int)sender_pe, (int)sender_history_table_idx, (double)timeEntryMethodStarted);
00183 #endif
00184 }
00185
00186 void setDebug100(){
00187 preceding_path_time = 100.0;
00188 CkPrintf("Setting path length to 100\n");
00189 }
00190
00191 };
00192
00193
00200 class PathHistoryTableEntry {
00201 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00202
00203 public:
00204 int sender_pe;
00205 int sender_history_table_idx;
00206 int local_ep;
00207 int local_arr;
00208 int local_pe;
00209
00210 private:
00211 double start_time;
00212 double local_path_time;
00213 double preceding_path_time;
00214
00215 public:
00216
00217 PathHistoryTableEntry()
00218 : sender_pe(-1),
00219 sender_history_table_idx(-1),
00220 start_time(0.0),
00221 local_path_time(0.0),
00222 preceding_path_time(0.0),
00223 local_ep(-1),
00224 local_arr(-1),
00225 local_pe(CkMyPe())
00226 {
00227
00228 }
00229
00230
00232 PathHistoryTableEntry(const MergeablePathHistory& p, double localContribution = 0.0)
00233 : sender_pe(p.sender_pe),
00234 sender_history_table_idx(p.sender_history_table_idx),
00235 local_path_time(localContribution),
00236 preceding_path_time(p.preceding_path_time),
00237 start_time(p.timeEntryMethodStarted),
00238 local_ep(p.local_ep),
00239 local_arr(p.local_arr),
00240 local_pe(CkMyPe())
00241 {
00242
00243 }
00244
00246 PathHistoryTableEntry(const MergeablePathHistory& p, double start, double finish)
00247 : sender_pe(p.sender_pe),
00248 sender_history_table_idx(p.sender_history_table_idx),
00249 local_path_time(finish-start),
00250 preceding_path_time(p.preceding_path_time),
00251 start_time(start),
00252 local_ep(p.local_ep),
00253 local_arr(p.local_arr),
00254 local_pe(CkMyPe())
00255 {
00256
00257 }
00258
00259 void printInfo(char *prefix = ""){
00260 CkPrintf("%s [sender pe=%d table idx=%d] [local path contribution=%lf ep=%d] [Time= %lf + %lf]\n", prefix,
00261 sender_pe, sender_history_table_idx, local_path_time, local_ep, preceding_path_time, local_path_time);
00262 }
00263
00264
00266 int addToTableAndEnvelope(envelope *env);
00267
00269 int addToTable();
00270
00272 double getTotalTime(){
00273 return local_path_time + preceding_path_time;
00274 }
00275
00276 double get_start_time() const {return start_time;}
00277 double get_local_path_time() const {return local_path_time;}
00278 double get_preceding_path_time() const {return preceding_path_time;}
00279 #endif
00280
00281 };
00282
00283
00284
00286 void saveCurrentPathAsUserEvent(const char* prefix="");
00287
00289 void setCurrentlyExecutingPathTo100(void);
00290
00292 void printPathInMsg(void* msg);
00293
00295 void printEPInfo();
00296
00297
00299 void traceCriticalPathBack(CkCallback cb, bool saveToProjectionsTraces = false);
00300
00301
00303 class pathInformationMsg : public CMessage_pathInformationMsg {
00304 public:
00305 PathHistoryTableEntry *history;
00306 int historySize;
00307 int saveAsProjectionsUserEvents;
00308 CkCallback cb;
00309 int table_idx;
00310
00311 void printme(){
00312 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00313 CkPrintf("Path contains %d entries\n", historySize);
00314 for(int i=historySize-1;i>=0;i--){
00315 CkPrintf("\tPath Step %d: local_path_time=%lf arr=%d ep=%d starttime=%lf preceding path time=%lf pe=%d\n",i, history[i].get_local_path_time(), history[i].local_arr, history[i].local_ep, history[i].get_start_time(), history[i].get_preceding_path_time(), history[i].local_pe);
00316 }
00317 #endif
00318 }
00319
00320 };
00321
00322
00323 CkpvExtern(MergeablePathHistory, currentlyExecutingPath);
00324 CkpvExtern(double, timeEntryMethodStarted);
00325
00326
00327 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00328
00329 typedef std::map<int, PathHistoryTableEntry> PathHistoryTableType;
00330 CkpvExtern(PathHistoryTableType, pathHistoryTable);
00332 CkpvExtern(int, pathHistoryTableLastIdx);
00333
00334
00335
00336
00337
00338 extern void resetThisEntryPath();
00339
00340 extern void criticalPath_start(envelope * env);
00341 extern void criticalPath_send(envelope * sendingEnv);
00342 extern void criticalPath_end();
00343 extern void criticalPath_split();
00344
00345
00346
00347
00349
00351 #define MERGE_PATH_DECLARE(x) MergeablePathHistory merge_path_##x
00352
00354 #define MERGE_PATH_RESET(x) merge_path_##x.reset()
00355
00357 #define MERGE_PATH_MAX(x) merge_path_##x.updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_##x;
00358
00359
00360
00362 #define MERGE_PATH_DECLARE_D(x) std::map<int,MergeablePathHistory> merge_path_D_##x
00363
00365 #define MERGE_PATH_RESET_D(x,n) merge_path_D_##x[n].reset()
00366
00368 #define MERGE_PATH_DELETE_D(x,n) merge_path_D_##x.erase(n)
00369
00371 #define MERGE_PATH_DELETE_ALL_D(x) merge_path_D_##x.clear()
00372
00374 #define MERGE_PATH_MAX_D(x,n) merge_path_D_##x[n].updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_D_##x[n];
00375
00376
00377
00378 #else
00379
00380
00382
00383 #define MERGE_PATH_DECLARE(x) ;
00384 #define MERGE_PATH_RESET(x) ;
00385 #define MERGE_PATH_MAX(x) ;
00386 #define MERGE_PATH_DECLARE_D(x) ;
00387 #define MERGE_PATH_RESET_D(x,n) ;
00388 #define MERGE_PATH_DELETE_D(x,n) ;
00389 #define MERGE_PATH_DELETE_ALL_D(x) ;
00390 #define MERGE_PATH_MAX_D(x,n) ;
00391
00392
00393 #endif
00394
00395
00396
00397
00399 #endif
00400 #endif