Critical path header changes for the pics merge 93/893/11
authorYanhua Sun <sun51@illinois.edu>
Mon, 2 Nov 2015 17:21:03 +0000 (11:21 -0600)
committerPhil Miller <mille121@illinois.edu>
Tue, 19 Jul 2016 21:37:04 +0000 (16:37 -0500)
Change-Id: Ic4ca573e9dd313a22b9ebe19303ea85f73c4a483

12 files changed:
src/ck-core/charm++.h
src/ck-core/ck.C
src/ck-core/ckreduction.C
src/ck-core/envelope-path.h
src/ck-core/envelope.h
src/ck-core/sdag.h
src/ck-cp/controlPoints.C
src/ck-cp/controlPoints.h
src/ck-cp/pathHistory.C
src/ck-cp/pathHistory.ci
src/ck-cp/pathHistory.h
src/xlat-i/sdag/CEntry.C

index 559e42714c6f8fb61edebb8230d9cb44cac7404b..61a443bd25388417099ae51791208cb73153b7dd 100644 (file)
@@ -1051,6 +1051,7 @@ if(CpvAccess(networkProgressCount) >=  p)  \
 #include "ckarrayreductionmgr.h"
 #include "trace.h"
 #include "envelope.h"
+#include "pathHistory.h"
 
 
 
index 282b45e26ee3b2ef11033b8b6360e75e6cc20303..770376d155e321b2b552c17cbcd25ef27cf8d383 100644 (file)
@@ -10,10 +10,7 @@ clients, including the rest of Charm++, are actually C++.
 #include "trace.h"
 #include "queueing.h"
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
 #include "pathHistory.h"
-void automaticallySetMessagePriority(envelope *env); // in control point framework.
-#endif
 
 #if CMK_LBDB_ON
 #include "LBDatabase.h"
@@ -1223,13 +1220,10 @@ void _processHandler(void *converseMsg,CkCoreState *ck)
                 }
         }
 #endif
-
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  //  CkPrintf("START\n");
-  criticalPath_start(env);
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+  CK_CRITICALPATH_START(env)
 #endif
 
-
   switch(env->getMsgtype()) {
 // Group support
     case BocInitMsg :
@@ -1317,12 +1311,10 @@ void _processHandler(void *converseMsg,CkCoreState *ck)
 #endif
 
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  criticalPath_end();
-  //  CkPrintf("STOP\n");
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+  CK_CRITICALPATH_END()
 #endif
 
-
 }
 
 
@@ -1575,9 +1567,10 @@ static inline int _prepareMsg(int eIdx,void *msg,const CkChareID *pCid)
   env->setMsgtype(ForChareMsg);
   env->setEpIdx(eIdx);
   env->setSrcPe(CkMyPe());
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  criticalPath_send(env);
-  automaticallySetMessagePriority(env);
+
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+  CK_CRITICALPATH_SEND(env)
+  //CK_AUTOMATE_PRIORITY(env)
 #endif
 #if CMK_CHARMDEBUG
   setMemoryOwnedBy(((char*)env)-sizeof(CmiChunkHeader), 0);
@@ -1622,9 +1615,10 @@ static inline int _prepareImmediateMsg(int eIdx,void *msg,const CkChareID *pCid)
   int destPE = _prepareMsg(eIdx, msg, pCid);
   if (destPE != -1) {
     register envelope *env = UsrToEnv(msg);
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-    criticalPath_send(env);
-    automaticallySetMessagePriority(env);
+    //criticalPath_send(env);
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    CK_CRITICALPATH_SEND(env)
+    //CK_AUTOMATE_PRIORITY(env)
 #endif
     CmiBecomeImmediate(env);
   }
