00001
00013 #ifndef __PATH_HISTORY_H__
00014 #define __PATH_HISTORY_H__
00015
00016 #include <vector>
00017 #include <map>
00018 #include <utility>
00019 #include <cmath>
00020 #include "PathHistory.decl.h"
00021 #include "envelope.h"
00022
00023 #include <pup_stl.h>
00024
00025 void initializeCriticalPath(void);
00026 void useThisCriticalPathForPriorities();
00027 void automaticallySetMessagePriority(envelope *env);
00028
00029 class pathHistoryManager : public CBase_pathHistoryManager {
00030 private:
00031 std::map< int, int> criticalPathForPriorityCounts;
00032
00033 pathInformationMsg *pathForUser;
00034
00035 public:
00036
00037 pathHistoryManager();
00038
00039 pathHistoryManager(CkMigrateMessage *m) : CBase_pathHistoryManager(m) {
00040 CkAbort("pathHistoryManager does not have a working migration constructor.");
00041 }
00042
00043 void pup(PUP::er &p) {
00044 CkAbort("pathHistoryManager cannot be pupped.");
00045 }
00046
00059 void traceCriticalPathBackStepByStep(pathInformationMsg *msg);
00060
00061 void broadcastCriticalPathProjections(pathInformationMsg *msg);
00062
00063 void criticalPathProjectionsDone(CkReductionMsg *msg);
00064
00065 void saveCriticalPathForPriorities(pathInformationMsg *msg);
00066
00068 void useCriticalPathForPriories();
00069
00070 const std::map< int, int> & getCriticalPathForPriorityCounts() const {
00071 return criticalPathForPriorityCounts;
00072 }
00073
00074 };
00075
00091 class MergeablePathHistory {
00092 public:
00093 double timeEntryMethodStarted;
00094
00095 double preceding_path_time;
00096
00097 int sender_pe;
00098 int sender_history_table_idx;
00099
00100 int local_ep;
00101
00102 int hops;
00103
00104 MergeablePathHistory(const envelope *env)
00105 {
00106 sender_pe = env->getSrcPe();
00107 #if USE_CRITICAL_PATH_HEADER_ARRAY
00108 sender_history_table_idx = env->pathHistory.get_sender_history_table_idx();
00109 preceding_path_time = env->pathHistory.getTime();
00110 hops = env->pathHistory.getHops() + 1;
00111 #endif
00112 local_ep = env->getEpIdx();
00113 timeEntryMethodStarted = 0.0;
00114 }
00115
00116 MergeablePathHistory() {
00117 reset();
00118 }
00119
00120 MergeablePathHistory(const MergeablePathHistory ¤t) {
00121 sender_pe = current.sender_pe;
00122 sender_history_table_idx = current.sender_history_table_idx;
00123 local_ep = current.local_ep;
00124 preceding_path_time = get_entry_method_time(current);
00125 hops = current.hops;
00126 }
00127
00128 double get_entry_method_time(const MergeablePathHistory ¤t) {
00129 return (current.preceding_path_time +
00130 CmiWallTimer() - current.timeEntryMethodStarted);
00131 }
00132
00133 void reset(){
00134 sender_pe = -1;
00135 sender_history_table_idx = -1;
00136 local_ep = -1;
00137 preceding_path_time = 0.0;
00138 timeEntryMethodStarted = -1;
00139 hops = 0;
00140 }
00141
00142 void sanity_check(){
00143 if(sender_history_table_idx > -1){
00144 CkAssert(sender_pe < CkNumPes());
00145 CkAssert(sender_pe >= -1);
00146 }
00147 }
00148
00149 void updateMax(const MergeablePathHistory& other){
00150 double now = CmiWallTimer();
00151
00152
00153 if(preceding_path_time + now - timeEntryMethodStarted < other.preceding_path_time)
00154 {
00155
00156 *this = other;
00157 timeEntryMethodStarted = now;
00158 }
00159 }
00160
00161 void updateMax(const envelope* env){
00162 updateMax(MergeablePathHistory(env));
00163 }
00164
00165 double getTotalTime() const{
00166 return preceding_path_time;
00167 }
00168
00170 void printHTMLToString(char* buf) const{
00171 buf[0] = '\0';
00172 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);
00173 }
00174
00175 void setDebug100(){
00176 preceding_path_time = 100.0;
00177 CkPrintf("Setting path length to 100\n");
00178 }
00179
00180 };
00181
00187 class PathHistoryTableEntry {
00188 public:
00189 int sender_pe;
00190 int sender_history_table_idx;
00191 int local_ep;
00192 int local_pe;
00193 private:
00194 double start_time;
00195 double local_path_time;
00196 double preceding_path_time;
00197
00198 public:
00199
00200 PathHistoryTableEntry()
00201 : sender_pe(-1),
00202 sender_history_table_idx(-1),
00203 local_ep(-1),
00204 local_pe(CkMyPe()),
00205 start_time(0.0),
00206 local_path_time(0.0),
00207 preceding_path_time(0.0)
00208 {
00209
00210 }
00211
00212
00214 PathHistoryTableEntry(const MergeablePathHistory& p, double localContribution = 0.0)
00215 : sender_pe(p.sender_pe),
00216 sender_history_table_idx(p.sender_history_table_idx),
00217 local_ep(p.local_ep),
00218 local_pe(CkMyPe()),
00219 start_time(p.timeEntryMethodStarted),
00220 local_path_time(localContribution),
00221 preceding_path_time(p.preceding_path_time)
00222 {
00223
00224 }
00225
00227 PathHistoryTableEntry(const MergeablePathHistory& p, double start, double finish)
00228 : sender_pe(p.sender_pe),
00229 sender_history_table_idx(p.sender_history_table_idx),
00230 local_ep(p.local_ep),
00231 local_pe(CkMyPe()),
00232 start_time(start),
00233 local_path_time(finish-start),
00234 preceding_path_time(p.preceding_path_time)
00235 {
00236
00237 }
00238
00239 void printInfo(const char *prefix = ""){
00240 CkPrintf("%s [sender pe=%d table idx=%d] [local path contribution=%lf ep=%d] [Time= %lf + %lf]\n", prefix,
00241 sender_pe, sender_history_table_idx, local_path_time, local_ep, preceding_path_time, local_path_time);
00242 }
00243
00244
00246 int addToTableAndEnvelope(envelope *env);
00247
00249 int addToTable();
00250
00252 double getTotalTime(){
00253 return local_path_time + preceding_path_time;
00254 }
00255
00256 double get_start_time() const {return start_time;}
00257 double get_local_path_time() const {return local_path_time;}
00258 double get_preceding_path_time() const {return preceding_path_time;}
00259 };
00260
00261
00263 void saveCurrentPathAsUserEvent(const char* prefix="");
00264
00266 void setCurrentlyExecutingPathTo100(void);
00267
00269 void printPathInMsg(void* msg);
00270
00272 void printEPInfo();
00273
00275 void traceCriticalPathBack(CkCallback cb, bool saveToProjectionsTraces = false);
00276
00277
00279 class pathInformationMsg : public CMessage_pathInformationMsg {
00280 public:
00281 PathHistoryTableEntry *history;
00282 int historySize;
00283 int saveAsProjectionsUserEvents;
00284 CkCallback cb;
00285 int table_idx;
00286 int hops;
00287
00288 void printme(){
00289 CkPrintf("Path contains %d entries\n", historySize);
00290 for(int i=historySize-1;i>=0;i--){
00291 CkPrintf("\tPath Step %d: local_path_time=%lf ep=%d starttime=%lf preceding path time=%lf pe=%d\n",i, history[i].get_local_path_time(), history[i].local_ep, history[i].get_start_time(), history[i].get_preceding_path_time(), history[i].local_pe);
00292 }
00293 }
00294 };
00295
00296
00297 CkpvExtern(MergeablePathHistory, currentlyExecutingPath);
00298 CkpvExtern(double, timeEntryMethodStarted);
00299
00301 typedef std::map<int, PathHistoryTableEntry> PathHistoryTableType;
00302 CkpvExtern(PathHistoryTableType, pathHistoryTable);
00304 CkpvExtern(int, pathHistoryTableLastIdx);
00305
00306
00307 extern void resetThisEntryPath();
00308
00309 #if USE_CRITICAL_PATH_HEADER_ARRAY
00310 extern void criticalPath_start(envelope * env);
00311 extern void criticalPath_setep(int epIdx);
00312 extern void criticalPath_send(envelope * sendingEnv);
00313 extern void criticalPath_end();
00314 extern void criticalPath_split();
00315
00316 extern MergeablePathHistory* saveCurrentPath();
00317 extern void mergePathHistory(MergeablePathHistory*);
00318 #define CK_AUTOMATE_PRIORITY(x) automaticallySetMessagePriority(x);
00319 #define CK_CRITICALPATH_SEND(x) criticalPath_send(x);
00320 #define CK_CRITICALPATH_START(x) criticalPath_start(x);
00321 #define CK_CRITICALPATH_SETEP(x) criticalPath_setep(x);
00322 #define CK_CRITICALPATH_END() criticalPath_end();
00323 #define CK_CRITICALPATH_SPLIT() criticalPath_split();
00324
00326 #define MERGE_PATH_DECLARE(x) MergeablePathHistory merge_path_##x
00327
00329 #define MERGE_PATH_RESET(x) merge_path_##x.reset()
00330
00332 #define MERGE_PATH_MAX(x) merge_path_##x.updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_##x;
00333
00335 #define MERGE_PATH_DECLARE_D(x) std::map<int,MergeablePathHistory> merge_path_D_##x
00336
00338 #define MERGE_PATH_RESET_D(x,n) merge_path_D_##x[n].reset()
00339
00341 #define MERGE_PATH_DELETE_D(x,n) merge_path_D_##x.erase(n)
00342
00344 #define MERGE_PATH_DELETE_ALL_D(x) merge_path_D_##x.clear()
00345
00347 #define MERGE_PATH_MAX_D(x,n) merge_path_D_##x[n].updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_D_##x[n];
00348
00349
00350 #else
00351
00353
00354 #define CK_AUTOMATE_PRIORITY(x)
00355 #define CK_CRITICALPATH_SETEP(x)
00356 #define CK_CRITICALPATH_SEND(x)
00357 #define CK_CRITICALPATH_START(x)
00358 #define CK_CRITICALPATH_END()
00359 #define CK_CRITICALPATH_SPLIT()
00360
00361 #define MERGE_PATH_DECLARE(x) ;
00362 #define MERGE_PATH_RESET(x) ;
00363 #define MERGE_PATH_MAX(x) ;
00364 #define MERGE_PATH_DECLARE_D(x) ;
00365 #define MERGE_PATH_RESET_D(x,n) ;
00366 #define MERGE_PATH_DELETE_D(x,n) ;
00367 #define MERGE_PATH_DELETE_ALL_D(x) ;
00368 #define MERGE_PATH_MAX_D(x,n) ;
00369
00370 #endif
00371
00373 #endif