@@ -1712,10 +1706,11 @@ static inline envelope *_prepareMsgBranch(int eIdx,void *msg,CkGroupID gID,int t
   nodeRedMgr.setZero();
   env->setRednMgr(nodeRedMgr);
 #endif
-  */
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  criticalPath_send(env);
-  automaticallySetMessagePriority(env);
+*/
+  //criticalPath_send(env);
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+  CK_CRITICALPATH_SEND(env)
+  //CK_AUTOMATE_PRIORITY(env)
 #endif
 #if CMK_CHARMDEBUG
   setMemoryOwnedBy(((char*)env)-sizeof(CmiChunkHeader), 0);
@@ -1727,9 +1722,9 @@ static inline envelope *_prepareMsgBranch(int eIdx,void *msg,CkGroupID gID,int t
 static inline envelope *_prepareImmediateMsgBranch(int eIdx,void *msg,CkGroupID gID,int type)
 {
   envelope *env = _prepareMsgBranch(eIdx, msg, gID, type);
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  criticalPath_send(env);
-  automaticallySetMessagePriority(env);
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+  CK_CRITICALPATH_SEND(env)
+  //CK_AUTOMATE_PRIORITY(env)
 #endif
   CmiBecomeImmediate(env);
   return env;
@@ -2697,6 +2692,4 @@ int isCharmEnvelope(void *msg) {
     return 1;
 }
 
-
 #include "CkMarshall.def.h"
-
index 54a89b9a325a8de48e130c8a3f1e3b5a97e4041b..53b66bf0cfce222eda494c93faec08543c521ab6 100644 (file)
@@ -50,9 +50,7 @@ waits for the migrant contributions to straggle in.
 #include "charm++.h"
 #include "ck.h"
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
 #include "pathHistory.h"
-#endif
 
 #if CMK_DEBUG_REDUCTIONS
 //Debugging messages:
@@ -1068,7 +1066,7 @@ CkReductionMsg *CkReductionMgr::reduceMessages(void)
 
 
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 
 #if CRITICAL_PATH_DEBUG > 3
   CkPrintf("combining critical path information from messages in CkReductionMgr::reduceMessages\n");
@@ -1276,7 +1274,7 @@ void CkReductionMgr :: endArrayReduction(){
        }
 
        
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 
 #if CRITICAL_PATH_DEBUG > 3
        CkPrintf("[%d] combining critical path information from messages in CkReductionMgr::endArrayReduction(). numMsgs=%d\n", CkMyPe(), numMsgs);
@@ -2784,7 +2782,7 @@ CkReductionMsg *CkNodeReductionMgr::reduceMessages(void)
   }
 
        
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 #if CRITICAL_PATH_DEBUG > 3
        CkPrintf("[%d] combining critical path information from messages in CkNodeReductionMgr::reduceMessages(). numMsgs=%d\n", CkMyPe(), nMsgs);
 #endif
index 9962ec56ff092a847f4c509e6d346f5271b38460..371d63865414213a07f0bd43d04175910484088a 100644 (file)
@@ -10,7 +10,7 @@
 
 // #define USE_CRITICAL_PATH_HEADER_ARRAY
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 // This critical path detection is still experimental
 // Added by Isaac (Dec 2008)
 
@@ -167,7 +167,7 @@ class PathHistory {
   }
   
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
   void createPath(PathHistory *parentPath){
     // Note that we are sending a message
     thisMethodSentAMessage = true;
index 82ca3295304ac659e550292ad8413b98a5326825..e42caba52d5dee4190c22efe2a675866be224a8f 100644 (file)
@@ -37,8 +37,6 @@
 #define CK_REDUCTION_MSG_MLOG  0x8
 #endif
 
-//#define USE_CRITICAL_PATH_HEADER_ARRAY
-
 /**
     \addtogroup CriticalPathFramework 
     @{
@@ -59,9 +57,7 @@ class PathHistoryEnvelope {
   int get_sender_history_table_idx() const{ return sender_history_table_idx; }
   void set_sender_history_table_idx(int i) { sender_history_table_idx = i; }
   PathHistoryEnvelope(){ 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
     reset(); 
-#endif
   }
   double getTime() const{ return totalTime; }
   void setTime(double t){ totalTime = t; }
@@ -345,7 +341,7 @@ public:
       env->setRef(0);
       env->setEpIdx(0);
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
       env->pathHistory.reset();
 #endif
 
@@ -478,7 +474,7 @@ public:
          return *(CkArrayIndex *)&type.array.index;
        }
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
  public:
     /** The information regarding the entry methods that executed along the path to this one.
        \addtogroup CriticalPathFramework
index 0833c54df32808fd797f72c39f82749aa2b4820c..6991bb66407de123ea03a2fa2b6a3e226814d8dd 100644 (file)
@@ -29,7 +29,9 @@ namespace SDAG {
 #include <debug-charm.h>
 
 class CkMessage;
-
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+class MergeablePathHistory;
+#endif
 namespace SDAG {
   struct TransportableBigSimLog : public Closure {
     void* log;
@@ -134,7 +136,6 @@ namespace SDAG {
     std::vector<CMK_REFNUM_TYPE> entries, refnums;
     std::vector<int> anyEntries;
     int speculationIndex;
-
     Continuation() : speculationIndex(-1) { }
     Continuation(CkMigrateMessage*) : speculationIndex(-1) { }
 
@@ -156,6 +157,13 @@ namespace SDAG {
       closure.push_back(cl);
     }
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    MergeablePathHistory *saved;
+    void setPath(MergeablePathHistory *tmp) {saved = tmp;}
+
+    MergeablePathHistory *getPath() { return saved;}
+#endif
+
     virtual ~Continuation() {
       for (size_t i = 0; i < closure.size(); i++)
         if (closure[i])
@@ -169,7 +177,9 @@ namespace SDAG {
     int entry;
     CMK_REFNUM_TYPE refnum;
     Closure* cl;
-
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    MergeablePathHistory *savedPath;
+#endif
 #if CMK_BIGSIM_CHARM
     void *bgLog1, *bgLog2;
 #endif
@@ -183,11 +193,25 @@ namespace SDAG {
 #if CMK_BIGSIM_CHARM
       , bgLog1(0)
       , bgLog2(0)
+#endif
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+      ,savedPath(NULL)
 #endif
     {
       if (cl) cl->ref();
     }
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    void  setPath(MergeablePathHistory* p)
+    {
+        savedPath = p;
+    }
+
+    MergeablePathHistory* getPath() 
+    {
+        return savedPath;
+    }
+#endif
     void pup(PUP::er& p) {
       p | entry;
       p | refnum;
index 298b81c26cbb3b05071ba479d574b9c5ba899933..347e8a6584ff40a738547e11e441097673dfca28 100644 (file)
@@ -734,7 +734,7 @@ void controlPointManager::setFrameworkAdvancePhase(bool _frameworkShouldAdvanceP
   void controlPointManager::setTiming(double time){
     currentPhaseData()->times.push_back(time);
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
        
     // First we should register this currently executing message as a path, because it is likely an important one to consider.
     //    registerTerminalEntryMethod();
index a7c4880517926be6446ef127accd2dcab1e8aed9..590deefee9dfd085d9da53ef957a65f550bc2f37 100644 (file)
@@ -181,7 +181,7 @@ public:
   std::map<std::string,int> controlPoints; // The control point values for this phase(don't vary within the phase)
   std::vector<double> times;  // A list of times observed for iterations in this phase
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+#if USE_CRITICAL_PATH_HEADER_ARRAY
   std::vector<PathHistoryTableEntry> criticalPaths;
 #endif
   
index fa596284e1e749ab5306675313a54bf1b4e873d7..bb26b6924e0b0a539a26154719a5e4dcb695f1eb 100644 (file)
@@ -7,67 +7,53 @@
 #include <vector>
 #include <utility>
 
-
-#if CMK_WITH_CONTROLPOINT
-
-
+//#define DEBUG  1
 #include "PathHistory.decl.h"
 #include "LBDatabase.h"
 #include "pathHistory.h"
-//#include "controlPoints.h"
-//#include "arrayRedistributor.h"
-#include <register.h> // for _entryTable
+#include <register.h> 
 
 #include "trace-projections.h"
 
-
 /**
  *  \addtogroup CriticalPathFramework
  *   @{
  *
  */
 
-
-
 /*readonly*/ CProxy_pathHistoryManager pathHistoryManagerProxy;
 
+CkpvDeclare(int, traceLastHop);
+
 CkpvDeclare(MergeablePathHistory, currentlyExecutingPath); // The maximal incoming path for the node
 CkpvDeclare(double, timeEntryMethodStarted);
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
 /** A table to store all the local nodes in the parallel dependency graph */
 CkpvDeclare(PathHistoryTableType, pathHistoryTable);
 /** A counter that defines the new keys for the entries in the pathHistoryTable */
 CkpvDeclare(int, pathHistoryTableLastIdx);
-#endif
 
 
 /// A mainchare that is used just to create a group at startup
 class pathHistoryMain : public CBase_pathHistoryMain {
 public:
   pathHistoryMain(CkArgMsg* args){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
     pathHistoryManagerProxy = CProxy_pathHistoryManager::ckNew();
-#endif
     delete args;
   }
   ~pathHistoryMain(){}
 };
 
+pathHistoryManager::pathHistoryManager(){ }
 
-pathHistoryManager::pathHistoryManager(){
-
-}
-
+/** Trace perform a traversal backwards over the critical path specified as a 
+ * table index for the processor upon which this is called.
+ *
+ * The callback cb will be called with the resulting msg after the path has 
+ * been traversed to its origin.  
+ **/
 
-  /** Trace perform a traversal backwards over the critical path specified as a 
-      table index for the processor upon which this is called.
-      
-      The callback cb will be called with the resulting msg after the path has 
-      been traversed to its origin.  
-  */
- void pathHistoryManager::traceCriticalPathBackStepByStep(pathInformationMsg *msg){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+void pathHistoryManager::traceCriticalPathBackStepByStep(pathInformationMsg *msg){
    int count = CkpvAccess(pathHistoryTable).count(msg->table_idx);
 
 #if DEBUGPRINT > 2
@@ -79,62 +65,58 @@ pathHistoryManager::pathHistoryManager(){
       PathHistoryTableEntry & path = CkpvAccess(pathHistoryTable)[msg->table_idx];
       int idx = path.sender_history_table_idx;
       int pe = path.sender_pe;
-
-#if DEBUGPRINT > 2
-      CkPrintf("Table entry %d on pe %d points to pe=%d idx=%d\n", msg->table_idx, CkMyPe(), pe, idx);
+//#if DEBUGPRINT > 2
+#if DEBUG
+      CkPrintf("Table entry %d on pe %d points to pe=%d idx=%d history size %d \n", msg->table_idx, CkMyPe(), pe, idx, msg->historySize);
 #endif
 
       // Make a copy of the message as we forward it along
       pathInformationMsg *newmsg = new(msg->historySize+1) pathInformationMsg;
       for(int i=0;i<msg->historySize;i++){
-       newmsg->history[i] = msg->history[i];
+          newmsg->history[i] = msg->history[i];
       }
       newmsg->history[msg->historySize] = path;
       newmsg->historySize = msg->historySize+1;
       newmsg->saveAsProjectionsUserEvents = msg->saveAsProjectionsUserEvents;
       newmsg->cb = msg->cb;
+      newmsg->hops = msg->hops -1;
       newmsg->table_idx = idx;
         
-      if(idx > -1 && pe > -1){
-       // Not yet at origin, keep tracing the path back
-       CkAssert(pe < CkNumPes() && pe >= 0);
-       thisProxy[pe].traceCriticalPathBackStepByStep(newmsg);
+      if(msg->hops > 0 ){
+          // Not yet at origin, keep tracing the path back
+          CkAssert(pe < CkNumPes() && pe >= 0);
+          thisProxy[pe].traceCriticalPathBackStepByStep(newmsg);
       } else {
-       CkPrintf("Traced critical path back to its origin.\n");
-       if(msg->saveAsProjectionsUserEvents){
-
-         // Keep a message for returning to the user's callback
-         pathForUser = new(msg->historySize+1) pathInformationMsg;
-         for(int i=0;i<msg->historySize;i++){
-           pathForUser->history[i] = msg->history[i];
-         }
-         pathForUser->history[msg->historySize] = path;
-         pathForUser->historySize = msg->historySize+1;
-         pathForUser->saveAsProjectionsUserEvents = msg->saveAsProjectionsUserEvents;
-         pathForUser->cb = msg->cb;
-         pathForUser->table_idx = idx;
-         
-         CkPrintf("Broadcasting it to all PE\n");
-         thisProxy.broadcastCriticalPathProjections(newmsg);
-       } else {
-         newmsg->cb.send(newmsg);
-       }
+          if(msg->saveAsProjectionsUserEvents){
+
+              // Keep a message for returning to the user's callback
+              pathForUser = new(msg->historySize+1) pathInformationMsg;
+              for(int i=0;i<msg->historySize;i++){
+                  pathForUser->history[i] = msg->history[i];
+              }
+              pathForUser->history[msg->historySize] = path;
+              pathForUser->historySize = msg->historySize+1;
+              pathForUser->saveAsProjectionsUserEvents = msg->saveAsProjectionsUserEvents;
+              pathForUser->cb = msg->cb;
+              pathForUser->table_idx = idx;
+
+              CkPrintf("Broadcasting it to all PE\n");
+              thisProxy.broadcastCriticalPathProjections(newmsg);
+          } else {
+              newmsg->cb.send(newmsg);
+          }
 
       }
     } else {
-      CkAbort("ERROR: Traced critical path back to a nonexistent table entry.\n");
+        CkAbort("ERROR: Traced critical path back to a nonexistent table entry.\n");
     }
 
     delete msg;
-#else
-    CkAbort("Shouldn't call pathHistoryManager::traceCriticalPathBack when critical path detection is not enabled");
-#endif
   }
 
 
 void pathHistoryManager::broadcastCriticalPathProjections(pathInformationMsg *msg){
 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   CkPrintf("[%d] Received broadcast of critical path\n", CkMyPe());
   int me = CkMyPe();
   int intersectsLocalPE = false;
@@ -146,7 +128,6 @@ void pathHistoryManager::broadcastCriticalPathProjections(pathInformationMsg *ms
       // Part of critical path is local
       // Create user event for it
 
-      //      CkPrintf("\t[%d] Path Step %d: local_path_time=%lf arr=%d ep=%d starttime=%lf preceding path time=%lf pe=%d\n",CkMyPe(), i, msg->history[i].get_local_path_time(), msg-> history[i].local_arr, msg->history[i].local_ep, msg->history[i].get_start_time(), msg->history[i].get_preceding_path_time(), msg->history[i].local_pe);
       traceUserBracketEvent(32000, msg->history[i].get_start_time(), msg->history[i].get_start_time() + msg->history[i].get_local_path_time());
 
       intersectsLocalPE = true;
@@ -183,35 +164,29 @@ void pathHistoryManager::broadcastCriticalPathProjections(pathInformationMsg *ms
   CkCallback cb(CkIndex_pathHistoryManager::criticalPathProjectionsDone(NULL),thisProxy[0]); 
   contribute(sizeof(int), &data, CkReduction::sum_int, cb);
 
-#endif
 
 }
 
 void pathHistoryManager::criticalPathProjectionsDone(CkReductionMsg *msg){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   CkPrintf("[%d] All PEs have received the critical path information. Sending critical path to user supplied callback.\n", CkMyPe());
   pathForUser->cb.send(pathForUser);
   pathForUser = NULL;
-#endif
 }
 
-
-
-
 /// An interface callable by the application.
 void useThisCriticalPathForPriorities(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   pathHistoryManagerProxy.ckLocalBranch()->useCriticalPathForPriories();
-#endif
 }
 
 
 /// Callable from inside charm++ delivery mechanisms (after envelope contains epIdx):
 void automaticallySetMessagePriority(envelope *env){
-  #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-
-#if DEBUG
-  if(env->getPriobits() == 8*sizeof(int)){
+    int ep = env->getEpIdx();
+    if (ep==CkIndex_CkArray::recvBroadcast(0))
+        ep = env->getsetArrayBcastEp();
+#if DEBUG 
+    CkPrintf("----------- ep = %d  %s \n", ep, _entryTable[ep]->name); 
+    if(env->getPriobits() == 8*sizeof(int)){
     CkPrintf("[%d] priorities for env=%p are integers\n", CkMyPe(), env);
   } else if(env->getPriobits() == 0) {
     CkPrintf("[%d] priorities for env=%p are not allocated in message\n", CkMyPe(), env);
@@ -220,85 +195,58 @@ void automaticallySetMessagePriority(envelope *env){
   }
 #endif
   
-  
-  const std::map< std::pair<int,int>, int> & criticalPathForPriorityCounts = pathHistoryManagerProxy.ckLocalBranch()->getCriticalPathForPriorityCounts();
-  
+  const std::map< int, int> & criticalPathForPriorityCounts = pathHistoryManagerProxy.ckLocalBranch()->getCriticalPathForPriorityCounts();
+
   if(criticalPathForPriorityCounts.size() > 0 && env->getPriobits() == 8*sizeof(int)) {
-    
     switch(env->getMsgtype()) {
     case ForArrayEltMsg:
     case ForIDedObjMsg:
     case ForChareMsg:
-      {        
-       const int ep = env->getsetArrayEp();
-       const int arr = env->getArrayMgrIdx();
-       
-       const std::pair<int,int> k = std::make_pair(arr, ep);
-       const int count = criticalPathForPriorityCounts.count(k);
-       
+    case ForNodeBocMsg:
+    case ForBocMsg:
+    case ArrayEltInitMsg:
+        {        
+          const int arr = env->getArrayMgrIdx();
+          const int count = criticalPathForPriorityCounts.count(ep);
 #if DEBUG
-       CkPrintf("[%d] destination array,ep occurs %d times along stored critical path\n", CkMyPe(), count);
+          CkPrintf("[%d] destination array,ep occurs %d times along stored critical path\n", CkMyPe(), count);
 #endif
        
-       if(count > 0){
-         // Set the integer priority to high
-#if DEBUG
-         CkPrintf("Prio auto high\n");
+          if(count > 0){
+              // Set the integer priority to high
+#if DEBUG 
+              CkPrintf("Prio auto high %d  %s \n", ep, _entryTable[ep]->name);
 #endif
-         *(int*)(env->getPrioPtr()) = -5;
-       } else {
-         // Set the integer priority to low
-#if DEBUG
-         CkPrintf("Prio auto low: %d,%d\n", arr, ep);
+              *(int*)(env->getPrioPtr()) = -5;
+          } else {
+              // Set the integer priority to low
+#if DEBUG 
+              CkPrintf("Prio auto low: %d,%d\n", arr, ep);
 #endif
-         *(int*)(env->getPrioPtr()) = 5;
-       }
-       
+              *(int*)(env->getPrioPtr()) = 0;
+          }
+
       }
       break;
       
-    case ForNodeBocMsg:
-      CkPrintf("Can't Critical Path Autoprioritize a ForNodeBocMsg\n");    
-      break;
-      
-    case ForBocMsg:
-      CkPrintf("Can't Critical Path Autoprioritize a ForBocMsg\n");
-      break;
-      
-    case ArrayEltInitMsg:
-      // Don't do anything special with these
-      CkPrintf("Can't Critical Path Autoprioritize a ArrayEltInitMsg\n");
-      break;
-      
     default:
-      CkPrintf("Can't Critical Path Autoprioritize messages of [unknown type]\n");
+      //CkPrintf("Can't Critical Path Autoprioritize messages of [unknown type]\n");
       break;
     }
       
   }
-
-#endif
 }
 
-
-
 void pathHistoryManager::useCriticalPathForPriories(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-
   // Request a critical path that will be stored everywhere for future use in autotuning message priorities
-  
   // The resulting critical path should be broadcast to saveCriticalPathForPriorities() on all PEs
   CkCallback cb(CkIndex_pathHistoryManager::saveCriticalPathForPriorities(NULL),thisProxy); 
   traceCriticalPathBack(cb, false);
-#endif  
 }
 
-
-
 void pathHistoryManager::saveCriticalPathForPriorities(pathInformationMsg *msg){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-
-  CkPrintf("[%d] saveCriticalPathForPriorities() Receiving critical paths\n", CkMyPe());
+  //CkPrintf("[%d] saveCriticalPathForPriorities() Receiving critical paths\n", CkMyPe());
   fflush(stdout);
   
   criticalPathForPriorityCounts.clear();
@@ -308,130 +256,80 @@ void pathHistoryManager::saveCriticalPathForPriorities(pathInformationMsg *msg){
     
     PathHistoryTableEntry &e = msg->history[i];
     
+//#if 1 
 #if DEBUG
     if(CkMyPe() == 0){
-      CkPrintf("\t[%d] Path Step %d: local_path_time=%lf arr=%d ep=%d starttime=%lf preceding path time=%lf pe=%d\n",CkMyPe(), i, e.get_local_path_time(), msg-> history[i].local_arr, e.local_ep, e.get_start_time(), e.get_preceding_path_time(), e.local_pe);
+        char name[100];
+        if(e.local_ep >=0)
+            strcpy(name, _entryTable[e.local_ep]->name);
+        else
+            strcpy(name, "unknow");
+
+      CkPrintf("\t[%d] Path Step %d: local_path_time=%lf ep=%d starttime=%lf preceding path time=%lf pe=%d name=%s\n",CkMyPe(), i, e.get_local_path_time(), e.local_ep, e.get_start_time(), e.get_preceding_path_time(), e.local_pe, name);
     }
 #endif
     
-    const std::pair<int,int> k = std::make_pair(e.local_arr, e.local_ep);
-    if(criticalPathForPriorityCounts.count(k) == 1)
-      criticalPathForPriorityCounts[k]++;
+    if(criticalPathForPriorityCounts.count(e.local_ep) == 1)
+      criticalPathForPriorityCounts[e.local_ep]++;
     else
-      criticalPathForPriorityCounts[k] = 1;  
+      criticalPathForPriorityCounts[e.local_ep] = 1;  
   }
-  
-
-
 
   // print out the list just for debugging purposes
   if(CkMyPe() == 0){
-    std::map< std::pair<int,int>, int>::iterator iter;
+    std::map< int, int>::iterator iter;
     for(iter=criticalPathForPriorityCounts.begin();iter!=criticalPathForPriorityCounts.end();++iter){
-      const std::pair<int,int> k = iter->first;
+      int epidx = iter->first;
       const int c = iter->second;
 
-      CkPrintf("[%d] On critical path EP %d,%d occurs %d times\n", CkMyPe(), k.first, k.second, c);
+#if DEBUG
+      CkPrintf("[%d] On critical path EP %d occurs %d times\n", CkMyPe(), epidx, c);
+#endif
 
     }
   }
-
-#endif
-}
-
-
-
-
-
-
-
-
-
-
-
-void initializeCriticalPath(void){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  CkpvInitialize(MergeablePathHistory, currentlyExecutingPath); // The maximal incoming path for the node
-  CkpvInitialize(double, timeEntryMethodStarted);
-  CkpvAccess(timeEntryMethodStarted) = 0.0;
-
-
-  CkpvInitialize(PathHistoryTableType, pathHistoryTable);
-  CkpvInitialize(int, pathHistoryTableLastIdx);
-  CkpvAccess(pathHistoryTableLastIdx) = 0;
-#endif
-}
-
-
-
-
-
-
-
-
-
-
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-// The PathHistoryEnvelope class is disabled if USE_CRITICAL_PATH_HEADER_ARRAY isn't defined
-void PathHistoryEnvelope::reset(){
-  totalTime = 0.0;
-  sender_history_table_idx = -1;
-}
-
-  
-void PathHistoryEnvelope::print() const {
-  CkPrintf("print() is not implemented\n");
 }
 
-/// Write a description of the path into the beginning of the provided buffer. The buffer ought to be large enough.
-
-  
-void PathHistoryEnvelope::incrementTotalTime(double time){
-  totalTime += time;
-}
-
-
-
-void PathHistoryEnvelope::setDebug100(){
-  totalTime = 100.0;   
-}
-
-
-
 /// Add an entry for this path history into the table, and write the corresponding information into the outgoing envelope
 int PathHistoryTableEntry::addToTableAndEnvelope(envelope *env){
   // Add to table
+#if USE_CRITICAL_PATH_HEADER_ARRAY
   int new_idx = addToTable();
 
   // Fill in outgoing envelope
   CkAssert(env != NULL);
   env->pathHistory.set_sender_history_table_idx(new_idx);
   env->pathHistory.setTime(local_path_time + preceding_path_time);
-
-#if 0
-  // Create a user event for projections
-  char *note = new char[4096];
-  sprintf(note, "addToTableAndEnvelope<br> ");
-  env->pathHistory.printHTMLToString(note+strlen(note));
-  traceUserSuppliedNote(note); // stores a copy of the string
-  delete[] note;
-#endif  
-
+#if DEBUG
+  if(local_path_time > 0.1)
+      CkPrintf("------########## %d generating new msg env   critical path length %f:%f:%f app time %f id:%d\n", CkMyPe(), local_path_time , preceding_path_time, local_path_time+preceding_path_time, CkWallTimer(), new_idx);
+#endif
   return new_idx;
+#endif
 }
-  
 
 /// Add an entry for this path history into the table. Returns the index in the table for it.
 int PathHistoryTableEntry::addToTable(){
   int new_idx = CkpvAccess(pathHistoryTableLastIdx) ++;
   CkpvAccess(pathHistoryTable)[new_idx] = *this;
+#if DEBUG
+  CkPrintf("-------- add to entry  %d   ----- %d  %d %d  \n", new_idx, local_ep,  local_pe, sender_history_table_idx); 
+#endif
   return new_idx;
 }
-#endif
 
+void initializeCriticalPath(void){
+  CkpvInitialize(MergeablePathHistory, currentlyExecutingPath); // The maximal incoming path for the node
+  CkpvInitialize(double, timeEntryMethodStarted);
+  CkpvAccess(timeEntryMethodStarted) = 0.0;
+  CkpvInitialize(PathHistoryTableType, pathHistoryTable);
+  CkpvInitialize(int, pathHistoryTableLastIdx);
+  CkpvAccess(pathHistoryTableLastIdx) = 0;
+  CkpvInitialize(int, traceLastHop);
+  CkpvAccess(traceLastHop) = 0;
+}
 
 
-  
 void resetThisEntryPath(void) {
   CkpvAccess(currentlyExecutingPath).reset();
 }
@@ -460,68 +358,53 @@ void  saveCurrentPathAsUserEvent(const char* prefix){
 
 
 void setCurrentlyExecutingPathTo100(void){
-  CkpvAccess(currentlyExecutingPath).setDebug100();
+    CkpvAccess(currentlyExecutingPath).setDebug100();
 }
 
-
 /// Acquire the critical path and deliver it to the user supplied callback
 void traceCriticalPathBack(CkCallback cb, bool saveToProjectionsTraces){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-  pathInformationMsg *newmsg = new(0) pathInformationMsg;
-  newmsg->historySize = 0;
-  newmsg->cb = cb;
-  newmsg->saveAsProjectionsUserEvents = saveToProjectionsTraces;
-  newmsg->table_idx = CkpvAccess(currentlyExecutingPath).sender_history_table_idx;
-  int pe = CkpvAccess(currentlyExecutingPath).sender_pe;
-  CkPrintf("Starting tracing of critical path from pe=%d table_idx=%d\n", pe,  CkpvAccess(currentlyExecutingPath).sender_history_table_idx);
-  CkAssert(pe < CkNumPes() && pe >= 0);
-  pathHistoryManagerProxy[pe].traceCriticalPathBackStepByStep(newmsg);
-#else
-  pathInformationMsg * pathForUser = new(0) pathInformationMsg;  
-  pathForUser->historySize = 0;                                                                                        
-  pathForUser->cb = CkCallback();                                                                                                      
-  pathForUser->table_idx = -1;      
-  cb.send(pathForUser);  
-#endif
+    pathInformationMsg *newmsg = new(0) pathInformationMsg;
+    newmsg->historySize = 0;
+    newmsg->cb = cb;
+    newmsg->hops = CkpvAccess(currentlyExecutingPath).hops - CkpvAccess(traceLastHop) -1;
+    CkpvAccess(traceLastHop) = CkpvAccess(currentlyExecutingPath).hops;
+    newmsg->saveAsProjectionsUserEvents = saveToProjectionsTraces;
+    newmsg->table_idx = CkpvAccess(currentlyExecutingPath).sender_history_table_idx;
+    int pe = CkpvAccess(currentlyExecutingPath).sender_pe;
+    //CkPrintf("Starting tracing of critical path  current PE : %d, current entry %d to pe=%d table_idx=%d\n", CkMyPe(), pe,  CkpvAccess(currentlyExecutingPath).local_ep, CkpvAccess(currentlyExecutingPath).sender_history_table_idx);
+    CkAssert(pe < CkNumPes() && pe >= 0);
+    pathHistoryManagerProxy[pe].traceCriticalPathBackStepByStep(newmsg);
 }
 
-
-
-// void  printPathInMsg(void* msg){
-//   envelope *env = UsrToEnv(msg);
-//   env->printPath();
-// }
-
-
-
 /// A debugging routine that prints the number of EPs for the program, and the size of the envelope's path fields
 void  printEPInfo(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   CkPrintf("printEPInfo():\n");
   CkPrintf("There are %d EPs\n", (int)_entryTable.size());
   for (int epIdx=0;epIdx<_entryTable.size();epIdx++)
     CkPrintf("EP %d is %s\n", epIdx, _entryTable[epIdx]->name);
-#endif
 }
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 
-
-
-/// Save information about the critical path contained in the message that is about to execute.
-void criticalPath_start(envelope * env){ 
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
+void criticalPath_setep(int epIdx){ 
+    CkpvAccess(currentlyExecutingPath).local_ep  = epIdx;
 #if DEBUG
-  CkPrintf("criticalPath_start(envelope * env) srcpe=%d sender table idx=%d  time=%lf\n", env->getSrcPe(),  env->pathHistory.get_sender_history_table_idx(), env->pathHistory.getTotalTime() );
+    if(epIdx >= 0)
+        CkPrintf(" setting current method name %d %s",epIdx,  _entryTable[epIdx]->name);  
+    CkPrintf("\n");
 #endif
+}
 
+/// Save information about the critical path contained in the message that is about to execute.
+void criticalPath_start(envelope * env){ 
   CkpvAccess(currentlyExecutingPath).sender_pe = env->getSrcPe();
   CkpvAccess(currentlyExecutingPath).sender_history_table_idx = env->pathHistory.get_sender_history_table_idx();
   CkpvAccess(currentlyExecutingPath).preceding_path_time = env->pathHistory.getTotalTime();
+  CkpvAccess(currentlyExecutingPath).hops =  env->pathHistory.getHops() + 1;
 
   CkpvAccess(currentlyExecutingPath).sanity_check();
   
-  CkpvAccess(currentlyExecutingPath).local_ep  = -1;
-  CkpvAccess(currentlyExecutingPath).local_arr = -1;
+  CkpvAccess(currentlyExecutingPath).local_ep  = env->getEpIdx();
 
   double now = CmiWallTimer();
   CkpvAccess(currentlyExecutingPath).timeEntryMethodStarted = now;
@@ -529,58 +412,54 @@ void criticalPath_start(envelope * env){
 
   switch(env->getMsgtype()) {
   case ForArrayEltMsg:
-    //    CkPrintf("Critical Path Detection handling a ForArrayEltMsg\n");    
+  case ArrayEltInitMsg:
     CkpvAccess(currentlyExecutingPath).local_ep = env->getsetArrayEp();
-    CkpvAccess(currentlyExecutingPath).local_arr = env->getArrayMgrIdx();
-    
     break;
 
   case ForNodeBocMsg:
-    //CkPrintf("Critical Path Detection handling a ForNodeBocMsg\n");    
-    break;
-
-  case ForChareMsg:
-    //CkPrintf("Critical Path Detection handling a ForChareMsg\n");        
     break;
 
   case ForBocMsg:
     //CkPrintf("Critical Path Detection handling a ForBocMsg\n");    
     break;
 
-  case ArrayEltInitMsg:
-    // Don't do anything special with these
+  case ForChareMsg:
+    //CkPrintf("Critical Path Detection handling a ForChareMsg\n");        
     break;
 
   default:
-    CkPrintf("Critical Path Detection can't yet handle message type %d\n", (int)env->getMsgtype());
+    break;
+    //CkPrintf("Critical Path Detection can't yet handle message type %d\n", (int)env->getMsgtype());
   }
-  
-  
-
-  saveCurrentPathAsUserEvent("criticalPath_start()<br> ");
 
+  if(CkpvAccess(currentlyExecutingPath).local_ep == CkIndex_CkArray::recvBroadcast(0))
+      CkpvAccess(currentlyExecutingPath).local_ep = env->getsetArrayBcastEp();
 
+#if DEBUG
+  CkPrintf("criticalPath_start(envelope * env) srcpe=%d sender table idx=%d  time=%lf current ep=%d ", env->getSrcPe(),  env->pathHistory.get_sender_history_table_idx(), env->pathHistory.getTotalTime(), env->getEpIdx() );
+  if(env->getEpIdx() >= 0)
+      CkPrintf(" current method name %d  %s", CkpvAccess(currentlyExecutingPath).local_ep, _entryTable[CkpvAccess(currentlyExecutingPath).local_ep]->name);  
+  CkPrintf("\n");
 #endif
+
+  saveCurrentPathAsUserEvent("criticalPath_start()<br> ");
 }
 
 
 /// Modify the envelope of a message that is being sent for critical path detection and store an entry in a table on this PE.
 void criticalPath_send(envelope * sendingEnv){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
 #if DEBUG
   CkPrintf("criticalPath_send(envelope * sendingEnv)\n");
 #endif
   double now = CmiWallTimer();
   PathHistoryTableEntry entry(CkpvAccess(currentlyExecutingPath), CkpvAccess(timeEntryMethodStarted), now);
   entry.addToTableAndEnvelope(sendingEnv);
-  
-#endif
+  sendingEnv->pathHistory.setHops(CkpvAccess(currentlyExecutingPath).hops);
+  automaticallySetMessagePriority(sendingEnv);
 }
 
-
 /// Handle the end of the entry method in the critical path detection processes. This should create a forward dependency for the object.
 void criticalPath_end(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   saveCurrentPathAsUserEvent("criticalPath_end()<br> ");
 
   CkpvAccess(currentlyExecutingPath).reset();
@@ -588,41 +467,40 @@ void criticalPath_end(){
 #if DEBUG
   CkPrintf("criticalPath_end()\n");
 #endif
-
-#endif
 }
 
-
+#endif
 
 /// Split an entry method invocation into multiple logical tasks for the critical path analysis.
 /// SDAG doen's break up the code in useful ways, so I'll make it add calls to this in the generated code.
 void criticalPath_split(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
   saveCurrentPathAsUserEvent("criticalPath_split()<br> ");
 
   // save an entry in the table
   double now = CmiWallTimer();
   PathHistoryTableEntry entry(CkpvAccess(currentlyExecutingPath), now-CkpvAccess(timeEntryMethodStarted) );
   int tableidx = entry.addToTable();
-
   // end the old task
-
-  
   // start the new task
   CkpvAccess(currentlyExecutingPath).sender_pe = CkMyPe();
   CkpvAccess(currentlyExecutingPath).sender_history_table_idx = tableidx;
   CkpvAccess(currentlyExecutingPath).preceding_path_time = entry.getTotalTime();
   CkpvAccess(currentlyExecutingPath).timeEntryMethodStarted = now;
   CkpvAccess(timeEntryMethodStarted) = now;
-#endif
 }
 
+MergeablePathHistory* saveCurrentPath()
+{
+    MergeablePathHistory *savedPath = new MergeablePathHistory(CkpvAccess(currentlyExecutingPath));
+    return savedPath;
+}
 
 
-
+void mergePathHistory(MergeablePathHistory* tmp)
+{
+    CkpvAccess(currentlyExecutingPath).updateMax(*tmp);
+}
 
 #include "PathHistory.def.h"
 
 /*! @} */
-
-#endif
index 880fbfd39c36ad139608794eb8ea64a0cd352879..6cba8006e94b6138bae80ec0a356b8b18c55a06d 100644 (file)
@@ -15,7 +15,7 @@ module PathHistory {
   };
 
 
- group pathHistoryManager {
+ group [migratable] pathHistoryManager {
      entry pathHistoryManager();
 
      entry void traceCriticalPathBackStepByStep(pathInformationMsg *msg);
index 6400ba2d01bc4b337c39b706a959fddbb815d2d2..2e799f73305fc03bb6af3d97e7f917b36d994be7 100644 (file)
@@ -1,22 +1,18 @@
 
 /**     @defgroup CriticalPathFramework Critical Path Detection
+ *
+ *      Usable for determining the critical paths in Charm++, Charisma, and SDAG programs.
+ */
 
-       Usable for determining the critical paths in Charm++, Charisma, and SDAG programs. 
-*/
-
-/** 
-
-    @addtogroup CriticalPathFramework
-    @{
-
-*/
+/**
+ *
+ *    @addtogroup CriticalPathFramework
+ *    @{
+ *
+ */
 #ifndef __PATH_HISTORY_H__
 #define __PATH_HISTORY_H__
 
-
-#if CMK_WITH_CONTROLPOINT
-
-
 #include <vector>
 #include <map>
 #include <utility>
 #include <pup_stl.h>
 
 
-
 void initializeCriticalPath(void);
-
 void useThisCriticalPathForPriorities();
 void automaticallySetMessagePriority(envelope *env);
 
-
 class pathHistoryManager : public CBase_pathHistoryManager {
- private:
-  std::map< std::pair<int,int>, int> criticalPathForPriorityCounts;
-  
-  pathInformationMsg *pathForUser; // A place to store the path while we perform a broadcast and reduction to save projections user events.
-
- public:
+private:
+    std::map< int, int> criticalPathForPriorityCounts;
 
-  pathHistoryManager();
-
-  pathHistoryManager(CkMigrateMessage *m){
-    CkAbort("pathHistoryManager does not have a working migration constructor."); 
-  }
-  
-  void pup(PUP::er &p) { 
-    CkAbort("pathHistoryManager cannot be pupped.");
-  } 
+    pathInformationMsg *pathForUser; // A place to store the path while we perform a broadcast and reduction to save projections user events.
 
+public:
 
+    pathHistoryManager();
 
- /** Trace perform a traversal backwards over the critical path specified as a 
-      table index for the processor upon which this is called.
+    pathHistoryManager(CkMigrateMessage *m) : CBase_pathHistoryManager(m) {
+        CkAbort("pathHistoryManager does not have a working migration constructor.");
+    }
 
-      If msg->saveAsProjectionsUserEvents is true then the resulting path will be 
-      broadcast to broadcastCriticalPathProjections() which will then call a 
-      reduction to criticalPathProjectionsDone() which will call the user supplied 
-      callback.
-      
-      Otherwise, the callback cb will be called with the resulting msg after the path has 
-      been traversed to its origin.  
+    void pup(PUP::er &p) {
+        CkAbort("pathHistoryManager cannot be pupped.");
+    }
 
-  */
+    /** Trace perform a traversal backwards over the critical path specified as a
+     * table index for the processor upon which this is called.
+     *
+     * * If msg->saveAsProjectionsUserEvents is true then the resulting path will be
+     * broadcast to broadcastCriticalPathProjections() which will then call a
+     * reduction to criticalPathProjectionsDone() which will call the user supplied
+     * callback.
+     *
+     * Otherwise, the callback cb will be called with the resulting msg after the path has
+     * been traversed to its origin.
+     *
+     */
  void traceCriticalPathBackStepByStep(pathInformationMsg *msg);
 
-
-
  void broadcastCriticalPathProjections(pathInformationMsg *msg);
+
  void criticalPathProjectionsDone(CkReductionMsg *msg);
 
  void saveCriticalPathForPriorities(pathInformationMsg *msg);
 
-
  /// Traverse back and aquire the critical path to be used for automatic message prioritization
  void useCriticalPathForPriories();
 
- const std::map< std::pair<int,int>, int> & getCriticalPathForPriorityCounts() const { 
-   return criticalPathForPriorityCounts;
+ const std::map< int, int> & getCriticalPathForPriorityCounts() const {
+     return criticalPathForPriorityCounts;
  }
-  
-};
-
 
+};
 
 /**
  Augments the PathHistory in the envelope with the other necessary information
  from the envelope. These should be derived from an incoming message.
-
-   These objects can then be used for storing of information about a path 
-   outside of the incoming message's header. 
-
* Augments the PathHistory in the envelope with the other necessary information
* from the envelope. These should be derived from an incoming message.
+ *
+ * These objects can then be used for storing of information about a path
+ * outside of the incoming message's header.
+ *
    These are used for:
-      1) information about the currently executing message
-      2) combining the maximum paths along a reduction
-      3) combining multiple paths in Charisma and SDAG programs
+   1) information about the currently executing message
+   2) combining the maximum paths along a reduction
+   3) combining multiple paths in Charisma and SDAG programs
 
    This can be constructed from an envelope.
-*/
+   */
 
 class MergeablePathHistory {
- public:
-  double timeEntryMethodStarted;
+public:
+    double timeEntryMethodStarted;
 
-  double preceding_path_time;
+    double preceding_path_time;
 
-  int sender_pe;  // for traversing back over the PAG
-  int sender_history_table_idx; // for traversing back over the PAG
-  
-  int local_ep;  // The locally executing EP
-  int local_arr; // The locally executing array
-
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
- MergeablePathHistory(const envelope *env) 
-   : sender_pe(env->getSrcPe()), 
-    sender_history_table_idx(env->pathHistory.get_sender_history_table_idx()), 
-    local_ep(env->getEpIdx()),
-    local_arr(env->getArrayMgrIdx()),
-    preceding_path_time(env->pathHistory.getTime()),
-    timeEntryMethodStarted(0.0)
-      {
-       // No body
-      }
-#else
- MergeablePathHistory(const envelope *env) 
-   : sender_pe(env->getSrcPe()), 
-    local_ep(env->getEpIdx()),
-    local_arr(env->getArrayMgrIdx()),
-    timeEntryMethodStarted(0.0)
-      {
-       // No body
-      }
+    int sender_pe;  // for traversing back over the PAG
+    int sender_history_table_idx; // for traversing back over the PAG
+
+    int local_ep;  // The locally executing EP
+
+    int hops;
+
+    MergeablePathHistory(const envelope *env)
+    {
+        sender_pe = env->getSrcPe();
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+        sender_history_table_idx = env->pathHistory.get_sender_history_table_idx();
+        preceding_path_time = env->pathHistory.getTime();
+        hops = env->pathHistory.getHops() + 1;
 #endif
+        local_ep = env->getEpIdx();
+        timeEntryMethodStarted = 0.0;
+    }
 
-  MergeablePathHistory() {
-    reset();
-  }
-  
-  void reset(){
-    sender_pe = -1; 
-    sender_history_table_idx = -1; 
-    local_ep = -1;
-    preceding_path_time = 0.0;
-    timeEntryMethodStarted = 0.0;
-  }
-  
-  void sanity_check(){
-    if(sender_history_table_idx > -1){ 
-      CkAssert(sender_pe < CkNumPes()); 
-      CkAssert(sender_pe >= -1);
+    MergeablePathHistory() {
+        reset();
     }
-/*     CkAssert(sender_history_table_idx < 100000); */
-/*     CkAssert(sender_history_table_idx >= 0); */
-   
-/*     CkAssert(local_ep < 500); */
-/*     CkAssert(local_ep >= 0); */
 
-  }
+    MergeablePathHistory(const MergeablePathHistory &current) {
+        sender_pe = current.sender_pe;
+        sender_history_table_idx = current.sender_history_table_idx;
+        local_ep = current.local_ep;
+        preceding_path_time = get_entry_method_time(current);
+        hops = current.hops;
+    }
 
-  void updateMax(const MergeablePathHistory& other){
-    if(preceding_path_time < other.preceding_path_time)
-      *this = other;
-  }
+    double get_entry_method_time(const MergeablePathHistory &current) {
+      return (current.preceding_path_time +
+        CmiWallTimer() - current.timeEntryMethodStarted);
+    }
+
+    void reset(){
+        sender_pe = -1;
+        sender_history_table_idx = -1;
+        local_ep = -1;
+        preceding_path_time = 0.0;
+        timeEntryMethodStarted = -1;
+        hops = 0;
+    }
 
+    void sanity_check(){
+        if(sender_history_table_idx > -1){
+            CkAssert(sender_pe < CkNumPes());
+            CkAssert(sender_pe >= -1);
+        }
+    }
 
-  void updateMax(const envelope* env){
-    updateMax(MergeablePathHistory(env));
-  }
-  
-  double getTotalTime() const{
-    return preceding_path_time;
-  }
+    void updateMax(const MergeablePathHistory& other){
+        double now = CmiWallTimer();
+        //CkPrintf("====== merging history table  current (%d:%d:%d:%d:%f) \n", sender_pe, sender_history_table_idx, local_ep, local_arr, preceding_path_time+now - timeEntryMethodStarted);
+        //CkPrintf("====== merging history table  old (%d:%d:%d:%d:%f)\n", other.sender_pe, other.sender_history_table_idx, other.local_ep, other.local_arr, other.preceding_path_time);
+        if(preceding_path_time + now - timeEntryMethodStarted < other.preceding_path_time)
+        {
+            //CkPrintf(" switch current to the other \n");
+            *this = other;
+            timeEntryMethodStarted = now;
+        }
+    }
 
-  /// Write a description of the path into the beginning of the provided buffer. The buffer ought to be large enough.
+    void updateMax(const envelope* env){
+        updateMax(MergeablePathHistory(env));
+    }
+
+    double getTotalTime() const{
+        return preceding_path_time;
+    }
+
+    /// Write a description of the path into the beginning of the provided buffer. The buffer ought to be large enough.
   void printHTMLToString(char* buf) const{
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-    buf[0] = '\0';
-    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);
-#endif
+      buf[0] = '\0';
+      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);
   }
 
   void setDebug100(){
-    preceding_path_time = 100.0;
-    CkPrintf("Setting path length to 100\n");
+      preceding_path_time = 100.0;
+      CkPrintf("Setting path length to 100\n");
   }
 
 };
 
-
 /** 
     Stores information about the critical path in the table on each PE. 
     The PAG can be constructed by merging these together.
-
     These can be constructed from a MergeablePathHistory, and are assumed to refer to the local PE.
 */
 class PathHistoryTableEntry {
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-
- public:
-  int sender_pe;
-  int sender_history_table_idx;
-  int local_ep;
-  int local_arr;
-  int local_pe;
-
- private:
-  double start_time;
-  double local_path_time;
-  double preceding_path_time;
+public:
+    int sender_pe;
+    int sender_history_table_idx;
+    int local_ep;
+    int local_pe;
+private:
+    double start_time;
+    double local_path_time;
+    double preceding_path_time;
+
+public:
 
- public:
-  
  PathHistoryTableEntry() 
    : sender_pe(-1), 
     sender_history_table_idx(-1), 
@@ -221,7 +205,6 @@ class PathHistoryTableEntry {
     local_path_time(0.0), 
     preceding_path_time(0.0),     
     local_ep(-1),
-    local_arr(-1),
     local_pe(CkMyPe())
       {
        // No body
@@ -236,7 +219,6 @@ class PathHistoryTableEntry {
     preceding_path_time(p.preceding_path_time),
     start_time(p.timeEntryMethodStarted),
     local_ep(p.local_ep),
-    local_arr(p.local_arr),
     local_pe(CkMyPe())
       {
        // No body
@@ -250,15 +232,14 @@ class PathHistoryTableEntry {
     preceding_path_time(p.preceding_path_time),
     start_time(start),
     local_ep(p.local_ep),
-    local_arr(p.local_arr),
     local_pe(CkMyPe())
       {
        // No body
       }
 
   void printInfo(char *prefix = ""){
-    CkPrintf("%s [sender pe=%d table idx=%d] [local path contribution=%lf ep=%d] [Time= %lf + %lf]\n", prefix,  
-            sender_pe, sender_history_table_idx, local_path_time, local_ep, preceding_path_time, local_path_time);  
+      CkPrintf("%s [sender pe=%d table idx=%d] [local path contribution=%lf ep=%d] [Time= %lf + %lf]\n", prefix,
+          sender_pe, sender_history_table_idx, local_path_time, local_ep, preceding_path_time, local_path_time);
   }
 
 
@@ -270,18 +251,15 @@ class PathHistoryTableEntry {
   
   /// Return the length of the path up to and including this entry
   double getTotalTime(){
-    return local_path_time + preceding_path_time;
+      return local_path_time + preceding_path_time;
   }
 
   double get_start_time() const {return start_time;}
   double get_local_path_time() const {return local_path_time;}
   double get_preceding_path_time() const {return preceding_path_time;}
-#endif
-
 };
 
 
-
 /// A debugging routine that outputs critical path info as Projections user events.
 void  saveCurrentPathAsUserEvent(const char* prefix="");
 
@@ -294,58 +272,56 @@ void  printPathInMsg(void* msg);
 /// A debugging routine that outputs critical path info as Projections user events.
 void  printEPInfo();
 
-
 /// Acquire the critical path and deliver it to the user supplied callback
 void traceCriticalPathBack(CkCallback cb, bool saveToProjectionsTraces = false);
 
 
 /// A message containing information about a path of entry method invocations. This contains an array of PathHistoryTableEntry objects
 class pathInformationMsg : public CMessage_pathInformationMsg {
- public:
-  PathHistoryTableEntry *history;
-  int historySize;
-  int saveAsProjectionsUserEvents;
-  CkCallback cb;
-  int table_idx;
-
-  void printme(){
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
-    CkPrintf("Path contains %d entries\n", historySize);
-    for(int i=historySize-1;i>=0;i--){
-      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);
+public:
+    PathHistoryTableEntry *history;
+    int historySize;
+    int saveAsProjectionsUserEvents;
+    CkCallback cb;
+    int table_idx;
+    int hops;
+
+    void printme(){
+        CkPrintf("Path contains %d entries\n", historySize);
+        for(int i=historySize-1;i>=0;i--){
+            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);
+        }
     }
-#endif    
-  }
-  
 };
 
 
 CkpvExtern(MergeablePathHistory, currentlyExecutingPath); // The maximal incoming path for the node
 CkpvExtern(double, timeEntryMethodStarted);
 
-
-#ifdef USE_CRITICAL_PATH_HEADER_ARRAY
 /** A table to store all the local nodes in the parallel dependency graph */
 typedef std::map<int, PathHistoryTableEntry> PathHistoryTableType;
 CkpvExtern(PathHistoryTableType, pathHistoryTable);
 /** A counter that defines the new keys for the entries in the pathHistoryTable */
 CkpvExtern(int, pathHistoryTableLastIdx);
 
-
-
-
 // Reset the counts for the currently executing message. Cut the incoming path
 extern void resetThisEntryPath();
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
 extern void criticalPath_start(envelope * env); 
+extern void criticalPath_setep(int epIdx);
 extern void criticalPath_send(envelope * sendingEnv);
 extern void criticalPath_end();
 extern void criticalPath_split(); 
 
-
-
-
-/// Wrappers for Charm++ programs to use to annotate their program dependencies
+extern   MergeablePathHistory* saveCurrentPath();
+extern   void mergePathHistory(MergeablePathHistory*);
+#define CK_AUTOMATE_PRIORITY(x)     automaticallySetMessagePriority(x);
+#define CK_CRITICALPATH_SEND(x)   criticalPath_send(x);
+#define CK_CRITICALPATH_START(x)  criticalPath_start(x);
+#define CK_CRITICALPATH_SETEP(x)  criticalPath_setep(x);
+#define CK_CRITICALPATH_END()     criticalPath_end();
+#define CK_CRITICALPATH_SPLIT()   criticalPath_split();
 
 /// Declare a MergeablePathHistory variable, whose name is mangled with the supplied parameter
 #define MERGE_PATH_DECLARE(x) MergeablePathHistory merge_path_##x
@@ -356,8 +332,6 @@ extern void criticalPath_split();
 /// Take the maximal path from the stored merge_path variable and the currently executing path. Put the result in currently executing path.
 #define MERGE_PATH_MAX(x) merge_path_##x.updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_##x; 
 
-
-
 /// Declare a dynamic MergeablePathHistory variable. Each object can have many merge points stored in this single DECLARE.
 #define MERGE_PATH_DECLARE_D(x) std::map<int,MergeablePathHistory> merge_path_D_##x
 
@@ -374,12 +348,17 @@ extern void criticalPath_split();
 #define MERGE_PATH_MAX_D(x,n) merge_path_D_##x[n].updateMax(CkpvAccess(currentlyExecutingPath)); CkpvAccess(currentlyExecutingPath) = merge_path_D_##x[n]; 
 
 
-
 #else
 
-
 /// Empty no-op version for when critical path history is not compiled in
 
+#define CK_AUTOMATE_PRIORITY(x)
+#define CK_CRITICALPATH_SETEP(x)
+#define CK_CRITICALPATH_SEND(x)
+#define CK_CRITICALPATH_START(x)
+#define CK_CRITICALPATH_END()
+#define CK_CRITICALPATH_SPLIT()
+
 #define MERGE_PATH_DECLARE(x) ;
 #define MERGE_PATH_RESET(x) ;
 #define MERGE_PATH_MAX(x) ;
@@ -389,12 +368,7 @@ extern void criticalPath_split();
 #define MERGE_PATH_DELETE_ALL_D(x) ;
 #define MERGE_PATH_MAX_D(x,n) ;
 
-
 #endif
 
-
-
-
 /** @} */
 #endif
-#endif
index 5c837e3b81b415b038e9d7b38fe104c1af15e8ac..18d9f23d3935b493ef4c29767aaf968b4c63b536 100644 (file)
@@ -143,6 +143,10 @@ namespace xi {
     // found a continuation
     defs << "  if (c) {\n";
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    defs << "    MergeablePathHistory *currentSaved = c->getPath();\n";
+    defs << "    mergePathHistory(currentSaved);\n";
+#endif
     SdagConstruct::generateTraceEndCall(defs, 2);
 #if CMK_BIGSIM_CHARM
     SdagConstruct::generateEndExec(defs);
@@ -168,6 +172,12 @@ namespace xi {
     defs << "    delete c;\n";
     defs << "  }\n";
 
+#if USE_CRITICAL_PATH_HEADER_ARRAY
+    defs << "else {\n";
+    defs << "    MergeablePathHistory *currentSaved = saveCurrentPath();\n";
+    defs << "    buff0->setPath(currentSaved);\n";
+    defs << "}\n";
+#endif
     defs << "}\n\n";
     templateGuardEnd(defs);
   }